summaryrefslogtreecommitdiff
path: root/tikzit/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'tikzit/src/common')
-rw-r--r--tikzit/src/common/Edge.m22
-rw-r--r--tikzit/src/common/util.h8
-rw-r--r--tikzit/src/common/util.m18
3 files changed, 47 insertions, 1 deletions
diff --git a/tikzit/src/common/Edge.m b/tikzit/src/common/Edge.m
index 4ecb9bf..e90806d 100644
--- a/tikzit/src/common/Edge.m
+++ b/tikzit/src/common/Edge.m
@@ -522,7 +522,27 @@
- (NSRect)boundingRect {
[self updateControls];
- return NSRectAround4Points(src, targ, cp1, cp2);
+ NSRect bound = NSRectAround4Points(head, tail, cp1, cp2);
+ if ([self style] != nil) {
+ switch ([[self style] decorationStyle]) {
+ case ED_Arrow:
+ bound = NSRectWithPoint(bound, [self midTan]);
+ case ED_Tick:
+ bound = NSRectWithPoint(bound, [self leftNormal]);
+ bound = NSRectWithPoint(bound, [self rightNormal]);
+ case ED_None:
+ break;
+ }
+ if ([[self style] headStyle] != AH_None) {
+ bound = NSRectWithPoint(bound, [self leftHeadNormal]);
+ bound = NSRectWithPoint(bound, [self rightHeadNormal]);
+ }
+ if ([[self style] tailStyle] != AH_None) {
+ bound = NSRectWithPoint(bound, [self leftTailNormal]);
+ bound = NSRectWithPoint(bound, [self rightTailNormal]);
+ }
+ }
+ return bound;
}
- (void) adjustWeight:(float)handle_dist withCourseness:(float)wcourseness {
diff --git a/tikzit/src/common/util.h b/tikzit/src/common/util.h
index d868903..1ee4ef5 100644
--- a/tikzit/src/common/util.h
+++ b/tikzit/src/common/util.h
@@ -43,6 +43,14 @@
NSRect NSRectAroundPoints(NSPoint p1, NSPoint p2);
/*!
+ @brief Compute a bounding rectangle for two given points.
+ @param rect the base rectangle
+ @param the point to ensure is included
+ @result A rectangle containing rect and p
+ */
+NSRect NSRectWithPoint(NSRect rect, NSPoint p);
+
+/*!
@brief Compute a bounding rectangle for two given points with a given padding.
@param p1 a point.
@param p2 another point.
diff --git a/tikzit/src/common/util.m b/tikzit/src/common/util.m
index 762516f..2d40cbd 100644
--- a/tikzit/src/common/util.m
+++ b/tikzit/src/common/util.m
@@ -25,6 +25,24 @@ static BOOL fuzzyCompare(float f1, float f2) {
return (ABS(f1 - f2) <= 0.00001f * MIN(ABS(f1), ABS(f2)));
}
+NSRect NSRectWithPoint(NSRect rect, NSPoint p) {
+ CGFloat minX = NSMinX(rect);
+ CGFloat maxX = NSMaxX(rect);
+ CGFloat minY = NSMinY(rect);
+ CGFloat maxY = NSMaxY(rect);
+ if (p.x < minX) {
+ minX = p.x;
+ } else if (p.x > maxX) {
+ maxX = p.x;
+ }
+ if (p.y < minY) {
+ minY = p.y;
+ } else if (p.y > maxY) {
+ maxY = p.y;
+ }
+ return NSMakeRect(minX, minY, maxX - minX, maxY - minY);
+}
+
NSRect NSRectAroundPointsWithPadding(NSPoint p1, NSPoint p2, float padding) {
return NSMakeRect(MIN(p1.x,p2.x)-padding,
MIN(p1.y,p2.y)-padding,