mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +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));
|
||||
}
|
||||
|
||||
public function round(){
|
||||
return new Vector3((int) round($this->x), (int) round($this->y), (int) round($this->z));
|
||||
public function round(int $precision = 0, int $mode = PHP_ROUND_HALF_UP){
|
||||
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(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user