# 2d-density

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

Latest version **1.0.1** (published 2018-03-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install 2d-density
pnpm add 2d-density
yarn add 2d-density
bun add 2d-density
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-03-12 |
| First published | 2018-03-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Niles Tanner |
| Maintainers | nilestanner |
| Keywords | math, density, algorithm, grid, spacing |

## Links

- npm: https://www.npmjs.com/package/2d-density
- Repository: https://github.com/nilestanner/2d-density
- Homepage: https://github.com/nilestanner/2d-density#readme
- Issues: https://github.com/nilestanner/2d-density/issues
- npm.io page: https://npm.io/package/2d-density

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-03-12
- 1.0.0 — 2018-03-12

## README

# 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](https://circleci.com/gh/nilestanner/2d-density/tree/master.svg?style=svg)](https://circleci.com/gh/nilestanner/2d-density/tree/master)

## 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:

| x |   | x |   | x |
|---|---|---|---|---|
|   | x |   | x |   |
| x |   | x |   | x |
|   | x |   | x |   |

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.

| x |   |   |   | x |
|---|---|---|---|---|
|   |   | x |   |   |
|   |   |   |   |   |
|   | x |   |   | x |
|   |   |   |   |   |

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

---
_Source: https://npm.io/package/2d-density · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
