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 🙏

© 2025 – Pkg Stats / Ryan Hefner

triangle-completion

v0.10.0

Published

Calculate a triangle from a partial spec. Basic trig nicely packaged.

Downloads

5

Readme

triangle-completion

Calc a triangle from a partial spec. Basic trig nicely packaged.

Usage

import solveTriangle, { TriangleError } from 'trig';
console.log(solveTriangle({ alpha:60, beta: 30, B: 1 }));
{
  alpha: 60,
  beta: 30,
  gamma: 90,
  A: 1.7320508075688774,
  B: 1
  C: 2.0000000000000004,
}
console.log(solveTriangle({ A:1, C:2, alpha: 10 }));
{
  A: 1,
  B: 2.907370933399707
  C: 3.7264028721887454,
  alpha: 10,
  beta: 30.32203701650613,
  gamma: 139.67796298349387,
  alt: {
    A: 1,
    B: 2,
    C: 2.907370933399707,
    alpha: 10,
    beta: 20.32203701650614
    gamma: 149.67796298349387,
  },
}

Specifications use alpha, beta, gamma for angles and A, B, C for the corresponding opposite sides. As shown, an SSA spec involving an acute angle generates both possible solutions.

Invalid inputs (zero/NaN/undefined, or unsolvable specifications) throw TriangleError, trivially derived from Error. null inputs propogate to the output without throwing an error.

Optimizing

solveTriangle analyzes and mutates the input spec to match up with one of several solver functions. You can import and invoke these solver functions directly, saving both the cost of the analysis (for sure a few conditional evaluations and likely a few rotate/invert object manipulations) and the cost in time and space of importing unused logic. The individual solvers are named for the inputs they expect as follows:

  • Angle-Angle-Side: aas.js solveGammaAlphaC({ gamma: 20, alpha: 80, C: 3 })
  • Angle-Side-Angle: asa.js solveAlphaBGamma({ alpha: 80, B: 3, gamma: 20 })
  • Side-Angle-Side: sas.js solveAGammaB({ A: 1, gamma: 20, B: 3 })
  • Side-Side-Side: sss.js solveABC({ A: 1, B: 3, C: 5 })
  • Side-Side-Angle: ssa.js solveABAlpha({ A: 1, B: 3, alpha: 40 })

This last is ambiguous if the angle is acute. As shown above, the solution includes an "alt" key giving another matching triangle. Nothing determines which solution is presented as "alt".

There are also some trivial support functions in common.js, but it's unlikely they'll be of much interest on their own.

Contributing

Zero optimization of code for performance, have at it: [https://github.com/swork/triangle-completion.git]

npx test runs a Jasmine suite, please extend it to reflect your changes.