init static method
Implementation
static Contact init(
Fixture fixtureA,
int indexA,
Fixture fixtureB,
int indexB,
) {
// Remember that we use the order in the enum here to determine in which
// order the arguments should come in the different contact classes.
// { CIRCLE, EDGE, POLYGON, CHAIN }
// TODO(spydon): Clean this mess up.
final typeA = fixtureA.type.index < fixtureB.type.index
? fixtureA.type
: fixtureB.type;
final typeB = fixtureA.type == typeA ? fixtureB.type : fixtureA.type;
final indexTemp = indexA;
final firstIndex = fixtureA.type == typeA ? indexA : indexB;
final secondIndex = fixtureB.type == typeB ? indexB : indexTemp;
final temp = fixtureA;
final firstFixture = fixtureA.type == typeA ? fixtureA : fixtureB;
final secondFixture = fixtureB.type == typeB ? fixtureB : temp;
if (typeA == ShapeType.circle && typeB == ShapeType.circle) {
return CircleContact(firstFixture, secondFixture);
} else if (typeA == ShapeType.polygon && typeB == ShapeType.polygon) {
return PolygonContact(firstFixture, secondFixture);
} else if (typeA == ShapeType.circle && typeB == ShapeType.polygon) {
return PolygonAndCircleContact(secondFixture, firstFixture);
} else if (typeA == ShapeType.circle && typeB == ShapeType.edge) {
return EdgeAndCircleContact(
secondFixture,
secondIndex,
firstFixture,
firstIndex,
);
} else if (typeA == ShapeType.edge && typeB == ShapeType.polygon) {
return EdgeAndPolygonContact(
firstFixture,
firstIndex,
secondFixture,
secondIndex,
);
} else if (typeA == ShapeType.circle && typeB == ShapeType.chain) {
return ChainAndCircleContact(
secondFixture,
secondIndex,
firstFixture,
firstIndex,
);
} else if (typeA == ShapeType.polygon && typeB == ShapeType.chain) {
return ChainAndPolygonContact(
secondFixture,
secondIndex,
firstFixture,
firstIndex,
);
} else {
assert(false, 'Not compatible contact type');
return CircleContact(firstFixture, secondFixture);
}
}