diff options
author | randomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64> | 2012-01-17 18:39:31 +0000 |
---|---|---|
committer | randomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64> | 2012-01-17 18:39:31 +0000 |
commit | f90dd4ffc4b679e61a2a8cf43853b7d3c72c3e83 (patch) | |
tree | 15842d8311e621dc2776a77c9740bd72784f13f1 /tikzit/src/common/Edge.m | |
parent | 18871fdd7bbfb43eb0971ee358554f321f789eee (diff) |
Calculate the head and tail of edges to be just where they contact the node (ie: behave more like tikz).
git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@388 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64
Diffstat (limited to 'tikzit/src/common/Edge.m')
-rw-r--r-- | tikzit/src/common/Edge.m | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/tikzit/src/common/Edge.m b/tikzit/src/common/Edge.m index efd9707..1878165 100644 --- a/tikzit/src/common/Edge.m +++ b/tikzit/src/common/Edge.m @@ -22,6 +22,7 @@ // #import "Edge.h" +#import "Shape.h" #import "util.h" @implementation Edge @@ -73,7 +74,37 @@ } - (NSPoint) _findContactPointOn:(Node*)node at:(float)angle { - return [node point]; + NSPoint rayStart = [node point]; + Shape *shape = [node shape]; + if (shape == nil) { + return rayStart; + } + + Transformer *shapeTrans = [node shapeTransformer]; + NSRect searchArea = [node boundsUsingShapeTransform:shapeTrans]; + if (!NSPointInRect(rayStart, searchArea)) { + return rayStart; + } + + NSPoint rayEnd = findExitPointOfRay (rayStart, angle, searchArea); + + for (NSArray *path in [shape paths]) { + for (Edge *curve in path) { + NSPoint intersect; + [curve updateControls]; + if (lineSegmentIntersectsBezier (rayStart, rayEnd, + [shapeTrans toScreen:curve->head], + [shapeTrans toScreen:curve->cp1], + [shapeTrans toScreen:curve->cp2], + [shapeTrans toScreen:curve->tail], + &intersect)) { + // we just keep shortening the line + rayStart = intersect; + } + } + } + + return rayStart; } - (void)updateControls { @@ -190,6 +221,16 @@ return NSMakePoint(mid.x - (mid.y - midTan.y), mid.y + (mid.x - midTan.x)); } +- (NSPoint) head { + [self updateControls]; + return head; +} + +- (NSPoint) tail { + [self updateControls]; + return tail; +} + - (NSPoint)cp1 { [self updateControls]; return cp1; |