I am looking for a data structure representing axis aligned cuboids
Something like System.Drawing.Rectangle, but in 3d, e.g.
struct AACuboid
{
int posX, posY, posZ;
int width, length, height;
}
with the standard operations like c1.Contains(c2), c1.Intersects(c2), c1.Rotate(axis,0/90/180)…
and the basic operations like equality, iComparable, hashCode…
Such a data type is easy enough to write, the problem I am worried about is writing it fast, since I’ll be doing a lot of cube intersections and comparisons per second.
Rather than reinventing the wheel ,and probably forgetting some basic optimisation step, is there a freely available class I could use?
Even better if this also includes some sort of R-Tree or similar structure to speed up intersections, although that is optional at this point.
Otherwise, what would be the basic optimisation steps I should not forget?
(i.e. struct or class? x,y,z internally represented as individual class members or single array or struct?)
So far the best match for what I seek seems to be
Microsoft.Xna.Framework.BoundingBox, the study of which has proven to be both enlightening and confusing.
it is a struct:
With Vector3 being another struct:
So I suppose structs containing floats are a good design choice for this kind of data, even thought they get rather large (24 bytes, double the officially recommended maximum for structs)
The main thing that confuses me for now is that these structs are mutable, and the implemented methods make use of that mutability a lot. I would have thought these sorts of types would be immutable or at least have no public non-readonly variables.
But I guess Microsoft knows what they are doing.
Right now I am unsure whether I should include the whole xna framework just for these types, or simply model my own types after them.
I am however open for other suggestions.