Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with Line & Polygon #31

Open
MentalGear opened this issue Feb 23, 2023 · 0 comments
Open

Usage with Line & Polygon #31

MentalGear opened this issue Feb 23, 2023 · 0 comments

Comments

@MentalGear
Copy link

First: thanks for this handy and super speedy library!

I'd appreciate an example in the docs on how to do clipping of a Line and a Polygone as I'm not that knowledgeable in vector graphics (yet).

Specifically, I'd like like to clip a Line (open path) from a user-defined Polygon (rectangle, but can also be more complex polygon with holes).

Here's what I tried, and I would much appreciate some hints on how to do this correctly.

import * as clipperLib from "js-angusj-clipper"; // es6 / typescript

async function mainAsync() {
  // create an instance of the library (usually only do this once in your app)
  const clipper = await clipperLib.loadNativeClipperLibInstanceAsync(
    // let it autodetect which one to use, but also available WasmOnly and AsmJsOnly
    clipperLib.NativeClipperLibRequestedFormat.WasmWithAsmJsFallback
  );

  const line = [
    { x: 10, y: 10 },
    { x: 50, y: 50 },
    { x: 100, y: 100 }
  ];


  const rect = [
    { x: 25, y: 25 },
    { x: 25, y: 75 },
    { x: 75, y: 75 },
    { x: 75, y: 25 }
  ];


  const polyResult = clipper.clipToPaths({
    clipType: clipperLib.ClipType.Union,

    subjectInputs: [{ data: rect, closed: true }],

    clipInputs: [{ data: line, closed: false }],

    subjectFillType: clipperLib.PolyFillType.EvenOdd
  });

  console.log("polyResult", polyResult);
}

mainAsync();
@MentalGear MentalGear changed the title Usage with Line & Polygone Usage with Line & Polygon Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant