Struct Segment2
pub struct Segment2 { /* private fields */ }Expand description
A finite line segment between two 2D points.
Implementations§
§impl Segment2
impl Segment2
pub fn try_new(start: Point2, end: Point2) -> Result<Segment2, GeometryError>
pub fn try_new(start: Point2, end: Point2) -> Result<Segment2, GeometryError>
Creates a segment from start to end with finite point coordinates.
§Errors
Returns GeometryError::NonFiniteComponent when either input point
contains a non-finite coordinate.
§Examples
use use_geometry::{GeometryError, Point2, Segment2};
let segment = Segment2::try_new(Point2::new(0.0, 0.0), Point2::new(4.0, 2.0))?;
assert_eq!(segment.midpoint(), Point2::new(2.0, 1.0));pub fn length_squared(self) -> f64
pub fn length_squared(self) -> f64
Returns the squared segment length.
pub const fn point_at(self, t: f64) -> Point2
pub const fn point_at(self, t: f64) -> Point2
Returns the point at parameter t along the segment.
§Examples
use use_geometry::{Point2, Segment2};
let segment = Segment2::new(Point2::new(0.0, 0.0), Point2::new(4.0, 2.0));
assert_eq!(segment.point_at(0.25), Point2::new(1.0, 0.5));pub const fn reversed(self) -> Segment2
pub const fn reversed(self) -> Segment2
Returns the segment with its endpoints reversed.
§Examples
use use_geometry::{Point2, Segment2};
let segment = Segment2::new(Point2::new(1.0, 2.0), Point2::new(4.0, 6.0));
assert_eq!(segment.reversed().start(), Point2::new(4.0, 6.0));
assert_eq!(segment.reversed().end(), Point2::new(1.0, 2.0));pub fn is_degenerate(self) -> bool
pub fn is_degenerate(self) -> bool
Returns true when the segment collapses to a single point.
pub fn is_degenerate_with_tolerance(
self,
tolerance: f64,
) -> Result<bool, GeometryError>
pub fn is_degenerate_with_tolerance( self, tolerance: f64, ) -> Result<bool, GeometryError>
Returns true when the segment length is within tolerance of zero.
§Errors
Returns GeometryError::NonFiniteTolerance when tolerance is NaN
or infinite.
Returns GeometryError::NegativeTolerance when tolerance is negative.
§Examples
use use_geometry::{GeometryError, Point2, Segment2};
let segment = Segment2::new(Point2::new(2.0, 2.0), Point2::new(2.0, 2.0));
assert!(segment.is_degenerate_with_tolerance(0.0)?);Trait Implementations§
impl Copy for Segment2
impl StructuralPartialEq for Segment2
Auto Trait Implementations§
impl Freeze for Segment2
impl RefUnwindSafe for Segment2
impl Send for Segment2
impl Sync for Segment2
impl Unpin for Segment2
impl UnsafeUnpin for Segment2
impl UnwindSafe for Segment2
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more