So I may want various functions that operate on a line:
inline float yIntercept(const vec2& ptA, const vec2& ptB, float x);
inline float xIntercept(const vec2& ptA, const vec2& ptB, float y);
inline bool lineIntersection(const vec2& ptA0, const vec2& ptB0, const vec2& ptA1, const vec2& ptB1);
The functions takes 2 points for each line representing the line.
Or I can write a line class that has those 2 points and various useful line related methods.
struct Line {
... stuff
inline float xIntercept(float y);
inline float yIntercept(float x);
inline bool lineIntersection(const Line& other);
vec2 m_point[2];
};
One thing I was thinking about is performance of creating an instance of this line class every time I need to call one of these functions just given 2 points.
I may be operating on a point list representing a polygon and don't actually have any line objects instantiated.
At any time I may either call
yIntercept(somePointA, somePointB, 3.0f);
Or
Line(somePointA, somePointB).yIntercept(3.0f); //I think this would compile
I like the idea of having classes for these kinds of things rather than C style functions, but I was wondering if there's some performance penalty of creating an instance of the class like this rather than just passing the points right into a function. Maybe the compiler does some optimization?