npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pointscape

v1.6.3

Published

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

Downloads

80

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";

Examples

 import { 
    distance,
    triangle,
    center, 
    inRange,
    chunk, 
    randomBoolean } from "pointscape";


 const distanceBetweenPoints = distance({x: 0, y: 0}, {x: 10, y: 10});
 console.log(distanceBetweenPoints); 
 // output: 14.142135623730951


 const pointsForTriangle = triangle({x: 0, y: 0}, 10);
 console.log(pointsForTriangle); 
 // output: [ { x: 0, y: 0 }, { x: -10, y: 0 }, { x: -5, y: 8.660254037844386 } ]


 const centralPoint = center(
   [{x:0, y: 0}, {x:0, y:10}, {x:10, y:10}, {x:10, y:0}]
 );
 console.log(centralPoint);
 // output: { x: 5, y: 5 }


 const isInTheRange = inRange(1, 0, 10);
 console.log(isInTheRange);
 // output: true


 const chunks = chunk([1, 1, 1, 1], 2);
 console.log(chunks);
 // output: [[1, 1], [1, 1]]


 const randomBool = randomBoolean();
 console.log(randomBool)
 // output: true or false

Functions

Actions with points in XY coordinate system

distance

area

collision

collisionInArray

positionInCircle

angle

middle

nearest

perimeter

pointWithoutCollision

randomPoint

randomPointInDistance

randomPoints

possibleConnections

circleArea

center

farest

rotate

sort

scale

inLine

cross

move

square

rectangle

pentagon

triangle

Math

degreesToRadians

radiansToDegrees

inRange

roundToPrecision

average

Arrays

intersection

difference

chunk

removeDuplicate

sample

Randomization

randomNumber

randomBoolean

uniqueId

Actions with points in XY coordinate system

  • distance(point1, point2)

    Returns the distance beetween two points, each point is an object with x and y properties.

  • 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.

  • collision(point1, point2, collisionDistance, [callback])

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

  • collisionInArray(point, radius, points, [callback])

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

  • positionInCircle(point, radius, angleInRadians)

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

  • angle(point1, point2)

    Returns the angle formed by the connection of two points.

  • middle(point1, point2)

    Returns the midpoint between two points.

  • nearest(point, points)

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

  • perimeter(points)

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

  • 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.

  • randomPoint([xMin], [xMax], [yMin], [yMax])

    Returns a random point within the given dimensions, if provided, otherwise in 100 units on both axes.

  • randomPointInDistance(point, distance)

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

  • randomPoints(quantity, [xMin], [xMax], [yMin], [yMax], )

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

  • possibleConnections(pointsCount)

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

  • circleArea(radius)

    Returns the area of the circle.

  • center(points)

    Returns the center of given points.

  • farest(point, points)

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

  • rotate(point, points, angleInRadians)

    Returns the points rotated around the given point.

  • sort(points, [coordinate])

    Returns sorted array of the points.The coordinate parameter can be "x", "y", or none for sorting both for "x" and "y".

  • scale(scaleFactorX, scaleFactorY, points)

    Returns the scaled points.

  • inLine([point1, point2, point3])

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

  • cross(line1Start, line1End, line2Start, line2End)

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

  • move(point, 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.

  • square(point, size, [direction])

    Returns an array of points representing a shape of square.Takes four parameters: starting coordinates (x and y), size of square side, and direction which should be one of the values "left", "right", "up", "down".

  • rectangle(point, size, [direction])

    Returns an array of points representing a shape of rectangle.Takes same parameters as square function.

  • triangle(point, size, [direction])

    Returns an array of points representing a shape of triangle.Takes same parameters as square function.

  • pentagon(point, size, [direction])

    Returns an array of points representing a shape of pentagon.Takes four parameters: starting coordinates (x and y), size of pentagon side, and the angle of pentagon's rotation.

Math

  • degreesToRadians(degrees)

    Converts degrees to radians.

  • radiansToDegrees(radians)

    Converts radians to degrees.

  • inRange(number, min, max)

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

  • roundToPrecision(number, precision)

    Rounds the number to the given precision.

  • average(numbers)

    Returns the average of all numbers in an array.

Arrays

  • intersection(arr1, arr2)

    Returns the array of intersection of two arrays.

  • difference(arr1, arr2)

    Returns the array of difference of two arrays.

  • chunk(arr, perArr)

    Returns an array splited into chunks based on elements count per chunk.

  • removeDuplicates(arr)

    Returns the array without duplicates.

  • sample(arr, [size])

    Returns a random sample from an array with optional size argument for sampling length. If not specified, it returns only one element.

Randomization

  • randomNumber(min, max)

    Returns a random number within the given range.

  • randomBoolean()

    Returns a random boolean value.

  • uniqueId([other ids])

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