I have three shape classes Circle
, Square
, ConvexPolygon
, and I have the functions
bool ShapesIntersect(const Circle& s1, const Circle& s2);
bool ShapesIntersect(const Circle& s1, const Square& s2);
// ... and the other 7 combinations
I would like a polymorphic function sort of like
Matrix<bool> ComputeShapeIntersectionMatrix(
const vector<Shape>& shapes1,
const vector<Shape>& shapes2);
that calls the shape-specific methods above to fill the matrix of intersections.
I think it is impossible to do exactly this in c++, but I'm ok with any other solution, as long as I can add a new shape type without changing the code that computes the intersection matrix.
Intersect
function in the baseShape
class that is overridden in the child classes? – Some programmer dude