Expand grammar and add CSG parity fixtures
This commit is contained in:
parent
d754cda94e
commit
cc4bbaa635
5 changed files with 94 additions and 1 deletions
|
|
@ -13,6 +13,14 @@ pub enum BrushOp {
|
|||
Intersect,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum PolygonCategory {
|
||||
Inside,
|
||||
Outside,
|
||||
Aligned,
|
||||
ReverseAligned,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Aabb {
|
||||
pub min: Vec3,
|
||||
|
|
|
|||
|
|
@ -330,6 +330,35 @@ fn polygon_normal(vertices: &[Vec3]) -> Vec3 {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn assert_box_parity(solid: &ConvexSolid, material: MaterialId) {
|
||||
assert_eq!(solid.polygons.len(), 6);
|
||||
assert_eq!(solid.clip_planes.len(), 6);
|
||||
assert!(
|
||||
solid
|
||||
.polygons
|
||||
.iter()
|
||||
.all(|polygon| polygon.vertices.len() == 4)
|
||||
);
|
||||
assert!(
|
||||
solid
|
||||
.polygons
|
||||
.iter()
|
||||
.all(|polygon| polygon.material == material)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parity_box_brush_from_planes_has_six_quad_polygons() {
|
||||
let solid = ConvexSolid::box_from_center_size(
|
||||
Vec3::ZERO,
|
||||
Vec3::splat(2.0),
|
||||
Quat::IDENTITY,
|
||||
MaterialId(9),
|
||||
);
|
||||
|
||||
assert_box_parity(&solid, MaterialId(9));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subtract_center_box_emits_six_convex_fragments() {
|
||||
let source = ConvexSolid::box_from_center_size(
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ mod mesh;
|
|||
mod primitives;
|
||||
|
||||
pub use assembler::{Assembler, BuildOutput, BuildReport, BuildWarning};
|
||||
pub use brush::{Aabb, Brush, BrushId, BrushOp, MaterialId, Primitive};
|
||||
pub use brush::{Aabb, Brush, BrushId, BrushOp, MaterialId, PolygonCategory, Primitive};
|
||||
pub use convex::{ConvexPolygon, ConvexSolid, Plane};
|
||||
pub use dsl::LevelDsl;
|
||||
pub use mesh::TriangleMesh;
|
||||
|
|
|
|||
Loading…
Reference in a new issue