diff options
| author | Martin <mhaug@live.de> | 2021-04-07 13:50:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-07 13:50:21 +0200 |
| commit | df58a4d89b67783b1ffc5c3b7282302d59db8c70 (patch) | |
| tree | 2bdc3a7ad1704ccee7c14972df1fa3cb9c77097a /src/geom | |
| parent | 318eb9021edc493f5181247dbb7963de34126688 (diff) | |
| parent | 3d2ee54848db80a8ede7e00fd5a53bc059138122 (diff) | |
Merge pull request #19 from typst/shape-runs 🔀
Text work
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/align.rs | 4 | ||||
| -rw-r--r-- | src/geom/length.rs | 5 | ||||
| -rw-r--r-- | src/geom/size.rs | 3 |
3 files changed, 8 insertions, 4 deletions
diff --git a/src/geom/align.rs b/src/geom/align.rs index 422624d8..515efdf2 100644 --- a/src/geom/align.rs +++ b/src/geom/align.rs @@ -13,8 +13,8 @@ pub enum Align { impl Align { /// Returns the position of this alignment in the given range. - pub fn resolve(self, range: Range<Length>) -> Length { - match self { + pub fn resolve(self, dir: Dir, range: Range<Length>) -> Length { + match if dir.is_positive() { self } else { self.inv() } { Self::Start => range.start, Self::Center => (range.start + range.end) / 2.0, Self::End => range.end, diff --git a/src/geom/length.rs b/src/geom/length.rs index 1175876c..1c2a5f86 100644 --- a/src/geom/length.rs +++ b/src/geom/length.rs @@ -81,6 +81,11 @@ impl Length { Self { raw: self.raw.max(other.raw) } } + /// Whether the other length fits into this one (i.e. is smaller). + pub fn fits(self, other: Self) -> bool { + self.raw + 1e-6 >= other.raw + } + /// Whether the length is zero. pub fn is_zero(self) -> bool { self.raw == 0.0 diff --git a/src/geom/size.rs b/src/geom/size.rs index 1ba2f04b..2dd34a87 100644 --- a/src/geom/size.rs +++ b/src/geom/size.rs @@ -28,8 +28,7 @@ impl Size { /// Whether the other size fits into this one (smaller width and height). pub fn fits(self, other: Self) -> bool { - const EPS: Length = Length::raw(1e-6); - self.width + EPS >= other.width && self.height + EPS >= other.height + self.width.fits(other.width) && self.height.fits(other.height) } /// Whether both components are finite. |
