stroke/
lib.rs

1#![no_std]
2#![forbid(unsafe_code)]
3#![allow(incomplete_features)]
4// this is needed to use expressions in const generics such as N-1 (see curve derivatives)
5#![feature(generic_const_exprs)]
6// this feature is needed for tinyvec < 2.0 to compile for const generic arrays like ArrayVec<[f32;N]>
7//#![feature(min_const_generics)]
8// removes the need for generics with associated types to specify the
9// associated type like P:Point instead of P: Point<Scalar=f64>
10#![feature(associated_type_bounds)]
11// make splines usable as Fn in trait bounds
12//#![feature(fn_traits)]
13
14use core::ops::{Add, Mul, Sub};
15
16extern crate num_traits;
17use num_traits::float::Float;
18
19extern crate tinyvec;
20use tinyvec::ArrayVec;
21
22// abstraction types
23pub mod bezier_segment;
24// specialized types
25pub mod cubic_bezier;
26pub mod line;
27pub mod quadratic_bezier;
28// generic types
29pub mod bezier;
30pub mod bspline;
31pub mod point_generic;
32
33// Traits
34pub mod point;
35pub mod spline;
36
37mod roots;
38
39// export common types at crate root
40pub use bezier::Bezier;
41pub use bspline::BSpline;
42pub use cubic_bezier::CubicBezier;
43pub use line::LineSegment;
44pub use point::Point;
45pub use point_generic::PointN;
46pub use quadratic_bezier::QuadraticBezier;
47pub use spline::Spline;
48
49// Conditionally compiled newtype pattern used to determine which size float to use for internal constants
50// so that the library can specialize internal types for the architecture for best performance
51// TODO An FPU size definition is not available to the compiler, so
52
53//   1. Either fix everything to 32-bit and accept performance loss (how it's done now)
54
55//   2. Make this value a 'must-config' in cargo.toml (requires either external libraries
56//      or must wait for additional float types)
57
58// If it is a modern 64 bit architecture, it likely also has a 64 bit FPU
59#[cfg(target_pointer_width = "64")]
60type NativeFloat = f64;
61#[cfg(target_pointer_width = "64")]
62const EPSILON: f64 = f64::EPSILON;
63// For now, we fix all non-64 bit architectures to 32bit floats
64// as smaller-width architectures are more likely to have different int/float sizes if they have a fpu
65#[cfg(not(target_pointer_width = "64"))]
66type NativeFloat = f32;
67#[cfg(not(target_pointer_width = "64"))]
68const EPSILON: f32 = f32::EPSILON;
69// This might change when/if Rust gets additional types like f16 or f24