Andy Finnell avatar Andy Finnell committed 7ff2159

cleaning up the code by removing dead code and consolidating methods

Comments (0)

Files changed (1)

VectorBoolean/FBBezierGraph.m

 
 @interface FBBezierGraph ()
 
-- (NSUInteger) numberOfCrossings;
 - (void) removeDuplicateCrossings;
 - (BOOL) doesEdge:(FBContourEdge *)edge1 crossEdge:(FBContourEdge *)edge2 atIntersection:(FBBezierIntersection *)intersection;
-- (BOOL) insertCrossingsWithBezierGraph:(FBBezierGraph *)other;
-- (BOOL) containsPoint:(NSPoint)point;
+- (void) insertCrossingsWithBezierGraph:(FBBezierGraph *)other;
 - (FBEdgeCrossing *) firstUnprocessedCrossing;
 - (void) markCrossingsAsEntryOrExitWithBezierGraph:(FBBezierGraph *)otherGraph markInside:(BOOL)markInside;
 - (FBBezierGraph *) bezierGraphFromIntersections;
 - (void) removeCrossings;
 
 - (void) addContour:(FBBezierContour *)contour;
-- (void) addBezierGraph:(FBBezierGraph *)graph;
 - (void) round;
 - (FBContourInside) contourInsides:(FBBezierContour *)contour;
 
-- (void) markCrossingsAsEntryOrExitWithBezierGraphForUnion:(FBBezierGraph *)otherGraph;
-- (void) markCrossingsAsEntryOrExitWithBezierGraphForIntersect:(FBBezierGraph *)otherGraph;
-- (void) markCrossingsAsEntryOrExitWithBezierGraphForDifference:(FBBezierGraph *)otherGraph markInside:(BOOL)markInside;
-
 - (NSArray *) nonintersectingContours;
 - (BOOL) containsContour:(FBBezierContour *)contour;
 - (FBBezierContour *) containerForContour:(FBBezierContour *)testContour;
 
 @property (readonly) NSArray *contours;
 @property (readonly) NSRect bounds;
-@property (readonly) NSPoint testPoint;
 
 @end
 
 {
     [self insertCrossingsWithBezierGraph:graph];
     
-    [self markCrossingsAsEntryOrExitWithBezierGraphForUnion:graph];
-    [graph markCrossingsAsEntryOrExitWithBezierGraphForUnion:self];
+    [self markCrossingsAsEntryOrExitWithBezierGraph:graph markInside:NO];
+    [graph markCrossingsAsEntryOrExitWithBezierGraph:self markInside:NO];
 
     FBBezierGraph *result = [self bezierGraphFromIntersections];
     [result round];
     return result;
 }
 
-- (void) markCrossingsAsEntryOrExitWithBezierGraphForUnion:(FBBezierGraph *)otherGraph
-{
-    for (FBBezierContour *contour in self.contours) {
-        NSArray *intersectingContours = contour.intersectingContours;
-        for (FBBezierContour *otherContour in intersectingContours) {
-            if ( otherContour.inside == FBContourInsideHole )
-                [contour markCrossingsAsEntryOrExitWithContour:otherContour markInside:YES];
-            else
-                [contour markCrossingsAsEntryOrExitWithContour:otherContour markInside:NO];
-        }
-    }
-}
-
 - (FBBezierGraph *) intersectWithBezierGraph:(FBBezierGraph *)graph
 {
     [self insertCrossingsWithBezierGraph:graph];
     
-    [self markCrossingsAsEntryOrExitWithBezierGraphForIntersect:graph];
-    [graph markCrossingsAsEntryOrExitWithBezierGraphForIntersect:self];
+    [self markCrossingsAsEntryOrExitWithBezierGraph:graph markInside:YES];
+    [graph markCrossingsAsEntryOrExitWithBezierGraph:self markInside:YES];
     
     FBBezierGraph *result = [self bezierGraphFromIntersections];
     [result round];
     return result;
 }
 
-- (void) markCrossingsAsEntryOrExitWithBezierGraphForIntersect:(FBBezierGraph *)otherGraph
-{
-    for (FBBezierContour *contour in self.contours) {
-        NSArray *intersectingContours = contour.intersectingContours;
-        for (FBBezierContour *otherContour in intersectingContours) {
-            if ( otherContour.inside == FBContourInsideHole )
-                [contour markCrossingsAsEntryOrExitWithContour:otherContour markInside:NO];
-            else
-                [contour markCrossingsAsEntryOrExitWithContour:otherContour markInside:YES];
-        }
-    }
-}
-
 - (FBBezierGraph *) differenceWithBezierGraph:(FBBezierGraph *)graph
 {
-#if 1
     [self insertCrossingsWithBezierGraph:graph];
     
-    [self markCrossingsAsEntryOrExitWithBezierGraphForDifference:graph markInside:NO];
-    [graph markCrossingsAsEntryOrExitWithBezierGraphForDifference:self markInside:YES];
+    [self markCrossingsAsEntryOrExitWithBezierGraph:graph markInside:NO];
+    [graph markCrossingsAsEntryOrExitWithBezierGraph:self markInside:YES];
     
     FBBezierGraph *result = [self bezierGraphFromIntersections];
     [result round];
     [graph removeCrossings];
     
     return result;  
-#else
-    BOOL hasCrossings = [self insertCrossingsWithBezierGraph:graph];
-    if ( !hasCrossings ) {
-        // There are no crossings, which means one contains the other, or they're completely disjoint 
-        BOOL subjectContainsClip = [self containsPoint:graph.testPoint];
-        BOOL clipContainsSubject = [graph containsPoint:self.testPoint];
-        
-        // Clean up crossings so the graphs can be reused
-        [self removeCrossings];
-        [graph removeCrossings];
-        
-        if ( subjectContainsClip ) {
-            // Clip punches a clean (non-intersecting) hole in subject
-            FBBezierGraph *result = [FBBezierGraph bezierGraph];
-            [result addBezierGraph:self];
-            [result addBezierGraph:graph];
-            return result;
-        }
-        
-        if ( clipContainsSubject )
-            // We're subtracting out everything
-            return [FBBezierGraph bezierGraph];
-        
-        // No crossings, so nothing to subtract from subject
-        return self;
-    }
-    
-    [self markCrossingsAsEntryOrExitWithBezierGraph:graph markInside:NO];
-    [graph markCrossingsAsEntryOrExitWithBezierGraph:self markInside:YES];
-    
-    FBBezierGraph *result = [self bezierGraphFromIntersections];
-    [result round];
-    
-    // Clean up crossings so the graphs can be reused
-    [self removeCrossings];
-    [graph removeCrossings];
-    
-    return result;
-#endif
 }
 
