npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

arrugator

v1.2.1

Published

Utility for warping GIS-like triangular meshes to fit a projection; meant for helping WebGL raster reprojection.

Downloads

43

Readme

Arrugator

A tool for subdividing triangular meshes for GIS reprojection purposes.

See https://ivan.sanchezortega.es/development/2021/03/08/introducing-arrugator.html

Usage

The inputs are:

  • A projector function (which takes an Array of 2 Numbers, and returns an Array of 2 Numbers). Typically this is meant to be a proj4js forward projection function, like proj4(srcCRS, destCRS).forward; however, arrugator has no hard dependency on proj4js, so other projection methods could be used.
  • The unprojected coordinates (an Array of Arrays of 2 Numbers, typically NW-SW-NE-SE)
  • The UV-mapping coordinates (an Array of Arrays of 2 Numbers, typically [[0,0],[0,1],[1,0],[1,1]])
  • The vertex indices of the triangles composing the initial mesh (an Array of Arrays of 3 Numbers, typically [[0,1,3],[0,3,2]]).

Note that the typical input is four vertices, but there's no hard requirement on that. Any triangular mesh should do (and maybe there are edge cases I haven't think of where it's required so things work for weird projections like polyhedral ones).

And the ouputs are:

  • The unprojected vertex coordinates (an Array of Arrays of 2 Numbers)
  • The projected vertex coordinates (an Array of Arrays of 2 Numbers)
  • The UV-mapping coordinates (an Array of Arrays of 2 Numbers)
  • The vertex indices of the triangles composing the mesh (an Array of Arrays of 3 Numbers).

Usage example

Initialize some data (assuming proj4 has already been set up):

// These are the corner coordinates of a Spanish 1:2.000.000 overview map in ETRS89+UTM30N:
let epsg25830coords = [
	[-368027.127, 4880336.821], // top-left
	[-368027.127, 3859764.821], // bottom-left
	[1152416.873, 4880336.821], // top-right
	[1152416.873, 3859764.821], // bottom-right
];

let sourceUV = [
	[0, 0], // top-left
	[0, 1], // bottom-left
	[1, 0], // top-right
	[1, 1], // bottom-right
];

let arruga = new Arrugator(
	proj4("EPSG:25830", "EPSG:3034").forward,
	epsg25830coords,
	sourceUV,
	[
		[0, 1, 3],
		[0, 3, 2],
	] // topleft-bottomleft-bottomright ; topleft-bottomright-topright
);

Then, subdivide once:

arruga.step();

Or subdivide several times:

for (let i = 0; i < 10; i++) {
	arruga.step();
}

Or subdivide until epsilon is lower than a given number (square of distance in map units of the projected CRS - in this example, EPSG:3034 map units):

arruga.lowerEpsilon(1000000); // 1000 "meter"s, squared

Once you're happy with the subdivisions, fetch the mesh state:

let arrugado = arruga.output();

let unprojectedCoords = arrugado.unprojected;
let projectedCoords = arrugado.projected;
let uvCoords = arrugado.uv;
let trigs = arrugado.trigs;

The output are Arrays of Arrays, so the use case of dumping the data into a TypedArray to use it in a WebGL buffer needs them to be .flat()tened before.

How to do this depends on how you're usign WebGL (or what WebGL framework you're using). For example, my glii examples work like:

const pos = new glii.SingleAttribute({ glslType: "vec2", growFactor: 2 });
const uv = new glii.SingleAttribute({ glslType: "vec2", growFactor: 2 });
const indices = new glii.TriangleIndices({ growFactor: 2 });

pos.setBytes(0, 0, Float32Array.from(arrugado.projected.flat()));
uv.setBytes(0, 0, Float32Array.from(arrugado.uv.flat()));
solidIndices.allocateSlots(arrugado.trigs.length * 3);
solidIndices.set(0, arrugado.trigs.flat());
wireIndices.allocateSlots(arrugado.trigs.length * 3);
wireIndices.set(0, arrugado.trigs.flat());

Demos

See the demo branch of this git repository; there are some glii-powered examples there, including demo raster data.

Legalese

Released under the General Public License, v3. See the LICENSE file for details.