bmx-ng / brl.mod

BlitzMax Runtime Libraries, for BlitzMax NG.
12 stars 11 forks source link

BRL.Geometry #116

Open HurryStarfish opened 5 years ago

HurryStarfish commented 5 years ago

Recently, BRL.Geometry has been added. Having standard types for vectors etc. is nice and will surely be useful. :slightly_smiling_face: As I had made my own personal vector types before (though with less functionality than these ones), I've taken a look at the module to see what could be improved in my opinion. These are my suggestions, loosely in order of importance:

I can make a pull request out of this with the respective changes, but before that, I made this issue and the above list for discussion purposes :)

GWRon commented 5 years ago

Re 7. I would say "Interpolate" is too common. There is a set of often used interpolation functions (bounce, quad,...). This one here means "LinearInterpolate". Still "Lerp" is how many name it...so I am OK with it.

Re 9. I think type or struct names should not be part of ToString. Also brackets are only needed if you passed multiple triplets to the string.

ToString() is there to create a textual representation of the value behind the type. For integers it is the number, for strings the text, for rgb the three values and so on. You can always wrap some stuff around the ToString() call.

Think it depends on your assumptions around this command.

HurryStarfish commented 5 years ago

ToString() is there to create a textual representation of the value behind the type.

I agree, but that value is "a vector", rather than just "three numbers", so that should be indicated in some way. I guess you're right, having the type as a prefix might be in the way when you don't need it, and it's easier to add to the string in post than to remove it. But I'd say at least parentheses should be included. "(1, 2, 3)" or similar is also how you'd commonly write them in math.

woollybah commented 5 years ago

I've implemented some of the above.

@ SIMD I don't see much mileage in applying anything to the code as it currently stands. However, if we were at some point to introduce methods that process arrays of points then yes, I could see it might be useful. Otherwise, for a single matrix, for example, I doubt there's a significant efficiency to be found by implementing it using intrinsics.

Of course, if someone were to prove otherwise... :-)

GWRon commented 5 years ago

Won't gcc optimize stuff for us anyways?

HurryStarfish commented 5 years ago

I've added checkboxes to the items in the list to show which ones have been implemented.

An comment to 1.: Since there's SVec2F and SVec2I for Float and Int vectors now, I'd name the Double version SVec2D to match them. It makes the naming scheme more consistent and leaves open the possibility of adding something like Struct SVec<T> Where T Extends INumber in the future.

woollybah commented 5 years ago

I'm also working on some other related things - so far I have SBoundingBox - but I expect to have others. Any recommendations as to where to put these?

GWRon commented 5 years ago

If there were multiple levels for modules you could sort stuff better.

If it is auxiliary stuff then maybe use a new module-parent: math.mod/boundingbox.mod -> import math.boundingbox

woollybah commented 5 years ago

Indeed... I may as well move them all to math.mod then.

GWRon commented 5 years ago

The main module name is only used for categorization ..and to somehow define what is auto-imported if you do not use the framework command.

People who learn the language or do not want to remember where stuff was "sorted in" just want to do

Local v:TVec2i = new TVec2i

So if this is an often used type it should be in the list of auto-imported modules (like BRL for now).

This all would be not that important if the IDE would give the dev a hint..that a planned-to-use type is not known yet but defined in the following modules: Brl.vectors MyMathModules.vectors ...right click contains "add import statement".

Maybe an intermediary step is to add simple lookup support/cache to BMK. If a type name is not known during a compilation try , then BMK scans the module folders, creates a list of types...and puts a suggestion next to the error message. Yes it is not the task of BMK so maybe use it to write a little tool doing this (offload task) and BMK just asks the tool for a list of candidates to a given type name.

woollybah commented 5 years ago

I think I may move the new modules into their own namespace... I'd rather do it before the next release. If they are in their own namespace, it makes it easier to add new related functionality without adding lots more stuff to brl. math seems like a reasonable namespace identifier. This would also become part of the release, and could also become a default module.

HurryStarfish commented 5 years ago

BRL is indeed starting to become bloated as more and more stuff is added to it. But on the other hand it also feels weird to have something like Math on the same level as BRL and Pub. Seeing how those "main categories" normally represent the module author (or at the very least huge projects encompassing many smaller modules like wx)... A "cleaner" solution might be to allow for deeper nested namespaces as module names: BRL.Math.Vector, BRL.Math.Matrix, and so on. This would allow for deeper structure and finer separation, which would be useful for other new modules too (BRL.Collections.LinkedList etc). If somebody wants to bulk-import all modules below a certain namespace, there could be a syntax for that (Import BRL.Math.* perhaps). Not sure how much effort it would take to implement this, though.

GWRon commented 5 years ago

I think (and already proposed) a multi-level namespace would suit better when stuff has to belong to "default runtime modules" - of course it can create hassle if you add stuff to brl.math.XYZ which is not needed as default - so you add it to supplementary.math.XYZ which isn't that clean either.

Also we should not forget that all this "auto import/default modules" is only needed as the IDEs are not of help here. in Java the bigger IDEs tell you what to import and a right click later the import statement was added.

@ BMK and efforts Brl.MaxUtil offers some functions regardings modules. ModulePath() does replace "brl.math.vector"-path to something like "brl.mod/math.mod" and the ModuleIdent() only takes care of the last part: so ident is "vector". It looks as if BMK could handle all the stuff already. It's BCC which would need some love and attention.

woollybah commented 5 years ago

Well, I don't see a re-engineering of module hierarchy being done in the foreseeable future.

GWRon commented 5 years ago

You might have a look at the other issue I opened for thes regards.

Am sure it needs tackling some more stuff (mangled name clashes or so).

HurryStarfish commented 5 years ago

Well, I don't see a re-engineering of module hierarchy being done in the foreseeable future.

Ah, just to clarify, I'm not trying to suggest rearranging and of the existing, old modules. Just that the new, still-work-in-progress modules (such as Geometry and Collections) and future additions would benefit from being allowed to have nested namespaces.