You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1021 B

  1. /**
  2. * @file dangling_ends.cpp
  3. */
  4. #include <fctsys.h>
  5. #include <gr_basic.h>
  6. #include <sch_item_struct.h>
  7. #include <wxEeschemaStruct.h>
  8. #include <general.h>
  9. #include <protos.h>
  10. #include <class_libentry.h>
  11. #include <lib_pin.h>
  12. #include <sch_component.h>
  13. /* Returns true if the point P is on the segment S. */
  14. bool SegmentIntersect( wxPoint aSegStart, wxPoint aSegEnd, wxPoint aTestPoint )
  15. {
  16. wxPoint vectSeg = aSegEnd - aSegStart; // Vector from S1 to S2
  17. wxPoint vectPoint = aTestPoint - aSegStart; // Vector from S1 to P
  18. // Use long long here to avoid overflow in calculations
  19. if( (long long) vectSeg.x * vectPoint.y - (long long) vectSeg.y * vectPoint.x )
  20. return false; /* Cross product non-zero, vectors not parallel */
  21. if( ( (long long) vectSeg.x * vectPoint.x + (long long) vectSeg.y * vectPoint.y ) <
  22. ( (long long) vectPoint.x * vectPoint.x + (long long) vectPoint.y * vectPoint.y ) )
  23. return false; /* Point not on segment */
  24. return true;
  25. }