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
impl Frame2D
Sourcepub const WORLD: Frame2D
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);Sourcepub fn new(
origin: Point2D,
x_direction: Vector2D,
y_direction: Vector2D,
) -> Result<Frame2D, FrameConstructionError>
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);Sourcepub fn from_x(
origin: Point2D,
x_direction: Vector2D,
) -> Result<Frame2D, FrameConstructionError>
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());Sourcepub fn origin(self) -> Point2D
pub fn origin(self) -> Point2D
Returns the origin point of the frame.
§Examples
use geomcore::{Frame2D, Point2D};
assert_eq!(Frame2D::WORLD.origin(), Point2D::ORIGIN);Sourcepub fn x_direction(self) -> Vector2D
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);Sourcepub fn y_direction(self) -> Vector2D
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);