← Back

ofxBezierRs

github.com/Daandelange/ofxBezierRs · @Daandelange
OF 0.11 Archived Graphics Bridges Geometry 2D

An OpenFrameworks wrapper for bezier-rs providing a set geometrical functions on cartesian planar Beziér paths or shapes.

3 0 Last commit 1mo ago Created 2y ago

README

ofxBezierRs

An OpenFrameworks wrapper for bezier-rs providing a set geometrical functions on cartesian planar Beziér paths or shapes. In terms of algorithm, the Bezier-rs is quite close to bezier.js from Pomax's research work.

Demo : ofxBezierRs Demo Watch a video of the example.

Early state

Bezier-rs provides plenty of functions, not all are implemented yet. Right now, consider this addon as a proof-of-concept for using libBezierRs with C++ code. Tested on osx 10.12 + OF 0.11.2 and linux + OF 0.11.2, the binaries are not yet bundled.

Update dec 2025

Bezier-rs has been depreciated. Graphite now uses Kubo which seems more performance-oriented, but it's also using a different vector data structure, which makes compatibility harder. While Bezier-rs won't evolve anymore, it's still a solid choice for 2d vector math operations. Over time I'll probably move to lib2geom, once they ported boolean operations from Livarot.

Update sept 2026

ofxBezierRs has now also been depreciated, please refer to ofxKurbo as its successor ! Warning: Segment-based data and other minor "breaking" changes.

Functions :

Shapes

The shape object is close to the underlying one used in bezier-rs. Their concept is quite simple : Note: Shapes work better if handles are winded clockwise.

Implementation notes

Bezier-rs is a library written in Rust which can build a C compatible library.

ofxBezierRs relies on 3 essential components :

Usage

#include "ofxBezierRs.h"
int main(){

	// Build an array-compatible list of beziers handles.
	// Must remain accessible when calling bez_rs_shape_create.
	std::vector<bezrsBezierHandle> bezierHandles = { ... }; // <-- Fill this with your vector drawing
	// Make raw handle
	bezrsShapeRaw bezRsShapeInput = { bezierHandles.data(), bezierHandles.size(), true };
	// Build internal/opaque shape from raw input
	bezrsShape bezRsShape = bezrs_shape_create( &bezRsShapeInput, true);
	// Transform the shape
	bezrs_cubic_bezier_offset(bezRsShape, 10, bezrsJoinType::Round, 0);
	// Retrieve resulting shape
	bezrsShapeRaw offsetShapeRaw = bezrs_shape_return_handle_data(bezRsShape);
	// Use result
	size_t bhi = 0;
	for (const bezrsBezierHandle bh = offsetShapeRaw.data; bhi < offsetShapeRaw.len; bh++){
		ofDrawCircle(bh->pos.x, bh->pos.y, 5.f); // draw
		// or copy to own variable

		bhi++;
	}
	// Destroy shape handle
	bezrs_shape_destroy(bezRsShape);

	return 0;
}


There's a set of ImGui helpers available, to opt-in, define OFXBEZRS_DEFINE_IMGUI_HELPERS.

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 bezier-rs crate is licensed MIT or Apache-2.0. The bezier-rs crate is made by the team behind Graphite.rs. ofxBezierRs and bezier-rs-ffi are MIT and made by Daan de Lange.

Get this addon

HTTPS
SSH