Having recently done some vectorial mapping (including z / 3D) and seeing your Android tag, I recommend flipping yours.
There are many reasons:
- You can configure to meet specific performance / memory / performance constraints.
- If multithreading, you can make your class immutable and thread safe
- those. If memory is limited, you can save all three dimensions in int or long
- If cpu constrained you can use simple separate numbers
- If GC / Garbage is limited, you can recycle and merge instances (mutable)
In the end, most of these primitives are fairly simple to write, test, etc. The main methods you need to write (in addition to the template constructor / get / set / ...) - Distance - Scalar product - Unify (make length == 1 for various mathematical operations) - And I used DistanceSquared in the past for comparison functions .. This removes the sqrt operator from most distance methods, calculating a relative distance useful enough to compare point distances, etc.
source share