Struct Position

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

Represents the size, location and centerpoint of a shape. We align shapes along their center points, and have edges directed at the center. Shapes like Box and Circle have their center point in the middle, but labels have their center point in one of the sides to make sure that edges don’t obscure the text. The halo is the gap around the shape where nothing can be placed and it is applied symmetrically to the sides.

This struct has fields that represent the following points:


| _____________ | | | | | | | | | | | M <––|—|–the middle of the shape, in absolute coordinates. | | C <-|—|–the center point, saved as delta, relative to M. | |_____________| | | ^—|— the size of the shape. |____________________| <—– size + halo.

Implementations§

Source§

impl Position

Source

pub fn new(middle: Point, size: Point, center: Point, halo: Point) -> Self

Source

pub fn distance_to_left(&self, with_halo: bool) -> f64

Source

pub fn distance_to_right(&self, with_halo: bool) -> f64

Source

pub fn left(&self, with_halo: bool) -> f64

Source

pub fn right(&self, with_halo: bool) -> f64

Source

pub fn top(&self, with_halo: bool) -> f64

Source

pub fn bottom(&self, with_halo: bool) -> f64

Source

pub fn bbox(&self, with_halo: bool) -> (Point, Point)

Source

pub fn center(&self) -> Point

Returns the center of the shape in absolute coordinates.

Source

pub fn middle(&self) -> Point

Returns the middle of the shape. (not center!)

Source

pub fn size(&self, with_halo: bool) -> Point

Source

pub fn in_x_range(&self, range: (f64, f64), with_halo: bool) -> bool

\return True if the box fits within the x ranges of \p range.

Source

pub fn set_size(&mut self, size: Point)

Source

pub fn set_new_center_point(&mut self, center: Point)

Update the center point for the shape. This is expressed as the delta from the center of mass (middle-point).

Source

pub fn move_to(&mut self, p: Point)

Source

pub fn align_to_top(&mut self, y: f64)

Source

pub fn align_to_left(&mut self, x: f64)

Source

pub fn align_to_right(&mut self, x: f64)

Source

pub fn translate(&mut self, d: Point)

Source

pub fn align_x(&mut self, x: f64, to_left: bool)

Align the shape to the line \p x, to the right or the left, depending on \p to_left.

Source

pub fn set_x(&mut self, x: f64)

Source

pub fn set_y(&mut self, y: f64)

Source

pub fn transpose(&mut self)

Trait Implementations§

Source§

impl Clone for Position

Source§

fn clone(&self) -> Position

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Position

Source§

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

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

impl Copy for Position

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.