@@ -66,15 +66,15 @@ private function findPaths()
66
66
}
67
67
68
68
/**
69
- * @param int $x
70
- * @param int $y
69
+ * @param int $xPosition
70
+ * @param int $yPosition
71
71
* @return bool
72
72
*/
73
- private function isCorner ($ x , $ y )
73
+ private function isCorner ($ xPosition , $ yPosition )
74
74
{
75
- $ currentPoint = $ this ->qrCode ->getRow ($ y )->getPoint ($ x );
76
- $ neighbourPoint = $ this ->qrCode ->getRow ($ y - 1 )->getPoint ($ x - 1 );
77
- if ($ neighbourPoint == $ this ->qrCode ->getRow ($ y )->getPoint ($ x - 1 ) && $ neighbourPoint == $ this ->qrCode ->getRow ($ y - 1 )->getPoint ($ x )) {
75
+ $ currentPoint = $ this ->qrCode ->getRow ($ yPosition )->getPoint ($ xPosition );
76
+ $ neighbourPoint = $ this ->qrCode ->getRow ($ yPosition - 1 )->getPoint ($ xPosition - 1 );
77
+ if ($ neighbourPoint == $ this ->qrCode ->getRow ($ yPosition )->getPoint ($ xPosition - 1 ) && $ neighbourPoint == $ this ->qrCode ->getRow ($ yPosition - 1 )->getPoint ($ xPosition )) {
78
78
if ($ neighbourPoint != $ currentPoint ) {
79
79
return true ;
80
80
}
@@ -83,90 +83,90 @@ private function isCorner($x, $y)
83
83
}
84
84
85
85
/**
86
- * @param int $startX
87
- * @param int $startY
86
+ * @param int $startXPosition
87
+ * @param int $startYPosition
88
88
* @param bool $active
89
89
* @return array
90
90
*/
91
- private function traceComposite ($ startX , $ startY , $ active )
91
+ private function traceComposite ($ startXPosition , $ startYPosition , $ active )
92
92
{
93
93
94
- $ x = $ startX ;
95
- $ y = $ startY ;
94
+ $ xPosition = $ startXPosition ;
95
+ $ yPosition = $ startYPosition ;
96
96
$ switched = !$ active ;
97
97
98
98
$ direction = self ::DIRECTION_RIGHT ;
99
99
100
100
$ path = new Path ();
101
- $ path ->addPoint ($ this ->getPoint ($ x , $ y ));
101
+ $ path ->addPoint ($ this ->getPoint ($ xPosition , $ yPosition ));
102
102
103
103
do {
104
104
switch ($ direction ) {
105
105
case self ::DIRECTION_RIGHT :
106
- $ current = $ this ->qrCode ->getRow ($ y )->getPoint ($ x );
107
- $ other = $ this ->qrCode ->getRow ($ y - 1 )->getPoint ($ x );
106
+ $ current = $ this ->qrCode ->getRow ($ yPosition )->getPoint ($ xPosition );
107
+ $ other = $ this ->qrCode ->getRow ($ yPosition - 1 )->getPoint ($ xPosition );
108
108
if ($ current != $ other ) {
109
109
$ switched = $ other ;
110
- $ x ++;
110
+ $ xPosition ++;
111
111
} else {
112
- $ path ->addPoint ($ this ->getPoint ($ x , $ y ));
112
+ $ path ->addPoint ($ this ->getPoint ($ xPosition , $ yPosition ));
113
113
$ direction = ($ switched == $ other ) ? self ::DIRECTION_DOWN : self ::DIRECTION_UP ;
114
114
}
115
115
break ;
116
116
case self ::DIRECTION_UP :
117
- $ current = $ this ->qrCode ->getRow ($ y - 1 )->getPoint ($ x );
118
- $ other = $ this ->qrCode ->getRow ($ y - 1 )->getPoint ($ x - 1 );
117
+ $ current = $ this ->qrCode ->getRow ($ yPosition - 1 )->getPoint ($ xPosition );
118
+ $ other = $ this ->qrCode ->getRow ($ yPosition - 1 )->getPoint ($ xPosition - 1 );
119
119
if ($ current != $ other ) {
120
120
$ switched = $ other ;
121
- $ y --;
121
+ $ yPosition --;
122
122
} else {
123
- $ path ->addPoint ($ this ->getPoint ($ x , $ y ));
123
+ $ path ->addPoint ($ this ->getPoint ($ xPosition , $ yPosition ));
124
124
$ direction = ($ switched == $ other ) ? self ::DIRECTION_RIGHT : self ::DIRECTION_LEFT ;
125
- if ($ direction == self ::DIRECTION_RIGHT && $ this ->isCorner ($ x , $ y )) {
126
- $ this ->visited [$ y ][$ x ] = true ;
125
+ if ($ direction == self ::DIRECTION_RIGHT && $ this ->isCorner ($ xPosition , $ yPosition )) {
126
+ $ this ->visited [$ yPosition ][$ xPosition ] = true ;
127
127
}
128
128
}
129
129
break ;
130
130
case self ::DIRECTION_LEFT :
131
- $ current = $ this ->qrCode ->getRow ($ y - 1 )->getPoint ($ x - 1 );
132
- $ other = $ this ->qrCode ->getRow ($ y )->getPoint ($ x - 1 );
131
+ $ current = $ this ->qrCode ->getRow ($ yPosition - 1 )->getPoint ($ xPosition - 1 );
132
+ $ other = $ this ->qrCode ->getRow ($ yPosition )->getPoint ($ xPosition - 1 );
133
133
if ($ current != $ other ) {
134
134
$ switched = $ other ;
135
- $ x --;
135
+ $ xPosition --;
136
136
} else {
137
- $ path ->addPoint ($ this ->getPoint ($ x , $ y ));
137
+ $ path ->addPoint ($ this ->getPoint ($ xPosition , $ yPosition ));
138
138
$ direction = ($ switched == $ other ) ? self ::DIRECTION_UP : self ::DIRECTION_DOWN ;
139
- if ($ direction == self ::DIRECTION_DOWN && $ this ->isCorner ($ x , $ y )) {
140
- $ this ->visited [$ y ][$ x ] = true ;
139
+ if ($ direction == self ::DIRECTION_DOWN && $ this ->isCorner ($ xPosition , $ yPosition )) {
140
+ $ this ->visited [$ yPosition ][$ xPosition ] = true ;
141
141
}
142
142
}
143
143
break ;
144
144
case self ::DIRECTION_DOWN :
145
- $ current = $ this ->qrCode ->getRow ($ y )->getPoint ($ x - 1 );
146
- $ other = $ this ->qrCode ->getRow ($ y )->getPoint ($ x );
145
+ $ current = $ this ->qrCode ->getRow ($ yPosition )->getPoint ($ xPosition - 1 );
146
+ $ other = $ this ->qrCode ->getRow ($ yPosition )->getPoint ($ xPosition );
147
147
if ($ current != $ other ) {
148
148
$ switched = $ other ;
149
- $ y ++;
149
+ $ yPosition ++;
150
150
} else {
151
- $ path ->addPoint ($ this ->getPoint ($ x , $ y ));
151
+ $ path ->addPoint ($ this ->getPoint ($ xPosition , $ yPosition ));
152
152
$ direction = ($ switched == $ other ) ? self ::DIRECTION_LEFT : self ::DIRECTION_RIGHT ;
153
153
}
154
154
break ;
155
155
}
156
- } while (!($ x == $ startX && $ y == $ startY ));
156
+ } while (!($ xPosition == $ startXPosition && $ yPosition == $ startYPosition ));
157
157
158
158
return $ path ;
159
159
160
160
}
161
161
162
162
/**
163
- * @param int $x
164
- * @param int $y
163
+ * @param int $xPosition
164
+ * @param int $yPosition
165
165
* @return PathPoint
166
166
*/
167
- private function getPoint ($ x , $ y )
167
+ private function getPoint ($ xPosition , $ yPosition )
168
168
{
169
- return new PathPoint ($ x - 1 , $ y - 1 );
169
+ return new PathPoint ($ xPosition - 1 , $ yPosition - 1 );
170
170
}
171
171
172
172
}
0 commit comments