Represents an immutable point in two-dimensional Cartesian coordinates with double precision.
Remarks
In addition to being used to model points Point also includes a number of useful properties and methods that allow it to be treated as a vector.
Furthermore, Point provides various methods for analyzing and manipulating geometry in general, such as:
- Distance measurements – distanceTo, distanceToSegment
- Projections – getProjectionOnSegment, getProjectionOnLine, getProjectionOnRay
- Hit-tests – hits, hitsLineSegment, hitsPolyline
This is a convertible type that can be used with the following notation(s) in parameter lists, parameter objects or setters.
It is possible to specify an Object or plain Object to define the Point:
[5, 5] // x, y
{ x: 5, y: 5 }
Examples
// Create a new point
const p1 = new Point(-5, 2)
// Create another point somewhere else
const p2 = new Point(23, 42)
console.log(
`Point 1 is at (${p1.x},${p1.y}), point 2 is at (${p2.x},${p2.y})`
)
// Subtract one point from the other to get a vector between them
// which is also represented as a Point
const v = p2.subtract(p1)
// Point offers a few handy properties when interpreting it as a vector
console.log(`VectorLength: ${v.vectorLength}`)
// VectorLength in this case is equivalent to p1.distanceTo(p2):
console.log(`Distance: ${p1.distanceTo(p2)}`)
console.log(`IsHorizontalVector: ${v.isHorizontalVector}`)
console.log(`IsVerticalVector: ${v.isVerticalVector}`)
console.log(`Normalized: ${v.normalized}`)
const halfLength = v.multiply(0.2).vectorLength
const doubleLength = v.multiply(2).vectorLength
console.log(`Original vector: ${v.vectorLength}`)
console.log(`Half-length vector: ${halfLength}`)
console.log(`Double-length vector: ${doubleLength}`)
Type Details
- yfiles module
- view-component
- yfiles-umd modules
- All view modules
- Legacy UMD name
- yfiles.geometry.Point
Constructors
Properties
Gets the length of the vector that has x and y as its components.
Remarks
See Also
Gets the X coordinate of the point.
Implements
Gets the Y coordinate of the point.
Implements
Methods
Determines the distance between this point and a line segment.
Indicates whether this instance and a specified object are equal.
Parameters
A map of options to pass to the method.
- other - Object
- Another object to compare to.
Returns
- ↪boolean
- true if
other
and this instance are the same type and represent the same value; otherwise, false.
Examples
Determines whether the two given points have the same coordinates with respect to a certain given eps
.
Parameters
A map of options to pass to the method.
- other - Point
- The other point to check for equality against this point.
- eps - number
- The epsilon value.
Returns
- ↪boolean
- Whether both coordinates are equal with respect for the given epsilon.
Examples
Create a constrained copy of this instance that lies within the given non-empty rectangle
.
Remarks
If the point lies outside the rectangle
its projection on the closest border will be returned.
If the given rectangle is EMPTY, the return value is unchanged.
Parameters
A map of options to pass to the method.
- rectangle - Rect
- The rectangle to constrain this instance by.
Returns
- ↪Point
- A constrained copy of this instance.
Calculates the projection of this point onto a ray.
Remarks
rayStart
) the rayStart
is returned instead.Parameters
A map of options to pass to the method.
Returns
- ↪Point
- The point on the ray that is closest to this point.
Calculates the projection of this point onto a segment.
Remarks
Parameters
A map of options to pass to the method.
Returns
- ↪Point
- The point on the segment that is closest to this point.
Determines if the point lies close to this point given an epsilon.
Parameters
A map of options to pass to the method.
- other - Point
- The coordinates of the other point.
- hitTestRadius - number
- The hit test epsilon.
Returns
- ↪boolean
- Whether the distance between the two points is smaller than
hitTestRadius
Determines whether this point hits the line segment with respect to a given radius
.
Determines whether a polygonal line is hit by this point given an epsilon.
Parameters
A map of options to pass to the method.
- points - IEnumerable<IPoint>
- The list of points that is treated as a polygon
- radius - number
- A positive value allows for fuzzy hit testing. If the point lies outside the given object but it's distance is less than or equal to that value, it will be considered a hit.
Returns
- ↪boolean
- Whether the point hits the polygon.
Multiplies the given factor with this instance using scalar multiplication and returns the result as new instance.
Subtracts the given vector from this instance and returns the result as new instance.
Creates a MutablePoint that has the same coordinates as this instance.
Returns
- ↪MutablePoint
- A MutablePoint with the same coordinates.
Examples
const point = new Point(10, 15)
console.log(`Initial point: ${point}`) // (10, 15)
const mPoint = point.toMutablePoint()
// The following also works, due to an implicit conversion:
const mPoint2 = point
mPoint.x = 42
const point2 = mPoint.toPoint()
// The following also works, due an explicit conversion:
const point3 = mPoint
console.log(`Changed point: ${point2}`) // (42, 15)
Static Methods
Performs an explicit conversion from MutablePoint to Point.
Parameters
A map of options to pass to the method.
- p - MutablePoint
- The point to convert.
Returns
- ↪Point
- The result of the conversion.
Examples
const point = new Point(10, 15)
console.log(`Initial point: ${point}`) // (10, 15)
const mPoint = point.toMutablePoint()
// The following also works, due to an implicit conversion:
const mPoint2 = point
mPoint.x = 42
const point2 = mPoint.toPoint()
// The following also works, due an explicit conversion:
const point3 = mPoint
console.log(`Changed point: ${point2}`) // (42, 15)
Performs an implicit conversion from Point to MutablePoint.
Parameters
A map of options to pass to the method.
- point - Point
- The point to convert.
Examples
const point = new Point(10, 15)
console.log(`Initial point: ${point}`) // (10, 15)
const mPoint = point.toMutablePoint()
// The following also works, due to an implicit conversion:
const mPoint2 = point
mPoint.x = 42
const point2 = mPoint.toPoint()
// The following also works, due an explicit conversion:
const point3 = mPoint
console.log(`Changed point: ${point2}`) // (42, 15)
Calculates a linear interpolation between two points.
Remarks
t
defines where to estimate the value on the interpolated line. It is 0
at point1
and 1
at point2
. For interpolated values between the two points t
ranges between 0
and 1
. Values of t
outside this range result in extrapolation.Parameters
A map of options to pass to the method.
- point1 - Point
- The point where
t
is0
. - point2 - Point
- The point where
t
is1
. - t - number
- The parameter that defines where to estimate the value on the interpolated line.
Returns
- ↪Point
- The interpolated value.