Class PointMathExtensions
- Namespace
- Splat
- Assembly
- Splat.dll
Provides extension methods for performing common mathematical operations on Point and PointF structures.
public static class PointMathExtensions
- Inheritance
-
PointMathExtensions
Remarks
These methods enable vector-like operations such as scaling, normalization, dot product, projection, and distance calculations directly on Point and PointF instances. They are intended to simplify geometric computations in graphical or mathematical applications.
Methods
AngleInDegrees(PointF)
Calculates the angle, in degrees, between the positive X-axis and the vector represented by the specified point.
public static float AngleInDegrees(this PointF value)
Parameters
valuePointFThe point whose vector angle is to be calculated. The X and Y coordinates represent the vector components.
Returns
- float
The angle, in degrees, between the positive X-axis and the vector from the origin to
value. The result is in the range -180 to 180 degrees.
Remarks
A positive result indicates a counterclockwise angle from the X-axis, while a negative result
indicates a clockwise angle. If value is (0, 0), the result is 0.
DistanceTo(PointF, PointF)
Calculates the Euclidean distance between two points represented by PointF structures.
public static float DistanceTo(this PointF value, PointF other)
Parameters
valuePointFThe first point from which to measure the distance.
otherPointFThe second point to which the distance is measured.
Returns
- float
The straight-line distance between
valueandother, measured in the same units as the point coordinates.
DotProduct(PointF, PointF)
Calculates the dot product of two 2D points represented by PointF instances.
public static float DotProduct(this PointF value, PointF other)
Parameters
valuePointFThe first point to use in the dot product calculation.
otherPointFThe second point to use in the dot product calculation.
Returns
- float
A single-precision floating-point value representing the dot product of the two points.
Remarks
The dot product is calculated as (value.X * other.X) + (value.Y * other.Y). This operation is commonly used in vector mathematics to determine the angle or projection between two vectors.
Floor(Point)
Returns a new PointF whose coordinates are the largest integers less than or equal to the corresponding coordinates of the specified Point.
public static PointF Floor(this Point value)
Parameters
valuePointThe Point whose coordinates are to be floored.
Returns
- PointF
A PointF whose X and Y values are the result of applying the floor operation to the X and Y values of the input Point.
Length(PointF)
Calculates the distance from the origin to the specified point.
public static float Length(this PointF value)
Parameters
valuePointFThe point for which to calculate the distance from the origin.
Returns
- float
The distance from the origin (0,0) to the specified point, measured in the same units as the point's coordinates.
Normalize(PointF)
Returns a new PointF representing the normalized (unit length) vector of the specified point.
public static PointF Normalize(this PointF value)
Parameters
valuePointFThe PointF to normalize.
Returns
- PointF
A PointF with the same direction as the input but with a length of 1.0, or the original point if its length is zero.
Remarks
If the input point has a length of zero, the original point is returned unchanged to avoid division by zero.
ProjectAlong(PointF, PointF)
Projects the specified point onto the given direction vector, returning the component of the point that lies along that direction.
public static PointF ProjectAlong(this PointF value, PointF direction)
Parameters
valuePointFThe point to be projected onto the direction vector.
directionPointFThe direction vector along which to project the point. Does not need to be normalized.
Returns
Remarks
If direction is the zero vector, the result will be a zero vector. The
returned vector has the same direction as direction and a magnitude equal to the component of
value along that direction.
ProjectAlongAngle(PointF, float)
Projects the specified point onto a vector defined by the given angle in degrees.
public static PointF ProjectAlongAngle(this PointF value, float angleInDegrees)
Parameters
valuePointFThe point to project.
angleInDegreesfloatThe angle, in degrees, specifying the direction of the projection. Measured counterclockwise from the positive X-axis.
Returns
ScaledBy(PointF, float)
Returns a new PointF whose coordinates are scaled by the specified factor.
public static PointF ScaledBy(this PointF value, float factor)
Parameters
valuePointFThe PointF to scale.
factorfloatThe multiplier applied to both the X and Y coordinates of the point.
Returns
- PointF
A new PointF whose X and Y values are equal to those of the original point multiplied by the specified factor.
WithinEpsilonOf(PointF, PointF, float)
Determines whether the distance between two points is less than the specified epsilon value.
public static bool WithinEpsilonOf(this PointF value, PointF other, float epsilon)
Parameters
valuePointFThe point to compare to
other.otherPointFThe point to compare to
value.epsilonfloatThe maximum allowed distance between the two points for them to be considered within epsilon. Must be non-negative.
Returns
- bool
true if the distance between
valueandotheris less thanepsilon; otherwise, false.