Skip to content

Commit

Permalink
custom shapes: add argument validation to constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Mar 2, 2024
1 parent 3fa0e0d commit 36de005
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.jme3.util.clone.Cloner;
import java.io.IOException;
import java.util.logging.Logger;
import jme3utilities.Validate;
import jme3utilities.math.MyVolume;

/**
Expand Down Expand Up @@ -91,6 +92,7 @@ protected CustomBox() {
*/
public CustomBox(float halfExtent) {
super(halfExtent, halfExtent, halfExtent);
Validate.positive(halfExtent, "half extent");

this.unscaledHe = new Vector3f(halfExtent, halfExtent, halfExtent);
setScale(scale);
Expand All @@ -109,6 +111,10 @@ public CustomBox(float halfExtent) {
public CustomBox(float xHalfExtent, float yHalfExtent, float zHalfExtent) {
super(xHalfExtent, yHalfExtent, zHalfExtent);

Validate.positive(xHalfExtent, "X half extent");
Validate.positive(yHalfExtent, "Y half extent");
Validate.positive(zHalfExtent, "Z half extent");

this.unscaledHe = new Vector3f(xHalfExtent, yHalfExtent, zHalfExtent);
setScale(scale);
}
Expand All @@ -121,6 +127,7 @@ public CustomBox(float xHalfExtent, float yHalfExtent, float zHalfExtent) {
*/
public CustomBox(Vector3f halfExtents) {
super(halfExtents);
Validate.positive(halfExtents, "half extents");

this.unscaledHe = halfExtents.clone();
setScale(scale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.jme3.math.Vector3f;
import java.io.IOException;
import java.util.logging.Logger;
import jme3utilities.Validate;
import jme3utilities.math.MyMath;
import jme3utilities.math.MyVolume;

Expand Down Expand Up @@ -101,6 +102,9 @@ protected CustomCone() {
public CustomCone(float radius, float height) {
super(new Vector3f(radius, 0.75f * height, radius));

Validate.positive(radius, "radius");
Validate.positive(height, "height");

this.unscaledHeight = height;
this.unscaledRadius = radius;
setScale(scale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.jme3.math.Vector3f;
import java.io.IOException;
import java.util.logging.Logger;
import jme3utilities.Validate;
import jme3utilities.math.MyMath;
import jme3utilities.math.MyVolume;

Expand Down Expand Up @@ -101,6 +102,9 @@ protected CustomCylinder() {
public CustomCylinder(float radius, float height) {
super(new Vector3f(radius, 0.5f * height, radius));

Validate.positive(radius, "radius");
Validate.positive(height, "height");

this.unscaledHeight = height;
this.unscaledRadius = radius;
setScale(scale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.jme3.util.clone.Cloner;
import java.io.IOException;
import java.util.logging.Logger;
import jme3utilities.Validate;
import jme3utilities.math.MyMath;

/**
Expand Down Expand Up @@ -100,6 +101,7 @@ protected CustomEllipsoid() {
*/
public CustomEllipsoid(float radius) {
super(radius, radius, radius);
Validate.positive(radius, "radius");

this.unscaledHe = new Vector3f(radius, radius, radius);
this.inertiaFactor = 0.2f;
Expand All @@ -122,6 +124,10 @@ public CustomEllipsoid(float xHalfExtent, float yHalfExtent,
float zHalfExtent, float inertiaFactor) {
super(xHalfExtent, yHalfExtent, zHalfExtent);

Validate.positive(xHalfExtent, "X half extent");
Validate.positive(yHalfExtent, "Y half extent");
Validate.positive(zHalfExtent, "Z half extent");

this.unscaledHe = new Vector3f(xHalfExtent, yHalfExtent, zHalfExtent);
this.inertiaFactor = inertiaFactor;
setScale(scale);
Expand All @@ -137,6 +143,7 @@ public CustomEllipsoid(float xHalfExtent, float yHalfExtent,
*/
public CustomEllipsoid(Vector3f halfExtents, float inertiaFactor) {
super(halfExtents);
Validate.positive(halfExtents, "half extents");

this.unscaledHe = halfExtents.clone();
this.inertiaFactor = inertiaFactor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.jme3.math.Vector3f;
import java.io.IOException;
import java.util.logging.Logger;
import jme3utilities.Validate;
import jme3utilities.math.MyMath;

/**
Expand Down Expand Up @@ -112,6 +113,10 @@ protected CustomFrustum() {
public CustomFrustum(float a, float b, float height) {
super(halfExtents(a, b, height));

Validate.positive(a, "A radius");
Validate.positive(b, "B radius");
Validate.positive(height, "height");

this.unscaledA = a;
this.unscaledB = b;
this.unscaledHeight = height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.jme3.math.Vector3f;
import java.io.IOException;
import java.util.logging.Logger;
import jme3utilities.Validate;
import jme3utilities.math.MyMath;
import jme3utilities.math.MyVolume;

Expand Down Expand Up @@ -110,6 +111,9 @@ protected CustomHalfCylinder() {
public CustomHalfCylinder(float radius, float height) {
super(halfExtents(radius, height));

Validate.positive(radius, "radius");
Validate.positive(height, "height");

this.unscaledHeight = height;
this.unscaledRadius = radius;
setScale(scale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.jme3.math.Vector3f;
import java.io.IOException;
import java.util.logging.Logger;
import jme3utilities.Validate;
import jme3utilities.math.MyMath;
import jme3utilities.math.MyVector3f;
import jme3utilities.math.MyVolume;
Expand Down Expand Up @@ -93,6 +94,7 @@ protected CustomHemisphere() {
*/
public CustomHemisphere(float radius) {
super(halfExtents(radius));
Validate.positive(radius, "radius");

this.unscaledRadius = radius;
setScale(scale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.jme3.math.Vector3f;
import java.io.IOException;
import java.util.logging.Logger;
import jme3utilities.Validate;
import jme3utilities.math.MyMath;

/**
Expand Down Expand Up @@ -105,6 +106,9 @@ protected CustomParaboloid() {
public CustomParaboloid(float radius, float height) {
super(new Vector3f(radius, height / 1.5f, radius));

Validate.positive(radius, "radius");
Validate.positive(height, "height");

this.unscaledHeight = height;
this.unscaledRadius = radius;
setScale(scale);
Expand Down

0 comments on commit 36de005

Please sign in to comment.