https://github.com/superraytin/slices
Node.js module for slicing given area into blocks with the given reference lines. :fork_and_knife: :cake:
https://github.com/superraytin/slices
Last synced: about 1 year ago
JSON representation
Node.js module for slicing given area into blocks with the given reference lines. :fork_and_knife: :cake:
- Host: GitHub
- URL: https://github.com/superraytin/slices
- Owner: superRaytin
- License: mit
- Created: 2015-12-13T14:11:56.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-15T03:57:00.000Z (almost 10 years ago)
- Last Synced: 2025-04-03T14:39:18.629Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 135 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Yeah, no kidding, you give me a range (width & height) and reference lines, and I'll give you blocks, the same as cutting the cake! :fork_and_knife: :cake:
# slices
> Node.js module for slicing given area into blocks with the given reference lines
[](https://travis-ci.org/superRaytin/slices)
[![NPM version][npm-image]][npm-url]
[![Downloads][downloads-image]][npm-url]
[](https://npmjs.org/package/slices)
[npm-url]: https://npmjs.org/package/slices
[downloads-image]: http://img.shields.io/npm/dm/slices.svg
[npm-image]: http://img.shields.io/npm/v/slices.svg
```js
var Slices = require('slices');
var blocks = Slices(500, 500, [100], [100]);
```
Get blocks:
```js
[
{ width: 100, height: 100, x: 0, y: 0 },
{ width: 400, height: 100, x: 100, y: 0 },
{ width: 100, height: 400, x: 0, y: 100 },
{ width: 400, height: 400, x: 100, y: 100 }
]
```
# Installation
```
npm install slices
```
# API
### Slices(width, height, lineXArray, lineYArray [, options])
- **width:** Number of pixels wide
- **height:** Number of pixels high
- **lineXArray:** reference lines of the X axis
- **lineYArray:** reference lines of the Y axis
- **options:** slice with some optional parameters, see [options](#options) for detail.
## Options
### middleBoundaryMode
Either true or false, default is false.
If set to true, this will put spaces between each two lines of X axis as parent-block,
the areas between the first line of Y axis and the last will be children of the parent-block, and it will generate boundary data.
Below is an example:
```js
Slices(500, 500, [100, 300], [100, 200, 300], {middleBoundaryMode: true});
```
Get blocks like below:
```js
[
{
"width": 500,
"height": 100,
"x": 0,
"y": 0,
"children": [
{
"width": 100,
"height": 100,
"x": 100,
"y": 0,
"left": 0,
"top": 0,
"parentBlockIndex": 0,
"index": 0
},
{
"width": 100,
"height": 100,
"x": 200,
"y": 0,
"left": 100,
"top": 0,
"parentBlockIndex": 0,
"index": 1
}
],
"boundary": {
"leftTop": {
"x": 100,
"y": 0
},
"rightBottom": {
"x": 300,
"y": 100
}
}
},
...
]
```
## Where is this library used?
If you are using this library in one of your projects, add it in this list :)
- [image-to-slices](https://github.com/superRaytin/image-to-slices)
- [Puzzler](https://github.com/superRaytin/puzzler)
# Testing
```
npm test
```
# License
MIT, see the [LICENSE](/LICENSE) file for detail.