Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/*.svg
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
134 changes: 76 additions & 58 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "capstan"
version = "0.0.3"
version = "0.0.4"
authors = ["Jonathan Merritt <j.s.merritt@gmail.com>"]
edition = "2018"
edition = "2021"
license = "MIT"
description = "NURBS library with a CAD focus"
homepage = "https://github.com/lancelet/capstan/"
Expand All @@ -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"
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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<f32, Vector2<f32>>;

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
33 changes: 33 additions & 0 deletions examples/circle_example.rs
Original file line number Diff line number Diff line change
@@ -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<f32, Vector2<f32>>;

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))
}
File renamed without changes.
Loading