Catalog npm
Back to packageRELEASE DETAILS

1.0.1

npm

2d-density

Calulates how full a grid will be if each item is spaced out by a given amount

algorithmdensitygridmathspacing
Published12 Mar 2018
Direct dependencies1
Transitive dependenciesNot calculated

README

Current package documentation

2d density

An algorithm than can be used to find the maximum number of cells that can fit into a grid with a predefined spacing. In other words two-dimensional density.

Build Status

CircleCI

Install

npm install 2d-density

Usage

const twoDDensity = require('2d-density');

const gridWidth = 100;
const gridHeight = 100;
const spacing = 3;

const result = twoDDensity.findPercentFull(gridWidth, gridHeight, spacing);

Width, height and spacing should all be whole numbers.

Spacing does not count diagonals. Thus a cell that is diagonally adjacent is really spaced 2 cells away.

Sample output

{
  count: 2000,
  percent: 0.2
}

Visual example

Say you have a grid with a width of 5 and a height of 4 and you want to fill cells that are 2 away from each other. You might end up with something like this:

xxx
xx
xxx
xx

The count would be 10 and percentage full would be 0.5. This would be pretty easy to calculate for spacing of 2 but things get more complex when using spacings with odd numbers.

For example a 5 by 5 grid with spacing of 3.

xx
x
xx

The count is only 5 and the percentage would be 0.2.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 1

Native requirements
1 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
jasmine
Environment
{
  "local_name": "jasmine",
  "alias": false,
  "peer_metadata": null
}
^3.0.0development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-CLYtkJNsek7h97Pi6SGgfJiJbpJm7gI7DmdyBoeNiaCLy7hHMDluAw31WZ7lodn9DK9lGPzERNB1m9e6TrxpPw==",
  "shasum": "7cd08f47231b21498661404c702289ff4046225b",
  "tarball": "https://registry.npmjs.org/2d-density/-/2d-density-1.0.1.tgz",
  "fileCount": 7,
  "unpackedSize": 14878,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEYCIQDsBQV+ZmrXtqp26BDtVhU2UaDN2LpNeJDZjS7945VXZgIhALqvrAZ9/HRr1lqdXag8CXuW6W5sObKcWKyKwWWu815h"
    }
  ]
}

Repository

PENDING
nilestanner/2d-density

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:10 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:991850af3ea2a137cc548033ce67b44e8dfd2301a2688665eb395300fb23f4f2

Other collected versions

1.0.012 MarView all collected versions →