T
Twisted
I've got some math/geometry stuff going on here which has given me a
curious problem. I have some generic stuff, and now need a generic
ball, parametrized by P, which is supposed to be a class of geometric
point from some sort of space or another. Determining if a point lies
in the ball when the ball is centered on the origin will be simple: I
require P to implement an interface or extend a class that defines an
abstract modulus-squared method, and see if the modulus squared fails
to exceed the ball radius squared.
Determining the ball's number of dimensions has me stumped. This needs
to be done where there isn't a preexisting instance of P handy.
Obviously, P can't be guaranteed to implement a no-arguments
constructor that could be used to get a dummy instance. If P is
required to implement an *interface* named Point, I can't specify that
there be a static method getDimensions() or similar. If P is required
to extend an *abstract class* named Point, I can put such a static
method in Point, but not override it in a subclass. Same with a static
method to get a dummy instance.
Of course, I could just have a single concrete Point class built on an
array and a method to return its length, but this is less type-safe
(points of different dimensionalities could get mixed up). I could use
a Point class built on an array, declare it abstract, and only make
concrete subclasses that fix the number of dimensions. That would solve
it, but there's an added complication: complex numbers. Vector spaces
over both R and C may occur, and the dimension over R is twice the
plain dimension in the latter case...and what if I go and add
quaternions or some such later on? Ack! I figured a more open-ended
framework using interfaces as much as possible would be better, but
there seems to be no clean way to get the number of dimensions (over R,
or generally) in that case, short of praying you can use a construction
to turn P into a run-time classname and using a lookup table or
something equally ugly.
Any suggestions?
curious problem. I have some generic stuff, and now need a generic
ball, parametrized by P, which is supposed to be a class of geometric
point from some sort of space or another. Determining if a point lies
in the ball when the ball is centered on the origin will be simple: I
require P to implement an interface or extend a class that defines an
abstract modulus-squared method, and see if the modulus squared fails
to exceed the ball radius squared.
Determining the ball's number of dimensions has me stumped. This needs
to be done where there isn't a preexisting instance of P handy.
Obviously, P can't be guaranteed to implement a no-arguments
constructor that could be used to get a dummy instance. If P is
required to implement an *interface* named Point, I can't specify that
there be a static method getDimensions() or similar. If P is required
to extend an *abstract class* named Point, I can put such a static
method in Point, but not override it in a subclass. Same with a static
method to get a dummy instance.
Of course, I could just have a single concrete Point class built on an
array and a method to return its length, but this is less type-safe
(points of different dimensionalities could get mixed up). I could use
a Point class built on an array, declare it abstract, and only make
concrete subclasses that fix the number of dimensions. That would solve
it, but there's an added complication: complex numbers. Vector spaces
over both R and C may occur, and the dimension over R is twice the
plain dimension in the latter case...and what if I go and add
quaternions or some such later on? Ack! I figured a more open-ended
framework using interfaces as much as possible would be better, but
there seems to be no clean way to get the number of dimensions (over R,
or generally) in that case, short of praying you can use a construction
to turn P into a run-time classname and using a lookup table or
something equally ugly.
Any suggestions?