Skip to content

Commit

Permalink
Add the examples from the readme to the main lib file
Browse files Browse the repository at this point in the history
  • Loading branch information
Logicalshift committed Feb 27, 2023
1 parent 8f5ceb1 commit 01c60ad
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ A set of curve and coordinate types are provided by the library, as well as a se
on any types with suitable properties. Implementing these traits makes it possible to add the extra features of this
library to any existing code that has its own way of representing coordinates, curves or paths.

`flo_curves` was built as a support library for `flowbetween`, an animation tool I'm working on.

Examples
========

Expand All @@ -43,7 +41,7 @@ Intersections:
```Rust
use flo_curves::bezier;

for (t1, t2) in bezier::curve_intersects_curve_clip(curve1, curve2) {
for (t1, t2) in bezier::curve_intersects_curve_clip(curve1, curve2, 0.01) {
let pos = curve1.point_at_pos(t1);
println!("Intersection, curve1 t: {}, curve2 t: {}, position: {}, {}", t1, t2, pos.x(), pos.y());
}
Expand Down
73 changes: 71 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//!
//! flo_curves
//! ==========
//! # flo_curves
//!
//! `flo_curves` is a library of routines for inspecting and manipulating curves, with a focus on cubic Bézier curves. In
//! this library, you'll find routines for computing points on curves, performing collision detection between curves and
Expand All @@ -14,7 +13,77 @@
//! library to any existing code that has its own way of representing coordinates, curves or paths.
//!
//! `flo_curves` was built as a support library for `flowbetween`, an animation tool I'm working on.
//!
//! ## Examples
//!
//! Creating a curve:
//!
//! ```
//! use flo_curves::*;
//! use flo_curves::bezier;
//!
//! let curve = bezier::Curve::from_points(Coord2(1.0, 2.0), (Coord2(2.0, 0.0), Coord2(3.0, 5.0)), Coord2(4.0, 2.0));
//! ```
//!
//! Finding a point on a curve:
//!
//! ```
//! # use flo_curves::*;
//! # use flo_curves::bezier;
//! #
//! # let curve = bezier::Curve::from_points(Coord2(1.0, 2.0), (Coord2(2.0, 0.0), Coord2(3.0, 5.0)), Coord2(4.0, 2.0));
//! #
//! let pos = curve.point_at_pos(0.5);
//! ```
//!
//! Intersections:
//!
//! ```
//! use flo_curves::*;
//! use flo_curves::bezier;
//! #
//! # let curve1 = bezier::Curve::from_points(Coord2(1.0, 2.0), (Coord2(2.0, 0.0), Coord2(3.0, 5.0)), Coord2(4.0, 2.0));
//! # let curve2 = bezier::Curve::from_points(Coord2(2.0, 1.0), (Coord2(0.0, 2.0), Coord2(5.0, 3.0)), Coord2(2.0, 4.0));
//!
//! for (t1, t2) in bezier::curve_intersects_curve_clip(&curve1, &curve2, 0.01) {
//! let pos = curve1.point_at_pos(t1);
//! println!("Intersection, curve1 t: {}, curve2 t: {}, position: {}, {}", t1, t2, pos.x(), pos.y());
//! }
//! ```
//!
//! Creating a path:
//!
//! ```
//! use flo_curves::*;
//! use flo_curves::bezier;
//! use flo_curves::bezier::path::*;
//!
//! let rectangle1 = BezierPathBuilder::<SimpleBezierPath>::start(Coord2(1.0, 1.0))
//! .line_to(Coord2(5.0, 1.0))
//! .line_to(Coord2(5.0, 5.0))
//! .line_to(Coord2(1.0, 5.0))
//! .line_to(Coord2(1.0, 1.0))
//! .build();
//! ```
//!
//! Path arithmetic:
//!
//! ```
//! use flo_curves::*;
//! use flo_curves::arc::*;
//! use flo_curves::bezier::path::*;
//!
//! let rectangle = BezierPathBuilder::<SimpleBezierPath>::start(Coord2(1.0, 1.0))
//! .line_to(Coord2(5.0, 1.0))
//! .line_to(Coord2(5.0, 5.0))
//! .line_to(Coord2(1.0, 5.0))
//! .line_to(Coord2(1.0, 1.0))
//! .build();
//! let circle = Circle::new(Coord2(3.0, 3.0), 1.0).to_path::<SimpleBezierPath>();
//!
//! let rectangle_with_hole = path_sub::<SimpleBezierPath>(&vec![rectangle], &vec![circle], 0.01);
//! ```
//!

#![warn(bare_trait_objects)]

Expand Down

0 comments on commit 01c60ad

Please sign in to comment.