diff --git a/packages/core/src/path.mjs b/packages/core/src/path.mjs index 4b606b4189e..5388676eb78 100644 --- a/packages/core/src/path.mjs +++ b/packages/core/src/path.mjs @@ -7,6 +7,7 @@ import { curvesIntersect, pointOnLine, pointOnCurve, + relativeOffsetOnCurve, curveEdge, round, __addNonEnumProp, @@ -902,7 +903,13 @@ Path.prototype.split = function (point) { break } } else if (path.ops[1].type === 'curve') { - let t = pointOnCurve(path.ops[0].to, path.ops[1].cp1, path.ops[1].cp2, path.ops[1].to, point) + let t = relativeOffsetOnCurve( + path.ops[0].to, + path.ops[1].cp1, + path.ops[1].cp2, + path.ops[1].to, + point + ) if (t !== false) { let curve = new Bezier( { x: path.ops[0].to.x, y: path.ops[0].to.y }, diff --git a/packages/core/src/utils.mjs b/packages/core/src/utils.mjs index 22bc34fb6d5..9a5ecf17fd7 100644 --- a/packages/core/src/utils.mjs +++ b/packages/core/src/utils.mjs @@ -541,16 +541,30 @@ export function pointOnBeam(from, to, check, precision = 1e6) { /** * Finds out whether a Point lies on a (cubic) Bezier curve * - * @param {Point} from - Start of the curve + * @param {Point} start - Start of the curve * @param {Point} cp1 - Control point at the start of the curve - * @param {Point} cp1 - Control point at the end of the curve + * @param {Point} cp2 - Control point at the end of the curve * @param {Point} end - End of the curve * @param {Point} check - Point to check - * @return {bool} result - True of the Point is on the curve, false when not + * @return {boolean} result - True of the Point is on the curve, false when not */ export function pointOnCurve(start, cp1, cp2, end, check) { - if (start.sitsOn(check)) return true - if (end.sitsOn(check)) return true + return relativeOffsetOnCurve(start, cp1, cp2, end, check) !== false +} + +/** + * Finds where a Point lies on a (cubic) Bezier curve + * + * @param {Point} start - Start of the curve + * @param {Point} cp1 - Control point at the start of the curve + * @param {Point} cp2 - Control point at the end of the curve + * @param {Point} end - End of the curve + * @param {Point} check - Point to check + * @return {false|number} result - relative position on the curve (value between 0 and 1), false when not on curve + */ +export function relativeOffsetOnCurve(start, cp1, cp2, end, check) { + if (start.sitsOn(check)) return 0 + if (end.sitsOn(check)) return 1 let curve = new Bezier( { x: start.x, y: start.y }, { x: cp1.x, y: cp1.y },