@Override public AABBOld reflect() { // We need to manually do this since AABB breaks if v00 is to the right // of v11, as we make algorithmic simplifications on the assumption // that v00 is always to the left of v11. return new AABBOld(Vec2.immutable(-v11.x(), v00.y()), Vec2.immutable(-v00.x(), v11.y())); }
@Override protected boolean intersectsOnOwnAxes(Shape s) { // return getHorizontalProjection().intersects(s.getHorizontalProjection()) && // getVerticalProjection().intersects(s.getVerticalProjection()); return s.getHorizontalProjection().intersects(v00.x(), v11.x()) && s.getVerticalProjection().intersects(v00.y(), v11.y()); }
@Override protected Vec2[] getVertices() { // throw new UnsupportedOperationException("AABB should have no need " // + "for getVertices()!"); return new Vec2[] { v00, Vec2.immutable(v11.x(), v00.y()), // v10 v11, Vec2.immutable(v00.x(), v11.y()) // v01 }; }
@Override protected ShapeProjection getProjection(Vec2 axis) { // This method of computation is preferable to the default impl., // which invokes getVertices(). float p0 = axis.dot(v00); float p1 = axis.dot(v11); float p2 = axis.dot(v00.x(), v11.y()); float p3 = axis.dot(v11.x(), v00.y()); return new ShapeProjection( Maths.min(Maths.min(p0, p1), Maths.min(p2, p3)), Maths.max(Maths.max(p0, p1), Maths.max(p2, p3))); }
/** Calculates and returns the width of this AABB. */ public float width() { return v11.x() - v00.x(); }
/** Gets the x-coordinate of the top-right vertex of this AABB. */ public float getMaxX() { return v11.x(); }
/** * Gets the x-coordinate of the bottom-left vertex - or the origin - of this AABB. * * @return The x-coordinate of this AABB's origin. */ public float getOriginX() { return v00.x(); }
@Override ShapeProjection getHorizontalProjection() { return new ShapeProjection(v00.x(), v11.x()); }
@Override public boolean containsPoint(float x, float y) { return x >= v00.x() && x <= v11.x() && y >= v00.y() && y <= v11.y(); }
/** * Calculates whether or not this AABB contains the specified AABB. * * @return {@code true} if this AABB contains {@code a}; {@code false} otherwise. */ public boolean containsAABB(AABBOld a) { return v00.x() <= a.v00.x() && v11.x() >= a.v11.x() && v00.y() <= a.v00.y() && v11.y() >= a.v11.y(); }
/** * Calculates whether or not two axis-aligned bounding boxes intersect. * * @param a The AABB with which to test intersection. * @return {@code true} if the two AABBs intersect; {@code false} otherwise. */ public boolean intersectsAABB(AABBOld a) { return v00.x() <= a.v11.x() && v11.x() >= a.v00.x() && v00.y() <= a.v11.y() && v11.y() >= a.v00.y(); }