Skip to main content

pivot_pdf/
graphics.rs

1/// An angle value that can be specified in either degrees or radians.
2///
3/// Used by [`PdfDocument::arc`] to accept angles in either unit without
4/// requiring separate methods.
5#[derive(Debug, Clone, Copy, PartialEq)]
6pub struct Angle(f64); // stored in radians
7
8impl Angle {
9    /// Create an angle from degrees.
10    pub fn degrees(deg: f64) -> Self {
11        Angle(deg.to_radians())
12    }
13
14    /// Create an angle from radians.
15    pub fn radians(rad: f64) -> Self {
16        Angle(rad)
17    }
18
19    /// Return the angle in radians.
20    pub fn to_radians(self) -> f64 {
21        self.0
22    }
23}
24
25/// RGB color for PDF graphics operations.
26///
27/// Each component is in the range 0.0 (none) to 1.0 (full intensity).
28#[derive(Debug, Clone, Copy, PartialEq)]
29pub struct Color {
30    /// Red component (0.0–1.0).
31    pub r: f64,
32    /// Green component (0.0–1.0).
33    pub g: f64,
34    /// Blue component (0.0–1.0).
35    pub b: f64,
36}
37
38impl Color {
39    /// Create a color from RGB components (each 0.0–1.0).
40    pub fn rgb(r: f64, g: f64, b: f64) -> Self {
41        Color { r, g, b }
42    }
43
44    /// Create a grayscale color (r = g = b = level).
45    pub fn gray(level: f64) -> Self {
46        Color {
47            r: level,
48            g: level,
49            b: level,
50        }
51    }
52}