OF wrapper for lib Kurbo, providing a set of geometrical functions on cartesian planar Beziér paths or shapes.
README
ofxKurbo
An OpenFrameworks wrapper for Kurbo providing a set of geometrical functions on cartesian planar 2D paths (or shapes). Kurbo is a modern, high-performance 2D curve geometry library in Rust, with a strong focus on Bezier paths.
Where other libre geometric algebra libraries tend to "flatten" (sampling & approxitions) data in the process, Kurbo uses modern algorithms that resultg in way cleaner and more accurate results.
Project history
ofxKurbo is a continuation of ofxBezierRs _(with some differences)_. Bezier-rs was used in the excellent Graphite Editor and has mainly been replaced by Kurbo. In the migration process, some Bezier-rs algos have moved to Kurbo too and some missing parts have moved to the Graphite::vector_types. Graphite now also integrates Linesweeper, providing boolean operations and path cleaning. ofxKurbo glues together various functions from all these libraries to provide some of the bezier algorithms used within Graphite. It also provides some utilities to get cleaner output from it and facilitate usage with OpenFrameworks (or C++) applications.
<!-- Demo :
Watch a video of the example. -->Early state
Kurbo & Linesweeper provide plenty of functions. Right now, consider this addon as a proof-of-concept for using Kurbo with C++ code. Smooth Openframeworks integration is yet to be done.
Path offsetting details
I made this specially for its bezier path offsetting capabilities. Other libraries (Livarot, Clipper2) tend to flatten the the offset curve to polygons, then eventually use curve fitting algorithms to obtain bezier data as output. Kurbo ports the logics described in Pomax's excellent research work, which is more modern and generally results in both cleaner & more precise Bezier data output.
Requirements
Tested on
osx + OF 0.12 and linux + OF 0.12 in c++17. Rust installed for building the library.Geometrical functions
- [x] Segment based vector data _(like SVG and ofPath)_
- [x] Shape offset
- [x] Shape outline
- [x] Shape rotation
- [x] Reversing winding direction
- [x] Computing the bounding box of a shape
- [x] Shape hit testing
- [x] Inflections
- [ ] Find shape self intersections
- [x] Evaluate a point on the shape (t-value: linear & euclidean)
- [x] Normal from t-value
- [x] Tangent from t-value
- [x] Curvature from t-value
- [x] Find closest point on shape (projection)
- [x] Boolean path operations.
- [ ] Morphing
- [ ] Extrusion
Shapes
The shape object is close to the underlying one used in kurbo. Unlike ofxBezierRs, which is anchor-based, ofxKurbo is segment-based, more like the ofPath object & SVG commands. Note: Closed shape operations work better when handles are winded clockwise.
Implementation notes
Kurbo is a library written in Rust which can build a C compatible library.
ofxKurbo relies on 3 essential components :
kurbo-ffi: A rust crate to build a library that provides API for communicating with C (anffiin Rust's terms).kurbo-ffi.h: C++ bindings for the compiled library, generated from the rust crate.ofxKurbo.h: Some glue to make it work better with OF.
Usage
See the examples for more advanced usage demos.
#include "ofxKurbo.h"
int main() {
// Create a new path
kurboBezPath* path = kurbo_path_create(nullptr);
// Todo !
// Destroy path handles when done
kurbo_path_destroy(path);
return 0;
}ofxImGui
There's a set of ImGui helpers available, to opt-in, define
OFXBEZRS_DEFINE_IMGUI_HELPERS. It will automatically be enabled with the standard ofxAddons_ENABLE_IMGUI.Development
To build a new library binary for your platform, make sure that you have Rust installed.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
cd ./libs/kurbo-ffi/cargo build --release- Copy lib files to
ofxKurbo/libs/kurbo-ffi/lib/PLATFORM/libkurbo_ffi.a|dylib|so(PLATFORM: osx, linux64, etc.)
- Install or update cbindgen :
cargo install --force cbindgen cd ./libs/kurbo-ffi/- Run :
cbindgen --config ./cbindgen.toml --crate kurbo-ffi --output include/kurbo-ffi.h. - Copy
kurbo-ffi.htolibs/kurbo-ffi/include.
cd ./libs/kurbo-ffi && ./Build.sh
License
The kurbo crate is licensed MIT or Apache-2.0 and is made by the LineBender organisation. Some capabilities were contributed by the team behind Graphite.rs which is licensed MIT or Apache-2.0. Linesweeper is licensed MIT or Apache-2.0.
ofxKurbo and kurbo-ffi are MIT and made by Daan de Lange.
ofxAddons