From 59e7050db1e62dd4df14fb97754b27ea6c4fc85f Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 16 Dec 2020 13:44:43 +0100 Subject: [PATCH 1/6] Update RNSVGPathMeasure.m --- ios/Utils/RNSVGPathMeasure.m | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/ios/Utils/RNSVGPathMeasure.m b/ios/Utils/RNSVGPathMeasure.m index ed32e1f5e..475966777 100644 --- a/ios/Utils/RNSVGPathMeasure.m +++ b/ios/Utils/RNSVGPathMeasure.m @@ -17,16 +17,6 @@ */ static CGFloat idealFlatness = (CGFloat).01; -/** - * returns the distance between two points - */ -CGFloat distance(CGPoint p1, CGPoint p2) -{ - CGFloat dx = p2.x - p1.x; - CGFloat dy = p2.y - p1.y; - return hypot(dx, dy); -} - // Subdivide a Bézier (specific division) /* * (c) 2004 Alastair J. Houghton @@ -85,10 +75,18 @@ void subdivideBezierAtT(const CGPoint bez[4], CGPoint bez1[4], CGPoint bez2[4], } @implementation RNSVGPathMeasure +/** +* returns the distance between two points +*/ ++(CGFloat) distanceFrom:(CGPoint) p1 to:(CGPoint) p2 { + CGFloat dx = p2.x - p1.x; + CGFloat dy = p2.y - p1.y; + return hypot(dx, dy); +} - (void)addLine:(CGPoint *)last next:(const CGPoint *)next { NSArray *line = @[[NSValue valueWithCGPoint:*last], [NSValue valueWithCGPoint:*next]]; - _pathLength += distance(*last, *next); + _pathLength += [RNSVGPathMeasure distanceFrom:*last to:*next]; [_lengths addObject:[NSNumber numberWithDouble:_pathLength]]; [_lines addObject:line]; *last = *next; @@ -153,10 +151,10 @@ - (void)extractPathData:(CGPathRef)path { CGPoint ctrl2 = bez[2]; CGPoint next = bez[3]; CGFloat polyLen = - distance(last, ctrl1) + - distance(ctrl1, ctrl2) + - distance(ctrl2, next); - CGFloat chordLen = distance(last, next); + [RNSVGPathMeasure distanceFrom:last to:ctrl1] + + [RNSVGPathMeasure distanceFrom:ctrl1 to:ctrl2] + + [RNSVGPathMeasure distanceFrom:ctrl2 to:next]; + CGFloat chordLen = [RNSVGPathMeasure distanceFrom:last to:next]; CGFloat error = polyLen - chordLen; // if the error is less than our accepted level of error From a236382dbd01422706b623a3eda952cc2e340738 Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 16 Dec 2020 13:45:15 +0100 Subject: [PATCH 2/6] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e74bf3984..9bd66ad8e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "12.1.0", + "version": "12.1.1", "name": "react-native-svg", "description": "SVG library for react-native", "homepage": "https://github.com/react-native-community/react-native-svg", From cf09aa92bfd0a91190ae28bc33d2f05c34dd3d02 Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 3 Mar 2022 12:04:55 +0100 Subject: [PATCH 3/6] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9bd66ad8e..e74bf3984 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "12.1.1", + "version": "12.1.0", "name": "react-native-svg", "description": "SVG library for react-native", "homepage": "https://github.com/react-native-community/react-native-svg", From 8c09fc45b15c4760a7dae7094bfcb20ab90b4528 Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 3 Mar 2022 12:14:56 +0100 Subject: [PATCH 4/6] Update RNSVGPathMeasure.m --- ios/Utils/RNSVGPathMeasure.m | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ios/Utils/RNSVGPathMeasure.m b/ios/Utils/RNSVGPathMeasure.m index 475966777..6443bed8d 100644 --- a/ios/Utils/RNSVGPathMeasure.m +++ b/ios/Utils/RNSVGPathMeasure.m @@ -48,8 +48,17 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ -void subdivideBezierAtT(const CGPoint bez[4], CGPoint bez1[4], CGPoint bez2[4], CGFloat t) -{ +@implementation RNSVGPathMeasure +/** +* returns the distance between two points +*/ ++(CGFloat) distanceFrom:(CGPoint) p1 to:(CGPoint) p2 { + CGFloat dx = p2.x - p1.x; + CGFloat dy = p2.y - p1.y; + return hypot(dx, dy); +} + ++(void) subdivideBezierAtT:(const CGPoint) bez[4] bez1:(CGPoint)bez1[4] bez2:(CGPoint)bez2[4] t:(CGFloat)t { CGPoint q; CGFloat mt = 1 - t; @@ -74,15 +83,6 @@ 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; } -@implementation RNSVGPathMeasure -/** -* returns the distance between two points -*/ -+(CGFloat) distanceFrom:(CGPoint) p1 to:(CGPoint) p2 { - CGFloat dx = p2.x - p1.x; - CGFloat dy = p2.y - p1.y; - return hypot(dx, dy); -} - (void)addLine:(CGPoint *)last next:(const CGPoint *)next { NSArray *line = @[[NSValue valueWithCGPoint:*last], [NSValue valueWithCGPoint:*next]]; @@ -164,7 +164,7 @@ - (void)extractPathData:(CGPathRef)path { _lineCount++; } else { CGPoint bez1[4], bez2[4]; - subdivideBezierAtT(bez, bez1, bez2, .5); + [RNSVGPathMeasure subdivideBezierAtT:bez bez1:bez1 bez2:bez2 t:.5]; [curves addObject:[NSValue valueWithBytes:&bez2 objCType:@encode(CGPoint[4])]]; [curves addObject:[NSValue valueWithBytes:&bez1 objCType:@encode(CGPoint[4])]]; curveIndex += 2; From 85a743394dbbd52b8362dd35e51a5b93e2a66eb9 Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 3 Mar 2022 12:16:21 +0100 Subject: [PATCH 5/6] Update RNSVGPathMeasure.m --- ios/Utils/RNSVGPathMeasure.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Utils/RNSVGPathMeasure.m b/ios/Utils/RNSVGPathMeasure.m index 6443bed8d..8655b70a8 100644 --- a/ios/Utils/RNSVGPathMeasure.m +++ b/ios/Utils/RNSVGPathMeasure.m @@ -52,13 +52,13 @@ @implementation RNSVGPathMeasure /** * returns the distance between two points */ -+(CGFloat) distanceFrom:(CGPoint) p1 to:(CGPoint) p2 { ++(CGFloat) distanceFrom:(CGPoint)p1 to:(CGPoint) p2 { CGFloat dx = p2.x - p1.x; CGFloat dy = p2.y - p1.y; return hypot(dx, dy); } -+(void) subdivideBezierAtT:(const CGPoint) bez[4] bez1:(CGPoint)bez1[4] bez2:(CGPoint)bez2[4] t:(CGFloat)t { ++(void) subdivideBezierAtT:(const CGPoint)bez[4] bez1:(CGPoint)bez1[4] bez2:(CGPoint)bez2[4] t:(CGFloat)t { CGPoint q; CGFloat mt = 1 - t; From 10b2575acaf6da16eef1f86302b9c1a70a48a574 Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 3 Mar 2022 12:18:40 +0100 Subject: [PATCH 6/6] Update RNSVGPathMeasure.m --- ios/Utils/RNSVGPathMeasure.m | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/ios/Utils/RNSVGPathMeasure.m b/ios/Utils/RNSVGPathMeasure.m index 8655b70a8..7fe3085a1 100644 --- a/ios/Utils/RNSVGPathMeasure.m +++ b/ios/Utils/RNSVGPathMeasure.m @@ -17,6 +17,16 @@ */ static CGFloat idealFlatness = (CGFloat).01; +/** + * returns the distance between two points + */ +static CGFloat distance(CGPoint p1, CGPoint p2) +{ + CGFloat dx = p2.x - p1.x; + CGFloat dy = p2.y - p1.y; + return hypot(dx, dy); +} + // Subdivide a Bézier (specific division) /* * (c) 2004 Alastair J. Houghton @@ -48,17 +58,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ -@implementation RNSVGPathMeasure -/** -* returns the distance between two points -*/ -+(CGFloat) distanceFrom:(CGPoint)p1 to:(CGPoint) p2 { - CGFloat dx = p2.x - p1.x; - CGFloat dy = p2.y - p1.y; - return hypot(dx, dy); -} - -+(void) subdivideBezierAtT:(const CGPoint)bez[4] bez1:(CGPoint)bez1[4] bez2:(CGPoint)bez2[4] t:(CGFloat)t { +static void subdivideBezierAtT(const CGPoint bez[4], CGPoint bez1[4], CGPoint bez2[4], CGFloat t) +{ CGPoint q; CGFloat mt = 1 - t; @@ -83,10 +84,11 @@ +(void) subdivideBezierAtT:(const CGPoint)bez[4] bez1:(CGPoint)bez1[4] bez2:(CGP bez1[3].y = bez2[0].y = mt * bez1[2].y + t * bez2[1].y; } +@implementation RNSVGPathMeasure - (void)addLine:(CGPoint *)last next:(const CGPoint *)next { NSArray *line = @[[NSValue valueWithCGPoint:*last], [NSValue valueWithCGPoint:*next]]; - _pathLength += [RNSVGPathMeasure distanceFrom:*last to:*next]; + _pathLength += distance(*last, *next); [_lengths addObject:[NSNumber numberWithDouble:_pathLength]]; [_lines addObject:line]; *last = *next; @@ -151,10 +153,10 @@ - (void)extractPathData:(CGPathRef)path { CGPoint ctrl2 = bez[2]; CGPoint next = bez[3]; CGFloat polyLen = - [RNSVGPathMeasure distanceFrom:last to:ctrl1] + - [RNSVGPathMeasure distanceFrom:ctrl1 to:ctrl2] + - [RNSVGPathMeasure distanceFrom:ctrl2 to:next]; - CGFloat chordLen = [RNSVGPathMeasure distanceFrom:last to:next]; + distance(last, ctrl1) + + distance(ctrl1, ctrl2) + + distance(ctrl2, next); + CGFloat chordLen = distance(last, next); CGFloat error = polyLen - chordLen; // if the error is less than our accepted level of error @@ -164,7 +166,7 @@ - (void)extractPathData:(CGPathRef)path { _lineCount++; } else { CGPoint bez1[4], bez2[4]; - [RNSVGPathMeasure subdivideBezierAtT:bez bez1:bez1 bez2:bez2 t:.5]; + 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;