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

jsbezier

v0.9.5

Published

Bezier curve helper functions for JavaScript. Used by jsPlumb; perhaps useful for others.

Downloads

100

Readme

jsBezier

This is a set of Bezier curve functions that deal with Beziers, used by jsPlumb, and perhaps useful for other people. These functions work with Bezier curves of arbitrary degree.

Installation

npm install jsbezier

Notes

  • all input points should be in the format {x:.., y:..}. all output points are in this format too.
  • all input curves should be in the format [ {x:.., y:..}, {x:.., y:..}, {x:.., y:..}, {x:.., y:..} ]
  • The order of the points is [ start, control point 1, ..., control point N, end ]. location as used as an input here refers to a decimal in the range [0-1], which indicates a point some proportion along the length of the curve. location as output has the same format and meaning.

Function List

Functions are all in the 'jsBezier' namespace.

  • distanceFromCurve(point, curve)

Calculates the distance that the given point lies from the given Bezier. Note that it is computed relative to the center of the Bezier, so if you have stroked the curve with a wide pen you may wish to take that into account! The distance returned is relative to the values of the curve and the point - it will most likely be pixels.

  • gradientAtPoint(curve, location)

Calculates the gradient to the curve at the given location, as a decimal between 0 and 1 inclusive.

  • gradientAtPointAlongCurveFrom(location, distance)

Calculates the gradient to the curve at the point which is 'distance' units from the given location. See pointAlongCurveFrom.

  • nearestPointOnCurve(point, curve)

Calculates the nearest point to the given point on the given curve. The return value of this is a JS object literal, containing both the point's coordinates and also the location of the point (see above), for example:

	{ point:{ x:551,y:150 }, location:0.263365 }.
  • pointOnCurve(curve, location)

Calculates the coordinates of the point on the given Bezier curve at the given location.

  • pointAlongCurveFrom(curve, location, distance)

Calculates the coordinates of the point on the given curve that is distance units from location. distance should be in the same coordinate space as that used to construct the Bezier curve. For an HTML Canvas usage, for example, distance would be a measure of pixels. The return value is a point in the form:

	{ x:..., y:... }
  • locationAlongCurveFrom(curve, location, distance)

Calculates the location of the point on the given curve that is distance units from location. distance should be in the same coordinate space as that used to construct the Bezier curve. For an HTML Canvas usage, for example, distance would be a measure of pixels. The return value is a float in the range [0,1].

  • pointAlongCurve(curve, location, distance)

Calculates both the coordinates and location of the point on the given curve that is distance units from location. This function is the function that both locationAlongCurveFrom and pointAlongCurveFrom call. The return value is a JS object containing:

	{ point:the new point, location: location in range [0,1], originalPoint:the reference point }
  • perpendicularToCurveAt(curve, location, length, distance)

Calculates the perpendicular to the given curve at the given location. length is the length of the line you wish for (it will be centered on the point at location). distance is optional, and allows you to specify a point along the path from the given location as the center of the perpendicular returned. The return value of this is an array of two points:

	[ {x:...,y:...}, {x:...,y:...} ].