Skip to content
Prev Previous commit
Next Next commit
fix: reject a wind delta whose square is zero
A zero step and squares that underflow to +0 no longer clear the wind or spend a weather op. 1e-22 still redirects. The gameplay trace no longer says apply_weave_op bakes a navmesh.

Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
  • Loading branch information
cursoragent and lazyxeon committed Oct 21, 2026
commit 9403e3b6dbc75e9713d3e08119bb2ac1b3a0ef0f
6 changes: 2 additions & 4 deletions astraweave-gameplay/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ pub enum WeaveOpKind {
RedirectWind,
LowerWater,
RaisePlatform,
/// W.2c.3 — freeze the water surface at `a`. **Presentation-only** today: a
/// valid weave that consumes the weather budget and carries `a` for the render
/// layer's freeze deformation. The truth-bearing freeze (walkable ice / buoyancy
/// block) is deferred to the post-surface-arc gameplay-truth-coupling phase.
/// W.2c.3 — freeze the water surface at `a`. A kept origin consumes one
/// weather op and inserts a static AABB from the compiled ice bounds.
FreezeWater,
}

Expand Down
334 changes: 332 additions & 2 deletions astraweave-gameplay/src/weaving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,14 @@ fn wind_direction(from: glam::Vec3, to: glam::Vec3) -> Option<glam::Vec3> {
return None;
}
let len2 = delta.length_squared();
if !len2.is_finite() {
if !len2.is_finite() || len2 == 0.0 {
return None;
}
Some(delta.normalize_or_zero())
let dir = delta.normalize_or_zero();
if dir.length_squared() == 0.0 || !dir.is_finite() {
return None;
}
Some(dir)
}

