Make pointOnCurve behaviour match documentation
This commit is contained in:
parent
452d0c540d
commit
1909955d73
2 changed files with 27 additions and 6 deletions
|
@ -7,6 +7,7 @@ import {
|
||||||
curvesIntersect,
|
curvesIntersect,
|
||||||
pointOnLine,
|
pointOnLine,
|
||||||
pointOnCurve,
|
pointOnCurve,
|
||||||
|
relativeOffsetOnCurve,
|
||||||
curveEdge,
|
curveEdge,
|
||||||
round,
|
round,
|
||||||
__addNonEnumProp,
|
__addNonEnumProp,
|
||||||
|
@ -902,7 +903,13 @@ Path.prototype.split = function (point) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else if (path.ops[1].type === 'curve') {
|
} 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) {
|
if (t !== false) {
|
||||||
let curve = new Bezier(
|
let curve = new Bezier(
|
||||||
{ x: path.ops[0].to.x, y: path.ops[0].to.y },
|
{ x: path.ops[0].to.x, y: path.ops[0].to.y },
|
||||||
|
|
|
@ -541,16 +541,30 @@ export function pointOnBeam(from, to, check, precision = 1e6) {
|
||||||
/**
|
/**
|
||||||
* Finds out whether a Point lies on a (cubic) Bezier curve
|
* 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 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} end - End of the curve
|
||||||
* @param {Point} check - Point to check
|
* @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) {
|
export function pointOnCurve(start, cp1, cp2, end, check) {
|
||||||
if (start.sitsOn(check)) return true
|
return relativeOffsetOnCurve(start, cp1, cp2, end, check) !== false
|
||||||
if (end.sitsOn(check)) return true
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(
|
let curve = new Bezier(
|
||||||
{ x: start.x, y: start.y },
|
{ x: start.x, y: start.y },
|
||||||
{ x: cp1.x, y: cp1.y },
|
{ x: cp1.x, y: cp1.y },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue