1. Andy Finnell
  2. VectorBoolean

Commits

Andy Finnell  committed b66f81c

don't pick shared points when determining a test point

  • Participants
  • Parent commits 8604862
  • Branches default

Comments (0)

Files changed (4)

File VectorBoolean/FBBezierContour.m

View file
     if ( [_edges count] == 0 )
         return NSZeroPoint;
     FBContourEdge *edge = [_edges objectAtIndex:0];
-    return [edge.curve pointAtParameter:0.5 leftBezierCurve:nil rightBezierCurve:nil];
+    FBContourEdge *stopValue = edge;
+    while ( edge.isStartShared ) {
+        edge = edge.next;
+        if ( edge == stopValue )
+            break;
+    }
+    return edge.curve.endPoint1;
 }
 
 - (id)copyWithZone:(NSZone *)zone

File VectorBoolean/FBBezierGraph.m

View file
                 for (FBContourEdge *theirEdge in theirContour.edges) {
                     NSArray *intersections = [ourEdge.curve intersectionsWithBezierCurve:theirEdge.curve];
                     for (FBBezierIntersection *intersection in intersections) {
+                        // Mark shared points
+                        if ( intersection.isAtStartOfCurve1 ) {
+                            ourEdge.startShared = YES;
+                            ourEdge.previous.stopShared = YES;
+                        } else if ( intersection.isAtStopOfCurve1 ) {
+                            ourEdge.stopShared = YES;
+                            ourEdge.next.startShared = YES;
+                        }
+                        if ( intersection.isAtStartOfCurve2 ) {
+                            theirEdge.startShared = YES;
+                            theirEdge.previous.stopShared = YES;
+                        } else if ( intersection.isAtStopOfCurve2 ) {
+                            theirEdge.stopShared = YES;
+                            theirEdge.next.startShared = YES;
+                        }
+
+                        // Don't add a crossing unless one edge actually crosses the other
                         if ( ![self doesEdge:ourEdge crossEdge:theirEdge atIntersection:intersection] )
                             continue;
 
     }
  
     [self removeDuplicateCrossings];
+    [other removeDuplicateCrossings];
 
     return [self numberOfCrossings];
 }
     // Find any duplicate crossings. These will happen at the endpoints of edges
     for (FBBezierContour *ourContour in self.contours) {
         for (FBContourEdge *ourEdge in ourContour.edges) {
-            for (FBEdgeCrossing *crossing in ourEdge.crossings) {
+            NSArray *crossings = [[ourEdge.crossings copy] autorelease];
+            for (FBEdgeCrossing *crossing in crossings) {
                 if ( crossing.isAtStart && crossing.edge.previous.lastCrossing.isAtEnd ) {
                     FBEdgeCrossing *counterpart = crossing.counterpart;
                     [crossing removeFromEdge];
         //  the other graph.
         FBContourEdge *startEdge = [contour.edges objectAtIndex:0];
         FBContourEdge *stopValue = startEdge;
-        while ( startEdge.firstCrossing != nil && startEdge.firstCrossing.isAtStart ) {
+        while ( startEdge.isStartShared ) {
             startEdge = startEdge.next;
             if ( startEdge == stopValue )
                 break; // for safety

File VectorBoolean/FBContourEdge.h

View file
     NSMutableArray *_crossings;
     FBBezierContour *_contour;
     NSUInteger _index;
+    BOOL _startShared;
+    BOOL _stopShared;
 }
 
 - (id) initWithBezierCurve:(FBBezierCurve *)curve contour:(FBBezierContour *)contour;
 @property (readonly) FBEdgeCrossing *firstCrossing;
 @property (readonly) FBEdgeCrossing *lastCrossing;
 
+@property (getter = isStartShared) BOOL startShared;
+@property (getter = isStopShared) BOOL stopShared;
+
 - (void) addCrossing:(FBEdgeCrossing *)crossing;
 - (void) removeCrossing:(FBEdgeCrossing *)crossing;
 - (void) removeAllCrossings;

File VectorBoolean/FBContourEdge.m

View file
 @synthesize crossings=_crossings;
 @synthesize index=_index;
 @synthesize contour=_contour;
+@synthesize startShared=_startShared;
+@synthesize stopShared=_stopShared;
 
 - (id) initWithBezierCurve:(FBBezierCurve *)curve contour:(FBBezierContour *)contour
 {