Skip to main content

Angle

Enum Angle 

Source
pub enum Angle {
    Degree(f64),
    Radian(f64),
}
Expand description

Angles

Variants§

§

Degree(f64)

§

Radian(f64)

Implementations§

Source§

impl Angle

Source

pub fn to_degree(self) -> f64

Get the angle in degrees

Source

pub fn to_radian(self) -> f64

Get the angle in radians

Examples found in repository?
examples/sunflower.rs (line 18)
4fn main() {
5    let points = Vogel::golden_builder()
6        .seeds(256)
7        .scaling_factor(50.0)
8        .build();
9    let mut canvas = Canvas::builder()
10        .size(2560.0, 1440.0)
11        .background_color("#fcba03".try_into().unwrap())
12        .points(points)
13        .build();
14
15    let polygon_builder = || {
16        Polygon::builder()
17            .sides(4)
18            .rotation_fn(move |n: &usize| Angle::Radian(*n as f64 * points.angle.to_radian()))
19    };
20    canvas.add_shape(
21        polygon_builder()
22            .size(100.0)
23            .color("#3d2f06".try_into().unwrap())
24            .build(),
25    );
26    canvas.add_shape(
27        polygon_builder()
28            .size(20.0)
29            .color("#dedbd5".try_into().unwrap())
30            .build(),
31    );
32
33    let document = canvas.render(|_| true);
34    svg::save("examples/sunflower.svg", &document).unwrap();
35}
More examples
Hide additional examples
examples/placemat.rs (line 21)
5fn main() {
6    let mut rng = rand::rng();
7
8    let lattice = Lattice::builder()
9        .grid_size(rng.random_range(5..50), rng.random_range(1..50))
10        .len_a(rng.random_range(100.0..400.0))
11        .len_b(rng.random_range(100.0..400.0))
12        .theta(Angle::Degree(rng.random_range(0.0..90.0)))
13        .build();
14    let mut canvas_builder = Canvas::builder()
15        .size(2560.0, 1440.0)
16        .background_color("#e0d8d1".try_into().unwrap())
17        .points(lattice);
18
19    let size = rng
20        .random_range(100.0..lattice.len_a)
21        .min(rng.random_range(100.0..lattice.len_b) * lattice.theta.to_radian().sin());
22
23    canvas_builder.add_shape(
24        Polygon::builder()
25            .sides_fn(|_| rand::rng().random_range(3..8))
26            .size(size)
27            .color_fn(|_| {
28                vec![
29                    "#6f6e6a", "#b3b4af", "#b09e90", "#bea24e", "#d9bdb9", "#9a9ba0",
30                ]
31                .choose(&mut rand::rng())
32                .copied()
33                .unwrap()
34                .try_into()
35                .unwrap()
36            })
37            .cv_fn(|_| rand::rng().random_range(0.1..0.5) / 6.0)
38            .build(),
39    );
40
41    let canvas = canvas_builder.build();
42
43    let document = canvas.render(|_| rand::rng().random_bool(0.9));
44    svg::save("examples/placemat.svg", &document).unwrap();
45}

Trait Implementations§

Source§

impl Add for Angle

Source§

type Output = Angle

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign for Angle

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Angle

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 Angle

Source§

impl Debug for Angle

Source§

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

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

impl Default for Angle

Source§

fn default() -> Self

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

impl Mul<f64> for Angle

Source§

type Output = Angle

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self::Output

Performs the * operation. Read more

Auto Trait Implementations§

§

impl Forget for Angle

§

impl Freeze for Angle

§

impl Move for Angle

§

impl RefUnwindSafe for Angle

§

impl Send for Angle

§

impl Sync for Angle

§

impl Unpin for Angle

§

impl UnsafeUnpin for Angle

§

impl UnwindSafe for Angle

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.