/twodee

2d primitives: circle, rectangle, obb, triangle, polygon, ray, intersections

Primary LanguageJavaScript

#twodee

Two dimensional geometry manipulation

##Install

$ npm install twodee

##Use

###Creating a simple Triangle

twodee uses xyzw for vector manipulation.

$ npm install xyzw
import Vector2 from 'xyzw/source/Vector2';
import Triangle2 from 'twodee/source/Triangle2';

To get es5 safe versions of all files replace /source with /es5

###Creating a triangle

const triangleA = new Triangle2(
	new Vector2([0.0, 0.0]),
	new Vector2([0.0, 1.0]),
	new Vector2([1.0, 0.0])
);

const point0 = triangleA.p0;
const point1 = triangleA.p1;
const point2 = triangleA.p2;
const orientation = triangleA.orientation;
const centroid = triangleA.centroid;
const circumcenter = triangleA.circumcenter
const area = triangleA.area;

####Factory constructors

All primitives come with convenient factory constructors:

const center = new Vector2([0.0, 0.0]);
const radius = 1.0;
const rotation = Math.PI;

const triangleB = Triangle2.Equilateral(center, radius, rotation);

####Collision testing

Triangles can test for collisions with points, segments and other triangles:

const intersections = [];
const collision = triangleA.intersects(triangleB, intersections);

All intersection tests have static versions that do not require actual objects:

const intersections = [];
const collision = Triangle2.intersect(
	triangleA.p0, triangleA.p1, triangleA.p2,
	triangleB.p0, triangleB.p1, triangleB.p2,
	intersections
)

###Creating a ray

import Ray2 from 'twodee/source/Ray2';

const ray = new Ray2(new Vector2([0.0, 0.0]), new Vector2([0.0, 1.0]));

const origin = ray.origin;
const orientation = ray.orientation;

Rays can test for intersections with line segments and other rays. All line intersection tests guarantee valid results for parallel and co-linear entities.

const point0 = new Vector2([4.0, -0.5]);
const point1 = new Vector2([4.0, 0.5]);
const intersection = new Vector2();
const collision = ray.intersectsSegment(point0, point1, intersection);

###Creating a Bounding Box Rectangle

import Vector2 from 'xyzw/source/Vector2';
import Rectangle2 from 'twodee/source/Rectangle2';


const box = Rectangle2.AABB([
	new Vector2([0.0, 0.0]),
	new Vector2([0.0, 1.0]),
	new Vector2([1.0, 0.0])
]);

const transform = box.transform;
const extend = box.extend;
const center = box.center;
const width = box.width;
const height = box.height;
const aspect = box.aspect;
const area = box.area;

Rectangles can test for collisions with points, segments and other rectangles

###Creating a segmented line

import PolyLine2 from 'twodee/source/PolyLine2';


const lineA = PolyLine2.Rectangle2(box);

const points = lineA.point;
const segments = lineA.segments;
const closed = lineA.closed;

Segmented lines can test for collisions with points, line segments and other segment lines. All line intersection test guarantee valid results for parallel and co-linear entities.

const lineB = PolyLine2.ConvexHullGraham([
	new Vector2([0.0, 0.0]),
	new Vector2([0.0, 1.0]),
	new Vector2([1.0, 0.0]),
	new Vector2([1.0, 1.0])
]);

const intersections = [];
const collision = lineB.intersects(lineA, intersections);

###Creating a Polygon

import Polygon2 from 'twodee/source/Polygon2';

const poly = new Polygon2();

const v0 = poly.createVertex(new Vector2([0.0, 0.0]));
const v1 = poly.createVertex(new Vector2([0.0, 1.0]));
const v2 = poly.createVertex(new Vector2([1.0, 0.0]));
const v3 = poly.createVertex(new Vector2([1.0, 1.0]));

const f0 = poly.createFace(v0, v1, v2);
const f1 = poly.createFace(v1, v3, v2);

const center = poly.centroid;
const area = poly.area;

const vertices = poly.vertex;
const edges = poly.edge;
const faces = poly.face;
const point = poly.point;
const drawList = poly.indexList;

Polygons expose a rich api for geometry manipulations:

const [e0] = poly.edgeOfVertex(v1, [v2]);
const e1 = poly.turnEdge(e0);

const [f2, f3] = poly.faceOfEdge(e1);
const [f4, f5, f6] = poly.subdivideFace(f3);

Polygons can test for collisions with Points and other Polygons

