public function testFitInRange() { // Value between range $this->assertEquals(5, Normalize::fitInRange(5, 0, 23)); $this->assertEquals(23, Normalize::fitInRange(23, 0, 23)); // Value out of range $this->assertEquals(23, Normalize::fitInRange(121, 0, 23)); $this->assertEquals(0, Normalize::fitInRange(-121, 0, 23)); // Just force min value $this->assertEquals(121, Normalize::fitInRange(121, 0)); $this->assertEquals(0, Normalize::fitInRange(-121, 0)); // Just force max value $this->assertEquals(0, Normalize::fitInRange(121, false, 0)); $this->assertEquals(-121, Normalize::fitInRange(-121, false, 0)); }
/** * Required by vignette to generate the propper colors. * * @param float $size Size of the vignette, between 0 and 10. Low is sharper. * @param float $level Vignete transparency, between 0 and 1 * @param int $x X position of the pixel. * @param int $y Y position of the pixel. * @param array &$rgb Current pixel olor information. * @return void * @codeCoverageIgnore */ protected function vignetteEffect($size, $level, $x, $y, &$rgb) { $l = sin(M_PI / $this->width * $x) * sin(M_PI / $this->height * $y); $l = pow($l, Normalize::fitInRange($size, 0, 10)); $l = 1 - Normalize::fitInRange($level, 0, 1) * (1 - $l); $rgb['red'] *= $l; $rgb['green'] *= $l; $rgb['blue'] *= $l; }