KiCad PCB EDA Suite
ray.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2017 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #ifndef _RAY_H_
31 #define _RAY_H_
32 
34 
35 
37 {
38  MMM, MMP, MPM, MPP, PMM, PMP, PPM, PPP, POO, MOO, OPO, OMO, OOP, OOM, OMM,
40 };
41 
42 
43 struct RAY
44 {
46  unsigned int rayID;
47 
50 
52 
53  float ibyj, jbyi, kbyj, jbyk, ibyk, kbyi; // slope
54  float c_xy, c_xz, c_yx, c_yz, c_zx, c_zy;
55 
56  unsigned int m_dirIsNeg[3];
57 
58  void Init( const SFVEC3F& o, const SFVEC3F& d );
59 
60  bool IntersectSphere( const SFVEC3F &aCenter,
61  float aRadius,
62  float &aOutT0,
63  float &aOutT1 ) const;
64 
65  SFVEC3F at( float t ) const { return m_Origin + m_Dir * t; }
66 
67  SFVEC2F at2D( float t ) const {
68  return SFVEC2F( m_Origin.x + m_Dir.x * t, m_Origin.y + m_Dir.y * t ); }
69 
70  void debug() const;
71 };
72 
73 
74 struct RAY2D
75 {
79 
80  RAY2D( const SFVEC2F& o, const SFVEC2F& d ) { m_Origin = o; m_Dir = d; m_InvDir = (1.0f / d); }
81 
82  SFVEC2F at( float t ) const { return m_Origin + m_Dir * t; }
83 };
84 
85 
86 struct RAYSEG2D
87 {
93  float m_Length;
95 
96  RAYSEG2D( const SFVEC2F& s, const SFVEC2F& e );
97 
98  bool IntersectSegment( const SFVEC2F &aStart,
99  const SFVEC2F &aEnd_minus_start,
100  float *aOutT ) const;
101 
102  bool IntersectCircle( const SFVEC2F &aCenter,
103  float aRadius,
104  float *aOutT0,
105  float *aOutT1,
106  SFVEC2F *aOutNormalT0,
107  SFVEC2F *aOutNormalT1 ) const;
108 
109  float DistanceToPointSquared( const SFVEC2F &aPoint ) const;
110 
115  SFVEC2F atNormalized( float t ) const { return m_Start + m_End_minus_start * t; }
116 
117  SFVEC2F at( float t ) const { return m_Start + m_Dir * t; }
118 };
119 
120 
121 bool IntersectSegment( const SFVEC2F &aStartA, const SFVEC2F &aEnd_minus_startA,
122  const SFVEC2F &aStartB, const SFVEC2F &aEnd_minus_startB );
123 
124 #if(GLM_ARCH != GLM_ARCH_PURE)
125 /*
126 struct RAY4
127 {
128  glm::simdVec4 m_orgX; ///< x coordinate of ray origin
129  glm::simdVec4 m_orgy; ///< y coordinate of ray origin
130  glm::simdVec4 m_orgz; ///< z coordinate of ray origin
131 
132  glm::simdVec4 m_dirX; ///< x direction of ray
133  glm::simdVec4 m_diry; ///< y direction of ray
134  glm::simdVec4 m_dirz; ///< z direction of ray
135 
136  glm::simdVec4 m_tnear; ///< Start of ray segment
137  glm::simdVec4 m_tfar; ///< End of ray segment
138 };*/
139 
140 #endif
141 
142 
143 #endif // _RAY_H_
Definition: ray.h:38
Definition: ray.h:38
Definition: ray.h:38
RAY2D(const SFVEC2F &o, const SFVEC2F &d)
Definition: ray.h:80
float c_xy
Definition: ray.h:54
Definition: ray.h:39
Definition: ray.h:38
void Init(const SFVEC3F &o, const SFVEC3F &d)
Definition: ray.cpp:38
bool IntersectSegment(const SFVEC2F &aStartA, const SFVEC2F &aEnd_minus_startA, const SFVEC2F &aStartB, const SFVEC2F &aEnd_minus_startB)
Definition: ray.cpp:181
float DistanceToPointSquared(const SFVEC2F &aPoint) const
Definition: ray.cpp:323
Definition: ray.h:38
Definition: ray.h:39
SFVEC3F at(float t) const
Definition: ray.h:65
Definition: ray.h:39
float c_zy
Definition: ray.h:54
SFVEC2F m_Dir
Definition: ray.h:91
Definition: ray.h:43
SFVEC2F at(float t) const
Definition: ray.h:82
SFVEC2F at(float t) const
Definition: ray.h:117
Definition: ray.h:39
float jbyk
Definition: ray.h:53
RAY_CLASSIFICATION
Definition: ray.h:36
void debug() const
Definition: ray.cpp:396
Definition: ray.h:39
float kbyi
Definition: ray.h:53
float c_yx
Definition: ray.h:54
SFVEC2F m_Dir
Definition: ray.h:77
Definition: ray.h:38
Definition: ray.h:38
SFVEC3F m_InvDir
Definition: ray.h:51
bool IntersectSphere(const SFVEC3F &aCenter, float aRadius, float &aOutT0, float &aOutT1) const
Definition: ray.cpp:212
Definition: ray.h:39
Definition: ray.h:38
Definition: ray.h:39
float kbyj
Definition: ray.h:53
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
Definition: ray.h:38
Definition: ray.h:39
RAY_CLASSIFICATION m_Classification
Definition: ray.h:49
unsigned int m_dirIsNeg[3]
Definition: ray.h:56
float m_DOT_End_minus_start
dot( m_End_minus_start, m_End_minus_start)
Definition: ray.h:94
float m_Length
Definition: ray.h:93
SFVEC2F at2D(float t) const
Definition: ray.h:67
Definition: ray.h:38
SFVEC2F m_End
Definition: ray.h:89
unsigned int rayID
unique ray ID - not used - dummy
Definition: ray.h:46
SFVEC2F m_InvDir
Definition: ray.h:92
Definition: ray.h:39
SFVEC2F atNormalized(float t) const
Function atNormalized - returns the position at t t - value 0.0 ...
Definition: ray.h:115
SFVEC3F m_Dir
Definition: ray.h:48
Definition: ray.h:39
float ibyj
Definition: ray.h:53
float jbyi
Definition: ray.h:53
float c_yz
Definition: ray.h:54
SFVEC3F m_Origin
Definition: ray.h:45
SFVEC2F m_Start
Definition: ray.h:88
Definition: ray.h:38
Definition: ray.h:38
float c_zx
Definition: ray.h:54
Definition: ray.h:38
Definition: ray.h:38
Definition: ray.h:74
RAYSEG2D(const SFVEC2F &s, const SFVEC2F &e)
Definition: ray.cpp:270
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
SFVEC2F m_InvDir
Definition: ray.h:78
float c_xz
Definition: ray.h:54
Definition: ray.h:39
Definition: ray.h:38
bool IntersectCircle(const SFVEC2F &aCenter, float aRadius, float *aOutT0, float *aOutT1, SFVEC2F *aOutNormalT0, SFVEC2F *aOutNormalT1) const
Definition: ray.cpp:346
bool IntersectSegment(const SFVEC2F &aStart, const SFVEC2F &aEnd_minus_start, float *aOutT) const
Definition: ray.cpp:289
SFVEC2F m_Origin
Definition: ray.h:76
SFVEC2F m_End_minus_start
Definition: ray.h:90
float ibyk
Definition: ray.h:53
Definition: ray.h:86