{"_id":"@deltasnare/physics2d-collision","_rev":"1-8e81df174161f4147f2c1e5331fbd233","name":"@deltasnare/physics2d-collision","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@deltasnare/physics2d-collision","version":"1.0.0","description":"Polygon-to-polygon collision calculator for Deltasnare's physics engine","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/b3nsn0w/deltasnare-physics2d-collision.git"},"author":{"name":"Ben Snow","email":"balintbence97@gmail.com"},"license":"LGPL-3.0","bugs":{"url":"https://github.com/b3nsn0w/deltasnare-physics2d-collision/issues"},"homepage":"https://github.com/b3nsn0w/deltasnare-physics2d-collision#readme","dependencies":{"gl-matrix":"^2.8.1"},"gitHead":"515239ae851b74c69801e1f0f92117e2445c2f78","_id":"@deltasnare/physics2d-collision@1.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.10.0","_npmUser":{"name":"b3nsn0w","email":"balintbence97@gmail.com"},"dist":{"integrity":"sha512-X3uuoQo56TdAXoGeeJUvHUuSFuNGLWLw0cpRP2ZDY6gv/bWdV48HCsnr3AkbdQutx8GS86QcljX5NpK9DJwUKw==","shasum":"e3b8eec4b727a676cf69c3f119dbb190084e5a02","tarball":"https://registry.npmjs.org/@deltasnare/physics2d-collision/-/physics2d-collision-1.0.0.tgz","fileCount":4,"unpackedSize":7300,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcCyyTCRA9TVsSAnZWagAA+50P/0RNyxJHD2fZXbYfBZlV\njfTM++PEPnFcXQj5I7hTup9JOGDgxes3pL2w4bBnj84N0wIfMSJz9gK9x9oF\nVcjf8UupE4u9oTT/CHnWfdv/mupQCkvMCodLjm62mrdHL/O9HeH6jakhyhXJ\nWH18yikitlKbZhP0a2KXZ2MbvIj96as9SY9upGjO11RaJ/1H/B6pnN3FAUQm\n9kU3X/A6xggMm6ejWcxLrTIz9u+eKBjpC1S+wJfnqxCH7Vai8Zuq/IhLp7Gy\nJTX2YL+KzzOjvEp09XhLWWPyamNBRtBD9TUSzJLMNZS1KcoLpt6xtl5VTnhf\n/Q+CxM7qRb9jrE5K8mn9ie+xzFNpYYYBHmvlVewikNpMNd6Vpo4U21npyk6M\nPxH/ziPZtmfFGN3Tm7en6Yck2rkZP3/O9UgFI5ONhk2j7HqDn/TCCdbo3hu6\nWo91xwb+KUN7UJqxnIwaSbWQ05GXqHdafnLoVF2lTDIIr57QoJ5NbLHnLi73\nje3oIyHz5IHmY7CzQfrN9fUIYqm0LISENNKaNYPtT/vxodx3LfTqp1o3sxZr\nNdg8tW3bhsVvgXQmbi8vqwcThqcXxICDxnwulnWqKBlnTMdc3CgitpP2nk98\nzv6TjeY0yHZceK3zJRYoazJ/Yf/7kFu8+e+EdGCVyNtY6xrgMyo1tSmTfFIf\nZYXh\r\n=ti2t\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICyj/IXj5lRL55YTG/O8wktbAR72jDXRGdWPYh02rHK/AiASJFzH7OFx96+GosT9s9DQq9LB6OHeukj4S4Xw7yKCKA=="}]},"maintainers":[{"name":"require('rontap')","email":"aron.tatai@gmail.com"},{"name":"b3nsn0w","email":"balintbence97@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/physics2d-collision_1.0.0_1544236178693_0.2358780270864873"},"_hasShrinkwrap":false}},"time":{"created":"2018-12-08T02:29:38.513Z","1.0.0":"2018-12-08T02:29:38.811Z","modified":"2022-04-05T03:43:00.484Z"},"maintainers":[{"name":"require('rontap')","email":"aron.tatai@gmail.com"},{"name":"b3nsn0w","email":"balintbence97@gmail.com"}],"description":"Polygon-to-polygon collision calculator for Deltasnare's physics engine","homepage":"https://github.com/b3nsn0w/deltasnare-physics2d-collision#readme","repository":{"type":"git","url":"git+https://github.com/b3nsn0w/deltasnare-physics2d-collision.git"},"author":{"name":"Ben Snow","email":"balintbence97@gmail.com"},"bugs":{"url":"https://github.com/b3nsn0w/deltasnare-physics2d-collision/issues"},"license":"LGPL-3.0","readme":"Polygon-to-polygon collision calculator for Deltasnare's physics engine\n\n# Usage\n\n```javascript\nconst collision = require('@deltasnare/physics2d-collision')\nconst { mat2d } = require('gl-matrix')\n\n// create some collider models\nconst target = collision.create([[0, 5], [-2, 0], [0, -5], [2, 0]])\nconst near = collision.create([[1, 3], [1, -3], [4, -3], [4, 3]])\nconst far = collision.create([[3, 3], [3, -3], [6, -3], [6, 3]])\n\n// transform models\nconst transformed = collision.transform(target, mat2d.fromTranslation([], [-1, -5]))\n\n// test for collisions\nconst nearCollision = collision.check(target, near) // { depth: 1, normal: [1, 0] }\nconst farCollision = collision.check(target, far) // null\n```\n\nThe collision module exports three functions:\n\n## `collision.create(vertices)`\n\nCreates a collider model. The argument is an array of vertices in `vec2` format (`[x, y]`). **The vertices must define a convex mesh in counter-clockwise order. Failing to comply with this assumption may lead to undefiend behavior and/or the physics engine blowing up.** For the structure of the returned collider model, [see below](#collision-models).\n\n## `collision.transform(model, transform)`\n\nTransforms a collider model with a 2D matrix, returning the resulting model. The `model` argument must be a collider model created by `collision.create()` or compatible with it, and `transform` is a `mat2d`, a 3x2 2D transformation matrix.\n\n## `collision.check(first, second)`\n\nChecks if two models collide. Both arguments must be collider models created by `collision.create()` or compatible with it. Returns `null` if the objects do not collide. If they do, it returns a collision in the following format:\n\n```javascript\n{ depth: 1, normal: [1, 0] }\n```\n\nWhere\n - `depth` is the penetration depth (how far the objects overlap)\n - `normal` is the collision normal, the direction of the penetration. This vector is normalized.\n\n# Collider Models\n\nCollider models are the basic models that can be collided with this module. Here is an example:\n\n```javascript\n{ vertices: [ [ 0, 5 ], [ -2, 0 ], [ 0, -5 ], [ 2, 0 ] ],\n  normals:\n   [ [ -0.9284766908852593, 0.3713906763541037 ],\n     [ -0.9284766908852593, -0.3713906763541037 ],\n     [ 0.9284766908852593, -0.3713906763541037 ],\n     [ 0.9284766908852593, 0.3713906763541037 ] ],\n  boundingBox: { min: [ -2, -5 ], max: [ 2, 5 ] } }\n```\n\nCollider models are objects, with the following layout:\n - `vertices` is an array of `vec2` which define a convex polygon in counter-clockwise order\n - `normals` is an array of `vec2` where each member `normals[i]` corresponds to the outer normal of the edge between `vertices[i]` and `vertices[i + 1]`\n - `boundingBox` defines an axis-aligned bounding box of the mesh using an object, where:\n   - `min` is a `vec2`, containing the lowest coordinates of the box in each axis, and\n   - `max` is a `vec2`, containing the highest coordinates of the box in each axis\n","readmeFilename":"README.md"}