Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

132 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iShape

crates.io docs.rs license

i_shape provides compact, generic data structures and utilities for 2D polygon data. It includes:

  • integer and floating-point path, contour, shape, and shapes aliases;
  • flat contour and shape buffers for allocation-efficient geometry pipelines;
  • area, winding, convexity, simplification, despiking, and deduplication helpers;
  • conversion between floating-point and integer coordinates through i_float;
  • a common ShapeResource interface for accepting contours, shapes, and flat buffers.

The crate is no_std, uses alloc, and supports i16, i32, and i64 integer coordinates.

Installation

[dependencies]
i_shape = "4.0"

Enable serde when serialized geometry or flat buffers are required:

[dependencies]
i_shape = { version = "4.0", features = ["serde"] }

Integer contours

use i_shape::int::area::Area;
use i_shape::int::path::ContourExtension;
use i_shape::int_path;

let contour = int_path![[0_i32, 0], [10, 0], [10, 10], [0, 10]];

assert_eq!(contour.area_two(), 200_i64);
assert!(!contour.is_clockwise_ordered());
assert!(contour.contains_point(i_shape::int::IntPoint::new(5, 5)));

Integer operations use the wide type associated with the coordinate type. See the i_float coordinate-range documentation for the arithmetic preconditions that apply to geometric predicates.

Flat buffers

Flat buffers store points contiguously and describe contours and shapes with index ranges. This is useful when passing geometry between algorithms without rebuilding nested Vecs.

use i_shape::flat::buffer::FlatContoursBuffer;
use i_shape::int_path;

let contour = int_path![[0_i32, 0], [4, 0], [4, 4], [0, 4]];
let mut buffer = FlatContoursBuffer::default();
buffer.add_contour(&contour);

assert_eq!(buffer.ranges, [0..4]);
assert_eq!(buffer.to_contours(), vec![contour]);

Floating-point equivalents are available as FloatFlatContoursBuffer<P> and FloatFlatShapesBuffer<P>, where P can be any FloatPointCompatible type such as [f32; 2] or [f64; 2].

License

Licensed under the MIT License. See the license file.

About

iShape is a compact and efficient library specifically designed for representing 2D data structures using FixVec.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages