I have the following interface:
class IHittable
{
virtual Intersections intersects(const Ray & ray) = 0
}
which will be implemented by various geometric objects(Spheres, Triangles etc).
Now the class World
will look like this:
class World
{
public:
Intersection intesects(const Ray & ray)
{
auto intersections = Intersections();
for(auto object : objects)
{
auto xs = object.intersection();
if(xs.size() > 0)
{
intersections.append(xs);
}
}
return intersections;
}
private:
std::vector<std::shared_ptr<IHittable>> objects;
}
My question is, should the class World
also implement the IHittable interface? because its member looks the same and does exactly the same thing? How bad is it if I don't do that?
A second more generall question if this is allowed:
When should I make a function free standing and when not, in my case the function intersects
inside the World
class could be easily made free standing just with one extra argument. I don't know how to think about such cases.
Am I going against the "Single Responsibility Principle" if Intersects
is a member of World
?