From f90dd4ffc4b679e61a2a8cf43853b7d3c72c3e83 Mon Sep 17 00:00:00 2001 From: randomguy3 Date: Tue, 17 Jan 2012 18:39:31 +0000 Subject: 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 --- tikzit/src/common/Edge.m | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'tikzit/src/common/Edge.m') 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; -- cgit v1.2.3