Skip to content

feat: add isize geometry module #27

@lemmih

Description

@lemmih

Summary

Add an apfp::geometry::isize module to provide geometric predicates for isize coordinates.

Motivation

When integrating apfp into rgeometry, we found that isize is a commonly used coordinate type but there's no corresponding apfp::geometry::isize module. Currently we work around this by casting to i64:

impl PolygonScalar for isize {
  fn cmp_slope(p: &[Self; 2], q: &[Self; 2], r: &[Self; 2]) -> std::cmp::Ordering {
    use apfp::geometry::{Orientation, i64 as apfp_mod};
    let orient = apfp_mod::orient2d(
      &apfp_mod::Coord::new(p[0] as i64, p[1] as i64),
      &apfp_mod::Coord::new(q[0] as i64, q[1] as i64),
      &apfp_mod::Coord::new(r[0] as i64, r[1] as i64),
    );
    // ...
  }
  // ... similar for cmp_dist, cmp_vector_slope, cmp_perp_vector_slope, incircle
}

This works (since isize is at most 64-bit on all platforms), but it would be cleaner to have native isize support.

Proposed Solution

Add apfp::geometry::isize module with the same API as the other integer modules:

  • Coord struct with isize components
  • orient2d, orient2d_vec, orient2d_normal
  • cmp_dist
  • incircle

The implementation could either:

  1. Delegate to i64 internally (simple, works everywhere)
  2. Use cfg attributes to delegate to i32 or i64 based on platform pointer width (slightly more efficient on 32-bit platforms)

Option 1 is probably fine since 32-bit platforms are increasingly rare.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions