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:
SOFe 2017-08-04 16:56:42 +08:00 committed by Dylan K. Taylor
parent 63c12440dc
commit 3048a3b39b

View File

@ -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(){