Socket
Book a DemoInstallSign in
Socket

@jiricekcz/geometry.js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jiricekcz/geometry.js

Object-oriented typescript library for analytic geometry

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Geometry JS

Geometry JS is a JavaScript/TypeScript library for creating and manipulating 2D geometry objects.

Table of contents

  • Geometry JS

Getting started

Install the library using npm:

npm install @jiricekcz/geometry-js

Import the library in your code:

import * as GeometryJS from '@jiricekcz/geometry-js';

Documentation

The API documentation is available at https://geometryjs.jiricekcz.dev/. For more indepth information, see the wiki.

Requirements

Geometry JS requires a JavaScript runtime with support for ES6. It is a zero-dependency TypeScript library, so it can be used in any JavaScript project (Node.js, React, Angular, Vue, etc.). For more information about requirements, see the wiki (Requirements).

Usage

After importing the library, getting started is easy.
First, we need to create the main Plane object. This object represents the 2D plane on which all geometry objects are created.

import * as GeometryJS from '@jiricekcz/geometry-js';

// Create the main Plane object
const plane = GeometryJS.createPlane();

After that, we can create some geometry objects. For example, let's create a value (variable) x and a readonly value y.

// Create a value (variable) x
const x = plane.createValue(1);

// Create a readonly value y
const y = plane.createReadonlyValue(2);

Now, we can create a point A with coordinates x and y.

// Create a point A with coordinates x and y
const A = plane.createPointFromTwoValues(x, y);

We can also create a point B with coordinates 3 and 4.

// Create a point B with coordinates 3 and 4
const B = plane.createPointFromCoordinates(3, 4);

Now, we can create a line l from points A and B.

// Create a line l from points A and B
const l = plane.createLineFromTwoPoints(A, B);

We can also create a point O at the origin of the plane.

// Create a point O at the origin of the plane
const O = plane.createPointFromCoordinates(0, 0);

Then we can construct a line perpendicular to AB through O.

// Create a line perpendicular to l through O
const perpendicular = plane.constructPerpendicularLineFromPoint(l, O);

With just this code, we have declaratively defined the geometry. If we change any property of any non-readonly object, the whole geometry will be recalculated.

The whole code with minimal comments:

import * as GeometryJS from '@jiricekcz/geometry-js';

const plane = GeometryJS.createPlane();

const x = plane.createValue(1);
const y = plane.createReadonlyValue(2);

const A = plane.createPointFromTwoValues(x, y);
const B = plane.createPointFromCoordinates(3, 4);

const l = plane.createLineFromTwoPoints(A, B);

const O = plane.createPointFromCoordinates(0, 0);

const perpendicular = plane.constructPerpendicularLineFromPoint(l, O);

Beacuse of the declarative nature and descriptive names of the functions, the code is very readable and easy to understand.

FAQs

Package last updated on 02 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.