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

simplify-wasm

v0.1.10

Published

Algorithm for converting points to smooth bezier curves, ported from paper.js

Downloads

11

Readme

npm version

simplify-wasm

This repository contains a WebAssembly (WASM) port of the simplify-rs library, offering a robust algorithm for simplifying a path represented by a sequence of points to a sequence of cubic Bezier curves with a specified maximum error tolerance. The original Rust-based library efficiently reduces the complexity of paths while maintaining a high degree of visual fidelity, and this WASM port brings that capability directly to the web, enabling high-performance path simplification directly in the browser.

live demo

Live Demo

Features

  • High Performance: Leverages the efficiency of Rust and WASM for fast path simplification directly in the web environment.
  • Automatic Scaling for Precision: Optionally scales paths to a target area before simplification to improve precision, particularly useful for paths with a wide range of sizes.

Usage

First, ensure you have included the simplify-wasm module in your project.

npm install simplify-wasm

Then, you can use the module in your JavaScript or TypeScript code as follows:

import init, { simplify_js } from 'simplify_wasm';

async function run() {
    await init(); // Initialize the WASM module

    // Define an array of points
    const points = [
        {x: 0, y: 0},
        {x: 1, y: 1},
        ...
    ];

    // Set the maximum error tolerance for the simplification
    const tolerance = 0.1;

    // Enable automatic up & down scaling for better precision
    const auto_scale_for_precision = true;

    // Simplify points
    const simplifiedCurves = simplify_js(points, tolerance, auto_scale_for_precision);

    /*
    The output is a sequence of cubic bezier curves, each represented by 4 points:
    [{x: 0, y: 0}, {x: 1, y: 1}, {x: 2, y: 2}, {x: 3, y: 3}]
    [0] = start point
    [1] = control point 1
    [2] = control point 2
    [3] = end point
    */

    console.log(simplifiedCurves);
}

run();

See also

Parameters

  • points: Array of points representing the path to simplify. Each point should be an object with x and y properties.
  • tolerance: The allowed maximum error when fitting the curves through the segment points.
  • auto_scale_for_precision: If true, scales the path to a target area before simplification to increase precision.

Building from Source

If you'd like to build the WASM module from the source, ensure you have the Rust toolchain and wasm-pack installed. Then, run:

sh ./scripts/compile-wasm.sh prod

This script compiles the Rust code into a WASM module.

Performance

This WASM port aims to offer similar performance advantages to the original Rust library, enabling the simplification of complex paths in milliseconds, depending on the path complexity and the host system's capabilities.