Table of Contents

Struct FixedTriangle2d

Namespace
FixedMathSharp.Geometry
Assembly
FixedMathSharp.dll

Represents a triangle in two-dimensional fixed-point space.

[MemoryPackable(GenerateType.Object)]
public struct FixedTriangle2d : IEquatable<FixedTriangle2d>, IMemoryPackable<FixedTriangle2d>, IMemoryPackFormatterRegister
Implements
IMemoryPackable<FixedTriangle2d>
IMemoryPackFormatterRegister
Inherited Members

Remarks

MemoryPack GenerateType: unmanaged

FixedMathSharp.Vector2d A
FixedMathSharp.Vector2d B
FixedMathSharp.Vector2d C

Constructors

FixedTriangle2d(Vector2d, Vector2d, Vector2d)

Initializes a triangle from ordered vertices.

[JsonConstructor]
public FixedTriangle2d(Vector2d a, Vector2d b, Vector2d c)

Parameters

a Vector2d
b Vector2d
c Vector2d

Fields

A

The first vertex.

[JsonInclude]
[MemoryPackOrder(0)]
public Vector2d A

Field Value

Vector2d

B

The second vertex.

[JsonInclude]
[MemoryPackOrder(1)]
public Vector2d B

Field Value

Vector2d

C

The third vertex.

[JsonInclude]
[MemoryPackOrder(2)]
public Vector2d C

Field Value

Vector2d

EdgeCount

The number of edges in a triangle.

public const int EdgeCount = 3

Field Value

int

VertexCount

The number of vertices in a triangle.

public const int VertexCount = 3

Field Value

int

Properties

Area

The non-negative saturating magnitude of SignedArea.

[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 Area { get; }

Property Value

Fixed64

Bounds

The normalized axis-aligned area that contains all vertices.

[JsonIgnore]
[MemoryPackIgnore]
public FixedBoundArea Bounds { get; }

Property Value

FixedBoundArea

Centroid

The arithmetic center of the three vertices, averaged independently per component.

[JsonIgnore]
[MemoryPackIgnore]
public Vector2d Centroid { get; }

Property Value

Vector2d

IsDegenerate

Returns true when the exact area magnitude is less than or equal to Epsilon.

[JsonIgnore]
[MemoryPackIgnore]
public bool IsDegenerate { get; }

Property Value

bool

SignedArea

The signed area of the triangle. Positive values indicate counter-clockwise winding.

[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 SignedArea { get; }

Property Value

Fixed64

Remarks

The exact endpoint-difference cross product is halved and converted once with round-half-to-even and signed saturation.

Methods

ClosestPoint(Vector2d)

Finds the closest point on or inside this triangle to the supplied point.

public Vector2d ClosestPoint(Vector2d point)

Parameters

point Vector2d

Returns

Vector2d

Remarks

Edge candidates are compared in AB, BC, CA order with exact squared distances. Exact ties retain the first candidate.

Contains(Vector2d)

Determines whether the point is inside the triangle, including epsilon-wide edges and vertices.

public bool Contains(Vector2d point)

Parameters

point Vector2d

Returns

bool

Remarks

Exact wide orientations make the winding-independent decision before scalar saturation. Collapsed line and point triangles retain edge-distance behavior.

Deconstruct(out Vector2d, out Vector2d, out Vector2d)

Deconstructs the triangle into ordered vertices.

public void Deconstruct(out Vector2d a, out Vector2d b, out Vector2d c)

Parameters

a Vector2d
b Vector2d
c Vector2d

DistanceSquared(Vector2d)

Computes the squared distance from the supplied point to this triangle.

public Fixed64 DistanceSquared(Vector2d point)

Parameters

point Vector2d

Returns

Fixed64

Equals(FixedTriangle2d)

public bool Equals(FixedTriangle2d other)

Parameters

other FixedTriangle2d

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetEdge(int)

Gets an edge by stable index: 0 = AB, 1 = BC, 2 = CA.

public FixedSegment2d GetEdge(int index)

Parameters

index int

Returns

FixedSegment2d

GetHashCode()

public override int GetHashCode()

Returns

int

GetPoint(Fixed64, Fixed64)

Gets the point represented by barycentric weights for vertices B and C.

public Vector2d GetPoint(Fixed64 weightB, Fixed64 weightC)

Parameters

weightB Fixed64
weightC Fixed64

Returns

Vector2d

Remarks

Each component uses the shared full-domain barycentric interpolation contract with one final round-half-to-even/saturating conversion.

GetVertex(int)

Gets a vertex by stable index: 0 = A, 1 = B, 2 = C.

public Vector2d GetVertex(int index)

Parameters

index int

Returns

Vector2d

TryGetBarycentricWeights(Vector2d, out Fixed64, out Fixed64, out Fixed64)

Computes barycentric weights for a point relative to this triangle.

public bool TryGetBarycentricWeights(Vector2d point, out Fixed64 weightA, out Fixed64 weightB, out Fixed64 weightC)

Parameters

point Vector2d
weightA Fixed64
weightB Fixed64
weightC Fixed64

Returns

bool

True when the exact doubled-area magnitude is greater than Epsilon; otherwise false with three zero outputs.

Remarks

The three weights use direct exact area numerators and are rounded and saturated independently. Reversing winding does not change the result.

Operators

operator ==(FixedTriangle2d, FixedTriangle2d)

Determines whether two triangles have the same ordered vertices.

public static bool operator ==(FixedTriangle2d left, FixedTriangle2d right)

Parameters

left FixedTriangle2d
right FixedTriangle2d

Returns

bool

operator !=(FixedTriangle2d, FixedTriangle2d)

Determines whether two triangles have different ordered vertices.

public static bool operator !=(FixedTriangle2d left, FixedTriangle2d right)

Parameters

left FixedTriangle2d
right FixedTriangle2d

Returns

bool