XY Class

Minimal object containing x,y and operations that are meaningful without change in both point and vector.

  • XY is not instantiable.
  • The derived (instantiable) classes are
    • Point2d
    • Vector2d

Extended by

Implements

Methods

Name Description
constructor(x: number = 0, y: number = 0): XY Protected    
distance(other: Readonly<WritableXAndY>): number Return the distance from this point to other  
distanceSquared(other: Readonly<WritableXAndY>): number Return squared distance from this point to other  
freeze(): Readonly<XY> Freeze this instance so it is read-only  
isAlmostEqual(other: Readonly<WritableXAndY>, tol?: number): boolean Returns true if this and other have equal x,y parts within Geometry.smallMetricDistance.  
isAlmostEqualMetric(other: Readonly<WritableXAndY>): boolean returns true if x,y match other within metric tolerance  
isAlmostEqualXY(x: number, y: number, tol?: number): boolean Returns true if this and other have equal x,y parts within Geometry.smallMetricDistance.  
isExactEqual(other: Readonly<WritableXAndY>): boolean returns true if the x,y components are exactly equal.  
magnitude(): number Return the magnitude of the vector  
magnitudeSquared(): number Return the squared magnitude of the vector.  
maxAbs(): number Return the largest absolute value of any component  
maxDiff(other: Readonly<WritableXAndY>): number Return the largest absolute distance between corresponding components  
set(x: number = 0, y: number = 0): void Set both x and y.  
setFrom(other?: Readonly<WritableXAndY>): void Set both x and y from other.  
setFromJSON(json?: XYProps): void Set x and y from a JSON source such as [1,2] or {x:1, y:2}  
setZero(): void Set both x and y to zero  
toJSON(): XYProps return a json array [x,y]  
toJSONXY(): XYProps return a json object {x: 1, y:2}  
unitVectorTo(target: Readonly<WritableXAndY>, result?: Vector2d): undefined | Vector2d Return a unit vector from this point to other  
vectorTo(other: Readonly<WritableXAndY>, result?: Vector2d): Vector2d Return a (full length) vector from this point to other  
crossProductToPoints(origin: Readonly<WritableXAndY>, targetA: Readonly<WritableXAndY>, targetB: Readonly<WritableXAndY>): number Static cross product of vectors from origin to targets  

Properties

Name Type Description
isAlmostZero Accessor ReadOnly boolean returns true if the x,y components are both small by metric metric tolerance  
x number x component  
y number y component  

Defined in

Last Updated: 12 June, 2024