@rtorcato/js-common / geometry
geometry
Functions
distance2D()
distance2D(
x1,y1,x2,y2):number
Defined in: geometry/index.ts:9
Calculates the distance between two points in 2D space.
Parameters
x1
number
X coordinate of first point.
y1
number
Y coordinate of first point.
x2
number
X coordinate of second point.
y2
number
Y coordinate of second point.
Returns
number
The distance.
midpoint2D()
midpoint2D(
x1,y1,x2,y2): [number,number]
Defined in: geometry/index.ts:21
Calculates the midpoint between two points in 2D space.
Parameters
x1
number
X coordinate of first point.
y1
number
Y coordinate of first point.
x2
number
X coordinate of second point.
y2
number
Y coordinate of second point.
Returns
[number, number]
The midpoint as [x, y].
angle2D()
angle2D(
x1,y1,x2,y2):number
Defined in: geometry/index.ts:33
Calculates the angle (in radians) between two points in 2D space.
Parameters
x1
number
X coordinate of first point.
y1
number
Y coordinate of first point.
x2
number
X coordinate of second point.
y2
number
Y coordinate of second point.
Returns
number
The angle in radians.
pointInRect()
pointInRect(
px,py,rx,ry,rw,rh):boolean
Defined in: geometry/index.ts:47
Checks if a point is inside a rectangle.
Parameters
px
number
X coordinate of the point.
py
number
Y coordinate of the point.
rx
number
X coordinate of the rectangle's top-left corner.
ry
number
Y coordinate of the rectangle's top-left corner.
rw
number
Rectangle width.
rh
number
Rectangle height.
Returns
boolean
True if inside, false otherwise.
rectsOverlap()
rectsOverlap(
ax,ay,aw,ah,bx,by,bw,bh):boolean
Defined in: geometry/index.ts:70
Checks if two rectangles overlap.
Parameters
ax
number
X of rect A.
ay
number
Y of rect A.
aw
number
Width of rect A.
ah
number
Height of rect A.
bx
number
X of rect B.
by
number
Y of rect B.
bw
number
Width of rect B.
bh
number
Height of rect B.
Returns
boolean
True if rectangles overlap.
polygonArea()
polygonArea(
points):number
Defined in: geometry/index.ts:88
Calculates the area of a polygon given its vertices (Shoelace formula).
Parameters
points
[number, number][]
Array of [x, y] pairs.
Returns
number
The area (positive value).