diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5cd143d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +packages +pubspec.lock diff --git a/bin/bench2d.dart b/bin/bench2d.dart index 8dca3c2..3b1ee5a 100644 --- a/bin/bench2d.dart +++ b/bin/bench2d.dart @@ -22,7 +22,7 @@ * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ -import '../lib/box2d/box2d.dart'; +import 'package:box2d/box2d.dart'; main() { Bench2D bench = new Bench2D(); diff --git a/codereview.settings b/codereview.settings new file mode 100644 index 0000000..73a13fd --- /dev/null +++ b/codereview.settings @@ -0,0 +1,2 @@ +CODE_REVIEW_SERVER: https://codereview.chromium.org/ +VIEW_VC: https://github.com/google/dbox2d/commit/ diff --git a/lib/box2d/box2d.dart b/lib/box2d.dart similarity index 99% rename from lib/box2d/box2d.dart rename to lib/box2d.dart index 36ff49a..7304a12 100644 --- a/lib/box2d/box2d.dart +++ b/lib/box2d.dart @@ -176,4 +176,3 @@ part 'src/pooling/normal/mutable_stack.dart'; part 'src/pooling/normal/ordered_stack.dart'; part 'src/pooling/stacks/dynamic_int_stack.dart'; - diff --git a/lib/box2d/src/callbacks/contact_filter.dart b/lib/src/callbacks/contact_filter.dart similarity index 97% rename from lib/box2d/src/callbacks/contact_filter.dart rename to lib/src/callbacks/contact_filter.dart index 68d837c..5252d0b 100644 --- a/lib/box2d/src/callbacks/contact_filter.dart +++ b/lib/src/callbacks/contact_filter.dart @@ -46,7 +46,7 @@ class ContactFilter { } bool collide = ((filterA.maskBits & filterB.categoryBits) != 0) && - ((filterA.categoryBits & filterB.maskBits) != 0); + ((filterA.categoryBits & filterB.maskBits) != 0); return collide; } } diff --git a/lib/box2d/src/callbacks/contact_impulse.dart b/lib/src/callbacks/contact_impulse.dart similarity index 100% rename from lib/box2d/src/callbacks/contact_impulse.dart rename to lib/src/callbacks/contact_impulse.dart diff --git a/lib/box2d/src/callbacks/contact_listener.dart b/lib/src/callbacks/contact_listener.dart similarity index 100% rename from lib/box2d/src/callbacks/contact_listener.dart rename to lib/src/callbacks/contact_listener.dart diff --git a/lib/box2d/src/callbacks/debug_draw.dart b/lib/src/callbacks/debug_draw.dart similarity index 97% rename from lib/box2d/src/callbacks/debug_draw.dart rename to lib/src/callbacks/debug_draw.dart index 982c8d4..6c60b00 100644 --- a/lib/box2d/src/callbacks/debug_draw.dart +++ b/lib/src/callbacks/debug_draw.dart @@ -162,14 +162,16 @@ abstract class DebugDraw { * * @param colors can be null */ - void drawParticles(List centers, double radius, List colors, int count); + void drawParticles( + List centers, double radius, List colors, int count); /** * Draw a particle array * * @param colors can be null */ - void drawParticlesWireframe(List centers, double radius, List colors, int count); + void drawParticlesWireframe( + List centers, double radius, List colors, int count); /** Called at the end of drawing a world */ void flush() {} @@ -192,7 +194,6 @@ abstract class DebugDraw { viewportTransform.setCamera(x, y, scale); } - /** * @param argScreen * @param argWorld diff --git a/lib/box2d/src/callbacks/destruction_listener.dart b/lib/src/callbacks/destruction_listener.dart similarity index 100% rename from lib/box2d/src/callbacks/destruction_listener.dart rename to lib/src/callbacks/destruction_listener.dart diff --git a/lib/box2d/src/callbacks/pair_callback.dart b/lib/src/callbacks/pair_callback.dart similarity index 100% rename from lib/box2d/src/callbacks/pair_callback.dart rename to lib/src/callbacks/pair_callback.dart diff --git a/lib/box2d/src/callbacks/particle_destruction_listener.dart b/lib/src/callbacks/particle_destruction_listener.dart similarity index 100% rename from lib/box2d/src/callbacks/particle_destruction_listener.dart rename to lib/src/callbacks/particle_destruction_listener.dart diff --git a/lib/box2d/src/callbacks/particle_query_callback.dart b/lib/src/callbacks/particle_query_callback.dart similarity index 100% rename from lib/box2d/src/callbacks/particle_query_callback.dart rename to lib/src/callbacks/particle_query_callback.dart diff --git a/lib/box2d/src/callbacks/particle_raycast_callback.dart b/lib/src/callbacks/particle_raycast_callback.dart similarity index 99% rename from lib/box2d/src/callbacks/particle_raycast_callback.dart rename to lib/src/callbacks/particle_raycast_callback.dart index 69d96ac..af37517 100644 --- a/lib/box2d/src/callbacks/particle_raycast_callback.dart +++ b/lib/src/callbacks/particle_raycast_callback.dart @@ -37,5 +37,4 @@ abstract class ParticleRaycastCallback { * @return */ double reportParticle(int index, Vec2 point, Vec2 normal, double fraction); - } diff --git a/lib/box2d/src/callbacks/query_callback.dart b/lib/src/callbacks/query_callback.dart similarity index 100% rename from lib/box2d/src/callbacks/query_callback.dart rename to lib/src/callbacks/query_callback.dart diff --git a/lib/box2d/src/callbacks/raycast_callback.dart b/lib/src/callbacks/raycast_callback.dart similarity index 96% rename from lib/box2d/src/callbacks/raycast_callback.dart rename to lib/src/callbacks/raycast_callback.dart index a93ad88..c7c86a8 100644 --- a/lib/box2d/src/callbacks/raycast_callback.dart +++ b/lib/src/callbacks/raycast_callback.dart @@ -44,5 +44,6 @@ abstract class RayCastCallback { * closest hit, 1 to continue * @param fraction */ - double reportFixture(Fixture fixture, Vec2 point, Vec2 normal, double fraction); + double reportFixture( + Fixture fixture, Vec2 point, Vec2 normal, double fraction); } diff --git a/lib/box2d/src/callbacks/tree_callback.dart b/lib/src/callbacks/tree_callback.dart similarity index 99% rename from lib/box2d/src/callbacks/tree_callback.dart rename to lib/src/callbacks/tree_callback.dart index 85d97f2..d4c03b7 100644 --- a/lib/box2d/src/callbacks/tree_callback.dart +++ b/lib/src/callbacks/tree_callback.dart @@ -29,7 +29,7 @@ part of box2d; * */ abstract class TreeCallback { - + /** * Callback from a query request. * @param proxyId the id of the proxy diff --git a/lib/box2d/src/callbacks/tree_raycast_callback.dart b/lib/src/callbacks/tree_raycast_callback.dart similarity index 96% rename from lib/box2d/src/callbacks/tree_raycast_callback.dart rename to lib/src/callbacks/tree_raycast_callback.dart index 7af9479..f25859e 100644 --- a/lib/box2d/src/callbacks/tree_raycast_callback.dart +++ b/lib/src/callbacks/tree_raycast_callback.dart @@ -22,7 +22,6 @@ * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ - part of box2d; /** @@ -37,5 +36,5 @@ abstract class TreeRayCastCallback { * @param nodeId * @return the fraction to the node */ - double raycastCallback( RayCastInput input, int nodeId); + double raycastCallback(RayCastInput input, int nodeId); } diff --git a/lib/box2d/src/collision/aabb.dart b/lib/src/collision/aabb.dart similarity index 84% rename from lib/box2d/src/collision/aabb.dart rename to lib/src/collision/aabb.dart index b41b5bd..76ba2d9 100644 --- a/lib/box2d/src/collision/aabb.dart +++ b/lib/src/collision/aabb.dart @@ -34,7 +34,9 @@ class AABB { /** * Creates the default object, with vertices at 0,0 and 0,0. */ - AABB() : lowerBound = new Vec2.zero(), upperBound = new Vec2.zero(); + AABB() + : lowerBound = new Vec2.zero(), + upperBound = new Vec2.zero(); /** * Copies from the given object @@ -42,9 +44,9 @@ class AABB { * @param copy the object to copy from */ AABB.copy(final AABB copy) - : lowerBound = new Vec2.copy(copy.lowerBound), - upperBound = new Vec2.copy(copy.upperBound); - + : lowerBound = new Vec2.copy(copy.lowerBound), + upperBound = new Vec2.copy(copy.upperBound); + /** * Creates an AABB object using the given bounding vertices. * @@ -54,7 +56,7 @@ class AABB { AABB.withVec2(final Vec2 lowerVertex, final Vec2 upperVertex) : lowerBound = new Vec2.copy(lowerVertex), upperBound = new Vec2.copy(upperVertex); - + /** * Sets this object from the given object * @@ -132,10 +134,18 @@ class AABB { * @param aab */ void combine2(final AABB aabb1, final AABB aab) { - lowerBound.x = aabb1.lowerBound.x < aab.lowerBound.x ? aabb1.lowerBound.x : aab.lowerBound.x; - lowerBound.y = aabb1.lowerBound.y < aab.lowerBound.y ? aabb1.lowerBound.y : aab.lowerBound.y; - upperBound.x = aabb1.upperBound.x > aab.upperBound.x ? aabb1.upperBound.x : aab.upperBound.x; - upperBound.y = aabb1.upperBound.y > aab.upperBound.y ? aabb1.upperBound.y : aab.upperBound.y; + lowerBound.x = aabb1.lowerBound.x < aab.lowerBound.x + ? aabb1.lowerBound.x + : aab.lowerBound.x; + lowerBound.y = aabb1.lowerBound.y < aab.lowerBound.y + ? aabb1.lowerBound.y + : aab.lowerBound.y; + upperBound.x = aabb1.upperBound.x > aab.upperBound.x + ? aabb1.upperBound.x + : aab.upperBound.x; + upperBound.y = aabb1.upperBound.y > aab.upperBound.y + ? aabb1.upperBound.y + : aab.upperBound.y; } /** @@ -153,10 +163,14 @@ class AABB { * @param aabb */ void combine(final AABB aabb) { - lowerBound.x = lowerBound.x < aabb.lowerBound.x ? lowerBound.x : aabb.lowerBound.x; - lowerBound.y = lowerBound.y < aabb.lowerBound.y ? lowerBound.y : aabb.lowerBound.y; - upperBound.x = upperBound.x > aabb.upperBound.x ? upperBound.x : aabb.upperBound.x; - upperBound.y = upperBound.y > aabb.upperBound.y ? upperBound.y : aabb.upperBound.y; + lowerBound.x = + lowerBound.x < aabb.lowerBound.x ? lowerBound.x : aabb.lowerBound.x; + lowerBound.y = + lowerBound.y < aabb.lowerBound.y ? lowerBound.y : aabb.lowerBound.y; + upperBound.x = + upperBound.x > aabb.upperBound.x ? upperBound.x : aabb.upperBound.x; + upperBound.y = + upperBound.y > aabb.upperBound.y ? upperBound.y : aabb.upperBound.y; } /** @@ -172,8 +186,10 @@ class AABB { */ // djm: faster putting all of them together, as if one is false we leave the logic // early - return lowerBound.x <= aabb.lowerBound.x && lowerBound.y <= aabb.lowerBound.y - && aabb.upperBound.x <= upperBound.x && aabb.upperBound.y <= upperBound.y; + return lowerBound.x <= aabb.lowerBound.x && + lowerBound.y <= aabb.lowerBound.y && + aabb.upperBound.x <= upperBound.x && + aabb.upperBound.y <= upperBound.y; } /** @@ -193,7 +209,8 @@ class AABB { * @param output * @param input */ - bool raycastWithPool(final RayCastOutput output, final RayCastInput input, IWorldPool argPool) { + bool raycastWithPool(final RayCastOutput output, final RayCastInput input, + IWorldPool argPool) { double tmin = -double.MAX_FINITE; double tmax = double.MAX_FINITE; @@ -297,11 +314,13 @@ class AABB { } static bool testOverlap(final AABB a, final AABB b) { - if (b.lowerBound.x - a.upperBound.x > 0.0 || b.lowerBound.y - a.upperBound.y > 0.0) { + if (b.lowerBound.x - a.upperBound.x > 0.0 || + b.lowerBound.y - a.upperBound.y > 0.0) { return false; } - if (a.lowerBound.x - b.upperBound.x > 0.0 || a.lowerBound.y - b.upperBound.y > 0.0) { + if (a.lowerBound.x - b.upperBound.x > 0.0 || + a.lowerBound.y - b.upperBound.y > 0.0) { return false; } diff --git a/lib/box2d/src/collision/broadphase/broadphase.dart b/lib/src/collision/broadphase/broadphase.dart similarity index 99% rename from lib/box2d/src/collision/broadphase/broadphase.dart rename to lib/src/collision/broadphase/broadphase.dart index 9b5e618..9e5fe86 100644 --- a/lib/box2d/src/collision/broadphase/broadphase.dart +++ b/lib/src/collision/broadphase/broadphase.dart @@ -25,7 +25,6 @@ part of box2d; abstract class BroadPhase { - static const int NULL_PROXY = -1; /** diff --git a/lib/box2d/src/collision/broadphase/broadphase_strategy.dart b/lib/src/collision/broadphase/broadphase_strategy.dart similarity index 99% rename from lib/box2d/src/collision/broadphase/broadphase_strategy.dart rename to lib/src/collision/broadphase/broadphase_strategy.dart index 8a7bb46..f05966c 100644 --- a/lib/box2d/src/collision/broadphase/broadphase_strategy.dart +++ b/lib/src/collision/broadphase/broadphase_strategy.dart @@ -49,7 +49,7 @@ abstract class BroadPhaseStrategy { * @return true if the proxy was re-inserted. */ bool moveProxy(int proxyId, AABB aabb, Vec2 displacement); - + Object getUserData(int proxyId); AABB getFatAABB(int proxyId); diff --git a/lib/box2d/src/collision/broadphase/default_broadphase_buffer.dart b/lib/src/collision/broadphase/default_broadphase_buffer.dart similarity index 95% rename from lib/box2d/src/collision/broadphase/default_broadphase_buffer.dart rename to lib/src/collision/broadphase/default_broadphase_buffer.dart index 6beeaf1..c9c4fd8 100644 --- a/lib/box2d/src/collision/broadphase/default_broadphase_buffer.dart +++ b/lib/src/collision/broadphase/default_broadphase_buffer.dart @@ -32,7 +32,6 @@ part of box2d; * @author Daniel Murphy */ class DefaultBroadPhaseBuffer implements TreeCallback, BroadPhase { - final BroadPhaseStrategy _m_tree; int _m_proxyCount = 0; @@ -92,11 +91,13 @@ class DefaultBroadPhaseBuffer implements TreeCallback, BroadPhase { // return _m_tree.overlap(proxyIdA, proxyIdB); final AABB a = _m_tree.getFatAABB(proxyIdA); final AABB b = _m_tree.getFatAABB(proxyIdB); - if (b.lowerBound.x - a.upperBound.x > 0.0 || b.lowerBound.y - a.upperBound.y > 0.0) { + if (b.lowerBound.x - a.upperBound.x > 0.0 || + b.lowerBound.y - a.upperBound.y > 0.0) { return false; } - if (a.lowerBound.x - b.upperBound.x > 0.0 || a.lowerBound.y - b.upperBound.y > 0.0) { + if (a.lowerBound.x - b.upperBound.x > 0.0 || + a.lowerBound.y - b.upperBound.y > 0.0) { return false; } @@ -152,7 +153,8 @@ class DefaultBroadPhaseBuffer implements TreeCallback, BroadPhase { // Skip any duplicate pairs. while (i < _m_pairCount) { Pair pair = _m_pairBuffer[i]; - if (pair.proxyIdA != primaryPair.proxyIdA || pair.proxyIdB != primaryPair.proxyIdB) { + if (pair.proxyIdA != primaryPair.proxyIdA || + pair.proxyIdB != primaryPair.proxyIdB) { break; } ++i; diff --git a/lib/box2d/src/collision/broadphase/dynamic_tree.dart b/lib/src/collision/broadphase/dynamic_tree.dart similarity index 96% rename from lib/box2d/src/collision/broadphase/dynamic_tree.dart rename to lib/src/collision/broadphase/dynamic_tree.dart index 1059263..b88e73a 100644 --- a/lib/box2d/src/collision/broadphase/dynamic_tree.dart +++ b/lib/src/collision/broadphase/dynamic_tree.dart @@ -159,7 +159,8 @@ class DynamicTree implements BroadPhaseStrategy { } } else { if (nodeStack.length - nodeStackIndex - 2 <= 0) { - List newBuffer = new List(nodeStack.length * 2); + List newBuffer = + new List(nodeStack.length * 2); Settings.arraycopy(nodeStack, 0, newBuffer, 0, nodeStack.length); nodeStack = newBuffer; } @@ -243,7 +244,8 @@ class DynamicTree implements BroadPhaseStrategy { hy = (nodeAABB.upperBound.y - nodeAABB.lowerBound.y) * .5; tempx = p1x - cx; tempy = p1y - cy; - double separation = (vx * tempx + vy * tempy).abs() - (absVx * hx + absVy * hy); + double separation = + (vx * tempx + vy * tempy).abs() - (absVx * hx + absVy * hy); if (separation > 0.0) { continue; } @@ -277,7 +279,8 @@ class DynamicTree implements BroadPhaseStrategy { } } else { if (nodeStack.length - nodeStackIndex - 2 <= 0) { - List newBuffer = new List(nodeStack.length * 2); + List newBuffer = + new List(nodeStack.length * 2); Settings.arraycopy(nodeStack, 0, newBuffer, 0, nodeStack.length); nodeStack = newBuffer; } @@ -310,7 +313,8 @@ class DynamicTree implements BroadPhaseStrategy { _validateMetrics(_m_root); int freeCount = 0; - DynamicTreeNode freeNode = _m_freeList != NULL_NODE ? _m_nodes[_m_freeList] : null; + DynamicTreeNode freeNode = + _m_freeList != NULL_NODE ? _m_nodes[_m_freeList] : null; while (freeNode != null) { assert(0 <= freeNode.id && freeNode.id < _m_nodeCapacity); assert(freeNode == _m_nodes[freeNode.id]); @@ -452,7 +456,8 @@ class DynamicTree implements BroadPhaseStrategy { // Build a linked list for the free list. for (int i = _m_nodeCapacity - 1; i >= _m_nodeCount; i--) { _m_nodes[i] = new DynamicTreeNode(i); - _m_nodes[i].parent = (i == _m_nodeCapacity - 1) ? null : _m_nodes[i + 1]; + _m_nodes[i].parent = + (i == _m_nodeCapacity - 1) ? null : _m_nodes[i + 1]; _m_nodes[i].height = -1; } _m_freeList = _m_nodeCount; @@ -843,14 +848,18 @@ class DynamicTree implements BroadPhaseStrategy { final Color3f _color = new Color3f.zero(); final Vec2 _textVec = new Vec2.zero(); - void drawTreeX(DebugDraw argDraw, DynamicTreeNode node, int spot, int height) { + void drawTreeX( + DebugDraw argDraw, DynamicTreeNode node, int spot, int height) { node.aabb.getVertices(drawVecs); - _color.setRGB(1.0, (height - spot) * 1.0 / height, (height - spot) * 1.0 / height); + _color.setRGB( + 1.0, (height - spot) * 1.0 / height, (height - spot) * 1.0 / height); argDraw.drawPolygon(drawVecs, 4, _color); - argDraw.getViewportTranform().getWorldToScreen(node.aabb.upperBound, _textVec); - argDraw.drawStringXY(_textVec.x, _textVec.y, "$node.id-${(spot + 1)}/$height", _color); + argDraw.getViewportTranform().getWorldToScreen( + node.aabb.upperBound, _textVec); + argDraw.drawStringXY( + _textVec.x, _textVec.y, "$node.id-${(spot + 1)}/$height", _color); if (node.child1 != null) { drawTreeX(argDraw, node.child1, spot + 1, height); diff --git a/lib/box2d/src/collision/broadphase/dynamic_tree_flatnodes.dart b/lib/src/collision/broadphase/dynamic_tree_flatnodes.dart similarity index 96% rename from lib/box2d/src/collision/broadphase/dynamic_tree_flatnodes.dart rename to lib/src/collision/broadphase/dynamic_tree_flatnodes.dart index 97ea2ee..74279c2 100644 --- a/lib/box2d/src/collision/broadphase/dynamic_tree_flatnodes.dart +++ b/lib/src/collision/broadphase/dynamic_tree_flatnodes.dart @@ -56,8 +56,10 @@ class DynamicTreeFlatNodes implements BroadPhaseStrategy { static Object allocObject() => new Object(); void _expandBuffers(int oldSize, int newSize) { - m_aabb = BufferUtils.reallocateBufferWithAlloc(m_aabb, oldSize, newSize, allocAABB); - m_userData = BufferUtils.reallocateBufferWithAlloc(m_userData, oldSize, newSize, allocObject); + m_aabb = BufferUtils.reallocateBufferWithAlloc( + m_aabb, oldSize, newSize, allocAABB); + m_userData = BufferUtils.reallocateBufferWithAlloc( + m_userData, oldSize, newSize, allocObject); m_parent = BufferUtils.reallocateBufferInt(m_parent, oldSize, newSize); m_child1 = BufferUtils.reallocateBufferInt(m_child1, oldSize, newSize); m_child2 = BufferUtils.reallocateBufferInt(m_child2, oldSize, newSize); @@ -104,7 +106,10 @@ class DynamicTreeFlatNodes implements BroadPhaseStrategy { final AABB nodeAABB = m_aabb[node]; // if (nodeAABB.contains(aabb)) { - if (nodeAABB.lowerBound.x <= aabb.lowerBound.x && nodeAABB.lowerBound.y <= aabb.lowerBound.y && aabb.upperBound.x <= nodeAABB.upperBound.x && aabb.upperBound.y <= nodeAABB.upperBound.y) { + if (nodeAABB.lowerBound.x <= aabb.lowerBound.x && + nodeAABB.lowerBound.y <= aabb.lowerBound.y && + aabb.upperBound.x <= nodeAABB.upperBound.x && + aabb.upperBound.y <= nodeAABB.upperBound.y) { return false; } @@ -169,7 +174,8 @@ class DynamicTreeFlatNodes implements BroadPhaseStrategy { } } else { if (_nodeStack.length - _nodeStackIndex - 2 <= 0) { - _nodeStack = BufferUtils.reallocateBufferInt(_nodeStack, _nodeStack.length, _nodeStack.length * 2); + _nodeStack = BufferUtils.reallocateBufferInt( + _nodeStack, _nodeStack.length, _nodeStack.length * 2); } _nodeStack[_nodeStackIndex++] = child1; _nodeStack[_nodeStackIndex++] = m_child2[node]; @@ -251,7 +257,8 @@ class DynamicTreeFlatNodes implements BroadPhaseStrategy { hy = (nodeAABB.upperBound.y - nodeAABB.lowerBound.y) * .5; tempx = p1x - cx; tempy = p1y - cy; - double separation = (vx * tempx + vy * tempy).abs() - (absVx * hx + absVy * hy); + double separation = + (vx * tempx + vy * tempy).abs() - (absVx * hx + absVy * hy); if (separation > 0.0) { continue; } @@ -834,11 +841,13 @@ class DynamicTreeFlatNodes implements BroadPhaseStrategy { AABB a = m_aabb[node]; a.getVertices(drawVecs); - _color.setRGB(1.0, (height - spot) * 1.0 / height, (height - spot) * 1.0 / height); + _color.setRGB( + 1.0, (height - spot) * 1.0 / height, (height - spot) * 1.0 / height); argDraw.drawPolygon(drawVecs, 4, _color); argDraw.getViewportTranform().getWorldToScreen(a.upperBound, _textVec); - argDraw.drawStringXY(_textVec.x, _textVec.y, "$node-${(spot + 1)}/$height", _color); + argDraw.drawStringXY( + _textVec.x, _textVec.y, "$node-${(spot + 1)}/$height", _color); int c1 = m_child1[node]; int c2 = m_child2[node]; diff --git a/lib/box2d/src/collision/broadphase/dynamic_tree_node.dart b/lib/src/collision/broadphase/dynamic_tree_node.dart similarity index 100% rename from lib/box2d/src/collision/broadphase/dynamic_tree_node.dart rename to lib/src/collision/broadphase/dynamic_tree_node.dart diff --git a/lib/box2d/src/collision/broadphase/pair.dart b/lib/src/collision/broadphase/pair.dart similarity index 94% rename from lib/box2d/src/collision/broadphase/pair.dart rename to lib/src/collision/broadphase/pair.dart index a351d3e..90a5906 100644 --- a/lib/box2d/src/collision/broadphase/pair.dart +++ b/lib/src/collision/broadphase/pair.dart @@ -38,7 +38,9 @@ class Pair implements Comparable { } if (this.proxyIdA == pair2.proxyIdA) { - return proxyIdB < pair2.proxyIdB ? -1 : proxyIdB == pair2.proxyIdB ? 0 : 1; + return proxyIdB < pair2.proxyIdB + ? -1 + : proxyIdB == pair2.proxyIdB ? 0 : 1; } return 1; diff --git a/lib/box2d/src/collision/collision.dart b/lib/src/collision/collision.dart similarity index 94% rename from lib/box2d/src/collision/collision.dart rename to lib/src/collision/collision.dart index cce41a3..042fad1 100644 --- a/lib/box2d/src/collision/collision.dart +++ b/lib/src/collision/collision.dart @@ -79,9 +79,7 @@ enum PointState { * This structure is used to keep track of the best separating axis. */ -enum EPAxisType { - UNKNOWN, EDGE_A, EDGE_B -} +enum EPAxisType { UNKNOWN, EDGE_A, EDGE_B } class EPAxis { EPAxisType type = EPAxisType.UNKNOWN; @@ -109,7 +107,8 @@ class TempPolygon { * Reference face used for clipping */ class _ReferenceFace { - int i1 = 0, i2 = 0; + int i1 = 0, + i2 = 0; final Vec2 v1 = new Vec2.zero(); final Vec2 v2 = new Vec2.zero(); final Vec2 normal = new Vec2.zero(); @@ -121,7 +120,6 @@ class _ReferenceFace { double sideOffset2 = 0.0; } - /** * Functions used for computing contact points, distance queries, and TOI queries. Collision methods * are non-static for pooling speed, retrieve a collision object from the {@link SingletonPool}. @@ -144,7 +142,7 @@ class Collision { final DistanceInput _input = new DistanceInput(); final SimplexCache _cache = new SimplexCache(); final DistanceOutput _output = new DistanceOutput(); - + /** * Determine if two generic shapes overlap. * @@ -179,9 +177,9 @@ class Collision { * @param manifold1 * @param manifold2 */ - static void getPointStates(final List state1, final List state2, - final Manifold manifold1, final Manifold manifold2) { - + static void getPointStates(final List state1, + final List state2, final Manifold manifold1, + final Manifold manifold2) { for (int i = 0; i < Settings.maxManifoldPoints; i++) { state1[i] = PointState.NULL_STATE; state2[i] = PointState.NULL_STATE; @@ -225,8 +223,9 @@ class Collision { * @param offset * @return */ - static int clipSegmentToLine(final List vOut, final List vIn, - final Vec2 normal, double offset, int vertexIndexA) { + static int clipSegmentToLine(final List vOut, + final List vIn, final Vec2 normal, double offset, + int vertexIndexA) { // Start with no _output points int numOut = 0; @@ -370,7 +369,6 @@ class Collision { final double tempy = cLocaly - vertex.y; s = normals[i].x * tempx + normals[i].y * tempy; - if (s > radius) { // early out return; @@ -531,7 +529,7 @@ class Collision { List n1s = poly1.m_normals; List v1s = poly1.m_vertices; List v2s = poly2.m_vertices; - + Transform.mulTransToOutUnsafe(xf2, xf1, _xf); final Rot xfq = _xf.q; @@ -551,7 +549,7 @@ class Collision { si = sij; } } - + if (si > maxSeparation) { maxSeparation = si; bestIndex = i; @@ -563,7 +561,8 @@ class Collision { } void findIncidentEdge(final List c, final PolygonShape poly1, - final Transform xf1, int edge1, final PolygonShape poly2, final Transform xf2) { + final Transform xf1, int edge1, final PolygonShape poly2, + final Transform xf2) { int count1 = poly1.m_count; final List normals1 = poly1.m_normals; @@ -571,7 +570,7 @@ class Collision { final List vertices2 = poly2.m_vertices; final List normals2 = poly2.m_normals; - assert (0 <= edge1 && edge1 < count1); + assert(0 <= edge1 && edge1 < count1); final ClipVertex c0 = c[0]; final ClipVertex c1 = c[1]; @@ -673,10 +672,10 @@ class Collision { return; } - PolygonShape poly1; // reference polygon - PolygonShape poly2; // incident polygon + PolygonShape poly1; // reference polygon + PolygonShape poly2; // incident polygon Transform xf1, xf2; - int edge1; // reference edge + int edge1; // reference edge bool flip; final double k_tol = 0.1 * Settings.linearSlop; @@ -728,7 +727,6 @@ class Collision { final double normalx = 1.0 * _tangent.y; final double normaly = -1.0 * _tangent.x; - Transform.mulToOutVec2(xf1, _v11, _v11); Transform.mulToOutVec2(xf1, _v12, _v12); // _v11 = Mul(xf1, _v11); @@ -741,8 +739,10 @@ class Collision { // Side offsets, extended by polytope skin thickness. // double sideOffset1 = -Vec2.dot(_tangent, _v11) + totalRadius; // double sideOffset2 = Vec2.dot(_tangent, _v12) + totalRadius; - double sideOffset1 = -(_tangent.x * _v11.x + _tangent.y * _v11.y) + totalRadius; - double sideOffset2 = _tangent.x * _v12.x + _tangent.y * _v12.y + totalRadius; + double sideOffset1 = + -(_tangent.x * _v11.x + _tangent.y * _v11.y) + totalRadius; + double sideOffset2 = + _tangent.x * _v12.x + _tangent.y * _v12.y + totalRadius; // Clip incident edge against extruded edge1 side edges. // ClipVertex _clipPoints1[2]; @@ -752,7 +752,8 @@ class Collision { // Clip to box side 1 // np = ClipSegmentToLine(_clipPoints1, _incidentEdge, -sideNormal, sideOffset1); _tangent.negateLocal(); - np = clipSegmentToLine(_clipPoints1, _incidentEdge, _tangent, sideOffset1, iv1); + np = clipSegmentToLine( + _clipPoints1, _incidentEdge, _tangent, sideOffset1, iv1); _tangent.negateLocal(); if (np < 2) { @@ -760,7 +761,8 @@ class Collision { } // Clip to negative box side 1 - np = clipSegmentToLine(_clipPoints2, _clipPoints1, _tangent, sideOffset2, iv2); + np = clipSegmentToLine( + _clipPoints2, _clipPoints1, _tangent, sideOffset2, iv2); if (np < 2) { return; @@ -773,7 +775,9 @@ class Collision { int pointCount = 0; for (int i = 0; i < Settings.maxManifoldPoints; ++i) { // double separation = Vec2.dot(normal, _clipPoints2[i].v) - frontOffset; - double separation = normalx * _clipPoints2[i].v.x + normaly * _clipPoints2[i].v.y - frontOffset; + double separation = normalx * _clipPoints2[i].v.x + + normaly * _clipPoints2[i].v.y - + frontOffset; if (separation <= totalRadius) { ManifoldPoint cp = manifold.points[pointCount]; @@ -803,11 +807,10 @@ class Collision { // Compute contact points for edge versus circle. // This accounts for edge connectivity. - void collideEdgeAndCircle(Manifold manifold, final EdgeShape edgeA, final Transform xfA, - final CircleShape circleB, final Transform xfB) { + void collideEdgeAndCircle(Manifold manifold, final EdgeShape edgeA, + final Transform xfA, final CircleShape circleB, final Transform xfB) { manifold.pointCount = 0; - // Compute circle in frame of edge // Vec2 Q = MulT(xfA, Mul(xfB, circleB.m_p)); Transform.mulToOutUnsafeVec2(xfB, circleB.m_p, _temp); @@ -898,7 +901,7 @@ class Collision { // Region AB double den = Vec2.dot(_e, _e); - assert (den > 0.0); + assert(den > 0.0); // Vec2 P = (1.0f / den) * (u * A + v * B); _P.set(A).mulLocal(u).addLocal(_temp.set(B).mulLocal(v)); @@ -929,8 +932,8 @@ class Collision { final EPCollider _collider = new EPCollider(); - void collideEdgeAndPolygon(Manifold manifold, final EdgeShape edgeA, final Transform xfA, - final PolygonShape polygonB, final Transform xfB) { + void collideEdgeAndPolygon(Manifold manifold, final EdgeShape edgeA, + final Transform xfA, final PolygonShape polygonB, final Transform xfB) { _collider.collide(manifold, edgeA, xfA, polygonB, xfB); } @@ -939,12 +942,9 @@ class Collision { */ } -enum VertexType { - ISOLATED, CONCAVE, CONVEX -} +enum VertexType { ISOLATED, CONCAVE, CONVEX } class EPCollider { - final TempPolygon m_polygonB = new TempPolygon(); final Transform m_xf = new Transform.zero(); @@ -958,7 +958,8 @@ class EPCollider { final Vec2 m_normal2 = new Vec2.zero(); final Vec2 m_normal = new Vec2.zero(); - VertexType m_type1 = VertexType.ISOLATED, m_type2 = VertexType.ISOLATED; + VertexType m_type1 = VertexType.ISOLATED, + m_type2 = VertexType.ISOLATED; final Vec2 m_lowerLimit = new Vec2.zero(); final Vec2 m_upperLimit = new Vec2.zero(); @@ -986,7 +987,6 @@ class EPCollider { void collide(Manifold manifold, final EdgeShape edgeA, final Transform xfA, final PolygonShape polygonB, final Transform xfB) { - Transform.mulTransToOutUnsafe(xfA, xfB, m_xf); Transform.mulToOutUnsafeVec2(m_xf, polygonB.m_centroid, m_centroidB); @@ -1002,8 +1002,10 @@ class EPCollider { _edge1.normalize(); m_normal1.setXY(_edge1.y, -_edge1.x); double offset1 = Vec2.dot(m_normal1, _temp.set(m_centroidB).subLocal(m_v1)); - double offset0 = 0.0, offset2 = 0.0; - bool convex1 = false, convex2 = false; + double offset0 = 0.0, + offset2 = 0.0; + bool convex1 = false, + convex2 = false; // Is there a preceding edge? if (hasVertex0) { @@ -1188,7 +1190,8 @@ class EPCollider { // Get polygonB in frameA m_polygonB.count = polygonB.m_count; for (int i = 0; i < polygonB.m_count; ++i) { - Transform.mulToOutUnsafeVec2(m_xf, polygonB.m_vertices[i], m_polygonB.vertices[i]); + Transform.mulToOutUnsafeVec2( + m_xf, polygonB.m_vertices[i], m_polygonB.vertices[i]); Rot.mulToOutUnsafe(m_xf.q, polygonB.m_normals[i], m_polygonB.normals[i]); } @@ -1208,7 +1211,8 @@ class EPCollider { } computePolygonSeparation(_polygonAxis); - if (_polygonAxis.type != EPAxisType.UNKNOWN && _polygonAxis.separation > m_radius) { + if (_polygonAxis.type != EPAxisType.UNKNOWN && + _polygonAxis.separation > m_radius) { return; } @@ -1219,7 +1223,8 @@ class EPCollider { EPAxis primaryAxis; if (_polygonAxis.type == EPAxisType.UNKNOWN) { primaryAxis = _edgeAxis; - } else if (_polygonAxis.separation > k_relativeTol * _edgeAxis.separation + k_absoluteTol) { + } else if (_polygonAxis.separation > + k_relativeTol * _edgeAxis.separation + k_absoluteTol) { primaryAxis = _polygonAxis; } else { primaryAxis = _edgeAxis; @@ -1301,14 +1306,16 @@ class EPCollider { int np; // Clip to box side 1 - np = Collision.clipSegmentToLine(_clipPoints1, _ie, _rf.sideNormal1, _rf.sideOffset1, _rf.i1); + np = Collision.clipSegmentToLine( + _clipPoints1, _ie, _rf.sideNormal1, _rf.sideOffset1, _rf.i1); if (np < Settings.maxManifoldPoints) { return; } // Clip to negative box side 1 - np = Collision.clipSegmentToLine(_clipPoints2, _clipPoints1, _rf.sideNormal2, _rf.sideOffset2, _rf.i2); + np = Collision.clipSegmentToLine( + _clipPoints2, _clipPoints1, _rf.sideNormal2, _rf.sideOffset2, _rf.i2); if (np < Settings.maxManifoldPoints) { return; @@ -1327,14 +1334,16 @@ class EPCollider { for (int i = 0; i < Settings.maxManifoldPoints; ++i) { double separation; - separation = Vec2.dot(_rf.normal, _temp.set(_clipPoints2[i].v).subLocal(_rf.v1)); + separation = + Vec2.dot(_rf.normal, _temp.set(_clipPoints2[i].v).subLocal(_rf.v1)); if (separation <= m_radius) { ManifoldPoint cp = manifold.points[pointCount]; if (primaryAxis.type == EPAxisType.EDGE_A) { // cp.localPoint = MulT(m_xf, _clipPoints2[i].v); - Transform.mulTransToOutUnsafeVec2(m_xf, _clipPoints2[i].v, cp.localPoint); + Transform.mulTransToOutUnsafeVec2( + m_xf, _clipPoints2[i].v, cp.localPoint); cp.id.set(_clipPoints2[i].id); } else { cp.localPoint.set(_clipPoints2[i].v); @@ -1351,7 +1360,6 @@ class EPCollider { manifold.pointCount = pointCount; } - void computeEdgeSeparation(EPAxis axis) { axis.type = EPAxisType.EDGE_A; axis.index = m_front ? 0 : 1; @@ -1407,11 +1415,13 @@ class EPCollider { // Adjacency if (_n.x * _perp.x + _n.y * _perp.y >= 0.0) { - if (Vec2.dot(_temp.set(_n).subLocal(m_upperLimit), m_normal) < -Settings.angularSlop) { + if (Vec2.dot(_temp.set(_n).subLocal(m_upperLimit), m_normal) < + -Settings.angularSlop) { continue; } } else { - if (Vec2.dot(_temp.set(_n).subLocal(m_lowerLimit), m_normal) < -Settings.angularSlop) { + if (Vec2.dot(_temp.set(_n).subLocal(m_lowerLimit), m_normal) < + -Settings.angularSlop) { continue; } } @@ -1424,4 +1434,3 @@ class EPCollider { } } } - diff --git a/lib/box2d/src/collision/contactid.dart b/lib/src/collision/contactid.dart similarity index 87% rename from lib/box2d/src/collision/contactid.dart rename to lib/src/collision/contactid.dart index 0e73fad..6c4a9b0 100644 --- a/lib/box2d/src/collision/contactid.dart +++ b/lib/src/collision/contactid.dart @@ -24,22 +24,29 @@ part of box2d; -enum ContactIDType { - VERTEX, FACE -} +enum ContactIDType { VERTEX, FACE } class ContactID implements Comparable { Int8List _data = new Int8List(4); - - void set indexA(v) { _data[0] = v; } - void set indexB(v) { _data[1] = v; } - void set typeA(v) { _data[2] = v; } - void set typeB(v) { _data[3] = v; ; } - - int get indexA => _data[0]; - int get indexB => _data[1]; - int get typeA => _data[2]; - int get typeB => _data[3]; + + void set indexA(v) { + _data[0] = v; + } + void set indexB(v) { + _data[1] = v; + } + void set typeA(v) { + _data[2] = v; + } + void set typeB(v) { + _data[3] = v; + ; + } + + int get indexA => _data[0]; + int get indexB => _data[1]; + int get typeA => _data[2]; + int get typeB => _data[3]; int getKey() { return (indexA << 24) | (indexB << 16) | (typeA << 8) | (typeB); diff --git a/lib/box2d/src/collision/distance.dart b/lib/src/collision/distance.dart similarity index 96% rename from lib/box2d/src/collision/distance.dart rename to lib/src/collision/distance.dart index ff64e5f..a99f82c 100644 --- a/lib/box2d/src/collision/distance.dart +++ b/lib/src/collision/distance.dart @@ -45,7 +45,6 @@ class _SimplexVertex { } } - class SimplexCache { /** length or area */ double metric = 0.0; @@ -84,10 +83,10 @@ class _Simplex { vertices[1] = m_v2; vertices[2] = m_v3; } - + void readCache(SimplexCache cache, DistanceProxy proxyA, Transform transformA, DistanceProxy proxyB, Transform transformB) { - assert (cache.count <= 3); + assert(cache.count <= 3); // Copy data from cache. m_count = cache.count; @@ -109,7 +108,9 @@ class _Simplex { if (m_count > 1) { double metric1 = cache.metric; double metric2 = getMetric(); - if (metric2 < 0.5 * metric1 || 2.0 * metric1 < metric2 || metric2 < Settings.EPSILON) { + if (metric2 < 0.5 * metric1 || + 2.0 * metric1 < metric2 || + metric2 < Settings.EPSILON) { // Reset the simplex. m_count = 0; } @@ -161,7 +162,7 @@ class _Simplex { } return; default: - assert (false); + assert(false); out.setZero(); return; } @@ -179,7 +180,7 @@ class _Simplex { void getClosestPoint(final Vec2 out) { switch (m_count) { case 0: - assert (false); + assert(false); out.setZero(); return; case 1: @@ -194,7 +195,7 @@ class _Simplex { out.setZero(); return; default: - assert (false); + assert(false); out.setZero(); return; } @@ -207,7 +208,7 @@ class _Simplex { void getWitnessPoints(Vec2 pA, Vec2 pB) { switch (m_count) { case 0: - assert (false); + assert(false); break; case 1: @@ -236,7 +237,7 @@ class _Simplex { break; default: - assert (false); + assert(false); break; } } @@ -245,7 +246,7 @@ class _Simplex { double getMetric() { switch (m_count) { case 0: - assert (false); + assert(false); return 0.0; case 1: @@ -261,7 +262,7 @@ class _Simplex { return Vec2.cross(_case3, _case33); default: - assert (false); + assert(false); return 0.0; } } @@ -440,7 +441,7 @@ class _Simplex { m_v3.a = d123_3 * inv_d123; m_count = 3; } -} // Class _Simplex +} // Class _Simplex class DistanceProxy { final List m_vertices; @@ -448,8 +449,8 @@ class DistanceProxy { double m_radius; final List m_buffer; - DistanceProxy() - : m_vertices = new List(Settings.maxPolygonVertices), + DistanceProxy() + : m_vertices = new List(Settings.maxPolygonVertices), m_buffer = new List(2) { for (int i = 0; i < m_vertices.length; i++) { m_vertices[i] = new Vec2.zero(); @@ -481,7 +482,7 @@ class DistanceProxy { break; case ShapeType.CHAIN: final ChainShape chain = shape; - assert (0 <= index && index < chain.m_count); + assert(0 <= index && index < chain.m_count); m_buffer[0] = chain.m_vertices[index]; if (index + 1 < chain.m_count) { @@ -503,7 +504,7 @@ class DistanceProxy { m_radius = edge.m_radius; break; default: - assert (false); + assert(false); } } @@ -563,10 +564,10 @@ class DistanceProxy { * @return */ Vec2 getVertex(int index) { - assert (0 <= index && index < m_count); + assert(0 <= index && index < m_count); return m_vertices[index]; } -} // Class _DistanceProxy. +} // Class _DistanceProxy. class Distance { static const int MAX_ITERS = 20; @@ -575,7 +576,6 @@ class Distance { static int GJK_ITERS = 0; static int GJK_MAX_ITERS = 20; - _Simplex _simplex = new _Simplex(); List _saveA = BufferUtils.allocClearIntList(3); List _saveB = BufferUtils.allocClearIntList(3); @@ -639,7 +639,7 @@ class Distance { _simplex.solve3(); break; default: - assert (false); + assert(false); } // If we have 3 points, then the origin is in the corresponding triangle. @@ -683,11 +683,13 @@ class Distance { Rot.mulTransUnsafeVec2(transformA.q, _d.negateLocal(), _temp); vertex.indexA = proxyA.getSupport(_temp); - Transform.mulToOutUnsafeVec2(transformA, proxyA.getVertex(vertex.indexA), vertex.wA); + Transform.mulToOutUnsafeVec2( + transformA, proxyA.getVertex(vertex.indexA), vertex.wA); // Vec2 wBLocal; Rot.mulTransUnsafeVec2(transformB.q, _d.negateLocal(), _temp); vertex.indexB = proxyB.getSupport(_temp); - Transform.mulToOutUnsafeVec2(transformB, proxyB.getVertex(vertex.indexB), vertex.wB); + Transform.mulToOutUnsafeVec2( + transformB, proxyB.getVertex(vertex.indexB), vertex.wB); vertex.w.set(vertex.wB).subLocal(vertex.wA); // Iteration count is equated to the number of support point calls. @@ -747,5 +749,4 @@ class Distance { } } } - } diff --git a/lib/box2d/src/collision/distance_input.dart b/lib/src/collision/distance_input.dart similarity index 100% rename from lib/box2d/src/collision/distance_input.dart rename to lib/src/collision/distance_input.dart diff --git a/lib/box2d/src/collision/distance_output.dart b/lib/src/collision/distance_output.dart similarity index 100% rename from lib/box2d/src/collision/distance_output.dart rename to lib/src/collision/distance_output.dart diff --git a/lib/box2d/src/collision/manifold.dart b/lib/src/collision/manifold.dart similarity index 89% rename from lib/box2d/src/collision/manifold.dart rename to lib/src/collision/manifold.dart index 6388af0..14a1ec4 100644 --- a/lib/box2d/src/collision/manifold.dart +++ b/lib/src/collision/manifold.dart @@ -47,9 +47,7 @@ part of box2d; * This structure is stored across time steps, so we keep it small. */ -enum ManifoldType { - CIRCLES, FACE_A, FACE_B -} +enum ManifoldType { CIRCLES, FACE_A, FACE_B } class Manifold { /** The points of contact. */ @@ -70,25 +68,25 @@ class Manifold { * creates a manifold with 0 points, with it's points array full of instantiated ManifoldPoints. */ Manifold() - : points = new List(Settings.maxManifoldPoints), - localNormal = new Vec2.zero(), - localPoint = new Vec2.zero() { + : points = new List(Settings.maxManifoldPoints), + localNormal = new Vec2.zero(), + localPoint = new Vec2.zero() { for (int i = 0; i < Settings.maxManifoldPoints; i++) { points[i] = new ManifoldPoint(); } } - + /** * Creates this manifold as a copy of the other * * @param other */ Manifold.copy(Manifold other) - : points = new List(Settings.maxManifoldPoints), - localNormal = other.localNormal.clone(), - localPoint = other.localPoint.clone(), - pointCount = other.pointCount { - type = other.type; + : points = new List(Settings.maxManifoldPoints), + localNormal = other.localNormal.clone(), + localPoint = other.localPoint.clone(), + pointCount = other.pointCount { + type = other.type; // djm: this is correct now for (int i = 0; i < Settings.maxManifoldPoints; i++) { points[i] = new ManifoldPoint.copy(other.points[i]); diff --git a/lib/box2d/src/collision/manifold_point.dart b/lib/src/collision/manifold_point.dart similarity index 100% rename from lib/box2d/src/collision/manifold_point.dart rename to lib/src/collision/manifold_point.dart diff --git a/lib/box2d/src/collision/raycast_input.dart b/lib/src/collision/raycast_input.dart similarity index 93% rename from lib/box2d/src/collision/raycast_input.dart rename to lib/src/collision/raycast_input.dart index 8512205..c00638d 100644 --- a/lib/box2d/src/collision/raycast_input.dart +++ b/lib/src/collision/raycast_input.dart @@ -24,15 +24,15 @@ part of box2d; - /** * Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1). */ -class RayCastInput{ - final Vec2 p1 = new Vec2.zero(), p2 = new Vec2.zero(); +class RayCastInput { + final Vec2 p1 = new Vec2.zero(), + p2 = new Vec2.zero(); double maxFraction = 0.0; - void set(final RayCastInput rci){ + void set(final RayCastInput rci) { p1.set(rci.p1); p2.set(rci.p2); maxFraction = rci.maxFraction; diff --git a/lib/box2d/src/collision/raycast_output.dart b/lib/src/collision/raycast_output.dart similarity index 96% rename from lib/box2d/src/collision/raycast_output.dart rename to lib/src/collision/raycast_output.dart index 2aa598c..e97fded 100644 --- a/lib/box2d/src/collision/raycast_output.dart +++ b/lib/src/collision/raycast_output.dart @@ -28,13 +28,12 @@ part of box2d; * Ray-cast output data. The ray hits at p1 + fraction * (p2 - p1), where p1 and p2 * come from b2RayCastInput. */ -class RayCastOutput{ +class RayCastOutput { final Vec2 normal = new Vec2.zero(); double fraction = 0.0; - void set(final RayCastOutput rco){ + void set(final RayCastOutput rco) { normal.set(rco.normal); fraction = rco.fraction; } } - diff --git a/lib/box2d/src/collision/shapes/chain_shape.dart b/lib/src/collision/shapes/chain_shape.dart similarity index 95% rename from lib/box2d/src/collision/shapes/chain_shape.dart rename to lib/src/collision/shapes/chain_shape.dart index 03bc0c9..2b157c4 100644 --- a/lib/box2d/src/collision/shapes/chain_shape.dart +++ b/lib/src/collision/shapes/chain_shape.dart @@ -32,7 +32,6 @@ part of box2d; */ class ChainShape extends Shape { - List m_vertices; int m_count = 0; final Vec2 m_prevVertex = new Vec2.zero(), @@ -92,7 +91,8 @@ class ChainShape extends Shape { } } - double computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut) { + double computeDistanceToOut( + Transform xf, Vec2 p, int childIndex, Vec2 normalOut) { final EdgeShape edge = _pool0; getChildEdge(edge, childIndex); return edge.computeDistanceToOut(xf, p, 0, normalOut); @@ -102,7 +102,8 @@ class ChainShape extends Shape { return false; } - bool raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex) { + bool raycast( + RayCastOutput output, RayCastInput input, Transform xf, int childIndex) { assert(childIndex < m_count); final EdgeShape edgeShape = _pool0; @@ -179,7 +180,8 @@ class ChainShape extends Shape { Vec2 v1 = vertices[i - 1]; Vec2 v2 = vertices[i]; // If the code crashes here, it means your vertices are too close together. - if (MathUtils.distanceSquared(v1, v2) < Settings.linearSlop * Settings.linearSlop) { + if (MathUtils.distanceSquared(v1, v2) < + Settings.linearSlop * Settings.linearSlop) { throw "Vertices of chain shape are too close together"; } } @@ -208,7 +210,8 @@ class ChainShape extends Shape { Vec2 v1 = vertices[i - 1]; Vec2 v2 = vertices[i]; // If the code crashes here, it means your vertices are too close together. - if (MathUtils.distanceSquared(v1, v2) < Settings.linearSlop * Settings.linearSlop) { + if (MathUtils.distanceSquared(v1, v2) < + Settings.linearSlop * Settings.linearSlop) { throw "Vertices of chain shape are too close together"; } } diff --git a/lib/box2d/src/collision/shapes/circle_shape.dart b/lib/src/collision/shapes/circle_shape.dart similarity index 95% rename from lib/box2d/src/collision/shapes/circle_shape.dart rename to lib/src/collision/shapes/circle_shape.dart index 03b2eee..3feab50 100644 --- a/lib/box2d/src/collision/shapes/circle_shape.dart +++ b/lib/src/collision/shapes/circle_shape.dart @@ -28,11 +28,9 @@ part of box2d; * A circle shape. */ class CircleShape extends Shape { - final Vec2 m_p = new Vec2.zero(); - CircleShape() - : super(ShapeType.CIRCLE) { + CircleShape() : super(ShapeType.CIRCLE) { m_radius = 0.0; } @@ -94,7 +92,8 @@ class CircleShape extends Shape { return centerx * centerx + centery * centery <= m_radius * m_radius; } - double computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut) { + double computeDistanceToOut( + Transform xf, Vec2 p, int childIndex, Vec2 normalOut) { final Rot xfq = xf.q; double centerx = xfq.c * m_p.x - xfq.s * m_p.y + xf.p.x; double centery = xfq.s * m_p.x + xfq.c * m_p.y + xf.p.y; @@ -110,7 +109,8 @@ class CircleShape extends Shape { // From Section 3.1.2 // x = s + a * r // norm(x) = radius - bool raycast(RayCastOutput output, RayCastInput input, Transform transform, int childIndex) { + bool raycast(RayCastOutput output, RayCastInput input, Transform transform, + int childIndex) { final Vec2 inputp1 = input.p1; final Vec2 inputp2 = input.p2; final Rot tq = transform.q; @@ -175,6 +175,7 @@ class CircleShape extends Shape { // inertia about the local origin // massData.I = massData.mass * (0.5f * m_radius * m_radius + Vec2.dot(m_p, m_p)); - massData.I = massData.mass * (0.5 * m_radius * m_radius + (m_p.x * m_p.x + m_p.y * m_p.y)); + massData.I = massData.mass * + (0.5 * m_radius * m_radius + (m_p.x * m_p.x + m_p.y * m_p.y)); } } diff --git a/lib/box2d/src/collision/shapes/edge_shape.dart b/lib/src/collision/shapes/edge_shape.dart similarity index 96% rename from lib/box2d/src/collision/shapes/edge_shape.dart rename to lib/src/collision/shapes/edge_shape.dart index 0caf081..dc113f8 100644 --- a/lib/box2d/src/collision/shapes/edge_shape.dart +++ b/lib/src/collision/shapes/edge_shape.dart @@ -35,7 +35,7 @@ class EdgeShape extends Shape { /** * edge vertex 1 */ - final Vec2 m_vertex1 = new Vec2.zero(); + final Vec2 m_vertex1 = new Vec2.zero(); /** * edge vertex 2 */ @@ -49,8 +49,8 @@ class EdgeShape extends Shape { * optional adjacent vertex 2. Used for smooth collision */ final Vec2 m_vertex3 = new Vec2.zero(); - bool m_hasVertex0 = false, m_hasVertex3 = false; - + bool m_hasVertex0 = false, + m_hasVertex3 = false; EdgeShape() : super(ShapeType.EDGE) { m_radius = Settings.polygonRadius; @@ -73,7 +73,8 @@ class EdgeShape extends Shape { // for pooling final Vec2 normal = new Vec2.zero(); - double computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut) { + double computeDistanceToOut( + Transform xf, Vec2 p, int childIndex, Vec2 normalOut) { double xfqc = xf.q.c; double xfqs = xf.q.s; double xfpx = xf.p.x; @@ -114,8 +115,8 @@ class EdgeShape extends Shape { // v = v1 + s * e // p1 + t * d = v1 + s * e // s * e - t * d = p1 - v1 - bool raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex) { - + bool raycast( + RayCastOutput output, RayCastInput input, Transform xf, int childIndex) { double tempx, tempy; final Vec2 v1 = m_vertex1; final Vec2 v2 = m_vertex2; diff --git a/lib/box2d/src/collision/shapes/mass_data.dart b/lib/src/collision/shapes/mass_data.dart similarity index 100% rename from lib/box2d/src/collision/shapes/mass_data.dart rename to lib/src/collision/shapes/mass_data.dart diff --git a/lib/box2d/src/collision/shapes/polygon_shape.dart b/lib/src/collision/shapes/polygon_shape.dart similarity index 94% rename from lib/box2d/src/collision/shapes/polygon_shape.dart rename to lib/src/collision/shapes/polygon_shape.dart index d90fa06..6092fff 100644 --- a/lib/box2d/src/collision/shapes/polygon_shape.dart +++ b/lib/src/collision/shapes/polygon_shape.dart @@ -61,8 +61,7 @@ class PolygonShape extends Shape { final Vec2 _pool4 = new Vec2.zero(); Transform _poolt1 = new Transform.zero(); - PolygonShape() - : super(ShapeType.POLYGON) { + PolygonShape() : super(ShapeType.POLYGON) { for (int i = 0; i < m_vertices.length; i++) { m_vertices[i] = new Vec2.zero(); } @@ -103,7 +102,8 @@ class PolygonShape extends Shape { * @warning the points may be re-ordered, even if they form a convex polygon. * @warning collinear points are removed. */ - void setWithPools(final List verts, final int num, final Vec2Array vecPool, final IntArray intPool) { + void setWithPools(final List verts, final int num, + final Vec2Array vecPool, final IntArray intPool) { assert(3 <= num && num <= Settings.maxPolygonVertices); if (num < 3) { setAsBoxXY(1.0, 1.0); @@ -113,7 +113,9 @@ class PolygonShape extends Shape { int n = Math.min(num, Settings.maxPolygonVertices); // Perform welding and copy vertices into local buffer. - List ps = (vecPool != null) ? vecPool.get(Settings.maxPolygonVertices) : new List(Settings.maxPolygonVertices); + List ps = (vecPool != null) + ? vecPool.get(Settings.maxPolygonVertices) + : new List(Settings.maxPolygonVertices); int tempCount = 0; for (int i = 0; i < n; ++i) { Vec2 v = verts[i]; @@ -152,7 +154,9 @@ class PolygonShape extends Shape { } } - List hull = (intPool != null) ? intPool.get(Settings.maxPolygonVertices) : BufferUtils.allocClearIntList(Settings.maxPolygonVertices); + List hull = (intPool != null) + ? intPool.get(Settings.maxPolygonVertices) + : BufferUtils.allocClearIntList(Settings.maxPolygonVertices); int m = 0; int ih = i0; @@ -241,7 +245,8 @@ class PolygonShape extends Shape { * @param center the center of the box in local coordinates. * @param angle the rotation of the box in local coordinates. */ - void setAsBox(final double hx, final double hy, final Vec2 center, final double angle) { + void setAsBox( + final double hx, final double hy, final Vec2 center, final double angle) { m_count = 4; m_vertices[0].setXY(-hx, -hy); m_vertices[1].setXY(hx, -hy); @@ -350,7 +355,8 @@ class PolygonShape extends Shape { return m_vertices[index]; } - double computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut) { + double computeDistanceToOut( + Transform xf, Vec2 p, int childIndex, Vec2 normalOut) { double xfqc = xf.q.c; double xfqs = xf.q.s; double tx = p.x - xf.p.x; @@ -384,7 +390,8 @@ class PolygonShape extends Shape { Vec2 vertex = m_vertices[i]; double distanceVecX = pLocalx - vertex.x; double distanceVecY = pLocaly - vertex.y; - double distance2 = (distanceVecX * distanceVecX + distanceVecY * distanceVecY); + double distance2 = + (distanceVecX * distanceVecX + distanceVecY * distanceVecY); if (minDistance2 > distance2) { minDistanceX = distanceVecX; minDistanceY = distanceVecY; @@ -404,7 +411,8 @@ class PolygonShape extends Shape { return distance; } - bool raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex) { + bool raycast( + RayCastOutput output, RayCastInput input, Transform xf, int childIndex) { final double xfqc = xf.q.c; final double xfqs = xf.q.s; final Vec2 xfp = xf.p; @@ -481,7 +489,8 @@ class PolygonShape extends Shape { return false; } - void computeCentroidToOut(final List vs, final int count, final Vec2 out) { + void computeCentroidToOut( + final List vs, final int count, final Vec2 out) { assert(count >= 3); out.setXY(0.0, 0.0); @@ -571,7 +580,10 @@ class PolygonShape extends Shape { for (int i = 0; i < m_count; ++i) { // Triangle vertices. e1.set(m_vertices[i]).subLocal(s); - e2.set(s).negateLocal().addLocal(i + 1 < m_count ? m_vertices[i + 1] : m_vertices[0]); + e2 + .set(s) + .negateLocal() + .addLocal(i + 1 < m_count ? m_vertices[i + 1] : m_vertices[0]); final double D = Vec2.cross(e1, e2); diff --git a/lib/box2d/src/collision/shapes/shape.dart b/lib/src/collision/shapes/shape.dart similarity index 97% rename from lib/box2d/src/collision/shapes/shape.dart rename to lib/src/collision/shapes/shape.dart index 9a925c7..805529d 100644 --- a/lib/box2d/src/collision/shapes/shape.dart +++ b/lib/src/collision/shapes/shape.dart @@ -30,7 +30,6 @@ part of box2d; * one or more child shapes. */ abstract class Shape { - final ShapeType m_type; double m_radius = 0.0; @@ -86,7 +85,7 @@ abstract class Shape { * @return if hit */ bool raycast(RayCastOutput output, RayCastInput input, Transform transform, - int childIndex); + int childIndex); /** * Given a transform, compute the associated axis aligned bounding box for a child shape. @@ -114,7 +113,8 @@ abstract class Shape { * @param normalOut returns the direction in which the distance increases. * @return distance returns the distance from the current shape. */ - double computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut); + double computeDistanceToOut( + Transform xf, Vec2 p, int childIndex, Vec2 normalOut); Shape clone(); } diff --git a/lib/box2d/src/collision/shapes/shape_type.dart b/lib/src/collision/shapes/shape_type.dart similarity index 54% rename from lib/box2d/src/collision/shapes/shape_type.dart rename to lib/src/collision/shapes/shape_type.dart index 6b1c808..ff73a5f 100644 --- a/lib/box2d/src/collision/shapes/shape_type.dart +++ b/lib/src/collision/shapes/shape_type.dart @@ -4,6 +4,4 @@ part of box2d; * Types of shapes * @author Daniel */ -enum ShapeType { - CIRCLE, EDGE, POLYGON, CHAIN -} +enum ShapeType { CIRCLE, EDGE, POLYGON, CHAIN } diff --git a/lib/box2d/src/collision/time_of_impact.dart b/lib/src/collision/time_of_impact.dart similarity index 96% rename from lib/box2d/src/collision/time_of_impact.dart rename to lib/src/collision/time_of_impact.dart index 24a7138..c7bc95d 100644 --- a/lib/box2d/src/collision/time_of_impact.dart +++ b/lib/src/collision/time_of_impact.dart @@ -40,9 +40,7 @@ class TOIInput { double tMax = 0.0; } -enum TOIOutputState { - UNKNOWN, FAILED, OVERLAPPED, TOUCHING, SEPARATED -} +enum TOIOutputState { UNKNOWN, FAILED, OVERLAPPED, TOUCHING, SEPARATED } /** * Output parameters for TimeOfImpact @@ -54,7 +52,6 @@ class TOIOutput { double t = 0.0; } - /** * Class used for computing the time of impact. This class should not be constructed usually, just * retrieve from the {@link SingletonPool#getTOI()}. @@ -69,7 +66,7 @@ class TimeOfImpact { static int toiMaxIters = 0; static int toiRootIters = 0; static int toiMaxRootIters = 0; - + // djm pooling final SimplexCache _cache = new SimplexCache(); final DistanceInput _distanceInput = new DistanceInput(); @@ -83,8 +80,8 @@ class TimeOfImpact { final IWorldPool _pool; - TimeOfImpact(this._pool) ; - + TimeOfImpact(this._pool); + /** * Compute the upper bound on time before two shapes penetrate. Time is represented as a fraction * between [0,tMax]. This uses a swept separating axis and may miss some intermediate, @@ -118,10 +115,11 @@ class TimeOfImpact { double totalRadius = proxyA.m_radius + proxyB.m_radius; // djm: whats with all these constants? - double target = Math.max(Settings.linearSlop, totalRadius - 3.0 * Settings.linearSlop); + double target = + Math.max(Settings.linearSlop, totalRadius - 3.0 * Settings.linearSlop); double tolerance = 0.25 * Settings.linearSlop; - assert (target > tolerance); + assert(target > tolerance); double t1 = 0.0; int iter = 0; @@ -218,7 +216,8 @@ class TimeOfImpact { // Compute 1D root of: f(x) - target = 0 int rootIterCount = 0; - double a1 = t1, a2 = t2; + double a1 = t1, + a2 = t2; for (;;) { // Use a mix of the secant rule and bisection. double t; @@ -285,15 +284,11 @@ class TimeOfImpact { // System.out.printf("final sweeps: %f, %f, %f; %f, %f, %f", input.s) toiMaxIters = Math.max(toiMaxIters, iter); } - -} // Class TimeOfImpact. +} // Class TimeOfImpact. -enum SeparationFunctionType { - POINTS, FACE_A, FACE_B -} +enum SeparationFunctionType { POINTS, FACE_A, FACE_B } class SeparationFunction { - DistanceProxy m_proxyA; DistanceProxy m_proxyB; SeparationFunctionType m_type; @@ -315,15 +310,16 @@ class SeparationFunction { final Vec2 _temp = new Vec2.zero(); final Transform _xfa = new Transform.zero(); final Transform _xfb = new Transform.zero(); - + // TODO_ERIN might not need to return the separation - double initialize(final SimplexCache cache, final DistanceProxy proxyA, final Sweep sweepA, - final DistanceProxy proxyB, final Sweep sweepB, double t1) { + double initialize(final SimplexCache cache, final DistanceProxy proxyA, + final Sweep sweepA, final DistanceProxy proxyB, final Sweep sweepB, + double t1) { m_proxyA = proxyA; m_proxyB = proxyB; int count = cache.count; - assert (0 < count && count < 3); + assert(0 < count && count < 3); m_sweepA = sweepA; m_sweepB = sweepB; @@ -409,7 +405,6 @@ class SeparationFunction { // double FindMinSeparation(int* indexA, int* indexB, double t) const double findMinSeparation(List indexes, double t) { - m_sweepA.getTransform(_xfa, t); m_sweepB.getTransform(_xfb, t); @@ -464,7 +459,7 @@ class SeparationFunction { return separation; default: - assert (false); + assert(false); indexes[0] = -1; indexes[1] = -1; return 0.0; @@ -489,7 +484,7 @@ class SeparationFunction { double separation = Vec2.dot(_pointB.subLocal(_pointA), m_axis); return separation; - + case SeparationFunctionType.FACE_A: Rot.mulToOutUnsafe(_xfa.q, m_axis, _normal); Transform.mulToOutUnsafeVec2(_xfa, m_localPoint, _pointA); @@ -516,7 +511,7 @@ class SeparationFunction { return separation; default: - assert (false); + assert(false); return 0.0; } } diff --git a/lib/box2d/src/collision/world_manifold.dart b/lib/src/collision/world_manifold.dart similarity index 60% rename from lib/box2d/src/collision/world_manifold.dart rename to lib/src/collision/world_manifold.dart index f360345..751e26b 100644 --- a/lib/box2d/src/collision/world_manifold.dart +++ b/lib/src/collision/world_manifold.dart @@ -61,76 +61,79 @@ class WorldManifold { } switch (manifold.type) { - case ManifoldType.CIRCLES: { - final Vec2 pointA = _pool3; - final Vec2 pointB = _pool4; - - normal.x = 1.0; - normal.y = 0.0; - Vec2 v = manifold.localPoint; - // Transform.mulToOutUnsafe(xfA, manifold.localPoint, pointA); - // Transform.mulToOutUnsafe(xfB, manifold.points[0].localPoint, pointB); - pointA.x = (xfA.q.c * v.x - xfA.q.s * v.y) + xfA.p.x; - pointA.y = (xfA.q.s * v.x + xfA.q.c * v.y) + xfA.p.y; - Vec2 mp0p = manifold.points[0].localPoint; - pointB.x = (xfB.q.c * mp0p.x - xfB.q.s * mp0p.y) + xfB.p.x; - pointB.y = (xfB.q.s * mp0p.x + xfB.q.c * mp0p.y) + xfB.p.y; - - if (MathUtils.distanceSquared(pointA, pointB) > Settings.EPSILON * Settings.EPSILON) { - normal.x = pointB.x - pointA.x; - normal.y = pointB.y - pointA.y; - normal.normalize(); + case ManifoldType.CIRCLES: + { + final Vec2 pointA = _pool3; + final Vec2 pointB = _pool4; + + normal.x = 1.0; + normal.y = 0.0; + Vec2 v = manifold.localPoint; + // Transform.mulToOutUnsafe(xfA, manifold.localPoint, pointA); + // Transform.mulToOutUnsafe(xfB, manifold.points[0].localPoint, pointB); + pointA.x = (xfA.q.c * v.x - xfA.q.s * v.y) + xfA.p.x; + pointA.y = (xfA.q.s * v.x + xfA.q.c * v.y) + xfA.p.y; + Vec2 mp0p = manifold.points[0].localPoint; + pointB.x = (xfB.q.c * mp0p.x - xfB.q.s * mp0p.y) + xfB.p.x; + pointB.y = (xfB.q.s * mp0p.x + xfB.q.c * mp0p.y) + xfB.p.y; + + if (MathUtils.distanceSquared(pointA, pointB) > + Settings.EPSILON * Settings.EPSILON) { + normal.x = pointB.x - pointA.x; + normal.y = pointB.y - pointA.y; + normal.normalize(); + } + + final double cAx = normal.x * radiusA + pointA.x; + final double cAy = normal.y * radiusA + pointA.y; + + final double cBx = -normal.x * radiusB + pointB.x; + final double cBy = -normal.y * radiusB + pointB.y; + + points[0].x = (cAx + cBx) * .5; + points[0].y = (cAy + cBy) * .5; + separations[0] = (cBx - cAx) * normal.x + (cBy - cAy) * normal.y; } - - final double cAx = normal.x * radiusA + pointA.x; - final double cAy = normal.y * radiusA + pointA.y; - - final double cBx = -normal.x * radiusB + pointB.x; - final double cBy = -normal.y * radiusB + pointB.y; - - points[0].x = (cAx + cBx) * .5; - points[0].y = (cAy + cBy) * .5; - separations[0] = (cBx - cAx) * normal.x + (cBy - cAy) * normal.y; - } break; - case ManifoldType.FACE_A: { - final Vec2 planePoint = _pool3; - - Rot.mulToOutUnsafe(xfA.q, manifold.localNormal, normal); - Transform.mulToOutVec2(xfA, manifold.localPoint, planePoint); - - final Vec2 clipPoint = _pool4; - - for (int i = 0; i < manifold.pointCount; i++) { - // b2Vec2 clipPoint = b2Mul(xfB, manifold->points[i].localPoint); - // b2Vec2 cA = clipPoint + (radiusA - b2Dot(clipPoint - planePoint, - // normal)) * normal; - // b2Vec2 cB = clipPoint - radiusB * normal; - // points[i] = 0.5f * (cA + cB); - Transform.mulToOutVec2(xfB, manifold.points[i].localPoint, clipPoint); - // use cA as temporary for now - // cA.set(clipPoint).subLocal(planePoint); - // double scalar = radiusA - Vec2.dot(cA, normal); - // cA.set(normal).mulLocal(scalar).addLocal(clipPoint); - // cB.set(normal).mulLocal(radiusB).subLocal(clipPoint).negateLocal(); - // points[i].set(cA).addLocal(cB).mulLocal(0.5f); - - final double scalar = - radiusA - - ((clipPoint.x - planePoint.x) * normal.x + (clipPoint.y - planePoint.y) - * normal.y); - - final double cAx = normal.x * scalar + clipPoint.x; - final double cAy = normal.y * scalar + clipPoint.y; - - final double cBx = -normal.x * radiusB + clipPoint.x; - final double cBy = -normal.y * radiusB + clipPoint.y; - - points[i].x = (cAx + cBx) * .5; - points[i].y = (cAy + cBy) * .5; - separations[i] = (cBx - cAx) * normal.x + (cBy - cAy) * normal.y; + case ManifoldType.FACE_A: + { + final Vec2 planePoint = _pool3; + + Rot.mulToOutUnsafe(xfA.q, manifold.localNormal, normal); + Transform.mulToOutVec2(xfA, manifold.localPoint, planePoint); + + final Vec2 clipPoint = _pool4; + + for (int i = 0; i < manifold.pointCount; i++) { + // b2Vec2 clipPoint = b2Mul(xfB, manifold->points[i].localPoint); + // b2Vec2 cA = clipPoint + (radiusA - b2Dot(clipPoint - planePoint, + // normal)) * normal; + // b2Vec2 cB = clipPoint - radiusB * normal; + // points[i] = 0.5f * (cA + cB); + Transform.mulToOutVec2( + xfB, manifold.points[i].localPoint, clipPoint); + // use cA as temporary for now + // cA.set(clipPoint).subLocal(planePoint); + // double scalar = radiusA - Vec2.dot(cA, normal); + // cA.set(normal).mulLocal(scalar).addLocal(clipPoint); + // cB.set(normal).mulLocal(radiusB).subLocal(clipPoint).negateLocal(); + // points[i].set(cA).addLocal(cB).mulLocal(0.5f); + + final double scalar = radiusA - + ((clipPoint.x - planePoint.x) * normal.x + + (clipPoint.y - planePoint.y) * normal.y); + + final double cAx = normal.x * scalar + clipPoint.x; + final double cAy = normal.y * scalar + clipPoint.y; + + final double cBx = -normal.x * radiusB + clipPoint.x; + final double cBy = -normal.y * radiusB + clipPoint.y; + + points[i].x = (cAx + cBx) * .5; + points[i].y = (cAy + cBy) * .5; + separations[i] = (cBx - cAx) * normal.x + (cBy - cAy) * normal.y; + } } - } break; case ManifoldType.FACE_B: final Vec2 planePoint = _pool3; @@ -168,10 +171,9 @@ class WorldManifold { // clipPoint.y = xfA.p.y + xfA.q.ex.y * manifold.points[i].localPoint.x + xfA.q.ey.y * // manifold.points[i].localPoint.y; - final double scalar = - radiusB - - ((clipPoint.x - planePoint.x) * normal.x + (clipPoint.y - planePoint.y) - * normal.y); + final double scalar = radiusB - + ((clipPoint.x - planePoint.x) * normal.x + + (clipPoint.y - planePoint.y) * normal.y); final double cBx = normal.x * scalar + clipPoint.x; final double cBy = normal.y * scalar + clipPoint.y; diff --git a/lib/box2d/src/common/buffer_utils.dart b/lib/src/common/buffer_utils.dart similarity index 86% rename from lib/box2d/src/common/buffer_utils.dart rename to lib/src/common/buffer_utils.dart index 5541162..aeca12d 100644 --- a/lib/box2d/src/common/buffer_utils.dart +++ b/lib/src/common/buffer_utils.dart @@ -27,7 +27,8 @@ part of box2d; class BufferUtils { /** Reallocate a buffer. */ - static List reallocateBufferWithAlloc(List oldBuffer, int oldCapacity, int newCapacity, alloc) { + static List reallocateBufferWithAlloc( + List oldBuffer, int oldCapacity, int newCapacity, alloc) { assert(newCapacity > oldCapacity); List newBuffer = new List(newCapacity); if (oldBuffer != null) { @@ -44,7 +45,8 @@ class BufferUtils { } /** Reallocate a buffer. */ - static List reallocateBufferInt(List oldBuffer, int oldCapacity, int newCapacity) { + static List reallocateBufferInt( + List oldBuffer, int oldCapacity, int newCapacity) { assert(newCapacity > oldCapacity); List newBuffer = new List(newCapacity); if (oldBuffer != null) { @@ -57,7 +59,8 @@ class BufferUtils { } /** Reallocate a buffer. */ - static Float64List reallocateBuffer(Float64List oldBuffer, int oldCapacity, int newCapacity) { + static Float64List reallocateBuffer( + Float64List oldBuffer, int oldCapacity, int newCapacity) { assert(newCapacity > oldCapacity); Float64List newBuffer = new Float64List(newCapacity); if (oldBuffer != null) { @@ -70,11 +73,14 @@ class BufferUtils { * Reallocate a buffer. A 'deferred' buffer is reallocated only if it is not NULL. If * 'userSuppliedCapacity' is not zero, buffer is user supplied and must be kept. */ - static List reallocateBufferWithAllocDeferred(List buffer, int userSuppliedCapacity, int oldCapacity, int newCapacity, bool deferred, alloc) { + static List reallocateBufferWithAllocDeferred(List buffer, + int userSuppliedCapacity, int oldCapacity, int newCapacity, bool deferred, + alloc) { assert(newCapacity > oldCapacity); assert(userSuppliedCapacity == 0 || newCapacity <= userSuppliedCapacity); if ((!deferred || buffer != null) && userSuppliedCapacity == 0) { - buffer = reallocateBufferWithAlloc(buffer, oldCapacity, newCapacity, alloc); + buffer = + reallocateBufferWithAlloc(buffer, oldCapacity, newCapacity, alloc); } return buffer; } @@ -83,7 +89,9 @@ class BufferUtils { * Reallocate an int buffer. A 'deferred' buffer is reallocated only if it is not NULL. If * 'userSuppliedCapacity' is not zero, buffer is user supplied and must be kept. */ - static List reallocateBufferIntDeferred(List buffer, int userSuppliedCapacity, int oldCapacity, int newCapacity, bool deferred) { + static List reallocateBufferIntDeferred(List buffer, + int userSuppliedCapacity, int oldCapacity, int newCapacity, + bool deferred) { assert(newCapacity > oldCapacity); assert(userSuppliedCapacity == 0 || newCapacity <= userSuppliedCapacity); if ((!deferred || buffer != null) && userSuppliedCapacity == 0) { @@ -96,7 +104,9 @@ class BufferUtils { * Reallocate a float buffer. A 'deferred' buffer is reallocated only if it is not NULL. If * 'userSuppliedCapacity' is not zero, buffer is user supplied and must be kept. */ - static Float64List reallocateBufferFloat64Deferred(Float64List buffer, int userSuppliedCapacity, int oldCapacity, int newCapacity, bool deferred) { + static Float64List reallocateBufferFloat64Deferred(Float64List buffer, + int userSuppliedCapacity, int oldCapacity, int newCapacity, + bool deferred) { assert(newCapacity > oldCapacity); assert(userSuppliedCapacity == 0 || newCapacity <= userSuppliedCapacity); if ((!deferred || buffer != null) && userSuppliedCapacity == 0) { @@ -130,5 +140,4 @@ class BufferUtils { } return res; } - } diff --git a/lib/box2d/src/common/color3f.dart b/lib/src/common/color3f.dart similarity index 99% rename from lib/box2d/src/common/color3f.dart rename to lib/src/common/color3f.dart index 38d8d9e..1334fca 100644 --- a/lib/box2d/src/common/color3f.dart +++ b/lib/src/common/color3f.dart @@ -25,7 +25,6 @@ part of box2d; class Color3f { - static final Color3f WHITE = new Color3f(1.0, 1.0, 1.0); static final Color3f BLACK = new Color3f(0.0, 0.0, 0.0); static final Color3f BLUE = new Color3f(0.0, 0.0, 1.0); diff --git a/lib/box2d/src/common/iviewporttransform.dart b/lib/src/common/iviewporttransform.dart similarity index 99% rename from lib/box2d/src/common/iviewporttransform.dart rename to lib/src/common/iviewporttransform.dart index 3112ce5..bfbe17c 100644 --- a/lib/box2d/src/common/iviewporttransform.dart +++ b/lib/src/common/iviewporttransform.dart @@ -82,14 +82,12 @@ abstract class IViewportTransform { */ void getWorldVectorToScreen(Vec2 world, Vec2 screen); - /** * Transforms the given directional screen vector back to the world direction. */ void getScreenVectorToWorld(Vec2 screen, Vec2 world); - - Mat22 getMat22Representation(); + Mat22 getMat22Representation(); /** * takes the world coordinate (world) puts the corresponding screen coordinate in screen. It @@ -97,7 +95,6 @@ abstract class IViewportTransform { */ void getWorldToScreen(Vec2 world, Vec2 screen); - /** * takes the screen coordinates (screen) and puts the corresponding world coordinates in world. It * should be safe to give the same object as both parameters. diff --git a/lib/box2d/src/common/mat22.dart b/lib/src/common/mat22.dart similarity index 97% rename from lib/box2d/src/common/mat22.dart rename to lib/src/common/mat22.dart index d52d58f..4c77443 100644 --- a/lib/box2d/src/common/mat22.dart +++ b/lib/src/common/mat22.dart @@ -64,7 +64,8 @@ class Mat22 { * @param exy * @param col2y */ - Mat22.withCoords(final double exx, final double col2x, final double exy, final double col2y) + Mat22.withCoords(final double exx, final double col2x, final double exy, + final double col2y) : ex = new Vec2(exx, exy), ey = new Vec2(col2x, col2y); @@ -81,7 +82,8 @@ class Mat22 { return this; } - Mat22 setCoords(final double exx, final double col2x, final double exy, final double col2y) { + Mat22 setCoords(final double exx, final double col2x, final double exy, + final double col2y) { ex.x = exx; ex.y = exy; ey.x = col2x; @@ -200,8 +202,6 @@ class Mat22 { out.ey.y = det * a; } - - /** * Return the matrix composed of the absolute values of all elements. djm: fixed double allocation * @@ -419,7 +419,8 @@ class Mat22 { if (det != 0.0) { det = 1.0 / det; } - final Vec2 x = new Vec2(det * (a22 * b.x - a12 * b.y), det * (a11 * b.y - a21 * b.x)); + final Vec2 x = + new Vec2(det * (a22 * b.x - a12 * b.y), det * (a11 * b.y - a21 * b.x)); return x; } @@ -485,7 +486,8 @@ class Mat22 { } static Vec2 mulTransVec2_(final Mat22 R, final Vec2 v) { - return new Vec2((v.x * R.ex.x + v.y * R.ex.y), (v.x * R.ey.x + v.y * R.ey.y)); + return new Vec2( + (v.x * R.ex.x + v.y * R.ex.y), (v.x * R.ey.x + v.y * R.ey.y)); } static void mulTransToOutVec2_(final Mat22 R, final Vec2 v, final Vec2 out) { @@ -494,7 +496,8 @@ class Mat22 { out.x = outx; } - static void mulTransToOutUnsafeVec2(final Mat22 R, final Vec2 v, final Vec2 out) { + static void mulTransToOutUnsafeVec2( + final Mat22 R, final Vec2 v, final Vec2 out) { assert(out != v); out.y = v.x * R.ey.x + v.y * R.ey.y; out.x = v.x * R.ex.x + v.y * R.ex.y; @@ -521,7 +524,8 @@ class Mat22 { out.ey.y = y2; } - static void mulTransToOutUnsafeMat22(final Mat22 A, final Mat22 B, final Mat22 out) { + static void mulTransToOutUnsafeMat22( + final Mat22 A, final Mat22 B, final Mat22 out) { assert(A != out); assert(B != out); out.ex.x = A.ex.x * B.ex.x + A.ex.y * B.ex.y; diff --git a/lib/box2d/src/common/mat33.dart b/lib/src/common/mat33.dart similarity index 95% rename from lib/box2d/src/common/mat33.dart rename to lib/src/common/mat33.dart index 767a995..ea50ee2 100644 --- a/lib/box2d/src/common/mat33.dart +++ b/lib/src/common/mat33.dart @@ -30,8 +30,8 @@ part of box2d; * @author Daniel Murphy */ class Mat33 { - - static final Mat33 IDENTITY = new Mat33(new Vec3(1.0, 0.0, 0.0), new Vec3(0.0, 1.0, 0.0), new Vec3(0.0, 0.0, 1.0)); + static final Mat33 IDENTITY = new Mat33(new Vec3(1.0, 0.0, 0.0), + new Vec3(0.0, 1.0, 0.0), new Vec3(0.0, 0.0, 1.0)); final Vec3 ex, ey, ez; @@ -45,7 +45,8 @@ class Mat33 { ey = new Vec3.zero(), ez = new Vec3.zero(); - Mat33.withCoords(double exx, double exy, double exz, double eyx, double eyy, double eyz, double ezx, double ezy, double ezz) + Mat33.withCoords(double exx, double exy, double exz, double eyx, double eyy, + double eyz, double ezx, double ezy, double ezz) : ex = new Vec3(exx, exy, exz), ey = new Vec3(eyx, eyy, eyz), ez = new Vec3(ezx, ezy, ezz); @@ -56,7 +57,8 @@ class Mat33 { ez.setZero(); } - void setCoords(double exx, double exy, double exz, double eyx, double eyy, double eyz, double ezx, double ezy, double ezz) { + void setCoords(double exx, double exy, double exz, double eyx, double eyy, + double eyz, double ezx, double ezy, double ezz) { ex.x = exx; ex.y = exy; ex.z = exz; @@ -97,7 +99,9 @@ class Mat33 { // / Multiply a matrix times a vector. static Vec3 mul(Mat33 A, Vec3 v) { - return new Vec3(v.x * A.ex.x + v.y * A.ey.x + v.z + A.ez.x, v.x * A.ex.y + v.y * A.ey.y + v.z * A.ez.y, v.x * A.ex.z + v.y * A.ey.z + v.z * A.ez.z); + return new Vec3(v.x * A.ex.x + v.y * A.ey.x + v.z + A.ez.x, + v.x * A.ex.y + v.y * A.ey.y + v.z * A.ez.y, + v.x * A.ex.z + v.y * A.ey.z + v.z * A.ez.z); } static Vec2 mul22(Mat33 A, Vec2 v) { @@ -164,7 +168,6 @@ class Mat33 { out.y = det * (a11 * b.y - a21 * b.x); } - // djm pooling from below /** * Solve A * x = b, where b is a column vector. This is more efficient than computing the inverse @@ -255,7 +258,6 @@ class Mat33 { M.ez.z = det * (a11 * a22 - a12 * a12); } - static void setScaleTransform(double scale, Mat33 out) { out.ex.x = scale; out.ey.y = scale; diff --git a/lib/box2d/src/common/math_utils.dart b/lib/src/common/math_utils.dart similarity index 96% rename from lib/box2d/src/common/math_utils.dart rename to lib/src/common/math_utils.dart index ace2338..57b0ea9 100644 --- a/lib/box2d/src/common/math_utils.dart +++ b/lib/src/common/math_utils.dart @@ -42,7 +42,8 @@ class MathUtils { } /** Returns the closest value to 'a' that is in between 'low' and 'high' */ - static double clampDouble(final double a, final double low, final double high) { + static double clampDouble( + final double a, final double low, final double high) { return Math.max(low, Math.min(a, high)); } @@ -89,7 +90,6 @@ class MathUtils { } if (Settings.SINCOS_LUT_LERP) { - x /= Settings.SINCOS_LUT_PRECISION; final int index = x.toInt(); @@ -104,14 +104,13 @@ class MathUtils { } else { return ((1 - x) * sinLUT[index] + x * sinLUT[index + 1]); } - } else { - return sinLUT[(x / Settings.SINCOS_LUT_PRECISION).round() % Settings.SINCOS_LUT_LENGTH]; + return sinLUT[(x / Settings.SINCOS_LUT_PRECISION).round() % + Settings.SINCOS_LUT_LENGTH]; } } static double cos(double x) { return Math.cos(x); } - } diff --git a/lib/box2d/src/common/obbviewporttransform.dart b/lib/src/common/obbviewporttransform.dart similarity index 100% rename from lib/box2d/src/common/obbviewporttransform.dart rename to lib/src/common/obbviewporttransform.dart diff --git a/lib/box2d/src/common/raycast_result.dart b/lib/src/common/raycast_result.dart similarity index 100% rename from lib/box2d/src/common/raycast_result.dart rename to lib/src/common/raycast_result.dart diff --git a/lib/box2d/src/common/rot.dart b/lib/src/common/rot.dart similarity index 99% rename from lib/box2d/src/common/rot.dart rename to lib/src/common/rot.dart index c5045d6..0d73adc 100644 --- a/lib/box2d/src/common/rot.dart +++ b/lib/src/common/rot.dart @@ -25,7 +25,6 @@ part of box2d; class Rot { - double s = 0.0, c = 1.0; // sin and cos @@ -131,5 +130,4 @@ class Rot { out.x = q.c * v.x + q.s * v.y; out.y = -q.s * v.x + q.c * v.y; } - } diff --git a/lib/box2d/src/common/settings.dart b/lib/src/common/settings.dart similarity index 96% rename from lib/box2d/src/common/settings.dart rename to lib/src/common/settings.dart index 1ad616a..68cfd7b 100644 --- a/lib/box2d/src/common/settings.dart +++ b/lib/src/common/settings.dart @@ -61,7 +61,8 @@ class Settings { * */ static const double SINCOS_LUT_PRECISION = .00011; - static final int SINCOS_LUT_LENGTH = (Math.PI * 2.0 / SINCOS_LUT_PRECISION).ceil(); + static final int SINCOS_LUT_LENGTH = + (Math.PI * 2.0 / SINCOS_LUT_PRECISION).ceil(); /** * Use if the table's precision is large (eg .006 or greater). Although it is more expensive, it * greatly increases accuracy. Look in the MathUtils source for some test results on the accuracy @@ -159,7 +160,6 @@ class Settings { static const double baumgarte = 0.2; static const double toiBaugarte = 0.75; - // Sleep /** @@ -203,7 +203,8 @@ class Settings { * The maximum distance between particles in a triad, divided by the particle radius. */ static const int maxTriadDistance = 2; - static const int maxTriadDistanceSquared = (maxTriadDistance * maxTriadDistance); + static const int maxTriadDistanceSquared = + (maxTriadDistance * maxTriadDistance); /** * The initial size of particle data buffers. @@ -213,7 +214,8 @@ class Settings { /** * Helper function for ease of porting Java to Dart. */ - static void arraycopy(List src, int srcPos, List dest, int destPos, int length) { + static void arraycopy( + List src, int srcPos, List dest, int destPos, int length) { dest.setRange(destPos, length + destPos, src, srcPos); } @@ -224,5 +226,4 @@ class Settings { temp.sort(); list.setRange(fromPos, toPos, temp); } - } diff --git a/lib/box2d/src/common/sweep.dart b/lib/src/common/sweep.dart similarity index 100% rename from lib/box2d/src/common/sweep.dart rename to lib/src/common/sweep.dart diff --git a/lib/box2d/src/common/timer.dart b/lib/src/common/timer.dart similarity index 99% rename from lib/box2d/src/common/timer.dart rename to lib/src/common/timer.dart index 1850686..72e6416 100644 --- a/lib/box2d/src/common/timer.dart +++ b/lib/src/common/timer.dart @@ -25,7 +25,6 @@ part of box2d; class Timer { - Stopwatch _stopWatch = new Stopwatch(); Timer() { diff --git a/lib/box2d/src/common/transform.dart b/lib/src/common/transform.dart similarity index 86% rename from lib/box2d/src/common/transform.dart rename to lib/src/common/transform.dart index b6d1022..61b69a9 100644 --- a/lib/box2d/src/common/transform.dart +++ b/lib/src/common/transform.dart @@ -35,7 +35,6 @@ class Transform { /** A matrix representing a rotation */ final Rot q; - /** The default constructor. */ Transform.zero() : p = new Vec2.zero(), @@ -76,7 +75,8 @@ class Transform { } static Vec2 mulVec2(final Transform T, final Vec2 v) { - return new Vec2((T.q.c * v.x - T.q.s * v.y) + T.p.x, (T.q.s * v.x + T.q.c * v.y) + T.p.y); + return new Vec2((T.q.c * v.x - T.q.s * v.y) + T.p.x, + (T.q.s * v.x + T.q.c * v.y) + T.p.y); } static void mulToOutVec2(final Transform T, final Vec2 v, final Vec2 out) { @@ -85,7 +85,8 @@ class Transform { out.y = tempy; } - static void mulToOutUnsafeVec2(final Transform T, final Vec2 v, final Vec2 out) { + static void mulToOutUnsafeVec2( + final Transform T, final Vec2 v, final Vec2 out) { assert(v != out); out.x = (T.q.c * v.x - T.q.s * v.y) + T.p.x; out.y = (T.q.s * v.x + T.q.c * v.y) + T.p.y; @@ -97,8 +98,8 @@ class Transform { return new Vec2((T.q.c * px + T.q.s * py), (-T.q.s * px + T.q.c * py)); } - - static void mulTransToOutVec2(final Transform T, final Vec2 v, final Vec2 out) { + static void mulTransToOutVec2( + final Transform T, final Vec2 v, final Vec2 out) { final double px = v.x - T.p.x; final double py = v.y - T.p.y; final double tempy = (-T.q.s * px + T.q.c * py); @@ -106,7 +107,8 @@ class Transform { out.y = tempy; } - static void mulTransToOutUnsafeVec2(final Transform T, final Vec2 v, final Vec2 out) { + static void mulTransToOutUnsafeVec2( + final Transform T, final Vec2 v, final Vec2 out) { assert(v != out); final double px = v.x - T.p.x; final double py = v.y - T.p.y; @@ -122,14 +124,16 @@ class Transform { return C; } - static void mulToOut(final Transform A, final Transform B, final Transform out) { + static void mulToOut( + final Transform A, final Transform B, final Transform out) { assert(out != A); Rot.mul(A.q, B.q, out.q); Rot.mulToOut(A.q, B.p, out.p); out.p.addLocal(A.p); } - static void mulToOutUnsafe(final Transform A, final Transform B, final Transform out) { + static void mulToOutUnsafe( + final Transform A, final Transform B, final Transform out) { assert(out != B); assert(out != A); Rot.mulUnsafe(A.q, B.q, out.q); @@ -147,14 +151,16 @@ class Transform { return C; } - void mulTransToOut(final Transform A, final Transform B, final Transform out) { + void mulTransToOut( + final Transform A, final Transform B, final Transform out) { assert(out != A); Rot.mulTrans(A.q, B.q, out.q); _pool.set(B.p).subLocal(A.p); Rot.mulTransVec2(A.q, _pool, out.p); } - static void mulTransToOutUnsafe(final Transform A, final Transform B, final Transform out) { + static void mulTransToOutUnsafe( + final Transform A, final Transform B, final Transform out) { assert(out != A); assert(out != B); Rot.mulTransUnsafe(A.q, B.q, out.q); diff --git a/lib/box2d/src/common/vec2.dart b/lib/src/common/vec2.dart similarity index 97% rename from lib/box2d/src/common/vec2.dart rename to lib/src/common/vec2.dart index 0204420..c5f8c1c 100644 --- a/lib/box2d/src/common/vec2.dart +++ b/lib/src/common/vec2.dart @@ -26,13 +26,17 @@ part of box2d; class Vec2 { final Float64List _d = new Float64List(2); - - set x (v) { _d[0] = v; } - set y (v) { _d[1] = v; } - + + set x(v) { + _d[0] = v; + } + set y(v) { + _d[1] = v; + } + get x => _d[0]; get y => _d[1]; - + Vec2(double x, double y) { _d[0] = x; _d[1] = y; @@ -44,7 +48,7 @@ class Vec2 { _d[0] = other._d[0]; _d[1] = other._d[1]; } - + /** Zero out this vector. */ setZero() { x = 0.0; @@ -268,7 +272,7 @@ class Vec2 { if (obj == null) return false; if (obj is! Vec2) return false; Vec2 other = obj; - return MathUtils.approxEquals(x, other.x) && MathUtils.approxEquals(y, other.y); + return MathUtils.approxEquals(x, other.x) && + MathUtils.approxEquals(y, other.y); } - } diff --git a/lib/box2d/src/common/vec3.dart b/lib/src/common/vec3.dart similarity index 95% rename from lib/box2d/src/common/vec3.dart rename to lib/src/common/vec3.dart index 8335033..74656b7 100644 --- a/lib/box2d/src/common/vec3.dart +++ b/lib/src/common/vec3.dart @@ -126,8 +126,8 @@ class Vec3 { if (obj is! Vec3) return false; Vec3 other = obj; return MathUtils.approxEquals(x, other.x) && - MathUtils.approxEquals(y, other.y) && - MathUtils.approxEquals(z, other.z); + MathUtils.approxEquals(y, other.y) && + MathUtils.approxEquals(z, other.z); } static double dot(Vec3 a, Vec3 b) { @@ -135,7 +135,8 @@ class Vec3 { } static Vec3 cross(Vec3 a, Vec3 b) { - return new Vec3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); + return new Vec3( + a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); } static void crossToOut(Vec3 a, Vec3 b, Vec3 out) { diff --git a/lib/box2d/src/dynamics/body.dart b/lib/src/dynamics/body.dart similarity index 97% rename from lib/box2d/src/dynamics/body.dart rename to lib/src/dynamics/body.dart index 640d8fa..c264b16 100644 --- a/lib/box2d/src/dynamics/body.dart +++ b/lib/src/dynamics/body.dart @@ -24,7 +24,6 @@ part of box2d; - /** * A rigid body. These are created via World.createBody. * @@ -460,7 +459,8 @@ class Body { m_force.x += force.x; m_force.y += force.y; - m_torque += (point.x - m_sweep.c.x) * force.y - (point.y - m_sweep.c.y) * force.x; + m_torque += + (point.x - m_sweep.c.x) * force.y - (point.y - m_sweep.c.y) * force.x; } /** @@ -525,7 +525,9 @@ class Body { m_linearVelocity.x += impulse.x * m_invMass; m_linearVelocity.y += impulse.y * m_invMass; - m_angularVelocity += m_invI * ((point.x - m_sweep.c.x) * impulse.y - (point.y - m_sweep.c.y) * impulse.x); + m_angularVelocity += m_invI * + ((point.x - m_sweep.c.x) * impulse.y - + (point.y - m_sweep.c.y) * impulse.x); } /** @@ -559,7 +561,10 @@ class Body { * @return the rotational inertia, usually in kg-m^2. */ double getInertia() { - return m_I + m_mass * (m_sweep.localCenter.x * m_sweep.localCenter.x + m_sweep.localCenter.y * m_sweep.localCenter.y); + return m_I + + m_mass * + (m_sweep.localCenter.x * m_sweep.localCenter.x + + m_sweep.localCenter.y * m_sweep.localCenter.y); } /** @@ -573,7 +578,10 @@ class Body { // data.center.set(m_sweep.localCenter); data.mass = m_mass; - data.I = m_I + m_mass * (m_sweep.localCenter.x * m_sweep.localCenter.x + m_sweep.localCenter.y * m_sweep.localCenter.y); + data.I = m_I + + m_mass * + (m_sweep.localCenter.x * m_sweep.localCenter.x + + m_sweep.localCenter.y * m_sweep.localCenter.y); data.center.x = m_sweep.localCenter.x; data.center.y = m_sweep.localCenter.y; } @@ -1103,8 +1111,12 @@ class Body { // inlined: xf1.q.s = MathUtils.sin(m_sweep.a0); xf1.q.c = MathUtils.cos(m_sweep.a0); - xf1.p.x = m_sweep.c0.x - xf1.q.c * m_sweep.localCenter.x + xf1.q.s * m_sweep.localCenter.y; - xf1.p.y = m_sweep.c0.y - xf1.q.s * m_sweep.localCenter.x - xf1.q.c * m_sweep.localCenter.y; + xf1.p.x = m_sweep.c0.x - + xf1.q.c * m_sweep.localCenter.x + + xf1.q.s * m_sweep.localCenter.y; + xf1.p.y = m_sweep.c0.y - + xf1.q.s * m_sweep.localCenter.x - + xf1.q.c * m_sweep.localCenter.y; // end inline for (Fixture f = m_fixtureList; f != null; f = f.m_next) { @@ -1162,7 +1174,7 @@ class Body { Rot.mulToOutUnsafe(m_xf.q, m_sweep.localCenter, m_xf.p); m_xf.p.mulLocal(-1.0).addLocal(m_sweep.c); } - + String toString() { return "Body[pos: ${getPosition()} linVel: ${getLinearVelocity()} angVel: ${getAngularVelocity()}]"; } diff --git a/lib/box2d/src/dynamics/body_def.dart b/lib/src/dynamics/body_def.dart similarity index 100% rename from lib/box2d/src/dynamics/body_def.dart rename to lib/src/dynamics/body_def.dart diff --git a/lib/box2d/src/dynamics/body_type.dart b/lib/src/dynamics/body_type.dart similarity index 84% rename from lib/box2d/src/dynamics/body_type.dart rename to lib/src/dynamics/body_type.dart index e3e59de..95e1e55 100644 --- a/lib/box2d/src/dynamics/body_type.dart +++ b/lib/src/dynamics/body_type.dart @@ -7,6 +7,4 @@ part of box2d; * dynamic: positive mass, non-zero velocity determined by forces, moved by solver * */ -enum BodyType { - STATIC, KINEMATIC, DYNAMIC -} \ No newline at end of file +enum BodyType { STATIC, KINEMATIC, DYNAMIC } diff --git a/lib/box2d/src/dynamics/contact_manager.dart b/lib/src/dynamics/contact_manager.dart similarity index 97% rename from lib/box2d/src/dynamics/contact_manager.dart rename to lib/src/dynamics/contact_manager.dart index 17d4c66..1dbd9cc 100644 --- a/lib/box2d/src/dynamics/contact_manager.dart +++ b/lib/src/dynamics/contact_manager.dart @@ -24,15 +24,13 @@ part of box2d; - /** * Delegate of World. * * @author Daniel Murphy */ - -class ContactManager implements PairCallback { +class ContactManager implements PairCallback { BroadPhase m_broadPhase; Contact m_contactList; int m_contactCount = 0; @@ -103,7 +101,8 @@ class ContactManager implements PairCallback { } // Check user filtering. - if (m_contactFilter != null && m_contactFilter.shouldCollide(fixtureA, fixtureB) == false) { + if (m_contactFilter != null && + m_contactFilter.shouldCollide(fixtureA, fixtureB) == false) { return; } @@ -246,7 +245,8 @@ class ContactManager implements PairCallback { } // Check user filtering. - if (m_contactFilter != null && m_contactFilter.shouldCollide(fixtureA, fixtureB) == false) { + if (m_contactFilter != null && + m_contactFilter.shouldCollide(fixtureA, fixtureB) == false) { Contact cNuke = c; c = cNuke.getNext(); destroy(cNuke); @@ -284,4 +284,3 @@ class ContactManager implements PairCallback { } } } - diff --git a/lib/box2d/src/dynamics/contacts/chain_and_circle_contact.dart b/lib/src/dynamics/contacts/chain_and_circle_contact.dart similarity index 90% rename from lib/box2d/src/dynamics/contacts/chain_and_circle_contact.dart rename to lib/src/dynamics/contacts/chain_and_circle_contact.dart index 09291d6..70c0b4d 100644 --- a/lib/box2d/src/dynamics/contacts/chain_and_circle_contact.dart +++ b/lib/src/dynamics/contacts/chain_and_circle_contact.dart @@ -25,13 +25,12 @@ part of box2d; class ChainAndCircleContact extends Contact { - ChainAndCircleContact(IWorldPool argPool) : super(argPool); void init(Fixture fA, int indexA, Fixture fB, int indexB) { super.init(fA, indexA, fB, indexB); - assert (m_fixtureA.getType() == ShapeType.CHAIN); - assert (m_fixtureB.getType() == ShapeType.CIRCLE); + assert(m_fixtureA.getType() == ShapeType.CHAIN); + assert(m_fixtureB.getType() == ShapeType.CIRCLE); } final EdgeShape _edge = new EdgeShape(); @@ -39,7 +38,7 @@ class ChainAndCircleContact extends Contact { void evaluate(Manifold manifold, Transform xfA, Transform xfB) { ChainShape chain = m_fixtureA.getShape(); chain.getChildEdge(_edge, m_indexA); - pool.getCollision().collideEdgeAndCircle(manifold, _edge, xfA, - m_fixtureB.getShape(), xfB); + pool.getCollision().collideEdgeAndCircle( + manifold, _edge, xfA, m_fixtureB.getShape(), xfB); } } diff --git a/lib/box2d/src/dynamics/contacts/chain_and_polygon_contact.dart b/lib/src/dynamics/contacts/chain_and_polygon_contact.dart similarity index 90% rename from lib/box2d/src/dynamics/contacts/chain_and_polygon_contact.dart rename to lib/src/dynamics/contacts/chain_and_polygon_contact.dart index b85d150..7a26773 100644 --- a/lib/box2d/src/dynamics/contacts/chain_and_polygon_contact.dart +++ b/lib/src/dynamics/contacts/chain_and_polygon_contact.dart @@ -25,13 +25,12 @@ part of box2d; class ChainAndPolygonContact extends Contact { - ChainAndPolygonContact(IWorldPool argPool) : super(argPool); void init(Fixture fA, int indexA, Fixture fB, int indexB) { super.init(fA, indexA, fB, indexB); - assert (m_fixtureA.getType() == ShapeType.CHAIN); - assert (m_fixtureB.getType() == ShapeType.POLYGON); + assert(m_fixtureA.getType() == ShapeType.CHAIN); + assert(m_fixtureB.getType() == ShapeType.POLYGON); } final EdgeShape _edge = new EdgeShape(); @@ -39,7 +38,7 @@ class ChainAndPolygonContact extends Contact { void evaluate(Manifold manifold, Transform xfA, Transform xfB) { ChainShape chain = m_fixtureA.getShape(); chain.getChildEdge(_edge, m_indexA); - pool.getCollision().collideEdgeAndPolygon(manifold, _edge, xfA, - m_fixtureB.getShape(), xfB); + pool.getCollision().collideEdgeAndPolygon( + manifold, _edge, xfA, m_fixtureB.getShape(), xfB); } } diff --git a/lib/box2d/src/dynamics/contacts/circle_contact.dart b/lib/src/dynamics/contacts/circle_contact.dart similarity index 88% rename from lib/box2d/src/dynamics/contacts/circle_contact.dart rename to lib/src/dynamics/contacts/circle_contact.dart index 200852b..aa964c8 100644 --- a/lib/box2d/src/dynamics/contacts/circle_contact.dart +++ b/lib/src/dynamics/contacts/circle_contact.dart @@ -25,17 +25,16 @@ part of box2d; class CircleContact extends Contact { - CircleContact(IWorldPool argPool) : super(argPool); void init0(Fixture fixtureA, Fixture fixtureB) { init(fixtureA, 0, fixtureB, 0); - assert (m_fixtureA.getType() == ShapeType.CIRCLE); - assert (m_fixtureB.getType() == ShapeType.CIRCLE); + assert(m_fixtureA.getType() == ShapeType.CIRCLE); + assert(m_fixtureB.getType() == ShapeType.CIRCLE); } void evaluate(Manifold manifold, Transform xfA, Transform xfB) { - pool.getCollision().collideCircles(manifold, m_fixtureA.getShape(), xfA, - m_fixtureB.getShape(), xfB); + pool.getCollision().collideCircles( + manifold, m_fixtureA.getShape(), xfA, m_fixtureB.getShape(), xfB); } } diff --git a/lib/box2d/src/dynamics/contacts/contact.dart b/lib/src/dynamics/contacts/contact.dart similarity index 95% rename from lib/box2d/src/dynamics/contacts/contact.dart rename to lib/src/dynamics/contacts/contact.dart index fd027da..5e692fa 100644 --- a/lib/box2d/src/dynamics/contacts/contact.dart +++ b/lib/src/dynamics/contacts/contact.dart @@ -123,7 +123,8 @@ abstract class Contact { final Shape shapeA = m_fixtureA.getShape(); final Shape shapeB = m_fixtureB.getShape(); - worldManifold.initialize(m_manifold, bodyA.getTransform(), shapeA.m_radius, bodyB.getTransform(), shapeB.m_radius); + worldManifold.initialize(m_manifold, bodyA.getTransform(), shapeA.m_radius, + bodyB.getTransform(), shapeB.m_radius); } /** @@ -202,7 +203,8 @@ abstract class Contact { } void resetFriction() { - m_friction = Contact.mixFriction(m_fixtureA.m_friction, m_fixtureB.m_friction); + m_friction = + Contact.mixFriction(m_fixtureA.m_friction, m_fixtureB.m_friction); } void setRestitution(double restitution) { @@ -214,7 +216,8 @@ abstract class Contact { } void resetRestitution() { - m_restitution = Contact.mixRestitution(m_fixtureA.m_restitution, m_fixtureB.m_restitution); + m_restitution = Contact.mixRestitution( + m_fixtureA.m_restitution, m_fixtureB.m_restitution); } void setTangentSpeed(double speed) { @@ -238,7 +241,6 @@ abstract class Contact { final Manifold _oldManifold = new Manifold(); void update(ContactListener listener) { - _oldManifold.set(m_manifold); // Re-enable this contact. @@ -261,7 +263,9 @@ abstract class Contact { if (sensor) { Shape shapeA = m_fixtureA.getShape(); Shape shapeB = m_fixtureB.getShape(); - touching = pool.getCollision().testOverlap(shapeA, m_indexA, shapeB, m_indexB, xfA, xfB); + touching = pool + .getCollision() + .testOverlap(shapeA, m_indexA, shapeB, m_indexB, xfA, xfB); // Sensors don't generate manifolds. m_manifold.pointCount = 0; @@ -340,5 +344,4 @@ abstract class Contact { static double mixRestitution(double restitution1, double restitution2) { return restitution1 > restitution2 ? restitution1 : restitution2; } - } diff --git a/lib/box2d/src/dynamics/contacts/contact_creator.dart b/lib/src/dynamics/contacts/contact_creator.dart similarity index 94% rename from lib/box2d/src/dynamics/contacts/contact_creator.dart rename to lib/src/dynamics/contacts/contact_creator.dart index e8945b9..57b7428 100644 --- a/lib/box2d/src/dynamics/contacts/contact_creator.dart +++ b/lib/src/dynamics/contacts/contact_creator.dart @@ -25,8 +25,8 @@ part of box2d; abstract class ContactCreator { - - Contact contactCreateFcn(IWorldPool argPool, Fixture fixtureA, Fixture fixtureB); + Contact contactCreateFcn( + IWorldPool argPool, Fixture fixtureA, Fixture fixtureB); void contactDestroyFcn(IWorldPool argPool, Contact contact); } diff --git a/lib/box2d/src/dynamics/contacts/contact_edge.dart b/lib/src/dynamics/contacts/contact_edge.dart similarity index 100% rename from lib/box2d/src/dynamics/contacts/contact_edge.dart rename to lib/src/dynamics/contacts/contact_edge.dart diff --git a/lib/box2d/src/dynamics/contacts/contact_position_and_constraint.dart b/lib/src/dynamics/contacts/contact_position_and_constraint.dart similarity index 100% rename from lib/box2d/src/dynamics/contacts/contact_position_and_constraint.dart rename to lib/src/dynamics/contacts/contact_position_and_constraint.dart diff --git a/lib/box2d/src/dynamics/contacts/contact_register.dart b/lib/src/dynamics/contacts/contact_register.dart similarity index 100% rename from lib/box2d/src/dynamics/contacts/contact_register.dart rename to lib/src/dynamics/contacts/contact_register.dart diff --git a/lib/box2d/src/dynamics/contacts/contact_solver.dart b/lib/src/dynamics/contacts/contact_solver.dart similarity index 88% rename from lib/box2d/src/dynamics/contacts/contact_solver.dart rename to lib/src/dynamics/contacts/contact_solver.dart index e58c3a3..3712e71 100644 --- a/lib/box2d/src/dynamics/contacts/contact_solver.dart +++ b/lib/src/dynamics/contacts/contact_solver.dart @@ -33,7 +33,6 @@ class ContactSolverDef { } class ContactSolver { - static const bool DEBUG_SOLVER = false; static const double k_errorTol = 1e-3; /** @@ -56,8 +55,10 @@ class ContactSolver { int m_count = 0; ContactSolver() { - m_positionConstraints = new List(INITIAL_NUM_CONSTRAINTS); - m_velocityConstraints = new List(INITIAL_NUM_CONSTRAINTS); + m_positionConstraints = + new List(INITIAL_NUM_CONSTRAINTS); + m_velocityConstraints = + new List(INITIAL_NUM_CONSTRAINTS); for (int i = 0; i < INITIAL_NUM_CONSTRAINTS; i++) { m_positionConstraints[i] = new ContactPositionConstraint(); m_velocityConstraints[i] = new ContactVelocityConstraint(); @@ -71,7 +72,8 @@ class ContactSolver { if (m_positionConstraints.length < m_count) { List old = m_positionConstraints; - m_positionConstraints = new List(Math.max(old.length * 2, m_count)); + m_positionConstraints = new List( + Math.max(old.length * 2, m_count)); Settings.arraycopy(old, 0, m_positionConstraints, 0, old.length); for (int i = old.length; i < m_positionConstraints.length; i++) { m_positionConstraints[i] = new ContactPositionConstraint(); @@ -80,7 +82,8 @@ class ContactSolver { if (m_velocityConstraints.length < m_count) { List old = m_velocityConstraints; - m_velocityConstraints = new List(Math.max(old.length * 2, m_count)); + m_velocityConstraints = new List( + Math.max(old.length * 2, m_count)); Settings.arraycopy(old, 0, m_velocityConstraints, 0, old.length); for (int i = old.length; i < m_velocityConstraints.length; i++) { m_velocityConstraints[i] = new ContactVelocityConstraint(); @@ -189,8 +192,10 @@ class ContactSolver { for (int j = 0; j < pointCount; ++j) { VelocityConstraintPoint vcp = vc.points[j]; - double Px = tangentx * vcp.tangentImpulse + normal.x * vcp.normalImpulse; - double Py = tangenty * vcp.tangentImpulse + normal.y * vcp.normalImpulse; + double Px = + tangentx * vcp.tangentImpulse + normal.x * vcp.normalImpulse; + double Py = + tangenty * vcp.tangentImpulse + normal.y * vcp.normalImpulse; wA -= iA * (vcp.rA.x * Py - vcp.rA.y * Px); vA.x -= Px * mA; @@ -324,7 +329,6 @@ class ContactSolver { } } - void solveVelocityConstraints() { for (int i = 0; i < m_count; ++i) { final ContactVelocityConstraint vc = m_velocityConstraints[i]; @@ -365,7 +369,8 @@ class ContactSolver { // Clamp the accumulated force final double maxFriction = friction * vcp.normalImpulse; - final double newImpulse = MathUtils.clampDouble(vcp.tangentImpulse + lambda, -maxFriction, maxFriction); + final double newImpulse = MathUtils.clampDouble( + vcp.tangentImpulse + lambda, -maxFriction, maxFriction); lambda = newImpulse - vcp.tangentImpulse; vcp.tangentImpulse = newImpulse; @@ -492,7 +497,7 @@ class ContactSolver { // final double k_errorTol = 1e-3f; // B2_NOT_USED(k_errorTol); - for ( ; ; ) { + for (;;) { // // Case 1: vn = 0 // @@ -534,8 +539,14 @@ class ContactSolver { vB.x += mB * (P1x + P2x); vB.y += mB * (P1y + P2y); - wA -= iA * (cp1rA.x * P1y - cp1rA.y * P1x + (cp2rA.x * P2y - cp2rA.y * P2x)); - wB += iB * (cp1rB.x * P1y - cp1rB.y * P1x + (cp2rB.x * P2y - cp2rB.y * P2x)); + wA -= iA * + (cp1rA.x * P1y - + cp1rA.y * P1x + + (cp2rA.x * P2y - cp2rA.y * P2x)); + wB += iB * + (cp1rB.x * P1y - + cp1rB.y * P1x + + (cp2rB.x * P2y - cp2rB.y * P2x)); // Accumulate cp1.normalImpulse = xx; @@ -552,8 +563,14 @@ class ContactSolver { */ if (DEBUG_SOLVER) { // Postconditions - Vec2 dv1 = vB.add(Vec2.crossDblVec2(wB, cp1rB).subLocal(vA).subLocal(Vec2.crossDblVec2(wA, cp1rA))); - Vec2 dv2 = vB.add(Vec2.crossDblVec2(wB, cp2rB).subLocal(vA).subLocal(Vec2.crossDblVec2(wA, cp2rA))); + Vec2 dv1 = vB.add(Vec2 + .crossDblVec2(wB, cp1rB) + .subLocal(vA) + .subLocal(Vec2.crossDblVec2(wA, cp1rA))); + Vec2 dv2 = vB.add(Vec2 + .crossDblVec2(wB, cp2rB) + .subLocal(vA) + .subLocal(Vec2.crossDblVec2(wA, cp2rA))); // Compute normal velocity vn1 = Vec2.dot(dv1, normal); vn2 = Vec2.dot(dv2, normal); @@ -600,8 +617,14 @@ class ContactSolver { vB.x += mB * (P1x + P2x); vB.y += mB * (P1y + P2y); - wA -= iA * (cp1rA.x * P1y - cp1rA.y * P1x + (cp2rA.x * P2y - cp2rA.y * P2x)); - wB += iB * (cp1rB.x * P1y - cp1rB.y * P1x + (cp2rB.x * P2y - cp2rB.y * P2x)); + wA -= iA * + (cp1rA.x * P1y - + cp1rA.y * P1x + + (cp2rA.x * P2y - cp2rA.y * P2x)); + wB += iB * + (cp1rB.x * P1y - + cp1rB.y * P1x + + (cp2rB.x * P2y - cp2rB.y * P2x)); // Accumulate cp1.normalImpulse = xx; @@ -617,7 +640,10 @@ class ContactSolver { */ if (DEBUG_SOLVER) { // Postconditions - Vec2 dv1 = vB.add(Vec2.crossDblVec2(wB, cp1rB).subLocal(vA).subLocal(Vec2.crossDblVec2(wA, cp1rA))); + Vec2 dv1 = vB.add(Vec2 + .crossDblVec2(wB, cp1rB) + .subLocal(vA) + .subLocal(Vec2.crossDblVec2(wA, cp1rA))); // Compute normal velocity vn1 = Vec2.dot(dv1, normal); @@ -660,8 +686,14 @@ class ContactSolver { vB.x += mB * (P1x + P2x); vB.y += mB * (P1y + P2y); - wA -= iA * (cp1rA.x * P1y - cp1rA.y * P1x + (cp2rA.x * P2y - cp2rA.y * P2x)); - wB += iB * (cp1rB.x * P1y - cp1rB.y * P1x + (cp2rB.x * P2y - cp2rB.y * P2x)); + wA -= iA * + (cp1rA.x * P1y - + cp1rA.y * P1x + + (cp2rA.x * P2y - cp2rA.y * P2x)); + wB += iB * + (cp1rB.x * P1y - + cp1rB.y * P1x + + (cp2rB.x * P2y - cp2rB.y * P2x)); // Accumulate cp1.normalImpulse = xx; @@ -677,7 +709,10 @@ class ContactSolver { */ if (DEBUG_SOLVER) { // Postconditions - Vec2 dv2 = vB.add(Vec2.crossDblVec2(wB, cp2rB).subLocal(vA).subLocal(Vec2.crossDblVec2(wA, cp2rA))); + Vec2 dv2 = vB.add(Vec2 + .crossDblVec2(wB, cp2rB) + .subLocal(vA) + .subLocal(Vec2.crossDblVec2(wA, cp2rA))); // Compute normal velocity vn2 = Vec2.dot(dv2, normal); @@ -719,8 +754,14 @@ class ContactSolver { vB.x += mB * (P1x + P2x); vB.y += mB * (P1y + P2y); - wA -= iA * (cp1rA.x * P1y - cp1rA.y * P1x + (cp2rA.x * P2y - cp2rA.y * P2x)); - wB += iB * (cp1rB.x * P1y - cp1rB.y * P1x + (cp2rB.x * P2y - cp2rB.y * P2x)); + wA -= iA * + (cp1rA.x * P1y - + cp1rA.y * P1x + + (cp2rA.x * P2y - cp2rA.y * P2x)); + wB += iB * + (cp1rB.x * P1y - + cp1rB.y * P1x + + (cp2rB.x * P2y - cp2rB.y * P2x)); // Accumulate cp1.normalImpulse = xx; @@ -850,7 +891,9 @@ class ContactSolver { minSeparation = Math.min(minSeparation, separation); // Prevent large corrections and allow slop. - final double C = MathUtils.clampDouble(Settings.baumgarte * (separation + Settings.linearSlop), -Settings.maxLinearCorrection, 0.0); + final double C = MathUtils.clampDouble( + Settings.baumgarte * (separation + Settings.linearSlop), + -Settings.maxLinearCorrection, 0.0); // Compute the effective mass. final double rnA = rAx * normal.y - rAy * normal.x; @@ -948,7 +991,9 @@ class ContactSolver { minSeparation = Math.min(minSeparation, separation); // Prevent large corrections and allow slop. - double C = MathUtils.clampDouble(Settings.toiBaugarte * (separation + Settings.linearSlop), -Settings.maxLinearCorrection, 0.0); + double C = MathUtils.clampDouble( + Settings.toiBaugarte * (separation + Settings.linearSlop), + -Settings.maxLinearCorrection, 0.0); // Compute the effective mass. double rnA = rAx * normal.y - rAy * normal.x; @@ -983,14 +1028,13 @@ class ContactSolver { } } - class PositionSolverManifold { - final Vec2 normal = new Vec2.zero(); final Vec2 point = new Vec2.zero(); double separation = 0.0; - void initialize(ContactPositionConstraint pc, Transform xfA, Transform xfB, int index) { + void initialize( + ContactPositionConstraint pc, Transform xfA, Transform xfB, int index) { assert(pc.pointCount > 0); final Rot xfAq = xfA.q; @@ -1008,10 +1052,14 @@ class PositionSolverManifold { // separation = Vec2.dot(temp, normal) - pc.radiusA - pc.radiusB; final Vec2 plocalPoint = pc.localPoint; final Vec2 pLocalPoints0 = pc.localPoints[0]; - final double pointAx = (xfAq.c * plocalPoint.x - xfAq.s * plocalPoint.y) + xfA.p.x; - final double pointAy = (xfAq.s * plocalPoint.x + xfAq.c * plocalPoint.y) + xfA.p.y; - final double pointBx = (xfBq.c * pLocalPoints0.x - xfBq.s * pLocalPoints0.y) + xfB.p.x; - final double pointBy = (xfBq.s * pLocalPoints0.x + xfBq.c * pLocalPoints0.y) + xfB.p.y; + final double pointAx = + (xfAq.c * plocalPoint.x - xfAq.s * plocalPoint.y) + xfA.p.x; + final double pointAy = + (xfAq.s * plocalPoint.x + xfAq.c * plocalPoint.y) + xfA.p.y; + final double pointBx = + (xfBq.c * pLocalPoints0.x - xfBq.s * pLocalPoints0.y) + xfB.p.x; + final double pointBy = + (xfBq.s * pLocalPoints0.x + xfBq.c * pLocalPoints0.y) + xfB.p.y; normal.x = pointBx - pointAx; normal.y = pointBy - pointAy; normal.normalize(); @@ -1020,7 +1068,8 @@ class PositionSolverManifold { point.y = (pointAy + pointBy) * .5; final double tempx = pointBx - pointAx; final double tempy = pointBy - pointAy; - separation = tempx * normal.x + tempy * normal.y - pc.radiusA - pc.radiusB; + separation = + tempx * normal.x + tempy * normal.y - pc.radiusA - pc.radiusB; break; case ManifoldType.FACE_A: @@ -1035,14 +1084,19 @@ class PositionSolverManifold { final Vec2 pcLocalPoint = pc.localPoint; normal.x = xfAq.c * pcLocalNormal.x - xfAq.s * pcLocalNormal.y; normal.y = xfAq.s * pcLocalNormal.x + xfAq.c * pcLocalNormal.y; - final double planePointx = (xfAq.c * pcLocalPoint.x - xfAq.s * pcLocalPoint.y) + xfA.p.x; - final double planePointy = (xfAq.s * pcLocalPoint.x + xfAq.c * pcLocalPoint.y) + xfA.p.y; - - final double clipPointx = (xfBq.c * pcLocalPointsI.x - xfBq.s * pcLocalPointsI.y) + xfB.p.x; - final double clipPointy = (xfBq.s * pcLocalPointsI.x + xfBq.c * pcLocalPointsI.y) + xfB.p.y; + final double planePointx = + (xfAq.c * pcLocalPoint.x - xfAq.s * pcLocalPoint.y) + xfA.p.x; + final double planePointy = + (xfAq.s * pcLocalPoint.x + xfAq.c * pcLocalPoint.y) + xfA.p.y; + + final double clipPointx = + (xfBq.c * pcLocalPointsI.x - xfBq.s * pcLocalPointsI.y) + xfB.p.x; + final double clipPointy = + (xfBq.s * pcLocalPointsI.x + xfBq.c * pcLocalPointsI.y) + xfB.p.y; final double tempx = clipPointx - planePointx; final double tempy = clipPointy - planePointy; - separation = tempx * normal.x + tempy * normal.y - pc.radiusA - pc.radiusB; + separation = + tempx * normal.x + tempy * normal.y - pc.radiusA - pc.radiusB; point.x = clipPointx; point.y = clipPointy; break; @@ -1062,14 +1116,19 @@ class PositionSolverManifold { final Vec2 pcLocalPoint = pc.localPoint; normal.x = xfBq.c * pcLocalNormal.x - xfBq.s * pcLocalNormal.y; normal.y = xfBq.s * pcLocalNormal.x + xfBq.c * pcLocalNormal.y; - final double planePointx = (xfBq.c * pcLocalPoint.x - xfBq.s * pcLocalPoint.y) + xfB.p.x; - final double planePointy = (xfBq.s * pcLocalPoint.x + xfBq.c * pcLocalPoint.y) + xfB.p.y; - - final double clipPointx = (xfAq.c * pcLocalPointsI.x - xfAq.s * pcLocalPointsI.y) + xfA.p.x; - final double clipPointy = (xfAq.s * pcLocalPointsI.x + xfAq.c * pcLocalPointsI.y) + xfA.p.y; + final double planePointx = + (xfBq.c * pcLocalPoint.x - xfBq.s * pcLocalPoint.y) + xfB.p.x; + final double planePointy = + (xfBq.s * pcLocalPoint.x + xfBq.c * pcLocalPoint.y) + xfB.p.y; + + final double clipPointx = + (xfAq.c * pcLocalPointsI.x - xfAq.s * pcLocalPointsI.y) + xfA.p.x; + final double clipPointy = + (xfAq.s * pcLocalPointsI.x + xfAq.c * pcLocalPointsI.y) + xfA.p.y; final double tempx = clipPointx - planePointx; final double tempy = clipPointy - planePointy; - separation = tempx * normal.x + tempy * normal.y - pc.radiusA - pc.radiusB; + separation = + tempx * normal.x + tempy * normal.y - pc.radiusA - pc.radiusB; point.x = clipPointx; point.y = clipPointy; normal.x *= -1; diff --git a/lib/box2d/src/dynamics/contacts/contact_velocity_constraint.dart b/lib/src/dynamics/contacts/contact_velocity_constraint.dart similarity index 91% rename from lib/box2d/src/dynamics/contacts/contact_velocity_constraint.dart rename to lib/src/dynamics/contacts/contact_velocity_constraint.dart index c26fb57..9d8f022 100644 --- a/lib/box2d/src/dynamics/contacts/contact_velocity_constraint.dart +++ b/lib/src/dynamics/contacts/contact_velocity_constraint.dart @@ -35,14 +35,17 @@ class VelocityConstraintPoint { } class ContactVelocityConstraint { - List points = new List(Settings.maxManifoldPoints); + List points = + new List(Settings.maxManifoldPoints); final Vec2 normal = new Vec2.zero(); final Mat22 normalMass = new Mat22.zero(); final Mat22 K = new Mat22.zero(); int indexA = 0; int indexB = 0; - double invMassA = 0.0, invMassB = 0.0; - double invIA = 0.0, invIB = 0.0; + double invMassA = 0.0, + invMassB = 0.0; + double invIA = 0.0, + invIB = 0.0; double friction = 0.0; double restitution = 0.0; double tangentSpeed = 0.0; @@ -54,4 +57,4 @@ class ContactVelocityConstraint { points[i] = new VelocityConstraintPoint(); } } -} \ No newline at end of file +} diff --git a/lib/box2d/src/dynamics/contacts/edge_and_circle_contact.dart b/lib/src/dynamics/contacts/edge_and_circle_contact.dart similarity index 88% rename from lib/box2d/src/dynamics/contacts/edge_and_circle_contact.dart rename to lib/src/dynamics/contacts/edge_and_circle_contact.dart index c771c04..dee464a 100644 --- a/lib/box2d/src/dynamics/contacts/edge_and_circle_contact.dart +++ b/lib/src/dynamics/contacts/edge_and_circle_contact.dart @@ -25,17 +25,16 @@ part of box2d; class EdgeAndCircleContact extends Contact { - EdgeAndCircleContact(IWorldPool argPool) : super(argPool); void init(Fixture fA, int indexA, Fixture fB, int indexB) { super.init(fA, indexA, fB, indexB); - assert (m_fixtureA.getType() == ShapeType.EDGE); - assert (m_fixtureB.getType() == ShapeType.CIRCLE); + assert(m_fixtureA.getType() == ShapeType.EDGE); + assert(m_fixtureB.getType() == ShapeType.CIRCLE); } void evaluate(Manifold manifold, Transform xfA, Transform xfB) { - pool.getCollision().collideEdgeAndCircle(manifold, m_fixtureA.getShape(), xfA, - m_fixtureB.getShape(), xfB); + pool.getCollision().collideEdgeAndCircle( + manifold, m_fixtureA.getShape(), xfA, m_fixtureB.getShape(), xfB); } } diff --git a/lib/box2d/src/dynamics/contacts/edge_and_polygon_contact.dart b/lib/src/dynamics/contacts/edge_and_polygon_contact.dart similarity index 88% rename from lib/box2d/src/dynamics/contacts/edge_and_polygon_contact.dart rename to lib/src/dynamics/contacts/edge_and_polygon_contact.dart index 605146d..c6c1adf 100644 --- a/lib/box2d/src/dynamics/contacts/edge_and_polygon_contact.dart +++ b/lib/src/dynamics/contacts/edge_and_polygon_contact.dart @@ -25,17 +25,16 @@ part of box2d; class EdgeAndPolygonContact extends Contact { - EdgeAndPolygonContact(IWorldPool argPool) : super(argPool); void init(Fixture fA, int indexA, Fixture fB, int indexB) { super.init(fA, indexA, fB, indexB); - assert (m_fixtureA.getType() == ShapeType.EDGE); - assert (m_fixtureB.getType() == ShapeType.POLYGON); + assert(m_fixtureA.getType() == ShapeType.EDGE); + assert(m_fixtureB.getType() == ShapeType.POLYGON); } void evaluate(Manifold manifold, Transform xfA, Transform xfB) { - pool.getCollision().collideEdgeAndPolygon(manifold, m_fixtureA.getShape(), xfA, - m_fixtureB.getShape(), xfB); + pool.getCollision().collideEdgeAndPolygon( + manifold, m_fixtureA.getShape(), xfA, m_fixtureB.getShape(), xfB); } } diff --git a/lib/box2d/src/dynamics/contacts/polygon_and_circle_contact.dart b/lib/src/dynamics/contacts/polygon_and_circle_contact.dart similarity index 88% rename from lib/box2d/src/dynamics/contacts/polygon_and_circle_contact.dart rename to lib/src/dynamics/contacts/polygon_and_circle_contact.dart index 6853b11..c8006f9 100644 --- a/lib/box2d/src/dynamics/contacts/polygon_and_circle_contact.dart +++ b/lib/src/dynamics/contacts/polygon_and_circle_contact.dart @@ -25,17 +25,16 @@ part of box2d; class PolygonAndCircleContact extends Contact { - PolygonAndCircleContact(IWorldPool argPool) : super(argPool); void init0(Fixture fixtureA, Fixture fixtureB) { init(fixtureA, 0, fixtureB, 0); - assert (m_fixtureA.getType() == ShapeType.POLYGON); - assert (m_fixtureB.getType() == ShapeType.CIRCLE); + assert(m_fixtureA.getType() == ShapeType.POLYGON); + assert(m_fixtureB.getType() == ShapeType.CIRCLE); } void evaluate(Manifold manifold, Transform xfA, Transform xfB) { - pool.getCollision().collidePolygonAndCircle(manifold, m_fixtureA.getShape(), - xfA, m_fixtureB.getShape(), xfB); + pool.getCollision().collidePolygonAndCircle( + manifold, m_fixtureA.getShape(), xfA, m_fixtureB.getShape(), xfB); } } diff --git a/lib/box2d/src/dynamics/contacts/polygon_contact.dart b/lib/src/dynamics/contacts/polygon_contact.dart similarity index 86% rename from lib/box2d/src/dynamics/contacts/polygon_contact.dart rename to lib/src/dynamics/contacts/polygon_contact.dart index 9b84cd1..e0ba40d 100644 --- a/lib/box2d/src/dynamics/contacts/polygon_contact.dart +++ b/lib/src/dynamics/contacts/polygon_contact.dart @@ -25,20 +25,18 @@ part of box2d; class PolygonContact extends Contact { - - PolygonContact(IWorldPool argPool) : super (argPool) { + PolygonContact(IWorldPool argPool) : super(argPool) { assert(pool != null); } void init0(Fixture fixtureA, Fixture fixtureB) { init(fixtureA, 0, fixtureB, 0); - assert (m_fixtureA.getType() == ShapeType.POLYGON); - assert (m_fixtureB.getType() == ShapeType.POLYGON); + assert(m_fixtureA.getType() == ShapeType.POLYGON); + assert(m_fixtureB.getType() == ShapeType.POLYGON); } void evaluate(Manifold manifold, Transform xfA, Transform xfB) { - pool.getCollision().collidePolygons(manifold, m_fixtureA.getShape(), xfA, - m_fixtureB.getShape(), xfB); + pool.getCollision().collidePolygons( + manifold, m_fixtureA.getShape(), xfA, m_fixtureB.getShape(), xfB); } - } diff --git a/lib/box2d/src/dynamics/contacts/position.dart b/lib/src/dynamics/contacts/position.dart similarity index 100% rename from lib/box2d/src/dynamics/contacts/position.dart rename to lib/src/dynamics/contacts/position.dart diff --git a/lib/box2d/src/dynamics/contacts/velocity.dart b/lib/src/dynamics/contacts/velocity.dart similarity index 100% rename from lib/box2d/src/dynamics/contacts/velocity.dart rename to lib/src/dynamics/contacts/velocity.dart diff --git a/lib/box2d/src/dynamics/filter.dart b/lib/src/dynamics/filter.dart similarity index 100% rename from lib/box2d/src/dynamics/filter.dart rename to lib/src/dynamics/filter.dart diff --git a/lib/box2d/src/dynamics/fixture.dart b/lib/src/dynamics/fixture.dart similarity index 96% rename from lib/box2d/src/dynamics/fixture.dart rename to lib/src/dynamics/fixture.dart index ddf741e..56fde3b 100644 --- a/lib/box2d/src/dynamics/fixture.dart +++ b/lib/src/dynamics/fixture.dart @@ -34,7 +34,6 @@ part of box2d; * @author daniel */ class Fixture { - double m_density = 0.0; Fixture m_next; @@ -286,7 +285,8 @@ class Fixture { * @return distance */ double computeDistance(Vec2 p, int childIndex, Vec2 normalOut) { - return m_shape.computeDistanceToOut(m_body.getTransform(), p, childIndex, normalOut); + return m_shape.computeDistanceToOut( + m_body.getTransform(), p, childIndex, normalOut); } // We need separation create/destroy functions from the constructor/destructor because @@ -300,7 +300,6 @@ class Fixture { m_body = body; m_next = null; - m_filter.set(def.filter); m_isSensor = def._isSensor; @@ -392,7 +391,8 @@ class Fixture { * @param xf1 * @param xf2 */ - void synchronize(BroadPhase broadPhase, final Transform transform1, final Transform transform2) { + void synchronize(BroadPhase broadPhase, final Transform transform1, + final Transform transform2) { if (m_proxyCount == 0) { return; } @@ -406,10 +406,18 @@ class Fixture { m_shape.computeAABB(aabb1, transform1, proxy.childIndex); m_shape.computeAABB(aab, transform2, proxy.childIndex); - proxy.aabb.lowerBound.x = aabb1.lowerBound.x < aab.lowerBound.x ? aabb1.lowerBound.x : aab.lowerBound.x; - proxy.aabb.lowerBound.y = aabb1.lowerBound.y < aab.lowerBound.y ? aabb1.lowerBound.y : aab.lowerBound.y; - proxy.aabb.upperBound.x = aabb1.upperBound.x > aab.upperBound.x ? aabb1.upperBound.x : aab.upperBound.x; - proxy.aabb.upperBound.y = aabb1.upperBound.y > aab.upperBound.y ? aabb1.upperBound.y : aab.upperBound.y; + proxy.aabb.lowerBound.x = aabb1.lowerBound.x < aab.lowerBound.x + ? aabb1.lowerBound.x + : aab.lowerBound.x; + proxy.aabb.lowerBound.y = aabb1.lowerBound.y < aab.lowerBound.y + ? aabb1.lowerBound.y + : aab.lowerBound.y; + proxy.aabb.upperBound.x = aabb1.upperBound.x > aab.upperBound.x + ? aabb1.upperBound.x + : aab.upperBound.x; + proxy.aabb.upperBound.y = aabb1.upperBound.y > aab.upperBound.y + ? aabb1.upperBound.y + : aab.upperBound.y; _displacement.x = transform2.p.x - transform1.p.x; _displacement.y = transform2.p.y - transform1.p.y; diff --git a/lib/box2d/src/dynamics/fixture_def.dart b/lib/src/dynamics/fixture_def.dart similarity index 100% rename from lib/box2d/src/dynamics/fixture_def.dart rename to lib/src/dynamics/fixture_def.dart diff --git a/lib/box2d/src/dynamics/fixture_proxy.dart b/lib/src/dynamics/fixture_proxy.dart similarity index 100% rename from lib/box2d/src/dynamics/fixture_proxy.dart rename to lib/src/dynamics/fixture_proxy.dart diff --git a/lib/box2d/src/dynamics/island.dart b/lib/src/dynamics/island.dart similarity index 93% rename from lib/box2d/src/dynamics/island.dart rename to lib/src/dynamics/island.dart index ce9df59..dbefbb4 100644 --- a/lib/box2d/src/dynamics/island.dart +++ b/lib/src/dynamics/island.dart @@ -146,7 +146,6 @@ part of box2d; * This is an internal class. */ class Island { - ContactListener m_listener; List m_bodies; @@ -188,7 +187,8 @@ class Island { // dynamic array if (m_velocities == null || m_bodyCapacity > m_velocities.length) { - final List old = m_velocities == null ? new List(0) : m_velocities; + final List old = + m_velocities == null ? new List(0) : m_velocities; m_velocities = new List(m_bodyCapacity); Settings.arraycopy(old, 0, m_velocities, 0, old.length); for (int i = old.length; i < m_velocities.length; i++) { @@ -198,7 +198,8 @@ class Island { // dynamic array if (m_positions == null || m_bodyCapacity > m_positions.length) { - final List old = m_positions == null ? new List(0) : m_positions; + final List old = + m_positions == null ? new List(0) : m_positions; m_positions = new List(m_bodyCapacity); Settings.arraycopy(old, 0, m_positions, 0, old.length); for (int i = old.length; i < m_positions.length; i++) { @@ -319,9 +320,11 @@ class Island { double translationx = v.x * h; double translationy = v.y * h; - if (translationx * translationx + translationy * translationy > Settings.maxTranslationSquared) { - double ratio = Settings.maxTranslation - / Math.sqrt(translationx * translationx + translationy * translationy); + if (translationx * translationx + translationy * translationy > + Settings.maxTranslationSquared) { + double ratio = Settings.maxTranslation / + Math.sqrt( + translationx * translationx + translationy * translationy); v.x *= ratio; v.y *= ratio; } @@ -379,8 +382,10 @@ class Island { if (allowSleep) { double minSleepTime = double.MAX_FINITE; - final double linTolSqr = Settings.linearSleepTolerance * Settings.linearSleepTolerance; - final double angTolSqr = Settings.angularSleepTolerance * Settings.angularSleepTolerance; + final double linTolSqr = + Settings.linearSleepTolerance * Settings.linearSleepTolerance; + final double angTolSqr = + Settings.angularSleepTolerance * Settings.angularSleepTolerance; for (int i = 0; i < m_bodyCount; ++i) { Body b = m_bodies[i]; @@ -388,9 +393,9 @@ class Island { continue; } - if ((b.m_flags & Body.e_autoSleepFlag) == 0 - || b.m_angularVelocity * b.m_angularVelocity > angTolSqr - || Vec2.dot(b.m_linearVelocity, b.m_linearVelocity) > linTolSqr) { + if ((b.m_flags & Body.e_autoSleepFlag) == 0 || + b.m_angularVelocity * b.m_angularVelocity > angTolSqr || + Vec2.dot(b.m_linearVelocity, b.m_linearVelocity) > linTolSqr) { b.m_sleepTime = 0.0; minSleepTime = 0.0; } else { @@ -412,8 +417,8 @@ class Island { final ContactSolverDef _toiSolverDef = new ContactSolverDef(); void solveTOI(TimeStep subStep, int toiIndexA, int toiIndexB) { - assert (toiIndexA < m_bodyCount); - assert (toiIndexB < m_bodyCount); + assert(toiIndexA < m_bodyCount); + assert(toiIndexB < m_bodyCount); // Initialize the body state. for (int i = 0; i < m_bodyCount; ++i) { @@ -434,7 +439,8 @@ class Island { // Solve position constraints. for (int i = 0; i < subStep.positionIterations; ++i) { - bool contactsOkay = _toiContactSolver.solveTOIPositionConstraints(toiIndexA, toiIndexB); + bool contactsOkay = + _toiContactSolver.solveTOIPositionConstraints(toiIndexA, toiIndexB); if (contactsOkay) { break; } @@ -503,10 +509,11 @@ class Island { // Check for large velocities double translationx = v.x * h; double translationy = v.y * h; - if (translationx * translationx + translationy * translationy > Settings.maxTranslationSquared) { - double ratio = - Settings.maxTranslation - / Math.sqrt(translationx * translationx + translationy * translationy); + if (translationx * translationx + translationy * translationy > + Settings.maxTranslationSquared) { + double ratio = Settings.maxTranslation / + Math.sqrt( + translationx * translationx + translationy * translationy); v.mulLocal(ratio); } @@ -543,19 +550,19 @@ class Island { } void addBody(Body body) { - assert (m_bodyCount < m_bodyCapacity); + assert(m_bodyCount < m_bodyCapacity); body.m_islandIndex = m_bodyCount; m_bodies[m_bodyCount] = body; ++m_bodyCount; } void addContact(Contact contact) { - assert (m_contactCount < m_contactCapacity); + assert(m_contactCount < m_contactCapacity); m_contacts[m_contactCount++] = contact; } void addJoint(Joint joint) { - assert (m_jointCount < m_jointCapacity); + assert(m_jointCount < m_jointCapacity); m_joints[m_jointCount++] = joint; } @@ -580,4 +587,3 @@ class Island { } } } - diff --git a/lib/box2d/src/dynamics/joints/constant_volume_joints.dart b/lib/src/dynamics/joints/constant_volume_joints.dart similarity index 85% rename from lib/box2d/src/dynamics/joints/constant_volume_joints.dart rename to lib/src/dynamics/joints/constant_volume_joints.dart index 9ad5c86..d809cef 100644 --- a/lib/box2d/src/dynamics/joints/constant_volume_joints.dart +++ b/lib/src/dynamics/joints/constant_volume_joints.dart @@ -25,7 +25,6 @@ part of box2d; class ConstantVolumeJoint extends Joint { - final List _bodies; Float64List _targetLengths; double _targetVolume = 0.0; @@ -60,7 +59,10 @@ class ConstantVolumeJoint extends Joint { _targetLengths = new Float64List(_bodies.length); for (int i = 0; i < _targetLengths.length; ++i) { final int next = (i == _targetLengths.length - 1) ? 0 : i + 1; - double dist = _bodies[i].getWorldCenter().sub(_bodies[next].getWorldCenter()).length(); + double dist = _bodies[i] + .getWorldCenter() + .sub(_bodies[next].getWorldCenter()) + .length(); _targetLengths[i] = dist; } _targetVolume = getBodyArea(); @@ -76,7 +78,8 @@ class ConstantVolumeJoint extends Joint { djd.frequencyHz = def.frequencyHz; // 20.0; djd.dampingRatio = def.dampingRatio; // 50.0; djd.collideConnected = def.collideConnected; - djd.initialize(_bodies[i], _bodies[next], _bodies[i].getWorldCenter(), _bodies[next].getWorldCenter()); + djd.initialize(_bodies[i], _bodies[next], _bodies[i].getWorldCenter(), + _bodies[next].getWorldCenter()); _distanceJoints[i] = _world.createJoint(djd); } } else { @@ -99,7 +102,8 @@ class ConstantVolumeJoint extends Joint { double area = 0.0; for (int i = 0; i < _bodies.length; ++i) { final int next = (i == _bodies.length - 1) ? 0 : i + 1; - area += _bodies[i].getWorldCenter().x * _bodies[next].getWorldCenter().y - _bodies[next].getWorldCenter().x * _bodies[i].getWorldCenter().y; + area += _bodies[i].getWorldCenter().x * _bodies[next].getWorldCenter().y - + _bodies[next].getWorldCenter().x * _bodies[i].getWorldCenter().y; } area *= .5; return area; @@ -109,7 +113,10 @@ class ConstantVolumeJoint extends Joint { double area = 0.0; for (int i = 0; i < _bodies.length; ++i) { final int next = (i == _bodies.length - 1) ? 0 : i + 1; - area += positions[_bodies[i].m_islandIndex].c.x * positions[_bodies[next].m_islandIndex].c.y - positions[_bodies[next].m_islandIndex].c.x * positions[_bodies[i].m_islandIndex].c.y; + area += positions[_bodies[i].m_islandIndex].c.x * + positions[_bodies[next].m_islandIndex].c.y - + positions[_bodies[next].m_islandIndex].c.x * + positions[_bodies[i].m_islandIndex].c.y; } area *= .5; return area; @@ -119,8 +126,10 @@ class ConstantVolumeJoint extends Joint { double perimeter = 0.0; for (int i = 0; i < _bodies.length; ++i) { final int next = (i == _bodies.length - 1) ? 0 : i + 1; - double dx = positions[_bodies[next].m_islandIndex].c.x - positions[_bodies[i].m_islandIndex].c.x; - double dy = positions[_bodies[next].m_islandIndex].c.y - positions[_bodies[i].m_islandIndex].c.y; + double dx = positions[_bodies[next].m_islandIndex].c.x - + positions[_bodies[i].m_islandIndex].c.x; + double dy = positions[_bodies[next].m_islandIndex].c.y - + positions[_bodies[i].m_islandIndex].c.y; double dist = Math.sqrt(dx * dx + dy * dy); if (dist < Settings.EPSILON) { dist = 1.0; @@ -138,10 +147,12 @@ class ConstantVolumeJoint extends Joint { bool done = true; for (int i = 0; i < _bodies.length; ++i) { final int next = (i == _bodies.length - 1) ? 0 : i + 1; - delta.setXY(toExtrude * (_normals[i].x + _normals[next].x), toExtrude * (_normals[i].y + _normals[next].y)); + delta.setXY(toExtrude * (_normals[i].x + _normals[next].x), + toExtrude * (_normals[i].y + _normals[next].y)); // sumdeltax += dx; double normSqrd = delta.lengthSquared(); - if (normSqrd > Settings.maxLinearCorrection * Settings.maxLinearCorrection) { + if (normSqrd > + Settings.maxLinearCorrection * Settings.maxLinearCorrection) { delta.mulLocal(Settings.maxLinearCorrection / Math.sqrt(normSqrd)); } if (normSqrd > Settings.linearSlop * Settings.linearSlop) { @@ -178,8 +189,10 @@ class ConstantVolumeJoint extends Joint { // Settings.maxLinearCorrection); // _m_impulse = lambda; for (int i = 0; i < _bodies.length; ++i) { - velocities[_bodies[i].m_islandIndex].v.x += _bodies[i].m_invMass * d[i].y * .5 * _m_impulse; - velocities[_bodies[i].m_islandIndex].v.y += _bodies[i].m_invMass * -d[i].x * .5 * _m_impulse; + velocities[_bodies[i].m_islandIndex].v.x += + _bodies[i].m_invMass * d[i].y * .5 * _m_impulse; + velocities[_bodies[i].m_islandIndex].v.y += + _bodies[i].m_invMass * -d[i].x * .5 * _m_impulse; } } else { _m_impulse = 0.0; @@ -213,8 +226,10 @@ class ConstantVolumeJoint extends Joint { _m_impulse += lambda; // System.out.println(_m_impulse); for (int i = 0; i < _bodies.length; ++i) { - velocities[_bodies[i].m_islandIndex].v.x += _bodies[i].m_invMass * d[i].y * .5 * lambda; - velocities[_bodies[i].m_islandIndex].v.y += _bodies[i].m_invMass * -d[i].x * .5 * lambda; + velocities[_bodies[i].m_islandIndex].v.x += + _bodies[i].m_invMass * d[i].y * .5 * lambda; + velocities[_bodies[i].m_islandIndex].v.y += + _bodies[i].m_invMass * -d[i].x * .5 * lambda; } } diff --git a/lib/box2d/src/dynamics/joints/constant_volume_joints_def.dart b/lib/src/dynamics/joints/constant_volume_joints_def.dart similarity index 98% rename from lib/box2d/src/dynamics/joints/constant_volume_joints_def.dart rename to lib/src/dynamics/joints/constant_volume_joints_def.dart index b6d3d98..ac4bc48 100644 --- a/lib/box2d/src/dynamics/joints/constant_volume_joints_def.dart +++ b/lib/src/dynamics/joints/constant_volume_joints_def.dart @@ -33,7 +33,7 @@ class ConstantVolumeJointDef extends JointDef { double frequencyHz = 0.0; double dampingRatio = 0.0; - List bodies= new List(); + List bodies = new List(); List joints; ConstantVolumeJointDef() : super(JointType.CONSTANT_VOLUME) { diff --git a/lib/box2d/src/dynamics/joints/distance_joint.dart b/lib/src/dynamics/joints/distance_joint.dart similarity index 92% rename from lib/box2d/src/dynamics/joints/distance_joint.dart rename to lib/src/dynamics/joints/distance_joint.dart index f92d2ca..92186f2 100644 --- a/lib/box2d/src/dynamics/joints/distance_joint.dart +++ b/lib/src/dynamics/joints/distance_joint.dart @@ -37,7 +37,6 @@ part of box2d; */ class DistanceJoint extends Joint { - double _m_frequencyHz = 0.0; double _m_dampingRatio = 0.0; double _m_bias = 0.0; @@ -64,9 +63,9 @@ class DistanceJoint extends Joint { double _m_mass = 0.0; DistanceJoint(IWorldPool argWorld, final DistanceJointDef def) - : super(argWorld, def), - _m_localAnchorA = def.localAnchorA.clone(), - _m_localAnchorB = def.localAnchorB.clone() { + : super(argWorld, def), + _m_localAnchorA = def.localAnchorA.clone(), + _m_localAnchorB = def.localAnchorB.clone() { _m_length = def.length; _m_frequencyHz = def.frequencyHz; _m_dampingRatio = def.dampingRatio; @@ -85,7 +84,7 @@ class DistanceJoint extends Joint { } void setLength(double argLength) { - _m_length = argLength; + _m_length = argLength; } void setDampingRatio(double damp) { @@ -96,12 +95,10 @@ class DistanceJoint extends Joint { return _m_dampingRatio; } - void getAnchorA(Vec2 argOut) { m_bodyA.getWorldPointToOut(_m_localAnchorA, argOut); } - void getAnchorB(Vec2 argOut) { m_bodyB.getWorldPointToOut(_m_localAnchorB, argOut); } @@ -117,7 +114,7 @@ class DistanceJoint extends Joint { /** * Get the reaction force given the inverse time step. Unit is N. */ - + void getReactionForce(double inv_dt, Vec2 argOut) { argOut.x = _m_impulse * _m_u.x * inv_dt; argOut.y = _m_impulse * _m_u.y * inv_dt; @@ -127,14 +124,12 @@ class DistanceJoint extends Joint { * Get the reaction torque given the inverse time step. Unit is N*m. This is always zero for a * distance joint. */ - + double getReactionTorque(double inv_dt) { return 0.0; } - void initVelocityConstraints(final SolverData data) { - _m_indexA = m_bodyA.m_islandIndex; _m_indexB = m_bodyB.m_islandIndex; _m_localCenterA.set(m_bodyA.m_sweep.localCenter); @@ -161,8 +156,10 @@ class DistanceJoint extends Joint { qB.setAngle(aB); // use _m_u as temporary variable - Rot.mulToOutUnsafe(qA, _m_u.set(_m_localAnchorA).subLocal(_m_localCenterA), _m_rA); - Rot.mulToOutUnsafe(qB, _m_u.set(_m_localAnchorB).subLocal(_m_localCenterB), _m_rB); + Rot.mulToOutUnsafe( + qA, _m_u.set(_m_localAnchorA).subLocal(_m_localCenterA), _m_rA); + Rot.mulToOutUnsafe( + qB, _m_u.set(_m_localAnchorB).subLocal(_m_localCenterB), _m_rB); _m_u.set(cB).addLocal(_m_rB).subLocal(cA).subLocal(_m_rA); pool.pushRot(2); @@ -176,10 +173,12 @@ class DistanceJoint extends Joint { _m_u.setXY(0.0, 0.0); } - double crAu = Vec2.cross(_m_rA, _m_u); double crBu = Vec2.cross(_m_rB, _m_u); - double invMass = _m_invMassA + _m_invIA * crAu * crAu + _m_invMassB + _m_invIB * crBu * crBu; + double invMass = _m_invMassA + + _m_invIA * crAu * crAu + + _m_invMassB + + _m_invIB * crBu * crBu; // Compute the effective mass matrix. _m_mass = invMass != 0.0 ? 1.0 / invMass : 0.0; @@ -234,7 +233,6 @@ class DistanceJoint extends Joint { data.velocities[_m_indexB].w = wB; } - void solveVelocityConstraints(final SolverData data) { Vec2 vA = data.velocities[_m_indexA].v; double wA = data.velocities[_m_indexA].w; @@ -254,7 +252,6 @@ class DistanceJoint extends Joint { double impulse = -_m_mass * (Cdot + _m_bias + _m_gamma * _m_impulse); _m_impulse += impulse; - double Px = impulse * _m_u.x; double Py = impulse * _m_u.y; @@ -273,7 +270,6 @@ class DistanceJoint extends Joint { pool.pushVec2(2); } - bool solvePositionConstraints(final SolverData data) { if (_m_frequencyHz > 0.0) { return true; @@ -292,14 +288,16 @@ class DistanceJoint extends Joint { qA.setAngle(aA); qB.setAngle(aB); - Rot.mulToOutUnsafe(qA, u.set(_m_localAnchorA).subLocal(_m_localCenterA), rA); - Rot.mulToOutUnsafe(qB, u.set(_m_localAnchorB).subLocal(_m_localCenterB), rB); + Rot.mulToOutUnsafe( + qA, u.set(_m_localAnchorA).subLocal(_m_localCenterA), rA); + Rot.mulToOutUnsafe( + qB, u.set(_m_localAnchorB).subLocal(_m_localCenterB), rB); u.set(cB).addLocal(rB).subLocal(cA).subLocal(rA); - double length = u.normalize(); double C = length - _m_length; - C = MathUtils.clampDouble(C, -Settings.maxLinearCorrection, Settings.maxLinearCorrection); + C = MathUtils.clampDouble( + C, -Settings.maxLinearCorrection, Settings.maxLinearCorrection); double impulse = -_m_mass * C; double Px = impulse * u.x; diff --git a/lib/box2d/src/dynamics/joints/distance_joint_def.dart b/lib/src/dynamics/joints/distance_joint_def.dart similarity index 95% rename from lib/box2d/src/dynamics/joints/distance_joint_def.dart rename to lib/src/dynamics/joints/distance_joint_def.dart index be3906d..4b3265b 100644 --- a/lib/box2d/src/dynamics/joints/distance_joint_def.dart +++ b/lib/src/dynamics/joints/distance_joint_def.dart @@ -52,8 +52,7 @@ class DistanceJointDef extends JointDef { */ double dampingRatio = 0.0; - DistanceJointDef() - : super(JointType.DISTANCE); + DistanceJointDef() : super(JointType.DISTANCE); /** * Initialize the bodies, anchors, and length using the world anchors. @@ -63,7 +62,8 @@ class DistanceJointDef extends JointDef { * @param anchor1 World anchor on first body * @param anchor2 World anchor on second body */ - void initialize(final Body b1, final Body b2, final Vec2 anchor1, final Vec2 anchor2) { + void initialize( + final Body b1, final Body b2, final Vec2 anchor1, final Vec2 anchor2) { bodyA = b1; bodyB = b2; localAnchorA.set(bodyA.getLocalPoint(anchor1)); diff --git a/lib/box2d/src/dynamics/joints/friction_joint.dart b/lib/src/dynamics/joints/friction_joint.dart similarity index 96% rename from lib/box2d/src/dynamics/joints/friction_joint.dart rename to lib/src/dynamics/joints/friction_joint.dart index 12598af..0f082c6 100644 --- a/lib/box2d/src/dynamics/joints/friction_joint.dart +++ b/lib/src/dynamics/joints/friction_joint.dart @@ -55,7 +55,6 @@ class FrictionJoint extends Joint { m_localAnchorA = new Vec2.copy(def.localAnchorA), m_localAnchorB = new Vec2.copy(def.localAnchorB), m_linearImpulse = new Vec2.zero() { - m_maxForce = def.maxForce; m_maxTorque = def.maxTorque; } @@ -76,12 +75,10 @@ class FrictionJoint extends Joint { m_bodyB.getWorldPointToOut(m_localAnchorB, argOut); } - void getReactionForce(double inv_dt, Vec2 argOut) { argOut.set(m_linearImpulse).mulLocal(inv_dt); } - double getReactionTorque(double inv_dt) { return inv_dt * m_angularImpulse; } @@ -126,7 +123,6 @@ class FrictionJoint extends Joint { Vec2 vB = data.velocities[m_indexB].v; double wB = data.velocities[m_indexB].w; - final Vec2 temp = pool.popVec2(); final Rot qA = pool.popRot(); final Rot qB = pool.popRot(); @@ -135,8 +131,10 @@ class FrictionJoint extends Joint { qB.setAngle(aB); // Compute the effective mass matrix. - Rot.mulToOutUnsafe(qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), m_rA); - Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), m_rB); + Rot.mulToOutUnsafe( + qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), m_rA); + Rot.mulToOutUnsafe( + qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), m_rB); // J = [-I -r1_skew I r2_skew] // [ 0 -1 0 1] @@ -219,7 +217,8 @@ class FrictionJoint extends Joint { double oldImpulse = m_angularImpulse; double maxImpulse = h * m_maxTorque; - m_angularImpulse = MathUtils.clampDouble(m_angularImpulse + impulse, -maxImpulse, maxImpulse); + m_angularImpulse = MathUtils.clampDouble( + m_angularImpulse + impulse, -maxImpulse, maxImpulse); impulse = m_angularImpulse - oldImpulse; wA -= iA * impulse; @@ -239,7 +238,6 @@ class FrictionJoint extends Joint { Mat22.mulToOutUnsafeVec2_(m_linearMass, Cdot, impulse); impulse.negateLocal(); - final Vec2 oldImpulse = pool.popVec2(); oldImpulse.set(m_linearImpulse); m_linearImpulse.addLocal(impulse); @@ -260,7 +258,6 @@ class FrictionJoint extends Joint { temp.set(impulse).mulLocal(mB); vB.addLocal(temp); wB += iB * Vec2.cross(m_rB, impulse); - } // data.velocities[m_indexA].v.set(vA); @@ -275,7 +272,6 @@ class FrictionJoint extends Joint { pool.pushVec2(4); } - bool solvePositionConstraints(final SolverData data) { return true; } diff --git a/lib/box2d/src/dynamics/joints/friction_joint_def.dart b/lib/src/dynamics/joints/friction_joint_def.dart similarity index 95% rename from lib/box2d/src/dynamics/joints/friction_joint_def.dart rename to lib/src/dynamics/joints/friction_joint_def.dart index 1580fa1..01b0880 100644 --- a/lib/box2d/src/dynamics/joints/friction_joint_def.dart +++ b/lib/src/dynamics/joints/friction_joint_def.dart @@ -52,9 +52,9 @@ class FrictionJointDef extends JointDef { double maxTorque = 0.0; FrictionJointDef() - : super(JointType.FRICTION), - localAnchorA = new Vec2.zero(), - localAnchorB = new Vec2.zero(); + : super(JointType.FRICTION), + localAnchorA = new Vec2.zero(), + localAnchorB = new Vec2.zero(); /** * Initialize the bodies, anchors, axis, and reference angle using the world anchor and world diff --git a/lib/box2d/src/dynamics/joints/gear_joint.dart b/lib/src/dynamics/joints/gear_joint.dart similarity index 98% rename from lib/box2d/src/dynamics/joints/gear_joint.dart rename to lib/src/dynamics/joints/gear_joint.dart index 4dc1f6b..598e427 100644 --- a/lib/box2d/src/dynamics/joints/gear_joint.dart +++ b/lib/src/dynamics/joints/gear_joint.dart @@ -119,7 +119,6 @@ class GearJoint extends Joint { m_typeB = def.joint2.getType(), m_bodyC = def.joint1.getBodyA(), m_bodyD = def.joint2.getBodyA() { - assert(m_typeA == JointType.REVOLUTE || m_typeA == JointType.PRISMATIC); assert(m_typeB == JointType.REVOLUTE || m_typeB == JointType.PRISMATIC); @@ -308,7 +307,9 @@ class GearJoint extends Joint { m_JvBD.set(u).mulLocal(m_ratio); m_JwD = m_ratio * Vec2.cross(rD, u); m_JwB = m_ratio * Vec2.cross(rB, u); - m_mass += m_ratio * m_ratio * (m_mD + m_mB) + m_iD * m_JwD * m_JwD + m_iB * m_JwB * m_JwB; + m_mass += m_ratio * m_ratio * (m_mD + m_mB) + + m_iD * m_JwD * m_JwD + + m_iB * m_JwB * m_JwB; pool.pushVec2(3); } @@ -359,7 +360,8 @@ class GearJoint extends Joint { Vec2 temp1 = pool.popVec2(); Vec2 temp2 = pool.popVec2(); - double Cdot = Vec2.dot(m_JvAC, temp1.set(vA).subLocal(vC)) + Vec2.dot(m_JvBD, temp2.set(vB).subLocal(vD)); + double Cdot = Vec2.dot(m_JvAC, temp1.set(vA).subLocal(vC)) + + Vec2.dot(m_JvBD, temp2.set(vB).subLocal(vD)); Cdot += (m_JwA * wA - m_JwC * wC) + (m_JwB * wB - m_JwD * wD); pool.pushVec2(2); @@ -382,7 +384,6 @@ class GearJoint extends Joint { vD.y -= (m_mD * impulse) * m_JvBD.y; wD -= m_iD * impulse * m_JwD; - // data.velocities[m_indexA].v = vA; data.velocities[m_indexA].w = wA; // data.velocities[m_indexB].v = vB; @@ -474,7 +475,9 @@ class GearJoint extends Joint { JvBD.set(u).mulLocal(m_ratio); JwD = Vec2.cross(rD, u); JwB = Vec2.cross(rB, u); - mass += m_ratio * m_ratio * (m_mD + m_mB) + m_iD * JwD * JwD + m_iB * JwB * JwB; + mass += m_ratio * m_ratio * (m_mD + m_mB) + + m_iD * JwD * JwD + + m_iB * JwB * JwB; pD.set(m_localAnchorD).subLocal(m_lcD); Rot.mulTransUnsafeVec2(qD, temp.set(rB).addLocal(cB).subLocal(cD), pB); diff --git a/lib/box2d/src/dynamics/joints/gear_joint_def.dart b/lib/src/dynamics/joints/gear_joint_def.dart similarity index 99% rename from lib/box2d/src/dynamics/joints/gear_joint_def.dart rename to lib/src/dynamics/joints/gear_joint_def.dart index 678d381..7755ca7 100644 --- a/lib/box2d/src/dynamics/joints/gear_joint_def.dart +++ b/lib/src/dynamics/joints/gear_joint_def.dart @@ -22,7 +22,6 @@ * POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ - part of box2d; /** @@ -52,4 +51,3 @@ class GearJointDef extends JointDef { GearJointDef() : super(JointType.GEAR); } - diff --git a/lib/box2d/src/dynamics/joints/jacobian.dart b/lib/src/dynamics/joints/jacobian.dart similarity index 100% rename from lib/box2d/src/dynamics/joints/jacobian.dart rename to lib/src/dynamics/joints/jacobian.dart diff --git a/lib/box2d/src/dynamics/joints/joint.dart b/lib/src/dynamics/joints/joint.dart similarity index 99% rename from lib/box2d/src/dynamics/joints/joint.dart rename to lib/src/dynamics/joints/joint.dart index 4bc38ed..461979e 100644 --- a/lib/box2d/src/dynamics/joints/joint.dart +++ b/lib/src/dynamics/joints/joint.dart @@ -31,7 +31,6 @@ part of box2d; * @author Daniel Murphy */ abstract class Joint { - static Joint create(World world, JointDef def) { // Joint joint = null; switch (def.type) { diff --git a/lib/box2d/src/dynamics/joints/joint_def.dart b/lib/src/dynamics/joints/joint_def.dart similarity index 98% rename from lib/box2d/src/dynamics/joints/joint_def.dart rename to lib/src/dynamics/joints/joint_def.dart index 6719fce..ca1b18f 100644 --- a/lib/box2d/src/dynamics/joints/joint_def.dart +++ b/lib/src/dynamics/joints/joint_def.dart @@ -29,8 +29,7 @@ part of box2d; * @author Daniel Murphy */ class JointDef { - - JointDef(JointType type){ + JointDef(JointType type) { this.type = type; userData = null; bodyA = null; @@ -41,22 +40,22 @@ class JointDef { * The joint type is set automatically for concrete joint types. */ JointType type; - + /** * Use this to attach application specific data to your joints. */ Object userData; - + /** * The first attached body. */ Body bodyA; - + /** * The second attached body. */ Body bodyB; - + /** * Set this flag to true if the attached bodies should collide. */ diff --git a/lib/box2d/src/dynamics/joints/joint_edge.dart b/lib/src/dynamics/joints/joint_edge.dart similarity index 99% rename from lib/box2d/src/dynamics/joints/joint_edge.dart rename to lib/src/dynamics/joints/joint_edge.dart index 7fb9acb..52b6c87 100644 --- a/lib/box2d/src/dynamics/joints/joint_edge.dart +++ b/lib/src/dynamics/joints/joint_edge.dart @@ -33,22 +33,22 @@ part of box2d; * @author Daniel */ class JointEdge { - + /** * Provides quick access to the other body attached */ Body other = null; - + /** * the joint */ Joint joint = null; - + /** * the previous joint edge in the body's joint list */ JointEdge prev = null; - + /** * the next joint edge in the body's joint list */ diff --git a/lib/box2d/src/dynamics/joints/joint_type.dart b/lib/src/dynamics/joints/joint_type.dart similarity index 91% rename from lib/box2d/src/dynamics/joints/joint_type.dart rename to lib/src/dynamics/joints/joint_type.dart index e68c646..dd5a8dd 100644 --- a/lib/box2d/src/dynamics/joints/joint_type.dart +++ b/lib/src/dynamics/joints/joint_type.dart @@ -25,5 +25,17 @@ part of box2d; enum JointType { - UNKNOWN, REVOLUTE, PRISMATIC, DISTANCE, PULLEY, MOUSE, GEAR, WHEEL, WELD, FRICTION, ROPE, CONSTANT_VOLUME, MOTOR + UNKNOWN, + REVOLUTE, + PRISMATIC, + DISTANCE, + PULLEY, + MOUSE, + GEAR, + WHEEL, + WELD, + FRICTION, + ROPE, + CONSTANT_VOLUME, + MOTOR } diff --git a/lib/box2d/src/dynamics/joints/limit_state.dart b/lib/src/dynamics/joints/limit_state.dart similarity index 96% rename from lib/box2d/src/dynamics/joints/limit_state.dart rename to lib/src/dynamics/joints/limit_state.dart index f8b4952..4b208c5 100644 --- a/lib/box2d/src/dynamics/joints/limit_state.dart +++ b/lib/src/dynamics/joints/limit_state.dart @@ -24,6 +24,4 @@ part of box2d; -enum LimitState { - INACTIVE, AT_LOWER, AT_UPPER, EQUAL -} +enum LimitState { INACTIVE, AT_LOWER, AT_UPPER, EQUAL } diff --git a/lib/box2d/src/dynamics/joints/motor_joint.dart b/lib/src/dynamics/joints/motor_joint.dart similarity index 94% rename from lib/box2d/src/dynamics/joints/motor_joint.dart rename to lib/src/dynamics/joints/motor_joint.dart index 4930b26..1292970 100644 --- a/lib/box2d/src/dynamics/joints/motor_joint.dart +++ b/lib/src/dynamics/joints/motor_joint.dart @@ -24,7 +24,6 @@ part of box2d; - //Point-to-point constraint //Cdot = v2 - v1 // = v2 + cross(w2, r2) - v1 - cross(w1, r1) @@ -70,8 +69,7 @@ class MotorJoint extends Joint { final Mat22 _m_linearMass = new Mat22.zero(); double _m_angularMass = 0.0; - MotorJoint(IWorldPool pool, MotorJointDef def) - : super(pool, def) { + MotorJoint(IWorldPool pool, MotorJointDef def) : super(pool, def) { _m_linearOffset.set(def.linearOffset); _m_angularOffset = def.angularOffset; @@ -110,7 +108,8 @@ class MotorJoint extends Joint { * Set the target linear offset, in frame A, in meters. */ void setLinearOffset(Vec2 linearOffset) { - if (linearOffset.x != _m_linearOffset.x || linearOffset.y != _m_linearOffset.y) { + if (linearOffset.x != _m_linearOffset.x || + linearOffset.y != _m_linearOffset.y) { m_bodyA.setAwake(true); m_bodyB.setAwake(true); _m_linearOffset.set(linearOffset); @@ -298,7 +297,8 @@ class MotorJoint extends Joint { double oldImpulse = _m_angularImpulse; double maxImpulse = h * _m_maxTorque; - _m_angularImpulse = MathUtils.clampDouble(_m_angularImpulse + impulse, -maxImpulse, maxImpulse); + _m_angularImpulse = MathUtils.clampDouble( + _m_angularImpulse + impulse, -maxImpulse, maxImpulse); impulse = _m_angularImpulse - oldImpulse; wA -= iA * impulse; @@ -311,8 +311,16 @@ class MotorJoint extends Joint { { // Cdot = vB + b2Cross(wB, m_rB) - vA - b2Cross(wA, m_rA) + inv_h * m_correctionFactor * // m_linearError; - Cdot.x = vB.x + -wB * _m_rB.y - vA.x - -wA * _m_rA.y + inv_h * _m_correctionFactor * _m_linearError.x; - Cdot.y = vB.y + wB * _m_rB.x - vA.y - wA * _m_rA.x + inv_h * _m_correctionFactor * _m_linearError.y; + Cdot.x = vB.x + + -wB * _m_rB.y - + vA.x - + -wA * _m_rA.y + + inv_h * _m_correctionFactor * _m_linearError.x; + Cdot.y = vB.y + + wB * _m_rB.x - + vA.y - + wA * _m_rA.x + + inv_h * _m_correctionFactor * _m_linearError.y; final Vec2 impulse = temp; Mat22.mulToOutUnsafeVec2_(_m_linearMass, Cdot, impulse); diff --git a/lib/box2d/src/dynamics/joints/motor_joint_def.dart b/lib/src/dynamics/joints/motor_joint_def.dart similarity index 100% rename from lib/box2d/src/dynamics/joints/motor_joint_def.dart rename to lib/src/dynamics/joints/motor_joint_def.dart diff --git a/lib/box2d/src/dynamics/joints/mouse_joint.dart b/lib/src/dynamics/joints/mouse_joint.dart similarity index 95% rename from lib/box2d/src/dynamics/joints/mouse_joint.dart rename to lib/src/dynamics/joints/mouse_joint.dart index 7905441..ffcfa7d 100644 --- a/lib/box2d/src/dynamics/joints/mouse_joint.dart +++ b/lib/src/dynamics/joints/mouse_joint.dart @@ -33,7 +33,6 @@ part of box2d; * @author Daniel */ class MouseJoint extends Joint { - final Vec2 _m_localAnchorB = new Vec2.zero(); final Vec2 _m_targetA = new Vec2.zero(); double _m_frequencyHz = 0.0; @@ -61,7 +60,8 @@ class MouseJoint extends Joint { assert(def.dampingRatio >= 0); _m_targetA.set(def.target); - Transform.mulTransToOutUnsafeVec2(m_bodyB.getTransform(), _m_targetA, _m_localAnchorB); + Transform.mulTransToOutUnsafeVec2( + m_bodyB.getTransform(), _m_targetA, _m_localAnchorB); _m_maxForce = def.maxForce; _m_impulse.setZero(); @@ -164,7 +164,8 @@ class MouseJoint extends Joint { Vec2 temp = pool.popVec2(); // Compute the effective mass matrix. - Rot.mulToOutUnsafe(qB, temp.set(_m_localAnchorB).subLocal(_m_localCenterB), _m_rB); + Rot.mulToOutUnsafe( + qB, temp.set(_m_localAnchorB).subLocal(_m_localCenterB), _m_rB); // K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)] // = [1/m1+1/m2 0 ] + invI1 * [r1.y*r1.y -r1.x*r1.y] + invI2 * [r1.y*r1.y -r1.x*r1.y] @@ -205,7 +206,6 @@ class MouseJoint extends Joint { } void solveVelocityConstraints(final SolverData data) { - Vec2 vB = data.velocities[_m_indexB].v; double wB = data.velocities[_m_indexB].w; @@ -217,7 +217,12 @@ class MouseJoint extends Joint { final Vec2 impulse = pool.popVec2(); final Vec2 temp = pool.popVec2(); - temp.set(_m_impulse).mulLocal(_m_gamma).addLocal(_m_C).addLocal(Cdot).negateLocal(); + temp + .set(_m_impulse) + .mulLocal(_m_gamma) + .addLocal(_m_C) + .addLocal(Cdot) + .negateLocal(); Mat22.mulToOutUnsafeVec2_(_m_mass, temp, impulse); Vec2 oldImpulse = temp; @@ -238,5 +243,4 @@ class MouseJoint extends Joint { pool.pushVec2(3); } - } diff --git a/lib/box2d/src/dynamics/joints/mouse_joint_def.dart b/lib/src/dynamics/joints/mouse_joint_def.dart similarity index 100% rename from lib/box2d/src/dynamics/joints/mouse_joint_def.dart rename to lib/src/dynamics/joints/mouse_joint_def.dart diff --git a/lib/box2d/src/dynamics/joints/prismatic_joint.dart b/lib/src/dynamics/joints/prismatic_joint.dart similarity index 94% rename from lib/box2d/src/dynamics/joints/prismatic_joint.dart rename to lib/src/dynamics/joints/prismatic_joint.dart index 836963a..10e922d 100644 --- a/lib/box2d/src/dynamics/joints/prismatic_joint.dart +++ b/lib/src/dynamics/joints/prismatic_joint.dart @@ -44,7 +44,6 @@ part of box2d; //s1 = cross(d + r1, a) = cross(p2 - x1, a) //s2 = cross(r2, a) = cross(p2 - x2, a) - //Motor/Limit linear constraint //C = dot(ax1, d) //Cdot = = -dot(ax1, v1) - dot(cross(d + r1, ax1), w1) + dot(ax1, v2) + dot(cross(r2, ax1), v2) @@ -134,7 +133,8 @@ class PrismaticJoint extends Joint { double m_a1 = 0.0, m_a2 = 0.0; final Mat33 m_K = new Mat33.zero(); - double m_motorMass = 0.0; // effective mass for motor/limit translational constraint. + double m_motorMass = + 0.0; // effective mass for motor/limit translational constraint. PrismaticJoint(IWorldPool argWorld, PrismaticJointDef def) : super(argWorld, def), @@ -162,12 +162,10 @@ class PrismaticJoint extends Joint { return m_localAnchorB; } - void getAnchorA(Vec2 argOut) { m_bodyA.getWorldPointToOut(m_localAnchorA, argOut); } - void getAnchorB(Vec2 argOut) { m_bodyB.getWorldPointToOut(m_localAnchorB, argOut); } @@ -179,7 +177,6 @@ class PrismaticJoint extends Joint { pool.pushVec2(1); } - double getReactionTorque(double inv_dt) { return inv_dt * m_impulse.y; } @@ -218,7 +215,6 @@ class PrismaticJoint extends Joint { double wA = bA.m_angularVelocity; double wB = bB.m_angularVelocity; - Vec2.crossToOutUnsafeDblVec2(wA, axis, temp); Vec2.crossToOutUnsafeDblVec2(wB, rB, temp2); Vec2.crossToOutUnsafeDblVec2(wA, rA, temp3); @@ -454,9 +450,9 @@ class PrismaticJoint extends Joint { // Compute motor and limit terms. if (m_enableLimit) { - double jointTranslation = Vec2.dot(m_axis, d); - if ((m_upperTranslation - m_lowerTranslation).abs() < 2.0 * Settings.linearSlop) { + if ((m_upperTranslation - m_lowerTranslation).abs() < + 2.0 * Settings.linearSlop) { m_limitState = LimitState.EQUAL; } else if (jointTranslation <= m_lowerTranslation) { if (m_limitState != LimitState.AT_LOWER) { @@ -490,8 +486,12 @@ class PrismaticJoint extends Joint { temp.set(m_axis).mulLocal(m_motorImpulse + m_impulse.z); P.set(m_perp).mulLocal(m_impulse.x).addLocal(temp); - double LA = m_impulse.x * m_s1 + m_impulse.y + (m_motorImpulse + m_impulse.z) * m_a1; - double LB = m_impulse.x * m_s2 + m_impulse.y + (m_motorImpulse + m_impulse.z) * m_a2; + double LA = m_impulse.x * m_s1 + + m_impulse.y + + (m_motorImpulse + m_impulse.z) * m_a1; + double LB = m_impulse.x * m_s2 + + m_impulse.y + + (m_motorImpulse + m_impulse.z) * m_a2; vA.x -= mA * P.x; vA.y -= mA * P.y; @@ -536,7 +536,8 @@ class PrismaticJoint extends Joint { double impulse = m_motorMass * (m_motorSpeed - Cdot); double oldImpulse = m_motorImpulse; double maxImpulse = data.step.dt * m_maxMotorForce; - m_motorImpulse = MathUtils.clampDouble(m_motorImpulse + impulse, -maxImpulse, maxImpulse); + m_motorImpulse = MathUtils.clampDouble( + m_motorImpulse + impulse, -maxImpulse, maxImpulse); impulse = m_motorImpulse - oldImpulse; final Vec2 P = pool.popVec2(); @@ -676,8 +677,10 @@ class PrismaticJoint extends Joint { iB = m_invIB; // Compute fresh Jacobians - Rot.mulToOutUnsafe(qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), rA); - Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), rB); + Rot.mulToOutUnsafe( + qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), rA); + Rot.mulToOutUnsafe( + qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), rB); d.set(cB).addLocal(rB).subLocal(cA).subLocal(rA); Rot.mulToOutUnsafe(qA, m_localXAxisA, axis); @@ -698,19 +701,25 @@ class PrismaticJoint extends Joint { double C2 = 0.0; if (m_enableLimit) { double translation = Vec2.dot(axis, d); - if ((m_upperTranslation - m_lowerTranslation).abs() < 2.0 * Settings.linearSlop) { + if ((m_upperTranslation - m_lowerTranslation).abs() < + 2.0 * Settings.linearSlop) { // Prevent large angular corrections - C2 = MathUtils.clampDouble(translation, -Settings.maxLinearCorrection, Settings.maxLinearCorrection); + C2 = MathUtils.clampDouble(translation, -Settings.maxLinearCorrection, + Settings.maxLinearCorrection); linearError = Math.max(linearError, translation.abs()); active = true; } else if (translation <= m_lowerTranslation) { // Prevent large linear corrections and allow some slop. - C2 = MathUtils.clampDouble(translation - m_lowerTranslation + Settings.linearSlop, -Settings.maxLinearCorrection, 0.0); + C2 = MathUtils.clampDouble( + translation - m_lowerTranslation + Settings.linearSlop, + -Settings.maxLinearCorrection, 0.0); linearError = Math.max(linearError, m_lowerTranslation - translation); active = true; } else if (translation >= m_upperTranslation) { // Prevent large linear corrections and allow some slop. - C2 = MathUtils.clampDouble(translation - m_upperTranslation - Settings.linearSlop, 0.0, Settings.maxLinearCorrection); + C2 = MathUtils.clampDouble( + translation - m_upperTranslation - Settings.linearSlop, 0.0, + Settings.maxLinearCorrection); linearError = Math.max(linearError, translation - m_upperTranslation); active = true; } @@ -785,6 +794,7 @@ class PrismaticJoint extends Joint { pool.pushVec3(1); pool.pushRot(2); - return linearError <= Settings.linearSlop && angularError <= Settings.angularSlop; + return linearError <= Settings.linearSlop && + angularError <= Settings.angularSlop; } } diff --git a/lib/box2d/src/dynamics/joints/prismatic_joint_def.dart b/lib/src/dynamics/joints/prismatic_joint_def.dart similarity index 99% rename from lib/box2d/src/dynamics/joints/prismatic_joint_def.dart rename to lib/src/dynamics/joints/prismatic_joint_def.dart index de95e8f..b640fba 100644 --- a/lib/box2d/src/dynamics/joints/prismatic_joint_def.dart +++ b/lib/src/dynamics/joints/prismatic_joint_def.dart @@ -70,7 +70,7 @@ class PrismaticJointDef extends JointDef { /** * The upper translation limit, usually in meters. */ - double upperTranslation= 0.0 ; + double upperTranslation = 0.0; /** * Enable/disable the joint motor. diff --git a/lib/box2d/src/dynamics/joints/pulley_joint.dart b/lib/src/dynamics/joints/pulley_joint.dart similarity index 96% rename from lib/box2d/src/dynamics/joints/pulley_joint.dart rename to lib/src/dynamics/joints/pulley_joint.dart index d4eb9a7..b1c3d53 100644 --- a/lib/box2d/src/dynamics/joints/pulley_joint.dart +++ b/lib/src/dynamics/joints/pulley_joint.dart @@ -34,7 +34,6 @@ part of box2d; * @author Daniel Murphy */ class PulleyJoint extends Joint { - static const double MIN_PULLEY_LENGTH = 2.0; final Vec2 _m_groundAnchorA = new Vec2.zero(); @@ -107,7 +106,6 @@ class PulleyJoint extends Joint { return length; } - Vec2 getLocalAnchorA() { return _m_localAnchorA; } @@ -116,23 +114,18 @@ class PulleyJoint extends Joint { return _m_localAnchorB; } - - void getAnchorA(Vec2 argOut) { m_bodyA.getWorldPointToOut(_m_localAnchorA, argOut); } - void getAnchorB(Vec2 argOut) { m_bodyB.getWorldPointToOut(_m_localAnchorB, argOut); } - void getReactionForce(double inv_dt, Vec2 argOut) { argOut.set(_m_uB).mulLocal(_m_impulse).mulLocal(inv_dt); } - double getReactionTorque(double inv_dt) { return 0.0; } @@ -169,7 +162,6 @@ class PulleyJoint extends Joint { return _m_ratio; } - void initVelocityConstraints(final SolverData data) { _m_indexA = m_bodyA.m_islandIndex; _m_indexB = m_bodyB.m_islandIndex; @@ -198,8 +190,10 @@ class PulleyJoint extends Joint { qB.setAngle(aB); // Compute the effective masses. - Rot.mulToOutUnsafe(qA, temp.set(_m_localAnchorA).subLocal(_m_localCenterA), _m_rA); - Rot.mulToOutUnsafe(qB, temp.set(_m_localAnchorB).subLocal(_m_localCenterB), _m_rB); + Rot.mulToOutUnsafe( + qA, temp.set(_m_localAnchorA).subLocal(_m_localCenterA), _m_rA); + Rot.mulToOutUnsafe( + qB, temp.set(_m_localAnchorB).subLocal(_m_localCenterB), _m_rB); _m_uA.set(cA).addLocal(_m_rA).subLocal(_m_groundAnchorA); _m_uB.set(cB).addLocal(_m_rB).subLocal(_m_groundAnchorB); @@ -264,7 +258,6 @@ class PulleyJoint extends Joint { pool.pushRot(2); } - void solveVelocityConstraints(final SolverData data) { Vec2 vA = data.velocities[_m_indexA].v; double wA = data.velocities[_m_indexA].w; @@ -302,7 +295,6 @@ class PulleyJoint extends Joint { pool.pushVec2(4); } - bool solvePositionConstraints(final SolverData data) { final Rot qA = pool.popRot(); final Rot qB = pool.popRot(); @@ -322,8 +314,10 @@ class PulleyJoint extends Joint { qA.setAngle(aA); qB.setAngle(aB); - Rot.mulToOutUnsafe(qA, temp.set(_m_localAnchorA).subLocal(_m_localCenterA), rA); - Rot.mulToOutUnsafe(qB, temp.set(_m_localAnchorB).subLocal(_m_localCenterB), rB); + Rot.mulToOutUnsafe( + qA, temp.set(_m_localAnchorA).subLocal(_m_localCenterA), rA); + Rot.mulToOutUnsafe( + qB, temp.set(_m_localAnchorB).subLocal(_m_localCenterB), rB); uA.set(cA).addLocal(rA).subLocal(_m_groundAnchorA); uB.set(cB).addLocal(rB).subLocal(_m_groundAnchorB); diff --git a/lib/box2d/src/dynamics/joints/pulley_joint_def.dart b/lib/src/dynamics/joints/pulley_joint_def.dart similarity index 96% rename from lib/box2d/src/dynamics/joints/pulley_joint_def.dart rename to lib/src/dynamics/joints/pulley_joint_def.dart index 4c1734a..6e3029c 100644 --- a/lib/box2d/src/dynamics/joints/pulley_joint_def.dart +++ b/lib/src/dynamics/joints/pulley_joint_def.dart @@ -67,15 +67,15 @@ class PulleyJointDef extends JointDef { */ double ratio = 1.0; - PulleyJointDef() - : super(JointType.PULLEY) { + PulleyJointDef() : super(JointType.PULLEY) { collideConnected = true; } /** * Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors. */ - void initialize(Body b1, Body b2, Vec2 ga1, Vec2 ga2, Vec2 anchor1, Vec2 anchor2, double r) { + void initialize(Body b1, Body b2, Vec2 ga1, Vec2 ga2, Vec2 anchor1, + Vec2 anchor2, double r) { bodyA = b1; bodyB = b2; groundAnchorA = ga1; @@ -87,6 +87,6 @@ class PulleyJointDef extends JointDef { Vec2 d2 = anchor2.sub(ga2); lengthB = d2.length(); ratio = r; - assert (ratio > Settings.EPSILON); + assert(ratio > Settings.EPSILON); } } diff --git a/lib/box2d/src/dynamics/joints/revolute_joint.dart b/lib/src/dynamics/joints/revolute_joint.dart similarity index 87% rename from lib/box2d/src/dynamics/joints/revolute_joint.dart rename to lib/src/dynamics/joints/revolute_joint.dart index bff8534..9cd659d 100644 --- a/lib/box2d/src/dynamics/joints/revolute_joint.dart +++ b/lib/src/dynamics/joints/revolute_joint.dart @@ -74,12 +74,14 @@ class RevoluteJoint extends Joint { double m_invMassB = 0.0; double m_invIA = 0.0; double m_invIB = 0.0; - final Mat33 m_mass = new Mat33.zero(); // effective mass for point-to-point constraint. - double m_motorMass = 0.0; // effective mass for motor/limit angular constraint. + final Mat33 m_mass = + new Mat33.zero(); // effective mass for point-to-point constraint. + double m_motorMass = + 0.0; // effective mass for motor/limit angular constraint. LimitState m_limitState = LimitState.INACTIVE; RevoluteJoint(IWorldPool argWorld, RevoluteJointDef def) - : super(argWorld, def) { + : super(argWorld, def) { m_localAnchorA.set(def.localAnchorA); m_localAnchorB.set(def.localAnchorB); m_referenceAngle = def.referenceAngle; @@ -119,8 +121,10 @@ class RevoluteJoint extends Joint { qB.setAngle(aB); // Compute the effective masses. - Rot.mulToOutUnsafe(qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), m_rA); - Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), m_rB); + Rot.mulToOutUnsafe( + qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), m_rA); + Rot.mulToOutUnsafe( + qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), m_rB); // J = [-I -r1_skew I r2_skew] // [ 0 -1 0 1] @@ -131,8 +135,10 @@ class RevoluteJoint extends Joint { // [ -r1y*iA*r1x-r2y*iB*r2x, mA+r1x^2*iA+mB+r2x^2*iB, r1x*iA+r2x*iB] // [ -r1y*iA-r2y*iB, r1x*iA+r2x*iB, iA+iB] - double mA = m_invMassA, mB = m_invMassB; - double iA = m_invIA, iB = m_invIB; + double mA = m_invMassA, + mB = m_invMassB; + double iA = m_invIA, + iB = m_invIB; bool fixedRotation = (iA + iB == 0.0); @@ -214,18 +220,23 @@ class RevoluteJoint extends Joint { Vec2 vB = data.velocities[m_indexB].v; double wB = data.velocities[m_indexB].w; - double mA = m_invMassA, mB = m_invMassB; - double iA = m_invIA, iB = m_invIB; + double mA = m_invMassA, + mB = m_invMassB; + double iA = m_invIA, + iB = m_invIB; bool fixedRotation = (iA + iB == 0.0); // Solve motor constraint. - if (m_enableMotor && m_limitState != LimitState.EQUAL && fixedRotation == false) { + if (m_enableMotor && + m_limitState != LimitState.EQUAL && + fixedRotation == false) { double Cdot = wB - wA - m_motorSpeed; double impulse = -m_motorMass * Cdot; double oldImpulse = m_motorImpulse; double maxImpulse = data.step.dt * m_maxMotorTorque; - m_motorImpulse = MathUtils.clampDouble(m_motorImpulse + impulse, -maxImpulse, maxImpulse); + m_motorImpulse = MathUtils.clampDouble( + m_motorImpulse + impulse, -maxImpulse, maxImpulse); impulse = m_motorImpulse - oldImpulse; wA -= iA * impulse; @@ -234,8 +245,9 @@ class RevoluteJoint extends Joint { final Vec2 temp = pool.popVec2(); // Solve limit constraint. - if (m_enableLimit && m_limitState != LimitState.INACTIVE && fixedRotation == false) { - + if (m_enableLimit && + m_limitState != LimitState.INACTIVE && + fixedRotation == false) { final Vec2 Cdot1 = pool.popVec2(); final Vec3 Cdot = pool.popVec3(); @@ -256,7 +268,10 @@ class RevoluteJoint extends Joint { double newImpulse = m_impulse.z + impulse.z; if (newImpulse < 0.0) { final Vec2 rhs = pool.popVec2(); - rhs.setXY(m_mass.ez.x, m_mass.ez.y).mulLocal(m_impulse.z).subLocal(Cdot1); + rhs + .setXY(m_mass.ez.x, m_mass.ez.y) + .mulLocal(m_impulse.z) + .subLocal(Cdot1); m_mass.solve22ToOut(rhs, temp); impulse.x = temp.x; impulse.y = temp.y; @@ -272,7 +287,10 @@ class RevoluteJoint extends Joint { double newImpulse = m_impulse.z + impulse.z; if (newImpulse > 0.0) { final Vec2 rhs = pool.popVec2(); - rhs.setXY(m_mass.ez.x, m_mass.ez.y).mulLocal(m_impulse.z).subLocal(Cdot1); + rhs + .setXY(m_mass.ez.x, m_mass.ez.y) + .mulLocal(m_impulse.z) + .subLocal(Cdot1); m_mass.solve22ToOut(rhs, temp); impulse.x = temp.x; impulse.y = temp.y; @@ -332,7 +350,6 @@ class RevoluteJoint extends Joint { pool.pushVec2(1); } - bool solvePositionConstraints(final SolverData data) { final Rot qA = pool.popRot(); final Rot qB = pool.popRot(); @@ -350,15 +367,16 @@ class RevoluteJoint extends Joint { bool fixedRotation = (m_invIA + m_invIB == 0.0); // Solve angular limit constraint. - if (m_enableLimit && m_limitState != LimitState.INACTIVE && fixedRotation == false) { + if (m_enableLimit && + m_limitState != LimitState.INACTIVE && + fixedRotation == false) { double angle = aB - aA - m_referenceAngle; double limitImpulse = 0.0; if (m_limitState == LimitState.EQUAL) { // Prevent large angular corrections - double C = - MathUtils.clampDouble(angle - m_lowerAngle, -Settings.maxAngularCorrection, - Settings.maxAngularCorrection); + double C = MathUtils.clampDouble(angle - m_lowerAngle, + -Settings.maxAngularCorrection, Settings.maxAngularCorrection); limitImpulse = -m_motorMass * C; angularError = C.abs(); } else if (m_limitState == LimitState.AT_LOWER) { @@ -366,14 +384,16 @@ class RevoluteJoint extends Joint { angularError = -C; // Prevent large angular corrections and allow some slop. - C = MathUtils.clampDouble(C + Settings.angularSlop, -Settings.maxAngularCorrection, 0.0); + C = MathUtils.clampDouble( + C + Settings.angularSlop, -Settings.maxAngularCorrection, 0.0); limitImpulse = -m_motorMass * C; } else if (m_limitState == LimitState.AT_UPPER) { double C = angle - m_upperAngle; angularError = C; // Prevent large angular corrections and allow some slop. - C = MathUtils.clampDouble(C - Settings.angularSlop, 0.0, Settings.maxAngularCorrection); + C = MathUtils.clampDouble( + C - Settings.angularSlop, 0.0, Settings.maxAngularCorrection); limitImpulse = -m_motorMass * C; } @@ -390,13 +410,17 @@ class RevoluteJoint extends Joint { final Vec2 C = pool.popVec2(); final Vec2 impulse = pool.popVec2(); - Rot.mulToOutUnsafe(qA, C.set(m_localAnchorA).subLocal(m_localCenterA), rA); - Rot.mulToOutUnsafe(qB, C.set(m_localAnchorB).subLocal(m_localCenterB), rB); + Rot.mulToOutUnsafe( + qA, C.set(m_localAnchorA).subLocal(m_localCenterA), rA); + Rot.mulToOutUnsafe( + qB, C.set(m_localAnchorB).subLocal(m_localCenterB), rB); C.set(cB).addLocal(rB).subLocal(cA).subLocal(rA); positionError = C.length(); - double mA = m_invMassA, mB = m_invMassB; - double iA = m_invIA, iB = m_invIB; + double mA = m_invMassA, + mB = m_invMassB; + double iA = m_invIA, + iB = m_invIB; final Mat22 K = pool.popMat22(); K.ex.x = mA + mB + iA * rA.y * rA.y + iB * rB.y * rB.y; @@ -424,32 +448,30 @@ class RevoluteJoint extends Joint { pool.pushRot(2); - return positionError <= Settings.linearSlop && angularError <= Settings.angularSlop; + return positionError <= Settings.linearSlop && + angularError <= Settings.angularSlop; } - + Vec2 getLocalAnchorA() { return m_localAnchorA; } - + Vec2 getLocalAnchorB() { return m_localAnchorB; } - + double getReferenceAngle() { return m_referenceAngle; } - void getAnchorA(Vec2 argOut) { m_bodyA.getWorldPointToOut(m_localAnchorA, argOut); } - void getAnchorB(Vec2 argOut) { m_bodyB.getWorldPointToOut(m_localAnchorB, argOut); } - void getReactionForce(double inv_dt, Vec2 argOut) { argOut.setXY(m_impulse.x, m_impulse.y).mulLocal(inv_dt); } @@ -526,7 +548,7 @@ class RevoluteJoint extends Joint { } void setLimits(final double lower, final double upper) { - assert (lower <= upper); + assert(lower <= upper); if (lower != m_lowerAngle || upper != m_upperAngle) { m_bodyA.setAwake(true); m_bodyB.setAwake(true); diff --git a/lib/box2d/src/dynamics/joints/revolute_joint_def.dart b/lib/src/dynamics/joints/revolute_joint_def.dart similarity index 100% rename from lib/box2d/src/dynamics/joints/revolute_joint_def.dart rename to lib/src/dynamics/joints/revolute_joint_def.dart diff --git a/lib/box2d/src/dynamics/joints/rope_joint.dart b/lib/src/dynamics/joints/rope_joint.dart similarity index 93% rename from lib/box2d/src/dynamics/joints/rope_joint.dart rename to lib/src/dynamics/joints/rope_joint.dart index 4c1f842..a2faa36 100644 --- a/lib/box2d/src/dynamics/joints/rope_joint.dart +++ b/lib/src/dynamics/joints/rope_joint.dart @@ -57,8 +57,7 @@ class RopeJoint extends Joint { double m_mass = 0.0; LimitState m_state = LimitState.INACTIVE; - RopeJoint(IWorldPool worldPool, RopeJointDef def) - : super(worldPool, def) { + RopeJoint(IWorldPool worldPool, RopeJointDef def) : super(worldPool, def) { m_localAnchorA.set(def.localAnchorA); m_localAnchorB.set(def.localAnchorB); @@ -93,8 +92,10 @@ class RopeJoint extends Joint { qB.setAngle(aB); // Compute the effective masses. - Rot.mulToOutUnsafe(qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), m_rA); - Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), m_rB); + Rot.mulToOutUnsafe( + qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), m_rA); + Rot.mulToOutUnsafe( + qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), m_rB); m_u.set(cB).addLocal(m_rB).subLocal(cA).subLocal(m_rA); @@ -119,7 +120,8 @@ class RopeJoint extends Joint { // Compute effective mass. double crA = Vec2.cross(m_rA, m_u); double crB = Vec2.cross(m_rB, m_u); - double invMass = m_invMassA + m_invIA * crA * crA + m_invMassB + m_invIB * crB * crB; + double invMass = + m_invMassA + m_invIA * crA * crA + m_invMassB + m_invIB * crB * crB; m_mass = invMass != 0.0 ? 1.0 / invMass : 0.0; @@ -212,8 +214,10 @@ class RopeJoint extends Joint { qB.setAngle(aB); // Compute the effective masses. - Rot.mulToOutUnsafe(qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), rA); - Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), rB); + Rot.mulToOutUnsafe( + qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), rA); + Rot.mulToOutUnsafe( + qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), rB); u.set(cB).addLocal(rB).subLocal(cA).subLocal(rA); double length = u.normalize(); @@ -247,7 +251,6 @@ class RopeJoint extends Joint { m_bodyA.getWorldPointToOut(m_localAnchorA, argOut); } - void getAnchorB(Vec2 argOut) { m_bodyB.getWorldPointToOut(m_localAnchorB, argOut); } @@ -256,7 +259,6 @@ class RopeJoint extends Joint { argOut.set(m_u).mulLocal(inv_dt).mulLocal(m_impulse); } - double getReactionTorque(double inv_dt) { return 0.0; } diff --git a/lib/box2d/src/dynamics/joints/rope_joint_def.dart b/lib/src/dynamics/joints/rope_joint_def.dart similarity index 97% rename from lib/box2d/src/dynamics/joints/rope_joint_def.dart rename to lib/src/dynamics/joints/rope_joint_def.dart index 46d9764..e2d30c8 100644 --- a/lib/box2d/src/dynamics/joints/rope_joint_def.dart +++ b/lib/src/dynamics/joints/rope_joint_def.dart @@ -48,8 +48,7 @@ class RopeJointDef extends JointDef { */ double maxLength = 0.0; - RopeJointDef() - : super(JointType.ROPE) { + RopeJointDef() : super(JointType.ROPE) { localAnchorA.setXY(-1.0, 0.0); localAnchorB.setXY(1.0, 0.0); } diff --git a/lib/box2d/src/dynamics/joints/weld_joint.dart b/lib/src/dynamics/joints/weld_joint.dart similarity index 96% rename from lib/box2d/src/dynamics/joints/weld_joint.dart rename to lib/src/dynamics/joints/weld_joint.dart index 16b0e87..beaa67e 100644 --- a/lib/box2d/src/dynamics/joints/weld_joint.dart +++ b/lib/src/dynamics/joints/weld_joint.dart @@ -38,7 +38,6 @@ part of box2d; //J = [0 0 -1 0 0 1] //K = invI1 + invI2 - /** * A weld joint essentially glues two bodies together. A weld joint may distort somewhat because the * island constraint solver is approximate. @@ -58,7 +57,6 @@ class WeldJoint extends Joint { double m_gamma = 0.0; final Vec3 m_impulse; - // Solver temp int m_indexA = 0; int m_indexB = 0; @@ -110,23 +108,19 @@ class WeldJoint extends Joint { this.m_dampingRatio = dampingRatio; } - void getAnchorA(Vec2 argOut) { m_bodyA.getWorldPointToOut(m_localAnchorA, argOut); } - void getAnchorB(Vec2 argOut) { m_bodyB.getWorldPointToOut(m_localAnchorB, argOut); } - void getReactionForce(double inv_dt, Vec2 argOut) { argOut.setXY(m_impulse.x, m_impulse.y); argOut.mulLocal(inv_dt); } - double getReactionTorque(double inv_dt) { return inv_dt * m_impulse.z; } @@ -159,8 +153,10 @@ class WeldJoint extends Joint { qB.setAngle(aB); // Compute the effective masses. - Rot.mulToOutUnsafe(qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), m_rA); - Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), m_rB); + Rot.mulToOutUnsafe( + qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), m_rA); + Rot.mulToOutUnsafe( + qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), m_rB); // J = [-I -r1_skew I r2_skew] // [ 0 -1 0 1] @@ -343,8 +339,10 @@ class WeldJoint extends Joint { double iA = m_invIA, iB = m_invIB; - Rot.mulToOutUnsafe(qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), rA); - Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), rB); + Rot.mulToOutUnsafe( + qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), rA); + Rot.mulToOutUnsafe( + qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), rB); double positionError, angularError; final Mat33 K = pool.popMat33(); @@ -410,6 +408,7 @@ class WeldJoint extends Joint { pool.pushRot(2); pool.pushMat33(1); - return positionError <= Settings.linearSlop && angularError <= Settings.angularSlop; + return positionError <= Settings.linearSlop && + angularError <= Settings.angularSlop; } } diff --git a/lib/box2d/src/dynamics/joints/weld_joint_def.dart b/lib/src/dynamics/joints/weld_joint_def.dart similarity index 99% rename from lib/box2d/src/dynamics/joints/weld_joint_def.dart rename to lib/src/dynamics/joints/weld_joint_def.dart index 7301d78..05fac96 100644 --- a/lib/box2d/src/dynamics/joints/weld_joint_def.dart +++ b/lib/src/dynamics/joints/weld_joint_def.dart @@ -24,7 +24,6 @@ part of box2d; - class WeldJointDef extends JointDef { /** * The local anchor point relative to body1's origin. diff --git a/lib/box2d/src/dynamics/joints/wheel_joint.dart b/lib/src/dynamics/joints/wheel_joint.dart similarity index 92% rename from lib/box2d/src/dynamics/joints/wheel_joint.dart rename to lib/src/dynamics/joints/wheel_joint.dart index 2c24a00..911a7a6 100644 --- a/lib/box2d/src/dynamics/joints/wheel_joint.dart +++ b/lib/src/dynamics/joints/wheel_joint.dart @@ -79,8 +79,10 @@ class WheelJoint extends Joint { final Vec2 m_ax = new Vec2.zero(); final Vec2 m_ay = new Vec2.zero(); - double m_sAx = 0.0, m_sBx = 0.0; - double m_sAy = 0.0, m_sBy = 0.0; + double m_sAx = 0.0, + m_sBx = 0.0; + double m_sAy = 0.0, + m_sBy = 0.0; double m_mass = 0.0; double m_motorMass = 0.0; @@ -89,8 +91,7 @@ class WheelJoint extends Joint { double m_bias = 0.0; double m_gamma = 0.0; - WheelJoint(IWorldPool argPool, WheelJointDef def) - : super(argPool, def) { + WheelJoint(IWorldPool argPool, WheelJointDef def) : super(argPool, def) { m_localAnchorA.set(def.localAnchorA); m_localAnchorB.set(def.localAnchorB); m_localXAxisA.set(def.localAxisA); @@ -118,18 +119,18 @@ class WheelJoint extends Joint { void getAnchorA(Vec2 argOut) { m_bodyA.getWorldPointToOut(m_localAnchorA, argOut); } - + void getAnchorB(Vec2 argOut) { m_bodyB.getWorldPointToOut(m_localAnchorB, argOut); } - + void getReactionForce(double inv_dt, Vec2 argOut) { final Vec2 temp = pool.popVec2(); temp.set(m_ay).mulLocal(m_impulse); argOut.set(m_ax).mulLocal(m_springImpulse).addLocal(temp).mulLocal(inv_dt); pool.pushVec2(1); } - + double getReactionTorque(double inv_dt) { return inv_dt * m_motorImpulse; } @@ -216,7 +217,6 @@ class WheelJoint extends Joint { final Vec2 rB = new Vec2.zero(); final Vec2 d = new Vec2.zero(); - void initVelocityConstraints(SolverData data) { m_indexA = m_bodyA.m_islandIndex; m_indexB = m_bodyB.m_islandIndex; @@ -227,8 +227,10 @@ class WheelJoint extends Joint { m_invIA = m_bodyA.m_invI; m_invIB = m_bodyB.m_invI; - double mA = m_invMassA, mB = m_invMassB; - double iA = m_invIA, iB = m_invIB; + double mA = m_invMassA, + mB = m_invMassB; + double iA = m_invIA, + iB = m_invIB; Vec2 cA = data.positions[m_indexA].c; double aA = data.positions[m_indexA].a; @@ -248,8 +250,10 @@ class WheelJoint extends Joint { qB.setAngle(aB); // Compute the effective masses. - Rot.mulToOutUnsafe(qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), rA); - Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), rB); + Rot.mulToOutUnsafe( + qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), rA); + Rot.mulToOutUnsafe( + qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), rB); d.set(cB).addLocal(rB).subLocal(cA).subLocal(rA); // Point to line constraint @@ -353,10 +357,11 @@ class WheelJoint extends Joint { data.velocities[m_indexB].w = wB; } - void solveVelocityConstraints(SolverData data) { - double mA = m_invMassA, mB = m_invMassB; - double iA = m_invIA, iB = m_invIB; + double mA = m_invMassA, + mB = m_invMassB; + double iA = m_invIA, + iB = m_invIB; Vec2 vA = data.velocities[m_indexA].v; double wA = data.velocities[m_indexA].w; @@ -368,8 +373,10 @@ class WheelJoint extends Joint { // Solve spring constraint { - double Cdot = Vec2.dot(m_ax, temp.set(vB).subLocal(vA)) + m_sBx * wB - m_sAx * wA; - double impulse = -m_springMass * (Cdot + m_bias + m_gamma * m_springImpulse); + double Cdot = + Vec2.dot(m_ax, temp.set(vB).subLocal(vA)) + m_sBx * wB - m_sAx * wA; + double impulse = + -m_springMass * (Cdot + m_bias + m_gamma * m_springImpulse); m_springImpulse += impulse; P.x = impulse * m_ax.x; @@ -393,7 +400,8 @@ class WheelJoint extends Joint { double oldImpulse = m_motorImpulse; double maxImpulse = data.step.dt * m_maxMotorTorque; - m_motorImpulse = MathUtils.clampDouble(m_motorImpulse + impulse, -maxImpulse, maxImpulse); + m_motorImpulse = MathUtils.clampDouble( + m_motorImpulse + impulse, -maxImpulse, maxImpulse); impulse = m_motorImpulse - oldImpulse; wA -= iA * impulse; @@ -402,7 +410,8 @@ class WheelJoint extends Joint { // Solve point to line constraint { - double Cdot = Vec2.dot(m_ay, temp.set(vB).subLocal(vA)) + m_sBy * wB - m_sAy * wA; + double Cdot = + Vec2.dot(m_ay, temp.set(vB).subLocal(vA)) + m_sBy * wB - m_sAy * wA; double impulse = -m_mass * Cdot; m_impulse += impulse; @@ -427,7 +436,6 @@ class WheelJoint extends Joint { data.velocities[m_indexB].w = wB; } - bool solvePositionConstraints(SolverData data) { Vec2 cA = data.positions[m_indexA].c; double aA = data.positions[m_indexA].a; @@ -453,7 +461,10 @@ class WheelJoint extends Joint { double C = Vec2.dot(d, ay); - double k = m_invMassA + m_invMassB + m_invIA * m_sAy * m_sAy + m_invIB * m_sBy * m_sBy; + double k = m_invMassA + + m_invMassB + + m_invIA * m_sAy * m_sAy + + m_invIB * m_sBy * m_sBy; double impulse; if (k != 0.0) { diff --git a/lib/box2d/src/dynamics/joints/wheel_joint_def.dart b/lib/src/dynamics/joints/wheel_joint_def.dart similarity index 98% rename from lib/box2d/src/dynamics/joints/wheel_joint_def.dart rename to lib/src/dynamics/joints/wheel_joint_def.dart index 90497b3..dd3a649 100644 --- a/lib/box2d/src/dynamics/joints/wheel_joint_def.dart +++ b/lib/src/dynamics/joints/wheel_joint_def.dart @@ -75,8 +75,7 @@ class WheelJointDef extends JointDef { */ double dampingRatio = 0.0; - WheelJointDef() - : super(JointType.WHEEL) { + WheelJointDef() : super(JointType.WHEEL) { localAxisA.setXY(1.0, 0.0); } diff --git a/lib/box2d/src/dynamics/profile.dart b/lib/src/dynamics/profile.dart similarity index 100% rename from lib/box2d/src/dynamics/profile.dart rename to lib/src/dynamics/profile.dart diff --git a/lib/box2d/src/dynamics/solver_data.dart b/lib/src/dynamics/solver_data.dart similarity index 100% rename from lib/box2d/src/dynamics/solver_data.dart rename to lib/src/dynamics/solver_data.dart diff --git a/lib/box2d/src/dynamics/time_step.dart b/lib/src/dynamics/time_step.dart similarity index 99% rename from lib/box2d/src/dynamics/time_step.dart rename to lib/src/dynamics/time_step.dart index 0fcd249..ef92398 100644 --- a/lib/box2d/src/dynamics/time_step.dart +++ b/lib/src/dynamics/time_step.dart @@ -28,19 +28,19 @@ part of box2d; * This is an internal structure. */ class TimeStep { - + /** time step */ double dt = 0.0; - + /** inverse time step (0 if dt == 0). */ double inv_dt = 0.0; - + /** dt * inv_dt0 */ double dtRatio = 0.0; - + int velocityIterations = 0; - + int positionIterations = 0; - + bool warmStarting = false; } diff --git a/lib/box2d/src/dynamics/world.dart b/lib/src/dynamics/world.dart similarity index 89% rename from lib/box2d/src/dynamics/world.dart rename to lib/src/dynamics/world.dart index fc71d00..b4c7fb9 100644 --- a/lib/box2d/src/dynamics/world.dart +++ b/lib/src/dynamics/world.dart @@ -36,7 +36,6 @@ class World { static const int LOCKED = 0x0002; static const int CLEAR_FORCES = 0x0004; - // statistics gathering int activeContacts = 0; int contactPoolCount = 0; @@ -86,15 +85,17 @@ class World { return res; } - List> contactStacks = _create2D(ShapeType.values.length, ShapeType.values.length); + List> contactStacks = + _create2D(ShapeType.values.length, ShapeType.values.length); /** * Construct a world object. * * @param gravity the world gravity vector. */ - factory World.withGravity (Vec2 gravity) { - var w = new World.withPool(gravity, new DefaultWorldPool(WORLD_POOL_SIZE, WORLD_POOL_CONTAINER_SIZE)); + factory World.withGravity(Vec2 gravity) { + var w = new World.withPool(gravity, + new DefaultWorldPool(WORLD_POOL_SIZE, WORLD_POOL_CONTAINER_SIZE)); return w; } @@ -108,13 +109,14 @@ class World { return w; } - factory World.withPoolAndStrategy(Vec2 gravity, IWorldPool pool, BroadPhaseStrategy strategy) { + factory World.withPoolAndStrategy( + Vec2 gravity, IWorldPool pool, BroadPhaseStrategy strategy) { var w = new World(gravity, pool, new DefaultBroadPhaseBuffer(strategy)); return w; } - World(Vec2 gravity, this.pool, BroadPhase broadPhase) : m_gravity = new Vec2.copy(gravity) { - + World(Vec2 gravity, this.pool, BroadPhase broadPhase) + : m_gravity = new Vec2.copy(gravity) { m_destructionListener = null; m_debugDraw = null; @@ -168,7 +170,8 @@ class World { return m_allowSleep; } - void _addType(IDynamicStack creator, ShapeType type1, ShapeType type2) { + void _addType( + IDynamicStack creator, ShapeType type1, ShapeType type2) { ContactRegister register = new ContactRegister(); register.creator = creator; register.primary = true; @@ -184,12 +187,16 @@ class World { void _initializeRegisters() { _addType(pool.getCircleContactStack(), ShapeType.CIRCLE, ShapeType.CIRCLE); - _addType(pool.getPolyCircleContactStack(), ShapeType.POLYGON, ShapeType.CIRCLE); + _addType( + pool.getPolyCircleContactStack(), ShapeType.POLYGON, ShapeType.CIRCLE); _addType(pool.getPolyContactStack(), ShapeType.POLYGON, ShapeType.POLYGON); - _addType(pool.getEdgeCircleContactStack(), ShapeType.EDGE, ShapeType.CIRCLE); + _addType( + pool.getEdgeCircleContactStack(), ShapeType.EDGE, ShapeType.CIRCLE); _addType(pool.getEdgePolyContactStack(), ShapeType.EDGE, ShapeType.POLYGON); - _addType(pool.getChainCircleContactStack(), ShapeType.CHAIN, ShapeType.CIRCLE); - _addType(pool.getChainPolyContactStack(), ShapeType.CHAIN, ShapeType.POLYGON); + _addType( + pool.getChainCircleContactStack(), ShapeType.CHAIN, ShapeType.CIRCLE); + _addType( + pool.getChainPolyContactStack(), ShapeType.CHAIN, ShapeType.POLYGON); } DestructionListener getDestructionListener() { @@ -204,7 +211,8 @@ class World { m_particleDestructionListener = listener; } - Contact popContact(Fixture fixtureA, int indexA, Fixture fixtureB, int indexB) { + Contact popContact( + Fixture fixtureA, int indexA, Fixture fixtureB, int indexB) { final ShapeType type1 = fixtureA.getType(); final ShapeType type2 = fixtureB.getType(); @@ -228,7 +236,9 @@ class World { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); - if (contact.m_manifold.pointCount > 0 && !fixtureA.isSensor() && !fixtureB.isSensor()) { + if (contact.m_manifold.pointCount > 0 && + !fixtureA.isSensor() && + !fixtureB.isSensor()) { fixtureA.getBody().setAwake(true); fixtureB.getBody().setAwake(true); } @@ -236,7 +246,8 @@ class World { ShapeType type1 = fixtureA.getType(); ShapeType type2 = fixtureB.getType(); - IDynamicStack creator = contactStacks[type1.index][type2.index].creator; + IDynamicStack creator = + contactStacks[type1.index][type2.index].creator; creator.push(contact); } @@ -290,7 +301,7 @@ class World { * @return */ Body createBody(BodyDef def) { - assert (isLocked() == false); + assert(isLocked() == false); if (isLocked()) { return null; } @@ -318,8 +329,8 @@ class World { * @param body */ void destroyBody(Body body) { - assert (m_bodyCount > 0); - assert (isLocked() == false); + assert(m_bodyCount > 0); + assert(isLocked() == false); if (isLocked()) { return; } @@ -392,7 +403,7 @@ class World { * @return */ Joint createJoint(JointDef def) { - assert (isLocked() == false); + assert(isLocked() == false); if (isLocked()) { return null; } @@ -456,7 +467,7 @@ class World { * @param joint */ void destroyJoint(Joint j) { - assert (isLocked() == false); + assert(isLocked() == false); if (isLocked()) { return; } @@ -518,7 +529,7 @@ class World { Joint.destroy(j); - assert (m_jointCount > 0); + assert(m_jointCount > 0); --m_jointCount; // If the joint prevents collisions, then flag any contacts for filtering. @@ -640,7 +651,6 @@ class World { return; } - int flags = m_debugDraw.getFlags(); bool wireframe = (flags & DebugDraw.e_wireframeDrawingBit) != 0; @@ -677,7 +687,9 @@ class World { if ((flags & DebugDraw.e_pairBit) != 0) { color.setRGB(0.3, 0.9, 0.9); - for (Contact c = m_contactManager.m_contactList; c != null; c = c.getNext()) { + for (Contact c = m_contactManager.m_contactList; + c != null; + c = c.getNext()) { Fixture fixtureA = c.getFixtureA(); Fixture fixtureB = c.getFixtureB(); fixtureA.getAABB(c.getChildIndexA()).getCenterToOut(cA); @@ -747,7 +759,8 @@ class World { * @param particleCallback callback for particles. * @param aabb the query box. */ - void queryAABBTwoCallbacks(QueryCallback callback, ParticleQueryCallback particleCallback, AABB aabb) { + void queryAABBTwoCallbacks(QueryCallback callback, + ParticleQueryCallback particleCallback, AABB aabb) { wqwrapper.broadPhase = m_contactManager.m_broadPhase; wqwrapper.callback = callback; m_contactManager.m_broadPhase.query(wqwrapper, aabb); @@ -795,8 +808,8 @@ class World { * @param point1 the ray starting point * @param point2 the ray ending point */ - void raycastTwoCallBacks(RayCastCallback callback, ParticleRaycastCallback particleCallback, - Vec2 point1, Vec2 point2) { + void raycastTwoCallBacks(RayCastCallback callback, + ParticleRaycastCallback particleCallback, Vec2 point1, Vec2 point2) { wrcwrapper.broadPhase = m_contactManager.m_broadPhase; wrcwrapper.callback = callback; input.maxFraction = 1.0; @@ -814,7 +827,8 @@ class World { * @param point1 the ray starting point * @param point2 the ray ending point */ - void raycastParticle(ParticleRaycastCallback particleCallback, Vec2 point1, Vec2 point2) { + void raycastParticle( + ParticleRaycastCallback particleCallback, Vec2 point1, Vec2 point2) { m_particleSystem.raycast(particleCallback, point1, point2); } @@ -884,8 +898,6 @@ class World { return m_continuousPhysics; } - - /** * Get the number of broad-phase proxies. * @@ -1012,7 +1024,8 @@ class World { } final Island island = new Island(); - List stack = new List(10); // TODO djm find a good initial stack number; + List stack = + new List(10); // TODO djm find a good initial stack number; final Timer broadphaseTimer = new Timer(); void solve(TimeStep step) { @@ -1069,7 +1082,7 @@ class World { while (stackCount > 0) { // Grab the next body off the stack and add it to the island. Body b = stack[--stackCount]; - assert (b.isActive() == true); + assert(b.isActive() == true); island.addBody(b); // Make sure the body is awake. @@ -1112,7 +1125,7 @@ class World { continue; } - assert (stackCount < stackSize); + assert(stackCount < stackSize); stack[stackCount++] = other; other.m_flags |= Body.e_islandFlag; } @@ -1137,7 +1150,7 @@ class World { continue; } - assert (stackCount < stackSize); + assert(stackCount < stackSize); stack[stackCount++] = other; other.m_flags |= Body.e_islandFlag; } @@ -1187,7 +1200,6 @@ class World { final Sweep backup2 = new Sweep(); void solveTOI(final TimeStep step) { - final Island island = toiIsland; island.init(2 * Settings.maxTOIContacts, Settings.maxTOIContacts, 0, m_contactManager.m_contactListener); @@ -1197,7 +1209,9 @@ class World { b.m_sweep.alpha0 = 0.0; } - for (Contact c = m_contactManager.m_contactList; c != null; c = c.m_next) { + for (Contact c = m_contactManager.m_contactList; + c != null; + c = c.m_next) { // Invalidate TOI c.m_flags &= ~(Contact.TOI_FLAG | Contact.ISLAND_FLAG); c.m_toiCount = 0.0; @@ -1211,7 +1225,9 @@ class World { Contact minContact = null; double minAlpha = 1.0; - for (Contact c = m_contactManager.m_contactList; c != null; c = c.m_next) { + for (Contact c = m_contactManager.m_contactList; + c != null; + c = c.m_next) { // Is this contact disabled? if (c.isEnabled() == false) { continue; @@ -1240,7 +1256,7 @@ class World { BodyType typeA = bA.m_type; BodyType typeB = bB.m_type; - assert (typeA == BodyType.DYNAMIC || typeB == BodyType.DYNAMIC); + assert(typeA == BodyType.DYNAMIC || typeB == BodyType.DYNAMIC); bool activeA = bA.isAwake() && typeA != BodyType.STATIC; bool activeB = bB.isAwake() && typeB != BodyType.STATIC; @@ -1270,7 +1286,7 @@ class World { bB.m_sweep.advance(alpha0); } - assert (alpha0 < 1.0); + assert(alpha0 < 1.0); int indexA = c.getChildIndexA(); int indexB = c.getChildIndexB(); @@ -1375,8 +1391,9 @@ class World { // Only add static, kinematic, or bullet bodies. Body other = ce.other; - if (other.m_type == BodyType.DYNAMIC && body.isBullet() == false - && other.isBullet() == false) { + if (other.m_type == BodyType.DYNAMIC && + body.isBullet() == false && + other.isBullet() == false) { continue; } @@ -1482,19 +1499,20 @@ class World { color.setRGB(0.5, 0.8, 0.8); switch (joint.getType()) { - // TODO djm write after writing joints + // TODO djm write after writing joints case JointType.DISTANCE: m_debugDraw.drawSegment(p1, p2, color); break; - case JointType.PULLEY: { - PulleyJoint pulley = joint; - Vec2 s1 = pulley.getGroundAnchorA(); - Vec2 s2 = pulley.getGroundAnchorB(); - m_debugDraw.drawSegment(s1, p1, color); - m_debugDraw.drawSegment(s2, p2, color); - m_debugDraw.drawSegment(s1, s2, color); - } + case JointType.PULLEY: + { + PulleyJoint pulley = joint; + Vec2 s1 = pulley.getGroundAnchorA(); + Vec2 s2 = pulley.getGroundAnchorB(); + m_debugDraw.drawSegment(s1, p1, color); + m_debugDraw.drawSegment(s2, p2, color); + m_debugDraw.drawSegment(s1, s2, color); + } break; case JointType.CONSTANT_VOLUME: case JointType.MOUSE: @@ -1525,74 +1543,79 @@ class World { void drawShape(Fixture fixture, Transform xf, Color3f color, bool wireframe) { switch (fixture.getType()) { - case ShapeType.CIRCLE: { - CircleShape circle = fixture.getShape(); - - // Vec2 center = Mul(xf, circle.m_p); - Transform.mulToOutUnsafeVec2(xf, circle.m_p, center); - double radius = circle.m_radius; - xf.q.getXAxis(axis); - - if (fixture.getUserData() != null && fixture.getUserData() == LIQUID_INT) { - Body b = fixture.getBody(); - liquidOffset.set(b.m_linearVelocity); - double linVelLength = b.m_linearVelocity.length(); - if (averageLinearVel == -1) { - averageLinearVel = linVelLength; + case ShapeType.CIRCLE: + { + CircleShape circle = fixture.getShape(); + + // Vec2 center = Mul(xf, circle.m_p); + Transform.mulToOutUnsafeVec2(xf, circle.m_p, center); + double radius = circle.m_radius; + xf.q.getXAxis(axis); + + if (fixture.getUserData() != null && + fixture.getUserData() == LIQUID_INT) { + Body b = fixture.getBody(); + liquidOffset.set(b.m_linearVelocity); + double linVelLength = b.m_linearVelocity.length(); + if (averageLinearVel == -1) { + averageLinearVel = linVelLength; + } else { + averageLinearVel = .98 * averageLinearVel + .02 * linVelLength; + } + liquidOffset.mulLocal(liquidLength / averageLinearVel / 2); + circCenterMoved.set(center).addLocal(liquidOffset); + center.subLocal(liquidOffset); + m_debugDraw.drawSegment(center, circCenterMoved, liquidColor); + return; + } + if (wireframe) { + m_debugDraw.drawCircleAxis(center, radius, axis, color); } else { - averageLinearVel = .98 * averageLinearVel + .02 * linVelLength; + m_debugDraw.drawSolidCircle(center, radius, axis, color); } - liquidOffset.mulLocal(liquidLength / averageLinearVel / 2); - circCenterMoved.set(center).addLocal(liquidOffset); - center.subLocal(liquidOffset); - m_debugDraw.drawSegment(center, circCenterMoved, liquidColor); - return; - } - if (wireframe) { - m_debugDraw.drawCircleAxis(center, radius, axis, color); - } else { - m_debugDraw.drawSolidCircle(center, radius, axis, color); } - } break; - case ShapeType.POLYGON: { - PolygonShape poly =fixture.getShape(); - int vertexCount = poly.m_count; - assert (vertexCount <= Settings.maxPolygonVertices); - List vertices = tlvertices.get(Settings.maxPolygonVertices); + case ShapeType.POLYGON: + { + PolygonShape poly = fixture.getShape(); + int vertexCount = poly.m_count; + assert(vertexCount <= Settings.maxPolygonVertices); + List vertices = tlvertices.get(Settings.maxPolygonVertices); - for (int i = 0; i < vertexCount; ++i) { - // vertices[i] = Mul(xf, poly.m_vertices[i]); - Transform.mulToOutUnsafeVec2(xf, poly.m_vertices[i], vertices[i]); - } - if (wireframe) { - m_debugDraw.drawPolygon(vertices, vertexCount, color); - } else { - m_debugDraw.drawSolidPolygon(vertices, vertexCount, color); + for (int i = 0; i < vertexCount; ++i) { + // vertices[i] = Mul(xf, poly.m_vertices[i]); + Transform.mulToOutUnsafeVec2(xf, poly.m_vertices[i], vertices[i]); + } + if (wireframe) { + m_debugDraw.drawPolygon(vertices, vertexCount, color); + } else { + m_debugDraw.drawSolidPolygon(vertices, vertexCount, color); + } } - } - break; - case ShapeType.EDGE: { - EdgeShape edge = fixture.getShape(); - Transform.mulToOutUnsafeVec2(xf, edge.m_vertex1, v1); - Transform.mulToOutUnsafeVec2(xf, edge.m_vertex2, v2); - m_debugDraw.drawSegment(v1, v2, color); - } break; - case ShapeType.CHAIN: { - ChainShape chain = fixture.getShape(); - int count = chain.m_count; - List vertices = chain.m_vertices; - - Transform.mulToOutUnsafeVec2(xf, vertices[0], v1); - for (int i = 1; i < count; ++i) { - Transform.mulToOutUnsafeVec2(xf, vertices[i], v2); + case ShapeType.EDGE: + { + EdgeShape edge = fixture.getShape(); + Transform.mulToOutUnsafeVec2(xf, edge.m_vertex1, v1); + Transform.mulToOutUnsafeVec2(xf, edge.m_vertex2, v2); m_debugDraw.drawSegment(v1, v2, color); - m_debugDraw.drawCircle(v1, 0.05, color); - v1.set(v2); } - } + break; + case ShapeType.CHAIN: + { + ChainShape chain = fixture.getShape(); + int count = chain.m_count; + List vertices = chain.m_vertices; + + Transform.mulToOutUnsafeVec2(xf, vertices[0], v1); + for (int i = 1; i < count; ++i) { + Transform.mulToOutUnsafeVec2(xf, vertices[i], v2); + m_debugDraw.drawSegment(v1, v2, color); + m_debugDraw.drawCircle(v1, 0.05, color); + v1.set(v2); + } + } break; default: break; @@ -1600,7 +1623,8 @@ class World { } void drawParticleSystem(ParticleSystem system) { - bool wireframe = (m_debugDraw.getFlags() & DebugDraw.e_wireframeDrawingBit) != 0; + bool wireframe = + (m_debugDraw.getFlags() & DebugDraw.e_wireframeDrawingBit) != 0; int particleCount = system.getParticleCount(); if (particleCount != 0) { double particleRadius = system.getParticleRadius(); @@ -1610,10 +1634,11 @@ class World { colorBuffer = system.getParticleColorBuffer(); } if (wireframe) { - m_debugDraw.drawParticlesWireframe(positionBuffer, particleRadius, colorBuffer, - particleCount); + m_debugDraw.drawParticlesWireframe( + positionBuffer, particleRadius, colorBuffer, particleCount); } else { - m_debugDraw.drawParticles(positionBuffer, particleRadius, colorBuffer, particleCount); + m_debugDraw.drawParticles( + positionBuffer, particleRadius, colorBuffer, particleCount); } } } @@ -1628,7 +1653,7 @@ class World { * @return the index of the particle. */ int createParticle(ParticleDef def) { - assert (isLocked() == false); + assert(isLocked() == false); if (isLocked()) { return 0; } @@ -1680,12 +1705,14 @@ class World { * @warning This function is locked during callbacks. * @return Number of particles destroyed. */ - int destroyParticlesInShapeFlag(Shape shape, Transform xf, bool callDestructionListener) { - assert (isLocked() == false); + int destroyParticlesInShapeFlag( + Shape shape, Transform xf, bool callDestructionListener) { + assert(isLocked() == false); if (isLocked()) { return 0; } - return m_particleSystem.destroyParticlesInShape(shape, xf, callDestructionListener); + return m_particleSystem.destroyParticlesInShape( + shape, xf, callDestructionListener); } /** @@ -1695,7 +1722,7 @@ class World { * @warning This function is locked during callbacks. */ ParticleGroup createParticleGroup(ParticleGroupDef def) { - assert (isLocked() == false); + assert(isLocked() == false); if (isLocked()) { return null; } @@ -1711,7 +1738,7 @@ class World { * @warning This function is locked during callbacks. */ void joinParticleGroups(ParticleGroup groupA, ParticleGroup groupB) { - assert (isLocked() == false); + assert(isLocked() == false); if (isLocked()) { return; } @@ -1725,8 +1752,9 @@ class World { * @param Whether to call the world b2DestructionListener for each particle is destroyed. * @warning This function is locked during callbacks. */ - void destroyParticlesInGroupFlag(ParticleGroup group, bool callDestructionListener) { - assert (isLocked() == false); + void destroyParticlesInGroupFlag( + ParticleGroup group, bool callDestructionListener) { + assert(isLocked() == false); if (isLocked()) { return; } @@ -1816,7 +1844,6 @@ class World { */ void setParticleGravityScale(double gravityScale) { m_particleSystem.setParticleGravityScale(gravityScale); - } /** @@ -1908,17 +1935,14 @@ class World { void setParticlePositionBuffer(List buffer, int capacity) { m_particleSystem.setParticlePositionBuffer(buffer, capacity); - } void setParticleVelocityBuffer(List buffer, int capacity) { m_particleSystem.setParticleVelocityBuffer(buffer, capacity); - } void setParticleColorBuffer(List buffer, int capacity) { m_particleSystem.setParticleColorBuffer(buffer, capacity); - } void setParticleUserDataBuffer(List buffer, int capacity) { @@ -1959,16 +1983,14 @@ class World { double computeParticleCollisionEnergy() { return m_particleSystem.computeParticleCollisionEnergy(); } - + // For debugging purposes. void forEachBody(void action(Body body)) { for (Body body = m_bodyList; body != null; body = body.getNext()) { action(body); - } + } } - -} // class World. - +} // class World. class WorldQueryWrapper implements TreeCallback { bool treeCallback(int nodeId) { @@ -1980,7 +2002,6 @@ class WorldQueryWrapper implements TreeCallback { QueryCallback callback; } - class WorldRayCastWrapper implements TreeRayCastCallback { // djm pooling diff --git a/lib/box2d/src/particle/particle_body_contact.dart b/lib/src/particle/particle_body_contact.dart similarity index 100% rename from lib/box2d/src/particle/particle_body_contact.dart rename to lib/src/particle/particle_body_contact.dart diff --git a/lib/box2d/src/particle/particle_color.dart b/lib/src/particle/particle_color.dart similarity index 93% rename from lib/box2d/src/particle/particle_color.dart rename to lib/src/particle/particle_color.dart index b0aa8de..e045c40 100644 --- a/lib/box2d/src/particle/particle_color.dart +++ b/lib/src/particle/particle_color.dart @@ -32,11 +32,19 @@ part of box2d; class ParticleColor { Int8List _data = new Int8List(4); - void set r(v) { _data[0] = v; } - void set g(v) { _data[1] = v; } - void set b(v) { _data[2] = v; } - void set a(v) { _data[3] = v; } - + void set r(v) { + _data[0] = v; + } + void set g(v) { + _data[1] = v; + } + void set b(v) { + _data[2] = v; + } + void set a(v) { + _data[3] = v; + } + get r => _data[0]; get g => _data[1]; get b => _data[2]; @@ -63,14 +71,14 @@ class ParticleColor { b = (255 * color.z); a = 255; } - + void setParticleColor(ParticleColor color) { r = color.r; g = color.g; b = color.b; a = color.a; } - + bool isZero() { return r == 0 && g == 0 && b == 0 && a == 0; } diff --git a/lib/box2d/src/particle/particle_contact.dart b/lib/src/particle/particle_contact.dart similarity index 99% rename from lib/box2d/src/particle/particle_contact.dart rename to lib/src/particle/particle_contact.dart index 3434002..f68dc36 100644 --- a/lib/box2d/src/particle/particle_contact.dart +++ b/lib/src/particle/particle_contact.dart @@ -24,7 +24,6 @@ part of box2d; - class ParticleContact { /** Indices of the respective particles making contact. */ int indexA = 0; diff --git a/lib/box2d/src/particle/particle_def.dart b/lib/src/particle/particle_def.dart similarity index 100% rename from lib/box2d/src/particle/particle_def.dart rename to lib/src/particle/particle_def.dart diff --git a/lib/box2d/src/particle/particle_group.dart b/lib/src/particle/particle_group.dart similarity index 99% rename from lib/box2d/src/particle/particle_group.dart rename to lib/src/particle/particle_group.dart index 2a0ac59..6c52eec 100644 --- a/lib/box2d/src/particle/particle_group.dart +++ b/lib/src/particle/particle_group.dart @@ -24,9 +24,7 @@ part of box2d; - class ParticleGroup { - ParticleSystem m_system; int m_firstIndex = 0; int m_lastIndex = 0; diff --git a/lib/box2d/src/particle/particle_group_def.dart b/lib/src/particle/particle_group_def.dart similarity index 100% rename from lib/box2d/src/particle/particle_group_def.dart rename to lib/src/particle/particle_group_def.dart diff --git a/lib/box2d/src/particle/particle_group_type.dart b/lib/src/particle/particle_group_type.dart similarity index 100% rename from lib/box2d/src/particle/particle_group_type.dart rename to lib/src/particle/particle_group_type.dart diff --git a/lib/box2d/src/particle/particle_system.dart b/lib/src/particle/particle_system.dart similarity index 84% rename from lib/box2d/src/particle/particle_system.dart rename to lib/src/particle/particle_system.dart index c404258..fc0653c 100644 --- a/lib/box2d/src/particle/particle_system.dart +++ b/lib/src/particle/particle_system.dart @@ -24,7 +24,6 @@ part of box2d; - class ParticleBuffer { List data; final allocClosure; @@ -37,7 +36,6 @@ class ParticleBufferInt { int userSuppliedCapacity; } - /** Connection between two particles */ class PsPair { int indexA = 0; @@ -82,7 +80,6 @@ class PsProxy implements Comparable { } } - class NewIndices { int start = 0, mid = 0, @@ -101,8 +98,6 @@ class NewIndices { } } - - class DestroyParticlesInShapeCallback implements ParticleQueryCallback { ParticleSystem system; Shape shape; @@ -114,7 +109,8 @@ class DestroyParticlesInShapeCallback implements ParticleQueryCallback { // TODO Auto-generated constructor stub } - void init(ParticleSystem system, Shape shape, Transform xf, bool callDestructionListener) { + void init(ParticleSystem system, Shape shape, Transform xf, + bool callDestructionListener) { this.system = system; this.shape = shape; this.xf = xf; @@ -137,7 +133,8 @@ class UpdateBodyContactsCallback implements QueryCallback { final Vec2 _tempVec = new Vec2.zero(); - static ParticleBodyContact allocParticleBodyContact() => new ParticleBodyContact(); + static ParticleBodyContact allocParticleBodyContact() => + new ParticleBodyContact(); bool reportFixture(Fixture fixture) { if (fixture.isSensor()) { @@ -153,32 +150,52 @@ class UpdateBodyContactsCallback implements QueryCallback { int childCount = shape.getChildCount(); for (int childIndex = 0; childIndex < childCount; childIndex++) { AABB aabb = fixture.getAABB(childIndex); - final double aabblowerBoundx = aabb.lowerBound.x - system.m_particleDiameter; - final double aabblowerBoundy = aabb.lowerBound.y - system.m_particleDiameter; - final double aabbupperBoundx = aabb.upperBound.x + system.m_particleDiameter; - final double aabbupperBoundy = aabb.upperBound.y + system.m_particleDiameter; - int firstProxy = ParticleSystem._lowerBound(system.m_proxyBuffer, system.m_proxyCount, ParticleSystem.computeTag(system.m_inverseDiameter * aabblowerBoundx, system.m_inverseDiameter * aabblowerBoundy)); - int lastProxy = ParticleSystem._upperBound(system.m_proxyBuffer, system.m_proxyCount, ParticleSystem.computeTag(system.m_inverseDiameter * aabbupperBoundx, system.m_inverseDiameter * aabbupperBoundy)); + final double aabblowerBoundx = + aabb.lowerBound.x - system.m_particleDiameter; + final double aabblowerBoundy = + aabb.lowerBound.y - system.m_particleDiameter; + final double aabbupperBoundx = + aabb.upperBound.x + system.m_particleDiameter; + final double aabbupperBoundy = + aabb.upperBound.y + system.m_particleDiameter; + int firstProxy = ParticleSystem._lowerBound(system.m_proxyBuffer, + system.m_proxyCount, ParticleSystem.computeTag( + system.m_inverseDiameter * aabblowerBoundx, + system.m_inverseDiameter * aabblowerBoundy)); + int lastProxy = ParticleSystem._upperBound(system.m_proxyBuffer, + system.m_proxyCount, ParticleSystem.computeTag( + system.m_inverseDiameter * aabbupperBoundx, + system.m_inverseDiameter * aabbupperBoundy)); for (int proxy = firstProxy; proxy != lastProxy; ++proxy) { int a = system.m_proxyBuffer[proxy].index; Vec2 ap = system.m_positionBuffer.data[a]; - if (aabblowerBoundx <= ap.x && ap.x <= aabbupperBoundx && aabblowerBoundy <= ap.y && ap.y <= aabbupperBoundy) { + if (aabblowerBoundx <= ap.x && + ap.x <= aabbupperBoundx && + aabblowerBoundy <= ap.y && + ap.y <= aabbupperBoundy) { double d; final Vec2 n = _tempVec; d = fixture.computeDistance(ap, childIndex, n); if (d < system.m_particleDiameter) { - double invAm = (system.m_flagsBuffer.data[a] & ParticleType.b2_wallParticle) != 0 ? 0 : system.getParticleInvMass(); + double invAm = (system.m_flagsBuffer.data[a] & + ParticleType.b2_wallParticle) != + 0 ? 0 : system.getParticleInvMass(); final double rpx = ap.x - bp.x; final double rpy = ap.y - bp.y; double rpn = rpx * n.y - rpy * n.x; if (system.m_bodyContactCount >= system.m_bodyContactCapacity) { int oldCapacity = system.m_bodyContactCapacity; - int newCapacity = system.m_bodyContactCount != 0 ? 2 * system.m_bodyContactCount : Settings.minParticleBufferCapacity; - system.m_bodyContactBuffer = BufferUtils.reallocateBufferWithAlloc(system.m_bodyContactBuffer, oldCapacity, newCapacity, allocParticleBodyContact); + int newCapacity = system.m_bodyContactCount != 0 + ? 2 * system.m_bodyContactCount + : Settings.minParticleBufferCapacity; + system.m_bodyContactBuffer = BufferUtils + .reallocateBufferWithAlloc(system.m_bodyContactBuffer, + oldCapacity, newCapacity, allocParticleBodyContact); system.m_bodyContactCapacity = newCapacity; } - ParticleBodyContact contact = system.m_bodyContactBuffer[system.m_bodyContactCount]; + ParticleBodyContact contact = + system.m_bodyContactBuffer[system.m_bodyContactCount]; contact.index = a; contact.body = b; contact.weight = 1 - d * system.m_inverseDiameter; @@ -208,19 +225,27 @@ class CreateParticleGroupCallback implements VoronoiDiagramCallback { final double dbcy = pb.y - pc.y; final double dcax = pc.x - pa.x; final double dcay = pc.y - pa.y; - double maxDistanceSquared = Settings.maxTriadDistanceSquared * system.m_squaredDiameter; - if (dabx * dabx + daby * daby < maxDistanceSquared && dbcx * dbcx + dbcy * dbcy < maxDistanceSquared && dcax * dcax + dcay * dcay < maxDistanceSquared) { + double maxDistanceSquared = + Settings.maxTriadDistanceSquared * system.m_squaredDiameter; + if (dabx * dabx + daby * daby < maxDistanceSquared && + dbcx * dbcx + dbcy * dbcy < maxDistanceSquared && + dcax * dcax + dcay * dcay < maxDistanceSquared) { if (system.m_triadCount >= system.m_triadCapacity) { int oldCapacity = system.m_triadCapacity; - int newCapacity = system.m_triadCount != 0 ? 2 * system.m_triadCount : Settings.minParticleBufferCapacity; - system.m_triadBuffer = BufferUtils.reallocateBufferWithAlloc(system.m_triadBuffer, oldCapacity, newCapacity, allocPsTriad); + int newCapacity = system.m_triadCount != 0 + ? 2 * system.m_triadCount + : Settings.minParticleBufferCapacity; + system.m_triadBuffer = BufferUtils.reallocateBufferWithAlloc( + system.m_triadBuffer, oldCapacity, newCapacity, allocPsTriad); system.m_triadCapacity = newCapacity; } PsTriad triad = system.m_triadBuffer[system.m_triadCount]; triad.indexA = a; triad.indexB = b; triad.indexC = c; - triad.flags = system.m_flagsBuffer.data[a] | system.m_flagsBuffer.data[b] | system.m_flagsBuffer.data[c]; + triad.flags = system.m_flagsBuffer.data[a] | + system.m_flagsBuffer.data[b] | + system.m_flagsBuffer.data[c]; triad.strength = def.strength; final double midPointx = 1.0 / 3.0 * (pa.x + pb.x + pc.x); final double midPointy = 1.0 / 3.0 * (pa.y + pb.y + pc.y); @@ -247,7 +272,9 @@ class CreateParticleGroupCallback implements VoronoiDiagramCallback { class JoinParticleGroupsCallback implements VoronoiDiagramCallback { void callback(int a, int b, int c) { // Create a triad if it will contain particles from both groups. - int countA = ((a < groupB.m_firstIndex) ? 1 : 0) + ((b < groupB.m_firstIndex) ? 1 : 0) + ((c < groupB.m_firstIndex) ? 1 : 0); + int countA = ((a < groupB.m_firstIndex) ? 1 : 0) + + ((b < groupB.m_firstIndex) ? 1 : 0) + + ((c < groupB.m_firstIndex) ? 1 : 0); if (countA > 0 && countA < 3) { int af = system.m_flagsBuffer.data[a]; int bf = system.m_flagsBuffer.data[b]; @@ -262,12 +289,18 @@ class JoinParticleGroupsCallback implements VoronoiDiagramCallback { final double dbcy = pb.y - pc.y; final double dcax = pc.x - pa.x; final double dcay = pc.y - pa.y; - double maxDistanceSquared = Settings.maxTriadDistanceSquared * system.m_squaredDiameter; - if (dabx * dabx + daby * daby < maxDistanceSquared && dbcx * dbcx + dbcy * dbcy < maxDistanceSquared && dcax * dcax + dcay * dcay < maxDistanceSquared) { + double maxDistanceSquared = + Settings.maxTriadDistanceSquared * system.m_squaredDiameter; + if (dabx * dabx + daby * daby < maxDistanceSquared && + dbcx * dbcx + dbcy * dbcy < maxDistanceSquared && + dcax * dcax + dcay * dcay < maxDistanceSquared) { if (system.m_triadCount >= system.m_triadCapacity) { int oldCapacity = system.m_triadCapacity; - int newCapacity = system.m_triadCount != 0 ? 2 * system.m_triadCount : Settings.minParticleBufferCapacity; - system.m_triadBuffer = BufferUtils.reallocateBufferWithAlloc(system.m_triadBuffer, oldCapacity, newCapacity, allocPsTriad); + int newCapacity = system.m_triadCount != 0 + ? 2 * system.m_triadCount + : Settings.minParticleBufferCapacity; + system.m_triadBuffer = BufferUtils.reallocateBufferWithAlloc( + system.m_triadBuffer, oldCapacity, newCapacity, allocPsTriad); system.m_triadCapacity = newCapacity; } PsTriad triad = system.m_triadBuffer[system.m_triadCount]; @@ -287,7 +320,8 @@ class JoinParticleGroupsCallback implements VoronoiDiagramCallback { triad.ka = -(dcax * dabx + dcay * daby); triad.kb = -(dabx * dbcx + daby * dbcy); triad.kc = -(dbcx * dcax + dbcy * dcay); - triad.s = Vec2.cross(pa, pb) + Vec2.cross(pb, pc) + Vec2.cross(pc, pa); + triad.s = + Vec2.cross(pa, pb) + Vec2.cross(pb, pc) + Vec2.cross(pc, pa); system.m_triadCount++; } } @@ -317,17 +351,30 @@ class SolveCollisionCallback implements QueryCallback { int childCount = shape.getChildCount(); for (int childIndex = 0; childIndex < childCount; childIndex++) { AABB aabb = fixture.getAABB(childIndex); - final double aabblowerBoundx = aabb.lowerBound.x - system.m_particleDiameter; - final double aabblowerBoundy = aabb.lowerBound.y - system.m_particleDiameter; - final double aabbupperBoundx = aabb.upperBound.x + system.m_particleDiameter; - final double aabbupperBoundy = aabb.upperBound.y + system.m_particleDiameter; - int firstProxy = ParticleSystem._lowerBound(system.m_proxyBuffer, system.m_proxyCount, ParticleSystem.computeTag(system.m_inverseDiameter * aabblowerBoundx, system.m_inverseDiameter * aabblowerBoundy)); - int lastProxy = ParticleSystem._upperBound(system.m_proxyBuffer, system.m_proxyCount, ParticleSystem.computeTag(system.m_inverseDiameter * aabbupperBoundx, system.m_inverseDiameter * aabbupperBoundy)); + final double aabblowerBoundx = + aabb.lowerBound.x - system.m_particleDiameter; + final double aabblowerBoundy = + aabb.lowerBound.y - system.m_particleDiameter; + final double aabbupperBoundx = + aabb.upperBound.x + system.m_particleDiameter; + final double aabbupperBoundy = + aabb.upperBound.y + system.m_particleDiameter; + int firstProxy = ParticleSystem._lowerBound(system.m_proxyBuffer, + system.m_proxyCount, ParticleSystem.computeTag( + system.m_inverseDiameter * aabblowerBoundx, + system.m_inverseDiameter * aabblowerBoundy)); + int lastProxy = ParticleSystem._upperBound(system.m_proxyBuffer, + system.m_proxyCount, ParticleSystem.computeTag( + system.m_inverseDiameter * aabbupperBoundx, + system.m_inverseDiameter * aabbupperBoundy)); for (int proxy = firstProxy; proxy != lastProxy; ++proxy) { int a = system.m_proxyBuffer[proxy].index; Vec2 ap = system.m_positionBuffer.data[a]; - if (aabblowerBoundx <= ap.x && ap.x <= aabbupperBoundx && aabblowerBoundy <= ap.y && ap.y <= aabbupperBoundy) { + if (aabblowerBoundx <= ap.x && + ap.x <= aabbupperBoundx && + aabblowerBoundy <= ap.y && + ap.y <= aabbupperBoundy) { Vec2 av = system.m_velocityBuffer.data[a]; final Vec2 temp = tempVec; Transform.mulTransToOutUnsafeVec2(body.m_xf0, ap, temp); @@ -337,8 +384,12 @@ class SolveCollisionCallback implements QueryCallback { input.maxFraction = 1.0; if (fixture.raycast(output, input, childIndex)) { final Vec2 p = tempVec; - p.x = (1 - output.fraction) * input.p1.x + output.fraction * input.p2.x + Settings.linearSlop * output.normal.x; - p.y = (1 - output.fraction) * input.p1.y + output.fraction * input.p2.y + Settings.linearSlop * output.normal.y; + p.x = (1 - output.fraction) * input.p1.x + + output.fraction * input.p2.x + + Settings.linearSlop * output.normal.x; + p.y = (1 - output.fraction) * input.p1.y + + output.fraction * input.p2.y + + Settings.linearSlop * output.normal.y; final double vx = step.inv_dt * (p.x - ap.x); final double vy = step.inv_dt * (p.y - ap.y); @@ -361,7 +412,6 @@ class SolveCollisionCallback implements QueryCallback { } } - class ParticleSystemTest { static bool IsProxyInvalid(final PsProxy proxy) { return proxy.index < 0; @@ -384,7 +434,6 @@ class ParticleSystemTest { } } - class ParticleSystem { /** All particle types that require creating pairs */ static const int k_pairFlags = ParticleType.b2_springParticle; @@ -506,7 +555,8 @@ class ParticleSystem { int createParticle(ParticleDef def) { if (m_count >= m_internalAllocatedCapacity) { - int capacity = m_count != 0 ? 2 * m_count : Settings.minParticleBufferCapacity; + int capacity = + m_count != 0 ? 2 * m_count : Settings.minParticleBufferCapacity; capacity = limitCapacity(capacity, m_maxCount); capacity = limitCapacity(capacity, m_flagsBuffer.userSuppliedCapacity); capacity = limitCapacity(capacity, m_positionBuffer.userSuppliedCapacity); @@ -514,15 +564,27 @@ class ParticleSystem { capacity = limitCapacity(capacity, m_colorBuffer.userSuppliedCapacity); capacity = limitCapacity(capacity, m_userDataBuffer.userSuppliedCapacity); if (m_internalAllocatedCapacity < capacity) { - m_flagsBuffer.data = reallocateBufferInt(m_flagsBuffer, m_internalAllocatedCapacity, capacity, false); - m_positionBuffer.data = reallocateBuffer(m_positionBuffer, m_internalAllocatedCapacity, capacity, false); - m_velocityBuffer.data = reallocateBuffer(m_velocityBuffer, m_internalAllocatedCapacity, capacity, false); - m_accumulationBuffer = BufferUtils.reallocateBufferFloat64Deferred(m_accumulationBuffer, 0, m_internalAllocatedCapacity, capacity, false); - m_accumulation2Buffer = BufferUtils.reallocateBufferWithAllocDeferred(m_accumulation2Buffer, 0, m_internalAllocatedCapacity, capacity, true, allocVec2); - m_depthBuffer = BufferUtils.reallocateBufferFloat64Deferred(m_depthBuffer, 0, m_internalAllocatedCapacity, capacity, true); - m_colorBuffer.data = reallocateBuffer(m_colorBuffer, m_internalAllocatedCapacity, capacity, true); - m_groupBuffer = BufferUtils.reallocateBufferWithAllocDeferred(m_groupBuffer, 0, m_internalAllocatedCapacity, capacity, false, allocParticleGroup); - m_userDataBuffer.data = reallocateBuffer(m_userDataBuffer, m_internalAllocatedCapacity, capacity, true); + m_flagsBuffer.data = reallocateBufferInt( + m_flagsBuffer, m_internalAllocatedCapacity, capacity, false); + m_positionBuffer.data = reallocateBuffer( + m_positionBuffer, m_internalAllocatedCapacity, capacity, false); + m_velocityBuffer.data = reallocateBuffer( + m_velocityBuffer, m_internalAllocatedCapacity, capacity, false); + m_accumulationBuffer = BufferUtils.reallocateBufferFloat64Deferred( + m_accumulationBuffer, 0, m_internalAllocatedCapacity, capacity, + false); + m_accumulation2Buffer = BufferUtils.reallocateBufferWithAllocDeferred( + m_accumulation2Buffer, 0, m_internalAllocatedCapacity, capacity, + true, allocVec2); + m_depthBuffer = BufferUtils.reallocateBufferFloat64Deferred( + m_depthBuffer, 0, m_internalAllocatedCapacity, capacity, true); + m_colorBuffer.data = reallocateBuffer( + m_colorBuffer, m_internalAllocatedCapacity, capacity, true); + m_groupBuffer = BufferUtils.reallocateBufferWithAllocDeferred( + m_groupBuffer, 0, m_internalAllocatedCapacity, capacity, false, + allocParticleGroup); + m_userDataBuffer.data = reallocateBuffer( + m_userDataBuffer, m_internalAllocatedCapacity, capacity, true); m_internalAllocatedCapacity = capacity; } } @@ -539,17 +601,22 @@ class ParticleSystem { m_depthBuffer[index] = 0.0; } if (m_colorBuffer.data != null || def.color != null) { - m_colorBuffer.data = requestParticleBuffer(m_colorBuffer.data, m_colorBuffer.allocClosure); + m_colorBuffer.data = + requestParticleBuffer(m_colorBuffer.data, m_colorBuffer.allocClosure); m_colorBuffer.data[index].setParticleColor(def.color); } if (m_userDataBuffer.data != null || def.userData != null) { - m_userDataBuffer.data = requestParticleBuffer(m_userDataBuffer.data, m_userDataBuffer.allocClosure); + m_userDataBuffer.data = requestParticleBuffer( + m_userDataBuffer.data, m_userDataBuffer.allocClosure); m_userDataBuffer.data[index] = def.userData; } if (m_proxyCount >= m_proxyCapacity) { int oldCapacity = m_proxyCapacity; - int newCapacity = m_proxyCount != 0 ? 2 * m_proxyCount : Settings.minParticleBufferCapacity; - m_proxyBuffer = BufferUtils.reallocateBufferWithAlloc(m_proxyBuffer, oldCapacity, newCapacity, allocPsProxy); + int newCapacity = m_proxyCount != 0 + ? 2 * m_proxyCount + : Settings.minParticleBufferCapacity; + m_proxyBuffer = BufferUtils.reallocateBufferWithAlloc( + m_proxyBuffer, oldCapacity, newCapacity, allocPsProxy); m_proxyCapacity = newCapacity; } m_proxyBuffer[m_proxyCount++].index = index; @@ -557,14 +624,19 @@ class ParticleSystem { } // reallocate a buffer - static List reallocateBuffer(ParticleBuffer buffer, int oldCapacity, int newCapacity, bool deferred) { + static List reallocateBuffer( + ParticleBuffer buffer, int oldCapacity, int newCapacity, bool deferred) { assert(newCapacity > oldCapacity); - return BufferUtils.reallocateBufferWithAllocDeferred(buffer.data, buffer.userSuppliedCapacity, oldCapacity, newCapacity, deferred, buffer.allocClosure); + return BufferUtils.reallocateBufferWithAllocDeferred(buffer.data, + buffer.userSuppliedCapacity, oldCapacity, newCapacity, deferred, + buffer.allocClosure); } - static List reallocateBufferInt(ParticleBufferInt buffer, int oldCapacity, int newCapacity, bool deferred) { + static List reallocateBufferInt(ParticleBufferInt buffer, + int oldCapacity, int newCapacity, bool deferred) { assert(newCapacity > oldCapacity); - return BufferUtils.reallocateBufferIntDeferred(buffer.data, buffer.userSuppliedCapacity, oldCapacity, newCapacity, deferred); + return BufferUtils.reallocateBufferIntDeferred(buffer.data, + buffer.userSuppliedCapacity, oldCapacity, newCapacity, deferred); } List requestParticleBuffer(List buffer, allocClosure) { @@ -597,16 +669,19 @@ class ParticleSystem { } final AABB _temp = new AABB(); - final DestroyParticlesInShapeCallback _dpcallback = new DestroyParticlesInShapeCallback(); + final DestroyParticlesInShapeCallback _dpcallback = + new DestroyParticlesInShapeCallback(); - int destroyParticlesInShape(Shape shape, Transform xf, bool callDestructionListener) { + int destroyParticlesInShape( + Shape shape, Transform xf, bool callDestructionListener) { _dpcallback.init(this, shape, xf, callDestructionListener); shape.computeAABB(_temp, xf, 0); m_world.queryAABBParticle(_dpcallback, _temp); return _dpcallback.destroyed; } - void destroyParticlesInGroup(ParticleGroup group, bool callDestructionListener) { + void destroyParticlesInGroup( + ParticleGroup group, bool callDestructionListener) { for (int i = group.m_firstIndex; i < group.m_lastIndex; i++) { destroyParticle(i, callDestructionListener); } @@ -616,7 +691,8 @@ class ParticleSystem { final Vec2 _tempVec = new Vec2.zero(); final Transform _tempTransform = new Transform.zero(); final Transform _tempTransform2 = new Transform.zero(); - CreateParticleGroupCallback _createParticleGroupCallback = new CreateParticleGroupCallback(); + CreateParticleGroupCallback _createParticleGroupCallback = + new CreateParticleGroupCallback(); final ParticleDef _tempParticleDef = new ParticleDef(); ParticleGroup createParticleGroup(ParticleGroupDef groupDef) { @@ -646,8 +722,12 @@ class ParticleSystem { } final double upperBoundY = aabb.upperBound.y; final double upperBoundX = aabb.upperBound.x; - for (double y = (aabb.lowerBound.y / stride).floor() * stride; y < upperBoundY; y += stride) { - for (double x = (aabb.lowerBound.x / stride).floor() * stride; x < upperBoundX; x += stride) { + for (double y = (aabb.lowerBound.y / stride).floor() * stride; + y < upperBoundY; + y += stride) { + for (double x = (aabb.lowerBound.x / stride).floor() * stride; + x < upperBoundX; + x += stride) { Vec2 p = _tempVec; p.x = x; p.y = y; @@ -656,7 +736,8 @@ class ParticleSystem { particleDef.position.x = p.x; particleDef.position.y = p.y; p.subLocal(groupDef.position); - Vec2.crossToOutUnsafeDblVec2(groupDef.angularVelocity, p, particleDef.velocity); + Vec2.crossToOutUnsafeDblVec2( + groupDef.angularVelocity, p, particleDef.velocity); particleDef.velocity.addLocal(groupDef.linearVelocity); createParticle(particleDef); } @@ -699,8 +780,11 @@ class ParticleSystem { if (firstIndex <= a && b < lastIndex) { if (m_pairCount >= m_pairCapacity) { int oldCapacity = m_pairCapacity; - int newCapacity = m_pairCount != 0 ? 2 * m_pairCount : Settings.minParticleBufferCapacity; - m_pairBuffer = BufferUtils.reallocateBufferWithAlloc(m_pairBuffer, oldCapacity, newCapacity, allocPsPair); + int newCapacity = m_pairCount != 0 + ? 2 * m_pairCount + : Settings.minParticleBufferCapacity; + m_pairBuffer = BufferUtils.reallocateBufferWithAlloc( + m_pairBuffer, oldCapacity, newCapacity, allocPsPair); m_pairCapacity = newCapacity; } PsPair pair = m_pairBuffer[m_pairCount]; @@ -708,7 +792,8 @@ class ParticleSystem { pair.indexB = b; pair.flags = contact.flags; pair.strength = groupDef.strength; - pair.distance = MathUtils.distance(m_positionBuffer.data[a], m_positionBuffer.data[b]); + pair.distance = MathUtils.distance( + m_positionBuffer.data[a], m_positionBuffer.data[b]); m_pairCount++; } } @@ -756,11 +841,17 @@ class ParticleSystem { a = b; b = temp; } - if (groupA.m_firstIndex <= a && a < groupA.m_lastIndex && groupB.m_firstIndex <= b && b < groupB.m_lastIndex) { + if (groupA.m_firstIndex <= a && + a < groupA.m_lastIndex && + groupB.m_firstIndex <= b && + b < groupB.m_lastIndex) { if (m_pairCount >= m_pairCapacity) { int oldCapacity = m_pairCapacity; - int newCapacity = m_pairCount != 0 ? 2 * m_pairCount : Settings.minParticleBufferCapacity; - m_pairBuffer = BufferUtils.reallocateBufferWithAlloc(m_pairBuffer, oldCapacity, newCapacity, allocPsPair); + int newCapacity = m_pairCount != 0 + ? 2 * m_pairCount + : Settings.minParticleBufferCapacity; + m_pairBuffer = BufferUtils.reallocateBufferWithAlloc( + m_pairBuffer, oldCapacity, newCapacity, allocPsPair); m_pairCapacity = newCapacity; } PsPair pair = m_pairBuffer[m_pairCount]; @@ -768,13 +859,15 @@ class ParticleSystem { pair.indexB = b; pair.flags = contact.flags; pair.strength = Math.min(groupA.m_strength, groupB.m_strength); - pair.distance = MathUtils.distance(m_positionBuffer.data[a], m_positionBuffer.data[b]); + pair.distance = MathUtils.distance( + m_positionBuffer.data[a], m_positionBuffer.data[b]); m_pairCount++; } } } if ((particleFlags & k_triadFlags) != 0) { - VoronoiDiagram diagram = new VoronoiDiagram(groupB.m_lastIndex - groupA.m_firstIndex); + VoronoiDiagram diagram = + new VoronoiDiagram(groupB.m_lastIndex - groupA.m_firstIndex); for (int i = groupA.m_firstIndex; i < groupB.m_lastIndex; i++) { if ((m_flagsBuffer.data[i] & ParticleType.b2_zombieParticle) == 0) { diagram.addGenerator(m_positionBuffer.data[i], i); @@ -836,7 +929,10 @@ class ParticleSystem { final ParticleContact contact = m_contactBuffer[k]; int a = contact.indexA; int b = contact.indexB; - if (a >= group.m_firstIndex && a < group.m_lastIndex && b >= group.m_firstIndex && b < group.m_lastIndex) { + if (a >= group.m_firstIndex && + a < group.m_lastIndex && + b >= group.m_firstIndex && + b < group.m_lastIndex) { double w = contact.weight; m_accumulationBuffer[a] += w; m_accumulationBuffer[b] += w; @@ -854,7 +950,10 @@ class ParticleSystem { final ParticleContact contact = m_contactBuffer[k]; int a = contact.indexA; int b = contact.indexB; - if (a >= group.m_firstIndex && a < group.m_lastIndex && b >= group.m_firstIndex && b < group.m_lastIndex) { + if (a >= group.m_firstIndex && + a < group.m_lastIndex && + b >= group.m_firstIndex && + b < group.m_lastIndex) { double r = 1 - contact.weight; double ap0 = m_depthBuffer[a]; double bp0 = m_depthBuffer[b]; @@ -897,8 +996,11 @@ class ParticleSystem { if (d2 < m_squaredDiameter) { if (m_contactCount >= m_contactCapacity) { int oldCapacity = m_contactCapacity; - int newCapacity = m_contactCount != 0 ? 2 * m_contactCount : Settings.minParticleBufferCapacity; - m_contactBuffer = BufferUtils.reallocateBufferWithAlloc(m_contactBuffer, oldCapacity, newCapacity, allocParticleContact); + int newCapacity = m_contactCount != 0 + ? 2 * m_contactCount + : Settings.minParticleBufferCapacity; + m_contactBuffer = BufferUtils.reallocateBufferWithAlloc( + m_contactBuffer, oldCapacity, newCapacity, allocParticleContact); m_contactCapacity = newCapacity; } double invD = d2 != 0 ? Math.sqrt(1 / d2) : double.MAX_FINITE; @@ -918,7 +1020,8 @@ class ParticleSystem { PsProxy proxy = m_proxyBuffer[p]; int i = proxy.index; Vec2 pos = m_positionBuffer.data[i]; - proxy.tag = computeTag(m_inverseDiameter * pos.x, m_inverseDiameter * pos.y); + proxy.tag = + computeTag(m_inverseDiameter * pos.x, m_inverseDiameter * pos.y); } Settings.sort(m_proxyBuffer, 0, m_proxyCount); m_contactCount = 0; @@ -934,7 +1037,7 @@ class ParticleSystem { addContact(a.index, b.index); } int bottomLeftTag = computeRelativeTag(a.tag, -1, 1); - for ( ; c_index < m_proxyCount; c_index++) { + for (; c_index < m_proxyCount; c_index++) { PsProxy c = m_proxyBuffer[c_index]; if (bottomLeftTag <= c.tag) { break; @@ -965,7 +1068,8 @@ class ParticleSystem { } } - final UpdateBodyContactsCallback _ubccallback = new UpdateBodyContactsCallback(); + final UpdateBodyContactsCallback _ubccallback = + new UpdateBodyContactsCallback(); void updateBodyContacts() { final AABB aabb = _temp; @@ -1035,7 +1139,9 @@ class ParticleSystem { return; } m_allGroupFlags = 0; - for (ParticleGroup group = m_groupList; group != null; group = group.getNext()) { + for (ParticleGroup group = m_groupList; + group != null; + group = group.getNext()) { m_allGroupFlags |= group.m_groupFlags; } final double gravityx = step.dt * m_gravityScale * m_world.getGravity().x; @@ -1047,7 +1153,9 @@ class ParticleSystem { v.y += gravityy; double v2 = v.x * v.x + v.y * v.y; if (v2 > criticalVelocytySquared) { - double a = v2 == 0 ? double.MAX_FINITE : Math.sqrt(criticalVelocytySquared / v2); + double a = v2 == 0 + ? double.MAX_FINITE + : Math.sqrt(criticalVelocytySquared / v2); v.x *= a; v.y *= a; } @@ -1124,7 +1232,9 @@ class ParticleSystem { double pressurePerWeight = m_pressureStrength * getCriticalPressure(step); for (int i = 0; i < m_count; i++) { double w = m_accumulationBuffer[i]; - double h = pressurePerWeight * Math.max(0.0, Math.min(w, Settings.maxParticleWeight) - Settings.minParticleWeight); + double h = pressurePerWeight * + Math.max(0.0, Math.min(w, Settings.maxParticleWeight) - + Settings.minParticleWeight); m_accumulationBuffer[i] = h; } // applies pressure between each particles in contact @@ -1235,7 +1345,9 @@ class ParticleSystem { final Transform _tempXf2 = new Transform.zero(); void solveRigid(final TimeStep step) { - for (ParticleGroup group = m_groupList; group != null; group = group.getNext()) { + for (ParticleGroup group = m_groupList; + group != null; + group = group.getNext()) { if ((group.m_groupFlags & ParticleGroupType.b2_rigidParticleGroup) != 0) { group.updateStatistics(); Vec2 temp = _tempVec; @@ -1243,7 +1355,11 @@ class ParticleSystem { Rot rotation = _tempRot; rotation.setAngle(step.dt * group.m_angularVelocity); Rot.mulToOutUnsafe(rotation, group.m_center, cross); - temp.set(group.m_linearVelocity).mulLocal(step.dt).addLocal(group.m_center).subLocal(cross); + temp + .set(group.m_linearVelocity) + .mulLocal(step.dt) + .addLocal(group.m_center) + .subLocal(cross); _tempXf.p.set(temp); _tempXf.q.set(rotation); Transform.mulToOut(_tempXf, group.m_transform, group.m_transform); @@ -1253,7 +1369,8 @@ class ParticleSystem { velocityTransform.q.s = step.inv_dt * _tempXf.q.s; velocityTransform.q.c = step.inv_dt * (_tempXf.q.c - 1); for (int i = group.m_firstIndex; i < group.m_lastIndex; i++) { - Transform.mulToOutUnsafeVec2(velocityTransform, m_positionBuffer.data[i], m_velocityBuffer.data[i]); + Transform.mulToOutUnsafeVec2(velocityTransform, + m_positionBuffer.data[i], m_velocityBuffer.data[i]); } } } @@ -1275,7 +1392,8 @@ class ParticleSystem { final Vec2 pc = m_positionBuffer.data[c]; final double px = 1.0 / 3 * (pa.x + pb.x + pc.x); final double py = 1.0 / 3 * (pa.y + pb.y + pc.y); - double rs = Vec2.cross(oa, pa) + Vec2.cross(ob, pb) + Vec2.cross(oc, pc); + double rs = + Vec2.cross(oa, pa) + Vec2.cross(ob, pb) + Vec2.cross(oc, pc); double rc = Vec2.dot(oa, pa) + Vec2.dot(ob, pb) + Vec2.dot(oc, pc); double r2 = rs * rs + rc * rc; double invR = r2 == 0 ? double.MAX_FINITE : Math.sqrt(1.0 / r2); @@ -1329,7 +1447,8 @@ class ParticleSystem { } void solveTensile(final TimeStep step) { - m_accumulation2Buffer = requestParticleBuffer(m_accumulation2Buffer, allocVec2); + m_accumulation2Buffer = + requestParticleBuffer(m_accumulation2Buffer, allocVec2); for (int i = 0; i < m_count; i++) { m_accumulationBuffer[i] = 0.0; m_accumulation2Buffer[i].setZero(); @@ -1366,7 +1485,8 @@ class ParticleSystem { double h = m_accumulationBuffer[a] + m_accumulationBuffer[b]; final double sx = a2B.x - a2A.x; final double sy = a2B.y - a2A.y; - double fn = (strengthA * (h - 2) + strengthB * (sx * n.x + sy * n.y)) * w; + double fn = + (strengthA * (h - 2) + strengthB * (sx * n.x + sy * n.y)) * w; final double fx = fn * n.x; final double fy = fn * n.y; final Vec2 va = m_velocityBuffer.data[a]; @@ -1392,8 +1512,10 @@ class ParticleSystem { final Vec2 va = m_velocityBuffer.data[a]; final double tempX = p.x - b.m_sweep.c.x; final double tempY = p.y - b.m_sweep.c.y; - final double vx = -b.m_angularVelocity * tempY + b.m_linearVelocity.x - va.x; - final double vy = b.m_angularVelocity * tempX + b.m_linearVelocity.y - va.y; + final double vx = + -b.m_angularVelocity * tempY + b.m_linearVelocity.x - va.x; + final double vy = + b.m_angularVelocity * tempX + b.m_linearVelocity.y - va.y; final Vec2 f = _tempVec; final double pInvMass = getParticleInvMass(); f.x = viscousStrength * m * w * vx; @@ -1499,13 +1621,17 @@ class ParticleSystem { void solveColorMixing(final TimeStep step) { // mixes color between contacting particles - m_colorBuffer.data = requestParticleBuffer(m_colorBuffer.data, allocParticleColor); + m_colorBuffer.data = + requestParticleBuffer(m_colorBuffer.data, allocParticleColor); int colorMixing256 = (256 * m_colorMixingStrength).toInt(); for (int k = 0; k < m_contactCount; k++) { final ParticleContact contact = m_contactBuffer[k]; int a = contact.indexA; int b = contact.indexB; - if ((m_flagsBuffer.data[a] & m_flagsBuffer.data[b] & ParticleType.b2_colorMixingParticle) != 0) { + if ((m_flagsBuffer.data[a] & + m_flagsBuffer.data[b] & + ParticleType.b2_colorMixingParticle) != + 0) { ParticleColor colorA = m_colorBuffer.data[a]; ParticleColor colorB = m_colorBuffer.data[b]; int dr = (colorMixing256 * (colorB.r - colorA.r)).toInt() >> 8; @@ -1531,8 +1657,10 @@ class ParticleSystem { for (int i = 0; i < m_count; i++) { int flags = m_flagsBuffer.data[i]; if ((flags & ParticleType.b2_zombieParticle) != 0) { - ParticleDestructionListener destructionListener = m_world.getParticleDestructionListener(); - if ((flags & ParticleType.b2_destructionListener) != 0 && destructionListener != null) { + ParticleDestructionListener destructionListener = + m_world.getParticleDestructionListener(); + if ((flags & ParticleType.b2_destructionListener) != 0 && + destructionListener != null) { destructionListener.sayGoodbyeIndex(i); } newIndices[i] = Settings.invalidParticleIndex; @@ -1547,7 +1675,8 @@ class ParticleSystem { m_depthBuffer[newCount] = m_depthBuffer[i]; } if (m_colorBuffer.data != null) { - m_colorBuffer.data[newCount].setParticleColor(m_colorBuffer.data[i]); + m_colorBuffer.data[newCount] + .setParticleColor(m_colorBuffer.data[i]); } if (m_userDataBuffer.data != null) { m_userDataBuffer.data[newCount] = m_userDataBuffer.data[i]; @@ -1665,7 +1794,9 @@ class ParticleSystem { m_triadCount = j; // update groups - for (ParticleGroup group = m_groupList; group != null; group = group.getNext()) { + for (ParticleGroup group = m_groupList; + group != null; + group = group.getNext()) { int firstIndex = newCount; int lastIndex = 0; bool modified = false; @@ -1682,7 +1813,8 @@ class ParticleSystem { group.m_firstIndex = firstIndex; group.m_lastIndex = lastIndex; if (modified) { - if ((group.m_groupFlags & ParticleGroupType.b2_rigidParticleGroup) != 0) { + if ((group.m_groupFlags & ParticleGroupType.b2_rigidParticleGroup) != + 0) { group.m_toBeSplit = true; } } @@ -1700,7 +1832,7 @@ class ParticleSystem { // m_world.m_stackAllocator.Free(newIndices); // destroy bodies with no particles - for (ParticleGroup group = m_groupList; group != null; ) { + for (ParticleGroup group = m_groupList; group != null;) { ParticleGroup next = group.getNext(); if (group.m_toBeDestroyed) { destroyParticleGroup(group); @@ -1771,7 +1903,9 @@ class ParticleSystem { } // update groups - for (ParticleGroup group = m_groupList; group != null; group = group.getNext()) { + for (ParticleGroup group = m_groupList; + group != null; + group = group.getNext()) { group.m_firstIndex = _newIndices.getIndex(group.m_firstIndex); group.m_lastIndex = _newIndices.getIndex(group.m_lastIndex - 1) + 1; } @@ -1851,12 +1985,14 @@ class ParticleSystem { } List getParticleColorBuffer() { - m_colorBuffer.data = requestParticleBuffer(m_colorBuffer.data, m_colorBuffer.allocClosure); + m_colorBuffer.data = + requestParticleBuffer(m_colorBuffer.data, m_colorBuffer.allocClosure); return m_colorBuffer.data; } List getParticleUserDataBuffer() { - m_userDataBuffer.data = requestParticleBuffer(m_userDataBuffer.data, m_userDataBuffer.allocClosure); + m_userDataBuffer.data = requestParticleBuffer( + m_userDataBuffer.data, m_userDataBuffer.allocClosure); return m_userDataBuffer.data; } @@ -1869,8 +2005,10 @@ class ParticleSystem { m_maxCount = count; } - void setParticleBufferInt(ParticleBufferInt buffer, List newData, int newCapacity) { - assert((newData != null && newCapacity != 0) || (newData == null && newCapacity == 0)); + void setParticleBufferInt( + ParticleBufferInt buffer, List newData, int newCapacity) { + assert((newData != null && newCapacity != 0) || + (newData == null && newCapacity == 0)); if (buffer.userSuppliedCapacity != 0) { // m_world.m_blockAllocator.Free(buffer.data, sizeof(T) * m_internalAllocatedCapacity); } @@ -1879,7 +2017,8 @@ class ParticleSystem { } void setParticleBuffer(ParticleBuffer buffer, List newData, int newCapacity) { - assert((newData != null && newCapacity != 0) || (newData == null && newCapacity == 0)); + assert((newData != null && newCapacity != 0) || + (newData == null && newCapacity == 0)); if (buffer.userSuppliedCapacity != 0) { // m_world.m_blockAllocator.Free(buffer.data, sizeof(T) * m_internalAllocatedCapacity); } @@ -1964,12 +2103,17 @@ class ParticleSystem { final double lowerBoundY = aabb.lowerBound.y; final double upperBoundX = aabb.upperBound.x; final double upperBoundY = aabb.upperBound.y; - int firstProxy = _lowerBound(m_proxyBuffer, m_proxyCount, computeTag(m_inverseDiameter * lowerBoundX, m_inverseDiameter * lowerBoundY)); - int lastProxy = _upperBound(m_proxyBuffer, m_proxyCount, computeTag(m_inverseDiameter * upperBoundX, m_inverseDiameter * upperBoundY)); + int firstProxy = _lowerBound(m_proxyBuffer, m_proxyCount, computeTag( + m_inverseDiameter * lowerBoundX, m_inverseDiameter * lowerBoundY)); + int lastProxy = _upperBound(m_proxyBuffer, m_proxyCount, computeTag( + m_inverseDiameter * upperBoundX, m_inverseDiameter * upperBoundY)); for (int proxy = firstProxy; proxy < lastProxy; ++proxy) { int i = m_proxyBuffer[proxy].index; final Vec2 p = m_positionBuffer.data[i]; - if (lowerBoundX < p.x && p.x < upperBoundX && lowerBoundY < p.y && p.y < upperBoundY) { + if (lowerBoundX < p.x && + p.x < upperBoundX && + lowerBoundY < p.y && + p.y < upperBoundY) { if (!callback.reportParticle(i)) { break; } @@ -1982,12 +2126,17 @@ class ParticleSystem { * @param point1 * @param point2 */ - void raycast(ParticleRaycastCallback callback, final Vec2 point1, final Vec2 point2) { + void raycast( + ParticleRaycastCallback callback, final Vec2 point1, final Vec2 point2) { if (m_proxyCount == 0) { return; } - int firstProxy = _lowerBound(m_proxyBuffer, m_proxyCount, computeTag(m_inverseDiameter * Math.min(point1.x, point2.x) - 1, m_inverseDiameter * Math.min(point1.y, point2.y) - 1)); - int lastProxy = _upperBound(m_proxyBuffer, m_proxyCount, computeTag(m_inverseDiameter * Math.max(point1.x, point2.x) + 1, m_inverseDiameter * Math.max(point1.y, point2.y) + 1)); + int firstProxy = _lowerBound(m_proxyBuffer, m_proxyCount, computeTag( + m_inverseDiameter * Math.min(point1.x, point2.x) - 1, + m_inverseDiameter * Math.min(point1.y, point2.y) - 1)); + int lastProxy = _upperBound(m_proxyBuffer, m_proxyCount, computeTag( + m_inverseDiameter * Math.max(point1.x, point2.x) + 1, + m_inverseDiameter * Math.max(point1.y, point2.y) + 1)); double fraction = 1.0; // solving the following equation: // ((1-t)*point1+t*point2-position)^2=diameter^2 @@ -2051,5 +2200,4 @@ class ParticleSystem { } return 0.5 * getParticleMass() * sum_v2; } - } diff --git a/lib/box2d/src/particle/particle_type.dart b/lib/src/particle/particle_type.dart similarity index 100% rename from lib/box2d/src/particle/particle_type.dart rename to lib/src/particle/particle_type.dart diff --git a/lib/box2d/src/particle/stack_queue.dart b/lib/src/particle/stack_queue.dart similarity index 98% rename from lib/box2d/src/particle/stack_queue.dart rename to lib/src/particle/stack_queue.dart index e469d8b..62fdf95 100644 --- a/lib/box2d/src/particle/stack_queue.dart +++ b/lib/src/particle/stack_queue.dart @@ -24,9 +24,7 @@ part of box2d; - class StackQueue { - List _m_buffer; int _m_front = 0; int _m_back = 0; @@ -54,7 +52,7 @@ class StackQueue { } T pop() { - assert (_m_front < _m_back); + assert(_m_front < _m_back); return _m_buffer[_m_front++]; } diff --git a/lib/box2d/src/particle/voronoi_diagram.dart b/lib/src/particle/voronoi_diagram.dart similarity index 97% rename from lib/box2d/src/particle/voronoi_diagram.dart rename to lib/src/particle/voronoi_diagram.dart index d907c08..2dbc223 100644 --- a/lib/box2d/src/particle/voronoi_diagram.dart +++ b/lib/src/particle/voronoi_diagram.dart @@ -28,7 +28,6 @@ abstract class VoronoiDiagramCallback { void callback(int aTag, int bTag, int cTag); } - class VoronoiGenerator { final Vec2 center = new Vec2.zero(); int tag = 0; @@ -65,11 +64,11 @@ class VoronoiDiagramTaskMutableStack extends MutableStack { } } - class VoronoiDiagram { List _m_generatorBuffer; int _m_generatorCount = 0; - int _m_countX = 0, _m_countY = 0; + int _m_countX = 0, + _m_countY = 0; // The diagram is an array of "pointers". List _m_diagram; @@ -113,9 +112,11 @@ class VoronoiDiagram { final Vec2 _lower = new Vec2.zero(); final Vec2 _upper = new Vec2.zero(); - MutableStack _taskPool = new VoronoiDiagramTaskMutableStack(50); + MutableStack _taskPool = + new VoronoiDiagramTaskMutableStack(50); - final StackQueue _queue = new StackQueue(); + final StackQueue _queue = + new StackQueue(); void generate(double radius) { assert(_m_diagram == null); diff --git a/lib/box2d/src/pooling/arrays/float_array.dart b/lib/src/pooling/arrays/float_array.dart similarity index 100% rename from lib/box2d/src/pooling/arrays/float_array.dart rename to lib/src/pooling/arrays/float_array.dart diff --git a/lib/box2d/src/pooling/arrays/generator_array.dart b/lib/src/pooling/arrays/generator_array.dart similarity index 100% rename from lib/box2d/src/pooling/arrays/generator_array.dart rename to lib/src/pooling/arrays/generator_array.dart diff --git a/lib/box2d/src/pooling/arrays/int_array.dart b/lib/src/pooling/arrays/int_array.dart similarity index 88% rename from lib/box2d/src/pooling/arrays/int_array.dart rename to lib/src/pooling/arrays/int_array.dart index 6dc111e..68332d0 100644 --- a/lib/box2d/src/pooling/arrays/int_array.dart +++ b/lib/src/pooling/arrays/int_array.dart @@ -25,21 +25,21 @@ part of box2d; class IntArray { - final HashMap> _map = new HashMap>(); - - List get(int argLength){ + + List get(int argLength) { assert(argLength > 0); - - if(!_map.containsKey(argLength)){ + + if (!_map.containsKey(argLength)) { _map[argLength] = getInitializedArray(argLength); } - - assert(_map[argLength].length == argLength); // : "Array not built of correct length"; + + assert(_map[argLength].length == + argLength); // : "Array not built of correct length"; return _map[argLength]; } - - List getInitializedArray(int argLength){ + + List getInitializedArray(int argLength) { return BufferUtils.allocClearIntList(argLength); } } diff --git a/lib/box2d/src/pooling/arrays/vec2_array.dart b/lib/src/pooling/arrays/vec2_array.dart similarity index 89% rename from lib/box2d/src/pooling/arrays/vec2_array.dart rename to lib/src/pooling/arrays/vec2_array.dart index d16a897..2f3b814 100644 --- a/lib/box2d/src/pooling/arrays/vec2_array.dart +++ b/lib/src/pooling/arrays/vec2_array.dart @@ -25,21 +25,21 @@ part of box2d; class Vec2Array { - final HashMap> _map = new HashMap>(); - - List get( int argLength){ + + List get(int argLength) { assert(argLength > 0); - - if(!_map.containsKey(argLength)){ + + if (!_map.containsKey(argLength)) { _map[argLength] = getInitializedArray(argLength); } - - assert(_map[argLength].length == argLength); // : "Array not built of correct length"; + + assert(_map[argLength].length == + argLength); // : "Array not built of correct length"; return _map[argLength]; } - - List getInitializedArray(int argLength){ + + List getInitializedArray(int argLength) { final List ray = new List(argLength); for (int i = 0; i < ray.length; i++) { ray[i] = new Vec2.zero(); diff --git a/lib/box2d/src/pooling/idynamic_stack.dart b/lib/src/pooling/idynamic_stack.dart similarity index 100% rename from lib/box2d/src/pooling/idynamic_stack.dart rename to lib/src/pooling/idynamic_stack.dart diff --git a/lib/box2d/src/pooling/iordered_stack.dart b/lib/src/pooling/iordered_stack.dart similarity index 99% rename from lib/box2d/src/pooling/iordered_stack.dart rename to lib/src/pooling/iordered_stack.dart index ca3d14b..66a250b 100644 --- a/lib/box2d/src/pooling/iordered_stack.dart +++ b/lib/src/pooling/iordered_stack.dart @@ -47,5 +47,4 @@ abstract class IOrderedStack { * @param argNum */ void push(int argNum); - } diff --git a/lib/box2d/src/pooling/iworld_pool.dart b/lib/src/pooling/iworld_pool.dart similarity index 98% rename from lib/box2d/src/pooling/iworld_pool.dart rename to lib/src/pooling/iworld_pool.dart index 26afc95..d694f81 100644 --- a/lib/box2d/src/pooling/iworld_pool.dart +++ b/lib/src/pooling/iworld_pool.dart @@ -24,23 +24,21 @@ part of box2d; - abstract class IWorldPool { - IDynamicStack getPolyContactStack(); IDynamicStack getCircleContactStack(); IDynamicStack getPolyCircleContactStack(); - + IDynamicStack getEdgeCircleContactStack(); - + IDynamicStack getEdgePolyContactStack(); IDynamicStack getChainCircleContactStack(); - + IDynamicStack getChainPolyContactStack(); - + Vec2 popVec2(); List popVec2Some(int num); @@ -58,9 +56,9 @@ abstract class IWorldPool { List popMat22Some(int num); void pushMat22(int num); - + Mat33 popMat33(); - + void pushMat33(int num); AABB popAABB(); @@ -68,11 +66,11 @@ abstract class IWorldPool { List popAABBSome(int num); void pushAABB(int num); - + Rot popRot(); void pushRot(int num); - + Collision getCollision(); TimeOfImpact getTimeOfImpact(); diff --git a/lib/box2d/src/pooling/normal/circle_stack.dart b/lib/src/pooling/normal/circle_stack.dart similarity index 100% rename from lib/box2d/src/pooling/normal/circle_stack.dart rename to lib/src/pooling/normal/circle_stack.dart diff --git a/lib/box2d/src/pooling/normal/default_world_pool.dart b/lib/src/pooling/normal/default_world_pool.dart similarity index 74% rename from lib/box2d/src/pooling/normal/default_world_pool.dart rename to lib/src/pooling/normal/default_world_pool.dart index 91bf73c..8169e9a 100644 --- a/lib/box2d/src/pooling/normal/default_world_pool.dart +++ b/lib/src/pooling/normal/default_world_pool.dart @@ -30,27 +30,33 @@ part of box2d; */ class OrderedStackVec2 extends OrderedStack { - OrderedStackVec2(int argStackSize, int argContainerSize) : super(argStackSize, argContainerSize); + OrderedStackVec2(int argStackSize, int argContainerSize) + : super(argStackSize, argContainerSize); Vec2 newInstance() => new Vec2.zero(); } class OrderedStackVec3 extends OrderedStack { - OrderedStackVec3(int argStackSize, int argContainerSize) : super(argStackSize, argContainerSize); + OrderedStackVec3(int argStackSize, int argContainerSize) + : super(argStackSize, argContainerSize); Vec3 newInstance() => new Vec3.zero(); } class OrderedStackMat22 extends OrderedStack { - OrderedStackMat22(int argStackSize, int argContainerSize) : super(argStackSize, argContainerSize); + OrderedStackMat22(int argStackSize, int argContainerSize) + : super(argStackSize, argContainerSize); Mat22 newInstance() => new Mat22.zero(); } class OrderedStackMat33 extends OrderedStack { - OrderedStackMat33(int argStackSize, int argContainerSize) : super(argStackSize, argContainerSize); + OrderedStackMat33(int argStackSize, int argContainerSize) + : super(argStackSize, argContainerSize); Mat33 newInstance() => new Mat33.zero(); } class OrderedStackAABB extends OrderedStack { - OrderedStackAABB(int argStackSize, int argContainerSize) : super(argStackSize, argContainerSize); + OrderedStackAABB(int argStackSize, int argContainerSize) + : super(argStackSize, argContainerSize); AABB newInstance() => new AABB(); } class OrderedStackRot extends OrderedStack { - OrderedStackRot(int argStackSize, int argContainerSize) : super(argStackSize, argContainerSize); + OrderedStackRot(int argStackSize, int argContainerSize) + : super(argStackSize, argContainerSize); Rot newInstance() => new Rot(); } @@ -60,35 +66,46 @@ abstract class MutableStackWithPool extends MutableStack { } class MutableStackPolygonContact extends MutableStackWithPool { - MutableStackPolygonContact(IWorldPool pool, int argInitSize) : super(pool, argInitSize); + MutableStackPolygonContact(IWorldPool pool, int argInitSize) + : super(pool, argInitSize); PolygonContact newInstance() => new PolygonContact(_pool); } class MutableStackCircleContact extends MutableStackWithPool { - MutableStackCircleContact(IWorldPool pool, int argInitSize) : super(pool, argInitSize); + MutableStackCircleContact(IWorldPool pool, int argInitSize) + : super(pool, argInitSize); CircleContact newInstance() => new CircleContact(_pool); } -class MutableStackPolygonAndCircleContact extends MutableStackWithPool { - MutableStackPolygonAndCircleContact(IWorldPool pool, int argInitSize) : super(pool, argInitSize); +class MutableStackPolygonAndCircleContact + extends MutableStackWithPool { + MutableStackPolygonAndCircleContact(IWorldPool pool, int argInitSize) + : super(pool, argInitSize); PolygonAndCircleContact newInstance() => new PolygonAndCircleContact(_pool); } -class MutableStackEdgeAndCircleContact extends MutableStackWithPool { - MutableStackEdgeAndCircleContact(IWorldPool pool, int argInitSize) : super(pool, argInitSize); +class MutableStackEdgeAndCircleContact + extends MutableStackWithPool { + MutableStackEdgeAndCircleContact(IWorldPool pool, int argInitSize) + : super(pool, argInitSize); EdgeAndCircleContact newInstance() => new EdgeAndCircleContact(_pool); } -class MutableStackEdgeAndPolygonContact extends MutableStackWithPool { - MutableStackEdgeAndPolygonContact(IWorldPool pool, int argInitSize) : super(pool, argInitSize); +class MutableStackEdgeAndPolygonContact + extends MutableStackWithPool { + MutableStackEdgeAndPolygonContact(IWorldPool pool, int argInitSize) + : super(pool, argInitSize); EdgeAndPolygonContact newInstance() => new EdgeAndPolygonContact(_pool); } -class MutableStackChainAndCircleContact extends MutableStackWithPool { - MutableStackChainAndCircleContact(IWorldPool pool, int argInitSize) : super(pool, argInitSize); +class MutableStackChainAndCircleContact + extends MutableStackWithPool { + MutableStackChainAndCircleContact(IWorldPool pool, int argInitSize) + : super(pool, argInitSize); ChainAndCircleContact newInstance() => new ChainAndCircleContact(_pool); } -class MutableStackChainAndPolygonContact extends MutableStackWithPool { - MutableStackChainAndPolygonContact(IWorldPool pool, int argInitSize) : super(pool, argInitSize); +class MutableStackChainAndPolygonContact + extends MutableStackWithPool { + MutableStackChainAndPolygonContact(IWorldPool pool, int argInitSize) + : super(pool, argInitSize); ChainAndPolygonContact newInstance() => new ChainAndPolygonContact(_pool); } - class DefaultWorldPool implements IWorldPool { final OrderedStack _vecs; final OrderedStack _vec3s; @@ -117,7 +134,6 @@ class DefaultWorldPool implements IWorldPool { TimeOfImpact _toi; final Distance _dist; - DefaultWorldPool(int argSize, int argContainerSize) : _vecs = new OrderedStackVec2(argSize, argContainerSize), _vec3s = new OrderedStackVec3(argSize, argContainerSize), @@ -126,13 +142,20 @@ class DefaultWorldPool implements IWorldPool { _rots = new OrderedStackRot(argSize, argContainerSize), _mat33s = new OrderedStackMat33(argSize, argContainerSize), _dist = new Distance() { - _pcstack = new MutableStackPolygonContact(this, Settings.CONTACT_STACK_INIT_SIZE); - _ccstack = new MutableStackCircleContact(this, Settings.CONTACT_STACK_INIT_SIZE); - _cpstack = new MutableStackPolygonAndCircleContact(this, Settings.CONTACT_STACK_INIT_SIZE); - _ecstack = new MutableStackEdgeAndCircleContact(this, Settings.CONTACT_STACK_INIT_SIZE); - _epstack = new MutableStackEdgeAndPolygonContact(this, Settings.CONTACT_STACK_INIT_SIZE); - _chcstack = new MutableStackChainAndCircleContact(this, Settings.CONTACT_STACK_INIT_SIZE); - _chpstack = new MutableStackChainAndPolygonContact(this, Settings.CONTACT_STACK_INIT_SIZE); + _pcstack = + new MutableStackPolygonContact(this, Settings.CONTACT_STACK_INIT_SIZE); + _ccstack = + new MutableStackCircleContact(this, Settings.CONTACT_STACK_INIT_SIZE); + _cpstack = new MutableStackPolygonAndCircleContact( + this, Settings.CONTACT_STACK_INIT_SIZE); + _ecstack = new MutableStackEdgeAndCircleContact( + this, Settings.CONTACT_STACK_INIT_SIZE); + _epstack = new MutableStackEdgeAndPolygonContact( + this, Settings.CONTACT_STACK_INIT_SIZE); + _chcstack = new MutableStackChainAndCircleContact( + this, Settings.CONTACT_STACK_INIT_SIZE); + _chpstack = new MutableStackChainAndPolygonContact( + this, Settings.CONTACT_STACK_INIT_SIZE); _collision = new Collision(this); _toi = new TimeOfImpact(this); _world = this; @@ -247,7 +270,8 @@ class DefaultWorldPool implements IWorldPool { _afloats[argLength] = new Float64List(argLength); } - assert(_afloats[argLength].length == argLength); // : "Array not built with correct length"; + assert(_afloats[argLength].length == + argLength); // : "Array not built with correct length"; return _afloats[argLength]; } @@ -256,7 +280,8 @@ class DefaultWorldPool implements IWorldPool { _aints[argLength] = BufferUtils.allocClearIntList(argLength); } - assert(_aints[argLength].length == argLength); // : "Array not built with correct length"; + assert(_aints[argLength].length == + argLength); // : "Array not built with correct length"; return _aints[argLength]; } @@ -269,7 +294,8 @@ class DefaultWorldPool implements IWorldPool { _avecs[argLength] = ray; } - assert(_avecs[argLength].length == argLength); // : "Array not built with correct length"; + assert(_avecs[argLength].length == + argLength); // : "Array not built with correct length"; return _avecs[argLength]; } } diff --git a/lib/box2d/src/pooling/normal/mutable_stack.dart b/lib/src/pooling/normal/mutable_stack.dart similarity index 98% rename from lib/box2d/src/pooling/normal/mutable_stack.dart rename to lib/src/pooling/normal/mutable_stack.dart index 03b2f22..c766473 100644 --- a/lib/box2d/src/pooling/normal/mutable_stack.dart +++ b/lib/src/pooling/normal/mutable_stack.dart @@ -25,7 +25,6 @@ part of box2d; abstract class MutableStack implements IDynamicStack { - List _stack; int _index; int _size; @@ -58,13 +57,13 @@ abstract class MutableStack implements IDynamicStack { } void push(E argObject) { - assert (_index > 0); + assert(_index > 0); _stack[--_index] = argObject; } /** Creates a new instance of the object contained by this stack. */ E newInstance(); - + List newArray(int size) { return new List(size); } diff --git a/lib/box2d/src/pooling/normal/ordered_stack.dart b/lib/src/pooling/normal/ordered_stack.dart similarity index 82% rename from lib/box2d/src/pooling/normal/ordered_stack.dart rename to lib/src/pooling/normal/ordered_stack.dart index 298e341..0373db4 100644 --- a/lib/box2d/src/pooling/normal/ordered_stack.dart +++ b/lib/src/pooling/normal/ordered_stack.dart @@ -25,15 +25,16 @@ part of box2d; abstract class OrderedStack { - final List _pool; int _index; final int _size; final List _container; OrderedStack(int argStackSize, int argContainerSize) - : _pool = new List(argStackSize), _index = 0, _size = argStackSize, - _container = new List(argContainerSize) { + : _pool = new List(argStackSize), + _index = 0, + _size = argStackSize, + _container = new List(argContainerSize) { // pool = new List(argStackSize); for (int i = 0; i < argStackSize; i++) { _pool[i] = newInstance(); @@ -41,13 +42,15 @@ abstract class OrderedStack { } E pop() { - assert (_index < _size); // "End of stack reached, there is probably a leak somewhere"; + assert(_index < + _size); // "End of stack reached, there is probably a leak somewhere"; return _pool[_index++]; } List popSome(int argNum) { - assert (_index + argNum < _size); // "End of stack reached, there is probably a leak somewhere"; - assert (argNum <= _container.length); // "Container array is too small"; + assert(_index + argNum < + _size); // "End of stack reached, there is probably a leak somewhere"; + assert(argNum <= _container.length); // "Container array is too small"; Settings.arraycopy(_pool, _index, _container, 0, argNum); _index += argNum; return _container; @@ -55,9 +58,9 @@ abstract class OrderedStack { void push(int argNum) { _index -= argNum; - assert (_index >= 0); + assert(_index >= 0); } /** Creates a new instance of the object contained by this stack. */ E newInstance(); -} \ No newline at end of file +} diff --git a/lib/box2d/src/pooling/stacks/dynamic_int_stack.dart b/lib/src/pooling/stacks/dynamic_int_stack.dart similarity index 100% rename from lib/box2d/src/pooling/stacks/dynamic_int_stack.dart rename to lib/src/pooling/stacks/dynamic_int_stack.dart diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..51ea3fe --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,2 @@ +name: box2d +homepage: https://github.com/google/dbox2d