1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! A face a hundred times narrower than a tolerance of 1e-5 mm, but wider than this kernel's
//! 1e-7 mm, is kept as a face: swept from an outline edge 90 tolerances long, measured, and left alone when faces are
//! unified.
use std::f64::consts::{FRAC_PI_2, PI, TAU};
use springrep::{
boolean::unify,
math::{Frame, Vec2},
measure,
profile::{NamedSegment, Profile, ProfileLoop, Segment},
sweep::extrude,
topo::Brep,
};
/// A 3 by 1 + `step` mm rect on a circle of radius 4 at the origin, extruded 6 mm: the rect's
/// top runs `step` past the circle's top point, so its left side leaves a strip `step` wide.
fn rect_past_a_circle(step: f64) -> Brep {
let line = |a: (f64, f64), b: (f64, f64), name: &str| {
NamedSegment::new(
Segment::Line {
a: Vec2::new(a.0, a.1),
b: Vec2::new(b.0, b.1),
},
name,
)
};
let r7 = 7f64.sqrt();
let top = 4.0 + step;
// The circle from its top point round to where it drops below the rect's foot, at (√7, 3).
let segments = vec![
NamedSegment::new(
Segment::Arc {
center: Vec2::ZERO,
radius: 4.0,
start: FRAC_PI_2,
sweep: TAU - (FRAC_PI_2 - 3f64.atan2(r7)),
},
"floor_side",
),
line((r7, 3.0), (3.0, 3.0), "body_v_min"),
line((3.0, 3.0), (3.0, top), "body_u_max"),
line((3.0, top), (0.0, top), "body_v_max"),
line((0.0, top), (0.0, 4.0), "body_u_min"),
];
let outline = Profile {
loops: vec![ProfileLoop { segments }],
};
unify(&extrude(&outline, &Frame::WORLD, 6.0, "x").unwrap()).unwrap()
}
#[test]
fn a_strip_90_tolerances_wide_stays_a_face() {
// The channels' corners lie 8.9e-6 mm outside their floor circles. At a tolerance of 1e-5
// mm such a strip is narrower than the tolerance; at 1e-7 mm it is a face, and merging it
// would move the neighbouring edge 90 tolerances. The area outside the circle is ∫ (4 + s −
// √(16 − x²)) to x = √7, where the circle drops below the rect, plus the full (3 − √7) by (1 +
// s) beyond.
let s = 8.936e-6;
let b = rect_past_a_circle(s);
let r7 = 7f64.sqrt();
let outside = r7 * (4.0 + s) - 1.5 * r7 - 8.0 * (r7 / 4.0).asin() + (3.0 - r7) * (1.0 + s);
let want = 6.0 * (16.0 * PI + outside);
assert!((measure::volume(&b) - want).abs() < 1e-9 * want);
assert_eq!(b.face_count(), 7);
let strip: Vec<_> = b
.face_ids()
.filter(|&f| {
b.face(f)
.names
.iter()
.any(|n| n.to_string() == "x.body_u_min")
})
.collect();
assert_eq!(strip.len(), 1);
assert!((measure::face_area(&b, strip[0]) - 6.0 * s).abs() < 1e-9);
assert_eq!(unify(&b).unwrap().face_count(), 7);
}