clipper2_sys/double/
path_d.rs1use crate::PointD;
2
3#[derive(Clone, Debug)]
4pub struct PathD(pub(crate) Vec<PointD>);
5
6impl PathD {
7 pub fn new(points: &Vec<PointD>) -> Self {
8 Self(points.clone())
9 }
10
11 pub fn is_empty(&self) -> bool {
12 self.0.is_empty()
13 }
14
15 pub fn len(&self) -> usize {
16 self.0.len()
17 }
18
19 pub fn get_point(&self, index: usize) -> PointD {
20 self.0[index]
21 }
22
23 pub fn add_point(&mut self, point: PointD) {
24 self.0.push(point)
25 }
26
27 pub fn translate(&self, dx: f64, dy: f64) -> Self {
28 let new_points = self
29 .0
30 .iter()
31 .map(|p| PointD {
32 x: p.x + dx,
33 y: p.y + dy,
34 })
35 .collect();
36 Self(new_points)
37 }
38
39 pub fn scale(&self, sx: f64, sy: f64) -> Self {
40 let mut _sx = sx;
41 if _sx == 0. {
42 _sx = 1.;
43 }
44 let mut _sy = sy;
45 if _sy == 0. {
46 _sy = 1.;
47 }
48 let new_points = self
49 .0
50 .iter()
51 .map(|p| PointD {
52 x: p.x * _sx,
53 y: p.y * _sy,
54 })
55 .collect();
56 Self(new_points)
57 }
58}