import { isCollinear } from "./is-collinear.js"; /** * Returns `true` if the given bezier has all control points collinear and * it is self-overlapping, i.e. if it intersects itself at an infinite number * of points. * * * a bezier curve can only intersect itself at an infinite number of * points if its locus is a 'self-overlapping line'. * * @param ps an order 0,1,2 or 3 bezier curve given as an array of its control * points, e.g. `[[1,2],[3,4],[5,6],[7,8]]` * * @doc mdx */ function isSelfOverlapping(ps: number[][]) { if (!isCollinear(ps)) { return false; } // Check if control points are non-strict monotone const xs = ps.map(p => p[0]); const ys = ps.map(p => p[1]); return !(isMonotone(xs) && isMonotone(ys)); } /** * Returns true if the given array of numbers are non-strict monotone increasing. * @param xs an array of numbers * * @internal */ function isMonotoneIncreasing(xs: number[]) { for (let i=1; i xs[i]) { return false; } } return true; } /** * Returns true if the given array of numbers are non-strict monotone decreasing. * @param xs an array of numbers * * @internal */ function isMonotoneDecreasing(xs: number[]) { for (let i=1; i