JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q47177F
  • License MIT

Points manipulation,distance and angle calculation and more with 2D coordinate system

Package Exports

  • pointscape

Readme

Simplify point manipulation and interactions in your 2D projects with this versatile toolkit.Effortlessly calculate distances, areas, collision detection, and more with this collection of handy functions.

How to use

  1. Installation
 npm install pointscape
  1. Usage
 import pointscape from "pointscape";

Functions

This section explains the usage of the utility functions.

Actions with points in XY coordinate system

  1. distance(x1, y1, x2, y2)

    Returns the distance beetween two points.

  2. area(points)

    Returns the area enclosed by the given points. Takes an array of points as argument, where each point is an object with x and y properties.

  3. collision(x1, y1, x2, y2,collisionDistance, [callback])

    Returns a boolean indicating if the two points are closer than the given distance.

  4. collisionInArray(x1, y1, radius, points, [callback])

    Returns the point that is closer than the radius to the given point, or false if there's no collision.

  5. positionInCircle(centerX, centerY, radius, angleInRadians)

    Returns the XY coordinates for the current point in the circle, given its center, radius, and angle.

  6. angle(x1, y1, x2, y2)

    Returns the angle formed by the connection of two points.

  7. middlePoint(x1, y1, x2, y2)

    Returns the midpoint between two points.

  8. nearest(x, y, points)

    Returns the nearest point to the given point from the array.

  9. perimeter(points)

    Returns the perimeter of the figure formed by the given points.

  10. pointWithoutCollision(minX, maxX, minY, maxY, distance, points)

    Returns a point that doesn't collide with any of the given points within the specified distance, if such a point exists, otherwise returns false.

  11. randomPoint([xMin], [xMax], [yMin], [yMax])

    Returns a random point within the given dimensions, if provided.

  12. randomPointInDistance(x, y, distance)

    Returns a random point within the given distance from the specified point.

  13. randomPoints([xMin], [xMax], [yMin], [yMax], quantity)

    Returns a specified quantity of random points within the given dimensions, if dimensions are provided.

  14. possibleConnections(pointsCount)

    Returns the quantity of possible connections among given quantity of points.

  15. circleArea(radius)

    Returns the area of the circle.

  16. center(points)

    Returns the center of given points.

  17. farest(x, y, points)

    Returns the farest point to the given point from the array.

  18. inLine(x, y, point1, point2)

    Returns boolean value indicating whether or not the given coordinates are on line defined by two other points.

  19. cross(line1Start, line1End, line2Start, line2End)

    Returns boolean value indicating if two lines each defined by two points intersect.

  20. movingPoint( x, y, xStep, yStep, count)

    Returns an array of points representing a moving point over time. The number of elements in the array is equal to "count". Each element contains coordinates of the point.

Math

  1. degreesToRadians(degrees)

    Converts degrees to radians.

  2. radiansToDegrees(radians)

    Converts radians to degrees.

  3. inRange(number, min, max)

    Returns true if the given number is within the specified range.

  4. roundToPrecision(number, precision)

    Rounds the number to the given precision.

  5. average(numbers)

    Returns the average of all numbers in an array.

Randomization

  1. randomNumber(min, max)

    Returns a random number within the given range.

  2. randomBoolean()

    Returns a random boolean value.

  3. uniqueId([other ids])

    Returns a unique ID that's different from the provided IDs, or a random ID if no other IDs are given.

Arrays

  1. intersection(arr1, arr2)

    Returns the array of intersection of two arrays.

  2. difference(arr1, arr2)

    Returns the array of difference of two arrays.