Skip to content

Commit

Permalink
HeightfieldCollisionShape: add 3 getters
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed May 8, 2024
1 parent 7f4669c commit e6535cb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ public HeightfieldCollisionShape(int stickLength, int stickWidth,
// *************************************************************************
// new methods exposed

/**
* Count how many columns are in the heightfield.
*
* @return the count (≥2)
*/
public int countColumns() {
assert heightStickWidth >= 2 : heightStickWidth;
return heightStickWidth;
}

/**
* Count how many data points are in the heightfield.
*
Expand All @@ -269,6 +279,28 @@ public int countMeshVertices() {
assert count > 0 : count;
return count;
}

/**
* Count how many rows are in the heightfield.
*
* @return the count (≥2)
*/
public int countRows() {
assert heightStickLength >= 2 : heightStickLength;
return heightStickLength;
}

/**
* Return the index of the height axis.
*
* @return the axis index: 0→X, 1→Y, 2→Z
*/
public int upAxis() {
assert upAxis == PhysicsSpace.AXIS_X
|| upAxis == PhysicsSpace.AXIS_Y
|| upAxis == PhysicsSpace.AXIS_Z : upAxis;
return upAxis;
}
// *************************************************************************
// CollisionShape methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ public String describe(CollisionShape shape) {
result.append(desc);

} else if (shape instanceof HeightfieldCollisionShape) {
int numV = ((HeightfieldCollisionShape) shape).countMeshVertices();
desc = String.format("[%d]", numV);
HeightfieldCollisionShape hcs = (HeightfieldCollisionShape) shape;
int numRows = hcs.countRows();
int numColumns = hcs.countColumns();
int upAxis = hcs.upAxis();
String up = MyString.axisName(upAxis);
desc = String.format("[%dx%d %sup]", numRows, numColumns, up);
result.append(desc);

} else if (shape instanceof HullCollisionShape) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -978,13 +978,16 @@ private static void testShapesConcave() {
HeightfieldCollisionShape hcs
= new HeightfieldCollisionShape(nineHeights);
testShape(hcs);
Assert.assertEquals(3, hcs.countColumns());
Assert.assertEquals(9, hcs.countMeshVertices());
Assert.assertEquals(3, hcs.countRows());
Assert.assertEquals(0.04f, hcs.getMargin(), 0f);
Assert.assertTrue(hcs.isConcave());
Assert.assertFalse(hcs.isConvex());
Assert.assertFalse(hcs.isInfinite());
Assert.assertTrue(hcs.isNonMoving());
Assert.assertFalse(hcs.isPolyhedral());
Assert.assertEquals(PhysicsSpace.AXIS_Y, hcs.upAxis());
testInverseInertia(hcs, 0f, 0f, 0f, 0f);

// MeshCollisionShape with a compressed (quantized) BVH:
Expand Down
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
<!-- Checks for size violations -->
<!-- See https://checkstyle.org/checks/sizes -->
<module name="MethodLength">
<property name="max" value="190"/>
<property name="max" value="200"/>
</module>
<module name="ParameterNumber">
<property name="max" value="12"/>
Expand Down

0 comments on commit e6535cb

Please sign in to comment.