From bde94a94b31660c5cfe10e3216f37094949d8e82 Mon Sep 17 00:00:00 2001 From: mmulli <6304106+mmulli@users.noreply.github.com> Date: Thu, 16 Dec 2021 17:47:40 +1100 Subject: [PATCH 1/7] Bump Nalgebra to 0.29.0 and testing VectorT implements on static Vectors instead of now deprecated VectorN --- Cargo.lock | 132 +++++++++++++++++++++++++++-------------------- Cargo.toml | 2 +- circle.svg | 22 ++++++++ cubic-bezier.svg | 17 ++++++ reed-leaf.svg | 30 +++++++++++ src/algebra.rs | 28 ++++++++-- 6 files changed, 170 insertions(+), 61 deletions(-) create mode 100644 circle.svg create mode 100644 cubic-bezier.svg create mode 100644 reed-leaf.svg diff --git a/Cargo.lock b/Cargo.lock index f4d0ea2..74e989b 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" @@ -58,7 +75,7 @@ name = "capstan" version = "0.0.3" dependencies = [ "alga", - "approx", + "approx 0.3.2", "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..22d27ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ readme = "README.md" [dependencies] alga = "0.9" approx = "0.3" -nalgebra = "0.22" +nalgebra = "0.29.0" num-traits = "0.2" svg = "0.8" thiserror = "1.0" diff --git a/circle.svg b/circle.svg new file mode 100644 index 0000000..45120c7 --- /dev/null +++ b/circle.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cubic-bezier.svg b/cubic-bezier.svg new file mode 100644 index 0000000..b383129 --- /dev/null +++ b/cubic-bezier.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/reed-leaf.svg b/reed-leaf.svg new file mode 100644 index 0000000..a7f0b6f --- /dev/null +++ b/reed-leaf.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/algebra.rs b/src/algebra.rs index 59af6b6..fd54409 100644 --- a/src/algebra.rs +++ b/src/algebra.rs @@ -1,3 +1,4 @@ +use nalgebra::{Vector1, Vector2, Vector3}; use nalgebra::base::allocator::Allocator; use nalgebra::base::{DefaultAllocator, DimName, VectorN}; use num_traits::identities::One; @@ -46,11 +47,32 @@ pub trait VectorT: type Field: ScalarT; } -impl VectorT for VectorN +// impl VectorT for VectorN +// where +// N: 'static + ScalarT, +// D: DimName, +// DefaultAllocator: Allocator, +// { +// type Field = N; +// } + +impl VectorT for Vector1 +where + N: 'static + ScalarT, +{ + type Field = N; +} + +impl VectorT for Vector2 +where + N: 'static + ScalarT, +{ + type Field = N; +} + +impl VectorT for Vector3 where N: 'static + ScalarT, - D: DimName, - DefaultAllocator: Allocator, { type Field = N; } From 77bac9ede560bcc217b4640009eb2ffb9ce77d2f Mon Sep 17 00:00:00 2001 From: mmulli <6304106+mmulli@users.noreply.github.com> Date: Thu, 16 Dec 2021 17:54:32 +1100 Subject: [PATCH 2/7] Re-testing with VectorN --- src/algebra.rs | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/algebra.rs b/src/algebra.rs index fd54409..15e7b4a 100644 --- a/src/algebra.rs +++ b/src/algebra.rs @@ -47,32 +47,32 @@ pub trait VectorT: type Field: ScalarT; } -// impl VectorT for VectorN -// where -// N: 'static + ScalarT, -// D: DimName, -// DefaultAllocator: Allocator, -// { -// type Field = N; -// } - -impl VectorT for Vector1 +impl VectorT for VectorN where N: 'static + ScalarT, + D: DimName, + DefaultAllocator: Allocator, { type Field = N; } -impl VectorT for Vector2 -where - N: 'static + ScalarT, -{ - type Field = N; -} +// impl VectorT for Vector1 +// where +// N: 'static + ScalarT, +// { +// type Field = N; +// } -impl VectorT for Vector3 -where - N: 'static + ScalarT, -{ - type Field = N; -} +// impl VectorT for Vector2 +// where +// N: 'static + ScalarT, +// { +// type Field = N; +// } + +// impl VectorT for Vector3 +// where +// N: 'static + ScalarT, +// { +// type Field = N; +// } From c5504a008dafdcd0f86ef512de51b2deea8f7e0a Mon Sep 17 00:00:00 2001 From: mmulli <6304106+mmulli@users.noreply.github.com> Date: Thu, 16 Dec 2021 17:58:19 +1100 Subject: [PATCH 3/7] Testing with OVector --- src/algebra.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/algebra.rs b/src/algebra.rs index 15e7b4a..aaa752e 100644 --- a/src/algebra.rs +++ b/src/algebra.rs @@ -1,4 +1,4 @@ -use nalgebra::{Vector1, Vector2, Vector3}; +use nalgebra::{Vector1, Vector2, Vector3, OVector}; use nalgebra::base::allocator::Allocator; use nalgebra::base::{DefaultAllocator, DimName, VectorN}; use num_traits::identities::One; @@ -47,7 +47,16 @@ pub trait VectorT: type Field: ScalarT; } -impl VectorT for VectorN +// impl VectorT for VectorN +// where +// N: 'static + ScalarT, +// D: DimName, +// DefaultAllocator: Allocator, +// { +// type Field = N; +// } + +impl VectorT for OVector where N: 'static + ScalarT, D: DimName, From 48d130f71ee825c247465067e30504cae29347f5 Mon Sep 17 00:00:00 2001 From: mmulli <6304106+mmulli@users.noreply.github.com> Date: Thu, 16 Dec 2021 21:02:50 +1100 Subject: [PATCH 4/7] 0.0.4 Release candidate. See CHANGELOG.md for details --- .gitignore | 1 + CHANGELOG.md | 15 ++++++++++++ Cargo.toml | 6 ++--- README.md | 8 +++++- circle.svg | 22 ----------------- cubic-bezier.svg | 17 ------------- src/main.rs => examples/svg_example.rs | 0 reed-leaf.svg | 30 ----------------------- src/algebra.rs | 34 ++------------------------ 9 files changed, 28 insertions(+), 105 deletions(-) delete mode 100644 circle.svg delete mode 100644 cubic-bezier.svg rename src/main.rs => examples/svg_example.rs (100%) delete mode 100644 reed-leaf.svg 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..61d8616 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 + +- Mention of example in README.md + +### 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 dependency to dev-dependencies so that it won't be included by default in release builds +- Edited .gitignore to ignore root level .svg artifacts generated from the example + ## [0.0.3] ### Added diff --git a/Cargo.toml b/Cargo.toml index 22d27ef..d1b7a95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "capstan" version = "0.0.3" authors = ["Jonathan Merritt "] -edition = "2018" +edition = "2021" license = "MIT" description = "NURBS library with a CAD focus" homepage = "https://github.com/lancelet/capstan/" @@ -15,10 +15,10 @@ readme = "README.md" [dependencies] alga = "0.9" approx = "0.3" -nalgebra = "0.29.0" +nalgebra = "0.29" num-traits = "0.2" -svg = "0.8" thiserror = "1.0" [dev-dependencies] +svg = "0.8" proptest = "0.10" \ No newline at end of file diff --git a/README.md b/README.md index 6ca4a98..1a8659d 100644 --- a/README.md +++ b/README.md @@ -36,4 +36,10 @@ 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. + +## Example + +See the examples folder for how to use the library. The example uses the svg crate as a dev dependency to export a number of different svg files. + +cargo run --example svg_example \ No newline at end of file diff --git a/circle.svg b/circle.svg deleted file mode 100644 index 45120c7..0000000 --- a/circle.svg +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/cubic-bezier.svg b/cubic-bezier.svg deleted file mode 100644 index b383129..0000000 --- a/cubic-bezier.svg +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ 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/reed-leaf.svg b/reed-leaf.svg deleted file mode 100644 index a7f0b6f..0000000 --- a/reed-leaf.svg +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/algebra.rs b/src/algebra.rs index aaa752e..9dd781c 100644 --- a/src/algebra.rs +++ b/src/algebra.rs @@ -1,6 +1,6 @@ -use nalgebra::{Vector1, Vector2, Vector3, OVector}; +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}; @@ -47,15 +47,6 @@ pub trait VectorT: type Field: ScalarT; } -// impl VectorT for VectorN -// where -// N: 'static + ScalarT, -// D: DimName, -// DefaultAllocator: Allocator, -// { -// type Field = N; -// } - impl VectorT for OVector where N: 'static + ScalarT, @@ -64,24 +55,3 @@ where { type Field = N; } - -// impl VectorT for Vector1 -// where -// N: 'static + ScalarT, -// { -// type Field = N; -// } - -// impl VectorT for Vector2 -// where -// N: 'static + ScalarT, -// { -// type Field = N; -// } - -// impl VectorT for Vector3 -// where -// N: 'static + ScalarT, -// { -// type Field = N; -// } From c4014ff044c3f544bf53e22f7485433b6aca1b7e Mon Sep 17 00:00:00 2001 From: mmulli <6304106+mmulli@users.noreply.github.com> Date: Thu, 16 Dec 2021 21:20:03 +1100 Subject: [PATCH 5/7] Bumped approx dependency to 0.5 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74e989b..f1d1359 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,7 +75,7 @@ name = "capstan" version = "0.0.3" dependencies = [ "alga", - "approx 0.3.2", + "approx 0.5.0", "nalgebra", "num-traits", "proptest", diff --git a/Cargo.toml b/Cargo.toml index d1b7a95..62f45bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" [dependencies] alga = "0.9" -approx = "0.3" +approx = "0.5" nalgebra = "0.29" num-traits = "0.2" thiserror = "1.0" From 8db1f030ebcce11b61ee551d7325ad5f81e5bea9 Mon Sep 17 00:00:00 2001 From: mmulli <6304106+mmulli@users.noreply.github.com> Date: Thu, 16 Dec 2021 21:30:42 +1100 Subject: [PATCH 6/7] Minor cleanup of Cargo.toml and bumped approx version to solve compile error related to Nalgebra upgrade --- CHANGELOG.md | 4 +++- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61d8616..aee5995 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ Please track all notable changes in this file. This format is based on ## [0.0.4] +General house keeping and version bumps + ### Added - Mention of example in README.md @@ -17,7 +19,7 @@ Please track all notable changes in this file. This format is based on - 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 dependency to dev-dependencies so that it won't be included by default in release builds +- Moved the svg and approx to dev-dependencies as these are used in examples and testing respectively - Edited .gitignore to ignore root level .svg artifacts generated from the example ## [0.0.3] diff --git a/Cargo.toml b/Cargo.toml index 62f45bb..9d53be7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,11 +14,11 @@ readme = "README.md" [dependencies] alga = "0.9" -approx = "0.5" nalgebra = "0.29" num-traits = "0.2" thiserror = "1.0" [dev-dependencies] +approx = "0.5" svg = "0.8" proptest = "0.10" \ No newline at end of file From 5dd971d1062b2e368c49d7a75b37ee69fca35dd7 Mon Sep 17 00:00:00 2001 From: mmulli <6304106+mmulli@users.noreply.github.com> Date: Thu, 16 Dec 2021 22:44:53 +1100 Subject: [PATCH 7/7] 0.0.4 Release candidate --- CHANGELOG.md | 6 ++--- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 48 +++++++++++++++++++++++++++++++++++--- examples/circle_example.rs | 33 ++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 examples/circle_example.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index aee5995..8cd62e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,9 @@ Please track all notable changes in this file. This format is based on ## [0.0.4] -General house keeping and version bumps - ### Added -- Mention of example in README.md +- Added short circle example directly to the README as well as to a new examples folder ### Changed @@ -19,7 +17,7 @@ General house keeping and version bumps - 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 and testing respectively +- 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] diff --git a/Cargo.lock b/Cargo.lock index f1d1359..cefe377 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,7 +72,7 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] name = "capstan" -version = "0.0.3" +version = "0.0.4" dependencies = [ "alga", "approx 0.5.0", diff --git a/Cargo.toml b/Cargo.toml index 9d53be7..d3f1e49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "capstan" -version = "0.0.3" +version = "0.0.4" authors = ["Jonathan Merritt "] edition = "2021" license = "MIT" diff --git a/README.md b/README.md index 1a8659d..cd485b9 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,50 @@ NURBS curve: The library uses the "Rhino" form of NURBS curves, where there are two fewer knots than in "traditional" NURBS. -## Example +## Usage -See the examples folder for how to use the library. The example uses the svg crate as a dev dependency to export a number of different svg files. +A simple circle example demonstrating how to obtain an interpolated value at an arbitrary location on a curve. -cargo run --example svg_example \ No newline at end of file +```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