1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the IrishDan\ResponsiveImageBundle package. |
4
|
|
|
* |
5
|
|
|
* (c) Daniel Byrne <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE file that was distributed with this source |
8
|
|
|
* code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace IrishDan\ResponsiveImageBundle\Tests\ImageProcessing; |
12
|
|
|
|
13
|
|
|
use IrishDan\ResponsiveImageBundle\ImageProcessing\CoordinateGeometry; |
14
|
|
|
|
15
|
|
|
class CoordinateGeometryTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
protected $geometry; |
18
|
|
|
|
19
|
|
|
public function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->geometry = new CoordinateGeometry(10, 20, 90, 100); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testAxisLength() |
25
|
|
|
{ |
26
|
|
|
$this->assertEquals(80, $this->geometry->axisLength('x')); |
27
|
|
|
$this->assertEquals(80, $this->geometry->axisLength('y')); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testScaleSize() |
31
|
|
|
{ |
32
|
|
|
// Scale with same proportions |
33
|
|
|
$scaledSize = $this->geometry->scaleSize(40, 40); |
34
|
|
|
|
35
|
|
|
$this->assertEquals(40, $scaledSize['width']); |
36
|
|
|
$this->assertEquals(40, $scaledSize['height']); |
37
|
|
|
|
38
|
|
|
// Scale with longer width |
39
|
|
|
$scaledSize = $this->geometry->scaleSize(80, 40); |
40
|
|
|
|
41
|
|
|
$this->assertEquals(40, $scaledSize['width']); |
42
|
|
|
$this->assertEquals(40, $scaledSize['height']); |
43
|
|
|
|
44
|
|
|
// Scale with longer height |
45
|
|
|
$scaledSize = $this->geometry->scaleSize(40, 80); |
46
|
|
|
|
47
|
|
|
$this->assertEquals(40, $scaledSize['width']); |
48
|
|
|
$this->assertEquals(40, $scaledSize['height']); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testAspectRatio() |
52
|
|
|
{ |
53
|
|
|
$this->assertEquals(1, $this->geometry->aspectRatio()); |
54
|
|
|
$this->assertEquals(2, $this->geometry->aspectRatio(50, 100)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testIsInside() |
58
|
|
|
{ |
59
|
|
|
$this->assertTrue($this->geometry->isInside(11, 21, 89, 99)); |
60
|
|
|
$this->assertTrue($this->geometry->isInside(10, 20, 90, 100)); |
61
|
|
|
// One coordinate falls outside |
62
|
|
|
$this->assertFalse($this->geometry->isInside(9, 21, 89, 99)); |
63
|
|
|
$this->assertFalse($this->geometry->isInside(11, 19, 89, 99)); |
64
|
|
|
$this->assertFalse($this->geometry->isInside(11, 21, 91, 99)); |
65
|
|
|
$this->assertFalse($this->geometry->isInside(11, 21, 89, 101)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testRoundAll() |
69
|
|
|
{ |
70
|
|
|
$data = [ |
71
|
|
|
'key1' => 3.870000007, |
72
|
|
|
'key2' => .9000099993, |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
$rounded = $this->geometry->roundAll($data); |
76
|
|
|
|
77
|
|
|
$this->assertEquals(4, $rounded['key1']); |
78
|
|
|
$this->assertEquals(1, $rounded['key2']); |
79
|
|
|
} |
80
|
|
|
} |