Home Reference Source
import Point from 'cgil-geom2d/src/Point.js'
public class | source

Point

Class representing a point in 2 dimension cartesian space

Static Method Summary

Static Public Methods
public static

fromPoint(otherPoint: Point): Point

get a new Point that is a copy (clone) of the otherPoint passed has parameter

public static

fromPolar(radius: number, theta: number, angleSystem: Object): Point

creates a new Point in cartesian space from polar coordinates

Constructor Summary

Public Constructor
public

Creates a point

Member Summary

Public Members
public
public
public get

x: number: *

Get the x value.

public set

x(value: number)

Set the x value

public get

y: number: *

Get the y value.

public set

y(value: number)

Set the y value

Private Members
private

_x: *

private

_y: *

Method Summary

Public Methods
public

copyRel(deltaX: number, deltaY: number): Point

copy this Point relative to its position by the deltaX, deltaY displacement in cartesian space

public

copyRelArray(arrVector: Array): Point

copy this Point relative to its position by the arrVector displacement in cartesian space

public

copyRelPolar(radius: number, theta: number, angleSystem: Object): Point

copy this Point relative to its position by the polar displacement in cartesian space

public

distance(otherPoint: Point): Number

get the distance from this point to otherPoint

public

equal(otherPoint: Point): boolean

allows to compare equality with otherPoint, they should have the same values for x and y Math.sqrt(2) Math.sqrt(2) should give 2 but gives instead 2.0000000000000004 Math.sqrt(3) Math.sqrt(3) should give 2 but gives instead 2.9999999999999996 i found So the Point Class equality should take this fact account to test near equality with EPSILON=0.0000000001 feel free to adapt EPSILON value to your needs in utils.js

public

moveRel(deltaX: number, deltaY: number): Point

move this Point relative to its position by the deltaX, deltaY displacement in cartesian space

public

moveRelArray(arrVector: Array): Point

move this Point relative to its position by the arrVector displacement in cartesian space

public

moveRelPolar(radius: number, theta: number, angleSystem: Object): Point

move this Point relative to its position by the polar displacement in cartesian space

public

moveTo(newX: number, newY: number): Point

will move this Point to the new position in cartesian space given by the newX and newY values

public

moveToArray(arrCoordinates: Array): Point

will move this Point to the new position in cartesian space given by the arrCoordinates

public

give an array representation of this Point class instance [x, y]

public

toEWKT(srid: number): string

give an Postgis Extended Well-known text (EWKT) representation of this class instance https://postgis.net/docs/using_postgis_dbmanagement.html#EWKB_EWKT

public

