Skip to content

solidcore: a 2D or 3D vector with a component above 1.34e154 has an infinite length, and unitize gives a zero vector instead of an error #16041

Open

Description

@CamWight

Requested by Cam

solidcore's 2D and 3D vectors measure their length by summing the squares of their components. For a component above about 1.34e154 (the square root of f64::MAX), the square overflows to infinity. Then length() returns infinity, and unitize() returns a zero vector as the "unit", with no error.

Where. solidcore/crates/solidcore/src/geom/vector2d.rs (Vec2::length_squared, length and unitize, lines 127-160 on main) and geom/vector3d.rs (Vec3::length_squared, length, unitize and unitize_or_z, from line 258). Both are SMLib's Length and Unitize, ported unchanged.

Reproduction (the same IEEE double arithmetic as the code):

let v = Vec2::new(1e155, 0.0);
// length_squared: 1e155 * 1e155 = inf
assert_eq!(v.length(), f64::INFINITY);           // the length is finite: 1e155
let u = v.unitize().unwrap();                    // Ok, not an error
assert_eq!((u.x, u.y), (0.0, 0.0));              // the "unit" is zero: 1e155 / inf

Expected: length() gives 1e155, and unitize() gives (1, 0). The direction is finite and well defined.
Actual: length() gives infinity, and unitize() gives (0, 0), which every caller takes as a valid unit.

The same happens for Vec3. The threshold is about sqrt(f64::MAX) = 1.3408e154.

Who reaches it. I found no real design or rig case that does: model coordinates are millimetres. A design or STEP file with a huge coordinate could reach it, if nothing on the way checks the size. I haven't confirmed which readers do.

How it was found. #16038 (a drawing's points along a line) needed a unit that never overflows. It scales the vector by its largest component before squaring (scaled3 in prism/profile.rs). That avoids the overflow for #16038's own callers only. The general fix belongs here, in geom. One open question for the fix: ported code keeps SMLib's results bit for bit (AGENTS.md §4b), so a scaled length should probably apply only where the plain one overflows. That's for triage.

Nothing is claimed. I'm leaving this for triage, as solidcore's AGENTS.md §0 asks.

Activity

  1. added
    area:doctimeline, components, parameters, naming
    needs-triageno priority yet; a maintainer sorts it with /triage
    on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:doctimeline, components, parameters, namingneeds-triageno priority yet; a maintainer sorts it with /triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions