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

vector-optimizer

v1.0.2

Published

curves for javascript

Downloads

5

Readme

CI GitHub license npm version

English | 한국어


VectorOptimizer

This is Javascript / Typescript implementation of Bobby Fraser's 'Curves' C# Project.

Curves is vector optimization utility library, and i have modified it for use browser and node.js environment.

After implementing all the features of the origin project first, I will add my own stuff that I need.

if you want to use this project, please thank to Bobby Fraser, not me.


What can you do with this?

if you draw in some shape using canvas or svg in browser, points will appear like below

Original Points

If you connect these points in a straight line, lines will appear like below

Original Lines

this looks like an intended shape, but points are too many and there's a bit of jitter visible.

Using this project, you can reduce the number of points as below and show a natural curve shape.

Linearized Points

Optimized Curves


Live Example

Screen Shot 2021-08-20 at 9 40 07 PM

I made an example app like the origin project, so you can test how it works and how much it deforms. (Link)


Currently supported features compared to the original project

Preprocessing

  • [x] linearize
  • [ ] Ramer-Douglas-Puecker

FitCurve

  • [x] FitCurve

Installation

$ npm install vector-optimizer

How to import

Plain HTML

<script src="https://unpkg.com/vector-optimizer@latest/dist/vector-optimizer.min.js"></script>

CommonJS

const VectorOptimizer = require('vector-optimizer');

ES6 Import

import * as VectorOptimizer from 'vector-optimizer';

API Document

It operates in two stages. The first is the Linearize(Simplify) step, and the second is the Fit(Fit curves to the data) step.

I recommend playing around with the sample app link for a bit to get a feel for exactly how the parameters and pre-processing methods work.

Also, please refer to the explanation of the original project.

Linearize

/**
 * @description
 * Creates a list of equally spaced points that lie on the path described by straight line segments between
 * adjacent points in the source list.
 * 
 * @param src - Source list of points.
 * @param minDistance - Distance between points on the new path.
 * @return - List of equally-spaced points on the path.
 */
export declare function linearize(
  src: Vector[],
  minDistance: number,
): Vector[];

Fit

export declare class CurveFit extends CurveFitBase {

  /**
   * @param points - Set of points to fit to.
   */
  constructor(
    points: ReadonlyArray<Vector>,
  );

/**
 * @description
 * Attempts to fit a set of Bezier curves to the given data. It returns a set of curves that form a
 * http://en.wikipedia.org/wiki/Composite_B%C3%A9zier_curve with C1 continuity (that is, each curve's start
 * point is coincident with the previous curve's end point, and the tangent vectors of the start and end
 * points are going in the same direction, so the curves will join up smoothly). Returns an empty array
 * if less than two points in input.
 * 
 * Input data MUST not contain repeated points (that is, the same point twice in succession). The best way to
 * ensure this is to call any one of the methods in <see cref="CurvePreprocess" />, since all three pre-processing
 * methods will remove duplicate points. If repeated points are encountered, unexpected behavior can occur.
 * 
 * @param maxError - Maximum distance from any data point to a point on the generated curve.
 */
  fit(maxError: number): CubicBezier[];
}