diff --git a/.gitignore b/.gitignore index ea8c4bf..fc8a45b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/*.svg \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index dd419c9..8cd62e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ Please track all notable changes in this file. This format is based on ## [Unreleased] +## [0.0.4] + +### Added + +- Added short circle example directly to the README as well as to a new examples folder + +### Changed + +- Bumped rust edition to 2021 +- Upgraded the Nalbegra dependency to 0.29 +- Implemented VectorT for OVector instead of VectorN as VectorN is now deprecated. +- Moved main.rs to the examples folder +- Moved the svg and approx to dev-dependencies as these are used in examples / testing only. +- Edited .gitignore to ignore root level .svg artifacts generated from the example + ## [0.0.3] ### Added diff --git a/Cargo.lock b/Cargo.lock index f4d0ea2..cefe377 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,13 +1,15 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "alga" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f823d037a7ec6ea2197046bafd4ae150e6bc36f9ca347404f46a46823fa84f2" dependencies = [ - "approx", - "num-complex", + "approx 0.3.2", + "num-complex 0.2.4", "num-traits", ] @@ -20,6 +22,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "approx" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "072df7202e63b127ab55acfe16ce97013d5b97bf160489336d3f1840fd78e99e" +dependencies = [ + "num-traits", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -47,6 +58,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "bytemuck" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b" + [[package]] name = "byteorder" version = "1.3.4" @@ -55,10 +72,10 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] name = "capstan" -version = "0.0.3" +version = "0.0.4" dependencies = [ "alga", - "approx", + "approx 0.5.0", "nalgebra", "num-traits", "proptest", @@ -78,15 +95,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "generic-array" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed1e761351b56f54eb9dcd0cfaca9fd0daecf93918e1cfc01c8a3d26ee7adcd" -dependencies = [ - "typenum", -] - [[package]] name = "getrandom" version = "0.1.15" @@ -118,31 +126,40 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "matrixmultiply" -version = "0.2.3" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4f7ec66360130972f34830bfad9ef05c6610a43938a467bcc9ab9369ab3478f" +checksum = "add85d4dd35074e6fedc608f8c8f513a3548619a9024b751949ef0e8e45a4d84" dependencies = [ "rawpointer", ] [[package]] name = "nalgebra" -version = "0.22.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a3f0b89b0a44cb7bb9b62c5e6fd485145ddc6bc14483ab005355e96029b3fbf" +checksum = "d506eb7e08d6329505faa8a3a00a5dcc6de9f76e0c77e4b75763ae3c770831ff" dependencies = [ - "approx", - "generic-array", + "approx 0.5.0", "matrixmultiply", - "num-complex", + "nalgebra-macros", + "num-complex 0.4.0", "num-rational", "num-traits", - "rand", - "rand_distr", "simba", "typenum", ] +[[package]] +name = "nalgebra-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01fcc0b8149b4632adc89ac3b7b31a12fb6099a0317a4eb2ebff574ef7de7218" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "num-complex" version = "0.2.4" @@ -153,6 +170,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-complex" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085" +dependencies = [ + "num-traits", +] + [[package]] name = "num-integer" version = "0.1.43" @@ -165,9 +191,9 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.2.4" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" +checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" dependencies = [ "autocfg", "num-integer", @@ -186,22 +212,9 @@ dependencies = [ [[package]] name = "paste" -version = "0.1.18" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" -dependencies = [ - "paste-impl", - "proc-macro-hack", -] - -[[package]] -name = "paste-impl" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" -dependencies = [ - "proc-macro-hack", -] +checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5" [[package]] name = "ppv-lite86" @@ -209,12 +222,6 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" -[[package]] -name = "proc-macro-hack" -version = "0.5.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" - [[package]] name = "proc-macro2" version = "1.0.24" @@ -291,15 +298,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rand_distr" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96977acbdd3a6576fb1d27391900035bf3863d4a16422973a409b488cf29ffb2" -dependencies = [ - "rand", -] - [[package]] name = "rand_hc" version = "0.2.0" @@ -357,16 +355,26 @@ dependencies = [ "wait-timeout", ] +[[package]] +name = "safe_arch" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "794821e4ccb0d9f979512f9c1973480123f9bd62a90d74ab0f9426fcf8f4a529" +dependencies = [ + "bytemuck", +] + [[package]] name = "simba" -version = "0.2.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdec3fb717e5504ecbef1cf4223c334a215f95323092afeae57125ec40e4995b" +checksum = "f0b7840f121a46d63066ee7a99fc81dcabbc6105e437cae43528cea199b5a05f" dependencies = [ - "approx", - "num-complex", + "approx 0.5.0", + "num-complex 0.4.0", "num-traits", "paste", + "wide", ] [[package]] @@ -447,6 +455,16 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wide" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476da2f1d225632b1fffe638ff979a4bc03907e29b0ab596efca7624014f8b62" +dependencies = [ + "bytemuck", + "safe_arch", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index acfd41e..d3f1e49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "capstan" -version = "0.0.3" +version = "0.0.4" authors = ["Jonathan Merritt "] -edition = "2018" +edition = "2021" license = "MIT" description = "NURBS library with a CAD focus" homepage = "https://github.com/lancelet/capstan/" @@ -14,11 +14,11 @@ readme = "README.md" [dependencies] alga = "0.9" -approx = "0.3" -nalgebra = "0.22" +nalgebra = "0.29" num-traits = "0.2" -svg = "0.8" thiserror = "1.0" [dev-dependencies] +approx = "0.5" +svg = "0.8" proptest = "0.10" \ No newline at end of file diff --git a/README.md b/README.md index 6ca4a98..cd485b9 100644 --- a/README.md +++ b/README.md @@ -36,4 +36,52 @@ NURBS curve: ## NURBS Curve Representation The library uses the "Rhino" form of NURBS curves, where there are two fewer -knots than in "traditional" NURBS. \ No newline at end of file +knots than in "traditional" NURBS. + +## Usage + +A simple circle example demonstrating how to obtain an interpolated value at an arbitrary location on a curve. + +```rust +use nalgebra::Vector2; +use capstan::{knotvec::KnotVec}; +type Curve = capstan::curve::Curve>; + +fn main() { + + let r = f32::sqrt(2.0) / 2.0; + let degree = 2; + let control_points = vec![ + Vector2::new(1.0, 0.0), + Vector2::new(1.0, 1.0), + Vector2::new(0.0, 1.0), + Vector2::new(-1.0, 1.0), + Vector2::new(-1.0, 0.0), + Vector2::new(-1.0, -1.0), + Vector2::new(0.0, -1.0), + Vector2::new(1.0, -1.0), + Vector2::new(1.0, 0.0), + ]; + let weights = vec![1.0, r, 1.0, r, 1.0, r, 1.0, r, 1.0]; + let knots = KnotVec::new(vec![ + 0.0, 0.0, 0.0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1.0, 1.0, 1.0, + ]) + .unwrap(); + + let circle = Curve::new(degree, control_points, weights, knots).unwrap(); + + let u = 0.5_f32; + + // The de_boor method is used to obtainin an interpolated point + println!("interpolation paramater value {}:{}", u, circle.de_boor(u)) +} +``` + +## Examples + +The examples folder includes the above as well as the more comprehensive svg_example.rs example that outputs a number of svg files. The svg crate is used for this but is only required for demonstration purposes. + +To run the svg_example: +$ cargo run --example svg_example + +This will output a number of .svg files into the working directory \ No newline at end of file diff --git a/examples/circle_example.rs b/examples/circle_example.rs new file mode 100644 index 0000000..1605c15 --- /dev/null +++ b/examples/circle_example.rs @@ -0,0 +1,33 @@ +//! A simple circle example demonstrating how to obtain an +//! interpolated value at an arbitrary location on a curve. + +use nalgebra::Vector2; +use capstan::{knotvec::KnotVec}; +type Curve = capstan::curve::Curve>; + +fn main() { + + let r = f32::sqrt(2.0) / 2.0; + let degree = 2; + let control_points = vec![ + Vector2::new(1.0, 0.0), + Vector2::new(1.0, 1.0), + Vector2::new(0.0, 1.0), + Vector2::new(-1.0, 1.0), + Vector2::new(-1.0, 0.0), + Vector2::new(-1.0, -1.0), + Vector2::new(0.0, -1.0), + Vector2::new(1.0, -1.0), + Vector2::new(1.0, 0.0), + ]; + let weights = vec![1.0, r, 1.0, r, 1.0, r, 1.0, r, 1.0]; + let knots = KnotVec::new(vec![ + 0.0, 0.0, 0.0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1.0, 1.0, 1.0, + ]) + .unwrap(); + + let circle = Curve::new(degree, control_points, weights, knots).unwrap(); + + let u = 0.5_f32; + println!("interpolation paramater value {}:{}", u, circle.de_boor(u)) +} \ No newline at end of file diff --git a/src/main.rs b/examples/svg_example.rs similarity index 100% rename from src/main.rs rename to examples/svg_example.rs diff --git a/src/algebra.rs b/src/algebra.rs index 59af6b6..9dd781c 100644 --- a/src/algebra.rs +++ b/src/algebra.rs @@ -1,5 +1,6 @@ +use nalgebra::OVector; use nalgebra::base::allocator::Allocator; -use nalgebra::base::{DefaultAllocator, DimName, VectorN}; +use nalgebra::base::{DefaultAllocator, DimName}; use num_traits::identities::One; use std::fmt::Debug; use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Sub}; @@ -46,7 +47,7 @@ pub trait VectorT: type Field: ScalarT; } -impl VectorT for VectorN +impl VectorT for OVector where N: 'static + ScalarT, D: DimName,