{"id":13634751,"url":"https://github.com/llafuente/js-2dmath","last_synced_at":"2025-04-11T14:31:24.680Z","repository":{"id":11200194,"uuid":"13583428","full_name":"llafuente/js-2dmath","owner":"llafuente","description":"Fast 2d geometry math: Vector2, Rectangle, Circle, Matrix2x3 (2D transformation), Circle, BoundingBox, Line2, Segment2, Intersections, Distances, Transitions (animation/tween), Noise, Random numbers","archived":false,"fork":false,"pushed_at":"2015-08-01T16:46:11.000Z","size":935,"stargazers_count":96,"open_issues_count":3,"forks_count":22,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-04-29T16:20:57.907Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/llafuente.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-15T07:33:13.000Z","updated_at":"2023-12-07T13:48:51.000Z","dependencies_parsed_at":"2022-09-11T16:10:21.758Z","dependency_job_id":null,"html_url":"https://github.com/llafuente/js-2dmath","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/llafuente%2Fjs-2dmath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llafuente%2Fjs-2dmath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llafuente%2Fjs-2dmath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llafuente%2Fjs-2dmath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/llafuente","download_url":"https://codeload.github.com/llafuente/js-2dmath/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999861,"owners_count":21031046,"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":[],"created_at":"2024-08-02T00:00:32.806Z","updated_at":"2025-04-11T14:31:20.286Z","avatar_url":"https://github.com/llafuente.png","language":"JavaScript","readme":"# js-2dmath [![Build Status](https://secure.travis-ci.org/llafuente/js-2dmath.png?branch=master)](http://travis-ci.org/llafuente/js-2dmath)\n\n\nFast 2d geometry math: Vector2, Rectangle, Circle, Matrix2x3 (2D transformation), Circle, BoundingBox, Line2, Segment2, Intersections, Distances, Transitions (animation/tween), Noise, Random numbers.\n\nSo the objective is \"**Be fast**\"\n\n\n## Help needed / TODO LIST\n\n* API completeness\n* Testing\n* Use falafel/esprima to create an asm.js build\n* More Numerical integrators\n* AI: Path-finding, Steer, Backtracking\n* IK: FABRIK\n* Minkowski distance, euclidean, Manhattan\n* Beizer math\n* Serialization / De-serialization\n* did I miss anything useful?\n\n\n## Performance\n\nPerformance is based on good practices.\n\n* Avoid **new**\n* Use arrays instead of objects, this is huge performance boost!\n* Avoid creating unnecessary variables (reuse intermediate variables) only `create` \u0026 `clone` methods should create new variables.\n* Cache every function call to a single variable. example: `Vec2.add` =\u003e `vec2_add`, even `Math.*`\n* If access a multi-dimensional array in a loop, cache the array access. `for(i...) carr=arr[i]; carr[X]`\n* Do not use `forEach`, `map`, `every` etc. or other looping method that require `apply`/`call` usage, both are costly.\n\nSee some [performance test](https://github.com/llafuente/js-2dmath/blob/master/js-performance-tests.markdown) that prove it.\n\n[funlinify](https://github.com/llafuente/funlinify) It's a library that do function inline expansion for javascript. It's in early stage but it works perfectly for our usage here.\n\nObviously I ignore myself in some parts of this library. Feel free to issue me :)\n\n\n## Grunt\n\n```bash\nnpm install -g grunt\nnpm install -g grunt-cli\n```\n\n### grunt dist\n\nCreate distribution packages using [browserify](https://github.com/substack/node-browserify) and documentation.\n\n* debug: *debug/js-2dmath-browser-debug.js*\n  * [argumentify](https://github.com/llafuente/argumentify) Assert on invalid arguments to properly debug your app.\n\n* dist: *dist/js-2dmath-browser.js*\n  * [funlinify](https://github.com/llafuente/funlinify) inline function\n\n* dist.min: *js-2dmath-browser.min.js*\n  * [funlinify](https://github.com/llafuente/funlinify) inline function\n  * [uglify](https://github.com/mishoo/UglifyJS)\n\n### grunt watch\n\nWatch every change and rebuild the distribution code.\n\n## What can you do with js-2dmath?\n\nSee some examples.\n\n* [Angles](http://htmlpreview.github.io/?https://github.com/llafuente/js-2dmath/blob/master/test/angle.html)\n* [Beizer](http://htmlpreview.github.io/?https://github.com/llafuente/js-2dmath/blob/master/test/beizer.html)\n* [Circle](http://htmlpreview.github.io/?https://github.com/llafuente/js-2dmath/blob/master/test/circle.html)\n* [Intersections](http://htmlpreview.github.io/?https://github.com/llafuente/js-2dmath/blob/master/test/intersections.html)\n* [line2](http://htmlpreview.github.io/?https://github.com/llafuente/js-2dmath/blob/master/test/line2.html)\n* [Matrix23](http://htmlpreview.github.io/?https://github.com/llafuente/js-2dmath/blob/master/test/matrix23.html)\n* [Segment2](http://htmlpreview.github.io/?https://github.com/llafuente/js-2dmath/blob/master/test/segment2.html)\n* [Transitions](http://htmlpreview.github.io/?https://github.com/llafuente/js-2dmath/blob/master/test/transitions.html)\n* [Triangle](http://htmlpreview.github.io/?https://github.com/llafuente/js-2dmath/blob/master/test/triangle.html)\n* [Vec2 collisions](http://htmlpreview.github.io/?https://github.com/llafuente/js-2dmath/blob/master/test/vec2-collisions.html)\n* [Vec2](http://htmlpreview.github.io/?https://github.com/llafuente/js-2dmath/blob/master/test/vec2.html)\n\n\n## API\n\nThe documentation is autogenerated with [falafel](https://github.com/substack/node-falafel) see dist.js for more fun! :)\n\n* [Vec2](https://github.com/llafuente/js-2dmath/blob/master/docs/vec2.markdown)\n* [Line2](https://github.com/llafuente/js-2dmath/blob/master/docs/line2.markdown)\n* [Segment2](https://github.com/llafuente/js-2dmath/blob/master/docs/segment2.markdown)\n* [Rectangle](https://github.com/llafuente/js-2dmath/blob/master/docs/rectangle.markdown)\n* [AABB2](https://github.com/llafuente/js-2dmath/blob/master/docs/aabb2.markdown)\n* [Circle](https://github.com/llafuente/js-2dmath/blob/master/docs/circle.markdown)\n* [Matrix22](https://github.com/llafuente/js-2dmath/blob/master/docs/matrix22.markdown)\n* [Matrix23](https://github.com/llafuente/js-2dmath/blob/master/docs/matrix23.markdown)\n* [Polygon](https://github.com/llafuente/js-2dmath/blob/master/docs/polygon.markdown)\n* [Beizer](https://github.com/llafuente/js-2dmath/blob/master/docs/beizer.markdown)\n* [Triangle](https://github.com/llafuente/js-2dmath/blob/master/docs/triangle.markdown)\n* [Intersection](https://github.com/llafuente/js-2dmath/blob/master/docs/intersection.markdown)\n* [Distance](https://github.com/llafuente/js-2dmath/blob/master/docs/distance.markdown)\n* [Transitions](https://github.com/llafuente/js-2dmath/blob/master/docs/transitions.markdown)\n* [Xorshift](https://github.com/llafuente/js-2dmath/blob/master/docs/xorshift.markdown)\n* [Noise](https://github.com/llafuente/js-2dmath/blob/master/docs/noise.markdown)\n* [Collision.SAT](https://github.com/llafuente/js-2dmath/blob/master/docs/collision-sat.markdown)\n* [Collision.GJK](https://github.com/llafuente/js-2dmath/blob/master/docs/collision-gjk.markdown)\n* [Collision.Resolve](https://github.com/llafuente/js-2dmath/blob/master/docs/collision-resolve.markdown)\n* [Collision.Manifold](https://github.com/llafuente/js-2dmath/blob/master/docs/collision-manifold.markdown)\n\n\n\n## FAQ\n\n**How do i know a variable type?**\n\nYou can't, there is no *instanceof* or anything like that, everything are numbers/arrays.\n\nI choose to keep track of all types using meaningful naming or enclose the variable in an object like\n\n```js\nvar movable = {\n    body: Polygon.create(/*...*/), // could be a circle, change the type...\n    type: \"polygon\"\n}\n```","funding_links":[],"categories":["graphic (图形库)"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllafuente%2Fjs-2dmath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fllafuente%2Fjs-2dmath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllafuente%2Fjs-2dmath/lists"}