Struct rekee::hexagon::Layout

source ·
pub struct Layout { /* private fields */ }
Expand description

Coefficients for converting between hexagonal grid coordinates and x/y pixels. Used as parameter for different conversion functions.

Implementations§

source§

impl Layout

source

pub fn new(orientation: &Orientation, size: Point, origin: Point) -> Self

Creates a new grid layout, consisting of hexagon orientation parameters, hexagon size in pixels, and the grid origin point.

source

pub fn orientation(&self) -> &Orientation

Returns a reference to the grid orientation parameters.

source

pub fn size(&self) -> Point

Returns the hexagon size of this grid layout.

source

pub fn origin(&self) -> Point

Returns the grid origin point.

source

pub fn is_pointy(&self) -> bool

Returns whether the hexagon orientation is “pointy top” or not.

source

pub fn is_flat(&self) -> bool

Returns whether the hexagon orientation is “flat top” or not.

source

pub fn with_orientation(&self, orientation: &Orientation) -> Self

Creates a copy of this layout with new grid orientation parameters.

source

pub fn with_size(&self, size: Point) -> Self

Creates a copy of this layout with new hexagon size parameters.

source

pub fn with_origin(&self, origin: Point) -> Self

Creates a copy of this layout with new grid origin point.

source

pub fn hexagon_corners(&self, hex: Coordinate) -> [Point; 6]

Calculates the corners of a hexagon with the given coordinate.

source

pub fn hexagon_rect(&self, hex: Coordinate) -> Rect

Calculates the rectangular box of a hexagon with the given coordinate.

source

pub fn direction_to_angle<D>(&self, dir: D) -> f32
where D: Into<FloatDirection>,

Convert a hexagon grid direction into an angle in degrees.

Applies the layout start_angle to the given direction. The returned value is wrapped within a range of 0° to 360°.

§Examples
let layout = Layout::new(Orientation::pointy(), Point(1.0, 1.0), Point(0.0, 0.0));

let dir = Direction::A;
assert_eq!(layout.direction_to_angle(dir), 90.0);

let dir = Direction::B;
assert_eq!(layout.direction_to_angle(dir), 150.0);

let dir = FloatDirection(1.5);
assert_eq!(layout.direction_to_angle(dir), 180.0);
source

pub fn direction_from_angle(&self, value: f32) -> FloatDirection

Convert an angle in degrees into a hexagon grid direction.

Subtracts the layout start_angle from the given angle.

§Examples
let layout = Layout::new(Orientation::pointy(), Point(1.0, 1.0), Point(0.0, 0.0));

let angle = 90.0;
assert_eq!(layout.direction_from_angle(angle), Direction::A.into());

let angle = 150.0;
assert_eq!(layout.direction_from_angle(angle), Direction::B.into());

let angle = 180.0;
assert_eq!(layout.direction_from_angle(angle), FloatDirection(1.5));

Trait Implementations§

source§

impl Clone for Layout

source§

fn clone(&self) -> Layout

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Layout

source§

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

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

impl Default for Layout

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Layout

§

impl RefUnwindSafe for Layout

§

impl Send for Layout

§

impl Sync for Layout

§

impl Unpin for Layout

§

impl UnwindSafe for Layout

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> 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,

§

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>,

§

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>,

§

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.
§

impl<T> Activity for T
where T: Any,