Giter VIP home page Giter VIP logo

circle.js's Introduction

Circle.js

NPM Package Build Status MIT license

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 and Angles.js.

Examples

var circle = require('circle.js');
var A = {x: 20, y: 20, r: 10};
var 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 commands:

bower install circle

or

npm install circle.js

Using Circle.js with the browser

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

Using Circle.js with require.js

<script src="require.js"></script>
<script>
requirejs(['circle.js'],
function(Circle) {
    console.log(Circle.intersectionArea(A, B));
});
</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.

Testing

If you plan to enhance the library, make sure you add test cases and all the previous tests are passing. You can test the library with

npm test

Copyright and licensing

Copyright (c) 2016, Robert Eisele Licensed under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.