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

ennea-tree

v2.3.0

Published

Immutable tilemap quad-tree with support for mega-tiles

Downloads

188

Readme

ennea-tree

Immutable tilemap quad-tree with support for mega-tiles

Installation

npm install --save ennea-tree

Usage

import * as enneaTree from 'ennea-tree'

let tree = enneaTree.createTree(16);
tree = enneaTree.set(tree, 'hello', {top:0, left:0});
tree = enneaTree.set(tree, 'hi', {top:4, left:7, width:3, height:5});
for(const fruit of enneaTree.getIterator(tree, {top:0, left:0, width:16, height:16})){
    console.log(fruit);
}

Methods

enneaTree.get(tree, top, left)

Get the data at the position, or null.

// returns
{
    data,
    top,
    left,
    width,
    height
}

enneaTree.set(tree, data, {top, left, width=1, height=1, right=left+width, bottom=top+height})

Set the data at the position or area. Specify either the width/height or right/bottom. Returns the modified tree. If the area is not empty, returns the original tree.

See also setUnsafe, which does not check if the area is empty before setting, and can therefore result in corrupted data.

enneaTree.diff(treeBefore, treeAfter)

Get the differences between two trees. This is a generator, you can use for of to loop through the changes.

// returns
{
    type: SET,
    top,
    left,
    width,
    height,
    after
}

{
    type: UPDATE,
    top,
    left,
    width,
    height,
    before,
    after
}

{
    type: CLEAR,
    top,
    left,
    width,
    height,
    before
}

enneaTree.clear(tree, {top, left, width=1, height=1, right=left+width, bottom=top+height})

Clear the position or area. Returns the modified tree.

See also clearUnsafe, which returns null if the tree becomes empty.

enneaTree.update(tree, (before, context, {top, left}) => after)

Update multiple positions in a tree without creating intermediate tree structures.

const updater = enneaTree.update(tree, (before, context, {top, left}) => before+context);
updater.update({0, 0}, 10);
tree = updater.result([
    {area: {1, 1}, context: 5},
    {area: {1, 2}, context: 5},
    {area: {1, 3}, context: 5}
]);

Note: updater.result takes an array that can be used as a queue. You can push changes onto this queue from the update callback.

enneaTree.getAll(tree, {top, left, width=1, height=1, right=left+width, bottom=top+height})

Get all the data within the area as an array. This is a convenience method that uses getIterator.

// returns
[{
    data,
    top,
    left,
    width,
    height
}]

enneaTree.isEmpty(tree, {top, left, width=1, height=1, right=left+width, bottom=top+height})

Check if the area is empty, ie, if getAll returns an empty array.

enneaTree.setUnsafe(tree, data, , {top, left, width=1, height=1, right=left+width, bottom=top+height})

This method can result in corrupted trees.

See set.

enneaTree.createNode(size=1)

returns a new empty node with the specified size.

enneaTree.clearUnsafe()

This method will return null if the tree is empty after clearing

See clear.

enneaTree.getIterator(tree, {top, left, width=1, height=1, right=left+width, bottom=top+height})

Get all the data within the area as an iterator, than can be looped over with a for of loop.

// returns
{
    data,
    top,
    left,
    width,
    height
}

enneaTree.createTree(size=1)

See createNode.

Constants

enneaTree.SET

'set'

enneaTree.UPDATE

'update'

enneaTree.CLEAR

'clear'