https://github.com/stein197/js-point
N-dimentional point implementation
https://github.com/stein197/js-point
2d 3d point
Last synced: 5 months ago
JSON representation
N-dimentional point implementation
- Host: GitHub
- URL: https://github.com/stein197/js-point
- Owner: stein197
- License: mit
- Created: 2022-05-15T11:14:06.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-07-15T07:07:06.000Z (almost 3 years ago)
- Last Synced: 2025-11-23T15:05:34.898Z (7 months ago)
- Topics: 2d, 3d, point
- Language: TypeScript
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# N-dimentional point implementation
This tiny package contains only one class `Point` that can be used to represen any-dimentional points.
## Installation
```
npm i @stein197/point
```
## Usage
Represents an N-dimentional point which can be applied in both two or three dimentions and more. Basic usage is:
```ts
let p = new Point<3>(0, 1, 2); // three-dimentional point
p.vector; // [0, 1, 2]: plain tuple
p.x; // 0
p.y; // 1
p.z; // 2
```
When working with two-dimentional points it's worth using static `Point.create()` function which excludes
redundant `z` property from the instance:
```ts
let p = Point.create<2>(1, 2);
p.x; // 1
p.y; // 2
p.z; // Error - z does not exist
```
The same applies to one-dimentional points:
```ts
let p = Point.create<1>(1);
p.x; // 1
p.y; // Error - y does not exist
```
## API
| Method | Return type | Description |
|---|---|---|
| `Point.getDistance(point: Point)` | `number` | Resolves the distance length between two points |
| `Point.interpolate(p1: Point, p2: Point, t: number)` | `Point` | Returns a new point at t between points p1 and p2 |
## NPM scripts
- `build` builds the project
- `test` runs unit tests