Semi-sensible refactor for ramhorn_twist?
This commit is contained in:
parent
bddedfd9f4
commit
5f27239525
@ -46,3 +46,5 @@
|
|||||||
obtain". Can I fix this somehow? Looks like a French-ism that made
|
obtain". Can I fix this somehow? Looks like a French-ism that made
|
||||||
its way in.
|
its way in.
|
||||||
- Multithread! This looks very task-parallel anywhere that I branch.
|
- Multithread! This looks very task-parallel anywhere that I branch.
|
||||||
|
- Would being able to name a rule node (perhaps conditionally under
|
||||||
|
some compile-time flag) help for debugging?
|
||||||
|
|||||||
@ -282,7 +282,7 @@ fn ramhorn_twist(depth: usize) -> Rule<RamHornCtxt> {
|
|||||||
|
|
||||||
// Quarter-turn in radians:
|
// Quarter-turn in radians:
|
||||||
let qtr = std::f32::consts::FRAC_PI_2;
|
let qtr = std::f32::consts::FRAC_PI_2;
|
||||||
let x = Vector3::x_axis();
|
let z = Vector3::z_axis();
|
||||||
|
|
||||||
let v = Unit::new_normalize(Vector3::new(-1.0, 0.0, 1.0));
|
let v = Unit::new_normalize(Vector3::new(-1.0, 0.0, 1.0));
|
||||||
let incr: Transform = Transform::new().
|
let incr: Transform = Transform::new().
|
||||||
@ -327,14 +327,26 @@ fn ramhorn_twist(depth: usize) -> Rule<RamHornCtxt> {
|
|||||||
vec![
|
vec![
|
||||||
Child {
|
Child {
|
||||||
rule: next_rule.clone(),
|
rule: next_rule.clone(),
|
||||||
xf: incr.translate(0.0, 0.0, 0.5).rotate(&x, -qtr/3.0),
|
xf: incr.scale(0.5).translate(1.0, 1.0, 2.0).rotate(&z, qtr*0.0),
|
||||||
vmap: vec![0,1,2,3],
|
vmap: vec![0,1,2,3],
|
||||||
},
|
},
|
||||||
Child {
|
Child {
|
||||||
rule: next_rule,
|
rule: next_rule.clone(),
|
||||||
xf: incr.translate(0.0, 0.0, 0.5).rotate(&x, qtr/3.0),
|
xf: incr.scale(0.5).translate(-1.0, 1.0, 2.0).rotate(&z, qtr*1.0),
|
||||||
vmap: vec![0,1,2,3],
|
vmap: vec![0,1,2,3],
|
||||||
},
|
},
|
||||||
|
Child {
|
||||||
|
rule: next_rule.clone(),
|
||||||
|
xf: incr.scale(0.5).translate(-1.0, -1.0, 2.0).rotate(&z, qtr*2.0),
|
||||||
|
vmap: vec![0,1,2,3],
|
||||||
|
},
|
||||||
|
Child {
|
||||||
|
rule: next_rule.clone(),
|
||||||
|
xf: incr.scale(0.5).translate(1.0, -1.0, 2.0).rotate(&z, qtr*3.0),
|
||||||
|
vmap: vec![0,1,2,3],
|
||||||
|
},
|
||||||
|
// TODO: Factor out repetition
|
||||||
|
// TODO: Produce midpoint/centroid vertices like 'start' does below
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
let next_rule = Rule {
|
let next_rule = Rule {
|
||||||
@ -365,7 +377,7 @@ fn ramhorn_twist(depth: usize) -> Rule<RamHornCtxt> {
|
|||||||
translate(0.0, 0.0, -1.0)
|
translate(0.0, 0.0, -1.0)
|
||||||
};
|
};
|
||||||
|
|
||||||
let start = move |self_: Rc<Rule<RamHornCtxt>>| -> RuleEval<RamHornCtxt> {
|
let trans = move |self_: Rc<Rule<RamHornCtxt>>| -> RuleEval<RamHornCtxt> {
|
||||||
|
|
||||||
RuleEval {
|
RuleEval {
|
||||||
geom: Rc::new(OpenMesh {
|
geom: Rc::new(OpenMesh {
|
||||||
@ -382,33 +394,25 @@ fn ramhorn_twist(depth: usize) -> Rule<RamHornCtxt> {
|
|||||||
vertex( 0.0, -0.5, 1.0), // 7 (connects 3-0)
|
vertex( 0.0, -0.5, 1.0), // 7 (connects 3-0)
|
||||||
// Top middle:
|
// Top middle:
|
||||||
vertex( 0.0, 0.0, 1.0), // 8
|
vertex( 0.0, 0.0, 1.0), // 8
|
||||||
// 'Bottom' vertices:
|
|
||||||
vertex(-0.5, -0.5, 0.0), // 9
|
|
||||||
vertex(-0.5, 0.5, 0.0), // 10
|
|
||||||
vertex( 0.5, 0.5, 0.0), // 11
|
|
||||||
vertex( 0.5, -0.5, 0.0), // 12
|
|
||||||
],
|
],
|
||||||
faces: vec![
|
faces: vec![
|
||||||
// bottom face:
|
|
||||||
Tag::Body(9), Tag::Body(10), Tag::Body(11),
|
|
||||||
Tag::Body(9), Tag::Body(11), Tag::Body(12),
|
|
||||||
// two faces straddling edge from vertex 0:
|
// two faces straddling edge from vertex 0:
|
||||||
Tag::Body(9), Tag::Body(0), Tag::Body(4),
|
Tag::Parent(0), Tag::Body(0), Tag::Body(4),
|
||||||
Tag::Body(9), Tag::Body(7), Tag::Body(0),
|
Tag::Parent(0), Tag::Body(7), Tag::Body(0),
|
||||||
// two faces straddling edge from vertex 1:
|
// two faces straddling edge from vertex 1:
|
||||||
Tag::Body(10), Tag::Body(1), Tag::Body(5),
|
Tag::Parent(1), Tag::Body(1), Tag::Body(5),
|
||||||
Tag::Body(10), Tag::Body(4), Tag::Body(1),
|
Tag::Parent(1), Tag::Body(4), Tag::Body(1),
|
||||||
// two faces straddling edge from vertex 2:
|
// two faces straddling edge from vertex 2:
|
||||||
Tag::Body(11), Tag::Body(2), Tag::Body(6),
|
Tag::Parent(2), Tag::Body(2), Tag::Body(6),
|
||||||
Tag::Body(11), Tag::Body(5), Tag::Body(2),
|
Tag::Parent(2), Tag::Body(5), Tag::Body(2),
|
||||||
// two faces straddling edge from vertex 3:
|
// two faces straddling edge from vertex 3:
|
||||||
Tag::Body(12), Tag::Body(3), Tag::Body(7),
|
Tag::Parent(3), Tag::Body(3), Tag::Body(7),
|
||||||
Tag::Body(12), Tag::Body(6), Tag::Body(3),
|
Tag::Parent(3), Tag::Body(6), Tag::Body(3),
|
||||||
// four faces from edge (0,1), (1,2), (2,3), (3,0):
|
// four faces from edge (0,1), (1,2), (2,3), (3,0):
|
||||||
Tag::Body(9), Tag::Body(4), Tag::Body(10),
|
Tag::Parent(0), Tag::Body(4), Tag::Parent(1),
|
||||||
Tag::Body(10), Tag::Body(5), Tag::Body(11),
|
Tag::Parent(1), Tag::Body(5), Tag::Parent(2),
|
||||||
Tag::Body(11), Tag::Body(6), Tag::Body(12),
|
Tag::Parent(2), Tag::Body(6), Tag::Parent(3),
|
||||||
Tag::Body(12), Tag::Body(7), Tag::Body(9),
|
Tag::Parent(3), Tag::Body(7), Tag::Parent(0),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
final_geom: Rc::new(prim::empty_mesh()),
|
final_geom: Rc::new(prim::empty_mesh()),
|
||||||
@ -436,12 +440,35 @@ fn ramhorn_twist(depth: usize) -> Rule<RamHornCtxt> {
|
|||||||
// TODO: These vertex mappings appear to be right.
|
// TODO: These vertex mappings appear to be right.
|
||||||
// Explain *why* they are right.
|
// Explain *why* they are right.
|
||||||
// TODO: Factor out the repetition here.
|
// TODO: Factor out the repetition here.
|
||||||
// TODO: 4 Rc::new calls in a row with identical
|
|
||||||
// params... why not just Rc?
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let start = move |self_: Rc<Rule<RamHornCtxt>>| -> RuleEval<RamHornCtxt> {
|
||||||
|
RuleEval {
|
||||||
|
geom: Rc::new(OpenMesh {
|
||||||
|
verts: vec![
|
||||||
|
vertex(-0.5, -0.5, 0.0),
|
||||||
|
vertex(-0.5, 0.5, 0.0),
|
||||||
|
vertex( 0.5, 0.5, 0.0),
|
||||||
|
vertex( 0.5, -0.5, 0.0),
|
||||||
|
],
|
||||||
|
faces: vec![
|
||||||
|
Tag::Body(0), Tag::Body(1), Tag::Body(2),
|
||||||
|
Tag::Body(0), Tag::Body(2), Tag::Body(3),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
final_geom: Rc::new(prim::empty_mesh()),
|
||||||
|
children: vec![
|
||||||
|
Child {
|
||||||
|
rule: Rc::new(Rule { eval: Rc::new(trans.clone()), ctxt: self_.ctxt }),
|
||||||
|
xf: Transform::new(),
|
||||||
|
vmap: vec![0,1,2,3],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Rule { eval: Rc::new(start), ctxt: RamHornCtxt { depth } }
|
Rule { eval: Rc::new(start), ctxt: RamHornCtxt { depth } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -619,5 +646,5 @@ pub fn main() {
|
|||||||
run_test_iter(&Rc::new(cube_thing()), 3, "cube_thing3");
|
run_test_iter(&Rc::new(cube_thing()), 3, "cube_thing3");
|
||||||
run_test_iter(&Rc::new(twist(1.0, 2)), 200, "twist");
|
run_test_iter(&Rc::new(twist(1.0, 2)), 200, "twist");
|
||||||
run_test_iter(&Rc::new(ramhorn()), 100, "ram_horn3");
|
run_test_iter(&Rc::new(ramhorn()), 100, "ram_horn3");
|
||||||
run_test_iter(&Rc::new(ramhorn_twist(6)), 40, "ram_horn3b_bug");
|
run_test_iter(&Rc::new(ramhorn_twist(5)), 30, "ram_horn3b_bug");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -222,6 +222,8 @@ impl<S> Rule<S> {
|
|||||||
// account for this, we must shift vmap by the offset that
|
// account for this, we must shift vmap by the offset that
|
||||||
// 'geom.connect' gave us:
|
// 'geom.connect' gave us:
|
||||||
let off = offsets[0];
|
let off = offsets[0];
|
||||||
|
// (We pass a one-element vector to geom.connect() above
|
||||||
|
// so offsets always has just one element.)
|
||||||
for child in eval.children.iter_mut() {
|
for child in eval.children.iter_mut() {
|
||||||
child.vmap = child.vmap.iter().map(|n| n + off).collect();
|
child.vmap = child.vmap.iter().map(|n| n + off).collect();
|
||||||
}
|
}
|
||||||
@ -236,7 +238,7 @@ impl<S> Rule<S> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !eval.children.is_empty() {
|
if !eval.children.is_empty() {
|
||||||
// Recurse further (i.e. put more onto stack):
|
// Recurse further (i.e. put more onto stack):
|
||||||
stack.push(State {
|
stack.push(State {
|
||||||
rules: eval.children,
|
rules: eval.children,
|
||||||
next: 0,
|
next: 0,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user