Replace vec
methods with operator overloads
#230
Labels
inconsistency
Issues that break convention rather than being faulty implementations
misimplementation
Circumlocutious or redundant implementation
The current class
vec
, while useful, requires the user to use an unusual means of calculating operations: named methods corresponding to the desired operation. However, C++ gives us operator overloads, and that is the way these types of operations should be conducted. Operator overloads don't require the developer to memorize what the method names are: you just have to call on the well known operators themselves (* + - / += -= > <
etc.).Some things to be aware of when rewriting methods:
From
rendersky
:We see spurious
vec()
constructor calls here becausevec
has no equivalent of the + operator, only the += operator. These vec() calls construct a new object to+=
on so that the original is not modified. Of course, these should be replaced by+
when encountered.In general, the operator methods already defined are of the
+=
type: they modify the object in place. This includes some operators such as**
which don't even have such operation/assignment equivalents.The
mul(vec o)
operator is not thedot
operator:mul
returns the element-wise multiplication ofthis
witho
.The text was updated successfully, but these errors were encountered: