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

svg-arc-center-endpoint

v0.0.2

Published

Conversion SVG arcs from center to endpoint parameterization, and vice versa.

Downloads

5

Readme

jsdelivr npm version codecov

svg-arc-center-endpoint

An Implementation of https://www.w3.org/TR/SVG/implnote.html#ArcConversionCenterToEndpoint

Conversion SVG arcs from center to endpoint parameterization, and vice versa.

Installation

npm install svg-arc-center-endpoint

Usage

ESM:

import { centerToEndpoint } from "svg-arc-center-endpoint";

const rx = 50;
const ry = 50;
const xAxisRotation = 0;

const {
  x1,
  x2,
  y1,
  y2,
  fa: largeArcFlag,
  fs: sweepFlag,
} = centerToEndpoint({
  cx: 100,
  cy: 100,
  rx,
  ry,
  phi: xAxisRotation,
  theta: 30,
  dTheta: 60,
});

const x1Fixed = x1.toFixed(3);
const y1Fixed = y1.toFixed(3);
const x2Fixed = x2.toFixed(3);
const y2Fixed = y2.toFixed(3);

const path = `M ${x1Fixed} ${y1Fixed} A ${rx} ${ry} ${xAxisRotation} ${largeArcFlag} ${sweepFlag} ${x2Fixed} ${y2Fixed}`;

console.log(path); // M 143.301 125.000 A 50 50 0 0 1 100.000 150.000

CDN:

<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script>
  const { centerToEndpoint } = svgArcCenterEndpoint;

  const rx = 50;
  const ry = 50;
  const xAxisRotation = 0;
  const theta = 30;
  const dTheta = 60;

  const {
    x1,
    x2,
    y1,
    y2,
    fa: largeArcFlag,
    fs: sweepFlag,
  } = centerToEndpoint({
    cx: 100,
    cy: 100,
    rx,
    ry,
    phi: xAxisRotation,
    theta,
    dTheta,
  });

  const x1Fixed = x1.toFixed(3);
  const y1Fixed = y1.toFixed(3);
  const x2Fixed = x2.toFixed(3);
  const y2Fixed = y2.toFixed(3);

  const path = `M ${x1Fixed} ${y1Fixed} A ${rx} ${ry} ${xAxisRotation} ${largeArcFlag} ${sweepFlag} ${x2Fixed} ${y2Fixed}`;

  console.log(path); // M 143.301 125.000 A 50 50 0 0 1 100.000 150.000
</script>

API

centerToEndpoint({cx, cy, rx, ry, phi, theta, dTheta})

The centerToEndpoint() method convert the given center parameterization to endpoint parameterization.

Parameters

  • cx (number) - The x-axis coordinate of the center of the ellipse.
  • cy (number) - The y-axis coordinate of the center of the ellipse.
  • rx (number) - The x-axis radius of the ellipse.
  • ry (number) - The y-axis radius of the ellipse.
  • phi (number) - The x-axis rotation of the ellipse.
  • theta (number) - The start angle of the arc. In degrees, range: (-360, 360).
  • dTheta (number) - The angular distance from the start angle to the end angle. In degrees, range: (-360, 360).

Returns

  • x1 (number) - The x-axis coordinate of the start point of the arc.
  • y1 (number) - The y-axis coordinate of the start point of the arc.
  • x2 (number) - The x-axis coordinate of the end point of the arc.
  • y2 (number) - The y-axis coordinate of the end point of the arc.
  • fa (number) - The large arc flag. (0 or 1)
  • fs (number) - The sweep flag. (0 or 1)

endpointToCenter()

The endpointToCenter() method convert the given endpoint parameterization to center parameterization.

getPointForAngle()

The getPointForAngle() method returns the point (x,y) on the ellipse for the given angle (theta).

Reference

Release Notes