Introduction: Despite my efforts to search online, I have been unable to find a solution to the specific problem I am facing.
Scenario: I am working on a project that involves maneuvering objects in a 2D space. Each object's position is stored in a Vector2D object, which includes an x coordinate, y coordinate, and other positioning-related data.
Currently, whenever I need to perform mathematical operations on these objects (such as moving them), I have to handle calculations separately for each axis, causing inconvenience.
The Question at Hand: Is there a way to implement operators (like '+' or '*') between classes to avoid writing distinct logic for individual variables? If so, how would this implementation look?
Example: I aim to shift object A by 4 units to the right and 4 units downwards.
Current Method:
this.ObjectA.x += 4;
This.objectA.y += 4;
Desired Approach: this.ObjectA += new Vector2D(4,4);