Skip to main content

use_crease/
lib.rs

1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4use use_point::Point2;
5
6/// A crease classification.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum CreaseKind {
9    /// Mountain crease.
10    Mountain,
11    /// Valley crease.
12    Valley,
13    /// Flat crease.
14    Flat,
15}
16
17/// A crease segment in a flat pattern.
18#[derive(Debug, Clone, Copy, PartialEq)]
19pub struct Crease {
20    start: Point2,
21    end: Point2,
22    kind: CreaseKind,
23}
24
25impl Crease {
26    /// Creates a crease.
27    #[must_use]
28    pub const fn new(start: Point2, end: Point2, kind: CreaseKind) -> Self {
29        Self { start, end, kind }
30    }
31
32    /// Returns the start point.
33    #[must_use]
34    pub const fn start(self) -> Point2 {
35        self.start
36    }
37
38    /// Returns the end point.
39    #[must_use]
40    pub const fn end(self) -> Point2 {
41        self.end
42    }
43
44    /// Returns the crease kind.
45    #[must_use]
46    pub const fn kind(self) -> CreaseKind {
47        self.kind
48    }
49}
50
51#[cfg(test)]
52mod tests {
53    use super::{Crease, CreaseKind};
54    use use_point::Point2;
55
56    #[test]
57    fn stores_crease_lines() {
58        let crease = Crease::new(
59            Point2::origin(),
60            Point2::new(1.0, 0.0),
61            CreaseKind::Mountain,
62        );
63
64        assert_eq!(crease.start(), Point2::origin());
65        assert_eq!(crease.end(), Point2::new(1.0, 0.0));
66        assert_eq!(crease.kind(), CreaseKind::Mountain);
67    }
68}