meo-skia-canvas
    Preparing search index...

    Interface Path2D

    This Canvas 2D API interface is used to declare a path that can then be used on a CanvasRenderingContext2D object. The path methods of the CanvasRenderingContext2D interface are also present on this interface, which gives you the convenience of being able to retain and replay your path whenever desired.

    MDN Reference

    interface Path2D {
        bounds: Path2DBounds;
        d: string;
        edges: readonly Path2DEdge[];
        addPath(path: Path2D, transform?: DOMMatrix2DInit): void;
        arc(
            x: number,
            y: number,
            radius: number,
            startAngle: number,
            endAngle: number,
            counterclockwise?: boolean,
        ): void;
        arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
        bezierCurveTo(
            cp1x: number,
            cp1y: number,
            cp2x: number,
            cp2y: number,
            x: number,
            y: number,
        ): void;
        closePath(): void;
        complement(otherPath: Path2D): Path2D;
        conicCurveTo(
            cpx: number,
            cpy: number,
            x: number,
            y: number,
            weight: number,
        ): void;
        contains(x: number, y: number): boolean;
        difference(otherPath: Path2D): Path2D;
        ellipse(
            x: number,
            y: number,
            radiusX: number,
            radiusY: number,
            rotation: number,
            startAngle: number,
            endAngle: number,
            counterclockwise?: boolean,
        ): void;
        interpolate(otherPath: Path2D, weight: number): Path2D;
        intersect(otherPath: Path2D): Path2D;
        jitter(segmentLength: number, amount: number, seed?: number): Path2D;
        lineTo(x: number, y: number): void;
        moveTo(x: number, y: number): void;
        offset(dx: number, dy: number): Path2D;
        points(step?: number): readonly [x: number, y: number][];
        quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
        rect(x: number, y: number, w: number, h: number): void;
        round(radius: number): Path2D;
        roundRect(
            x: number,
            y: number,
            w: number,
            h: number,
            radii?: number | DOMPointInit | (number | DOMPointInit)[],
        ): void;
        simplify(rule?: "evenodd" | "nonzero"): Path2D;
        transform(transform: Matrix): Path2D;
        transform(
            a: number,
            b: number,
            c: number,
            d: number,
            e: number,
            f: number,
        ): Path2D;
        trim(start: number, end: number, inverted?: boolean): Path2D;
        trim(start: number, inverted?: boolean): Path2D;
        union(otherPath: Path2D): Path2D;
        unwind(): Path2D;
        xor(otherPath: Path2D): Path2D;
    }

    Hierarchy (View Summary)

    Index
    bounds: Path2DBounds

    The smallest rectangle containing the path.

    Does not account for lineWidth, so a stroked path covers more than this. A browser Path2D is an opaque recorder of drawing commands with no way to measure it.

    🧪 Not in the HTML Canvas standard.

    d: string

    The path as SVG path data. Readable, writable, and appendable with +=.

    🧪 Not in the HTML Canvas standard.

    edges: readonly Path2DEdge[]

    Every segment added so far, as ["verb", ...points] entries.

    The verbs and their arguments match the method names, so the list can be replayed onto another path or onto a context.

    🧪 Not in the HTML Canvas standard.

    • Parameters

      • x: number
      • y: number
      • radius: number
      • startAngle: number
      • endAngle: number
      • Optionalcounterclockwise: boolean

      Returns void

    • Parameters

      • x1: number
      • y1: number
      • x2: number
      • y2: number
      • radius: number

      Returns void

    • Parameters

      • cp1x: number
      • cp1y: number
      • cp2x: number
      • cp2y: number
      • x: number
      • y: number

      Returns void

    • The area of otherPath that this path does not cover.

      🧪 Not in the HTML Canvas standard.

      Parameters

      Returns Path2D

    • Curve to (x, y), pulled toward the control point.

      weight sets how close the curve comes: 0 draws a straight line, 1 matches quadraticCurveTo, and larger values pull it nearer the control point.

      🧪 Not in the HTML Canvas standard.

      Parameters

      • cpx: number
      • cpy: number
      • x: number
      • y: number
      • weight: number

      Returns void

    • Whether the point is inside the path or on one of its contours.

      🧪 Not in the HTML Canvas standard.

      Parameters

      • x: number
      • y: number

      Returns boolean

    • The area of this path that otherPath does not cover.

      🧪 Not in the HTML Canvas standard.

      Parameters

      Returns Path2D

    • Parameters

      • x: number
      • y: number
      • radiusX: number
      • radiusY: number
      • rotation: number
      • startAngle: number
      • endAngle: number
      • Optionalcounterclockwise: boolean

      Returns void

    • A blend of two paths that share a sequence of verbs and differ only in their points.

      weight picks the mix: 0 is this path, 1 is otherPath.

      🧪 Not in the HTML Canvas standard.

      Parameters

      • otherPath: Path2D
      • weight: number

      Returns Path2D

    • A copy broken into segments of segmentLength with each point displaced at random by up to amount.

      The displacement is random but reproducible: the same seed gives the same path every run.

      🧪 Not in the HTML Canvas standard.

      Parameters

      • segmentLength: number
      • amount: number
      • Optionalseed: number

      Returns Path2D

    • A copy shifted by dx horizontally and dy vertically.

      🧪 Not in the HTML Canvas standard.

      Parameters

      • dx: number
      • dy: number

      Returns Path2D

    • The positions along the path at every step pixels, 1 by default.

      🧪 Not in the HTML Canvas standard.

      Parameters

      • Optionalstep: number

      Returns readonly [x: number, y: number][]

    • A copy with its corners rounded off to radius.

      🧪 Not in the HTML Canvas standard.

      Parameters

      • radius: number

      Returns Path2D

    • A copy with overlapping segments within the path removed, as though the path had been unioned with itself.

      "evenodd" keeps the overlap regions as holes while still removing the edge crossings.

      🧪 Not in the HTML Canvas standard.

      Parameters

      • Optionalrule: "evenodd" | "nonzero"

      Returns Path2D

    • A copy with its points transformed. The original is unmodified.

      Takes a DOMMatrix, a CSS transform string such as "rotate(20deg)", or the six numbers of a 2D matrix.

      🧪 Not in the HTML Canvas standard.

      Parameters

      Returns Path2D

    • As above, with the six components of a 2D matrix given directly, in the order a, b, c, d, e, f.

      🧪 Not in the HTML Canvas standard.

      Parameters

      • a: number
      • b: number
      • c: number
      • d: number
      • e: number
      • f: number

      Returns Path2D

    • The portion of the path between two points along its contour, each given as a fraction from 0 to 1.

      inverted takes everything except that span instead. With one number, a positive value trims from the start and a negative one trims to the end.

      🧪 Not in the HTML Canvas standard.

      Parameters

      • start: number
      • end: number
      • Optionalinverted: boolean

      Returns Path2D

    • As above, with one end named instead of two: a positive start trims from the beginning of the contour, a negative one trims back from its end.

      🧪 Not in the HTML Canvas standard.

      Parameters

      • start: number
      • Optionalinverted: boolean

      Returns Path2D

    • A copy that covers the same area under the "nonzero" rule as this path does under "evenodd".

      Useful when one path holds several overlapping contours, where the filled shape otherwise depends on their nesting and direction.

      🧪 Not in the HTML Canvas standard.

      Returns Path2D