const polyB = Polygon2.PolyLine2(lineB);

const intersections = [];
const collision = poly.intersects(polyB);

Table of Contents

Circle2

Circle geometry

constructor

Creates a new instance

Parameters

  • p Vector2 The center point
  • r number The radius

center

The center point

radius

The radius

define

Redefines the instance

Parameters

  • p Vector2 The center point
  • r Vector2 The radius

Returns Circle2

area

The area

intersectsPoint

Returns true if p intersects the instance, false otherwise

Parameters

  • p Vector2 The point

Returns boolean

intersects

Returns true if circle intersects the instance, false otherwise

Parameters

  • circle Circle2 The circle
  • points Array<Vector2>? The intersection points

Returns boolean

transformationOf

The transformation of circle

Parameters

  • circle Circle2 The source
  • transform Matrix3 The transform

Returns Circle2

copyOf

The copy of circle

Parameters

Returns Circle2

transformation

The transformation of the instance

Parameters

  • transform Matrix3 The transform

Returns Circle2

toString

Returns a string representation of the instance

Parameters

  • digits int The decimal places

Returns string

Define

Returns an instance representing p and r

Parameters

  • p Vector2 The center point
  • r number The radius
  • target Circle2? The target instance

Returns Circle2

Area

Returns an instance at p with area a

Parameters

  • p Vector2 The center point
  • a number The area
  • target Circle2? The target instance

Returns Circle2

Copy

Returns a copy of circle

Parameters

Returns Circle2

intersectPoint

Returns true if q intersects circle (p,r), false otherwise

Parameters

  • p Vector2 The circle center
  • r number The circle radius
  • q Vector2 The point

Returns boolean

intersect

Returns true if circle (p0,r0) intersects circle (p1,r1), false otherwise

Parameters

  • p0 Vector2 The first circle center
  • r0 number The first circle radius
  • p1 Vector2 The second circle center
  • r1 number The second circle radius
  • points Array<Vector2>? The intersection points

Returns boolean

isEQ

Returns true if a and b are equal (a == b), false otherwise

Parameters

Returns boolean

CubicBezier2

Cubic Bezier Curve

constructor

Creates an instance

Parameters

  • p0 Vector2
  • p1 Vector2
  • p2 Vector2
  • p3 Vector2

define

Defines the instance

Parameters

  • p0 Vector2
  • p1 Vector2
  • p2 Vector2
  • p3 Vector2

Returns CubicBezier2

getPointOfT

Returns the point at t

Parameters

Returns Vector2

copyOf

The copy of source

Parameters

Returns CubicBezier2

Copy

Returns a copy of source

Parameters

Returns CubicBezier2

getPointOfT

Return the point at t of cubic bezier curve p0,p1,p2,p3

Parameters

  • p0 Vector2
  • p1 Vector2
  • p2 Vector2
  • p3 Vector2
  • t Number The position

Returns Vector2

split

Returns the partial segments of source split at t

Parameters

Returns Array<CubicBezier2>

isEQ

Returns true if a and b represent the same curve, false otherwise

Parameters

Returns boolean

Polygon2

Planar triangle mesh

constructor

Creates a new instance

define

Redefines the instance

Returns Polygon2

face

The dereferenced defined face indices of the instance

edge

The dereferenced defined edge indices of the instance

vertex

The dereferenced defined vertex indices of the instance

point

The deferenced list of points of the instance

indexList

The dereferenced display list of vertex indices of the instance

centroid

The dereferenced centroid point

area

The area sum((1/2)|AB x AC|)

hasFace

Returns true if face is a defined face index, false otherwise

Parameters

  • face int The face index

Returns boolean

edgeOfFace

Returns a ccw-ordered Array of edge indices associated with face

Parameters

  • face int The face index
  • vertex int? The first ccw vertex index of the first edge index

Returns Array<int>

vertexOfFace

Returns a ccw-ordered Array of vertex indices associated with face

Parameters

  • face int The face index
  • edge int? The edge index of the first ccw vertex index

Returns Array<int>

pointOfFace

Returns the ccw ordered points associated with face Proxies Polygon2#vertexOfFace

Parameters

  • face int The face index
  • edge int? The edge index of the first ccw vertex index

Returns Array<Vector2>

hasEdge

Returns true if edge is a defined edge index, false otherwise

Parameters

  • edge int The edge index

Returns boolean

faceOfEdge

Returns a front,back sorted Array of face indices associated with edge

