Code Monkey home page Code Monkey logo

point3d's Introduction

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, rebuild the docs before committing your code. This can be done via one of the NPM scripts, as follows:

npm run build-docs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.