Table of Contents

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

value PointF

The 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

value PointF

The first point from which to measure the distance.

other PointF

The second point to which the distance is measured.

Returns

float

The straight-line distance between value and other, 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

value PointF

The first point to use in the dot product calculation.

other PointF

The 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

value Point

The 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

value PointF

The 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

value PointF

The 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

value PointF

The point to be projected onto the direction vector.

direction PointF

The direction vector along which to project the point. Does not need to be normalized.

Returns

PointF

A new PointF representing the projection of value onto direction.

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

value PointF

The point to project.

angleInDegrees float

The angle, in degrees, specifying the direction of the projection. Measured counterclockwise from the positive X-axis.

Returns

PointF

A new PointF representing the projection of the original point along the specified angle.

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

value PointF

The PointF to scale.

factor float

The 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

value PointF

The point to compare to other.

other PointF

The point to compare to value.

epsilon float

The 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 value and other is less than epsilon; otherwise, false.