]> _ Git - cubist_util.git/commitdiff
#6300 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 29 Sep 2023 12:15:09 +0000 (14:15 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 29 Sep 2023 12:15:27 +0000 (14:15 +0200)
src/Graphics/Color.php

index 5a377e5f502857a3d3764f1823e2826b2281cf75..b06b1482b28424ccc354f42084adb0b2a95257a1 100644 (file)
@@ -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');