Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AxisAlignedBB is now immutable #95

Merged
merged 13 commits into from
Dec 9, 2024
Prev Previous commit
Next Next commit
Change documentation
Dhaiven committed Dec 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 1a3ef4ee3e9451212f717f9dbedc61fe5625c08a
38 changes: 13 additions & 25 deletions src/AxisAlignedBB.php
Original file line number Diff line number Diff line change
@@ -88,9 +88,7 @@ public function addCoord(float $x, float $y, float $z) : AxisAlignedBB{
}

/**
* Outsets the bounds of this AxisAlignedBB by the specified X, Y and Z.
*
* Returns an expanded clone of this AxisAlignedBB.
* Returns a copy of the AxisAlignedBB with bounds outset by the specified X, Y and Z.
*/
public function expandedCopy(float $x, float $y, float $z): AxisAlignedBB{
return new AxisAlignedBB(
@@ -104,9 +102,7 @@ public function expandedCopy(float $x, float $y, float $z): AxisAlignedBB{
}

/**
* Shifts this AxisAlignedBB by the given X, Y and Z.
*
* Returns an offset clone of this AxisAlignedBB.
* Returns a copy of the AxisAlignedBB with bounds offset by the specified X, Y and Z.
dktapps marked this conversation as resolved.
Show resolved Hide resolved
*/
public function offsetCopy(float $x, float $y, float $z) : AxisAlignedBB{
return new AxisAlignedBB(
@@ -120,9 +116,7 @@ public function offsetCopy(float $x, float $y, float $z) : AxisAlignedBB{
}

/**
* Offsets this AxisAlignedBB in the given direction by the specified distance.
*
* Returns an offset clone of this AxisAlignedBB.
* Returns a copy of the AxisAlignedBB with bounds offset in the given direction by the specified distance.
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved
*/
public function offsetTowardsCopy(Facing $face, float $distance) : AxisAlignedBB{
[$offsetX, $offsetY, $offsetZ] = $face->offset();
@@ -131,9 +125,7 @@ public function offsetTowardsCopy(Facing $face, float $distance) : AxisAlignedBB
}

/**
* Insets the bounds of this AxisAlignedBB by the specified X, Y and Z.
*
* Returns an contracted clone of this AxisAlignedBB.
* Returns a copy of the AxisAlignedBB with bounds contracted by the specified X, Y and Z.
*/
public function contractedCopy(float $x, float $y, float $z) : AxisAlignedBB{
return new AxisAlignedBB(
@@ -147,11 +139,9 @@ public function contractedCopy(float $x, float $y, float $z) : AxisAlignedBB{
}

/**
* Extends the AABB in the given direction.
*
* @param float $distance Negative values pull the face in, positive values push out.
*
* Returns an extended clone of this AxisAlignedBB.
* Returns a copy of the AxisAlignedBB with bounds extended in the given direction.
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved
*/
public function extendedCopy(Facing $face, float $distance) : AxisAlignedBB{
$minX = $this->minX;
@@ -174,23 +164,21 @@ public function extendedCopy(Facing $face, float $distance) : AxisAlignedBB{
}

/**
* Inverse of extend().
* @see AxisAlignedBB::extendedCopy()
*
* @param float $distance Positive values pull the face in, negative values push out.
*
* Returns an trimmed clone of this AxisAlignedBB.
* Returns a copy of the AxisAlignedBB with bounds trimmed in the given direction.
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved
*
* Inverse of extend().
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved
* @see AxisAlignedBB::extendedCopy()
*/
public function trimmedCopy(Facing $face, float $distance) : AxisAlignedBB{
return $this->extendedCopy($face, -$distance);
}

/**
* Increases the dimension of the AABB along the given axis.
*
* @param float $distance Negative values reduce width, positive values increase width.
*
* Returns an stretched clone of this AxisAlignedBB.
* Returns a copy of the AxisAlignedBB with bounds stretched along the given axis.
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved
*/
public function stretchedCopy(Axis $axis, float $distance) : AxisAlignedBB{
$minX = $this->minX;
@@ -215,10 +203,10 @@ public function stretchedCopy(Axis $axis, float $distance) : AxisAlignedBB{
}

/**
* Reduces the dimension of the AABB on the given axis. Inverse of stretch().
* Returns a copy of the AxisAlignedBB with bounds squashed along the given axis.
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved
*
* Inverse of stretch().
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved
* @see AxisAlignedBB::stretchedCopy()
*
* Returns an squashed clone of this AxisAlignedBB.
*/
public function squashedCopy(Axis $axis, float $distance) : AxisAlignedBB{
return $this->stretchedCopy($axis, -$distance);