atagen

monolith

public
Star0
Watch0
2b30c550f0a9f11a2038f87ce6b24a3a7ebcd137
1
ssh://brewery@pls.lobotomise.me:33/atagen/monolith.git

Blame: crates/planner/src/relation.rs

b563d2da1c80atagen2026-10-16 08:25 UTC1
use crate::geom::Rect;
b563d2da1c80atagen2026-10-16 08:25 UTC2
b563d2da1c80atagen2026-10-16 08:25 UTC3
pub(crate) const LEFT: u8 = 1;
b563d2da1c80atagen2026-10-16 08:25 UTC4
pub(crate) const RIGHT: u8 = 2;
b563d2da1c80atagen2026-10-16 08:25 UTC5
pub(crate) const ABOVE: u8 = 4;
b563d2da1c80atagen2026-10-16 08:25 UTC6
pub(crate) const BELOW: u8 = 8;
b563d2da1c80atagen2026-10-16 08:25 UTC7
pub(crate) const X_BITS: u8 = LEFT | RIGHT;
b563d2da1c80atagen2026-10-16 08:25 UTC8
pub(crate) const Y_BITS: u8 = ABOVE | BELOW;
b563d2da1c80atagen2026-10-16 08:25 UTC9
b563d2da1c80atagen2026-10-16 08:25 UTC10
/// Which ways `a` is apart from `b`. Touching edges count as apart.
b563d2da1c80atagen2026-10-16 08:25 UTC11
pub(crate) fn separation(a: &Rect, b: &Rect, eps: f64) -> u8 {
b563d2da1c80atagen2026-10-16 08:25 UTC12
    let mut s = 0;
b563d2da1c80atagen2026-10-16 08:25 UTC13
    if a.right() <= b.x + eps {
b563d2da1c80atagen2026-10-16 08:25 UTC14
        s |= LEFT;
b563d2da1c80atagen2026-10-16 08:25 UTC15
    }
b563d2da1c80atagen2026-10-16 08:25 UTC16
    if b.right() <= a.x + eps {
b563d2da1c80atagen2026-10-16 08:25 UTC17
        s |= RIGHT;
b563d2da1c80atagen2026-10-16 08:25 UTC18
    }
b563d2da1c80atagen2026-10-16 08:25 UTC19
    if a.bottom() <= b.y + eps {
b563d2da1c80atagen2026-10-16 08:25 UTC20
        s |= ABOVE;
b563d2da1c80atagen2026-10-16 08:25 UTC21
    }
b563d2da1c80atagen2026-10-16 08:25 UTC22
    if b.bottom() <= a.y + eps {
b563d2da1c80atagen2026-10-16 08:25 UTC23
        s |= BELOW;
b563d2da1c80atagen2026-10-16 08:25 UTC24
    }
b563d2da1c80atagen2026-10-16 08:25 UTC25
    s
b563d2da1c80atagen2026-10-16 08:25 UTC26
}
b563d2da1c80atagen2026-10-16 08:25 UTC27
b563d2da1c80atagen2026-10-16 08:25 UTC28
/// Which sides of `a` sit against `b`, at most one gap apart and facing each other.
b563d2da1c80atagen2026-10-16 08:25 UTC29
pub(crate) fn adjacency(a: &Rect, b: &Rect, gap: f64, eps: f64) -> u8 {
b563d2da1c80atagen2026-10-16 08:25 UTC30
    let overlap_x = a.x < b.right() + eps && b.x < a.right() + eps;
b563d2da1c80atagen2026-10-16 08:25 UTC31
    let overlap_y = a.y < b.bottom() + eps && b.y < a.bottom() + eps;
b563d2da1c80atagen2026-10-16 08:25 UTC32
    let near = |d: f64| d.abs() <= gap + eps;
b563d2da1c80atagen2026-10-16 08:25 UTC33
    let mut s = 0;
b563d2da1c80atagen2026-10-16 08:25 UTC34
    if overlap_y && near(b.x - a.right()) {
b563d2da1c80atagen2026-10-16 08:25 UTC35
        s |= LEFT;
b563d2da1c80atagen2026-10-16 08:25 UTC36
    }
b563d2da1c80atagen2026-10-16 08:25 UTC37
    if overlap_y && near(a.x - b.right()) {
b563d2da1c80atagen2026-10-16 08:25 UTC38
        s |= RIGHT;
b563d2da1c80atagen2026-10-16 08:25 UTC39
    }
b563d2da1c80atagen2026-10-16 08:25 UTC40
    if overlap_x && near(b.y - a.bottom()) {
b563d2da1c80atagen2026-10-16 08:25 UTC41
        s |= ABOVE;
b563d2da1c80atagen2026-10-16 08:25 UTC42
    }
b563d2da1c80atagen2026-10-16 08:25 UTC43
    if overlap_x && near(a.y - b.bottom()) {
b563d2da1c80atagen2026-10-16 08:25 UTC44
        s |= BELOW;
b563d2da1c80atagen2026-10-16 08:25 UTC45
    }
b563d2da1c80atagen2026-10-16 08:25 UTC46
    s
b563d2da1c80atagen2026-10-16 08:25 UTC47
}