Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

point3d

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

point3d

Cartesian 3D data type, with basic vector math methods

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

point3d

Cartesian 3D data type, with basic vector math methods

How to use point3d in your project

point3d is published as an NPM module. To install it in your project, simply execute the following:

npm install --save point3d

point3d exports a single class. The class constructor can be used to construct Cartesian points at specified coordinates, as follows:

import { Point3d } from "point3d";

const point = new Point3d({ x: 1.0, y: 1.0, z: 1.0 });

The constructed Point has attached methods to perform basic vector math, such as equality checks, addition, subtraction, and scalar and vector products. The methods are written in a pseudo-functional style, always returning the result rather than modifying an existing object. This allows for a concise, chainable syntax. For example, to compute the linear sum a * x + b = c, you can simply chain as follows:

const c = x.scale(a).plus(b);

See the class documentation for more details.

About point3d development

point3d was written in a single 3-hour sprint. Development began with a 30-minute strategizing session, during which the following key decisions were made:

  • Code would be written as an ES6 class. This means it is not supported in Internet Explorer. But all other major browsers support classes, and classes are a good fit for defining a data type
  • Methods would be written in a pseudo-functional style, returning a new instance of the class where necessary. While potentially not as memory-efficient as modify-in-place libraries like glMatrix, it allows for more concise syntax
  • The constructor would input an object with x, y, and z properties, rather than separate parameters for each coordinate. This decision is perhaps of debatable value, but it allows the constructor to input another Point3d
  • The coordinates themselves (x, y, z) would be private to the class. This means they cannot be modified without calling the class methods

Actual coding took about 1.5 hours. Another half hour was needed to learn jasmine, and another half hour to learn JSDoc and write the README.

Contributing

Feedback and pull requests are welcome! If you want to try modifying the code, fork the repository on GitHub.

To make sure we don't break anything as we change the code, point3d has a test suite (implemented in jasmine, which you can run as follows:

npm run test

Please be sure to update the comments in the code. Comments should follow the JSDoc syntax. When you are done, be sure to rebuild the docs before committing your code. This can be done via another of the NPM scripts, as follows:

npm run build-docs

Keywords

FAQs

Package last updated on 07 May 2022

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc