From: Vincent Vanwaelscappel Date: Fri, 29 Sep 2023 12:15:09 +0000 (+0200) Subject: #6300 @0.25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=1937a5c4a9ff8b3ac214c51d06622031c468738c;p=cubist_util.git #6300 @0.25 --- diff --git a/src/Graphics/Color.php b/src/Graphics/Color.php index 5a377e5..b06b148 100644 --- a/src/Graphics/Color.php +++ b/src/Graphics/Color.php @@ -153,14 +153,23 @@ class Color /** * @return float[] */ - public function toLottie() + public function toLottie($digits = 12, $regex = false) { // Lottie colors are decimal numbers between 0 (0) and 1 (255) rounded at 12 digits - $digits = 12; - return [round($this->_red, $digits), round($this->_green, $digits), round($this->_blue, $digits), round($this->_alpha, $digits)]; + return [$this->_lottieRound($this->_red, $digits, $regex), $this->_lottieRound($this->_green, $digits, $regex), $this->_lottieRound($this->_blue, $digits, $regex), $this->_lottieRound($this->_alpha, $digits, $regex)]; } + protected function _lottieRound($n, $digits = 12, $regex = false) + { + $roundDigits = max(12, $digits); + $n = round($n, $roundDigits); + if ($roundDigits == $digits) { + return $n; + } + return substr((string)$n, 0, $digits + 2) . '\d*'; + } + public function toHexRVB() { return $this->toHexComposante('red') . $this->toHexComposante('green') . $this->toHexComposante('blue');