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

hexacubic

v0.1.0-alpha.17

Published

A mathy Javacript utility library for working with hexacubic grids functionally

Downloads

54

Readme

hexacubic

npm node npm npm Travis Coveralls github

⬢ → * → ⬡

A mathy Javacript utility library for working with hexacubic grids functionally

Getting started

Install via yarn or npm:

yarn add hexacubic
npm install hexacubic -S

CJS

const H = require('hexacubic')

ES6

import H from 'hexacubic'

API

H.centerToNeighbors(hexacube)

Point → [Point]

Takes a hexacube center point and returns an array of center points of its neighbor hexacubes.

Parameters
  • hexacube (Point): The center point of the hexacube.
Returns
  • ([Point]): Returns an array of center points of the neighbor hexacubes of the hexacube.
Examples
const origin = [0, 0, 0];

H.centerToNeighbors(origin);
// => 
// [
//  [1, 0, -1],
//  [-1, 0, 1],
//  [0, 1, -1],
//  [0, -1, 1],
//  [1, -1, 0],
//  [-1, 1, 0]
//]

H.isNeighborOf(hexacubeA)(hexacubeB)

Point → Point → Boolean

Creates a predicate function that evaluates if hexacubeB is a neighbor of hexacubeA.

Parameters
  • hexacubeA (Point): The center point of the source hexacube.
  • hexacubeB (Point): The center point of the target hexacube.
Returns
  • (Boolean): Returns true if source and target hexacubes are neighbors, else false.
Examples
const homer = [0, 0, 0];
const flanders = [1, 0, -1];

H.isNeighborOf(homer)(flanders);
// => true

const patty = [10, -5, -5];

H.isNeighborOf(homer)(patty);
// => false

const selma = patty;
H.isNeighborOf(patty)(selma);
// => false

H.centerToCorners(hexacube)

Point → [Point]

Takes a hexacube center point and returns its corner points.

Parameters
  • hexacube (Point): The center point of the hexacube.
Returns
  • ([Point]): Returns an array of corner points of the hexacube.
Examples
const origin = [0, 0, 0];

H.centerToCorners(origin);
// => 
//[ 
//   [ 0.3333333333333333, 0.3333333333333333, -0.6666666666666666 ],
//   [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ],
//   [ -0.6666666666666666, 0.3333333333333333, 0.3333333333333333 ],
//   [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ],
//   [ 0.3333333333333333, 0.3333333333333333, -0.6666666666666666 ],
//   [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ] 
// ]

H.centerToEdges(hexacube) [aliases: H.centerToBounds]

Point → [Edge]

Takes a hexacube center point and returns its edges.

Parameters
  • hexacube (Point): The center point of the hexacube.
Returns
  • ([Edge]): Returns an array of corner point pairs representing the edges of the hexacube.
Examples
const origin = [0, 0, 0];

H.centerToEdges(origin);
// => 
// [ 
//   [ 
//     [ 0.3333333333333333, 0.3333333333333333, -0.6666666666666666 ],
//     [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ] 
//   ],
//   [ 
//     [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ],
//     [ -0.6666666666666666, 0.3333333333333333, 0.3333333333333333 ] 
//   ],
//   [ 
//     [ -0.6666666666666666, 0.3333333333333333, 0.3333333333333333 ],
//     [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ] 
//   ],
//   [ 
//     [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ],
//     [ 0.3333333333333333, 0.3333333333333333, -0.6666666666666666 ] 
//   ],
//   [ 
//     [ 0.3333333333333333, 0.3333333333333333, -0.6666666666666666 ],
//     [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ] 
//   ],
//   [ 
//     [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ],
//     [ 0.3333333333333333, 0.3333333333333333, -0.6666666666666666 ] 
//   ]
// ]

H.centersToEdges(hexacubes)

[Point] → [Edge]

Takes a set of hexacube center points returns all the edges. (deduped)

Parameters
  • hexacubes ([Point]): The array of center points of the hexacubes.
Returns
  • ([Edge]): Returns an array of corner point pairs, or edges, of every hexacube.
Examples
const origin = [0, 0, 0];

const originAndNeighbors = [
    origin,
    ...H.centerToNeighbors(origin)
]

