Skip to content

Commit

Permalink
AxisAlignedBB: added offsetTowards() and offsetTowardsCopy()
Browse files Browse the repository at this point in the history
closes #64
closes #63
  • Loading branch information
dktapps committed Aug 3, 2023
1 parent 3557f51 commit 2c0be33
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/AxisAlignedBB.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ public function offsetCopy(float $x, float $y, float $z) : AxisAlignedBB{
return (clone $this)->offset($x, $y, $z);
}

/**
* Offsets this AxisAlignedBB in the given direction by the specified distance.
*
* @param int $face one of the Facing::* constants
*
* @return $this
*/
public function offsetTowards(int $face, float $distance) : AxisAlignedBB{
[$offsetX, $offsetY, $offsetZ] = Facing::OFFSET[$face] ?? throw new \InvalidArgumentException("Invalid Facing $face");

return $this->offset($offsetX * $distance, $offsetY * $distance, $offsetZ * $distance);
}

/**
* Returns an offset clone of this AxisAlignedBB.
*/
public function offsetTowardsCopy(int $face, float $distance) : AxisAlignedBB{
return (clone $this)->offsetTowards($face, $distance);
}

/**
* Insets the bounds of this AxisAlignedBB by the specified X, Y and Z.
*
Expand Down

0 comments on commit 2c0be33

Please sign in to comment.