Skip to content

Commit ed6fcc1

Browse files
committed
Fix symmetric puzzle gizmos
1 parent e973236 commit ed6fcc1

4 files changed

Lines changed: 29 additions & 11 deletions

File tree

‎crates/hyperpuzzle_core/src/puzzle/twists.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ impl fmt::Debug for TwistSystem {
4545

4646
impl TwistSystem {
4747
/// Returns an empty twist system.
48-
pub fn new_empty(axes: &Arc<AxisSystem>) -> Self {
48+
pub fn new_empty() -> Self {
4949
Self {
5050
meta: Arc::new(CatalogMetadata::dummy()),
51-
axes: Arc::clone(axes),
51+
axes: Arc::new(AxisSystem::new_empty()),
5252
axis_from_family: Box::new(|_| None),
5353
directions: IndexMap::new(),
5454
vantage_groups: IndexMap::from_iter([("trivial".to_string(), ().into())]),

‎crates/hyperpuzzle_impl_nd_euclid/src/hps/puzzle.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,17 @@ impl HpsPuzzle {
106106
};
107107

108108
let axes = self.twists().axes();
109-
let mut this = self.lock();
110-
let axes: Vec<Axis> = axis_vectors
109+
let axes_to_add_layers_to: Vec<Axis> = axis_vectors
111110
.iter()
112111
.map(|v| eyre::Ok(super::axis_from_vector(&*axes.lock_vectors()?, v)?))
113112
.try_collect()
114113
.at(span)?;
115114

115+
let mut this = self.lock();
116+
116117
// Add layers.
117-
this.axis_layers.resize(axes.len()).at(span)?;
118-
for axis in axes {
118+
for axis in axes_to_add_layers_to {
119+
this.axis_layers.extend_to_contain(axis);
119120
let axis_layers = &mut this.axis_layers[axis].0;
120121
for (&top, &bottom) in layers.iter().tuple_windows() {
121122
axis_layers

‎crates/hyperpuzzle_impl_nd_euclid/src/lib.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ impl PuzzleStateRenderData for NdEuclidPuzzleStateRenderData {}
6666
lazy_static! {
6767
/// Hard-coded placeholder puzzle with no pieces, no stickers, no mesh, etc.
6868
pub static ref PLACEHOLDER_PUZZLE: Arc<Puzzle> = {
69-
let axes = Arc::new(AxisSystem::new_empty());
70-
let twists = Arc::new(TwistSystem::new_empty(&axes));
7169
let mut components = ComponentList::new();
7270
let geom = Arc::new(NdEuclidPuzzleGeometry::placeholder());
7371
components.insert(Arc::clone(&geom));
72+
7473
Arc::new_cyclic(|this| Puzzle {
7574
this: Weak::clone(this),
7675
meta: Arc::new(CatalogMetadata {
@@ -90,7 +89,7 @@ lazy_static! {
9089
can_scramble: false,
9190
full_scramble_length: 0,
9291
axis_layers: PerAxis::new(),
93-
twists,
92+
twists: Arc::new(TwistSystem::new_empty()),
9493
new: Box::new(move |this| NdEuclidPuzzleState::new(this, Arc::clone(&geom)).into()),
9594
random_move: Box::new(move |_rng| None),
9695
components,

‎crates/hyperpuzzle_impl_symmetric/src/builder/mod.rs‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use hypermath::prelude::*;
1010
use hyperpuzzle_core::ComponentList;
1111
use hyperpuzzle_core::catalog::{BuildCtx, BuildTask};
1212
use hyperpuzzle_core::prelude::*;
13-
use hyperpuzzle_impl_nd_euclid::NdEuclidPuzzleGeometry;
13+
use hyperpuzzle_impl_nd_euclid::{NdEuclidPuzzleGeometry, ad_hoc_id};
1414

1515
mod axes;
1616
mod from_space;
@@ -170,7 +170,25 @@ impl ProductPuzzleBuilder {
170170
self.shape.build_piece_types(warn_fn)?;
171171

172172
let axes = Arc::new(self.axes.build_axis_system()?);
173-
let mut twists = TwistSystem::new_empty(&axes);
173+
let mut twists = TwistSystem {
174+
meta: Arc::new(CatalogMetadata::simple(
175+
ad_hoc_id(id.clone()),
176+
format!("{id} (ad-hoc)"),
177+
)),
178+
axes: Arc::clone(&axes),
179+
axis_from_family: Box::new({
180+
let axes = axes.clone();
181+
move |family_str| {
182+
// TODO: correct number of underscores
183+
let axis_name = match family_str.split_once('_') {
184+
Some((first, _)) => first,
185+
None => family_str,
186+
};
187+
axes.names.id_from_name(axis_name)
188+
}
189+
}),
190+
..TwistSystem::new_empty()
191+
};
174192
let axis_undeorbiters = self.axes.build_axis_undeorbiters();
175193

176194
let named_point_names = self.axes.build_named_point_names()?;

0 commit comments

Comments
 (0)