I want to implement a collision library using the interface Collidable
type Collidable interface{
BoundingBox() (float64,float64,float64,float64)
FastCollisionCheck(c2 Collidable) bool
DoesCollide(c2 Collidable) bool
Collide(c2 Collidable)
}
It has predefined shapes like.
type Circle struct{
X,Y,Radius float64
}
The idea is that I can do
type Rock struct{
collision.Circle
....
}
which then implements the interface Collidable, so I can pass it to a Spatial Hash Map (that expects a collidable). Only thing needed to do would be to override the Collide() function to my needs.
However the functions in type circle can not handle the type rock, even tough it has a circle embedded.
func (c1 *Circle) DoesCollide(i Collidable) bool{
switch c2 := value.(type) {
case Circle:
//doesn't fire, as it is of type Rock (unknown in this package)
//Needed is something like
//if i_embeds_Circle then c2 := i_to_Circle
}
}
Is this possible? Is there a better way?