|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cgi\Calc\Tests\Field; |
|
4
|
|
|
|
|
5
|
|
|
use Cgi\Calc\Field\CircularCenterRadius; |
|
6
|
|
|
use Cgi\Calc\Field\RectangularFromTwoPoints; |
|
7
|
|
|
use Cgi\Calc\Point; |
|
8
|
|
|
use Cgi\Calc\PointSet; |
|
9
|
|
|
|
|
10
|
|
|
class CircularCenterRadiusTest extends \PHPUnit_Framework_TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function test_draw() |
|
13
|
|
|
{ |
|
14
|
|
|
$circularProducer = new CircularCenterRadius(new Point(15,15), 10, true); |
|
15
|
|
|
$circle = $circularProducer->produce(); |
|
16
|
|
|
|
|
17
|
|
|
$circle->smallestRectangularEnvelope(); |
|
18
|
|
|
$rectangularProducer = new RectangularFromTwoPoints(new Point(0,0), new Point(30, 30)); |
|
19
|
|
|
$rect = $rectangularProducer->produce(); |
|
20
|
|
|
|
|
21
|
|
|
if (false) { |
|
|
|
|
|
|
22
|
|
|
$this->doDraw($circle, $rect); |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
static::assertFalse($circle->contains(new Point(11, 5))); |
|
26
|
|
|
static::assertTrue($circle->contains(new Point(12, 5))); |
|
27
|
|
|
|
|
28
|
|
|
static::assertTrue($circle->contains(new Point(15, 15))); |
|
29
|
|
|
|
|
30
|
|
|
static::assertTrue($circle->contains(new Point(15, 5))); |
|
31
|
|
|
static::assertTrue($circle->contains(new Point(15, 25))); |
|
32
|
|
|
|
|
33
|
|
|
static::assertTrue($circle->contains(new Point(5, 15))); |
|
34
|
|
|
static::assertTrue($circle->contains(new Point(25, 15))); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
private function doDraw(PointSet $circle, PointSet $rect) |
|
38
|
|
|
{ |
|
39
|
|
|
$arr = []; |
|
40
|
|
|
/** @var Point $point */ |
|
41
|
|
|
foreach ($rect as $point) { |
|
42
|
|
|
$arr[$point->getY()][$point->getX()] = '.'; |
|
43
|
|
|
} |
|
44
|
|
|
foreach ($circle as $point) { |
|
45
|
|
|
$arr[$point->getY()][$point->getX()] = 'X'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
print "\n\n\n\n"; |
|
49
|
|
|
$firstLine = true; |
|
50
|
|
|
for ($y=0, $yMax = count($arr); $y<$yMax; $y++) { |
|
51
|
|
|
$row = $arr[$y]; |
|
52
|
|
|
if ($firstLine) { |
|
53
|
|
|
$firstLine = false; |
|
54
|
|
|
print 'y '; |
|
55
|
|
View Code Duplication |
for ($x=0, $xMax = count($row); $x<$xMax; $x++) { |
|
|
|
|
|
|
56
|
|
|
print $x % 10; |
|
57
|
|
|
} |
|
58
|
|
|
print " x \n"; |
|
59
|
|
|
} |
|
60
|
|
|
print str_pad($y, 3); |
|
61
|
|
View Code Duplication |
for ($x=0, $xMax = count($row); $x<$xMax; $x++) { |
|
|
|
|
|
|
62
|
|
|
print $row[$x]; |
|
63
|
|
|
} |
|
64
|
|
|
print "\n"; |
|
65
|
|
|
} |
|
66
|
|
|
print "\n\n\n\n"; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|