JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 21
  • Score
    100M100P100Q67158F
  • License ISC

Library for polygons operations

Package Exports

  • @slydock/poly-js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@slydock/poly-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Poly-JS

Poly-JS is a library for manipulating 2D polygons, shapes, points...

Features

  1. 2D vertices operations
  2. 2D lines operations
  3. 2D polygons operations
  4. 2D rect operations
  5. 2D circle operations

Installation

npm i @slydock/poly-js

Basic Usage

For any component need, you'll need to import the plugin

const {
    Vector2,
    Line,
    Polygon,
    Rect,
    Circle
} =  require('@slydock/poly-js');

Vector2

Construction

    new Vector2() // Empty vector
    new Vector2(xy) // x and y will be set to the same value
    new Vector2(x, y) // x > x && y > y
    new Vector2({x: x, y: y}) // Create a vector from a vector like object

Properties

    x: float; //x value of the vector2
    y: float; //y value of the vector2

Methods

floor

@param float v Precision

    floor(v: float = 1.0)
    floorX(v: float = 1.0) // Only X axis
    floorY(v: float = 1.0) // Only Y axis

ceil

@param float v Precision

    ceil(v: float = 1.0)
    ceilX(v: float = 1.0) // Only X axis
    ceilY(v: float = 1.0) // Only Y axis

round

@param float v Precision

    round(v: float = 1.0)
    roundX(v: float = 1.0) // Only X axis
    roundY(v: float = 1.0) // Only Y axis

set

    set(x: float, y: float)
    set(xy: float)
    set({x: float, y: float})
    set(v: Vector2)
    setX(v: float) // Only X axis
    setY(v: float) // Only Y axis

add

    add(x: float, y: float)
    add(xy: float)
    add({x: float, y: float})
    add(v: Vector2)
    addX(v: float) // Only X axis
    addY(v: float) // Only Y axis

substract

    substract(x: float, y: float)
    substract(xy: float)
    substract({x: float, y: float})
    substract(v: Vector2)
    substractX(v: float) // Only X axis
    substractY(v: float) // Only Y axis

multiply

    multiply(x: float, y: float)
    multiply(xy: float)
    multiply({x: float, y: float})
    multiply(v: Vector2)
    multiplyX(v: float) // Only X axis
    multiplyY(v: float) // Only Y axis

divide

    divide(x: float, y: float)
    divide(xy: float)
    divide({x: float, y: float})
    divide(v: Vector2)
    divideX(v: float) // Only X axis
    divideY(v: float) // Only Y axis

invert

    invert()
    invertX() // Only X axis
    invertY() // Only Y axis

rotate

@param float angle Angle to rotate (degrees)

    rotate(angle: float)

equals

Compare two Vector2 and return true if there are equals

    equals(x: float, y: float)
    equals(xy: float)
    equals({x: float, y: float})
    equals(v: Vector2)
    equalsX(v: float) // Only X axis
    equalsY(v: float) // Only Y axis

isInside

Check if the Vector2 is inside a Polygon

    isInside(p: Polygon)

Getters

approximate

Get an approximated value of the Vector2, removing floating point error

normalized

Get the normalized Vector2 (alia: norm)

magnitude

Get the magnitude of the Vector2

get clone

Get a clone of the current Vector2

Static methods

Distance

Get the distance between two Vector2

    Distance(v1: Vector2, v2: Vector2)

Max

Get max values from two Vector2

    Max(v1: Vector2, v2: Vector2)

Min

Get min values from two Vector2

    Min(v1: Vector2, v2: Vector2)

Lerp

Get a clamped lerp Vector2 from v1 to v2, with t time

    Lerp(v1: Vector2, v2: Vector2, t: float)

LerpUnclamped

Get a unclamped lerp Vector2 from v1 to v2, with t time

    LerpUnclamped(v1: Vector2, v2: Vector2, t: float)