Implementation of vector class in Delphi?
-
18-09-2019 - |
Question
How would you go about creating a vector class in Delphi? I would prefer to put all math related stuff into a DLL. Should I use a record or a class implementing an interface?
Pros of record approach:
- Fast and lightweight
- Value type
- Operator overloading
Cons of record approach:
- Implementation cannot be hidden in DLL (no inheritance, so no abstract base class for the DLL interface possible)
- Problems with records as properties of classes (
Class.VectorProp.X := 42
)
What do you think?
Solution
It depends on your priorities.
If performance is a top priority, go for records. But if implementation hiding is top, go for interfaces.
But why not use a package so you can both use static and dynamic linking if you want it. Of course, a DLL is prefered if the code is to be used by other languages, a DLL is a better aproach.
Botom line, the requirements and their relative priority determine the implementation.
OTHER TIPS
I haven't used either of these, but they could save you some time.
- SDL MathPack - not sure if you would have to pay for it
- Jedi Math - looks like the project has been abandoned, but you should check it out anyway. If your not doing anything crazy it will probably work for you.