0.3.1 • Published 2 years ago

# @talesoft/geometry v0.3.1

5
MIT
Repository
github
Last release
2 years ago

## Geometry JS

A geometry data structure & calculation library.

## Installation

``npm i @talesoft/geometry``

Docs coming soon.

## Usage

### 2D Vectors

``````import { Vector2 } from '@talesoft/geometry';

const vec = new Vector2(14, 25);
vec.moveTowards({ x: 100, y: 200 }, 40);``````

Full API:

``````interface Vector2Literal {
x: number
y: number
}

type Vector2Tuple = readonly [number, number]

class Vector2 {
x: number
y: number

constructor(x?: number = 0, y?: number = 0);

set(vec2: Partial<Vector2Literal>): this
subtract(vec2: Partial<Vector2Literal>): this
multiply(vec2: Partial<Vector2Literal>): this
divide(vec2: Partial<Vector2Literal>): this
negate(): this
min(vec2: Vector2Literal): this
max(vec2: Vector2Literal): this
clamp(minValue: number, maxValue: number): this
clamp01(): this
normalize(): this
lerp(vec2: Vector2Literal, t: number): this
lerpUnclamped(vec2: Vector2Literal, t: number): this
perp(): this
moveTowards(vec2: Vector2Literal, maxDistanceDelta: number): this
moveBy(amount: number, direction: Vector2): this
getDotProduct(vec2: Vector2Literal): number
getAngleTo(vec2: Vector2): number
getDistanceTo(vec2: Vector2Literal): number
equals(vec2: Vector2Literal): boolean
isZero(): boolean
isOne(): boolean
copy(): Vector2
transform(matrix: TransformationMatrix2d): this
toTuple(): Vector2Tuple
toLiteral(): Vector2Literal
toString(): string

static fromTuple(tuple: Vector2Tuple): Vector2
static fromLiteral(literal: Vector2Literal): Vector2
}``````

### Edges

``````import { Edge, Vector2 } from '@talesoft/geometry';

const edge = new Edge(new Vector2(1, 1), new Vector2(10, 10));
console.log(edge.length);

const intersection = edge.intersectEdge(someOtherEdge);``````

Full API:

``````interface EdgeLiteral {
from: Vector2Literal
to: Vector2Literal
}

type EdgeTuple = readonly [number, number, number, number]

class Edge {
from: Vector2
to: Vector2

constructor(from: Vector2, to: Vector2)

intersectEdge(edge: Edge, ray?: boolean): Vector2 | null
toTuple(): EdgeTuple

static fromTuple(tuple: EdgeTuple): Edge
}``````

## Contributing

Before contributing, check out the Contribution Guidelines

Requires: npm

``````// Pull project
git clone https://github.com/Talesoft/geometry-js

// Enter project directory
cd geometry-js

// Install development dependencies
npm install

// ... make your changes ...

// Run tests
npm run test

// Lint
npm run lint

// Fix linting problems
npm run lint:fix

// Build
npm run build

// ... create branch, commit, push, merge request etc. ...``````
0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.1

3 years ago

0.1.0

3 years ago