clipper2_sys/int64/
path_64.rs1use crate::Point64;
2
3#[derive(Clone, Debug)]
4pub struct Path64(pub(crate) Vec<Point64>);
5
6impl Path64 {
7 pub fn new(points: &Vec<Point64>) -> 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) -> Point64 {
20 self.0[index]
21 }
22
23 pub fn add_point(&mut self, point: Point64) {
24 self.0.push(point)
25 }
26
27 pub fn translate(&self, dx: i64, dy: i64) -> Self {
28 let new_points = self
29 .0
30 .iter()
31 .map(|p| Point64 {
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| Point64 {
52 x: ((p.x as f64) * sx) as i64,
53 y: ((p.y as f64) * sy) as i64,
54 })
55 .collect();
56 Self(new_points)
57 }
58}