Parameters

  • edge int The edge index
  • face int? The second face index

Returns Array<int>

vertexOfEdge

Returns a from,to sorted Array of vertex indices associated with edge

Parameters

  • edge int The edge index
  • vertex int? The second vertex index

Returns Array<int>

pointOfEdge

Returns the from, to ordered points associated with edge Proxies Polygon2#vertexOfEdge

Parameters

  • edge int The edge
  • vertex int? The second vertex

Returns Array<Vector2>

hasVertex

Returns true if vertex is a defined vertex index, false otherwise

Parameters

  • vertex int The vertex index

Returns boolean

faceOfVertex

Returns an Array of face indices associated with vertex

Parameters

  • vertex int The vertex index
  • constraint Array<int>? Array of complementary face vertex indices

Returns Array<int>

edgeOfVertex

Returns an Array of edge indices associated with vertex

Parameters

  • vertex int The vertex index
  • constraint Array<int>? Array of complementary edge vertex indices

Returns Array<int>

pointOfVertex

Returns the point associated with vertex

Parameters

  • vertex int The vertex

Returns Vector2

hasPoint

Returns true if point is a defined point, false otherwise

Parameters

  • point Vector2 The point

Returns boolean

pointAt

Returns the point at coordinates of point if found, null otherwise

Parameters

  • point Vector2 The point

Returns (Vector2 | null)

vertexOfPoint

Returns the vertex index associated with point

Parameters

  • point Vector2 The point

Returns int

createFace

Returns the index of the face created between vertex0, vertex1 and vertex2

Parameters

  • vertex0 int The first vertex
  • vertex1 int The second vertex
  • vertex2 int The third vertex

Returns int

removeFace

Removes face

Parameters

  • face int The face index

createVertex

Returns the index of the vertex created from p

Parameters

  • p Vector2 The point

Returns int

removeVertex

Removes vertex and all associated faces

Parameters

  • vertex int

clearIsolatedVertices

Removes all isolated vertices

Returns Polygon2

subdivideFace

Returns the subdivision vertex index of the faces created by subdividing face

Parameters

  • face int The source face index
  • point Vector2? The subdivision point

Returns int

splitEdge

Returns the split vertex index of the edges created by splitting edge

Parameters

  • edge int The source edge index
  • point Vector2? The splitting point

Returns int

turnEdge

Returns the index of the edge created by turning edge

Parameters

  • edge int The edge

Returns int

intersectsPoint

Returns true if the instance intersects with q, false otherwise

Parameters

  • q Vector2 The antagonist
  • fuv Array<number>? The face index and barycentric (u,v) coordindates

Returns boolean

intersects

Returns true if the instance intersects with poly, false otherwise

Parameters

Returns boolean

transformationOf

The transformation of poly

Parameters

  • poly Polygon2 The source
  • transform Matrix3 The transform

Returns Polygon2

copyOf

The copy of poly

Parameters

Returns Polygon2

transformation

The transformation of the instance

Parameters

  • transform Matrix3 the transform

Returns Polygon2

toJSON

Returns a json reprentation of the instance

Returns {f: Array<int>, p: Array<float>}

Define

Returns a defined instance

Parameters

Returns Polygon2

JSON

Returns an instance created from json

Parameters

  • json Object The json representation of the instance
  • target Polygon2? The target instance

Returns Polygon2

Points

Returns an instance from points Using TriangleSubdivisionTree

Parameters

  • points Array<Vector2> The points

Returns Polygon2

PolyLine2

Returns an instance from outline Using TriangleSubdivisionTree

Parameters

Returns Polygon2

Copy

Returns a copy of poly

Parameters

Returns Polygon2

PolyLine2

Planar geometric primitive, first order

constructor

Creates a new instance

Parameters

  • point Array<Vector2> The points

point

The points

define

Redefines the instance

Parameters

  • point Array<Vector2>? The points

Returns PolyLine2

segments

The number of segments

closed

true if the first and last points are identical (===), false otherwise

intersectsPoint

Returns true if the instance intersects with point, false otherwise Alias for PolyLine2.intersectsPoint

Parameters

  • point Vector2 The antagonist

Returns boolean

intersects

Returns true if the instance intersects with poly, false otherwise Alias for PolyLine2.intersect

Parameters

  • poly PolyLine2 The antagonist
  • point Array<Vector2>? The intersection points References the intersection points if polylines intersect

Returns boolean

