liberscribble/src/scbutil.c File Reference

#include "scbutil.h"
#include <math.h>
#include <glib.h>
#include <scblog.h>

Go to the source code of this file.

Functions

int CCW (const ScbPointPtr p0, const ScbPointPtr p1, const ScbPointPtr p2)
gboolean Intersect (const ScbPointPtr p1, const ScbPointPtr p2, const ScbPointPtr p3, const ScbPointPtr p4)
gboolean scb_is_rect_intersect (const ScbRectPtr r1, const ScbRectPtr r2)
gboolean scb_is_lines_intersect (const ScbPointPtr p1, const ScbPointPtr p2, const ScbPointPtr p3, const ScbPointPtr p4)


Function Documentation

int CCW ( const ScbPointPtr  p0,
const ScbPointPtr  p1,
const ScbPointPtr  p2 
)

Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.

Definition at line 42 of file scbutil.c.

00043 {
00044     long dx1, dx2 ;
00045     long dy1, dy2 ;
00046 
00047     dx1 = p1->x - p0->x ; dx2 = p2->x - p0->x ;
00048     dy1 = p1->y - p0->y ; dy2 = p2->y - p0->y ;
00049 
00050     /* This is basically a slope comparison: we don't do divisions because
00051 
00052     * of divide by zero possibilities with pure horizontal and pure
00053     * vertical lines.
00054     */ 
00055     return ((dx1 * dy2 > dy1 * dx2) ? 1 : -1) ;
00056 }

gboolean Intersect ( const ScbPointPtr  p1,
const ScbPointPtr  p2,
const ScbPointPtr  p3,
const ScbPointPtr  p4 
)

Definition at line 68 of file scbutil.c.

00069 {
00070     return ((( CCW(p1, p2, p3) * CCW(p1, p2, p4)) <= 0)
00071         && (( CCW(p3, p4, p1) * CCW(p3, p4, p2)  <= 0) )) ;
00072 }

Here is the call graph for this function:

gboolean scb_is_lines_intersect ( const ScbPointPtr  p1,
const ScbPointPtr  p2,
const ScbPointPtr  p3,
const ScbPointPtr  p4 
)

Definition at line 89 of file scbutil.c.

00093 {
00094     gboolean bRet = ((( CCW(p1, p2, p3) * CCW(p1, p2, p4)) <= 0)
00095         && (( CCW(p3, p4, p1) * CCW(p3, p4, p2)  <= 0) )) ;
00096 
00097    
00098     return bRet;
00099 }

Here is the call graph for this function:

gboolean scb_is_rect_intersect ( const ScbRectPtr  rect1,
const ScbRectPtr  rect2 
)

Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.

Definition at line 78 of file scbutil.c.

00080 {
00081     return ! ( r2->left > r1->right 
00082         || r2->right < r1->left 
00083         || r2->top > r1->bottom 
00084         || r2->bottom < r1->top 
00085         );
00086 }


Generated on Sun Dec 14 17:15:12 2008 by  doxygen 1.5.6