public function __construct($r, $g, $b, $a = 1) { $this->r = roundInt(clamp($r, 0, 255)); $this->g = roundInt(clamp($g, 0, 255)); $this->b = roundInt(clamp($b, 0, 255)); $this->setAlpha($a); }
/** * Sets the alpha channel of the color * Use a normalized value between 0 and 1, * where 1 is 100% opaque and 0 is transparent * @param int|float $alpha */ protected function setAlpha($alpha) { $this->a = clamp($alpha, 0, 1); }
public function test_clamp_upper_bound() { $clamped = clamp(20, 0, 10); $this->assertSame($clamped, 10); }
/** * Clamps the hue between 0 and 360 * Also forces a hue of 360 to wrap back to 0 since HSV mapping is cylindrical, and 360 is the same as 0; * @param $h * @return float|int */ private function clampHue($h) { $h = clamp($h, 0, 360); return $h === 360 ? 0 : $h; }