Trait geo::algorithm::affine_ops::AffineOps
source · pub trait AffineOps<T: CoordNum> {
// Required methods
fn affine_transform(&self, transform: &AffineTransform<T>) -> Self;
fn affine_transform_mut(&mut self, transform: &AffineTransform<T>);
}
Expand description
Apply an AffineTransform
like scale
,
skew
, or rotate
to a
Geometry
.
Multiple transformations can be composed in order to be efficiently applied in a single
operation. See AffineTransform
for more on how to build up a transformation.
If you are not composing operations, traits that leverage this same machinery exist which might
be more readable. See: Scale
,
Translate
, Rotate
,
and Skew
.
Examples
Build up transforms by beginning with a constructor, then chaining mutation operations
use geo::{AffineOps, AffineTransform};
use geo::{line_string, BoundingRect, Point, LineString};
use approx::assert_relative_eq;
let ls: LineString = line_string![
(x: 0.0f64, y: 0.0f64),
(x: 0.0f64, y: 10.0f64),
];
let center = ls.bounding_rect().unwrap().center();
let transform = AffineTransform::skew(40.0, 40.0, center).rotated(45.0, center);
let skewed_rotated = ls.affine_transform(&transform);
assert_relative_eq!(skewed_rotated, line_string![
(x: 0.5688687f64, y: 4.4311312),
(x: -0.5688687, y: 5.5688687)
], max_relative = 1.0);
Required Methods§
sourcefn affine_transform(&self, transform: &AffineTransform<T>) -> Self
fn affine_transform(&self, transform: &AffineTransform<T>) -> Self
Apply transform
immutably, outputting a new geometry.
sourcefn affine_transform_mut(&mut self, transform: &AffineTransform<T>)
fn affine_transform_mut(&mut self, transform: &AffineTransform<T>)
Apply transform
to mutate self
.