All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.joml.AABBf Maven / Gradle / Ivy

There is a newer version: 1.10.1
Show newest version
/*
 * The MIT License
 *
 * Copyright (c) 2017-2020 JOML
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.joml;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.text.DecimalFormat;
import java.text.NumberFormat;

/**
 * Represents an axis-aligned box defined via the minimum and maximum corner coordinates.
 * 
 * @author Kai Burjack
 */
public class AABBf implements Externalizable {

    /**
     * The x coordinate of the minimum corner.
     */
    public float minX = Float.POSITIVE_INFINITY;
    /**
     * The y coordinate of the minimum corner.
     */
    public float minY = Float.POSITIVE_INFINITY;
    /**
     * The z coordinate of the minimum corner.
     */
    public float minZ = Float.POSITIVE_INFINITY;
    /**
     * The x coordinate of the maximum corner.
     */
    public float maxX = Float.NEGATIVE_INFINITY;
    /**
     * The y coordinate of the maximum corner.
     */
    public float maxY = Float.NEGATIVE_INFINITY;
    /**
     * The z coordinate of the maximum corner.
     */
    public float maxZ = Float.NEGATIVE_INFINITY;

    /**
     * Create a new {@link AABBf} representing the box with
     * (minX, minY, minZ)=(+inf, +inf, +inf) and (maxX, maxY, maxZ)=(-inf, -inf, -inf).
     */
    public AABBf() {
    }

    /**
     * Create a new {@link AABBf} as a copy of the given source.
     * 
     * @param source
     *          the {@link AABBf} to copy from
     */
    public AABBf(AABBf source) {
        this.minX = source.minX;
        this.minY = source.minY;
        this.minZ = source.minZ;
        this.maxX = source.maxX;
        this.maxY = source.maxY;
        this.maxZ = source.maxZ;
    }

    /**
     * Create a new {@link AABBf} with the given minimum and maximum corner coordinates.
     * 
     * @param min
     *          the minimum coordinates
     * @param max
     *          the maximum coordinates
     */
    public AABBf(Vector3fc min, Vector3fc max) {
        this.minX = min.x();
        this.minY = min.y();
        this.minZ = min.z();
        this.maxX = max.x();
        this.maxY = max.y();
        this.maxZ = max.z();
    }

    /**
     * Create a new {@link AABBf} with the given minimum and maximum corner coordinates.
     * 
     * @param minX
     *          the x coordinate of the minimum corner
     * @param minY
     *          the y coordinate of the minimum corner
     * @param minZ
     *          the z coordinate of the minimum corner
     * @param maxX
     *          the x coordinate of the maximum corner
     * @param maxY
     *          the y coordinate of the maximum corner
     * @param maxZ
     *          the z coordinate of the maximum corner
     */
    public AABBf(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
        this.minX = minX;
        this.minY = minY;
        this.minZ = minZ;
        this.maxX = maxX;
        this.maxY = maxY;
        this.maxZ = maxZ;
    }

    /**
     * Set this {@link AABBf} to be a clone of source.
     *
     * @param source
     *            the {@link AABBf} to copy from
     * @return this
     */
    public AABBf set(AABBf source){
        this.minX = source.minX;
        this.minY = source.minY;
        this.minZ = source.minZ;
        this.maxX = source.maxX;
        this.maxY = source.maxY;
        this.maxZ = source.maxZ;
        return this;
    }

    private AABBf validate() {
        if (!isValid()) {
            minX = Float.POSITIVE_INFINITY;
            minY = Float.POSITIVE_INFINITY;
            minZ = Float.POSITIVE_INFINITY;

            maxX = Float.NEGATIVE_INFINITY;
            maxY = Float.NEGATIVE_INFINITY;
            maxZ = Float.NEGATIVE_INFINITY;
        }
        return this;
    }

    /**
     * Check whether this rectangle represents a valid AABB.
     *
     * @return true iff this rectangle is valid; false otherwise
     */
    public boolean isValid() {
        return minX < maxX && minY < maxY && minZ < maxZ;
    }


    /**
     * Set the minimum corner coordinates.
     * 
     * @param minX
     *          the x coordinate of the minimum corner
     * @param minY
     *          the y coordinate of the minimum corner
     * @param minZ
     *          the z coordinate of the minimum corner
     * @return this
     */
    public AABBf setMin(float minX, float minY, float minZ) {
        this.minX = minX;
        this.minY = minY;
        this.minZ = minZ;
        return this;
    }

