Class Segment3d
Represents a 3D line segment defined by two endpoints.
public class Segment3d : IExpandToBox3d, IEquatable<Segment3d>, IBinaryIo, IWriteBin, IEnumerable<vec3d_t>, IEnumerable
- Inheritance
-
Segment3d
- Implements
- Inherited Members
- Extension Methods
Constructors
Segment3d()
Initializes a new instance of the Segment3d class with both endpoints unset (NaN), so that HasBothEnds is false until they are assigned.
public Segment3d()
Segment3d(vec3d_t, vec3d_t)
Initializes a new instance of the Segment3d class with endpoints.
public Segment3d(vec3d_t begin, vec3d_t end)
Parameters
Properties
Arrow
Gets the arrow vector from Begin to End.
public vec3d_t Arrow { get; }
Property Value
Begin
The starting point of the segment.
public vec3d_t Begin { get; set; }
Property Value
Center
Gets the midpoint of the segment.
public vec3d_t Center { get; }
Property Value
End
The ending point of the segment.
public vec3d_t End { get; set; }
Property Value
HasBothEnds
True when both endpoints have been set. An unset endpoint is NaN: a segment read back from a stream whose presence flag was clear, or built with Segment3d() and never assigned, has no endpoints and must not be drawn or measured; this is the one place that decides what “unset” looks like for an endpoint.
public bool HasBothEnds { get; }
Property Value
Length
Gets the length of the segment.
public double Length { get; }
Property Value
LengthSquare
The squared length of the segment.
public double LengthSquare { get; }
Property Value
Methods
ClosestPoint(vec3d_t)
Gets the closest point on the segment to the specified point.
public vec3d_t ClosestPoint(vec3d_t point)
Parameters
pointvec3d_tPoint to find closest point to.
Returns
- vec3d_t
Closest point on the segment.
Equals(Segment3d)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Segment3d other)
Parameters
otherSegment3dAn object to compare with this object.
Returns
Equals(object)
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current object.
Returns
ExpandToBox3d(ref box3d_t)
Expands the destination box.
This function is usually used to compute the bounding box of elements.
box3d_t is a value type, so the destination is passed by reference
(the C++ expand_to_box3d(box3&) shape); an implementation writes
dst = dst.Expanded(...) or forwards ref dst to its parts.
public void ExpandToBox3d(ref box3d_t dst)
Parameters
dstbox3d_tDestination box, expanded in place
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<vec3d_t> GetEnumerator()
Returns
- IEnumerator<vec3d_t>
An enumerator that can be used to iterate through the collection.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
PointAt(double)
Gets a point on the segment at the specified parameter t (0 <= t <= 1).
public vec3d_t PointAt(double t)
Parameters
tdoubleParameter value between 0 and 1.
Returns
- vec3d_t
Point on the segment.
ReadBin(BinaryReader)
Reads binary data to initialize the object.
public void ReadBin(BinaryReader reader)
Parameters
readerBinaryReaderThe binary reader to read from
Remarks
A cleared presence flag (written while an endpoint could still be null) reads back as an unset endpoint, NaN.
Swap()
Swaps the begin and end points of the segment.
public void Swap()
ToString()
Returns a string representation of the segment.
public override string ToString()
Returns
WriteBin(BinaryWriter)
Writes the object's data to a binary stream.
public void WriteBin(BinaryWriter writer)
Parameters
writerBinaryWriterThe binary writer to write to
Remarks
The presence flag before each endpoint stays in the stream for the old readers and is always true: an unset endpoint is NaN and is written as such.