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

circle_boundary

v0.1.19

Published

A Rust library to calculate the boundary of a circle, coordinates given in bitmap style discrete integers.

Downloads

4

Readme

Circle Boundary

A single purpose library. This library's aim is to return a circle boundary as represented in discrete pixels as shown in the following diagram.

five radius circle boundary

Usage

Include the library into your application with the following:

const load_wasm = import ('circle_boundary/circle_boundary.js')

Then you can use the calculate function to get a javascript object of boundary data structures back. Each boundary structure holds a pair of cartesian coordinates (x and y) where x is represented by a single number indicating it's position, and y is represented by a range to show where on the y-axis the boundary applies.

The web_calculate function expects the origin as represented by the first two arguments, a x value as an integer and a y value as an integer. The final argument is the radius of the circle you want a boundary for as represented as an integer as well.

Because of how Webpack loads the WASM you must wait till it is asynchronous loaded before you can call the function like so:

load_wasm.then(wasm => {
    let result = wasm.web_calculate(0, 0, 3)
})

As noted above the value returned is a javascript object that represents the boundary as such:

[
  {
    "x": -3,
    "y": {
      "start": -1,
      "end": 1
    }
  },
  {
    "x": -2,
    "y": {
      "start": -2,
      "end": 2
    }
  },
  {
    "x": -1,
    "y": {
      "start": -3,
      "end": 3
    }
  },
  {
    "x": 0,
    "y": {
      "start": -3,
      "end": 3
    }
  },
  {
    "x": 1,
    "y": {
      "start": -3,
      "end": 3
    }
  },
  {
    "x": 2,
    "y": {
      "start": -2,
      "end": 2
    }
  },
  {
    "x": 3,
    "y": {
      "start": -1,
      "end": 1
    }
  }
]

Which could be represented as in the following diagram. Where the dark grey square represents the origin, the green squares represent the lower bounds of the y range, and the red squares represent the upper bounds of the y range.

three radius circle boundary

Off origin example

As noted the web_calculate function can be given coordinates that offset the results from a (0,0) origin. If you pass in an offset like:

web_calculate(9, 3, 7);

This returns the following vector:

[
  {
    "x": 2,
    "y": {
      "start": 1,
      "end": 5
    }
  },
  {
    "x": 3,
    "y": {
      "start": -1,
      "end": 7
    }
  },
  {
    "x": 4,
    "y": {
      "start": -2,
      "end": 8
    }
  },
  {
    "x": 5,
    "y": {
      "start": -3,
      "end": 9
    }
  },
  {
    "x": 6,
    "y": {
      "start": -3,
      "end": 9
    }
  },
  {
    "x": 7,
    "y": {
      "start": -4,
      "end": 10
    }
  },
  {
    "x": 8,
    "y": {
      "start": -4,
      "end": 10
    }
  },
  {
    "x": 9,
    "y": {
      "start": -4,
      "end": 10
    }
  },
  {
    "x": 10,
    "y": {
      "start": -4,
      "end": 10
    }
  },
  {
    "x": 11,
    "y": {
      "start": -4,
      "end": 10
    }
  },
  {
    "x": 12,
    "y": {
      "start": -3,
      "end": 9
    }
  },
  {
    "x": 13,
    "y": {
      "start": -3,
      "end": 9
    }
  },
  {
    "x": 14,
    "y": {
      "start": -2,
      "end": 8
    }
  },
  {
    "x": 15,
    "y": {
      "start": -1,
      "end": 7
    }
  },
  {
    "x": 16,
    "y": {
      "start": 1,
      "end": 5
    }
  }
]

Which represents the following circle boundary where the black square represents the (0,0) origin:

seven radius circle boundary with offset

Examples

For more example on how to use this library you can look in the examples/ folder in this repository under wasm_introduction.

Development

This package is developed in Rust. The library and development instructions can be found here.