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
| <?php
class point
{
public $restriction;
public $angle;
public $valeur;
public function __construct($r,$a)
{
$this->restriction = $r;
$this->angle = $a;
}
public static function sort($p1, $p2)
{
if ($p1->angle == $p2->angle) {
return ($p1->restriction == $p2->restriction ? 0 : ($p1->restriction > $p2->restriction ? 1 : -1));
} else {
return ($p1->angle > $p2->angle ? 1 : -1);
}
}
}
$points = array(
new point(0, 0),
new point(1, 1),
new point(2, 1),
new point(1, 3),
new point(4, 5),
new point(2, 3),
new point(3, 2),
new point(4, 4),
new point(0, 0)
);
usort($points, array('point', 'sort'));
header('Content-type: text/plain');
foreach ($points as $p) {
printf ('(%d %d)' . PHP_EOL, $p->angle, $p->restriction);
}
?> |
Partager