polygonInside
Checks if one polygon is inside another polygon.
Basic example
Section titled “Basic example”True when every point of the first polygon lies inside the second and none of their edges cross. The layout uses this to decide whether a label’s box fits within a shape.
import {polygonInside} from "@d3plus/math";
const polyA = [
[70, 60],
[180, 70],
[170, 140],
[80, 130],
];
const polyB = [
[20, 20],
[240, 30],
[230, 180],
[30, 170],
];
polygonInside(polyA, polyB);
Overlapping
Section titled “Overlapping”A polygon that pokes out of the container is not inside it, even though most of its area overlaps.
import {polygonInside} from "@d3plus/math";
const polyA = [
[150, 60],
[300, 70],
[290, 140],
[160, 130],
];
const polyB = [
[20, 20],
[240, 30],
[230, 180],
[30, 170],
];
polygonInside(polyA, polyB);
Parameters
import {polygonInside} from "@d3plus/math";