{"id":18675893,"url":"https://github.com/foopis23/simple-game-math","last_synced_at":"2025-04-12T02:30:25.476Z","repository":{"id":57680325,"uuid":"475214643","full_name":"foopis23/simple-game-math","owner":"foopis23","description":"A node package for simple math functions and types for game development.","archived":true,"fork":false,"pushed_at":"2022-03-29T13:37:51.000Z","size":114,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-10T14:05:48.424Z","etag":null,"topics":["game","game-development","library","math","nodejs","package"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/simple-game-math","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/foopis23.png","metadata":{"files":{"readme":"ReadMe.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-28T23:42:53.000Z","updated_at":"2024-11-13T15:25:45.000Z","dependencies_parsed_at":"2022-09-15T18:03:10.123Z","dependency_job_id":null,"html_url":"https://github.com/foopis23/simple-game-math","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foopis23%2Fsimple-game-math","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foopis23%2Fsimple-game-math/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foopis23%2Fsimple-game-math/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foopis23%2Fsimple-game-math/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foopis23","download_url":"https://codeload.github.com/foopis23/simple-game-math/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248506901,"owners_count":21115503,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["game","game-development","library","math","nodejs","package"],"created_at":"2024-11-07T09:26:50.047Z","updated_at":"2025-04-12T02:30:25.127Z","avatar_url":"https://github.com/foopis23.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Game Math API Reference\nA node package for simple math functions and types for game development.\n\n## Vector2\nA module for Vector2 types and functions.\n\n### Interface: Vector2.IVector2\nAn interface for vectors.\n\n#### Vector2.IVector2.x : number\nX component of vector.\n\n#### Vector2.IVector2.y : number\nY component of vector.\n\n```ts\nimport { Vector2 } from 'simple-game-math'\nconst newVector: Vector2.IVector2 = {\n  x: 0,\n  y: 10\n}\n```\n\n```ts\nimport { Vector2 } from 'simple-game-math'\n\nclass Vector extends IVector2 {\n  constructor(public x: number, public y: number) {}\n}\n```\n\n### Vector2.distance(a: IVector2, b: IVector2): number\nReturns the distance between 2 vectors points.\n\n```ts\nimport { Vector2 } from 'simple-game-math'\nconst dist =  Vector2.distance({x: 0, y: 0}, {x: 10, y: 0})\n\nconsole.log(dist) // output: 10\n```\n\n### Vector2.dot(a: IVector2, b: IVector2): number\nReturns the dot product between 2 vectors.\n\n```ts\nimport { Vector2 } from 'simple-game-math'\n\nconsole.log(Vector2.dot({x: 1, y: 1}, {x: 10, y: 10})) // output: {x: 10, y: 10}\n```\n\n### Vector2.mag(v: IVector2): number\nReturns the magnitude of a vector.\n\n```ts\nimport { Vector2 } from 'simple-game-math'\n\nconsole.log(Vector2.mag({x: 5, y: 10})) //output: 11.180339887498949\n```\n\n### Vector2.normalize(v: IVector2): IVector2\nReturns a vector with a magnitude of one in the same direction as the input vector.\n\n```ts\nimport { Vector2 } from 'simple-game-math'\n\nconsole.log(Vector2.normalize({x: 5, y: 10})) // output: {x: 0.44721359549996, y: 0.89442719099992}\n```\n\n### Vector2.subtract(b: IVector2, a: IVector2): IVector2\nReturns a vector where the components are equal to `x = b.x - a.x and y = b.y - a.y`.\n\n```ts\nimport { Vector2 } from 'simple-game-math'\n\nconsole.log(Vector2.subtract({x: 10, y: 15}, {x: 5, y: 5})) //output: {x: 5, y: 10}\n```\n\n## Math\nA module for providing basic math functions.\n\n### Math.clamp(v: number, min: number, max: number): number\nReturns the a V clamped between min and max.\n\n```ts\nimport { Math } from 'simple-game-math'\n\nconsole.log(Math.clamp(20, 0, 10)) //output: 10\n```\n\n### Math.moveTowards(current: number, towards: number, maxStep: number): number\nReturns a number that is between current and towards but will not exceed towards.\n\n```ts\nimport { Math } from 'simple-game-math'\n\nconsole.log(Math.moveTowards(0, 10, 5)) // output: 5\nconsole.log(Math.moveTowards(0, 10, 20)) // output: 10\nconsole.log(Math.moveTowards(0, 10, -10)) // output: 0\n```\n\n### Math.lerp(start: number, end: number, step: number): number\nLinearly interpolates between two numbers\n\n```ts\nimport { Math } from 'simple-game-math'\n\nconsole.log(Math.lerp(0, 10, 0.5)) // output: 5\nconsole.log(Math.lerp(0, 10, 0.25)) // output: 2.5\nconsole.log(Math.lerp(0, 10, 0.75)) // output: 7.5\nconsole.log(Math.lerp(0, 10, 1)) // output: 10\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoopis23%2Fsimple-game-math","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoopis23%2Fsimple-game-math","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoopis23%2Fsimple-game-math/lists"}