fn legacy_geometry_kept(kind: u8, compiled: &astraweave_weaving::CompiledOp) -> bool {
Expand Down Expand Up @@ -817,4 +821,330 @@ mod tests {
assert_eq!(budget.weather_ops, 3);
assert_eq!(physics.wind, vec3(3.0, 0.0, 0.0));
}

#[test]
fn weave_op_edges_fail_closed() {
#[derive(Clone, Copy)]
struct Case {
name: &'static str,
kind: WeaveOpKind,
a: [f32; 3],
b: Option<[f32; 3]>,
keep: bool,
}
let cases = [
Case {
name: "reinforce origin",
kind: WeaveOpKind::ReinforcePath,
a: [0.0, 0.0, 0.0],
b: None,
keep: true,
},
Case {
name: "reinforce floor -1.5",
kind: WeaveOpKind::ReinforcePath,
a: [-1.5, 0.0, 0.0],
b: None,
keep: true,
},
Case {
name: "reinforce island edge",
kind: WeaveOpKind::ReinforcePath,
a: [2048.0, 0.0, -2048.0],
b: None,
keep: true,
},
Case {
name: "reinforce just outside",
kind: WeaveOpKind::ReinforcePath,
a: [2049.0, 0.0, 0.0],
b: None,
keep: false,
},
Case {
name: "reinforce negative floor edge",
kind: WeaveOpKind::ReinforcePath,
a: [-2047.1, 0.0, 0.0],
b: None,
keep: true,
},
Case {
name: "reinforce past negative edge",
kind: WeaveOpKind::ReinforcePath,
a: [-2048.1, 0.0, 0.0],
b: None,
keep: false,
},
Case {
name: "reinforce subnormal snaps to cell 0",
kind: WeaveOpKind::ReinforcePath,
a: [1e-45, 0.0, 0.0],
b: None,
keep: true,
},
Case {
name: "reinforce nan",
kind: WeaveOpKind::ReinforcePath,
a: [f32::NAN, 0.0, 0.0],
b: None,
keep: false,
},
Case {
name: "reinforce +inf",
kind: WeaveOpKind::ReinforcePath,
a: [f32::INFINITY, 0.0, 0.0],
b: None,
keep: false,
},
Case {
name: "reinforce -inf",
kind: WeaveOpKind::ReinforcePath,
a: [f32::NEG_INFINITY, 0.0, 0.0],
b: None,
keep: false,
},
Case {
name: "reinforce 1e20",
kind: WeaveOpKind::ReinforcePath,
a: [1.0e20, 0.0, 0.0],
b: None,
keep: false,
},
Case {
name: "reinforce 2^31/1000",
kind: WeaveOpKind::ReinforcePath,
a: [(i32::MAX as f32) / 1000.0, 0.0, 0.0],
b: None,
keep: false,
},
Case {
name: "raise origin",
kind: WeaveOpKind::RaisePlatform,
a: [1.0, 2.0, 3.0],
b: None,
keep: true,
},
Case {
name: "raise nan y",
kind: WeaveOpKind::RaisePlatform,
a: [0.0, f32::NAN, 0.0],
b: None,
keep: false,
},
Case {
name: "lower origin",
kind: WeaveOpKind::LowerWater,
a: [0.0, 0.0, 0.0],
b: None,
keep: true,
},
Case {
name: "lower inf z",
kind: WeaveOpKind::LowerWater,
a: [0.0, 0.0, f32::INFINITY],
b: None,
keep: false,
},
Case {
name: "freeze origin",
kind: WeaveOpKind::FreezeWater,
a: [1.0, 0.0, 1.0],
b: None,
keep: true,
},
Case {
name: "freeze nan",
kind: WeaveOpKind::FreezeWater,
a: [f32::NAN, f32::NAN, f32::NAN],
b: None,
keep: false,
},
Case {
name: "freeze 1e20",
kind: WeaveOpKind::FreezeWater,
a: [0.0, 1.0e20, 0.0],
b: None,
keep: false,
},
Case {
name: "collapse segment",
kind: WeaveOpKind::CollapseBridge,
a: [0.0, 0.0, 0.0],
b: Some([10.0, 0.0, 10.0]),
keep: true,
},
Case {
name: "collapse missing b",
kind: WeaveOpKind::CollapseBridge,
a: [0.0, 0.0, 0.0],
b: None,
keep: false,
},
Case {
name: "collapse point",
kind: WeaveOpKind::CollapseBridge,
a: [2.0, 0.0, 2.0],
b: Some([2.0, 0.0, 2.0]),
keep: true,
},
Case {
name: "collapse far b",
kind: WeaveOpKind::CollapseBridge,
a: [0.0, 0.0, 0.0],
b: Some([1.0e20, 0.0, 0.0]),
keep: false,
},
Case {
name: "collapse nan b",
kind: WeaveOpKind::CollapseBridge,
a: [0.0, 0.0, 0.0],
b: Some([f32::NAN, 0.0, 1.0]),
keep: false,
},
Case {
name: "collapse inf b",
kind: WeaveOpKind::CollapseBridge,
a: [0.0, 0.0, 0.0],
b: Some([0.0, f32::INFINITY, 0.0]),
keep: false,
},
Case {
name: "collapse -inf b",
kind: WeaveOpKind::CollapseBridge,
a: [0.0, 0.0, 0.0],
b: Some([0.0, 0.0, f32::NEG_INFINITY]),
keep: false,
},
Case {
name: "wind default +x",
kind: WeaveOpKind::RedirectWind,
a: [0.0, 0.0, 0.0],
b: None,
keep: true,
},
Case {
name: "wind finite step",
kind: WeaveOpKind::RedirectWind,
a: [0.0, 0.0, 0.0],
b: Some([1.0, 0.0, 0.0]),
keep: true,
},
Case {
name: "wind 1e-22",
kind: WeaveOpKind::RedirectWind,
a: [0.0, 0.0, 0.0],
b: Some([1e-22, 0.0, 0.0]),
keep: true,
},
Case {
name: "wind zero",
kind: WeaveOpKind::RedirectWind,
a: [1.0, 2.0, 3.0],
b: Some([1.0, 2.0, 3.0]),
keep: false,
},
Case {
name: "wind 1e-45",
kind: WeaveOpKind::RedirectWind,
a: [0.0, 0.0, 0.0],
b: Some([1e-45, 0.0, 0.0]),
keep: false,
},
Case {
name: "wind 1e-30",
kind: WeaveOpKind::RedirectWind,
a: [0.0, 0.0, 0.0],
b: Some([0.0, 1e-30, 0.0]),
keep: false,
},
Case {
name: "wind 1e-23",
kind: WeaveOpKind::RedirectWind,
a: [0.0, 0.0, 0.0],
b: Some([0.0, 0.0, 1e-23]),
keep: false,
},
Case {
name: "wind 1.9e19",
kind: WeaveOpKind::RedirectWind,
a: [0.0, 0.0, 0.0],
b: Some([1.9e19, 0.0, 0.0]),
keep: false,
},
Case {
name: "wind nan",
kind: WeaveOpKind::RedirectWind,
a: [0.0, 0.0, 0.0],
b: Some([f32::NAN, 0.0, 0.0]),
keep: false,
},
Case {
name: "wind +inf",
kind: WeaveOpKind::RedirectWind,
a: [0.0, 0.0, 0.0],
b: Some([f32::INFINITY, 0.0, 0.0]),
keep: false,
},
Case {
name: "wind -inf",
kind: WeaveOpKind::RedirectWind,
a: [0.0, 0.0, 0.0],
b: Some([f32::NEG_INFINITY, 0.0, 0.0]),
keep: false,
},
Case {
name: "wind nan origin",
kind: WeaveOpKind::RedirectWind,
a: [f32::NAN, 0.0, 0.0],
b: Some([1.0, 0.0, 0.0]),
keep: false,
},
];
for case in cases {
let mut world = create_test_world();
let mut physics = create_test_physics();
physics.wind = vec3(3.0, 0.0, 0.0);
let nav_src = vec![];
let mut budget = create_test_budget();
let op = WeaveOp {
kind: case.kind,
a: vec3(case.a[0], case.a[1], case.a[2]),
b: case.b.map(|p| vec3(p[0], p[1], p[2])),
budget_cost: 1,
};
let mut logger = |_: String| {};
let result = apply_weave_op(
&mut world,
&mut physics,
&nav_src,
&mut budget,
&op,
&mut logger,
);
if case.keep {
assert!(result.is_ok(), "{}", case.name);
let weather = matches!(
case.kind,
WeaveOpKind::RedirectWind | WeaveOpKind::LowerWater | WeaveOpKind::FreezeWater
);
if weather {
assert_eq!(budget.weather_ops, 2, "{}", case.name);
assert_eq!(budget.terrain_edits, 5, "{}", case.name);
} else {
assert_eq!(budget.terrain_edits, 4, "{}", case.name);
assert_eq!(budget.weather_ops, 3, "{}", case.name);
}
if matches!(case.kind, WeaveOpKind::RedirectWind) {
assert_ne!(physics.wind, vec3(3.0, 0.0, 0.0), "{}", case.name);
assert!(physics.wind.is_finite(), "{}", case.name);
assert!(physics.wind.length_squared() > 0.0, "{}", case.name);
}
} else {
assert!(result.is_err(), "{}", case.name);
assert_eq!(budget.terrain_edits, 5, "{}", case.name);
assert_eq!(budget.weather_ops, 3, "{}", case.name);
assert_eq!(physics.wind, vec3(3.0, 0.0, 0.0), "{}", case.name);
}
}
}
}
Loading