npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

points-to-vertices

v0.2.0

Published

:white_square_button: a points to vertices array convertor

Downloads

49

Readme

points-to-vertices

:white_square_button: a points to vertices array convertor

Node NPM Travis David Coverage Status

Gitmoji

Usage

import pointsToVertices from 'points-to-vertices';

const points = [
  {
    x: 1,
    y: 1,
    z: 1,
    color: `rgba(255, 0, 0, .3)`
  },
  {
    x: 1,
    y: - 1,
    z: 0,
    color: `#FF0000`
  }
];

const vertices = pointsToVertices(points);
console.log(vertices);
// > [1, 1, 1,  1, 0, 0, .3,  1, -1, 0,  1, 0, 0, 1]

Each point can have x, y, z and color (vec4, hex, rgb or rgba) properties points-to-vertices fills in the blanks with (provided) defaults.

result is an array of vertices

[

  // point 1
  1, 1, 1,      // x, y, z
  1, 0, 0, .3,  // r, g, b, a

  // point 2
  1, -1, 0,     // x, y, z
  1, 0, 0, 1    // r, g, b, a

]

Installation

Install via yarn

yarn add points-to-vertices (--dev)

or npm

npm install points-to-vertices (--save-dev)

configuration

You can pass in extra options as a configuration object (all parameters are optional)

import pointsToVertices from 'points-to-vertices';

const points = [
  {
    x: -1,
    y: 0,
    z: 0,
    color: `rgba(255, 0, 0, .3)`
  },
  {
    x: 0,
    y: - 1,
  }
];

const vertices = pointsToVertices(points, {
  meta: true, // wrap the data in an object
  color: false // no colors in result vertices array, only points
  dx: 1, // default x
  dy: 1, // default y
  dz: - 1, // default z
  dcolor: `#FFFF00` // default color
});

color ( boolean ) ✏️ true 📝 output colors in vertices array ℹ️ false => [x, y, z] vertex ℹ️ true => [x, y, z, r, g, b, a] vertex (default)

meta ( boolean ) ✏️ false 📝 wrap the result in an object (with a meta property) ℹ️ returns extra info on vertices, start and end of position, color, total length ℹ️ meta: false returns a simple vertices array

example output with meta: true (annotated for clarity)

{

  data: [

  	// point 1
  	0, 0, 1,     // position (x, y, z)
  	0, 1, 1, 1,  // color (r, g, b, a)

  	// point 2
  	1, - 1, 0,    // position (x, y, z)
  	0, 1, 1, 1   // color (r, g, b, a)

  ],

  meta: {

   	// each vertex is 7 long
   	vertexLength: 7,

    // there are 2 vertices in this array
   	amount: 2,

   	// position is 3 long, starts at index 0
    position: { start: 0, length: 3 },

    // color is 4 long, starts at index 3
    color: { start: 3, length: 4 }
  }

}

you can pass in default values for x, y, z and color if no value is set for x, y, z, or color, points-to-vertices will use the default

dx ( number ) ✏️ 0 📝 default x for a vertex

dy ( number ) ✏️ 0 📝 default y for a vertex

dz ( number ) ✏️ 0 📝 default z for a vertex

dcolor ( vec4 | string ) ✏️ [0, 0, 0, 1] (black) 📝 default z for a vertex

Examples

See example folder

Builds

If you don't use a package manager, you can access points-to-vertices via unpkg (CDN), download the source, or point your package manager to the url.

points-to-vertices is compiled as a collection of CommonJS modules & [ES2015 modules](http://www.2ality.com/2014/0 -9/es6-modules-final.html) for bundlers that support the jsnext:main or module field in package.json (Rollup, Webpack 2)

The points-to-vertices package includes precompiled production and development UMD builds in the dist folder. They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments. You can drop a UMD build as a <script> tag on your page. The UMD builds make points-to-vertices available as a window.pointsToVertices global variable.

License

The code is available under the MIT license.

Contributing

We are open to contributions, see CONTRIBUTING.md for more info.

Misc

This module was created using generator-module-boilerplate.