From dae8bb630b5966e5d14426d070e60e1319c00ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 9 Sep 2015 07:34:28 +0200 Subject: [PATCH] Avoid checking curves if completely out of control bounds. This leads to a huge speed increase! Relates to #765 --- src/path/Curve.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index eab994ff..2f33791a 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -1695,7 +1695,20 @@ new function() { // Scope for intersection using bezier fat-line clipping // #getIntersections() calls as it is required to create the resulting // CurveLocation objects. _getIntersections: function(v1, v2, curve1, curve2, locations, param) { - if (!param.startConnected && !param.endConnected + var min = Math.min, + max = Math.max; + // Avoid checking curves if completely out of control bounds. + // Also detect and handle overlaps. + if (!( + max(v1[0], v1[2], v1[4], v1[6]) >= + min(v2[0], v2[2], v2[4], v2[6]) && + max(v1[1], v1[3], v1[5], v1[7]) >= + min(v2[1], v2[3], v2[5], v2[7]) && + min(v1[0], v1[2], v1[4], v1[6]) <= + max(v2[0], v2[2], v2[4], v2[6]) && + min(v1[1], v1[3], v1[5], v1[7]) <= + max(v2[1], v2[3], v2[5], v2[7]) + ) || !param.startConnected && !param.endConnected && addOverlap(v1, v2, curve1, curve2, locations, param)) return locations; var straight1 = Curve.isStraight(v1),