Skip to main content

Frame2D

Struct Frame2D 

Source
pub struct Frame2D { /* private fields */ }
Expand description

A 2D coordinate frame: an origin and two orthogonal unit directions (x, y). The pair may be either direct (counterclockwise, x × y > 0) or indirect (clockwise); see Frame2D::is_direct.

§Examples

use geomcore::Frame2D;
let f = Frame2D::WORLD;
assert!(f.is_direct());

Implementations§

Source§

impl Frame2D

Source

pub const WORLD: Frame2D

The world frame: origin at Point2D::ORIGIN, axes aligned with Vector2D::X, Vector2D::Y.

§Examples
use geomcore::{Frame2D, Point2D, Vector2D};
assert_eq!(Frame2D::WORLD.origin(), Point2D::ORIGIN);
assert_eq!(Frame2D::WORLD.x_direction(), Vector2D::X);
Source

pub fn new( origin: Point2D, x_direction: Vector2D, y_direction: Vector2D, ) -> Result<Frame2D, FrameConstructionError>

Creates a frame from an origin and two directions.

Both directions are normalized independently; the resulting pair is stored as given (either handedness is accepted).

§Errors

Returns FrameConstructionError::NullDirection if either direction cannot be normalized (zero length), FrameConstructionError::NotOrthogonal if the normalized directions are not orthogonal (|x·y| > the default angular tolerance, 1e-12: further off square, the frame would move points across the model by more than the confusion tolerance), or FrameConstructionError::NonFinite if any input coordinate is NaN or infinite.

§Examples
use geomcore::{Frame2D, Point2D, Vector2D};
let f = Frame2D::new(Point2D::ORIGIN, Vector2D::X, Vector2D::Y).unwrap();
assert_eq!(f.x_direction(), Vector2D::X);
assert_eq!(f.y_direction(), Vector2D::Y);
Source

pub fn from_x( origin: Point2D, x_direction: Vector2D, ) -> Result<Frame2D, FrameConstructionError>

Creates a direct frame from an origin and an x direction; y is the counterclockwise perpendicular of x.

§Errors

Returns FrameConstructionError::NullDirection if x_direction cannot be normalized (zero length), or FrameConstructionError::NonFinite if any input coordinate is NaN or infinite.

§Examples
use geomcore::{Frame2D, Point2D, Vector2D};
let f = Frame2D::from_x(Point2D::ORIGIN, Vector2D::new(0.6, 0.8)).unwrap();
assert_eq!(f.y_direction(), Vector2D::new(-0.8, 0.6));
assert!(f.is_direct());
Source

pub fn origin(self) -> Point2D

Returns the origin point of the frame.

§Examples
use geomcore::{Frame2D, Point2D};
assert_eq!(Frame2D::WORLD.origin(), Point2D::ORIGIN);
Source

pub fn x_direction(self) -> Vector2D

Returns the unit x direction of the frame.

§Examples
use geomcore::{Frame2D, Vector2D};
assert_eq!(Frame2D::WORLD.x_direction(), Vector2D::X);
Source

pub fn y_direction(self) -> Vector2D

Returns the unit y direction of the frame.

§Examples
use geomcore::{Frame2D, Vector2D};
assert_eq!(Frame2D::WORLD.y_direction(), Vector2D::Y);
Source

pub fn is_direct(self) -> bool

Returns whether the frame is direct (counterclockwise, x × y > 0).

§Examples
use geomcore::Frame2D;
assert!(Frame2D::WORLD.is_direct());

Trait Implementations§

Source§

impl Clone for Frame2D

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Frame2D

Source§

impl Debug for Frame2D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Frame2D

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Frame2D

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.