Trait geo::algorithm::rotate::Rotate

source ·
pub trait Rotate<T: CoordFloat> {
    // Required methods
    fn rotate_around_centroid(&self, degrees: T) -> Self;
    fn rotate_around_centroid_mut(&mut self, degrees: T);
    fn rotate_around_center(&self, degrees: T) -> Self;
    fn rotate_around_center_mut(&mut self, degrees: T);
    fn rotate_around_point(&self, degrees: T, point: Point<T>) -> Self;
    fn rotate_around_point_mut(&mut self, degrees: T, point: Point<T>);
}
Expand description

Rotate a geometry around a point by an angle, in degrees.

Positive angles are counter-clockwise, and negative angles are clockwise rotations.

Performance

If you will be performing multiple transformations, like Scale, Skew, Translate, or Rotate, it is more efficient to compose the transformations and apply them as a single operation using the AffineOps trait.

Required Methods§

source

fn rotate_around_centroid(&self, degrees: T) -> Self

Rotate a geometry around its centroid by an angle, in degrees

Positive angles are counter-clockwise, and negative angles are clockwise rotations.

Examples
use geo::Rotate;
use geo::line_string;
use approx::assert_relative_eq;

let line_string = line_string![
    (x: 0.0, y: 0.0),
    (x: 5.0, y: 5.0),
    (x: 10.0, y: 10.0),
];

let rotated = line_string.rotate_around_centroid(-45.0);

let expected = line_string![
    (x: -2.071067811865475, y: 5.0),
    (x: 5.0, y: 5.0),
    (x: 12.071067811865476, y: 5.0),
];

assert_relative_eq!(expected, rotated);
source

fn rotate_around_centroid_mut(&mut self, degrees: T)

Mutable version of Self::rotate_around_centroid

source

fn rotate_around_center(&self, degrees: T) -> Self

Rotate a geometry around the center of its bounding box by an angle, in degrees.

Positive angles are counter-clockwise, and negative angles are clockwise rotations.

source

fn rotate_around_center_mut(&mut self, degrees: T)

Mutable version of Self::rotate_around_center

source

fn rotate_around_point(&self, degrees: T, point: Point<T>) -> Self

Rotate a Geometry around an arbitrary point by an angle, given in degrees

Positive angles are counter-clockwise, and negative angles are clockwise rotations.

Examples
use geo::Rotate;
use geo::{line_string, point};

let ls = line_string![
    (x: 0.0, y: 0.0),
    (x: 5.0, y: 5.0),
    (x: 10.0, y: 10.0)
];

let rotated = ls.rotate_around_point(
    -45.0,
    point!(x: 10.0, y: 0.0),
);

assert_eq!(rotated, line_string![
    (x: 2.9289321881345245, y: 7.071067811865475),
    (x: 10.0, y: 7.0710678118654755),
    (x: 17.071067811865476, y: 7.0710678118654755)
]);
source

fn rotate_around_point_mut(&mut self, degrees: T, point: Point<T>)

Mutable version of Self::rotate_around_point

Implementors§

source§

impl<G, IP, IR, T> Rotate<T> for Gwhere T: CoordFloat, IP: Into<Option<Point<T>>>, IR: Into<Option<Rect<T>>>, G: Clone + Centroid<Output = IP> + BoundingRect<T, Output = IR> + AffineOps<T>,