
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@flatten-js/boolean-op
Advanced tools
@flatten-js/boolean-op is a javascript library performing fast and reliable boolean operations on polygons. It provides binary boolean operations:
Polygon is actually a multi-polygon which may be comprised from a number of faces. The orientation of faces (clockwise or counterclockwise) is matter, because algorithm implemented in the way that it never changes an original direction of the edge. For the boolean operation to be performed correctly, faces have to fit the following rules:
Boolean operation algorithm does not check that polygon fits these rules, this is on the responsibility of the caller.
The result of boolean operation is also a polygon. Note, that the resulted polygon may be empty, for example as the result of the intersection between two disjoint polygons.
Follow me on Twitter @alex_bol_
Install this package together with @flatten-js/core package which provide class Polygon:
npm install @flatten-js/boolean-op @flatten-js/core --save
Then require package in your module, create two polygons using flatten-js library and call one of the methods:
import {intersect} from "@flatten-js/boolean-op"
import {Polygon, point} from "@flatten-js/core"
let polygon1 = new Polygon();
polygon1.addFace([point(200,10), point(100, 300), point(400, 150), point(250, 10)]);
let polygon2 = new Polygon();
polygon2.addFace([point(450, 10), point(0, 150), point(300,300), point(600, 300)]);
let polygon_res = intersect(polygon1, polygon2);
Algorithm implements the version of Kevin Weiler and Peter Atherton clipping algorithm, described in the article Hidden Surface Removal Using Polygon Area Sorting see https://www.cs.drexel.edu/~david/Classes/CS430/HWs/p214-weiler.pdf
In pseudocode, it may be described as below:
Remember that algorithm relies on the direction of the edges. It can find continuation of the interrupted chain only if edge from the second polygon is an precise continuation of the edge from the first one. That is why faces that have same meaning (island or hole) should have same orientation is both polygons.
Documentation may be found here https://alexbol99.github.io/flatten-boolean-op/index.html
FAQs
Boolean operations on polygons
The npm package @flatten-js/boolean-op receives a total of 99 weekly downloads. As such, @flatten-js/boolean-op popularity was classified as not popular.
We found that @flatten-js/boolean-op demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.