Class Point2D
The Point2D class can represent a position in 2D space, or a vector in 2D space. Some operations assume that the interpretation is a vector.
Inheritance
Inherited Members
Namespace: DesignData.SDS2.Primitives
Assembly: DesignData.SDS2.Primitives.dll
Syntax
public sealed class Point2D
Remarks
Note that intermediate arithmetic is done in floating point, and thus some operations may have intermediate results that overflow, underflow or experience cancellation error, like all floating-point arithmetic.
Constructors
Point2D()
Instantiates a point with X and Y set to zero
Declaration
public Point2D()
Point2D(Point2D)
Instantiates a point equal to the given point
Declaration
public Point2D(Point2D pt)
Parameters
Type | Name | Description |
---|---|---|
Point2D | pt | The point whose value to copy |
Point2D(Vector2D)
Instantiates a point with the X and Y values of the given vector
Declaration
public Point2D(Vector2D vector)
Parameters
Type | Name | Description |
---|---|---|
Vector2D | vector | The point whose value to copy |
Point2D(Double, Double)
Instantiates a point with the given X and Y values
Declaration
public Point2D(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
System.Double | x | The X value for the new point |
System.Double | y | The Y value for the new point |
Properties
X
The X-coordinate of the point
Declaration
public double X { get; }
Property Value
Type | Description |
---|---|
System.Double |
Y
The Y-coordinate of the point
Declaration
public double Y { get; }
Property Value
Type | Description |
---|---|
System.Double |
Methods
BinEquals(Point2D, Double)
Returns true if this point and the given point fall within the same "bin". A "bin" is a square region of space approximately binSize on a side.
Declaration
public bool BinEquals(Point2D other, double binSize)
Parameters
Type | Name | Description |
---|---|---|
Point2D | other | The other point |
System.Double | binSize | The size of a bin. |
Returns
Type | Description |
---|---|
System.Boolean |
Remarks
Unlike EpsilonEquals, BinEquals maintains the transitive rule of equality, but some points which are arbitrarily close together in distance are unequal according got EpsilonEquals, because they fall into different bins.
EpsilonEquals(Point2D, Double)
Returns true if the squared distance between this point and the given point is less than distance_squared.
Declaration
public bool EpsilonEquals(Point2D other, double distanceSquared)
Parameters
Type | Name | Description |
---|---|---|
Point2D | other | The other point |
System.Double | distanceSquared | The square of the smallest distance value that should be considered different |
Returns
Type | Description |
---|---|
System.Boolean |
Remarks
Note that EpsilonEquals can violate the transitivity rule of equality comparison, because there are many groups of points (p, q, r) where p.EpsilonEquals(q) and p.EpsilonEquals(r) but not q.EpsilonEquals(r).
Equals(Object)
Checks if each element of the points are equal using Double.Equals on each component. Note that this is an "exact" comparison method, and only appropriate in special circumstances.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The point to compare to |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
Finalize()
Declaration
protected void Finalize()
GetHashCode()
Returns the hash code for this instance. True for instances which are Equals(), otherwise False with high probability. Specific hash values are implementation-dependent.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
Interpolate(Point2D, Double)
Performs linear interpolation between this point and the other
Declaration
public Point2D Interpolate(Point2D other, double t)
Parameters
Type | Name | Description |
---|---|---|
Point2D | other | The other point |
System.Double | t | Controls the mixing between the two points. This function is defined
for all values of |
Returns
Type | Description |
---|---|
Point2D |
Remarks
This is equal to this + (other - this) * t
.
Note that due to floating point arithmetic, p.project(q, 1.0)
may not be exactly equal to q
.
ToString()
Formats the point into a string. Note that because the values are rounded for display, parsing them to retrieve the X and Y values will not necessarily yield the same point.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |
Overrides
Operators
Equality(Point2D, Point2D)
Checks if each element of the points are equal using == on each component. Note that this is an "exact" comparison method, and only appropriate in special circumstances.
Declaration
public static bool operator ==(Point2D p, Point2D q)
Parameters
Type | Name | Description |
---|---|---|
Point2D | p | The point to compare |
Point2D | q | The point to compare to |
Returns
Type | Description |
---|---|
System.Boolean |
Inequality(Point2D, Point2D)
Checks if any element of the points are unequal using != on each component. Note that this is an "exact" comparison method, and only appropriate in special circumstances.
Declaration
public static bool operator !=(Point2D p, Point2D q)
Parameters
Type | Name | Description |
---|---|---|
Point2D | p | The point to compare |
Point2D | q | The point to compare to |
Returns
Type | Description |
---|---|
System.Boolean |
Subtraction(Point2D, Point2D)
Return a vector which is the difference of the two given points
Declaration
public static Vector2D operator -(Point2D arg0, Point2D arg1)
Parameters
Type | Name | Description |
---|---|---|
Point2D | arg0 | |
Point2D | arg1 |
Returns
Type | Description |
---|---|
Vector2D |