Install

npm install github:MarquisNecrosis/SVGArea#main

Code Example

You can use this page to try the algorithms.

This algorithm computes the area of merged polygons and can also create the merged polygon.

import { polygonIntersectionInSvg } from "svg-area-intersection";
polygonIntersectionInSvg(svgID, {show, redraw, color, opacity})

Where parameters are:

  • svgID — ID of the SVG canvas
  • show — boolean to show the merged polygons
  • redraw — boolean to redraw existing merged polygons
  • color — hex color for merged polygons
  • opacity — 0–1 opacity for merged polygons

This algorithm simply computes all pixels inside polygons. It's raw and inefficient.

import { lazyStupidAreaCalculation } from "svg-area-intersection/heuristic";
lazyStupidAreaCalculation(svgID)

Where parameters are:

  • svgID — ID of the SVG canvas
import { areaInSvgWithIntersection } from "svg-area-intersection/heuristic";
areaInSvgWithIntersection(svgID, numberOfRandomPoints)

Where parameters are:

  • svgID — ID of the SVG canvas
  • numberOfRandomPoints — Number of random points to use. More points = more accurate, but slower