I have two methods to set the construct a parallelogram:
parallelogram(tiny_vec<float, 3> p1, tiny_vec<float, 3> p2, tiny_vec<float, 3> p3);
parallelogram(tiny_vec<float, 3> p1, tiny_vec<float, 3> height_vec, tiny_vec<float, 3> width_vec);
The first creates it out of three points and calculates the fourth.
The second takes one point and two vectors and calculates the other three points from that.
However, both, points and vectors, are stored as a 3d vector tiny_vec<float, 3>
Is there any convention how to handle this?
Merge them into one method and add a bool use_height_and_width parameter?
Add a useless parameter to one and give it a default value?
Haven't found any answers, just the opposite question (different types, one method)
Give the functions different names which make the meaning of the parameters clear. If they are constructors, make them instead appropriately named static member functions which return parallelogram objects.
See the Named Constructor Idiom.
Make points and vectors different types. This also has the benefit of helping to catch errors such as adding two points together.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With