give a GeoJSON (http://geojson.org/) representation of this class instance geometry

public

toString(separator: string, surroundingParenthesis: boolean, precision: number): string

give a string representation of this class instance

public

give an OGC Well-known text (WKT) representation of this class instance https://en.wikipedia.org/wiki/Well-known_text

Static Public Methods

public static fromPoint(otherPoint: Point): Point source

get a new Point that is a copy (clone) of the otherPoint passed has parameter

Params:

NameTypeAttributeDescription
otherPoint Point

is the Point you want to copy

Return:

Point

a new Point located at the same cartesian coordinates as otherPoint

public static fromPolar(radius: number, theta: number, angleSystem: Object): Point source

creates a new Point in cartesian space from polar coordinates

Params:

NameTypeAttributeDescription
radius number

is the distance from origin to the point

theta number

is the angle from x axes origin to point in mathematical order Counter-Clockwise

angleSystem Object

your choice of one of AngularSystem Enum Radian, Degree or Gradians

Return:

Point

a new Point(x,y) located at the given polar coordinates

Public Constructors

public constructor(x: number, y: number) source

Creates a point

Params:

NameTypeAttributeDescription
x number

coordinates in cartesian space or array with [x, y] numbers

y number

coordinates in cartesian space, ignored if first argument is an array

Public Members

public InvalidReason: string source

public isInvalid: boolean source

public get x: number: * source

Get the x value.

Return:

number

The x value.

public set x(value: number) source

Set the x value

public get y: number: * source

Get the y value.

Return:

number

The y value.

public set y(value: number) source

Set the y value

Private Members

private _x: * source

private _y: * source

Public Methods

public copyRel(deltaX: number, deltaY: number): Point source

copy this Point relative to its position by the deltaX, deltaY displacement in cartesian space

Params:

NameTypeAttributeDescription
deltaX number

is the increment to x coordinates to this Point

deltaY number

is the increment to y coordinates to this Point

Return:

Point

a new Point object at the relative deltaX, deltaY displacement from original Point

public copyRelArray(arrVector: Array): Point source

copy this Point relative to its position by the arrVector displacement in cartesian space

Params:

NameTypeAttributeDescription
arrVector Array

is an array representing the vector displacement to apply to actual coordinates [deltaX, deltaY]

Return:

Point

a new Point object at the relative displacement arrVector from original Point

public copyRelPolar(radius: number, theta: number, angleSystem: Object): Point source

copy this Point relative to its position by the polar displacement in cartesian space

Params:

NameTypeAttributeDescription
radius number

is the distance from origin to the point

theta number

is the angle from x axes origin to point in mathematical order Counter-Clockwise

angleSystem Object

your choice of one of AngularSystem Enum Radian, Degree or Gradians

Return:

Point

a new Point at the polar displacement from original Point

public distance(otherPoint: Point): Number source

get the distance from this point to otherPoint

Params:

NameTypeAttributeDescription
otherPoint Point

Return:

Number

public equal(otherPoint: Point): boolean source

allows to compare equality with otherPoint, they should have the same values for x and y Math.sqrt(2) Math.sqrt(2) should give 2 but gives instead 2.0000000000000004 Math.sqrt(3) Math.sqrt(3) should give 2 but gives instead 2.9999999999999996 i found So the Point Class equality should take this fact account to test near equality with EPSILON=0.0000000001 feel free to adapt EPSILON value to your needs in utils.js

Params:

NameTypeAttributeDescription
otherPoint Point

Return:

boolean

public moveRel(deltaX: number, deltaY: number): Point source

move this Point relative to its position by the deltaX, deltaY displacement in cartesian space

Params:

NameTypeAttributeDescription
deltaX number

is the new x coordinates in cartesian space of this Point

deltaY number

is the new y coordinates in cartesian space of this Point

Return:

Point

return this instance of the object (to allow function chaining)

public moveRelArray(arrVector: Array): Point source

move this Point relative to its position by the arrVector displacement in cartesian space

Params:

NameTypeAttributeDescription
arrVector Array

is an array representing the vector displacement to apply to actual coordinates [deltaX, deltaY]

Return:

Point

return this instance of the object (to allow function chaining)

public moveRelPolar(radius: number, theta: number, angleSystem: Object): Point source

move this Point relative to its position by the polar displacement in cartesian space

Params:

NameTypeAttributeDescription
radius number

is the distance from origin to the point

theta number

is the angle from x axes origin to point in mathematical order Counter-Clockwise

angleSystem Object

your choice of one of AngularSystem Enum Radian, Degree or Gradians

Return:

Point

return this instance of the object (to allow function chaining)

public moveTo(newX: number, newY: number): Point source

will move this Point to the new position in cartesian space given by the newX and newY values

Params:

NameTypeAttributeDescription
newX number

is the new x coordinates in cartesian space of this Point

newY number

is the new y coordinates in cartesian space of this Point

Return:

Point

return this instance of the object (to allow function chaining)

public moveToArray(arrCoordinates: Array): Point source

will move this Point to the new position in cartesian space given by the arrCoordinates

Params:

NameTypeAttributeDescription
arrCoordinates Array

is an array with the 2 cartesian coordinates [x, y]

Return:

Point

return this instance of the object (to allow function chaining)

public toArray(): Array source

give an array representation of this Point class instance [x, y]

Return:

Array

[x, y]

public toEWKT(srid: number): string source

give an Postgis Extended Well-known text (EWKT) representation of this class instance https://postgis.net/docs/using_postgis_dbmanagement.html#EWKB_EWKT

Params:

NameTypeAttributeDescription
srid number

is the Spatial reference systems identifier EPSG code default is 21781 for Switzerland MN03

Return:

string

public toGeoJSON(): string source

give a GeoJSON (http://geojson.org/) representation of this class instance geometry

Return:

string

public toString(separator: string, surroundingParenthesis: boolean, precision: number): string source

give a string representation of this class instance

Params:

NameTypeAttributeDescription
separator string

placed between x and y values ', ' by default

surroundingParenthesis boolean

allow to tell if result string should be surrounded with parenthesis (True by default)

precision number

defines the number of decimals for the coordinates (2 by default)

Return:

string

public toWKT(): string source

give an OGC Well-known text (WKT) representation of this class instance https://en.wikipedia.org/wiki/Well-known_text

Return:

string