Skip to content

Commit 6ec6be9

Browse files
authored
Merge pull request #60 from wybcp/patch-1
Update Square.php
2 parents 34cb6a0 + c420911 commit 6ec6be9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

package/Other/Square.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public function check()
2020
{
2121
$result = [];
2222
if (count($this->point) != 4) return false;
23-
for ($i = 0; $i < count($this->point); $i++) {
24-
for ($j = $i + 1; $j < count($this->point); $j++) {
23+
for ($i = 0; $i < 4; $i++) {
24+
for ($j = $i + 1; $j < 4; $j++) {
2525
$result[]=$this->_calculation($i,$j);
2626
}
2727
}
@@ -35,9 +35,9 @@ public function check()
3535

3636
private function _calculation($i, $j)
3737
{
38-
return ($this->point[$i][0] - $this->point[$j][0]) * ($this->point[$i][0] - $this->point[$j][0]) + ($this->point[$i][1] - $this->point[$j][1]) * ($this->point[$i][1] - $this->point[$j][1]);
38+
return pow($this->point[$i][0] - $this->point[$j][0],2) + pow($this->point[$i][1] - $this->point[$j][1] ,2);
3939
}
4040
}
4141

4242
$obj = new Square([[0, 0], [1, 0], [1, 1], [0, 1]]);
43-
var_dump($obj->check());
43+
var_dump($obj->check());

0 commit comments

Comments
 (0)