Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
codereview settings, formatting, moved library, added pubspec and .gi…
Browse files Browse the repository at this point in the history
…tignore

R=srdjan@google.com

Review URL: https://codereview.chromium.org//939363002
  • Loading branch information
kevmoo committed Feb 20, 2015
1 parent a731c15 commit b20889a
Show file tree
Hide file tree
Showing 141 changed files with 1,460 additions and 1,027 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
packages
pubspec.lock
2 changes: 1 addition & 1 deletion bin/bench2d.dart
Expand Up @@ -22,7 +22,7 @@
* POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/

import '../lib/box2d/box2d.dart';
import 'package:box2d/box2d.dart';

main() {
Bench2D bench = new Bench2D();
Expand Down
2 changes: 2 additions & 0 deletions codereview.settings
@@ -0,0 +1,2 @@
CODE_REVIEW_SERVER: https://codereview.chromium.org/
VIEW_VC: https://github.com/google/dbox2d/commit/
1 change: 0 additions & 1 deletion lib/box2d/box2d.dart → lib/box2d.dart
Expand Up @@ -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';

Expand Up @@ -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;
}
}
Expand Up @@ -162,14 +162,16 @@ abstract class DebugDraw {
*
* @param colors can be null
*/
void drawParticles(List<Vec2> centers, double radius, List<ParticleColor> colors, int count);
void drawParticles(
List<Vec2> centers, double radius, List<ParticleColor> colors, int count);

/**
* Draw a particle array
*
* @param colors can be null
*/
void drawParticlesWireframe(List<Vec2> centers, double radius, List<ParticleColor> colors, int count);
void drawParticlesWireframe(
List<Vec2> centers, double radius, List<ParticleColor> colors, int count);

/** Called at the end of drawing a world */
void flush() {}
Expand All @@ -192,7 +194,6 @@ abstract class DebugDraw {
viewportTransform.setCamera(x, y, scale);
}


/**
* @param argScreen
* @param argWorld
Expand Down
Expand Up @@ -37,5 +37,4 @@ abstract class ParticleRaycastCallback {
* @return
*/
double reportParticle(int index, Vec2 point, Vec2 normal, double fraction);

}
Expand Up @@ -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);
}
Expand Up @@ -29,7 +29,7 @@ part of box2d;
*
*/
abstract class TreeCallback {

/**
* Callback from a query request.
* @param proxyId the id of the proxy
Expand Down
Expand Up @@ -22,7 +22,6 @@
* POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/


part of box2d;

/**
Expand All @@ -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);
}
55 changes: 37 additions & 18 deletions lib/box2d/src/collision/aabb.dart → lib/src/collision/aabb.dart
Expand Up @@ -34,17 +34,19 @@ 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
*
* @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.
*
Expand All @@ -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
*
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
Expand Up @@ -25,7 +25,6 @@
part of box2d;

abstract class BroadPhase {

static const int NULL_PROXY = -1;

/**
Expand Down
Expand Up @@ -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);
Expand Down
Expand Up @@ -32,7 +32,6 @@ part of box2d;
* @author Daniel Murphy
*/
class DefaultBroadPhaseBuffer implements TreeCallback, BroadPhase {

final BroadPhaseStrategy _m_tree;

int _m_proxyCount = 0;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -159,7 +159,8 @@ class DynamicTree implements BroadPhaseStrategy {
}
} else {
if (nodeStack.length - nodeStackIndex - 2 <= 0) {
List<DynamicTreeNode> newBuffer = new List<DynamicTreeNode>(nodeStack.length * 2);
List<DynamicTreeNode> newBuffer =
new List<DynamicTreeNode>(nodeStack.length * 2);
Settings.arraycopy(nodeStack, 0, newBuffer, 0, nodeStack.length);
nodeStack = newBuffer;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -277,7 +279,8 @@ class DynamicTree implements BroadPhaseStrategy {
}
} else {
if (nodeStack.length - nodeStackIndex - 2 <= 0) {
List<DynamicTreeNode> newBuffer = new List<DynamicTreeNode>(nodeStack.length * 2);
List<DynamicTreeNode> newBuffer =
new List<DynamicTreeNode>(nodeStack.length * 2);
Settings.arraycopy(nodeStack, 0, newBuffer, 0, nodeStack.length);
nodeStack = newBuffer;
}
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit b20889a

Please sign in to comment.