{"id":16253323,"url":"https://github.com/arman2409/pointscape","last_synced_at":"2026-02-26T23:31:10.575Z","repository":{"id":216790802,"uuid":"740623144","full_name":"Arman2409/pointscape","owner":"Arman2409","description":"NPM package of utility functions for working with points in 2D coordinate system","archived":false,"fork":false,"pushed_at":"2026-01-16T12:48:33.000Z","size":123,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2026-01-17T03:22:07.728Z","etag":null,"topics":["2d","canvas","collision-detection","distance","npm-package","points","xy"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/pointscape","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Arman2409.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-01-08T18:12:40.000Z","updated_at":"2026-01-16T12:48:37.000Z","dependencies_parsed_at":"2024-03-09T10:30:13.217Z","dependency_job_id":"626d5c09-f5cc-49a4-bd77-6da868de4e04","html_url":"https://github.com/Arman2409/pointscape","commit_stats":null,"previous_names":["arman2409/2d","arman2409/2d-utils","arman2409/pointify"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/Arman2409/pointscape","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arman2409%2Fpointscape","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arman2409%2Fpointscape/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arman2409%2Fpointscape/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arman2409%2Fpointscape/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Arman2409","download_url":"https://codeload.github.com/Arman2409/pointscape/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arman2409%2Fpointscape/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29876902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T22:37:10.609Z","status":"ssl_error","status_checked_at":"2026-02-26T22:37:09.019Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2d","canvas","collision-detection","distance","npm-package","points","xy"],"created_at":"2024-10-10T15:16:45.592Z","updated_at":"2026-02-26T23:31:10.547Z","avatar_url":"https://github.com/Arman2409.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"**A collection of functions for working with points in a 2D coordinate system, along with additional utility functions.**\n\n## How to use\n\n1. Installation\n```bash\n npm install pointscape\n```\n\n2. Usage\n```typescript\n import pointscape from \"pointscape\";\n```\n\n## Examples\n\nMost of the functions are designed for working with points in a 2D coordinate system.\n```typescript\n import { \n    distance,\n    middle,\n    angle,\n    center,\n    perimeter\n    } from \"pointscape\";\n import type { Point } from \"pointscape\";  \n \n // Working with points\n\n const point1: Point = {x: 0, y: 0}, point2: Point = {x: 10, y: 10};\n\n\n const distanceBetweenPoints = distance(point1, point2); \n // result: 14.142135623730951\n\n\n const middlePoint = middle(point1, point2);\n // result: {x: 5, y: 5}\n\n\n const angleBetweenPoints = angle(point1, point2);\n // result: 0.7853981633974483\n \n\n const point3: Point = {x:0, y:10}, point4: Point = {x:10, y:0};\n\n const perimeterOfPoints = perimeter(\n   [point1, point2, point3, point4 ]\n );\n // result: 48.2842712474619\n\n```\n\nThe Point class can also be used for working with the points.\n```typescript\n import { Point } from \"pointscape\";\n\n const point1 = new Point(0, 0);\n const point2 = new Point(1, 1);\n\n const distance = point1.distanceTo(point2);\n // result:  1.4142135623730951\n\n const angle = point1.angleTo(point2);\n // result:  0.7853981633974483\n \n``` \n\nThere are other utility functions as well.\n```typescript\n import { \n    inRange,\n    chunk, \n    randomBoolean } from \"pointscape\";\n\n //  Helper functions for math \n\n const isInTheRange = inRange(1, 0, 10);\n // result: true\n\n\n // Helper functions for arrays \n\n const chunks = chunk([1, 1, 1, 1], 2);\n // result: [[1, 1], [1, 1]]\n\n\n // Helper functions for randomization \n\n const randomBool = randomBoolean();\n // result: true or false\n\n```\n## The list of available functions\n\n### Categories\n\n- [Points](#points)\n    - [Geometry](#geometry)\n    - [Positioning](#positioning)\n    - [Relationships](#relationships)\n- [Math](#math)\n- [Arrays](#arrays)\n- [Randomization](#randomization)\n\n\n\n#### Points\n\n\n##### Positioning\n\n[distance](#distance)\n\n[positionInCircle](#positionincircle)\n\n[angle](#angle)\n\n[nearest](#nearest)\n\n[farest](#farest)\n\n[randomPoint](#randompoint)\n\n[randomPointInDistance](#randompointindistance)\n\n[randomPoints](#randompoints)\n\n[rotate](#rotate)\n\n[inLine](#inline)\n\n[cross](#cross)\n\n[move](#move)\n\n\n##### Geometry\n\n[area](#area)\n\n[middle](#middle)\n\n[center](#center)\n\n[perimeter](#perimeter)\n\n[square](#square)\n\n[rectangle](#rectangle)\n\n[pentagon](#pentagon)\n\n[triangle](#triangle)\n\n[circleArea](#circlearea)\n\n\n##### Relationships\n\n[collision](#collision)\n\n[collisionInArray](#collisioninarray)\n\n[possibleConnections](#possibleconnections)\n\n[pointWithoutCollision](#pointwithoutcollision)\n\n[sort](#sort)\n\n[scale](#scale)\n\n\n#### Math\n\n[degreesToRadians](#degreestodadians)\n\n[radiansToDegrees](#radianstodegrees)\n\n[inRange](#inrange)\n\n[roundToPrecision](#roundtoprecision)\n\n[average](#average)\n\n\n#### Arrays\n\n[intersection](#intersection)\n\n[difference](#difference)\n\n[chunk](#chunk)\n\n[removeDuplicate](#removeDuplicates)\n\n[sample](#sample)\n\n\n#### Randomization\n\n[randomNumber](#randomnumber)\n\n[randomBoolean](#randomboolean)\n\n[uniqueId](#uniqueid)\n\n\n## Documentation for the functions \n\n### Points\n\n##### Positioning\n\n* \u003cb id=\"distance\"\u003edistance\u003c/b\u003e\n```typescript\n  interface Point {\n    x: number\n    y: number\n  }\n\n  (point1: Point, point2: Point) =\u003e number\n```\n\nReturns the distance beetween two points, each point is an object with x and y properties.\n\n* \u003cb id=\"positionincircle\"\u003epositionInCircle\u003c/b\u003e\n```typescript\n  (point: Point, radius: number, angleInRadians: number) =\u003e Point\n```\n\nReturns the x and y coordinates for the current point in the circle, given its center point, radius, and angle.\n\n* \u003cb id=\"angle\"\u003eangle\u003c/b\u003e\n```typescript\n  (point1: Point, point2: Point) =\u003e number\n```\n\nReturns the angle formed by the connection of two points.\n\n* \u003cb id=\"nearest\"\u003enearest\u003c/b\u003e\n```typescript\n  (point: Point, points: Point[]) =\u003e Point\n```\n\nReturns the nearest point to the given point from the array.\n\n* \u003cb id=\"farest\"\u003efarest\u003c/b\u003e\n```typescript\n  (point: Point, points: Point[]) =\u003e Point\n```\n\nReturns the farest point to the given point from the array.\n\n* \u003cb id=\"randompoint\"\u003erandomPoint\u003c/b\u003e\n```typescript\n  ([xBounds]: Bounds, [yBounds]: Bounds) =\u003e Point\n```\n\nReturns a random point within the given dimensions, if provided, otherwise in 100 units on both axes.\n\n* \u003cb id=\"randompointindistance\"\u003erandomPointInDistance\u003c/b\u003e\n```typescript\n  (point: Point, distance: number) =\u003e Point\n``` \n   \nReturns a random point within the given distance from the specified point.\n\n* \u003cb id=\"randompoints\"\u003erandomPoints\u003c/b\u003e\n```typescript\n   ([xBounds]: Bounds, [yBounds]: Bounds, quantity: number,) =\u003e Point[]\n```  \n\nReturns a specified quantity of random points within the given dimensions, if dimensions are provided, otherwise in the range of 100.\n\n* \u003cb id=\"rotate\"\u003erotate\u003c/b\u003e\n```typescript\n  (point: Point, points: Point[], angleInRadians: number) =\u003e Point[]\n```\n\nReturns the points rotated around the given point.\n\n* \u003cb id=\"inline\"\u003einLine\u003c/b\u003e\n```typescript\n  interface Line {\n    start: Point\n    end: Point\n  }\n\n  (point: Point, line: Line) =\u003e boolean\n```\n\nReturns boolean  value indicating whether or not the given coordinates are on line defined by two other points.\n\n* \u003cb id=\"cross\"\u003ecross\u003c/b\u003e\n```typescript\n (line1: Line, line2: Line) =\u003e boolean\n```\n\nReturns boolean value indicating if two lines each defined  by two points intersect.\n\n* \u003cb id=\"move\"\u003emove\u003c/b\u003e\n```typescript\n (point: Point, xStep: number, yStep: number) =\u003e Point\n```\n\nReturns a point of with the new coordinates.\n\n##### Geometry\n\n* \u003cb id=\"area\"\u003earea\u003c/b\u003e\n```typescript\n  (points: Point[]) =\u003e number\n```\n\nReturns 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.\n\n* \u003cb id=\"middle\"\u003emiddle\u003c/b\u003e\n```typescript\n  (point1: Point, point2: Point) =\u003e Point\n```\n\nReturns the midpoint between two points.\n\n* \u003cb id=\"center\"\u003ecenter\u003c/b\u003e\n```typescript\n  (points: Point[]) =\u003e Point\n```\n\nReturns the center of the given points.\n\n* \u003cb id=\"perimeter\"\u003eperimeter\u003c/b\u003e\n```typescript\n  (points: Point[]) =\u003e number\n```\n\nReturns the perimeter of the figure formed by the given points.\n\n* \u003cb id=\"square\"\u003esquare\u003c/b\u003e\n```typescript\n (point: Point, size: number, [direction]: \"left\" | \"right\" | \"down\" | \"up\" ) =\u003e Point[]\n```\n\nReturns 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\",\n\"down\".\n\n* \u003cb id=\"rectangle\"\u003erectangle(point, size, [direction])\u003c/b\u003e\n```typescript\n (point: Point, size: number, [direction]: \"left\" | \"right\" | \"down\" | \"up\" ) =\u003e Point[]\n```\n\nReturns an array of points representing a shape of rectangle.Takes same parameters as [square](#square) function.\n\n* \u003cb id=\"pentagon\"\u003epentagon(point, size, [direction])\u003c/b\u003e\n```typescript\n (point: Point, size: number, [direction]: \"left\" | \"right\" | \"down\" | \"up\" ) =\u003e Point[]\n```\n\nReturns 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.\n\n* \u003cb id=\"triangle\"\u003etriangle(point, size, [direction])\u003c/b\u003e\n```typescript\n (point: Point, size: number, [direction]: \"left\" | \"right\" | \"down\" | \"up\" ) =\u003e Point[]\n```\n\nReturns an array of points representing a shape of triangle.Takes same parameters as [square](#square) function.\n\n* \u003cb id=\"circlearea\"\u003ecircleArea\u003c/b\u003e\n```typescript\n  (radius): number =\u003e number\n``` \n\nReturns the area of the circle.\n\n##### Relationships\n\n* \u003cb id=\"collision\"\u003ecollision\u003c/b\u003e\n```typescript\n  (point1: Point, point2: Point, collisionDistance: number, [callback]: Function) =\u003e boolean\n```\n\nReturns a boolean indicating if the two points are closer than the given distance.\n\n* \u003cb id=\"collisioninarray\"\u003ecollisionInArray\u003c/b\u003e\n```typescript\n  (point: Point, radius: number, points: Point[], [callback]: Function) =\u003e Point[]\n```\n\nReturns the points that are closer than the radius to the given point.\n\n* \u003cb id=\"possibleconnections\"\u003epossibleConnections\u003c/b\u003e\n```typescript\n  (pointsCount: number) =\u003e number\n``` \n   \nReturns the quantity of possible connections among given quantity of points.\n\n* \u003cb id=\"pointwithoutcollision\"\u003epointWithoutCollision(minX, maxX, minY, maxY, distance, points)\u003c/b\u003e\n```typescript\n  interface Bounds {\n    min: number\n    max: number\n  }\n\n  (xBounds: Bounds, yBounds: Bounds, distance: number, points: Point[]) =\u003e Point | string\n```\n\nReturns a point that doesn't collide with any of the given points within the specified distance, if such a point exists, otherwise returns error string.\n\n* \u003cb id=\"sort\"\u003esort\u003c/b\u003e\n```typescript\n  (points: Point, [coordinate]: \"x\" | \"y\") =\u003e Point[]\n```\n\nReturns sorted array of the points.The coordinate parameter can be \"x\", \"y\", or none for sorting both for \"x\" and \"y\".\n\n* \u003cb id=\"scale\"\u003escale\u003c/b\u003e\n```typescript\n  (scaleFactorX: number, scaleFactorY: number, points: Point[]) =\u003e Point[]\n```\n\nReturns the scaled points.\n\n### Math\n\n* \u003cb id=\"degreestoradians\"\u003edegreesToRadians\u003c/b\u003e\n```typescript\n (degrees: number) =\u003e number\n```\n\nConverts degrees to radians.\n\n* \u003cb id=\"radianstodegrees\"\u003eradiansToDegrees\u003c/b\u003e\n```typescript\n (radians: number) =\u003e number\n```\n\nConverts radians to degrees.\n\n* \u003cb id=\"inrange\"\u003einRange\u003c/b\u003e\n```typescript\n (number: number, min: number, max: number) =\u003e boolean\n```\n\nReturns true if the given number is within the specified range.\n\n* \u003cb id=\"roundtoprecision\"\u003eroundToPrecision)\u003c/b\u003e\n```typescript\n (number: number, precision: -100 | -10 | 0 | 10 | 100 | number) =\u003e number\n```\n\nRounds the number to the given precision.\n\n* \u003cb id=\"average\"\u003eaverage\u003c/b\u003e\n```typescript\n (numbers: number[]) =\u003e number\n```\n\nReturns the average of all numbers in an array.\n\n### Arrays\n\n* \u003cb id=\"intersection\"\u003eintersection(\u003c/b\u003e\n```typescript\n (arr1: any[], arr2: any[]) =\u003e any[]\n```\n\nReturns the array of intersection of two arrays.\n\n* \u003cb id=\"difference\"\u003edifference\u003c/b\u003e\n```typescript\n (arr1: any[], arr2: any[]) =\u003e any[]\n```\n\nReturns the array of difference of two arrays.\n   \n* \u003cb id=\"chunk\"\u003echunk\u003c/b\u003e\n```typescript\n (arr: any[], perArr: number) =\u003e any[][]\n```\n\nReturns an array splited into chunks based on elements count per chunk.\n\n* \u003cb id=\"removeDuplicates\"\u003eremoveDuplicates(arr)\u003c/b\u003e\n```typescript\n (arr: any[]) =\u003e any[]\n```\n\nReturns the array without duplicates.\n\n* \u003cb id=\"sample\"\u003esample\u003c/b\u003e\n```typescript\n  (arr: any[], [size]: number[]) =\u003e any[]\n```\n\nReturns a random  sample from an array with optional size argument for sampling length. If not specified, it returns only one element.\n\n### Randomization\n\n* \u003cb id=\"randomnumber\"\u003erandomNumber\u003c/b\u003e\n```typescript\n  (min: number, max: number) =\u003e number\n```\n\nReturns a random number within the given range.\n\n* \u003cb id=\"randomboolean\"\u003erandomBoolean\u003c/b\u003e\n```typescript\n  () =\u003e boolean\n```\n\nReturns a random boolean value.\n\n* \u003cb id=\"uniqueid\"\u003euniqueId\u003c/b\u003e\n```typescript\n  ([other ids]: string[]) =\u003e string \n```\n\nReturns a unique ID that's different from the provided IDs, or a random ID if no other IDs are given.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farman2409%2Fpointscape","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farman2409%2Fpointscape","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farman2409%2Fpointscape/lists"}