line2d bugs

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
DataCable
Posts: 5
Joined: Sat Jan 07, 2006 6:51 am

line2d bugs

Post by DataCable »

I seem to have stumbled across a few undefined functions in line2d.h.

intersectWith() calls both getInterSectionOfLines() and isPointBetweenPoints(), neither of which are defined elsewhere in line2d.h, nor anywhere else I can find. I searched the forum for these names and came up with a few posts which mentioning this problem, none of which seemed to have been answered.

Am I missing something?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

I also couldn't find isPointBetweenPoints or getInterSectionOfLines when I searched the forum.

new intersectWith function-

Code: Select all

        bool intersectWith(const line2d<T>& l, vector2d<T>& out)
        {
            bool found=false;

            f32 a1,a2,b1,b2;
            
            // calculate slopes, deal with infinity
            if (end.X-start.X == 0)
                b1 = (f32)1e+10;
            else
                b1 = (end.Y-start.Y)/(end.X-start.X);
            if (l.end.X-l.start.X == 0)
                b2 = (f32)1e+10;
            else
                b2 = (l.end.Y-l.start.Y)/(l.end.X-l.start.X);
 
            // calculate position
            a1 = start.Y   - b1 *  start.X;
            a2 = l.start.Y - b2 * l.start.X;
            out.X = - (a1-a2)/(b1-b2);
            out.Y = a1 + b1*out.X;

            // did the lines cross?
            if ( (start.X-out.X)  *(out.X-end.X)  >=0 && 
                 (l.start.X-out.X)*(out.X-l.end.X)>=0 && 
                 (start.Y-out.Y)  *(out.Y-end.Y)  >=0 && 
                 (l.start.Y-out.Y)*(out.Y-l.end.Y)>=0 )
            {
                found = true;
            }

            return (found);
        }
edit: mentioning the offending functions seemed to fix the search index. sweet

edit2: somehow this code is bugged in msvc, but works fine in gcc. :?
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Post Reply