    /**
     * Set the maximum corner coordinates.
     * 
     * @param maxX
     *          the x coordinate of the maximum corner
     * @param maxY
     *          the y coordinate of the maximum corner
     * @param maxZ
     *          the z coordinate of the maximum corner
     * @return this
     */
    public AABBf setMax(float maxX, float maxY, float maxZ) {
        this.maxX = maxX;
        this.maxY = maxY;
        this.maxZ = maxZ;
        return this;
    }

    /**
     * Set the minimum corner coordinates.
     * 
     * @param min
     *          the minimum coordinates
     * @return this
     */
    public AABBf setMin(Vector3fc min) {
        return this.setMin(min.x(), min.y(), min.z());
    }

    /**
     * Set the maximum corner coordinates.
     * 
     * @param max
     *          the maximum coordinates
     * @return this
     */
    public AABBf setMax(Vector3fc max) {
        return this.setMax(max.x(), max.y(), max.z());
    }

    /**
     * Get the maximum corner coordinate of the given component.
     * 
     * @param component
     *          the component, within [0..2]
     * @return the maximum coordinate
     * @throws IllegalArgumentException if component is not within [0..2]
     */
    public float getMax(int component) throws IllegalArgumentException {
        switch (component) {
        case 0:
            return maxX;
        case 1:
            return maxY;
        case 2:
            return maxZ;
        default:
            throw new IllegalArgumentException();
        }
    }

    /**
     * Get the minimum corner coordinate of the given component.
     * 
     * @param component
     *          the component, within [0..2]
     * @return the maximum coordinate
     * @throws IllegalArgumentException if component is not within [0..2]
     */
    public float getMin(int component) throws IllegalArgumentException {
        switch (component) {
        case 0:
            return minX;
        case 1:
            return minY;
        case 2:
            return minZ;
        default:
            throw new IllegalArgumentException();
        }
    }

    /**
     * Set this to the union of this and the given point (x, y, z).
     * 
     * @param x
     *          the x coordinate of the point
     * @param y
     *          the y coordinate of the point
     * @param z
     *          the z coordinate of the point
     * @return this
     */
    public AABBf union(float x, float y, float z) {
        return union(x, y, z, this);
    }

    /**
     * Set this to the union of this and the given point p.
     * 
     * @param p
     *          the point
     * @return this
     */
    public AABBf union(Vector3fc p) {
        return union(p.x(), p.y(), p.z(), this);
    }

    /**
     * Compute the union of this and the given point (x, y, z) and store the result in dest.
     * 
     * @param x
     *          the x coordinate of the point
     * @param y
     *          the y coordinate of the point
     * @param z
     *          the z coordinate of the point
     * @param dest
     *          will hold the result
     * @return dest
     */
    public AABBf union(float x, float y, float z, AABBf dest) {
        dest.minX = this.minX < x ? this.minX : x;
        dest.minY = this.minY < y ? this.minY : y;
        dest.minZ = this.minZ < z ? this.minZ : z;
        dest.maxX = this.maxX > x ? this.maxX : x;
        dest.maxY = this.maxY > y ? this.maxY : y;
        dest.maxZ = this.maxZ > z ? this.maxZ : z;
        return dest;
    }

    /**
     * Compute the union of this and the given point p and store the result in dest.
     * 
     * @param p
     *          the point
     * @param dest
     *          will hold the result
     * @return dest
     */
    public AABBf union(Vector3fc p, AABBf dest) {
        return union(p.x(), p.y(), p.z(), dest);
    }

    /**
     * Set this to the union of this and other.
     * 
     * @param other
     *          the other {@link AABBf}
     * @return this
     */
    public AABBf union(AABBf other) {
        return this.union(other, this);
    }

    /**
     * Compute the union of this and other and store the result in dest.
     * 
     * @param other
     *          the other {@link AABBf}
     * @param dest
     *          will hold the result
     * @return dest
     */
    public AABBf union(AABBf other, AABBf dest) {
        dest.minX = this.minX < other.minX ? this.minX : other.minX;
        dest.minY = this.minY < other.minY ? this.minY : other.minY;
        dest.minZ = this.minZ < other.minZ ? this.minZ : other.minZ;
        dest.maxX = this.maxX > other.maxX ? this.maxX : other.maxX;
        dest.maxY = this.maxY > other.maxY ? this.maxY : other.maxY;
        dest.maxZ = this.maxZ > other.maxZ ? this.maxZ : other.maxZ;
        return dest;
    }

