1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use pyo3::prelude::*;

/// Represents a line segment between two points.
#[pyclass]
pub struct LineSegment {
    startx: f64,
    endx: f64,
    starty: f64,
    endy: f64,

}

#[pymethods]
impl LineSegment {
    #[new]
    fn new(startx: f64,starty: f64, endx: f64, endy: f64) -> Self {
        LineSegment {startx,starty, endx, endy}
    }

    /// Calculates the length of the line segment.
    ///
    /// Returns:
    /// - `f64`: Length of the line segment.
    fn length(&self) -> f64 {
        ((self.endx - self.startx).powi(2) + (self.endy - self.starty).powi(2)).sqrt()
    }

    /// Calculates the midpoint of the line segment.
    ///
    /// Returns:
    /// - `Point`: Midpoint of the line segment.
    fn midpoint(&self) -> (f64,f64) {
            ((self.startx + self.endx) / 2.0,(self.starty + self.endy) / 2.0)
    }
}