transformationOf

The transformation of poly

Parameters

  • poly PolyLine2 The source
  • transform Matrix3 The transform

Returns PolyLine2

copyOf

The copy of poly

Parameters

Returns PolyLine2

transformation

The transformation of the instance

Parameters

  • transform Matrix3 The transform

Returns PolyLine2

toString

Returns a string representation of the instance

Returns string

ConvexHullGraham

Returns a new instance from the convex hull of point Using graham scanning

Parameters

  • point Array<Vector2> The points
  • target PolyLine2? The target instance

Returns PolyLine2

Rectangle2

Returns a new instance from rectangle

Parameters

Returns PolyLine2

Transformation

Returns an instance representing the transformation of poly

Parameters

  • poly PolyLine2 The source
  • transform Matrix3 The transform
  • target PolyLine2? The target instance

Returns Polyline2

Copy

Returns a copy of poly

Parameters

Returns PolyLine2

intersectPoint

Returns true if point q0 intersects poly line pN, false otherwise Using the crossings test (RRp754)

Parameters

  • pN Array<Vector2> The poly line segments
  • q0 Vector2 The point

Returns boolean

intersectSegments

Returns true if segment (p0,p1) intersects segment (q0,q1), false otherwise (RRp781)

Parameters

  • p0 Vector2 The first point of the first segment
  • p1 Vector2 The second point of the first segment
  • q0 Vector2 The first point of the second segment
  • q1 Vector2 The second point of the second segment
  • r Vector2? The intersection point References the intersection point if segments intersect

Returns boolean

intersect

Returns true if pN intersects qN, false otherwise

Parameters

  • pN Array<Vector2> The first array of points
  • qN Array<Vector2> The second array of points
  • r Array<Vector2>? The intersection point(s) References the intersection point(s) if primitives intersect

Returns boolean

Ray2

Planar Ray

constructor

Creates a new instance

Parameters

  • origin Vector2 The ray origin
  • orientation Vector2 The orientation

origin

The origin

orientation

The orientation

define

Redefines the instance

Parameters

  • origin Vector2 The ray origin
  • orientation Vector2 The orientation

Returns Ray2

intersectsSegment

Returns true if the instance intersects line segment (p0, p1), false otherwise

Parameters

  • p0 Vector2 The first point of the segment
  • p1 Vector2 The second point of the segment
  • r Vector2? The intersection point

Returns boolean

intersects

Returns true if the instance intersects ray, false otherwise

Parameters

  • ray Ray2 The antagonist
  • r Vector2? The intersection point

Returns boolean

copyOf

The copy of ray

Parameters

  • ray Ray2 The source

Returns Ray2

toString

Returns a string representation of the instance

Parameters

  • digits int? The decimal digits (optional, default 3)

Returns string

Define

Returns a defined instance

Parameters

  • origin Vector2 The ray origin
  • orientation Vector2 The ray orientation
  • target Ray2? The target instance

Returns Ray2

intersectSegment

Returns true if ray (pa,oa) intersects line segment (q0,q1), false otherwise

Parameters

  • pa Vector2 The ray origin
  • oa Vector2 The ray orientation
  • q0 Vector2 The first point of the line segment
  • q1 Vector2 The second point of the line segment
  • r Vector2? The intersection point

Returns boolean

intersect

Returns true if ray (pa,oa) and ray (pb,ob) intersect, false otherwise

Parameters

  • pa Vector2 The origin of the first ray
  • oa Vector2 The orientation of the first ray
  • pb Vector2 The origin of the second ray
  • ob Vector2 The orientation of the second ray
  • r Vector2? The intersection point

Returns boolean

isEQ

Returns true if a and b represent the same ray (a == b), false otherwise

Parameters

  • a Ray2 The protagonist
  • b Ray2 The antagonist

Returns boolean

Rectangle2

Planar geometric primitive, second order

isEQ

Returns true if a and b represent the same rectangle, false otherwise

Parameters

Returns boolean

constructor

Creates a new instance

Parameters

  • transform Matrix3? The transform
  • extend Vector2? The extend

transform

The transform

extend

The half-dimensions

define

Redefines the instance

Parameters

  • transform Matrix3? The transform
  • extend Vector2? The half-dimensions

Returns Rectangle2

center

The dereferenced center point

width

The width Alias of Rectangle2#extend

height

The height Alias of Rectangle#extend

aspect

The aspect (w/h)

area

The area (w*h)

intersectsPoint

