summaryrefslogtreecommitdiff
path: root/tikzit/src/common/Edge.m
diff options
context:
space:
mode:
Diffstat (limited to 'tikzit/src/common/Edge.m')
-rw-r--r--tikzit/src/common/Edge.m43
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;