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

natninter

v0.1.3

Published

Natural neighbor interpolation

Downloads

8

Readme

2D natural neighbor interpolation (nni)

For Node and browsers.

Some info about nni.
The nii method is used to interpolate sparse data point along a regular 2D grid surface. This methods work with Voronoi cells and area stilling and is said to give results that are close to the "real solution". The only issue with this method is that it's very computational, and thus, quite slow.

On the left: nni, on the right: same but with using some threshold at rendering.

Concept

Sparse point interpolations need:

  • a set of sparse points. Here, we will call them seeds
  • an output size (width and height)

This implementation performs the interpolation in two steps:

  • build the interpolation map for each output pixel, aka the weight of each seeds involved in each output pixel
  • use the interpolation map to create the output image

The purpose of creating the map at an intermediary step is to be able to reuse it for the same configuration but with different seed values, because what takes a while to generate is this interpolation map.

Install

npm install --save natninter

Use it in a HTML file:

<script src="natinter/dist/natninter.js"></script>

Use it in ES6:

import * as natninter from 'natninter';

Use it in Node:

const natninter = require("natninter");

Basic usage

// a list of seeds
var seeds = [
  {x: 100, y: 100,  value: Math.random()*255 },
  {x: 300, y: 100,  value: Math.random()*255  },
  {x: 300, y: 300, value: Math.random()*255 },
  {x: 100, y: 300, value: Math.random()*255  },
  {x: 200 , y: 200 , value: Math.random()*255 }
]

// creating the nni interpolator instance
var nnInter = new natninter.Interpolator();

// setting the output size
nnInter.setOutputSize(256, 256);

// add a list of seeds
nnInter.addSeeds( seeds );

// Create the interpolation map
// (this may take some seconds, start with a small image to benchmark it)
nnInter.generateMap();

// generate the output image witha  nice interpolation
var output = nnInter.generateImage();

The output is actually an object of the form:

{
  _data: Float32Array,
  _metadata: {
    width: Number,
    heigth: Number
  }
}

Where _data is a 1D array of length heightxwidth arrange in a row major way.

Examples

A regular example and A wavy example
See the folder examples for a Node and a browser example.

Generate a map and save it locally

natninter comes with a node executable to generate a samplig-map file in JSON format. In a terminal, find the executable generatemap.js, located in the bin folder. Then:

./generatemap.js --seeds=your/own/seedsfile.json -width=400 --height=400 --output=somehwere/map.json

You can use the seed file in bin/samples/seeds1.json and use it as a a model to write your own seed file.

Special thanks

Since I didn't want to reinvent the wheel and that I trust some good developers out there, here are the dependencies natninter uses: