So far in this chapter, we have implemented the basic primitives for 2D shapes. Now we are going to implement the most basic primitive test for 2D shapes; point containment. It's often useful to know if a point is inside a shape or not.
We are going to implement a method to check if a point is on a line, as well as methods to check if a point is within a circle, rectangle, and oriented rectangle. These are the most basic 2D intersection tests we can perform.
Follow these steps to test if a point is contained within any of the two-dimensional primitives we have created so far:
Declare the containment functions in
Geometry2D.h
:bool PointOnLine(const Point2D& point, const Line2D& line); bool PointInCircle(const Point2D& point, const Circle& c); bool PointInRectangle(const Point2D& point, const Rectangle& rectangle); bool PointInOrientedRectangle(const Point2D& point, const OrientedRectangle& rectangle);
Implement...