pub struct Matrix { /* private fields */ }
Expand description
A transformation matrix for the pdf graphics state.
Matrixes can be created with numerous named constructors and combined by multiplication.
§Examples
canvas.concat(Matrix::translate(10.0, 24.0))?;
// Matrixes can be combined by multiplication:
canvas.concat(Matrix::translate(7.0, 0.0) * Matrix::rotate_deg(45.0))?;
// ... will be visualy identical to:
canvas.concat(Matrix::translate(7.0, 0.0))?;
canvas.concat(Matrix::rotate_deg(45.0))?;
Implementations§
Source§impl Matrix
impl Matrix
Sourcepub fn translate(dx: f32, dy: f32) -> Self
pub fn translate(dx: f32, dy: f32) -> Self
Construct a matrix for translation
Examples found in repository?
examples/mandala.rs (line 19)
10fn main() {
11 // Open our pdf document.
12 let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13 let mut args = env::args().skip(1);
14 let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16 // Render a page with something resembling a mandala on it.
17 document
18 .render_page(600.0, 600.0, |c| {
19 c.concat(Matrix::translate(300., 300.))?;
20 c.set_stroke_color(Color::gray(0))?;
21 let segment = 2. * PI / n as f32;
22 for _i in 0..n {
23 c.move_to(0., 33.5)?;
24 c.line_to(0., 250.)?;
25 let r = 99.;
26 c.circle(0., r, r * 1.25 * segment)?;
27 let d = 141.4;
28 let rr = 36.;
29 c.circle(0., d + rr, rr)?;
30 c.stroke()?;
31 c.concat(Matrix::rotate(segment))?;
32 }
33 c.concat(Matrix::rotate(segment / 2.))?;
34 for _i in 0..n {
35 let mut r0 = 58.66;
36 let mut r = 0.7705 * r0 * segment;
37 for _j in 0..(n + 1) / 3 {
38 c.circle(0., r0, r)?;
39 let r2 = 1.058 * r;
40 r0 = r0 + r + r2;
41 r = r2;
42 }
43 c.stroke()?;
44 c.concat(Matrix::rotate(segment))?;
45 }
46
47 Ok(())
48 })
49 .unwrap();
50 document.finish().unwrap();
51}
Sourcepub fn rotate(a: f32) -> Self
pub fn rotate(a: f32) -> Self
Construct a matrix for rotating by a
radians.
Examples found in repository?
examples/mandala.rs (line 31)
10fn main() {
11 // Open our pdf document.
12 let mut document = Pdf::create("mandala.pdf").expect("Create PDF file");
13 let mut args = env::args().skip(1);
14 let n: u8 = args.next().map(|s| s.parse().expect("number")).unwrap_or(7);
15
16 // Render a page with something resembling a mandala on it.
17 document
18 .render_page(600.0, 600.0, |c| {
19 c.concat(Matrix::translate(300., 300.))?;
20 c.set_stroke_color(Color::gray(0))?;
21 let segment = 2. * PI / n as f32;
22 for _i in 0..n {
23 c.move_to(0., 33.5)?;
24 c.line_to(0., 250.)?;
25 let r = 99.;
26 c.circle(0., r, r * 1.25 * segment)?;
27 let d = 141.4;
28 let rr = 36.;
29 c.circle(0., d + rr, rr)?;
30 c.stroke()?;
31 c.concat(Matrix::rotate(segment))?;
32 }
33 c.concat(Matrix::rotate(segment / 2.))?;
34 for _i in 0..n {
35 let mut r0 = 58.66;
36 let mut r = 0.7705 * r0 * segment;
37 for _j in 0..(n + 1) / 3 {
38 c.circle(0., r0, r)?;
39 let r2 = 1.058 * r;
40 r0 = r0 + r + r2;
41 r = r2;
42 }
43 c.stroke()?;
44 c.concat(Matrix::rotate(segment))?;
45 }
46
47 Ok(())
48 })
49 .unwrap();
50 document.finish().unwrap();
51}
Sourcepub fn rotate_deg(a: f32) -> Self
pub fn rotate_deg(a: f32) -> Self
Construct a matrix for rotating by a
degrees.
Sourcepub fn scale(sx: f32, sy: f32) -> Self
pub fn scale(sx: f32, sy: f32) -> Self
Construct a matrix for scaling by factor sx
in x-direction
and by sy
in y-direction.
Sourcepub fn uniform_scale(s: f32) -> Self
pub fn uniform_scale(s: f32) -> Self
Construct a matrix for scaling by the same factor, s
in both
directions.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Matrix
impl RefUnwindSafe for Matrix
impl Send for Matrix
impl Sync for Matrix
impl Unpin for Matrix
impl UnwindSafe for Matrix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more