# circle.js

> A function collection for working with circles

Latest version **0.2.3** (published 2024-10-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install circle.js
pnpm add circle.js
yarn add circle.js
bun add circle.js
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2024-10-09 |
| First published | 2016-10-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | * |
| Dependencies | 0 |
| Unpacked size | 23.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Robert Eisele |
| Maintainers | infusion |
| Keywords | circle, circles, intersection, area, perimeter, circle from three points |

## Links

- npm: https://www.npmjs.com/package/circle.js
- Repository: https://github.com/rawify/Circle.js
- Issues: https://github.com/rawify/Circle.js/issues
- Funding: https://github.com/sponsors/rawify
- npm.io page: https://npm.io/package/circle.js

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2024-10-09
- 0.2.2 — 2024-10-06
- 0.2.1 — 2024-10-05
- 0.2.0 — 2024-10-04
- 0.1.0 — 2024-05-06
- 0.0.10 — 2024-05-06
- 0.0.9 — 2018-04-13
- 0.0.8 — 2018-04-13
- 0.0.7 — 2018-03-29
- 0.0.6 — 2018-03-29
- 0.0.5 — 2018-03-29
- 0.0.4 — 2018-02-18
- 0.0.3 — 2018-01-31
- 0.0.2 — 2016-10-28
- 0.0.1 — 2016-10-28

## README

# Circle.js

[![NPM Package](https://img.shields.io/npm/v/circle.js.svg?style=flat)](https://npmjs.org/package/circle.js "View this project on npm")
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)


Circle.js is a collection of functions to work with circles. The aim is to have a fast and correct library, which makes it easy to calculate the intersection of circles, the area of a circle and so on.

Every circle is defined by a cartesian point `(x, y)` and the radius `r`.

Circles.js is analogous to [Rectangles.js](https://github.com/infusion/Rectangles.js) and [Angles.js](https://github.com/infusion/Angles.js).

## Examples


```javascript
const circle = require('circle.js');

const A = {x: 20, y: 20, r: 10};
const B = {x: 80, y: 80, r: 30};

if (circle.intersect(A, B)) {
  console.log(circle.intersection(A, B)); // Intersection points
  console.log(circle.intersectionArea(A, B)); // Intersection area
} else {
  console.log("no intersection");
}
```

## Functions


intersect(a, b)
---
Determines if two circles intersect

intersection(a, b)
---
Calculates the intersection points of two circles

intersectionArea(a, b)
---
Calculates the intersection area of two circles

area(a)
---
Calculates the area of a circle

height(a)
---
Calculates the height of a circle. Obviously, this is the same as the width.

width(a)
---
Calculates the width of a circle. Obviously, this is the same as the height.

perimater(a)
---
Calculates the perimeter of a circle

center(a)
---
Calculates the center point of a circle. Simply it's coordinates.

insetBy(a)
---
Resizes the circle by a given value on the center

fromThreePoints(p1, p2, p3)
---
Caclulates a circle {x, y, r} with given three {x, y} points

## Installation

Installing Circle.js is as easy as cloning this repo or use one of the following command:

```
npm install circle.js
```


## Using Circle.js with the browser

```html
<script src="circle.min.js"></script>
<script>
console.log(Circle.center(A));
</script>
```



## Coding Style

As every library I publish, Circle.js is also built to be as small as possible after compressing it with Google Closure Compiler in advanced mode. Thus the coding style orientates a little on maxing-out the compression rate. Please make sure you keep this style if you plan to extend the library.

## Building the library

After cloning the Git repository run:

```
npm install
npm run build
```

## Run a test

Testing the source against the shipped test suite is as easy as

```
npm run test
```

## Copyright and Licensing

Copyright (c) 2024, [Robert Eisele](https://raw.org/)
Licensed under the MIT license.

---
_Source: https://npm.io/package/circle.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
