Code Monkey home page Code Monkey logo

earcut-rs's Introduction

earcut-rs

Test codecov Crates.io Version

A Rust port of the mapbox/earcut polygon triangulation library, implemented from scratch with some reference to donbright/earcutr.

  • Based on the latest earcut 2.2.4 release.
  • Designed to avoid unnecessary memory allocations. You can reuse the internal buffer and the output index vector for multiple triangulations.
  • (Experimental) An additional module, utils3d, can rotate 3D coplanar polygons into the 2D plane before triangulation.
  • License: ISC

Benchmarks

on Macbook Pro (M1 Pro)

Polygon earcut.hpp earcut-rs (0.4.1) earcutr (0.4.3)
bad_hole 3.574 µs/i 4.623 µs/i 4.415 µs/i
building 397 ns/i 195 ns/i 604 ns/i
degenerate 142 ns/i 45 ns/i 206 ns/i
dude 5.061 µs/i 6.496 µs/i 8.096 µs/i
empty_square 195 ns/i 74 ns/i 331 ns/i
water 459.6 µs/i 574.5 µs/i 801.3 µs/i
water2 334.1 µs/i 393.9 µs/i 450.3 µs/i
water3 13.12 µs/i 19.21 µs/i 23.46 µs/i
water3b 1.340 µs/i 1.345 µs/i 2.165 µs/i
water4 81.48 µs/i 110.6 µs/i 154.1 µs/i
water_huge 6.906 ms/i 11.0 ms/i 10.90 ms/i
water_huge2 15.38 ms/i 23.60 ms/i 22.35 ms/i

(Earcutr 0.4.3 is not besed on the latest earcut.)

earcut-rs's People

Contributors

ciscorn avatar

Stargazers

 avatar Tao Jianhang avatar Thomas Diethelm avatar rot1024 avatar Vladyslav Vladinov avatar Nicholas Korn avatar  avatar  avatar Jari Pennanen avatar Hennadii Chernyshchyk avatar Ko Nagase avatar  avatar Kanahiro Iguchi avatar

Watchers

Sorami Hisamoto avatar  avatar Yasunori Kirimoto avatar  avatar

earcut-rs's Issues

Use const generics

I would like to suggest to pass a slice of arrays with dimension defined as const generic. And instead of accepting dimensions as a number, use [usize; 2] with indices to use. I.e. to use first two values from each array (x and y), use [0, 1].
It would be more ergonomic and more efficient since libraries usually represent meshes as vector of arrays instead of vector of values.

More API suggestions

Hi! Thanks a lot for implementing my suggestions in #5. I decided to try the crate, but noticed a few inconveniences with the API:

  1. You now accept iterator for vertices which is quite convenient, but you require item to be &[f32; 2]. It's a problem when you actually have 3D coordinates and you trying to convert them into 2D:
positions.iter().map(|&[x, y, _]| &[x, y]);

I can't return &[x, y] from a closure. I would suggest to remove the reference (make it just [f32; 2]) or make turn it into an iterator over just f32. I would suggest the latter since it will be a little closer to how the JS version works.

  1. You return triangles as Vec<[N; 3]>. But some crates, like Bevy, store them as just f32. I would suggest to return just Vec<N>. This way it will be more consistent with (1).

Is `11.0k ms/i` a typo?

In the benchmark section, earcut-rs (0.4.1) - water_huge2 is 11.0k ms/i, which is almost 1000 times earcutr (0.4.3) - water_huge2 (10.90 ms/i).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.