Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollonius

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollonius - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

CHANGELOG.md

26

index.js

@@ -161,2 +161,5 @@ const defaultEpsilon = 0.0000000001 // precision from affineplane

//
// Throws:
// if one or more of the given circles have missing or invalid properties.
//
const epsilon = options.epsilon

@@ -171,2 +174,13 @@

const dy31 = c1.y - c3.y
// Circle expressions of form x^2 + y^2 - r^2
const g1 = c1.x * c1.x + c1.y * c1.y - c1.r * c1.r
const g2 = c2.x * c2.x + c2.y * c2.y - c2.r * c2.r
const g3 = c3.x * c3.x + c3.y * c3.y - c3.r * c3.r
// Validate: detect bad input circles.
if (isNaN(g1) || isNaN(g2) || isNaN(g3)) {
throw new Error('Invalid input circle was detected.')
}
// Special case: linearly dependent circles
// If the vector between circles are linearly dependent i.e. their centers are along the same line,

@@ -180,6 +194,3 @@ // we cannot solve the circle with the common method. We need to check their independency.

}
// Circle expressions of form x^2 + y^2 - r^2
const g1 = c1.x * c1.x + c1.y * c1.y - c1.r * c1.r
const g2 = c2.x * c2.x + c2.y * c2.y - c2.r * c2.r
const g3 = c3.x * c3.x + c3.y * c3.y - c3.r * c3.r
// Coefficients for the coordinates x=(a+b*r)/D, y=(c+d*r)/D

@@ -190,2 +201,3 @@ // Determinant (denominator)

if (Math.abs(D) < epsilon) return null
const a = -(dy23 * g1 + dy31 * g2 + dy12 * g3)

@@ -204,9 +216,13 @@ const b = 2 * (c1.r * dy23 + c2.r * dy31 + c3.r * dy12)

const R = dx * dx + dy * dy - dr * dr
// Special case: quadratic formula denominator is zero.
if (Math.abs(P) < epsilon) return null
// Discriminant
let disc = Q * Q - P * R
// Special case: discriminant is negative. Deal with floating point issues.
if (Math.abs(disc) < epsilon) disc = 0
if (disc < 0) return null
// Find the target radius

@@ -219,3 +235,3 @@ const r = (Q - Math.sqrt(disc)) / P

return { x, y, r }
};
}

@@ -222,0 +238,0 @@ // Aliases

2

package.json
{
"name": "apollonius",
"version": "1.0.0",
"version": "1.1.0",
"description": "Solves Apollonius' problem by finding a fourth circle tangent to three given circles",

@@ -5,0 +5,0 @@ "type": "module",

@@ -6,2 +6,3 @@ # apollonius

[![npm version](https://img.shields.io/npm/v/apollonius?color=green)](https://www.npmjs.com/package/apollonius)
[![GitHub Actions workflow status](https://img.shields.io/github/actions/workflow/status/axelpale/apollonius/apollonius-ci.yml)](https://github.com/axelpale/apollonius/actions/workflows/apollonius-ci.yml)
[![license](https://img.shields.io/npm/l/apollonius)](#license)

@@ -15,3 +16,3 @@ ![NPM Type Definitions](https://img.shields.io/npm/types/apollonius?color=green)

The function is extremely efficient. It has time complexity of O(1) and does not call any trigonometric functions.
The function is very efficient. It has time complexity of O(1) and does not call any trigonometric functions.

@@ -100,2 +101,6 @@

Throws:
- if any of the input circles are missing.
- if any of the input circle properties are [NaN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN) or missing.
### apollonius.options.epsilon

@@ -102,0 +107,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc