diff options
| author | brian cully <bjc@spork.org> | 2025-12-27 12:58:44 -0500 |
|---|---|---|
| committer | brian cully <bjc@spork.org> | 2025-12-27 12:58:44 -0500 |
| commit | 69591cc5483d36bc819c75dce9347b08b04e33bf (patch) | |
| tree | 93d0f158621c6caea2f54e449a942f45ec829395 /src/line.rs | |
| parent | 0eaa19448a85473e85d4679faa4ab30108dbf4b5 (diff) | |
| download | polyring-69591cc5483d36bc819c75dce9347b08b04e33bf.tar.gz polyring-69591cc5483d36bc819c75dce9347b08b04e33bf.zip | |
add rust/wasm impl
Diffstat (limited to 'src/line.rs')
| -rw-r--r-- | src/line.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/line.rs b/src/line.rs new file mode 100644 index 0000000..07a1f03 --- /dev/null +++ b/src/line.rs @@ -0,0 +1,22 @@ +use crate::point::Point; + +pub struct Line { + p1: Point, + p2: Point, +} + +impl Line { + pub fn new(p1: Point, p2: Point) -> Self { + Self { p1, p2 } + } + + pub fn vec(&self) -> Point { + Point::new(self.p2.x - self.p1.x, self.p2.y - self.p1.y) + } + + pub fn angle_between(&self, other: &Self) -> f64 { + let v1 = self.vec(); + let v2 = other.vec(); + (v1.dot(&v2) / (v1.mag() * v2.mag())).acos() + } +} |
