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
Fields
A
The first vertex.
[JsonInclude]
[MemoryPackOrder(0)]
public Vector2d A
Field Value
B
The second vertex.
[JsonInclude]
[MemoryPackOrder(1)]
public Vector2d B
Field Value
C
The third vertex.
[JsonInclude]
[MemoryPackOrder(2)]
public Vector2d C
Field Value
EdgeCount
The number of edges in a triangle.
public const int EdgeCount = 3
Field Value
VertexCount
The number of vertices in a triangle.
public const int VertexCount = 3
Field Value
Properties
Area
The non-negative saturating magnitude of SignedArea.
[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 Area { get; }
Property Value
Bounds
The normalized axis-aligned area that contains all vertices.
[JsonIgnore]
[MemoryPackIgnore]
public FixedBoundArea Bounds { get; }
Property Value
Centroid
The arithmetic center of the three vertices, averaged independently per component.
[JsonIgnore]
[MemoryPackIgnore]
public Vector2d Centroid { get; }
Property Value
IsDegenerate
Returns true when the exact area magnitude is less than or equal to Epsilon.
[JsonIgnore]
[MemoryPackIgnore]
public bool IsDegenerate { get; }
Property Value
SignedArea
The signed area of the triangle. Positive values indicate counter-clockwise winding.
[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 SignedArea { get; }
Property Value
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
pointVector2d
Returns
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
pointVector2d
Returns
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
DistanceSquared(Vector2d)
Computes the squared distance from the supplied point to this triangle.
public Fixed64 DistanceSquared(Vector2d point)
Parameters
pointVector2d
Returns
Equals(FixedTriangle2d)
public bool Equals(FixedTriangle2d other)
Parameters
otherFixedTriangle2d
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
GetEdge(int)
Gets an edge by stable index: 0 = AB, 1 = BC, 2 = CA.
public FixedSegment2d GetEdge(int index)
Parameters
indexint
Returns
GetHashCode()
public override int GetHashCode()
Returns
GetPoint(Fixed64, Fixed64)
Gets the point represented by barycentric weights for vertices B and C.
public Vector2d GetPoint(Fixed64 weightB, Fixed64 weightC)
Parameters
Returns
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
indexint
Returns
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
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
leftFixedTriangle2drightFixedTriangle2d
Returns
operator !=(FixedTriangle2d, FixedTriangle2d)
Determines whether two triangles have different ordered vertices.
public static bool operator !=(FixedTriangle2d left, FixedTriangle2d right)
Parameters
leftFixedTriangle2drightFixedTriangle2d