|go ahead... be a heretic|
dokkeldepper's scratchpadby dokkeldepper (Friar)
|on Dec 07, 2005 at 13:35 UTC||Need Help??|
Adding Regression diagnostics and more tests to Statistics::OLS
Writing Inverters for Math::Business::BlackScholes
Writing Module for better Order statistics and Tests (say Statistics::Ranking )
Writing Module for Fisher LDA (say Statistics::FisherLDA)
Doing Statistics and Data Mining with perl...
Currently rethougt: my age old pluggable-perl-dataminer sketch (pSteiger)
Parsing SPSS Syntax in Perl
Parsing SAS Macros in Perl
Work in progress
An overloaded, planar geometry meditation on points and locations
In the beginning...
Currently, I played around to make an interactive, programmable display for higher dimensional datasets. Doing this, I stumbled over an elementary problem generating a usable class hierarchy for points/locations in high(>1)-dimensional spaces: How can I compare the location of two or more different points? How can I overload the ususal comparison operators correctly? Moreover, how can I find out if a point is situated between (whatever this means) two other points? Although there is a bunch of computational geometry literature around, these simple questions are not discussed. And even if this topic is covered, nothing is said on a sensible OO-implementation. Consquently, I started My Own Thing. To make things easy I begun with the plane, i.e. 2 dimensions.
... a new Location
A location (point) on the plain consists of a pair (X,Y) of coordinates. Because I deal with raster images only integers are uses. Thats why I decided to implement a location a a two-dimensional array.
Selfish as I am I use some constructs that are ... hmmm ... not really recomended. See the $AUTOLOAD thing for example.
For the ease of use I need some sensible defaults. Thse are implemented as class data.
And now the constructor...
... then the getters ...
... and setters.
The basic things are done. Did you do some testing? Yes? Fine, we can continue then. Let's start to mangle all the points a bit.
Dealing with points basically comes down to the question: How are the points situated with respect to each other? If we have two points we might want ot know if they are identical, if they are different and if so, where we have to go from one point to the other.
Lets behave like an idiot and start coding before thinking. Of course, nobody really works like this, do we?
Because we have a class whith possibly comparable objects we can use the overload module.
To do this we have to change the modules header:
Now we have to write a sub handles the comparison. In other words, we need an overload handler.
By the way, have your read this carefully? I wrote "sub" not "method". Remember, that in a method the first parameter ($_) is the class (=package) name. Remember this!
The sub compare is an overload handler which is called with three arguments. The first two are the locations to compare, the third indicates if the order of the arguments was swapped for technical reasons. If this was the case something incomparable was tried, we croak then.
To make the spaceship (<=>) work here the handler has to return the values -1 if the left location is smaller than the right one, 0 if they are equal and 1 if the left operand ist larger than the right operator.Now we try this: