-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMove.php
More file actions
81 lines (79 loc) · 1.64 KB
/
Move.php
File metadata and controls
81 lines (79 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
class Move
{
private $X;
private $Y;
//------------------------------------------------------------------
public function __construct( $X, $Y )
{
$this->X = $X;
$this->Y = $Y;
}
//------------------------------------------------------------------
public function get( $field )
{
if( property_exists( __CLASS__, $field ) )
{
return $this->$field;
}
return false;
}
//------------------------------------------------------------------
public function isEqualSpaces( $move )
{
if( !( $move instanceof Move ) )
{
return false;
}
if( abs( $this->X ) == abs( $move->X ) &&
abs( $this->Y ) == abs( $move->Y ) )
{
return true;
}
return false;
}
//------------------------------------------------------------------
public function isEqualMove( $move )
{
if( !( $move instanceof Move ) )
{
return false;
}
if( $this->X == $move->X &&
$this->Y == $move->Y )
{
return true;
}
return false;
}
//------------------------------------------------------------------
public function isEqualRatio( $move )
{
if( !( $move instanceof Move ) )
{
return false;
}
$move = $this->reduce( $move );
return( $this->reduce( $this )->isEqualSpaces( $move ) );
}
//------------------------------------------------------------------
private function reduce( $move )
{
$GCD = $this->GCD( $move->X, $move->Y );
return new Move( ( $move->X / $GCD ),
( $move->Y / $GCD ) );
}
//------------------------------------------------------------------
private function GCD( $a, $b )
{
if( $b == 0 )
{
return $a;
}
else
{
return $this->GCD( $b, $a % $b );
}
}
} //move
?>