예제 #1
0
 /**
  * Setups conversions with given precision.
  *
  */
 public static function setup()
 {
     if (self::$setup !== false) {
         return;
     }
     self::$angle = array('rad' => ILess_Math::divide(1, ILess_Math::multiply('2', str_replace(',', '.', M_PI))), 'deg' => ILess_Math::divide(1, 360), 'grad' => ILess_Math::divide(1, 400), 'turn' => '1');
     self::$length = array('m' => '1', 'cm' => '0.01', 'mm' => '0.001', 'in' => '0.0254', 'pt' => ILess_Math::divide('0.0254', '72'), 'pc' => ILess_Math::multiply(ILess_Math::divide('0.0254', '72'), '12'));
     self::$setup = true;
 }
예제 #2
0
 /**
  * Converts the $number to "real" number
  *
  * @param ILess_Node_Dimension|integer|float $number
  * @return double
  * @throws InvalidArgumentException
  */
 public function number($number)
 {
     if ($number instanceof ILess_Node_Dimension) {
         return $number->unit->is('%') ? ILess_Math::clean(ILess_Math::divide($number->value, '100')) : $number->value;
     } elseif (is_numeric($number)) {
         return $number;
     } else {
         throw new InvalidArgumentException(sprintf('Color functions take numbers as parameters. "%s" given.', gettype($number)));
     }
 }
예제 #3
0
파일: Color.php 프로젝트: poef/ariadne
 /**
  * Returns the luma
  *
  * @return integer
  */
 public function getLuma()
 {
     if ($this->luma !== null) {
         return $this->luma;
     }
     // Y = 0.2126 R + 0.7152 G + 0.0722 B
     $r = ILess_Math::multiply('0.2126', ILess_Math::divide($this->rgb[0], 255));
     $g = ILess_Math::multiply('0.7152', ILess_Math::divide($this->rgb[1], 255));
     $b = ILess_Math::multiply('0.0722', ILess_Math::divide($this->rgb[2], 255));
     $this->luma = ILess_Math::add(ILess_Math::add($r, $g), $b);
     return $this->luma;
 }
예제 #4
0
파일: Dimension.php 프로젝트: poef/ariadne
 /**
  * Converts to another unit
  *
  * @param array|string $conversions
  * @return ILess_Node_Dimension
  */
 public function convertTo($conversions)
 {
     $value = $this->value;
     $unit = clone $this->unit;
     if (is_string($conversions)) {
         $derivedConversions = array();
         foreach (ILess_UnitConversion::$groups as $i) {
             if (isset(ILess_UnitConversion::${$i}[$conversions])) {
                 $derivedConversions = array($i => $conversions);
             }
         }
         $conversions = $derivedConversions;
     }
     foreach ($conversions as $groupName => $targetUnit) {
         $group = ILess_UnitConversion::${$groupName};
         // numerator
         for ($i = 0, $count = count($unit->numerator); $i < $count; $i++) {
             $atomicUnit = $unit->numerator[$i];
             if (is_object($atomicUnit)) {
                 continue;
             }
             if (!isset($group[$atomicUnit])) {
                 continue;
             }
             $value = ILess_Math::multiply($value, ILess_Math::divide($group[$atomicUnit], $group[$targetUnit]));
             $unit->numerator[$i] = $targetUnit;
         }
         // denominator
         for ($i = 0, $count = count($unit->denominator); $i < $count; $i++) {
             $atomicUnit = $unit->denominator[$i];
             if (!isset($group[$atomicUnit])) {
                 continue;
             }
             // $value = $value / ($group[$atomicUnit] / $group[$targetUnit]);
             $value = ILess_Math::divide($value, ILess_Math::divide($group[$atomicUnit], $group[$targetUnit]));
             $unit->denominator[$i] = $targetUnit;
         }
     }
     $unit->cancel();
     return new ILess_Node_Dimension($value, $unit);
 }