2007-08-24 15:10:46 +00:00
|
|
|
/*********************/
|
|
|
|
/* dangling_ends.cpp */
|
|
|
|
/*********************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "sch_item_struct.h"
|
|
|
|
#include "wxEeschemaStruct.h"
|
2011-01-10 20:35:24 +00:00
|
|
|
#include "class_sch_screen.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2010-11-03 14:13:15 +00:00
|
|
|
#include "class_libentry.h"
|
2010-10-22 12:11:52 +00:00
|
|
|
#include "lib_pin.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_component.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-02-27 19:38:16 +00:00
|
|
|
|
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 )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
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
|
2010-09-05 17:01:48 +00:00
|
|
|
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
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
if( ( (long long) vectSeg.x * vectPoint.x + (long long) vectSeg.y * vectPoint.y ) <
|
2010-11-03 14:13:15 +00:00
|
|
|
( (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;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|