Initial Commit

This commit is contained in:
SoraKatadzuma committed 2026-11-11 11:53:37 -06:00
commit 5346df6dfb
84 files changed
+18825

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
#! Contains `sphere`, the places within a distance of a center: what holds a
#! body for the quickest test of whether two might meet, their distance against
#! the sum of their radii.
import std::serial;
import malunal::linear;
module malunal::geometry;
#! The places within `radius` of `center`.
@serial
pub struct sphere {
@serial pub var center: vec3;
@serial pub var radius: f32;
}
#! The least sphere holding a box: of its center, reaching its corners.
pub def sphere::of(b: bounds): sphere {
return sphere{ b.center, b.half_size.length };
}
pub def sphere::equals(&this, other: &sphere): bool {
return this.center == other.center && this.radius == other.radius;
}
#! Whether a place is within it.
pub def sphere::contains(&this, p: vec3): bool {
return distance_squared(&p, &this.center) <= this.radius * this.radius;
}
#! Whether it and another sphere meet.
pub def sphere::overlaps(&this, other: sphere): bool {
val reach := this.radius + other.radius;
return distance_squared(&other.center, &this.center) <= reach * reach;
}
#! Whether it and a box meet: whether the box's place nearest its center is
#! within it.
pub def sphere::overlaps(&this, b: bounds): bool {
return this.contains(b.closest(this.center));
}