Namespaces or un-globalifies a handful more iOS globals

This commit is contained in:
Ben Roth
2018-02-16 17:14:10 -08:00
parent 0c0c9c122d
commit 5f74c92a58
6 changed files with 44 additions and 40 deletions

View File

@@ -29,7 +29,7 @@ static CGFloat idealFlatness = .01;
/**
* returns the distance between two points
*/
CGFloat distance(CGPoint p1, CGPoint p2)
CGFloat RNSVGPerformanceBezier_distance(CGPoint p1, CGPoint p2)
{
CGFloat dx = p2.x - p1.x;
CGFloat dy = p2.y - p1.y;
@@ -68,7 +68,7 @@ CGFloat distance(CGPoint p1, CGPoint p2)
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
void subdivideBezierAtT(const CGPoint bez[4], CGPoint bez1[4], CGPoint bez2[4], CGFloat t)
void RNSVGPerformanceBezier_subdivideBezierAtT(const CGPoint bez[4], CGPoint bez1[4], CGPoint bez2[4], CGFloat t)
{
CGPoint q;
CGFloat mt = 1 - t;
@@ -94,10 +94,10 @@ void subdivideBezierAtT(const CGPoint bez[4], CGPoint bez1[4], CGPoint bez2[4],
bez1[3].y = bez2[0].y = mt * bez1[2].y + t * bez2[1].y;
}
void addLine(CGPoint *last, const CGPoint *next, NSMutableArray *lines, CGFloat *length, NSMutableArray *lengths) {
void RNSVGPerformanceBezier_addLine(CGPoint *last, const CGPoint *next, NSMutableArray *lines, CGFloat *length, NSMutableArray *lengths) {
NSArray *line = @[[NSValue valueWithCGPoint:*last], [NSValue valueWithCGPoint:*next]];
[lines addObject:line];
*length += distance(*last, *next);
*length += RNSVGPerformanceBezier_distance(*last, *next);
[lengths addObject:[NSNumber numberWithDouble:*length]];
*last = *next;
}
@@ -138,7 +138,7 @@ void addLine(CGPoint *last, const CGPoint *next, NSMutableArray *lines, CGFloat
case kCGPathElementAddLineToPoint: {
CGPoint next = element.point;
addLine(&last, &next, lines, &length, lengths);
RNSVGPerformanceBezier_addLine(&last, &next, lines, &length, lengths);
lineCount++;
break;
}
@@ -166,20 +166,20 @@ void addLine(CGPoint *last, const CGPoint *next, NSMutableArray *lines, CGFloat
CGPoint ctrl2 = bez[2];
CGPoint next = bez[3];
CGFloat polyLen =
distance(last, ctrl1) +
distance(ctrl1, ctrl2) +
distance(ctrl2, next);
CGFloat chordLen = distance(last, next);
RNSVGPerformanceBezier_distance(last, ctrl1) +
RNSVGPerformanceBezier_distance(ctrl1, ctrl2) +
RNSVGPerformanceBezier_distance(ctrl2, next);
CGFloat chordLen = RNSVGPerformanceBezier_distance(last, next);
CGFloat error = polyLen - chordLen;
// if the error is less than our accepted level of error
// then add a line, else, split the curve in half
if (error <= idealFlatness) {
addLine(&last, &next, lines, &length, lengths);
RNSVGPerformanceBezier_addLine(&last, &next, lines, &length, lengths);
lineCount++;
} else {
CGPoint bez1[4], bez2[4];
subdivideBezierAtT(bez, bez1, bez2, .5);
RNSVGPerformanceBezier_subdivideBezierAtT(bez, bez1, bez2, .5);
[curves addObject:[NSValue valueWithBytes:&bez2 objCType:@encode(CGPoint[4])]];
[curves addObject:[NSValue valueWithBytes:&bez1 objCType:@encode(CGPoint[4])]];
curveIndex += 2;
@@ -190,7 +190,7 @@ void addLine(CGPoint *last, const CGPoint *next, NSMutableArray *lines, CGFloat
case kCGPathElementCloseSubpath: {
CGPoint next = origin;
addLine(&last, &next, lines, &length, lengths);
RNSVGPerformanceBezier_addLine(&last, &next, lines, &length, lengths);
lineCount++;
isClosed = YES;
break;