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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gov.nasa.jpl.honeycomb/sampler-2d

v0.0.6

Published

Utility for sampling 2D float arrays in row major or column major order.

Downloads

3

Readme

Sampler 2D

Utility for sampling 2D float arrays in row major or column major order.

Use

import { Sampler2D } from '@gov.nasa.jpl.honeycomb/sampler-2d';

const data = new Float32Array( [
    0, 0, 1, 0,
    0, 1, 1, 1
] );

const sampler = new Sampler2D( data, 2, 2 );
const result = new Array();
sampler.sample( 0.5, 0.5, result ); // 0.5, 1
sampler.samplePixel( 0, 1, result ); // 0, 1

API

Sampler2D

Texture-like object with an API for sampling image data.

For simplicity image data should be thought about as 0 0 being the bottom left pixel of the image. Use xInvert or yInvert to flip the image if necessary. Data is assumed to be interleaved.

channels

channels : Number

Return the number of channels in the image.

data

data : TypedArray

The image data.

stride

stride : Number = 4

The stride of a single pixel vector in the array.

width

width : Number

The width of the data grid.

height

height : Number

The height of the data grid as derived from the data length, stride, and width.

rowMajor

rowMajor : Number = true

Whether the data should be sampled as row major (true) or column major (false).

invertX

invertX : Number = false

Whether the data should be inverted along X.

invertY

invertY : Number = false

Whether the data should be inverted along Y.

interpolate

interpolate : Number = true

If true, then the result of sampling is bilinearly interpolated between the adjacent pixels.

constructor

constructor( data : TypedArray, width : Number, stride : Number = 4 ) : void

samplePixelChannel

samplePixelChannel( x : Number, y : Number, channel : Number ) : Number | null

X is expected to be in the range [ 0, width ] and Y within [ 0, height ]. Sets target to the pixel value at the given pixel. Decimal values are not supported.

Returns null if the provided values are outside a valid range. Returns the sample value otherwise.

samplePixel

samplePixel( x : Number, y : Number, target : Array ) : Boolean

X is expected to be in the range [ 0, width ] and Y within [ 0, height ]. Sets target to the pixel value at the given pixel. Decimal values are not supported.

Returns false if the provided values are outside a valid range. Returns true otherwise.

sampleChannel

sampleChannel( u : Number, v : Number, channel : Number ) : Number | null

U and V are expected to be in the range [ 0, 1 ]. Reads and interpolates the pixels if interpolate is true.

Returns null if the provided values are outside a valid range. Returns the sample value otherwise.

sample

sample( u : Number, v : Number, target : Array ) : Boolean

U and V are expected to be in the range [ 0, 1 ]. Reads and interpolates the pixels if interpolate is true.

Returns false if the provided values are outside a valid range. Returns true otherwise.

generateMipMap

generateMipMap( target : Sampler2D = null ) : void

Creates a mip map of this Sampler2D. If the dimensions of this sampler are not a factor of two then weighted sampling over multiple pixels are used and a square mipmap is generated.

SpatialSampler2D

A sampler that contains members and functions for sampling with a 2D transform into the samplers texture space.

extends Sampler2D

inverseMatrix

inverseMatrix : Array<Number> = identity matrix

A 3x3 matrix that transforms from the given coordinate frame into the local [ 0, 1 ] texture space of the sampler for use in the spatial sample functions.

constructor

constructor( args : ...rest ) : void

spatialSampleChannel

spatialSampleChannel( x : Number, y : Number, channel : Number ) : Number | null

Transforms X and Y by inverseMatrix before sampling the texture using @Sampler2D#sampleChannel and returning the result.

spatialSample

spatialSample( x : Number, y : Number, target : Array ) : Boolean

Transforms X and Y by inverseMatrix before sampling the texture using @Sampler2D#sample and returning the result.

setMinMax

setMinMax( minX : Number, minY : Number, maxX : Number, maxY : Number ) : void

Sets inverseMatrix to transform from a span of min to max x and y into the span [ 0, 1 ].

BandSampler2D

A sampler that stores each channel as a separate sampler and samples data accordingly. Use this if image data is not provided as interleaved.

implements BandSampler2D

rowMajor

rowMajor : null

invertX

invertX : null

invertY

invertY : null

bands

bands : Array<Sampler2D> = []

Array of sampler 2d instances where each band corresponds to a different channel.

constructor

constructor( bands : Array<Sampler2D> = [] ) : void