radius($radius); $this->initial_x = $initial_x; $this->initial_y = $initial_y; $this->position($initial_x, $initial_y); if (!$name) { $name = $this->generateName(); } $this->name($name); } public function radius(int $radius = null): int|Boid { if ($radius) { $this->radius = $radius; return $this; } return $this->radius; } public function position(int $x = null, int $y = null): array|Boid { if ($x !== null xor $y !== null) { throw new Exception('Either 0 or 2 arguments are requried for Boid::position()'); } if ($x !== null) { $this->x = $x; $this->y = $y; return $this; } return [$this->x, $this->y]; } public function name(string $name = null): string|Boid { if ($name) { $this->name = $name; return $this; } return $this->name; } public function isCollisionWithWorld(int $w_w, int $w_h, int $w_x, int $w_y): bool { return Collision::circleWorld($this->radius, $this->x, $this->y, $w_w, $w_h, $w_x, $w_y); } protected function generateName() { return uniqid('boid'); } }