area-man
v0.3.6
Published
a simple utils lib for handling areas
Downloads
1
Readme
Area Manager
A simple utils library for handling areas. Create, move, reflect, scale, squash etc
Install:
Area Man is available as the area-man package on npm.
npm install area-man --save
Usage
var AreaMan = require('area-man');You can use ES6 imports too:
import {Area}} from 'area-man';
const area = new Area(params);AreaMan.newArea(params [,id])
Creates a new area.
params: object
Needs the properties x, y, width, height or x1, y1, x2, y2.
id: string
Optional id if you want to be able to retrieve an area later (WIP).
returns: Area
Area.width | height
Get or set the area's width or height
returns: [number]
Area.isWide | isTall | isSquare
compare width and height to tell is an area is taller than it is wide
returns: [boolean]
Area.area
calculate the area's surface area
returns: [number]
Area.centrePoint
TODO
Area.move(x: number = 0, y: number = 0)
Translate the area by x, y
returns: Area
Area.shrink(adjustments: number | [number, number, number, number])
Area.grow(adjustments: number | [number, number, number, number])
Shrink or grow the area, removing the given values from each side. If a single value is provided then all sides will be adjusted equally.
returns: Area
Area.scale(scale: number, originX: number, originY: number)
Scale an area.
returns: Area
Area.squash(squashDirection: string, percentage: number, originX: number, originY: number)
Squash an area, changing its size but keeping its surface area the same.
params: squashDirection
Specify "horizontal" or "vertical"
params: percentage
How much to squash the area as a percentage of its current size.
params: originX originY`
Origin point for the squash relative to the area. 0,0 is the top-left corner, 1,1 is bottom-right.
returns: Area
Area.reflect(reflectX: boolean, reflectY: boolean, originX: number, originY: number)
Reflect an area.
returns: Area
Area.clone(id?: string)
Clone an area.
returns: Area
Area.split(sliceDirection: string, percentage: number, clone: boolean = true)
Split an area in two. The default is to clone the source area and keep the original unchanged, but you can override this to affect the original area if needed.
returns: Area
Area.hitTest(areas: IArea | IArea[])
Test whether an area (or any of a list of areas) overlap a target area.
returns: boolean
TODO
- comprehensive documentation
- better demo page
- more operations
- different shapes
