Geometry
Constructors
Geometry is an abstract type and cannot be instantiated its own.
Methods
Finds intersections between all geometries in the array, including self-intersections.
geometriesGeometry[]An array of geometries to intersect
areaOfInterestIf supplied, only intersection results inside this bounding box will be returned. This can save a lot of computation if you only need to find intersections within a small area.
Returns An array of intersections
Finds intersections between two sets of geometries. This won't find self-intersections or intersections within the two sets.
geometries1Geometry[]The first geometry array to intersect
geometries2Geometry[]The second geometry array to intersect
areaOfInterestIf supplied, only intersection results inside this bounding box will be returned. This can save a lot of computation if you only need to find intersections within a small area.
Returns An array of intersections
Finds overlaps between all geometries in the array.
geometriesGeometry[]An array of geometries to find overlaps between.
areaOfInterestIf supplied, input geometry will be filtered so that only parts that intersect this bounding box will be tested. This can save a lot of time if only need to find overlaps within a small area.
tolerancenumberThe maximum distance apart two segments can be to be considered overlapping.
Returns An array of overlaps
Finds overlaps between two sets of geometry. This won't find overlaps within the two sets.
geometries1Geometry[]The first set of geometries
geometries2Geometry[]The second set of geometries
areaOfInterestIf supplied, input geometry will be filtered so that only parts that intersect this bounding box will be tested. This can save a lot of time if only need to find overlaps within a small area.
tolerancenumberThe maximum distance apart two segments can be to be considered overlapping.
Returns As array of overlaps between the two sets of geometry
geomunknownReturns true if geom is valid geometry
Returns true if this geometry is valid, or false otherwise.
Clone is useful when you need to make a change to geometry without changing the original.
const transformedPath = path.clone().transform({ rotation: 45 });
Returns A deep copy of this geometry
pointThe target point
areaOfInterestIf supplied, only results inside this bounding box
will be returned. This can save a lot of computation if you only need to
find closest points within a small area. Typically areaOfInterest is
centered on point, but this isn't required.
Returns The closest point to point that lies on this geometry, or
undefined if no point is found.
Spatially transforms this geometry by an affine transformation matrix.
Affine matrices can represent any 2-dimensional transformation that keeps lines parallel.
affineMatrixSpatially transforms this geometry by an affine transformation matrix, excluding translation. Only rotation, scale, and skew transformations will be applied.
affineMatrixTransforms this geometry.
A transform can optionally specify any of position, rotation, scale,
skew and origin.
origin defines the center (in pre-transform coordinates) of the
transformation for rotation, scale and skew.
// Simple translation
geometry.translate({
position: Vec(1, 0),
});
// Rotation and scale
geometry.transform({
rotation: 45,
scale: 2,
});
// Complicated transform
geometry.transform({
position: Vec(1, 1),
rotation: 180,
scale: Vec(2, 1),
skew: 45,
origin: Vec(-0.5, 0.5),
};
transformReverses this geometry.
Returns the smallest axis-aligned bounding box that contains this geometry.
The loose bounding box may not be the smallest possible, but it's usually cheaper to compute. Use this when the exact bounding box isn't required.
Returns an axis-aligned bounding box that contains this geometry.
Geometry is contained by a bounding box if no part of it lies beyond it's minimum and maximum.
boxGeometry intersects a bounding box if part of the geometry crosses the boundary between the inside and outside of the box.
boxGeometry is overlapped by a bounding box if a point can be chosen that is indside both the geometry and the box.
Geometry is overlapped by a bounding box if it's contained inside, or intersected by it.
boxgeometriesGeometry[]An array of geometries to intersect with.
areaOfInterestIf supplied, only intersection results inside this bounding box will be returned. This can save a lot of computation if you only need to find intersections within a small area.
Returns An array of intersections between this geometry and geometries
geometriesGeometry[]An array of geometries to find overlaps with.
areaOfInterestIf supplied, input geometry will be filtered so that only parts that intersect this bounding box will be tested. This can save a lot of time if only need to find overlaps within a small area.
tolerancenumberThe maximum distance apart two segments can be to be considered overlapping.
Returns An array of overlaps between this geometry and geometries
targetGeometryThe geometry to move toward.
directionThe direction to move in. This should point towards the target geometry, otherwise no intersection may be found.
optionsReturns approximately the smallest distance to move until this geometry intersects the target geometry.
If minOverlap is specified, the distance to move until the geometry
overlaps by some minimum width will be returned instead.
Returns undefined if no intersection is found.
The base class for anything that is representable on the canvas. Geometry types must support any affine transformation.