mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-10 05:34:54 +00:00
Added precision and mode arguments to Vector3::round() (#1256)
If the precision is positive (i.e. there are numbers after the decimal point), the results should be floating-point numbers rather than integers, hence the additional check. Even if the precision is negative or zero, the $mode parameter may still be useful.
This commit is contained in:
parent
63c12440dc
commit
3048a3b39b
@ -132,8 +132,10 @@ class Vector3{
|
|||||||
return new Vector3((int) floor($this->x), (int) floor($this->y), (int) floor($this->z));
|
return new Vector3((int) floor($this->x), (int) floor($this->y), (int) floor($this->z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function round(){
|
public function round(int $precision = 0, int $mode = PHP_ROUND_HALF_UP){
|
||||||
return new Vector3((int) round($this->x), (int) round($this->y), (int) round($this->z));
|
return $precision > 0 ?
|
||||||
|
new Vector3(round($this->x, $precision, $mode), round($this->y, $precision, $mode), round($this->z, $precision, $mode)) :
|
||||||
|
new Vector3((int) round($this->x, $precision, $mode), (int) round($this->y, $precision, $mode), (int) round($this->z, $precision, $mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function abs(){
|
public function abs(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user