Namespace: Cartesia
File Manifest
File Manifest| File | Language | Author(s) | Copyright |
|---|
| angle.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
| arc.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
| bezier.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
| cartesia.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
| catenary.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
| chainwrap.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
| circle.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
| hexCoordinateSystem.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
| hexGeometry.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
| line.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
| point.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
| polygon.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
Overview
The Cartesia namespace encapsulates all definitions related to the family of Cartesia classes.
The Cartesia library is a library which handles 2d geometry calculations with some functions operating on individual numbers and some functionality encapsulated within object classes.
Constant Registry
Item
Attributes
Cartesia.CCW
<read-only>
Cartesia.CCWCCW
<read-only>
Cartesia.CCWCW
<read-only>
Cartesia.CUBIC
<read-only>
Cartesia.CW
<read-only>
Cartesia.CWCCW
<read-only>
Cartesia.CWCW
<read-only>
Cartesia.DEGREES
<read-only>
Cartesia.INFINITE
<read-only>
Cartesia.INSIDE
<read-only>
Cartesia.LINE_INFINITE
<read-only>
Cartesia.LINE_SEGMENT
<read-only>
Cartesia.LINE_VECTOR
<read-only>
Cartesia.OUTSIDE
<read-only>
Cartesia.QUADRATIC
<read-only>
Cartesia.RAD0
<read-only>
Cartesia.RAD180
<read-only>
Cartesia.RAD270
<read-only>
Cartesia.RAD360
<read-only>
Cartesia.RAD45
<read-only>
Cartesia.RAD90
<read-only>
Cartesia.RADIANS
<read-only>
Cartesia.SEC0
<read-only>
Cartesia.SEC180
<read-only>
Cartesia.SEC270
<read-only>
Cartesia.SEC360
<read-only>
Cartesia.SEC45
<read-only>
Cartesia.SEC90
<read-only>
Cartesia.SECTONS
<read-only>
Cartesia.TALL
<read-only>
Cartesia.WIDE
<read-only>
Function Registry
Item
Attributes
Cartesia.bearingFrom(ax, ay, bx, by) → Number
-
Cartesia.bezierCurveLength(bezier) → Number
-
Cartesia.bezierGetEPoints(intervals, bezier, callback) → Array<Number>
-
Cartesia.bezierGetTPoints(intervals, bezier, callback) → Array<Number>
-
Cartesia.bezierHullLength(bezier) → Number
-
Cartesia.chordAngle(radius, length) → Number
-
Cartesia.chordLength(radius, angle) → Number
-
Cartesia.clampAngle(radians) → Number
-
Cartesia.clampAngleToPI(radians) → Number
-
Cartesia.cp2pt(cp) → Cartesia.Point
-
Cartesia.cpv2pts(cpv) → Array<Cartesia.Point> or Null
-
Cartesia.d2angle(d) → Cartesia.Angle
-
Cartesia.d2r(r) → Number
-
Cartesia.d2s(r) → Number
-
Cartesia.dabFrom(ax, ay, bx, by) → Array<Number>
-
Cartesia.distanceFrom(ax, ay, bx, by) → Number
-
Cartesia.dxyBearing(dx, dy) → Number
-
Cartesia.dxyDAB(dx, dy) → Array<Number>
-
Cartesia.dxyDistance(dx, dy) → Number
-
Cartesia.ensureAngle(angle) → Cartesia.Angle ⇏ ArgumentError
-
Cartesia.ensurePoint(point) → Cartesia.Point ⇏ ArgumentError
-
Cartesia.ensurePoints(pt) → Array<Cartesia.Point> ⇏ ArgumentError
-
Cartesia.findCircleArcOrigin(r, x1, y1, x2, y2, large_arc_flag, sweep_flag) → Array<Number>
-
Cartesia.getPointCoords(point) → Array<Number> ⇏ ArgumentError
-
Cartesia.getRadians(angle) → Number ⇏ ArgumentError
-
Cartesia.newLineSegment(reference, endpt) → Cartesia.Line
-
Cartesia.newRect(point, width, height) → Cartesia.Polygon
-
Cartesia.newSquare(point, size) → Cartesia.Polygon
-
Cartesia.pointBetween(ax, ay, bx, by, ratio) → Array<Number>
-
Cartesia.pointFrom(x, y, d, b) → Array<Number>
-
Cartesia.r2angle(r) → Cartesia.Angle
-
Cartesia.r2d(r) → Number
-
Cartesia.r2s(r) → Number
-
Cartesia.rotatedPointFrom(ax, ay, bx, by, db) → Array<Number>
-
Cartesia.s2angle(s) → Cartesia.Angle
-
Cartesia.s2d(s) → Number
-
Cartesia.s2r(s) → Number
-
Cartesia.u2r(m, uom) → Number ⇏ ArgumentError
-
Cartesia.xy2pt(x, y) → Cartesia.Point
-
Constant Details
Cartesia.CCW <read-only>
Cartesia.CCWCCW <read-only>
Cartesia.CCWCW <read-only>
Cartesia.CUBIC <read-only>
Cartesia.CW <read-only>
Cartesia.CWCCW <read-only>
Cartesia.CWCW <read-only>
Cartesia.DEGREES <read-only>
Cartesia.INFINITE <read-only>
Cartesia.INSIDE <read-only>
Cartesia.LINE_INFINITE <read-only>
Cartesia.LINE_SEGMENT <read-only>
Cartesia.LINE_VECTOR <read-only>
Cartesia.OUTSIDE <read-only>
Cartesia.QUADRATIC <read-only>
Cartesia.RAD0 <read-only>
Cartesia.RAD180 <read-only>
Cartesia.RAD270 <read-only>
Cartesia.RAD360 <read-only>
Cartesia.RAD45 <read-only>
Cartesia.RAD90 <read-only>
Cartesia.RADIANS <read-only>
Cartesia.SEC0 <read-only>
Cartesia.SEC180 <read-only>
Cartesia.SEC270 <read-only>
Cartesia.SEC360 <read-only>
Cartesia.SEC45 <read-only>
Cartesia.SEC90 <read-only>
Cartesia.SECTONS <read-only>
Cartesia.TALL <read-only>
Cartesia.WIDE <read-only>
Function Details
Cartesia.bearingFrom(ax, ay, bx, by) → Number
This function computes the distance & bearing (angle) between two points given their x,y coordinates.
Parameters:
- ax [Number] — the x-coordinate of the first point
- ay [Number] — the y-coordinate of the first point
- bx [Number] — the x-coordinate of the second point
- by [Number] — the y-coordinate of the second point
Returns:
- [Number] — the bearing between the two points in radians
Cartesia.bezierCurveLength(bezier) → Number
This function returns the length of the bezier curve.
Parameters:
- bezier [Object or Array<Number>] — the bezier curve representation
Returns:
- [Number] — the bezier curve length
Cartesia.bezierGetEPoints(intervals, bezier, callback) → Array<Number>
This function returns a list of evenly-spaced points along a bezier curve or calls a procedure for each point calculated. The callback's parameters are (nth,value) where nth is the index of the point and the value is the coordinate pair of the point.
Parameters:
- intervals [Integer] — the number of points to return
- bezier [Object or Array<Number>] — the bezier curve representation
- callback [Function] — a function to call as each point is calculated <default: null>
Returns:
- [Array<Number>] — the coordinates of each point as a coordinate list, if no callback was specified
Cartesia.bezierGetTPoints(intervals, bezier, callback) → Array<Number>
This function returns a list of timed points along a bezier curve or calls a procedure for each point calculated. The callback's parameters are (nth,value) where nth is the index of the point and the value is the coordinate pair of the point.
Parameters:
- intervals [Integer] — the number of points to return
- bezier [Object or Array<Number>] — the bezier curve representation
- callback [Function] — a function to call as each point is calculated <default: null>
Returns:
- [Array<Number>] — the coordinates of each point as a coordinate list, if no callback was specified
Cartesia.bezierHullLength(bezier) → Number
This function returns the hull length of the bezier curve.
Parameters:
- bezier [Object or Array<Number>] — the bezier curve representation
Returns:
- [Number] — the hull length of the bezier curve
Cartesia.chordAngle(radius, length) → Number
This function calculates the angle of a chord of a given length of a circle of a given radius.
Parameters:
- radius [Number] — the radius of the circle
- length [Number] — the length of the chord
Returns:
- [Number] — the angle of the chord in radians
Cartesia.chordLength(radius, angle) → Number
This function calculates the chord length of a circle of a given radius and angle between two points on the circle.
Parameters:
- radius [Number] — the radius of the circle
- angle [Number] — the angle, in radians, between two points on the circle
Returns:
- [Number] — the length of the chord
Cartesia.clampAngle(radians) → Number
This function ensures a radian angle measurement will be between 0° and 360°.
Parameters:
- radians [Number] — the angle measurement in radians
Returns:
- [Number] — the angle measurement in radians clamped between 0 and 2π
Cartesia.clampAngleToPI(radians) → Number
This function ensures a radian angle measurement will be between -180° and 180°.
Parameters:
- radians [Number] — the angle measurement in radians
Returns:
- [Number] — the angle measurement in radians clamped between -π and π
Cartesia.cp2pt(cp) → Cartesia.Point
This function creates a Cartesia.Point object from a coordinate pair.
Parameters:
- cp [Array<Number>] — the 2-element coordinate pair
Returns:
- [Cartesia.Point] — the Cartesia.Point object
Cartesia.cpv2pts(cpv) → Array<Cartesia.Point> or Null
This function creates an array of Cartesia.Point objects from an array of coordinates.
Parameters:
- cpv [Array<Number>] — the even-sized array of coordinates
Returns:
- [Array<Cartesia.Point> or Null] — the array of Cartesia.Point objects
Cartesia.d2angle(d) → Cartesia.Angle
This function creates a Cartesia.Angle object with a size in degrees.
Parameters:
- d [Number] — the size of the angle in degrees
Returns:
- [Cartesia.Angle] — the Cartesia.Angle object
Cartesia.d2r(r) → Number
This function converts degrees to radians.
Parameters:
- r [Number] — the angle measurement in degrees
Returns:
- [Number] — the angle measurement in radians
Cartesia.d2s(r) → Number
This function converts degrees to sectons.
Parameters:
- r [Number] — the angle measurement in degrees
Returns:
- [Number] — the angle measurement in sectons
Cartesia.dabFrom(ax, ay, bx, by) → Array<Number>
This function computes the bearing (angle) between two points given their x,y coordinates.
Parameters:
- ax [Number] — the x-coordinate of the first point
- ay [Number] — the y-coordinate of the first point
- bx [Number] — the x-coordinate of the second point
- by [Number] — the y-coordinate of the second point
Returns:
- [Array<Number>] — the distance & bearing between the two points, the latter in radians
Cartesia.distanceFrom(ax, ay, bx, by) → Number
This function computes the distance between two points given their x,y coordinates.
Parameters:
- ax [Number] — the x-coordinate of the first point
- ay [Number] — the y-coordinate of the first point
- bx [Number] — the x-coordinate of the second point
- by [Number] — the y-coordinate of the second point
Returns:
- [Number] — the direct distance between two points
Cartesia.dxyBearing(dx, dy) → Number
This function computes the bearing (angle) between two points given their dx and dy distances.
Parameters:
- dx [Number] — the x-axis distance between two points
- dy [Number] — the y-axis distance between two points
Returns:
- [Number] — the bearing between the two points in radians
Cartesia.dxyDAB(dx, dy) → Array<Number>
This function computes the distance & bearing (angle) between two points given their dx and dy distances.
Parameters:
- dx [Number] — the x-axis distance between two points
- dy [Number] — the y-axis distance between two points
Returns:
- [Array<Number>] — the distance & bearing between the two points, the latter in radians
Cartesia.dxyDistance(dx, dy) → Number
This function computes the distance between two points given their dx and dy distances.
Parameters:
- dx [Number] — the x-axis distance between two points
- dy [Number] — the y-axis distance between two points
Returns:
- [Number] — the direct distance between two points
Cartesia.ensureAngle(angle) → Cartesia.Angle ⇏ ArgumentError
This function is used throughout Cartesia to normalize angle representations to Cartesia.Angle object(s).
Parameters:
- angle [Cartesia.Angle or Number] — the angle argument as a Cartesia.Angle object or a measurement in radians
Returns:
- [Cartesia.Angle] — the Cartesia.Angle object to work on
Throws:
- [ArgumentError] — if the angle representation is invalid.
Cartesia.ensurePoint(point) → Cartesia.Point ⇏ ArgumentError
This function is used throughout Cartesia to normalize point representations to Cartesia.Point object(s).
Parameters:
- point [Variadic] — a point representation (see Cartesia.Point documentation)
Returns:
- [Cartesia.Point] — the Cartesia.Point object to work on
Throws:
- [ArgumentError] — if the point representation is invalid.
Cartesia.ensurePoints(pt) → Array<Cartesia.Point> ⇏ ArgumentError
This function is used throughout Cartesia to normalize multiple point representations to Cartesia.Point object(s).
Parameters:
- pt [Array<Cartesia.Point> or Array<Number>] — the points argument as an array of Cartesia.Points or as an even-length array of coordinates
Returns:
- [Array<Cartesia.Point>] — the Cartesia.Point objects to work on
Throws:
- [ArgumentError] — if the points representation is invalid.
Cartesia.findCircleArcOrigin(r, x1, y1, x2, y2, large_arc_flag, sweep_flag) → Array<Number>
This function calculates the origin of a circle given an arc described using endpoints, the circle's radius, whether it's a large arc and its sweep direction.
Parameters:
- r [Number] — the radius of the circle
- x1 [Number] — the x-coordinate of the first end point
- y1 [Number] — the y-coordinate of the first end point
- x2 [Number] — the x-coordinate of the second end point
- y2 [Number] — the y-coordinate of the second end point
- large_arc_flag [Boolean] — true, if the arc goes "the long way around" between the two end points
- sweep_flag [Boolean] — true, if the arc direction is counter-clockwise
Returns:
- [Array<Number>] — the x,y coordinates of the circle's origin
Cartesia.getPointCoords(point) → Array<Number> ⇏ ArgumentError
This function is used to get x,y coordinates regardless of point representation.
Parameters:
- point [Variadic] — a point representation (see Cartesia.Point documentation)
Returns:
- [Array<Number>] — an array containing the x,y coordinates
Throws:
- [ArgumentError] — if the point representation is invalid or unrecognized
Cartesia.getRadians(angle) → Number ⇏ ArgumentError
This function gets a radian measurement from a variety of angle representations.
Parameters:
- angle [Variadic] — the angle representation (see Cartesia.Angle documentation)
Returns:
- [Number] — the radian measurement of the angle
Throws:
- [ArgumentError] — if the angle representation is invalid or unrecognized
Cartesia.newLineSegment(reference, endpt) → Cartesia.Line
This function creates a new Cartesia.Line object which is a line segment composed of two points.
Parameters:
- reference [Cartesia.Point] — the starting point of the line segment
- endpt [Cartesia.Point] — the end point of the line segment
Returns:
- [Cartesia.Line] — the Cartesia.Line object
Cartesia.newRect(point, width, height) → Cartesia.Polygon
This function creates a new Cartesia.Polygon object which is a rectangle of a given size.
Parameters:
- point [Cartesia.Point] — the location of the rectangle
- width [Number] — the width of the rectangle
- height [Number] — the height of the rectangle
Returns:
- [Cartesia.Polygon] — the Cartesia.Polygon object
Cartesia.newSquare(point, size) → Cartesia.Polygon
This function creates a new Cartesia.Polygon object which is a square of a given size.
Parameters:
- point [Cartesia.Point] — the location of the square
- size [Number] — the size of the square
Returns:
- [Cartesia.Polygon] — the Cartesia.Polygon object
Cartesia.pointBetween(ax, ay, bx, by, ratio) → Array<Number>
This function computes the location of a point which is a proportional distance between the two given points.
Parameters:
- ax [Number] — the x-coordinate of the first point
- ay [Number] — the y-coordinate of the first point
- bx [Number] — the x-coordinate of the second point
- by [Number] — the y-coordinate of the second point
- ratio [Number] — the percentage, as a value from 0.0 to 1.0, from the first point along a line to the second point <default: 0.5>
Returns:
- [Array<Number>] — the x,y coordinates of the point in between
Cartesia.pointFrom(x, y, d, b) → Array<Number>
This function computes the point which is a distance and bearing from the given point, given its x,y coordinates.
Parameters:
- x [Number] — the x-coordinate of the point
- y [Number] — the y-coordinate of the point
- d [Number] — the distance the second point will be from the given point
- b [Number] — the bearing, in radians, the second point will be from the given point
Returns:
- [Array<Number>] — the x,y coordinates of the second point
Cartesia.r2angle(r) → Cartesia.Angle
This function creates a Cartesia.Angle object with a size in radians.
Parameters:
- r [Number] — the size of the angle in radians
Returns:
- [Cartesia.Angle] — the Cartesia.Angle object
Cartesia.r2d(r) → Number
This function converts radians to degrees.
Parameters:
- r [Number] — the angle measurement in radians
Returns:
- [Number] — the angle measurement in degrees
Cartesia.r2s(r) → Number
This function converts radians to sectons.
Parameters:
- r [Number] — the angle measurement in radians
Returns:
- [Number] — the angle measurement in sectons
Cartesia.rotatedPointFrom(ax, ay, bx, by, db) → Array<Number>
This function computes the location of a point which is a distance and bearing from the first point and based on a second point moving radially by a given angle.
Parameters:
- ax [Number] — the x-coordinate of the first point
- ay [Number] — the y-coordinate of the first point
- bx [Number] — the x-coordinate of the second point
- by [Number] — the y-coordinate of the second point
- db [Number] — the delta angular measurement, in radians
Returns:
- [Array<Number>] — the x,y coordinates of the third point
Cartesia.s2angle(s) → Cartesia.Angle
This function creates a Cartesia.Angle object with a size in sectons.
Parameters:
- s [Number] — the size of the angle in sectons
Returns:
- [Cartesia.Angle] — the Cartesia.Angle object
Cartesia.s2d(s) → Number
This function converts sectons to degrees.
Parameters:
- s [Number] — the angle measurement in sectons
Returns:
- [Number] — the angle measurement in degrees
Cartesia.s2r(s) → Number
This function converts sectons to radians.
Parameters:
- s [Number] — the angle measurement in sectons
Returns:
- [Number] — the angle measurement in radians
Cartesia.u2r(m, uom) → Number ⇏ ArgumentError
This function converts a given angular measurement into radians.
Parameters:
- m [Number] — the number of units
- uom [Symbol] — one of { Cartesia.RADIANS,Cartesia.DEGREES,Cartesia,SECTONS } <default: Cartesia.RADIANS>
Returns:
- [Number] — the angular measurement in radians
Throws:
- [ArgumentError] — if the unit of measurement is unrecognized
Cartesia.xy2pt(x, y) → Cartesia.Point
This function creates a Cartesia.Point object from x,y coordinates.
Parameters:
- x [Number] — the x-coordinate of the point
- y [Number] — the y-coordinate of the point
Returns:
- [Cartesia.Point] — the Cartesia.Point object
Class: Cartesia.Angle
File Manifest
File Manifest| File | Language | Author(s) | Copyright |
|---|
| angle.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
Overview
This class handles all angle-based calculations, including units of measure conversions.
Angle Representations
Raw angle representations used to create and/or operate on this class can come in many forms:
- Cartesia.Angle
- a 1-element or 2-element array of numerical units and an optional unit of measurement type
- numerical units and an optional unit of measurement type as separate arguments
This multitude of representations leads to the use of variadic arguments for the functions.
Sectons
One unique aspect of the library is an angle unit of measurement called a secton. Whereas radians use floating point numbers between 0 and 2π and degrees use numbers between 0 and 360, and can be integers or floating point, the secton is designed to be an integral unit between 0 and 64800. The upper limit was designed to fit within a 16-bit integer. One secton equals 1/180° and has a good enough granularity for most digital graphics applications.
Constructor Registry
Item
Attributes
new Cartesia.Angle(angle)
-
Property Registry
Item
Attributes
degrees
-
sections
-
Method Registry
Item
Attributes
add(angle) → Cartesia.Angle
-
add$(angle) → Cartesia.Angle
-
clone() → Cartesia.Angle
-
delta() → Cartesia.Angle
-
delta$() → Cartesia.Angle
-
difference(angle) → Number
-
reflectAroundPI() → Cartesia.Angle
-
reflectAroundPI$() → Cartesia.Angle
-
reflectTowardZero() → Cartesia.Angle
-
reflectTowardZero$() → Cartesia.Angle
-
set(angle) → Cartesia.Angle
-
toString() → String
-
valueOf() → Number
-
Constructor Details
new Cartesia.Angle(angle)
Parameters:
- angle [Variadic] — the initial value of the angle <default: 0.0>
Property Details
degrees
sections
Method Details
add(angle) → Cartesia.Angle
This method creates a new Cartesia.Angle by adding another angle to this angle.
Parameters:
- angle [Variadic] — the initial value of the angle <default: 0.0>
Returns:
- [Cartesia.Angle] — a new Cartesia.Angle object
add$(angle) → Cartesia.Angle
This method adds an angle to this one.
Parameters:
- angle [Variadic] — the initial value of the angle <default: 0.0>
Returns:
- [Cartesia.Angle] — itself
clone() → Cartesia.Angle
This function returns a new Cartesia.Angle with the same values.
Returns:
- [Cartesia.Angle] — the new Cartesia.Angle object
delta() → Cartesia.Angle
This method creates a new Cartesia.Angle which contains an angle which is represented as a difference measurement.
Returns:
- [Cartesia.Angle] — the new Cartesia.Angle object
delta$() → Cartesia.Angle
This method ensures that the angle is represented as a difference measurement.
Returns:
- [Cartesia.Angle] — itself
difference(angle) → Number
This method calculates the difference between this angle and another one, in radians.
Parameters:
- angle [Variadic] — the initial value of the angle <default: 0.0>
Returns:
- [Number] — the difference between the two angles
reflectAroundPI() → Cartesia.Angle
This method creates a new Cartesia.Angle which contains an angle which is a reflection between 0° and 180°.
Returns:
- [Cartesia.Angle] — the new Cartesia.Angle object
reflectAroundPI$() → Cartesia.Angle
This method ensures that the angle is reflection between 0° and 180°.
Returns:
- [Cartesia.Angle] — itself
reflectTowardZero() → Cartesia.Angle
This method creates a new Cartesia.Angle which contains an angle which is a reflection between 270° and 90° toward 0°.
Returns:
- [Cartesia.Angle] — the new Cartesia.Angle object
reflectTowardZero$() → Cartesia.Angle
This method ensures that the angle is reflected between 270° and 90° toward 0°.
Returns:
- [Cartesia.Angle] — itself
set(angle) → Cartesia.Angle
This method sets the angle's value.
Parameters:
- angle [Variadic] — the value of the angle to set <default: 0.0>
Returns:
- [Cartesia.Angle] — itself
toString() → String
This method returns a string representation of the angle.
Returns:
- [String] — the string representation
valueOf() → Number
This method returns the numerical value of the angle, in radians.
Returns:
- [Number] — the value of the angle, in radians
Class: Cartesia.Catenary
File Manifest
File Manifest| File | Language | Author(s) | Copyright |
|---|
| catenary.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
Overview
This class handles all catenary-based calculations. The how-to of catenary curve mathematics will be added later.
Constructor Registry
Item
Attributes
new Cartesia.Catenary(definition)
-
Property Registry
Item
Attributes
isTracking
-
Method Registry
Item
Attributes
$calcAGivenDXPhi(dx, phi) → Number
<private>
$calcAGivenDyPhi(dy, phi) → Number
<private>
$calcAGivenDydx(dy, dx, prec) → Number
<private>
$ctTrackPoint(is_first, pt, distance, precision) → Cartesia.Point
<private>
ctFirst(point, distance_from) → Cartesia.Point ⇏ Error
-
ctNext(distance_from) → Cartesia.Point ⇏ Error
-
dxAtDY(dy) → Number
-
dyAtDX(dx) → Number
-
finishCurveTracking()
-
phiAtDX(dx) → Number
-
phiAtDY(dy) → Number
-
sAtDX(dx) → Number
-
sAtDY(dy) → Number
-
startCurveTracking(anchor, dx, style, direction)
-
toString() → String
-
Constructor Details
new Cartesia.Catenary(definition)
This constructor will define a catenary curve based on a factor a, where y = a at x = 0, if a chain will drop to its lowest point at x = 0. The equation y = a cosh(x/a) defines the curve. The factor 'a', can be explictly given or it can be derived from dx, dy and/or phi values. Only two of the three values of dx, dy or phi need be supplied to calculate 'a'.
Parameters:
- definition [Object] — the parameters of the catenary curve
- a [Cartesia.Point] — the anchor point
- dx [Number] — the x-axis distance between the anchor point and the lowest point of the curve
- dy [Number] — the y-axis distance between the anchor point and the lowest point of the curve
- phi [Number] — the angle of descent from the anchor point
Property Details
isTracking
Method Details
$calcAGivenDXPhi(dx, phi) → Number <private>
This private method calculates 'a' based on the given dx and phi parameters.
Parameters:
- dx [Number] — the x-axis distance between the curve's anchor point and its end point
- phi [Number] — the curve's angle of departure from the anchor point
Returns:
- [Number] — the curve's a factor
$calcAGivenDyPhi(dy, phi) → Number <private>
This private method calculates 'a' based on the given dy and phi parameters.
Parameters:
- dy [Number] — the y-axis distance between the curve's anchor point and its end point
- phi [Number] — the curve's angle of departure from the anchor point
Returns:
- [Number] — the curve's a factor
$calcAGivenDydx(dy, dx, prec) → Number <private>
This private method calculates 'a' based on the given dx and dy parameters.
Parameters:
- dy [Number] — the y-axis distance between the curve's anchor point and its end point
- dx [Number] — the x-axis distance between the curve's anchor point and its end point
- prec [Number] — the calculation precision <default: 10>
Returns:
- [Number] — the curve's a factor
$ctTrackPoint(is_first, pt, distance, precision) → Cartesia.Point <private>
This private method calculates the curve tracking points based on the procedure's current state
Parameters:
- is_first [Boolean] — true, if we are calculating the first point
- pt [Cartesia.Point] — the point we are calculating from
- distance [Number] — the distance away from the given point we are calculating for
- precision [Number] — the level of precision we are limiting the calculations to <default: Cartesia.CatenaryPrecision>
Returns:
- [Cartesia.Point] — the next point on the curve
ctFirst(point, distance_from) → Cartesia.Point ⇏ Error
This method gets the first point in the curve tracking operation.
Parameters:
- point [Cartesia.Point] — a starting point not part of the curve <default: null>
- distance_from [Number] — a distance from the specified point <default: null>
Returns:
- [Cartesia.Point] — the first point in the curve
Throws:
- [Error] — if the operation has not been started
ctNext(distance_from) → Cartesia.Point ⇏ Error
This method gets the next point in the curve tracking operation.
Parameters:
- distance_from [Number] — a distance from the current point <default: null>
Returns:
- [Cartesia.Point] — the next point in the curve
Throws:
- [Error] — if the operation has not been started
dxAtDY(dy) → Number
This method returns the dx value at a point dy from the anchor point.
Parameters:
- dy [Number] — the dy value
Returns:
dyAtDX(dx) → Number
This method returns the dy value at a point dx from the anchor point.
Parameters:
- dx [Number] — the dx value
Returns:
finishCurveTracking()
This method ends the current curve tracking operation.
phiAtDX(dx) → Number
This method returns the phi value at a point dx from the anchor point.
Parameters:
- dx [Number] — the dx value
Returns:
phiAtDY(dy) → Number
This method returns the phi value at a point dy from the anchor point.
Parameters:
- dy [Number] — the dy value
Returns:
sAtDX(dx) → Number
This method returns the s value at a point dx from the anchor point.
Parameters:
- dx [Number] — the dx value
Returns:
sAtDY(dy) → Number
This method returns the s value at a point dy from the anchor point.
Parameters:
- dy [Number] — the dy value
Returns:
startCurveTracking(anchor, dx, style, direction)
This method starts an iterative curve tracking operation between an anchor point and the end point.
Parameters:
- anchor [Cartesia.Point] — the anchor point of the curve
- dx [Number] — the dx distance
- style [Symbol] — the tracking methodology: { Cartesia.ByPX, Cartesia.ByNX, Cartesia.ByInvPX, Cartesia.ByInvNX }
- direction [Symbol] — the direction of the tracking: { Cartesia.A2E, Cartesia.E2A }
toString() → String
This method returns a string representation of the catenary curve object.
Returns:
- [String] — the string representation
Class: Cartesia.Circle
File Manifest
File Manifest| File | Language | Author(s) | Copyright |
|---|
| circle.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
Overview
This class handles all circle-based calculations.
Constructor Registry
Item
Attributes
new Cartesia.Circle(center, radius)
-
Method Registry
Item
Attributes
boundingBox() → Cartesia.Polygon
-
clone() → Cartesia.Circle
-
closestIntersectionPointFromPoint(point) → Cartesia.Point
-
distanceFromPoint(point) → Number
-
getChordAngleByLength(length) → Cartesia.Angle
-
getChordLengthByAngle(angle) → Number
-
getChordLengthByNSegs(nsegs) → Number
-
getChordPointsByLength(length, direction, first_angle) → Array<Cartesia.Point>
-
getChordPointsByN(npts, first_angle) → Array<Cartesia.Point> ⇏ ArgumentError
-
getPoint(angle) → Cartesia.Point
-
getTangentLineBetweenCircles(circle, connection) → Array<Cartesia.Line>
-
getTangentVectors(bearing) → Array<Cartesia.Line>
-
intersectionWithCircle(circle) → Array<Cartesia.Point> or Symbol ⇏ ArgumentError
-
intersectionWithLine(line) → Array<Cartesia.Point> or Symbol ⇏ ArgumentError
-
isPointInside(point) → Boolean
-
toString() → String
-
Constructor Details
new Cartesia.Circle(center, radius)
Parameters:
- center [Cartesia.Point] — the location of the center point of the circle
- radius [Number] — the radius of the circle
Method Details
boundingBox() → Cartesia.Polygon
This method returns the bounding box of the circle.
Returns:
- [Cartesia.Polygon] — the square which makes up the circle's bounding box
clone() → Cartesia.Circle
This method creates a new circle identical to this one.
Returns:
- [Cartesia.Circle] — the new circle
closestIntersectionPointFromPoint(point) → Cartesia.Point
This method determines the point on the circle which is closest to the specified point.
Parameters:
- point [Variadic] — the specified point
Returns:
- [Cartesia.Point] — the point on the circle closest to the specified point
distanceFromPoint(point) → Number
This method determines the distance from the point on the circle which is closest to the specified point.
Parameters:
- point [Variadic] — the specified point
Returns:
- [Number] — the distance between the point on the circle closest to the specified point
getChordAngleByLength(length) → Cartesia.Angle
This method returns the angle of the circle's chord as defined by its length.
Parameters:
- length [Number] — the chord length
Returns:
- [Cartesia.Angle] — the angle of the chord
getChordLengthByAngle(angle) → Number
This method returns the length of the circle's chord based on the angle separating the points from the center point.
Parameters:
- angle [Cartesia.Angle] — the angle separating the points and determining the chord's length
Returns:
- [Number] — the length of the chord
getChordLengthByNSegs(nsegs) → Number
This method returns the length of the circle's chord based a number of equidistant chords running around the circle.
Parameters:
- nsegs [Integer] — the number of segments used to define the size of each equidistant chord
Returns:
- [Number] — the length of the chord
getChordPointsByLength(length, direction, first_angle) → Array<Cartesia.Point>
This method returns the points on the circle which are a given chord length
Parameters:
- length [Number] — the chord length
- direction [Symbol] — the direction around the circle to travel <default: Cartesia.CW>
- first_angle [Variadic] — the angle from center where the first point will be located <default: 0.0>
Returns:
- [Array<Cartesia.Point>] — the calculated chord points around the circle
getChordPointsByN(npts, first_angle) → Array<Cartesia.Point> ⇏ ArgumentError
This method returns N points on a circle where they are equidistant from each other.
Parameters:
- npts [Integer] — the number of points to get
- first_angle [Cartesia.Angle] — the first angle where the first point will be <default: 0.0>
Returns:
- [Array<Cartesia.Point>] — the chord points on the circle
Throws:
- [ArgumentError] — if the specified angle is invalid or unrecognized
getPoint(angle) → Cartesia.Point
This method returns the point at the specified angle from the circle's center.
Parameters:
- angle [Cartesia.Angle] — the angle from the circle's center point
Returns:
- [Cartesia.Point] — the point on the circle at the specified angle from the center point
getTangentLineBetweenCircles(circle, connection) → Array<Cartesia.Line>
This method calculates the tangent lines between two circles based on rotation directions around the circles.
Parameters:
- circle [Cartesia.Circle] — the second circle the tangent lines will connect with
- connection [Symbol] — the rotation directions around the two circles
Returns:
- [Array<Cartesia.Line>] — the two tangential lines connecting the two circles
getTangentVectors(bearing) → Array<Cartesia.Line>
This method returns the two tangential lines at a point on the circle bearing at an angle from the center point.
Parameters:
- bearing [Cartesia.Angle] — the bearing from center
Returns:
- [Array<Cartesia.Line>] — the two tangential lines emanating from the chosen point
intersectionWithCircle(circle) → Array<Cartesia.Point> or Symbol ⇏ ArgumentError
This method determines the intersection points between a circle and another circle.
Parameters:
- circle [Cartesia.Circle] — the circle the circle will intersect with
Returns:
- [Array<Cartesia.Point> or Symbol] — the array of points where the line intersects with the circle or a symbol denoting whether the circle is inside or outside or on top of the circle
Throws:
- [ArgumentError] — if the circle is invalid
intersectionWithLine(line) → Array<Cartesia.Point> or Symbol ⇏ ArgumentError
This method determines the intersection points between a circle and a line.
Parameters:
- line [Cartesia.Line] — the line the circle will intersect with
Returns:
- [Array<Cartesia.Point> or Symbol] — the array of points where the line intersects with the circle or a symbol denoting whether the line is inside or outside of the circle
Throws:
- [ArgumentError] — if the line is invalid
isPointInside(point) → Boolean
This method is used to determine if a given point is inside the circle.
Parameters:
- point [Variadic] — the specified point
Returns:
- [Boolean] — true, if the point is inside the circle
toString() → String
This method returns a string representation of the circle.
Returns:
- [String] — the string representation
Class: Cartesia.HexCoordinateSystem
File Manifest
File Manifest| File | Language | Author(s) | Copyright |
|---|
| hexCoordinateSystem.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
Overview
This class handles all hex coordinate system operations.
Constructor Registry
Item
Attributes
new Cartesia.HexCoordinateSystem(cpoint, size, granularity, orientation) ⇏ ArgumentError
-
Method Registry
Item
Attributes
eachPoint(callback)
-
eachPointAlongEdgeAxis(e, callback) ⇏ RangeError
-
isEdgePoint(point) → Boolean
-
nvAtE(e) → Integer ⇏ RangeError
-
pointAt(point, constrain) → Cartesia.Point
-
rotatedPoint(point, segments) → Cartesia.Point
-
Constructor Details
new Cartesia.HexCoordinateSystem(cpoint, size, granularity, orientation) ⇏ ArgumentError
Parameters:
- cpoint [Cartesia.Point] — the location of the center of the hexagon
- size [Number] — the edge-to-edge size of the hexagon
- granularity [Number] — the spacing between points within the hexagon
- orientation [Cartesia.WIDE or Cartesia.TALL] — the orientation of the hexagon <default: Cartesia.WIDE>
Throws:
- [ArgumentError] — if the orientation is invalid or unrecognized
Method Details
eachPoint(callback)
This method calls the supplied callback function for each point in the hexagon.
Parameters:
- callback [Function] — the callback function
eachPointAlongEdgeAxis(e, callback) ⇏ RangeError
This method calls a callback function for each point along a given edge-oriented axis.
Parameters:
- e [Integer] — the edge-oriented axis index with 0 running through the hex's center point
- callback [Function] — the function to call for each point
Throws:
- [RangeError] — if the e index is outside of the bounds of the granularity of the coordinate system
isEdgePoint(point) → Boolean
This method determines if the given point is along the edge of the hexagon's coordinate system.
Parameters:
- point [Variadic] — the point of the coordinate system
Returns:
- [Boolean] — true, if the point is along any of the six edges
nvAtE(e) → Integer ⇏ RangeError
This method returns the number of coordinate points along a specified edge-axis row.
Parameters:
- e [Integer] — the edge-oriented axis index with 0 running through the hex's center point
Returns:
- [Integer] — the number of coordinate points along that axis
Throws:
- [RangeError] — if the e index is outside of the bounds of the granularity of the coordinate system
pointAt(point, constrain) → Cartesia.Point
This method converts the hex coordinate point to the user space point.
Parameters:
- point [Variadic] — the point in the hex coordinate system
- constrain [Boolean] — true, if conversions outside of the hexagon are not allowed <default: true>
Returns:
- [Cartesia.Point] — the user space point
rotatedPoint(point, segments) → Cartesia.Point
This method returns a point matching its location in one of the other five partitions of the hexagon.
Parameters:
- point [Variadic] — a point in the hex coordinate system
- segments [Integer] — the number of segments to rotate round in a clockwise direction
Returns:
- [Cartesia.Point] — the associated point in the hex segment
Class: Cartesia.Line
File Manifest
File Manifest| File | Language | Author(s) | Copyright |
|---|
| line.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
Overview
This class handles all line-based calculations.
Line Representations
This class supports three types of lines: segments, vectors and infinite. As the the name implies, infinite lines are infinite. Segments have two end points, while vectors are infinite in a single direction from an end point.
Constructor Registry
Item
Attributes
new Cartesia.Line(options) ⇏ ArgumentError
-
Property Registry
Method Registry
Item
Attributes
clone() ⇏ Error
-
closestIntersectionPointFromPoint(point, force_infinite) → Cartesia.Point
-
distanceFromPoint(point) → Number
-
intersectionPoint(line) → Cartesia.Line or Cartesia.Point or Null ⇏ ArgumentError
-
pointAtDX(dx) → Cartesia.Point or Null
-
pointAtDY(dy) → Cartesia.Point or Null
-
pointAtX(x) → Cartesia.Point or Null
-
pointAtY(y) → Cartesia.Point or Null
-
set(options) → Cartesia.Line ⇏ ArgumentError
-
split() → Array<Cartesia.Line> ⇏ TypeError
-
toArray() → Array<Number>
-
toString() → String
-
Constructor Details
new Cartesia.Line(options) ⇏ ArgumentError
This constructor will build a Cartesia.Line object based on input criteria.
Parameters:
- options [Object] — the line parameters, specifying options for the three types of lines
- from [Variadic] — the starting point in a line segment
- to [Variadic] — the end point in a line segment
- reference [Variadic] — the starting point in a line vector or a reference point in an infinite line
- bearing [Variadic] — the angle defining the slope of the line vector
- slope [Variadic] — the angle defining the slope of the line vector
Throws:
- [ArgumentError] — if the options inputs are invalid or unrecognizable
Property Details
length
Method Details
clone() ⇏ Error
This method will build a new Cartesia.Line object identical to the current line
Throws:
- [Error] — if the current line is invalid
closestIntersectionPointFromPoint(point, force_infinite) → Cartesia.Point
This method finds the point on a line closest to a given point.
Parameters:
- point [Variadic] — the point to calculate the distance from
- force_infinite [Boolean] — an option to treat the line as an infinite line, regardless of type
Returns:
- [Cartesia.Point] — the point on the line which is closest to the specified point
distanceFromPoint(point) → Number
This method finds distance of a given point to the line at its closest point.
Parameters:
- point [Variadic] — the point to calculate the distance from
Returns:
- [Number] — the distance to the given point
intersectionPoint(line) → Cartesia.Line or Cartesia.Point or Null ⇏ ArgumentError
This method finds a point where two lines intersect, if they do.
Parameters:
- line [Cartesia.Line] — the line to compare against
Returns:
- [Cartesia.Line or Cartesia.Point or Null] — the intersection point if a point is found, null if not, or itself if the lines are identical
Throws:
- [ArgumentError] — if the given argument is not a line
pointAtDX(dx) → Cartesia.Point or Null
This method finds the point on a line at a distance from the line's reference point in the x-direction.
Parameters:
- dx [Number] — the distance from the line's reference point in the y-direction
Returns:
- [Cartesia.Point or Null] — the point on the line, if able to be calculated
pointAtDY(dy) → Cartesia.Point or Null
This method finds the point on a line at a distance from the line's reference point in the y-direction.
Parameters:
- dy [Number] — the distance from the line's reference point in the y-direction
Returns:
- [Cartesia.Point or Null] — the point on the line, if able to be calculated
pointAtX(x) → Cartesia.Point or Null
This method finds the point on a line at a specific x-coordinate.
Parameters:
- x [Number] — the x-coordinate
Returns:
- [Cartesia.Point or Null] — the point on the line, if able to be calculated
pointAtY(y) → Cartesia.Point or Null
This method finds the point on a line at a specific y-coordinate.
Parameters:
- y [Number] — the x-coordinate
Returns:
- [Cartesia.Point or Null] — the point on the line, if able to be calculated
set(options) → Cartesia.Line ⇏ ArgumentError
This method will build a Cartesia.Line object based on input criteria.
Parameters:
- options [Object] — the line parameters, specifying options for the three types of lines
- from [Variadic] — the starting point in a line segment
- to [Variadic] — the end point in a line segment
- reference [Variadic] — the starting point in a line vector or a reference point in an infinite line
- bearing [Variadic] — the angle defining the slope of the line vector
- slope [Variadic] — the angle defining the slope of the line vector
Returns:
Throws:
- [ArgumentError] — if the options inputs are invalid or unrecognizable
split() → Array<Cartesia.Line> ⇏ TypeError
This method splits an infinite line into two vectors at its reference point.
Returns:
- [Array<Cartesia.Line>] — the two line vectors split at the infinite line's reference point
Throws:
- [TypeError] — if the line is not an infinite line
toArray() → Array<Number>
This method converts a line to a N-element array of reference points and the line's end point, if a segment, or bearing, if not.
Returns:
- [Array<Number>] — the array of information
toString() → String
This method converts a line to a string representation.
Returns:
- [String] — a string representation of the line
Class: Cartesia.Point
File Manifest
File Manifest| File | Language | Author(s) | Copyright |
|---|
| point.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
Overview
This class handles all point-based calculations.
Point Representations
Raw point representations used to create and/or operate on this class can come in many forms:
- Cartesia.Point
- a 2-element array of x,y coordinates
- x,y coordinates as separate arguments, defaulting to 0,0
This multitude of representations leads to the use of variadic arguments for the functions.
Constructor Registry
Item
Attributes
new Cartesia.Point(point) ⇏ ArgumentError
-
Property Registry
Method Registry
Item
Attributes
bearingFrom(point) → Cartesia.Angle ⇏ ArgumentError
-
bearingTo(point) → Cartesia.Angle ⇏ ArgumentError
-
clone() → Cartesia.Point
-
distanceFrom(point) → Number ⇏ ArgumentError
-
dxyTo(point) → Array<Number> ⇏ ArgumentError
-
moveTo$(distance, bearing) → Cartesia.Point ⇏ ArgumentError
-
newPointFrom(distance, bearing) → Cartesia.Point
-
newPointRotatedFrom(angle, point) → Cartesia.Point ⇏ ArgumentError
-
newPointUsingDXY(dx, dy) → Cartesia.Point
-
rotateAround$(angle, point) → Cartesia.Point ⇏ ArgumentError
-
set(point) → Cartesia.Point ⇏ ArgumentError
-
toArray() → Array<Number>
-
toString() → String
-
Constructor Details
new Cartesia.Point(point) ⇏ ArgumentError
Parameters:
- point [Variadic] — the initial value of the point <default: 0,0>
Throws:
- [ArgumentError] — if the point representation is invalid or unrecognized
Property Details
x
y
Method Details
bearingFrom(point) → Cartesia.Angle ⇏ ArgumentError
This method calculates the bearing of a specified point from this point.
Parameters:
- point [Variadic] — the point away from this point <default: 0,0>
Returns:
- [Cartesia.Angle] — the bearing of the specified point from this point
Throws:
- [ArgumentError] — if the point representation is invalid or unrecognized
bearingTo(point) → Cartesia.Angle ⇏ ArgumentError
This method calculates the bearing of this point from a specified point.
Parameters:
- point [Variadic] — the point away from this point <default: 0,0>
Returns:
- [Cartesia.Angle] — the bearing of this point from the specified point
Throws:
- [ArgumentError] — if the point representation is invalid or unrecognized
clone() → Cartesia.Point
This function returns a new Cartesia.Point with the same values.
Returns:
- [Cartesia.Point] — the new Cartesia.Point object
distanceFrom(point) → Number ⇏ ArgumentError
This method calculates the distance between this point and a specified point.
Parameters:
- point [Variadic] — the point away from this point <default: 0,0>
Returns:
- [Number] — the distance between the points
Throws:
- [ArgumentError] — if the point representation is invalid or unrecognized
dxyTo(point) → Array<Number> ⇏ ArgumentError
This method calculates the dx,dy distances from this point to a specified point.
Parameters:
- point [Variadic] — the point away from this point <default: 0,0>
Returns:
- [Array<Number>] — the 2-element array of dx,dy distances between the points
Throws:
- [ArgumentError] — if the point representation is invalid or unrecognized
moveTo$(distance, bearing) → Cartesia.Point ⇏ ArgumentError
This method move this point to a new location some distance and bearing from its current location.
Parameters:
- distance [Number] — the distance to move this point from its current location
- bearing [Cartesia.Angle or Number] — the directional bearing from this point to move itself
Returns:
- [Cartesia.Point] — itself
Throws:
- [ArgumentError] — if the point or angle representation is invalid or unrecognized
newPointFrom(distance, bearing) → Cartesia.Point
This method creates a new point some distance and bearing from this point.
Parameters:
- distance [Number] — the distance from its current location
- bearing [Cartesia.Angle or Number] — the directional bearing from this point
Returns:
- [Cartesia.Point] — the new Cartesia.Point
newPointRotatedFrom(angle, point) → Cartesia.Point ⇏ ArgumentError
This method creates a new point some radial distance around another point by a specified angle.
Parameters:
- angle [Cartesia.Angle or Number] — the angle argument as a Cartesia.Angle object or a measurement in radians
- point [Variadic] — the point away from this point <default: 0,0>
Returns:
- [Cartesia.Point] — ths new Cartesia.Point
Throws:
- [ArgumentError] — if the point or angle representation is invalid or unrecognized
newPointUsingDXY(dx, dy) → Cartesia.Point
This method creates a new point some dx,dy distance from this point.
Parameters:
- dx [Number] — the dx distance
- dy [Number] — the dy distance
Returns:
- [Cartesia.Point] — the new Cartesia.Point
rotateAround$(angle, point) → Cartesia.Point ⇏ ArgumentError
This method moves this point around another point by a specified angle.
Parameters:
- angle [Cartesia.Angle or Number] — the angle argument as a Cartesia.Angle object or a measurement in radians
- point [Variadic] — the point away from this point <default: 0,0>
Returns:
- [Cartesia.Point] — itself
Throws:
- [ArgumentError] — if the point or angle representation is invalid or unrecognized
set(point) → Cartesia.Point ⇏ ArgumentError
This method sets the point's value.
Parameters:
- point [Variadic] — the value of the point to set <default: 0,0>
Returns:
- [Cartesia.Point] — itself
Throws:
- [ArgumentError] — if the point representation is invalid or unrecognized
toArray() → Array<Number>
This method converts this point to a coordinate array.
Returns:
- [Array<Number>] — the coordinate array
toString() → String
This method converts the point to a string representation.
Returns:
- [String] — the string representation of the point.
Class: Cartesia.Polygon
File Manifest
File Manifest| File | Language | Author(s) | Copyright |
|---|
| polygon.js | Javascript | Kenneth F. Guerin | Copyright © 2018-2024, Brick Mill Games, LLC, all rights reserved. |
Overview
This class handles all polygon-based calculations.
Constructor Registry
Item
Attributes
new Cartesia.Polygon(points) ⇏ ArgumentError
-
Method Registry
Item
Attributes
$ptDistanceInfo(point) → Variadic ⇏ ArgumentError
<private>
appendPoint(point) → Cartesia.Polygon ⇏ ArgumentError
-
appendPoints(points) → Cartesia.Polygon ⇏ ArgumentError
-
boundingBox() → Cartesia.Polygon
-
closestIntersectionPointFromPoint(point) → Cartesia.Point
-
deletePointAt(index) → Cartesia.Polygon ⇏ ArgumentError
-
distanceFromPoint(point) → Number
-
insertPoint(point, index) → Cartesia.Polygon ⇏ ArgumentError
-
insertPoints(points, index) → Cartesia.Polygon ⇏ ArgumentError
-
isPointInside(point) → Boolean ⇏ ArgumentError
-
lineSegments() → Array<Cartesia.Line>
-
set(points) → Cartesia.Polygon ⇏ ArgumentError
-
toString() → String
-
Constructor Details
new Cartesia.Polygon(points) ⇏ ArgumentError
This constructor creates a new polygon based on the supplied points, in order of connection.
Parameters:
- points [Array<Cartesia.Point>] — the points which make up the polygon
Throws:
- [ArgumentError] — if the supplied points vector is invalid
Method Details
$ptDistanceInfo(point) → Variadic ⇏ ArgumentError <private>
This private method calculates the point and distance between a given point and the polygon
Parameters:
- point [Cartesia.Point] — the point to compare against
Returns:
- [Variadic] — a 2-element array containing the point on the polygon which is closest and the distance between those points
Throws:
- [ArgumentError] — if the given point is invalid
appendPoint(point) → Cartesia.Polygon ⇏ ArgumentError
This method appends a point to the polygon's point list.
Parameters:
- point [Array<Cartesia.Point>] — the point to append to the polygon
Returns:
- [Cartesia.Polygon] — itself
Throws:
- [ArgumentError] — if the supplied points vector is invalid
appendPoints(points) → Cartesia.Polygon ⇏ ArgumentError
This method appends points to the polygon's point list.
Parameters:
- points [Array<Cartesia.Point>] — the points to append to the polygon
Returns:
- [Cartesia.Polygon] — itself
Throws:
- [ArgumentError] — if the supplied points vector is invalid
boundingBox() → Cartesia.Polygon
This method returns the bounding box of the polygon.
Returns:
- [Cartesia.Polygon] — the bounding box rectangle containing the polygon
closestIntersectionPointFromPoint(point) → Cartesia.Point
This method finds the point on the polygon closest to the specified point.
Parameters:
- point [Cartesia.Point] — the reference point to determining the closest point to
Returns:
- [Cartesia.Point] — the closest point of the polygon to the reference point
deletePointAt(index) → Cartesia.Polygon ⇏ ArgumentError
This method deletes a point from the polygon.
Parameters:
- index [Integer] — the zero-based index of the point of the polygon to delete
Returns:
- [Cartesia.Polygon] — itself
Throws:
- [ArgumentError] — if the index is invalid
distanceFromPoint(point) → Number
This method finds the closest distance between a given point and any point of the polygon.
Parameters:
- point [Cartesia.Point] — the reference point to determining the closest point to
Returns:
- [Number] — the closest distance to the point
insertPoint(point, index) → Cartesia.Polygon ⇏ ArgumentError
This method inserts a point into the polygon list at the specified location.
Parameters:
- point [Array<Cartesia.Point>] — the point to insert into the polygon
- index [Integer] — the zero-based index of the point of the polygon to delete
Returns:
- [Cartesia.Polygon] — itself
Throws:
- [ArgumentError] — if the supplied points vector is invalid
insertPoints(points, index) → Cartesia.Polygon ⇏ ArgumentError
This method inserts points to the polygon's point list at the specified location.
Parameters:
- points [Array<Cartesia.Point>] — the points to insert into the polygon
- index [Integer] — the zero-based index of the point of the polygon to delete
Returns:
- [Cartesia.Polygon] — itself
Throws:
- [ArgumentError] — if the supplied points vector is invalid
isPointInside(point) → Boolean ⇏ ArgumentError
This method determines if a given point is inside the polygon.
Parameters:
- point [Cartesia.Point] — the point we are checking for
Returns:
- [Boolean] — true, if the point is inside the polygon
Throws:
- [ArgumentError] — if the point is invalid
lineSegments() → Array<Cartesia.Line>
This method returns the array of line segments which will make up the polygon.
Returns:
- [Array<Cartesia.Line>] — the array of line segments
set(points) → Cartesia.Polygon ⇏ ArgumentError
This constructor creates a new polygon based on the supplied points, in order of connection.
Parameters:
- points [Array<Cartesia.Point>] — the points which make up the polygon
Returns:
- [Cartesia.Polygon] — itself
Throws:
- [ArgumentError] — if the supplied points vector is invalid
toString() → String
This method returns a string represention of the polygon.
Returns:
- [String] — the string representation