Giter Club home page Giter Club logo

shapes-interaction-library's Introduction

Shapes-Interaction-Library

A lightweight library of basic geometry shapes interactions. Enables a possibility of shape intersection determination or situation when shape contains other shape.

Installation

node :

$ npm install shapes-interaction

web :

<script src="unpkg.com/[email protected]/index.min.js"></script>

API

This module exports two functions:

The intersection function takes two shapes as an input and returns 'true' if shapes intersect or 'false' if shapes do not intersect

intersection(shape1, shape2)

The contain function takes two shapes as an input and returns 'true' if first shape contains second shape or 'false' if first shape does not contain second shape

contain(shape1, shape2)

Functions maintain 5 types of shapes such as:

point == [x, y] (array of two coordinates of point)

segment == [point, point] == [[x1, y1], [x2, y2]] (array of two points)

rectangle == [[point], width, height] == [[x, y], width, height] (array of vertex, width and height of rectangle)

circle == [[point], radius] == [[x, y], radius] (array of centre and radius of circle)

polygon == [[point1], [point2], ..., [pointN]] == [[x1, y1], [x2, y2], ..., [xN, yN]] (array of N points)

Usage example

Example image

    const shapesInteraction = require('shapes-interaction');

    const segment = [[160, 160], [280, 280]];
    const circle = [[375, 250], 40];
    const rectangle = [[210, 160], 150, 90];
    const polygon = [[75, 155], [245, 35], [420, 155], [355, 350], [140, 350]];

    shapesInteraction.intersection(segment, rectangle);  // true
    shapesInteraction.intersection(circle, segment);     // false
    shapesInteraction.intersection(rectangle, circle);   // true
    shapesInteraction.intersection(polygon, circle);     // true
    shapesInteraction.intersection(rectangle, polygon);  // false
    shapesInteraction.intersection(polygon, segment);    // false

    shapesInteraction.contain(polygon, rectangle);       // true
    shapesInteraction.contain(polygon, segment);         // true
    shapesInteraction.contain(polygon, circle);          // false
    shapesInteraction.contain(rectangle, segment);       // false

shapes-interaction-library's People

Contributors

maslovmykhailo avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

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.