@bucky24/toolbox
Toolbox
This is intended to be a collection of misc things that I've had to do over and over again. It is small but will hopefully continue to grow.
Importing
Import the code by using:
import { Polygon } from '@bucky24/toolbox';
Or for client items:
import { usePersistedState } from '@bucky24/toolbox/client';
Exports
Polygon
The Polygon class contains methods for manipulating and getting data about polygons.
pointInsidePolygon
This method returns a boolean indicating if the given Point is inside the given Polygon
| param | type | description |
|---|---|---|
| point | Point | The point to check against the polygon |
| polygon | Polygon | The Polygon to check |
Line
The Line class contains methods for getting data about lines
distanceFromLine
This method will calculate the distance from a Point to a Line. Note this does not calculate distance to a line segment, the Points given in the Line are used to calculate a line of infinite length.
| param | type | description |
|---|---|---|
| line | Line | The line to use for distance |
| point | Point | The point to use for distance |
doLinesIntersect
This method returns a boolean if the two Lines provided intersect. This is done on line segments, not infinite lines.
| param | type | description |
|---|---|---|
| line1 | Line | The line to compare |
| line2 | Line | The second line to compare |
usePersistedState
This behaves like useState in React, but persists the value to localStorage. On load, it attempts to load any value from localStorage. This allows a simple persisting of various state across reloads.
Types
Point
A point is a simple object that contains a numeric x and a numeric y.
Polygon
The Polygon type is simply an array of Points.
Line
A line is simply an array containing two Points, representing the start and end of a line segment.