Skip to content

Assertion failure when radius exceeds sqrt(2)/2 #1

@jackbackes

Description

@jackbackes

Description

The library panics with an assertion failure when the radius parameter exceeds sqrt(2)/2 ≈ 0.707:

thread 'Compute Task Pool (4)' panicked at poisson/src/lib.rs:135:9:
assertion failed: radius <= NumCast::from(2f64.sqrt() / 2.).expect("Casting constant should always work.")

Expected Behavior

The library should handle this gracefully, either by:

  1. Clamping the radius to the maximum allowed value
  2. Returning an error through a Result type
  3. Documenting the constraint clearly in the Builder API

Current Behavior

The library uses an assertion that panics at runtime, which is not a graceful failure mode for what appears to be a mathematical constraint rather than a true invariant violation.

Reproduction

use poisson::{Builder, Type, algorithm::Ebeida};
use nalgebra::Vector2;

let radius = 0.8; // Exceeds sqrt(2)/2
let poisson = Builder::<_, Vector2<f32>>::with_radius(radius, Type::Normal);
let generator = poisson.build(rand::thread_rng(), Ebeida);
let points = generator.generate(); // Panics here

Context

This issue was encountered in townmaker when bounding boxes were too small relative to the density setting, causing the normalized radius calculation to exceed the limit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions