about summary refs log tree commit diff
path: root/src/geometry.rs
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-13 21:03:36 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-13 21:03:36 -0700
commit15207d15aef96e1d38bd5fd0ee6bd8b6686efb36 (patch)
tree9ba6b372fd1976f4538a059f8da5f1374e1943fc /src/geometry.rs
parente521722f5fd339ef72ee51af88f3941b71b1d9cf (diff)
messing with metrics
thus far, everything is reverse engineered and documented. we're about as confident as we can be of these descriptions, without searching Usenet for historical nuance or reading the xft source.

in future work, it will be necessary to pick some specific characters to measure to reverse-engineer the desirable metrics.

Force-Push: yes
Change-Id: I54c7afb825909688d5a9b3f80974d76a69655796
Diffstat (limited to 'src/geometry.rs')
-rw-r--r--src/geometry.rs89
1 files changed, 86 insertions, 3 deletions
diff --git a/src/geometry.rs b/src/geometry.rs
index 3d25b5d..77f7a61 100644
--- a/src/geometry.rs
+++ b/src/geometry.rs
@@ -1,5 +1,12 @@
-use std::ops::Sub;
+/*   It is the nature of mathematical objects to have many small features
+ * which are not all needed in practice.
+ */
+#![allow(dead_code)]
 
+use std::ops::{ Add, Sub };
+
+#[derive(Clone, Copy, PartialEq, Eq)]
+pub enum Alignment { Left, Right }
 
 #[derive(Clone, Copy, PartialEq, Eq)]
 pub enum Side { Top, Bottom, Left, Right }
@@ -39,8 +46,11 @@ impl Corner {
 }
 
 
-pub trait Coordinate: Copy + From<u8> + Ord + Sub<Output=Self> { }
-impl<T: Copy + From<u8> + Ord + Sub<Output=T>> Coordinate for T { }
+pub trait Coordinate: Copy + From<u8> + Ord
+                      + Add<Output=Self> + Sub<Output=Self> { }
+impl<T: Copy + From<u8> + Ord
+        + Add<Output=T> + Sub<Output=T>>
+    Coordinate for T { }
 
 
 #[derive(Debug)]
@@ -50,6 +60,18 @@ pub struct Point<T: Coordinate> {
 }
 
 #[derive(Debug)]
+pub struct Offset<T: Coordinate> {
+  pub x: T,
+  pub y: T,
+}
+
+#[derive(Debug)]
+pub struct Size<T: Coordinate> {
+  pub width: T,
+  pub height: T,
+}
+
+#[derive(Debug)]
 pub struct Rectangle<T: Coordinate> {
   pub left: T,
   pub top: T,
@@ -57,6 +79,67 @@ pub struct Rectangle<T: Coordinate> {
   pub height: T,
 }
 
+impl<T: Coordinate> Point<T> {
+  pub fn new(x: T, y: T) -> Point<T> {
+    Point { x, y }
+  }
+
+  pub fn zero() -> Point<T> {
+    Point {
+      x: 0.into(),
+      y: 0.into(),
+    }
+  }
+
+  pub fn add_offset<U: Coordinate + Into<T>>(&self, offset: &Offset<U>)
+    -> Point<T>
+  {
+    Point {
+      x: self.x + offset.x.into(),
+      y: self.y + offset.y.into(),
+    }
+  }
+
+  pub fn sub_offset<U: Coordinate + Into<T>>(&self, offset: &Offset<U>)
+    -> Point<T>
+  {
+    Point {
+      x: self.x - offset.x.into(),
+      y: self.y - offset.y.into(),
+    }
+  }
+
+  pub fn add_size<U: Coordinate + Into<T>>(&self, size: &Size<U>)
+    -> Point<T>
+  {
+    Point {
+      x: self.x + size.width.into(),
+      y: self.y + size.height.into(),
+    }
+  }
+
+  pub fn sub_size<U: Coordinate + Into<T>>(&self, size: &Size<T>)
+    -> Point<T>
+  {
+    Point {
+      x: self.x - size.width.into(),
+      y: self.y - size.height.into(),
+    }
+  }
+}
+
+impl<T: Coordinate> Offset<T> {
+  pub fn new(x: T, y: T) -> Offset<T> {
+    Offset { x, y }
+  }
+}
+
+impl<T: Coordinate> Size<T> {
+  pub fn new(width: T, height: T) -> Size<T> {
+    Size { width, height }
+  }
+}
+
 impl<T: Coordinate> Rectangle<T> {
   pub fn corner_point(&self, corner: Corner) -> Point<T> {
     match corner {