    /**
     * Ensure that the minimum coordinates are strictly less than or equal to the maximum coordinates by swapping
     * them if necessary.
     * 
     * @return this
     */
    public AABBf correctBounds() {
        float tmp;
        if (this.minX > this.maxX) {
            tmp = this.minX;
            this.minX = this.maxX;
            this.maxX = tmp;
        }
        if (this.minY > this.maxY) {
            tmp = this.minY;
            this.minY = this.maxY;
            this.maxY = tmp;
        }
        if (this.minZ > this.maxZ) {
            tmp = this.minZ;
            this.minZ = this.maxZ;
            this.maxZ = tmp;
        }
        return this;
    }

    /**
     * Translate this by the given vector xyz.
     * 
     * @param xyz
     *          the vector to translate by
     * @return this
     */
    public AABBf translate(Vector3fc xyz) {
        return translate(xyz.x(), xyz.y(), xyz.z(), this);
    }

    /**
     * Translate this by the given vector xyz and store the result in dest.
     * 
     * @param xyz
     *          the vector to translate by
     * @param dest
     *          will hold the result
     * @return dest
     */
    public AABBf translate(Vector3fc xyz, AABBf dest) {
        return translate(xyz.x(), xyz.y(), xyz.z(), dest);
    }

    /**
     * Translate this by the vector (x, y, z).
     * 
     * @param x
     *          the x coordinate to translate by
     * @param y
     *          the y coordinate to translate by
     * @param z
     *          the z coordinate to translate by
     * @return this
     */
    public AABBf translate(float x, float y, float z) {
        return translate(x, y, z, this);
    }

    /**
     * Translate this by the vector (x, y, z) and store the result in dest.
     * 
     * @param x
     *          the x coordinate to translate by
     * @param y
     *          the y coordinate to translate by
     * @param z
     *          the z coordinate to translate by
     * @param dest
     *          will hold the result
     * @return dest
     */
    public AABBf translate(float x, float y, float z, AABBf dest) {
        dest.minX = minX + x;
        dest.minY = minY + y;
        dest.minZ = minZ + z;
        dest.maxX = maxX + x;
        dest.maxY = maxY + y;
        dest.maxZ = maxZ + z;
        return dest;
    }

