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§
Sourcefn rotate_around_centroid(&self, degrees: T) -> Self
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);
Sourcefn rotate_around_centroid_mut(&mut self, degrees: T)
fn rotate_around_centroid_mut(&mut self, degrees: T)
Mutable version of Self::rotate_around_centroid
Sourcefn rotate_around_center(&self, degrees: T) -> Self
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.
Sourcefn rotate_around_center_mut(&mut self, degrees: T)
fn rotate_around_center_mut(&mut self, degrees: T)
Mutable version of Self::rotate_around_center
Sourcefn rotate_around_point(&self, degrees: T, point: Point<T>) -> Self
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),
);
approx::assert_relative_eq!(rotated, line_string![
(x: 2.9289321881345245, y: 7.071067811865475),
(x: 10.0, y: 7.0710678118654755),
(x: 17.071067811865476, y: 7.0710678118654755)
]);
Sourcefn rotate_around_point_mut(&mut self, degrees: T, point: Point<T>)
fn rotate_around_point_mut(&mut self, degrees: T, point: Point<T>)
Mutable version of Self::rotate_around_point
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.