KiCad PCB EDA Suite
ray.cpp File Reference
#include "ray.h"
#include "../../3d_fastmath.h"
#include <stdio.h>
#include <wx/debug.h>
#include <cmath>

Go to the source code of this file.

Functions

bool IntersectSegment (const SFVEC2F &aStartA, const SFVEC2F &aEnd_minus_startA, const SFVEC2F &aStartB, const SFVEC2F &aEnd_minus_startB)
 

Function Documentation

bool IntersectSegment ( const SFVEC2F aStartA,
const SFVEC2F aEnd_minus_startA,
const SFVEC2F aStartB,
const SFVEC2F aEnd_minus_startB 
)

Definition at line 183 of file ray.cpp.

References abs.

Referenced by RAYSEG2D::at(), and CROUNDSEGMENT2D::Intersects().

185 {
186  float rxs = aEnd_minus_startA.x *
187  aEnd_minus_startB.y - aEnd_minus_startA.y *
188  aEnd_minus_startB.x;
189 
190  if( std::abs( rxs ) > glm::epsilon<float>() )
191  {
192  float inv_rxs = 1.0f / rxs;
193 
194  SFVEC2F pq = aStartB - aStartA;
195 
196  float t = (pq.x * aEnd_minus_startB.y - pq.y * aEnd_minus_startB.x) * inv_rxs;
197 
198  if( (t < 0.0f) || (t > 1.0f) )
199  return false;
200 
201  float u = (pq.x * aEnd_minus_startA.y - pq.y * aEnd_minus_startA.x) * inv_rxs;
202 
203  if( (u < 0.0f) || (u > 1.0f) )
204  return false;
205 
206  return true;
207  }
208 
209  return false;
210 }
#define abs(a)
Definition: auxiliary.h:84
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45