kicad/eeschema/dangling_ends.cpp

34 lines
1.1 KiB
C++
Raw Normal View History

/*********************/
/* dangling_ends.cpp */
/*********************/
#include "fctsys.h"
#include "gr_basic.h"
#include "sch_item_struct.h"
#include "wxEeschemaStruct.h"
#include "class_sch_screen.h"
#include "general.h"
#include "protos.h"
#include "class_libentry.h"
#include "lib_pin.h"
#include "sch_component.h"
2010-07-17 11:14:57 +00:00
/* Returns true if the point P is on the segment S. */
bool SegmentIntersect( wxPoint aSegStart, wxPoint aSegEnd, wxPoint aTestPoint )
{
wxPoint vectSeg = aSegEnd - aSegStart; // Vector from S1 to S2
2010-07-17 11:14:57 +00:00
wxPoint vectPoint = aTestPoint - aSegStart; // Vector from S1 to P
2008-04-22 16:38:23 +00:00
2010-07-17 11:14:57 +00:00
// Use long long here to avoid overflow in calculations
if( (long long) vectSeg.x * vectPoint.y - (long long) vectSeg.y * vectPoint.x )
2010-07-17 11:14:57 +00:00
return false; /* Cross product non-zero, vectors not parallel */
2008-04-22 16:38:23 +00:00
if( ( (long long) vectSeg.x * vectPoint.x + (long long) vectSeg.y * vectPoint.y ) <
( (long long) vectPoint.x * vectPoint.x + (long long) vectPoint.y * vectPoint.y ) )
2010-07-17 11:14:57 +00:00
return false; /* Point not on segment */
2008-04-22 16:38:23 +00:00
2010-07-17 11:14:57 +00:00
return true;
}