KiCad PCB EDA Suite
ray.h File Reference

Go to the source code of this file.

Classes

struct  RAY
 
struct  RAY2D
 
struct  RAYSEG2D
 

Enumerations

enum  RAY_CLASSIFICATION {
  RAY_CLASSIFICATION::MMM, RAY_CLASSIFICATION::MMP, RAY_CLASSIFICATION::MPM, RAY_CLASSIFICATION::MPP,
  RAY_CLASSIFICATION::PMM, RAY_CLASSIFICATION::PMP, RAY_CLASSIFICATION::PPM, RAY_CLASSIFICATION::PPP,
  RAY_CLASSIFICATION::POO, RAY_CLASSIFICATION::MOO, RAY_CLASSIFICATION::OPO, RAY_CLASSIFICATION::OMO,
  RAY_CLASSIFICATION::OOP, RAY_CLASSIFICATION::OOM, RAY_CLASSIFICATION::OMM, RAY_CLASSIFICATION::OMP,
  RAY_CLASSIFICATION::OPM, RAY_CLASSIFICATION::OPP, RAY_CLASSIFICATION::MOM, RAY_CLASSIFICATION::MOP,
  RAY_CLASSIFICATION::POM, RAY_CLASSIFICATION::POP, RAY_CLASSIFICATION::MMO, RAY_CLASSIFICATION::MPO,
  RAY_CLASSIFICATION::PMO, RAY_CLASSIFICATION::PPO
}
 

Functions

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

Enumeration Type Documentation

◆ RAY_CLASSIFICATION

Function Documentation

◆ IntersectSegment()

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

Definition at line 186 of file ray.cpp.

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

Referenced by CROUNDSEGMENT2D::Intersects().