time = $t; } public function addEntity(DiffInterface $entity, ?DiffInterface $intersects): self { $this->entities[] = $entity; if ($intersects != null) $this->intersects[array_key_last($this->entities)] = $intersects; return $this; } public function getTime(): Time { return $this->time; } public function getIntersection(DiffInterface $entity): ?DiffInterface { $key = (function() use ($entity) : int { foreach ($this->entities as $key => $ent) if ($ent == $entity) return $key; })(); if (isset($this->intersects[$key])) return $this->intersects[$key]; return null; } public function isEmpty(): bool { return empty($this->entities); } public function getIterator(): \Generator { foreach ($this->entities as $entity) yield $entity; } }