I am working with computer graphics.
I would like to represent a line with two end points, and, then I would like my Line2d
class to have a method that
If you want to be very mathematical, maybe this can help: https://en.wikipedia.org/wiki/Homogeneous_coordinates
In 2d that means a position is (x,y,1) and a direction (dx,dy,0). The reason for this is projection, which is rare in 2d but common in 3d.
So to try to answer: Just use 4 component vectors all the time. Positions have a w=1, directions a w=0.
Just try it with a line based of two points A and B, both have w=1. The vector from A to B is B-A, which ends up with w=0.
Also what you use in your code does matter very little unless you end up optimizing a special case. Just go for the smallest data structure. Start and end should be fine.
Maybe think about indexed: A flat array of all vertices and every line is just two indices into the vertex array.