
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@jiricekcz/geometry.js
Advanced tools
Geometry JS is a JavaScript/TypeScript library for creating and manipulating 2D geometry objects.
Install the library using npm:
npm install @jiricekcz/geometry-js
Import the library in your code:
import * as GeometryJS from '@jiricekcz/geometry-js';
The API documentation is available at https://geometryjs.jiricekcz.dev/. For more indepth information, see the wiki.
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).
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
Object-oriented typescript library for analytic geometry
We found that @jiricekcz/geometry.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.