If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Unanswered: Pl Sql Data Type

I have worked on this Algorithm to implement it in PL SQL for line intersection.

I NEED TO CREATE A NEW DATA TYPE and...
I need to implement this LINE CROSSOVER ALGORITHM as a MEMBER FUNCTION of the NEW DATA TYPE.
I have made a basic idea of the code and whole like to get help or ideas on how i can go further? I have tried it as a procedure, but i need to work with is as a NEW DATA TYPE and MEMBER FUNCTION..

if ( (r3!=0) and (r4!=0) and (asign = bsign) ) then
return 'False';
-- /* Check signs of r3 and r4. If both point 3 and point 4 lie on
-- * same side of line 1, the line segments do not intersect.
-- */

2) Define a POINT data type with attributes x and y, and change the function to return a POINT value (null if no intersection) instead of the string 'True'. This would seem to fit in better with your OO design anyway.

To be honest, I don't really understand what you are doing here. You have declared a type called POINT_A, but what does it represent? Normally, points have about 2 attributes (e.g. x and y), but yours has about a dozen.

Maybe what you really wanted to create was a package, not a type?

I don't use types much myself, so I can't help with resolvng the specific issue - but it really doesn't look like you want a type anyway.

I don't think what you are doing makes sense. If you want a procedure that takes 8 values as parameters and returns the point of intersection why don't you just write one (a procedure) - why create a strange TYPE called POINT_A?

TYPEs are meant to represent (complex) data types that variables can be based on: simple (pre-defined) types are things like integer, varchar2; complex types could be things like POINT (a pair of x, y values), LINE (a pair of points).

Create or replace type Line as object
(start point, end point
member function Intersection( aPoint Point) return number --The member function is to go through the intersection algorithm and give
--the point where the 2 intersect. But how do i create the 2 lines?
);

How can i create the point for the line x1,x2 etc. And wil the member function Intersection work in the way i have created it?

It doesn't really make sense for Intersection to be a member of the Line type, because it doesn't return information about or act upon a line, it takes two lines as parameters and returns a point. It could be created as a stand-alone function (create or replace function intersect...) or as part of a package (create package geom_pkg as ...).

To "create a point" in PL/SQL you do this:

Code:

declare
p point := point(1,2);
...

Really, you don't need to be working with "create type" at all if you don't want to (this OO stuff is hard to get to grips with). You can just create a procedure that takes in 8 numbers (x1,y1,x2,y2,...) and outputs 2 (xc,yc).

Then you could give it a constructor function that took two LINE objects and figured out the intersection point, so you could code something like

v_linepair LINE_PAIR := NEW LINE_PAIR(v_someline, v_otherline);

and you would automagically have a LINE_PAIR object with an intersection attribute populated.

This is the whole strength of OO in PL/SQL - you define types that represent something meaningful and give them useful methods, thus breaking down the problem, and the whole thing makes some intuitive sense. I'm in favour of this approach.

Where it gets hard is when you create tables with OO attributes nested and subtyped in funky ways, thus giving yourself all kinds of headaches when you come to query/load/copy/update/delete the data or change the type definition, at which point you wish you'd created OO views of relational tables.