PHP library containing math related code used in PocketMine-MP
Facing::OFFSET
constant (map of facing directions to their coordinate offsets)AxisAlignedBB->offsetTowards()
and AxisAlignedBB->offsetTowardsCopy()
- moves the BB in the given direction by a specified distanceDespite the version bump to 1.0.0, this isn't a huge release. Staying on 0.x for so long was a mistake that needed to be corrected.
Matrix::offsetGet()
(missed due to PHPStan bug).VoxelRayTrace::betweenPoints()
.Facing::rotate()
when given incompatible axes and facings - they now show the names instead of the integer ID.Matrix
on PHP 8.1.Vector3
elements:
__construct()
getX()
getY()
getZ()
add()
subtract()
maxPlainDistance()
withComponents()
x
, y
and z
fieldsVector2
x
and y
fields now use native float
property types.Vector2->__construct()
parameters are now mandatory.Vector2->addVector(Vector2)
and Vector2->subtractVector(Vector2)
, replacing the overloaded behaviour of add()
and subtract()
.Vector2->add()
no longer accepts Vector2
in the first argument (use addVector()
instead).Vector2->subtract()
no longer accepts Vector2
in the first argument (use subtractVector()
instead).Vector2->distance()
no longer accepts float, float
(now Vector2
is required).Vector2->distanceSquared()
no longer accepts float, float
(now Vector2
is required).Matrix
has been modernized. All cases that used to return false
on error now throw exceptions instead.Axis
, AxisAlignedBB
, Facing
, Math
, VectorMath
and VoxelRayTrace
are now final.This is a feature release, featuring significant API changes compared to 0.2.x.
Facing
class, which allows using and manipulating 3D Facing
values.
Vector3::SIDE_*
constants are removed and replaced with Facing::*
constants.Vector3::getOppositeSide()
is replaced by Facing::opposite()
.Facing::axis()
, Facing::isPositive()
, Facing::rotate()
etc are provided.Axis
class.Vector3
getOppositeSide()
: use Facing::opposite()
insteadsetComponents()
: mutating Vector3
is now discouraged, and in the future Vector3
will become immutable.Vector3::SIDE_*
constants have been removed (use Facing
instead).maxComponents()
: returns a Vector3
with the highest x, y and z values of all the vectors given.minComponents()
: returns a Vector3
with the lowest x, y and z values of all the vectors given.sum()
: returns a Vector3
with x, y and z equalling the sums of the x, y and z values of the given vectors respectively.Vector3->sides()
, which returns a Generator<Facing, Vector3>
for all axis-aligned sides of the vector.Vector3->sidesArray()
, which returns array<Facing, Vector3>
for all axis-aligned sides of the vector.Vector3->sidesAroundAxis()
, which returns Generator<Facing, Vector3>
for axis-aligned sides of the vector not on the given axis.Vector3->withComponents()
, which allows easily creating a copy of a Vector3
while replacing one or more components of it.Vector3->add()
is split into two functions:
Vector3->add()
now requires float, float, float
and has no optional parameters.Vector3->addVector()
accepts Vector3
, replacing the overloaded functionality of Vector3->add()
.Vector3->subtract()
is split into two functions:
Vector3->subtract()
now requires float, float, float
and has no optional parameters.Vector3->subtractVector()
accepts Vector3
, replacing the overloaded functionality of Vector3->subtract()
.AxisAlignedBB
AxisAlignedBB->__construct()
now throws InvalidArgumentException
if any of the min
components are larger than their corresponding max
components.setBounds()
: modifying AxisAlignedBB
is now discouraged and AxisAlignedBB
will become immutable in the futuresetBB()
extend()
: adds a length of distance to the given face of the bounding boxextendedCopy()
trim()
: removes a length of distance from the given face of the bounding boxtrimmedCopy()
stretch()
: adds a length of distance to both sides of the bounding box on the given axisstretchedCopy()
squash()
: removes a length of distance from both sides of the bounding box on the given axissquashedCopy()
getXLength()
: returns the difference between minX
and maxX
getYLength()
: returns the difference between minY
and maxY
getZLength()
: returns the difference between minZ
and maxZ
isCube()
: returns whether the bounding box's edges are all of approximately equal lengthgetVolume()
: returns the amount of space inside the bounding box in cubic unitsone()
: returns a new AxisAlignedBB
with min bounds 0,0,0
and max bounds 1,1,1
Vector3::subtract()
now requires at least 1 parameter.Vector3::maxPlainDistance()
now requires at least 1 parameter.Matrix
, Vector3
and AxisAlignedBB
.