    /**
     * Compute the AABB of intersection between this and the given AABB.
     * 

* If the two AABBs do not intersect, then the minimum coordinates of this * will have a value of {@link Float#POSITIVE_INFINITY} and the maximum coordinates will have a value of * {@link Float#NEGATIVE_INFINITY}. * * @param other * the other AABB * @param dest * will hold the result * @return dest */ public AABBf intersection(AABBf other, AABBf dest) { dest.minX = Math.max(minX, other.minX); dest.minY = Math.max(minY, other.minY); dest.minZ = Math.max(minZ, other.minZ); dest.maxX = Math.min(maxX, other.maxX); dest.maxY = Math.min(maxY, other.maxY); dest.maxZ = Math.min(maxZ, other.maxZ); return dest.validate(); } /** * Compute the AABB of intersection between this and the given AABB. *

* If the two AABBs do not intersect, then the minimum coordinates of this * will have a value of {@link Float#POSITIVE_INFINITY} and the maximum coordinates will have a value of * {@link Float#NEGATIVE_INFINITY}. * * @param other * the other AABB * @return this */ public AABBf intersection(AABBf other) { return intersection(other, this); } /** * Check if this AABB contains the given AABB. * * @param aabb * the AABB to test * @return true iff this AABB contains the AABB; false otherwise */ public boolean containsAABB(AABBd aabb) { return aabb.minX >= minX && aabb.maxX <= maxX && aabb.minY >= minY && aabb.maxY <= maxY && aabb.minZ >= minZ && aabb.maxZ <= maxZ; } /** * Check if this AABB contains the given AABB. * * @param aabb * the AABB to test * @return true iff this AABB contains the AABB; false otherwise */ public boolean containsAABB(AABBf aabb) { return aabb.minX >= minX && aabb.maxX <= maxX && aabb.minY >= minY && aabb.maxY <= maxY && aabb.minZ >= minZ && aabb.maxZ <= maxZ; } /** * Check if this AABB contains the given AABB. * * @param aabb * the AABB to test * @return true iff this AABB contains the AABB; false otherwise */ public boolean containsAABB(AABBi aabb) { return aabb.minX >= minX && aabb.maxX <= maxX && aabb.minY >= minY && aabb.maxY <= maxY && aabb.minZ >= minZ && aabb.maxZ <= maxZ; } /** * Test whether the point (x, y, z) lies inside this AABB. * * @param x * the x coordinate of the point * @param y * the y coordinate of the point * @param z * the z coordinate of the point * @return true iff the given point lies inside this AABB; false otherwise */ public boolean containsPoint(float x, float y, float z) { return x >= minX && y >= minY && z >= minZ && x <= maxX && y <= maxY && z <= maxZ; } /** * Test whether the given point lies inside this AABB. * * @param point * the coordinates of the point * @return true iff the given point lies inside this AABB; false otherwise */ public boolean containsPoint(Vector3fc point) { return containsPoint(point.x(), point.y(), point.z()); } /** * Test whether the plane given via its plane equation a*x + b*y + c*z + d = 0 intersects this AABB. *

* Reference: http://www.lighthouse3d.com ("Geometric Approach - Testing Boxes II") * * @param a * the x factor in the plane equation * @param b * the y factor in the plane equation * @param c * the z factor in the plane equation * @param d * the constant in the plane equation * @return true iff the plane intersects this AABB; false otherwise */ public boolean intersectsPlane(float a, float b, float c, float d) { return Intersectionf.testAabPlane(minX, minY, minZ, maxX, maxY, maxZ, a, b, c, d); } /** * Test whether the given plane intersects this AABB. *

* Reference: http://www.lighthouse3d.com ("Geometric Approach - Testing Boxes II") * * @param plane * the plane * @return true iff the plane intersects this AABB; false otherwise */ public boolean intersectsPlane(Planef plane) { return Intersectionf.testAabPlane(this, plane); } /** * Test whether this and other intersect. * * @param other * the other AABB * @return true iff both AABBs intersect; false otherwise */ public boolean intersectsAABB(AABBf other) { return this.maxX >= other.minX && this.maxY >= other.minY && this.maxZ >= other.minZ && this.minX <= other.maxX && this.minY <= other.maxY && this.minZ <= other.maxZ; } /** * Test whether this AABB intersects the given sphere with equation * (x - centerX)^2 + (y - centerY)^2 + (z - centerZ)^2 - radiusSquared = 0. *

* Reference: http://stackoverflow.com * * @param centerX * the x coordinate of the center of the sphere * @param centerY * the y coordinate of the center of the sphere * @param centerZ * the z coordinate of the center of the sphere * @param radiusSquared * the square radius of the sphere * @return true iff this AABB and the sphere intersect; false otherwise */ public boolean intersectsSphere(float centerX, float centerY, float centerZ, float radiusSquared) { return Intersectionf.testAabSphere(minX, minY, minZ, maxX, maxY, maxZ, centerX, centerY, centerZ, radiusSquared); } /** * Test whether this AABB intersects the given sphere. *

* Reference: http://stackoverflow.com * * @param sphere * the sphere * @return true iff this AABB and the sphere intersect; false otherwise */ public boolean intersectsSphere(Spheref sphere) { return Intersectionf.testAabSphere(this, sphere); } /** * Test whether the given ray with the origin (originX, originY, originZ) and direction (dirX, dirY, dirZ) * intersects this AABB. *

* This method returns true for a ray whose origin lies inside this AABB. *

* Reference: An Efficient and Robust Ray–Box Intersection * * @param originX * the x coordinate of the ray's origin * @param originY * the y coordinate of the ray's origin * @param originZ * the z coordinate of the ray's origin * @param dirX * the x coordinate of the ray's direction * @param dirY * the y coordinate of the ray's direction * @param dirZ * the z coordinate of the ray's direction * @return true if this AABB and the ray intersect; false otherwise */ public boolean intersectsRay(float originX, float originY, float originZ, float dirX, float dirY, float dirZ) { return Intersectionf.testRayAab(originX, originY, originZ, dirX, dirY, dirZ, minX, minY, minZ, maxX, maxY, maxZ); } /** * Test whether the given ray intersects this AABB. *

* This method returns true for a ray whose origin lies inside this AABB. *

* Reference: An Efficient and Robust Ray–Box Intersection * * @param ray * the ray * @return true if this AABB and the ray intersect; false otherwise */ public boolean intersectsRay(Rayf ray) { return Intersectionf.testRayAab(ray, this); } /** * Determine whether the given ray with the origin (originX, originY, originZ) and direction (dirX, dirY, dirZ) * intersects this AABB, and return the values of the parameter t in the ray equation * p(t) = origin + t * dir of the near and far point of intersection. *

* This method returns true for a ray whose origin lies inside this AABB. *

* Reference: An Efficient and Robust Ray–Box Intersection * * @param originX * the x coordinate of the ray's origin * @param originY * the y coordinate of the ray's origin * @param originZ * the z coordinate of the ray's origin * @param dirX * the x coordinate of the ray's direction * @param dirY * the y coordinate of the ray's direction * @param dirZ * the z coordinate of the ray's direction * @param result * a vector which will hold the resulting values of the parameter * t in the ray equation p(t) = origin + t * dir of the near and far point of intersection * iff the ray intersects this AABB * @return true if the given ray intersects this AABB; false otherwise */ public boolean intersectsRay(float originX, float originY, float originZ, float dirX, float dirY, float dirZ, Vector2f result) { return Intersectionf.intersectRayAab(originX, originY, originZ, dirX, dirY, dirZ, minX, minY, minZ, maxX, maxY, maxZ, result); } /** * Determine whether the given ray intersects this AABB, and return the values of the parameter t in the ray equation * p(t) = origin + t * dir of the near and far point of intersection. *

* This method returns true for a ray whose origin lies inside this AABB. *

* Reference: An Efficient and Robust Ray–Box Intersection * * @param ray * the ray * @param result * a vector which will hold the resulting values of the parameter * t in the ray equation p(t) = origin + t * dir of the near and far point of intersection * iff the ray intersects this AABB * @return true if the given ray intersects this AABB; false otherwise */ public boolean intersectsRay(Rayf ray, Vector2f result) { return Intersectionf.intersectRayAab(ray, this, result); } /** * Determine whether the undirected line segment with the end points (p0X, p0Y, p0Z) and (p1X, p1Y, p1Z) * intersects this AABB, and return the values of the parameter t in the ray equation * p(t) = origin + p0 * (p1 - p0) of the near and far point of intersection. *

* This method returns true for a line segment whose either end point lies inside this AABB. *

* Reference: An Efficient and Robust Ray–Box Intersection * * @param p0X * the x coordinate of the line segment's first end point * @param p0Y * the y coordinate of the line segment's first end point * @param p0Z * the z coordinate of the line segment's first end point * @param p1X * the x coordinate of the line segment's second end point * @param p1Y * the y coordinate of the line segment's second end point * @param p1Z * the z coordinate of the line segment's second end point * @param result * a vector which will hold the resulting values of the parameter * t in the ray equation p(t) = p0 + t * (p1 - p0) of the near and far point of intersection * iff the line segment intersects this AABB * @return {@link Intersectionf#INSIDE} if the line segment lies completely inside of this AABB; or * {@link Intersectionf#OUTSIDE} if the line segment lies completely outside of this AABB; or * {@link Intersectionf#ONE_INTERSECTION} if one of the end points of the line segment lies inside of this AABB; or * {@link Intersectionf#TWO_INTERSECTION} if the line segment intersects two sides of this AABB or lies on an edge or a side of this AABB */ public int intersectsLineSegment(float p0X, float p0Y, float p0Z, float p1X, float p1Y, float p1Z, Vector2f result) { return Intersectionf.intersectLineSegmentAab(p0X, p0Y, p0Z, p1X, p1Y, p1Z, minX, minY, minZ, maxX, maxY, maxZ, result); } /** * Determine whether the given undirected line segment intersects this AABB, and return the values of the parameter t in the ray equation * p(t) = origin + p0 * (p1 - p0) of the near and far point of intersection. *

* This method returns true for a line segment whose either end point lies inside this AABB. *

* Reference: An Efficient and Robust Ray–Box Intersection * * @param lineSegment * the line segment * @param result * a vector which will hold the resulting values of the parameter * t in the ray equation p(t) = p0 + t * (p1 - p0) of the near and far point of intersection * iff the line segment intersects this AABB * @return {@link Intersectionf#INSIDE} if the line segment lies completely inside of this AABB; or * {@link Intersectionf#OUTSIDE} if the line segment lies completely outside of this AABB; or * {@link Intersectionf#ONE_INTERSECTION} if one of the end points of the line segment lies inside of this AABB; or * {@link Intersectionf#TWO_INTERSECTION} if the line segment intersects two sides of this AABB or lies on an edge or a side of this AABB */ public int intersectsLineSegment(LineSegmentf lineSegment, Vector2f result) { return Intersectionf.intersectLineSegmentAab(lineSegment, this, result); } /** * Apply the given {@link Matrix4fc#isAffine() affine} transformation to this {@link AABBf}. *

* The matrix in m must be {@link Matrix4fc#isAffine() affine}. * * @param m * the affine transformation matrix * @return this */ public AABBf transform(Matrix4fc m) { return transform(m, this); } /** * Apply the given {@link Matrix4fc#isAffine() affine} transformation to this * {@link AABBf} and store the resulting AABB into dest. *

* The matrix in m must be {@link Matrix4fc#isAffine() affine}. * * @param m * the affine transformation matrix * @param dest * will hold the result * @return dest */ public AABBf transform(Matrix4fc m, AABBf dest) { float dx = maxX - minX, dy = maxY - minY, dz = maxZ - minZ; float minx = Float.POSITIVE_INFINITY, miny = Float.POSITIVE_INFINITY, minz = Float.POSITIVE_INFINITY; float maxx = Float.NEGATIVE_INFINITY, maxy = Float.NEGATIVE_INFINITY, maxz = Float.NEGATIVE_INFINITY; for (int i = 0; i < 8; i++) { float x = minX + (i & 1) * dx, y = minY + (i >> 1 & 1) * dy, z = minZ + (i >> 2 & 1) * dz; float tx = m.m00() * x + m.m10() * y + m.m20() * z + m.m30(); float ty = m.m01() * x + m.m11() * y + m.m21() * z + m.m31(); float tz = m.m02() * x + m.m12() * y + m.m22() * z + m.m32(); minx = Math.min(tx, minx); miny = Math.min(ty, miny); minz = Math.min(tz, minz); maxx = Math.max(tx, maxx); maxy = Math.max(ty, maxy); maxz = Math.max(tz, maxz); } dest.minX = minx; dest.minY = miny; dest.minZ = minz; dest.maxX = maxx; dest.maxY = maxy; dest.maxZ = maxz; return dest; } public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Float.floatToIntBits(maxX); result = prime * result + Float.floatToIntBits(maxY); result = prime * result + Float.floatToIntBits(maxZ); result = prime * result + Float.floatToIntBits(minX); result = prime * result + Float.floatToIntBits(minY); result = prime * result + Float.floatToIntBits(minZ); return result; } public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; AABBf other = (AABBf) obj; if (Float.floatToIntBits(maxX) != Float.floatToIntBits(other.maxX)) return false; if (Float.floatToIntBits(maxY) != Float.floatToIntBits(other.maxY)) return false; if (Float.floatToIntBits(maxZ) != Float.floatToIntBits(other.maxZ)) return false; if (Float.floatToIntBits(minX) != Float.floatToIntBits(other.minX)) return false; if (Float.floatToIntBits(minY) != Float.floatToIntBits(other.minY)) return false; if (Float.floatToIntBits(minZ) != Float.floatToIntBits(other.minZ)) return false; return true; } /** * Return a string representation of this AABB. *

* This method creates a new {@link DecimalFormat} on every invocation with the format string "0.000E0;-". * * @return the string representation */ public String toString() { return Runtime.formatNumbers(toString(Options.NUMBER_FORMAT)); } /** * Return a string representation of this AABB by formatting the vector components with the given {@link NumberFormat}. * * @param formatter * the {@link NumberFormat} used to format the vector components with * @return the string representation */ public String toString(NumberFormat formatter) { return "(" + Runtime.format(minX, formatter) + " " + Runtime.format(minY, formatter) + " " + Runtime.format(minZ, formatter) + ") < " + "(" + Runtime.format(maxX, formatter) + " " + Runtime.format(maxY, formatter) + " " + Runtime.format(maxZ, formatter) + ")"; } public void writeExternal(ObjectOutput out) throws IOException { out.writeFloat(minX); out.writeFloat(minY); out.writeFloat(minZ); out.writeFloat(maxX); out.writeFloat(maxY); out.writeFloat(maxZ); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { minX = in.readFloat(); minY = in.readFloat(); minZ = in.readFloat(); maxX = in.readFloat(); maxY = in.readFloat(); maxZ = in.readFloat(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy