← Back

ofxKurbo

github.com/Daandelange/ofxKurbo · @Daandelange
OF 0.12 Geometry 2D Algorithms

OF wrapper for lib Kurbo, providing a set of geometrical functions on cartesian planar Beziér paths or shapes.

2 0 Last commit 20d ago Created 1mo ago

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 : ofxKurbo 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



_Checked ones are implemented._

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 :

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. Build the library : Generate bindings : You can run the above instructions automatically :

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.

Get this addon

HTTPS
SSH