Returns true if the instance intersects with p, false otherwise Alias for Rectangle2.intersectPoint

Parameters

  • p Vector2 The antagonist

Returns boolean

intersectsSegment

Returns true if the instance intersects with segment (p0,p1), false otherwise Alias of Polyline2.intersect

Parameters

  • p0 Vector2 The first point of the antagonist
  • p1 Vector2 The second point of the antagonist
  • r Array<Vector2>? The intersection points References the intersection points if instances intersect

Returns boolean

intersects

Returns true if the instance intersects with rectangle, false otherwise Alias of Rectangle2.intersect

Parameters

  • rectangle Rectangle2 The antagonist
  • point Rectangle2? The intersection point(s) References the intersection point(s) if obbs intersect

Returns boolean

transformationOf

The transformation of rectangle

Parameters

  • rectangle Rectangle2 The source
  • transform Matrix3 The transform

Returns Rectangle2

copyOf

The copy of rectangle

Parameters

Returns Rectangle2

transformation

The transformation of the instance

Parameters

  • transform Matrix3 The transform

Returns Rectangle2

toString

Returns a string representation of the instance

Returns string

Define

Defines an instance

Parameters

  • transform Matrix3 The transform
  • extend Vector2 The extend
  • target Rectangle2? The target instance

Returns Rectangle2

Box

Returns a new instance from w, h

Parameters

AABB

Returns a new instance from point

Parameters

Returns Rectangle2

Transformation

Returns an instance representing the transformation of rectangle

Parameters

  • rectangle Rectangle2 The source
  • transform Matrix3 The transform
  • target Rectangle2? The target instance

Returns Rectangle2

Copy

Returns a copy of rectangle

Parameters

Returns Rectangle2

intersectPoint

Returns true if obb (tA,eA) intersects with point (p), false otherwise

Parameters

  • tA Matrix3 The transform of the obb
  • eA Vector2 The half-dimensions of the obb
  • p Vector2 The point

Returns boolean

intersectTriangle

Returns true if obb (t, e) intersects with triangle(p0,p1,p2)

Parameters

  • t Matrix3 The obb transform
  • e Vector2 The obb extend
  • p0 Vector2 The first point of the triangle
  • p1 Vector2 The second point of the triangle
  • p2 Vector2 The third point of the triangle

Returns boolean

intersect

Returns true if obb (tA,eA) intersects with obb (tB,eB), false otherwise OBB intersection test using the seperating axis method by Gottschalk et. al. [RRp767]

Parameters

  • tA Matrix3 The transform of the first obb
  • eA Vector2 The half-dimensions of the first obb
  • tB Matrix3 The transform of the second obb
  • eB Vector2 The half-dimensions of the second obb

Returns boolean

CW

The clockwise orientation sign

Type: number

CCW

The counter-clockwise orientation sign

DEGENERATE

The degenerate orientation sign

Type: number

Triangle2

Planar geometric primitive, second order

constructor

Creates a new instance

Parameters

  • p0 Vector2? The first point
  • p1 Vector2? The second point
  • p2 Vector2? The third point

p0

The first point

p1

The second point

p2

The third point

define

Redefines the instance

Parameters

  • p0 Vector2? The first point
  • p1 Vector2? The second point
  • p2 Vector2? The third point

Returns Triangle2

orientation

CW (1) if the instance is cw rotated, CCW (-1) if the instance is ccw rotated, DEGENERATE (0) if the instance is degenerate

centroid

The dereferenced centroid point

circumcenter

The dereferenced center of the enclosing circle

area

The area (1/2)|AB x AC|

intersectsPoint

Returns true if the instance intersects with point (q), false otherwise Alias of Triangle2.intersectPoint

Parameters

  • q Vector2 The point
  • uv Array<number>? Array holding the barycentric (u,v) coordinates References the barycentric intersection coordinates(u,v) if primitives intersect

Returns boolean

intersectsSegment

Returns true if the instance intersects with segment (q0,q1), false otherwise Alias of Triangle2.intersectSegment

Parameters

  • q0 Vector2 The first point of the segment
  • q1 Vector2 The second point of the segment
  • r Array<Vector2>? The intersection point(s) References the intersection points if instances intersect

Returns boolean

intersects

Returns true if the instance intersects with triangle, false otherwise Alias of Triangle2.intersect

Parameters

  • triangle Triangle2 The opposing Triangle
  • point Array<Vector2>? The intersection point(s) References the intersection points if instances intersect

