use super::*;
use ifc_lite_core::EntityDecoder;
fn parallelogram_step(dot: f64) -> String {
let y = (1.0 - dot * dot).sqrt();
let (p1x, p1y) = (1.0, 0.0);
let (p2x, p2y) = (1.0 + dot, y);
let (p3x, p3y) = (dot, y);
format!(
"#1=IFCCARTESIANPOINT((0.0,0.0));\n\
#2=IFCCARTESIANPOINT(({p1x},{p1y}));\n\
#3=IFCCARTESIANPOINT(({p2x},{p2y}));\n\
#4=IFCCARTESIANPOINT(({p3x},{p3y}));\n\
#5=IFCPOLYLINE((#1,#2,#3,#4));\n\
#6=IFCARBITRARYCLOSEDPROFILEDEF(.AREA.,'Test',#5);\n"
)
}
#[test]
fn read_rect_profile_2d_accepts_parallelogram_just_inside_perp_tolerance() {
let content = parallelogram_step(0.009);
let mut decoder = EntityDecoder::new(&content);
let profile_entity = decoder.decode_by_id(6).unwrap();
let router = GeometryRouter::new();
let result = router.read_rect_profile_2d(&profile_entity, &mut decoder);
assert!(
result.is_some(),
"dot=0.009 is within the 0.01 perpendicularity tolerance and must be accepted"
);
let (xd, yd, ..) = result.unwrap();
assert!((xd - 1.0).abs() < 1e-6, "xd should be ~1.0, got {xd}");
assert!((yd - 1.0).abs() < 1e-6, "yd should be ~1.0, got {yd}");
}
#[test]
fn read_rect_profile_2d_rejects_parallelogram_just_outside_perp_tolerance() {
let content = parallelogram_step(0.011);
let mut decoder = EntityDecoder::new(&content);
let profile_entity = decoder.decode_by_id(6).unwrap();
let router = GeometryRouter::new();
let result = router.read_rect_profile_2d(&profile_entity, &mut decoder);
assert!(
result.is_none(),
"dot=0.011 is outside the 0.01 perpendicularity tolerance and must be rejected, got {result:?}"
);
}