package main

import "opslag.de/schobers/geom"

type entityList []*entity

func (l entityList) Add(e *entity) entityList {
	return append(l, e)
}

func (l entityList) AddList(list entityList) entityList {
	return append(l, list...)
}

func (l entityList) Find(pos geom.Point) int {
	for i, e := range l {
		if e.pos == pos {
			return i
		}
	}
	return -1
}

func (l entityList) FindEntity(pos geom.Point) *entity {
	idx := l.Find(pos)
	if idx == -1 {
		return nil
	}
	return l[idx]
}

func (l entityList) Remove(pos geom.Point) entityList {
	idx := l.Find(pos)
	return append(l[:idx], l[idx+1:]...)
}