Returns boolean

transformationOf

The transformation of triangle

Parameters

  • triangle Triangle2 The source
  • transform Matrix3 The transform

Returns Triangle2

copyOf

The copy of triangle

Parameters

Returns Triangle2

transformation

The transformation of the instance

Parameters

  • transform Matrix3 The transform

Returns Triangle2

toString

Returns a string representation of the instance

Parameters

  • digits int? The decimal places (optional, default 3)

Returns string

Equilateral

Returns an instance representing the equilateral triangle circumscribed|inscribed by r, rotated by rad

Parameters

  • p Vector2 The centroid point
  • r number The distance between centroid and point
  • rad number? The angle (optional, default 0.0)
  • f boolean? The inscription factor (optional, default 0.0)
  • target Triangle2? The target instance

Returns Triangle2

Transformation

Returns an instance representing the transformation of triangle

Parameters

  • triangle Triangle2 The source
  • transform Matrix3 The transform
  • target Triangle2? The target instance

Returns Triangle2

Copy

Returns a copy of triangle

Parameters

Returns Triangle2

centroid

Returns a Vector2 representing the centroid of triangle (p0,p1,p2)

Parameters

  • p0 Vector2 The first point
  • p1 Vector2 The second point
  • p2 Vector2 The third point

Returns Vector2

circumcenter

Returns a Vector2 representing the circumcenter of triangle (p0,p1,p2)

Parameters

  • p0 Vector2 The first point
  • p1 Vector2 The second point
  • p2 Vector2 The third point

Returns Vector2

area

Returns the area (1/2)|AB x AC| of triangle (p0,p1,p2)

Parameters

  • p0 Vector2 The first point
  • p1 Vector2 The second point
  • p2 Vector2 The third point

Returns number

intersectPointCircumcircle

Returns true if the circumcircle of ccw triangle (p0,p1,p2) intersects with point (q0), false otherwise

Parameters

  • p0 Vector2 The first point of the triangle
  • p1 Vector2 The second point of the triangle
  • p2 Vector2 The third point of the triangle
  • q0 Vector2 The antagonist

Returns boolean

intersectPoint

Returns true if triangle (p0,p1,p2) intersects with point (q0), false otherwise

Parameters

  • p0 Vector2 The first point of the triangle
  • p1 Vector2 The second point of the triangle
  • p2 Vector2 The third point of the triangle
  • q Vector2 The point
  • uv Array<number>? Array holding the barycentric (u,v) coordinates References the barycentric intersection coordinates(u,v) if primitives intersect

Returns boolean

intersectSegment

Returns true if triangle (p0,p1,p2) intersects with segment (q0,q1), false otherwise

Parameters

  • p0 Vector2 The first point of the triangle
  • p1 Vector2 The second point of the triangle
  • p2 Vector2 The third point of the triangle
  • q0 Vector2 The first point of the segment
  • q1 Vector2 The second point of the segment
  • r Array<Vector2>? The intersection point(s) References the intersection points if primitives intersect

Returns boolean

intersect

Returns true if triangle (p0,p1,p2) intersects with triangle(q0,q1,q2), false otherwise

Parameters

  • p0 Vector2 The first point of the first triangle
  • p1 Vector2 The second point of the first triangle
  • p2 Vector2 The third point of the first triangle
  • q0 Vector2 The first point of the second triangle
  • q1 Vector2 The second point of the second triangle
  • q2 Vector2 The third point of the second triangle
  • r Array<Vector2>? The intersection point(s) References the intersection point(s) if triangles intersect

Returns boolean

TriangleSubdivisionTree

Delaunay triangulation subdivision tree

constructor

Creates a new instance

Parameters

poly

Returns a dereferenced polygon representing the subdivision state

Returns Polygon2

intersectsPoint

Returns the intersection face and barycentric coordinate if q intersects with the subdivision tree, null otherwise

Parameters

  • q Vector2 The point

Returns (null | Object)

testEdge

Returns true if edge is the optimal edge for the quad of face0 and the face opposite of edge, false otherwise

Parameters

  • face0 int The face index of the first face
  • edge int The edge index of the edge

Returns boolean

addPoint

Adds a point to the subdivision mesh

Parameters

  • point Vector2 The point

addPoints

Adds points to the subdivision mesh

Parameters

  • points Array<Vector2> The points

intersectOutline

Intersects outline with the subdivision mesh

Parameters