H.centersToEdges(originAndNeighbors);
// => 
// [ 
//   [ 
//     [ 0.3333333333333333, 0.3333333333333333, -0.6666666666666666 ],
//     [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ] 
//   ],
//   [ 
//     [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ],
//     [ -0.6666666666666666, 0.3333333333333333, 0.3333333333333333 ] 
//   ],
//   [ 
//     [ -0.6666666666666666, 0.3333333333333333, 0.3333333333333333 ],
//     [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ] 
//   ],
//   [ 
//     [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ],
//     [ 0.3333333333333333, 0.3333333333333333, -0.6666666666666666 ] 
//   ],
//   [ 
//     [ 0.3333333333333333, 0.3333333333333333, -0.6666666666666666 ],
//     [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ] 
//   ],
//   [ 
//     [ -0.3333333333333333, 0.6666666666666666, -0.3333333333333333 ],
//     [ 0.3333333333333333, 0.3333333333333333, -0.6666666666666666 ] 
//   ]
//   ... 36 more edges (6 edges for each neighbor of origin)
// ]

If you want all the edges with duplicates instead, use flatMap with .centerToEdges():

import _ from "lodash/fp"

const edges = _.flatMap(H.centerToEdges)(originAndNeighbors)

H.centersToBounds(hexacubes)

[Point] → [Edge]

Takes a set of hexacube center points and returns the edges of its boundary.

Parameters
  • hexacubes ([Point]): The array of the center points of the hexacubes.
Returns
  • ([Edge]): Returns an array of the edges of the boundary around the cluster(s) of hexacubes.
Examples
const origin = [0, 0, 0];

const originAndNeighbors = [
    origin,
    ...H.centerToNeighbors(origin)
]

H.centersToBounds(originAndNeighbors);
// => 
// [ 
//   ... 18 edges total (3 edges on boundary for each neighbor of origin)
// ]

H.accumlateBounds(accumulator, edge, edgeIndex, edges)

Accumlates an edge if it is a boundary edge with respect to a set of edges

const edges = H.centersToEdges(hexacubes);
const bounds = edges.reduce(H.accumlateBounds);

H.toProjection(point)

Point → XY

Projects a hexacubic point isometrically to a plane of view, where x-axis is the horizontal axis and y-axis and z-axis are the diagonal axis

H.toProjection(origin)
// => [0, 0]

H.centerToCorners(origin)
  .map(_.compose(customTransform, H.toProjection))
  .map(([x,y]) => <Point x={x} y={y}/>)
// =>

const customProjectionOf = _.compose(customTransform, H.toProjection)

H.centerToEdges(origin)
  .map(edge => edge.map(customProjectionOf))
  .map(([[Ax,Ay],[Bx,By]]) => <Line Ax={Ax} Ay={Ay} Bx={Bx} By={By}/>)
// =>

H.toProjectionWith(options)(point)

Point → * → XY

options:

  • size (Number) - The projection scalar.
  • offset ([Number]) - The projection translated.

H.toMidpoint(points)

[Point] → Point

Takes an array of hexacubic points and returns the midpoint, or median point.


const origin = [0, 0, 0];
const neighborOfOrigin = [0, 1, -1];

H.toMidpoint([origin, neighborOfOrigin])
// => [0, .5, -.5]

const neighborsOfOrigin = H.centerToNeighbors(origin);
H.toMidpoint(neighborsOfNeighbor);
// => [0, 0, 0]

H.distanceFrom(hexacubeA)(hexacubeB)

Point → Point → Number

Creates a function that calculates the distance of hexacubeB from hexacubeA.


const origin = [0, 0, 0];
const neighborOfOrigin = [0, 1, -1];

H.distanceFrom(origin)(neighborOfOrigin)
// => 1

const distanceFromOrigin = H.distanceFrom(origin)
const elsewhere = [5, -5, 0]
distanceFromOrigin(elsewhere)
// => 5

H.centersToPolygons(hexacubes)

[Point] → [Polygon]

Takes a set of hexacube center points and returns a set of one or more polygons (one for each bound cluster).

Parameters
  • hexacubes ([Point]): The array of the center points of the hexacubes.
Returns
  • ([Polygon]): Returns an array of the polygon(s) of the bound cluster(s) of hexacubes.
Examples
const origin = [0, 0, 0];

H.centersToPolygons([origin]);
// => 
// [ 
//   ... 1 polygon with 6 points
// ]


const originAndNeighbors = [
    origin,
    ...H.centerToNeighbors(origin)
]

H.centersToPolygons(originAndNeighbors);
// => 
// [ 
//   ... 1 polygon with 18 points
// ]