Coder Social home page Coder Social logo

papaew / lua-poly2tri Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tannerrogalsky/lua-poly2tri

0.0 0.0 0.0 250 KB

A Lua wrapper around poly2tri.

License: MIT License

C++ 3.98% C 54.68% Lua 1.54% CSS 0.21% Makefile 1.39% HTML 36.86% Groff 0.94% CMake 0.27% Batchfile 0.13%

lua-poly2tri's Introduction

lua-poly2tri

This is a Lua wrapper around poly2line. It provides fast, stable Constrained Delauney Triangulation of convex or concave polygons with or without holes. It works with Lua 5.1 and LuaJIT.

This is a continuation and expansion of peete-q's lua-polygon work.

Usage

Download or compile the appropriate binary for your system. Binaries: https://github.com/TannerRogalsky/lua-poly2tri/releases

-- require the module
local poly2tri = assert(package.loadlib(PATH_TO_BINARY, 'luaopen_poly2tri'))()

local vertices = {0, 0, 0, 200, 200, 200, 200, 0}
local holes = {
  {10, 10, 50, 10, 10, 50},
  {100, 10, 175, 10, 175, 100, 100, 50, 10, 100},
  {10, 175, 150, 100, 190, 175}
}
local triangles = poly2tri.triangulate(verts, holes)

The output will be a table where each entry is a table consisting of 6 numbers (3 vertices).

Limitations

There are limitations based on the underlying poly2tri library.

  • If you have a cyclic function that generates random points make sure you don't add the same coordinate twice.
  • Polygons must not self-intersect.
  • Interior holes must not touch other holes, nor touch the polyline boundary.

It might be useful to clean up your polygon data using something like clipper.

Compile

The dependencies for this project are very minimal:

  • CMake >= 2.8
  • MSVC on Windows

Then clone this project and it's submodule. git submodule update --init --recursive

Linux && OSX

mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make

Windows

Use Powershell or your favourite terminal emulator.

mkdir build && cd build
cmake ..
cmake --build . --config Release

Benchmarks

Benchmarks done using Nazca Heron data.

> luajit performance/bench.lua
Test 01: triangulating 1036 points in 240.70 ms
Test 02: triangulating 1036 points in 232.44 ms
Test 03: triangulating 1036 points in 228.36 ms
Test 04: triangulating 1036 points in 222.50 ms
Test 05: triangulating 1036 points in 241.56 ms

> lua5.1 performance/bench.lua
Test 01: triangulating 1036 points in 3426.86 ms
Test 02: triangulating 1036 points in 3445.12 ms
Test 03: triangulating 1036 points in 3378.10 ms
Test 04: triangulating 1036 points in 3415.09 ms
Test 05: triangulating 1036 points in 3438.49 ms
> love .
Test 01: triangulating 1036 points in 2.42 ms
Test 02: triangulating 1036 points in 2.30 ms
Test 03: triangulating 1036 points in 2.54 ms
Test 04: triangulating 1036 points in 2.37 ms
Test 05: triangulating 1036 points in 2.61 ms

lua-poly2tri

> lua5.1 performance/bench.lua
Test 01: triangulating 1036 points in 3.96 ms
Test 02: triangulating 1036 points in 4.79 ms
Test 03: triangulating 1036 points in 6.22 ms
Test 04: triangulating 1036 points in 4.73 ms
Test 05: triangulating 1036 points in 4.31 ms

> luajit performance/bench.lua
Test 01: triangulating 1036 points in 2.85 ms
Test 02: triangulating 1036 points in 3.64 ms
Test 03: triangulating 1036 points in 3.49 ms
Test 04: triangulating 1036 points in 5.73 ms
Test 05: triangulating 1036 points in 3.71 ms

lua-poly2tri's People

Contributors

tannerrogalsky avatar

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.