-- (void) markCrossingsAsEntryOrExitWithBezierGraphForDifference:(FBBezierGraph *)otherGraph markInside:(BOOL)markInside
+- (void) markCrossingsAsEntryOrExitWithBezierGraph:(FBBezierGraph *)otherGraph markInside:(BOOL)markInside
 {
     for (FBBezierContour *contour in self.contours) {
         NSArray *intersectingContours = contour.intersectingContours;
     }
 }
 
-
 - (FBBezierGraph *) xorWithBezierGraph:(FBBezierGraph *)graph
 {
     FBBezierGraph *allParts = [self unionWithBezierGraph:graph];
         [contour round];
 }
 
-- (BOOL) insertCrossingsWithBezierGraph:(FBBezierGraph *)other
+- (void) insertCrossingsWithBezierGraph:(FBBezierGraph *)other
 {
     // Find all intersections and, if they cross the other graph, create crossings for them
     for (FBBezierContour *ourContour in self.contours) {
  
     [self removeDuplicateCrossings];
     [other removeDuplicateCrossings];
-
-    return [self numberOfCrossings];
 }
 
 - (void) removeDuplicateCrossings
     }
 }
 
-- (NSUInteger) numberOfCrossings
-{
-    NSUInteger count = 0;
-    for (FBBezierContour *ourContour in self.contours)
-        for (FBContourEdge *ourEdge in ourContour.edges)
-            count += [ourEdge.crossings count];
-    return count;
-}
-
 - (BOOL) doesEdge:(FBContourEdge *)edge1 crossEdge:(FBContourEdge *)edge2 atIntersection:(FBBezierIntersection *)intersection
 {
     // Handle the main case first
     return _bounds;
 }
 
-- (BOOL) containsPoint:(NSPoint)testPoint
-{
-    // Create a test line from our point to somewhere outside our graph. We'll see how many times the test
-    //  line intersects edges of the graph. Based on the winding rule, if it's an odd number, we're inside
-    //  the graph, if even, outside.
-    NSPoint lineEndPoint = NSMakePoint(testPoint.x > NSMinX(self.bounds) ? NSMinX(self.bounds) - 10 : NSMaxX(self.bounds) + 10, testPoint.y); /* just move us outside the bounds of the graph */
-    FBBezierCurve *testCurve = [FBBezierCurve bezierCurveWithLineStartPoint:testPoint endPoint:lineEndPoint];
-    
-    NSUInteger intersectCount = 0;
-    for (FBBezierContour *contour in self.contours) {
-        for (FBContourEdge *edge in contour.edges) {
-            NSArray *intersections = [testCurve intersectionsWithBezierCurve:edge.curve];
-            for (FBBezierIntersection *intersection in intersections) {
-                if ( intersection.isTangent )
-                    continue;
-                intersectCount++;
-            }
-        }
-    }
-    
-    return (intersectCount % 2) == 1;
-}
-
 - (FBContourInside) contourInsides:(FBBezierContour *)testContour
 {
     NSPoint testPoint = testContour.firstPoint;
         [crossings removeObject:crossing];
 }
 
-- (void) markCrossingsAsEntryOrExitWithBezierGraph:(FBBezierGraph *)otherGraph markInside:(BOOL)markInside
-{
-    for (FBBezierContour *contour in self.contours) {
-        NSArray *intersectingContours = contour.intersectingContours;
-        for (FBBezierContour *otherContour in intersectingContours)
-            [contour markCrossingsAsEntryOrExitWithContour:otherContour markInside:markInside];
-    }
-}
-
-
 - (FBEdgeCrossing *) firstUnprocessedCrossing
 {
     for (FBBezierContour *contour in _contours) {
     _bounds = NSZeroRect;
 }
 
-- (void) addBezierGraph:(FBBezierGraph *)graph
-{
-    for (FBBezierContour *contour in graph.contours)
-        [self addContour:[[contour copy] autorelease]];
-}
-
-- (NSPoint) testPoint
-{
-    if ( [_contours count] == 0 )
-        return NSZeroPoint;
-    FBBezierContour *contour = [_contours objectAtIndex:0];
-    return contour.testPoint;
-}
-
 - (NSArray *) nonintersectingContours
 {
     NSMutableArray *contours = [NSMutableArray arrayWithCapacity:[_contours count]];
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.