From 15207d15aef96e1d38bd5fd0ee6bd8b6686efb36 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Fri, 13 Nov 2026 21:03:36 -0700 Subject: 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 --- src/geometry.rs | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-) (limited to 'src/geometry.rs') 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 + Ord + Sub { } -impl + Ord + Sub> Coordinate for T { } +pub trait Coordinate: Copy + From + Ord + + Add + Sub { } +impl + Ord + + Add + Sub> + Coordinate for T { } #[derive(Debug)] @@ -49,6 +59,18 @@ pub struct Point { pub y: T, } +#[derive(Debug)] +pub struct Offset { + pub x: T, + pub y: T, +} + +#[derive(Debug)] +pub struct Size { + pub width: T, + pub height: T, +} + #[derive(Debug)] pub struct Rectangle { pub left: T, @@ -57,6 +79,67 @@ pub struct Rectangle { pub height: T, } +impl Point { + pub fn new(x: T, y: T) -> Point { + Point { x, y } + } + + pub fn zero() -> Point { + Point { + x: 0.into(), + y: 0.into(), + } + } + + pub fn add_offset>(&self, offset: &Offset) + -> Point + { + Point { + x: self.x + offset.x.into(), + y: self.y + offset.y.into(), + } + } + + pub fn sub_offset>(&self, offset: &Offset) + -> Point + { + Point { + x: self.x - offset.x.into(), + y: self.y - offset.y.into(), + } + } + + pub fn add_size>(&self, size: &Size) + -> Point + { + Point { + x: self.x + size.width.into(), + y: self.y + size.height.into(), + } + } + + pub fn sub_size>(&self, size: &Size) + -> Point + { + Point { + x: self.x - size.width.into(), + y: self.y - size.height.into(), + } + } +} + +impl Offset { + pub fn new(x: T, y: T) -> Offset { + Offset { x, y } + } +} + +impl Size { + pub fn new(width: T, height: T) -> Size { + Size { width, height } + } +} + impl Rectangle { pub fn corner_point(&self, corner: Corner) -> Point { match corner { -- cgit 1.4.1