Code Monkey home page Code Monkey logo

dual-mesh's Introduction

http://unmaintained.tech/badge.svg

Dual mesh library for my polygon map generator projects (mapgen2, mapgen4). Feel free to use this, but it’s not a stable library and I do make breaking changes. The create.js interface is the most likely to change in the future.

This is a wrapper around Delaunator. I wrote the Delaunator Guide based on the code from this project. The code in the guide is easier to read and more general but less efficient than the code in this library.

Documentation is here, but it’s a bit rough. See my blog post about centroid polygons and my blog post about the dual mesh data structure for the history. Those blog posts used the names “seeds, edges, triangles” but now I call them “regions, sides, triangles”, and I use “ghost” elements to eliminate the boundaries.

The naming convention is: x_name_y takes type x (r, s, t) as input and produces type y (r, s, t) as output. For example, s_begin_r is a function that takes a side (s) as input and returns a region (r), and could be called r = mesh.s_begin_r(s).

For efficiency, the accessors never allocate new arrays, but take a parameter where the result should be written:

let out_r = [];
mesh.t_circulate_r(out_r, t);
// output written into out_r

For convenience, they also return the array, so this works:

let out_r = mesh.t_circulate_r([], t);

To create a mesh, use the MeshBuilder:

let mesh = new MeshBuilder()
    .addPoints(array_of_points)
    .create();
let Poisson = require('poisson-disk-sampling');
let mesh = new MeshBuilder({boundarySpacing: 75})
    .addPoisson(Poisson, 75)
    .create();

Built with

dual-mesh's People

Contributors

dependabot[bot] avatar redblobgames avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dual-mesh's Issues

License missing?

Dear RedBlobGames, i was wondering if you could add a MIT license to this code so that we can legally use it?

Move t_vertex, r_vertex behind accessor methods

For very large maps, we could save a lot of memory by putting the vertex positions into a flat typedarray. First step: move the positions to accessor methods r_x, r_y, t_x, t_y, and then we can change the representation.

Separate boundary/ghost phases from poisson disk creation

The create module combines:

  1. poisson disk point selection
  2. boundary point selection
  3. sanity checks
  4. ghost region/side/triangle creation

But all of these aren't always needed.

  • If using a pre-selected set of points, they need ghost creation but not the rest
  • Sometimes boundary points aren't needed with the poisson disk points
  • Sometimes boundary points are needed with the pre-selected points, but the module also inserts poisson disk points when there are boundary points

These should be split up so that the caller can choose which are needed.

Remove assumption of 1000x1000 size

Right now the library assumes the points will be 0 ≤ x ≤ 1000, 0 ≤ y ≤ 1000. What does this buy me? Is there any advantage to this limitation, or is just because that's the range I used for the map project this library came from?

Remove skinny triangles

create:checkTriangleInequality checks for skinny triangles but doesn't do anything about them. Insert new points at the circumcenters (I think) to eliminate most/all of the skinny triangles.

Make ghost elements optional

I use ghost elements for my projects but it might be nice if the library didn't assume they were there.

  • _r_any_s array should have incoming edges instead of outgoing
  • _r_any_s array should have leftmost edge instead of any edge
  • r_circulate_* functions need to be updated to use incoming/outgoing instead of outgoing/incoming, and also check for -1
  • make ghost step optional in creation api
  • have a boolean function to test if a point is on the convex hull, _r_any_s[r] == -1

Export ghost element creation

Ghost elements are useful to create even if not using the rest of create.js. This should be made available somehow, without the [500,500] hard-coded ghost point.

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.