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 <[email protected]>
5  * Copyright (C) 2015-2021 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 
25 #ifndef RAY_H
26 #define RAY_H
27 
29 
30 
32 {
33  MMM,
34  MMP,
35  MPM,
36  MPP,
37  PMM,
38  PMP,
39  PPM,
40  PPP,
41  POO,
42  MOO,
43  OPO,
44  OMO,
45  OOP,
46  OOM,
47  OMM,
48  OMP,
49  OPM,
50  OPP,
51  MOM,
52  MOP,
53  POM,
54  POP,
55  MMO,
56  MPO,
57  PMO,
58  PPO
59 };
60 
61 
62 struct RAY
63 {
65  unsigned int rayID;
66 
69 
71 
72  float ibyj, jbyi, kbyj, jbyk, ibyk, kbyi; // slope
73  float c_xy, c_xz, c_yx, c_yz, c_zx, c_zy;
74 
75  unsigned int m_dirIsNeg[3];
76 
77  void Init( const SFVEC3F& o, const SFVEC3F& d );
78 
79  bool IntersectSphere( const SFVEC3F &aCenter,
80  float aRadius,
81  float &aOutT0,
82  float &aOutT1 ) const;
83 
84  SFVEC3F at( float t ) const { return m_Origin + m_Dir * t; }
85 
86  SFVEC2F at2D( float t ) const
87  {
88  return SFVEC2F( m_Origin.x + m_Dir.x * t, m_Origin.y + m_Dir.y * t );
89  }
90 };
91 
92 
93 struct RAY2D
94 {
98 
99  RAY2D( const SFVEC2F& o, const SFVEC2F& d ) { m_Origin = o; m_Dir = d; m_InvDir = (1.0f / d); }
100 
101  SFVEC2F at( float t ) const { return m_Origin + m_Dir * t; }
102 };
103 
104 
105 struct RAYSEG2D
106 {
112  float m_Length;
114 
115  RAYSEG2D( const SFVEC2F& s, const SFVEC2F& e );
116 
117  bool IntersectSegment( const SFVEC2F &aStart,
118  const SFVEC2F &aEnd_minus_start,
119  float *aOutT ) const;
120 
121  bool IntersectCircle( const SFVEC2F &aCenter,
122  float aRadius,
123  float *aOutT0,
124  float *aOutT1,
125  SFVEC2F *aOutNormalT0,
126  SFVEC2F *aOutNormalT1 ) const;
127 
128  float DistanceToPointSquared( const SFVEC2F &aPoint ) const;
129 
135  SFVEC2F atNormalized( float t ) const { return m_Start + m_End_minus_start * t; }
136 
137  SFVEC2F at( float t ) const { return m_Start + m_Dir * t; }
138 };
139 
140 
141 bool IntersectSegment( const SFVEC2F &aStartA, const SFVEC2F &aEnd_minus_startA,
142  const SFVEC2F &aStartB, const SFVEC2F &aEnd_minus_startB );
143 
144 #if(GLM_ARCH != GLM_ARCH_PURE)
145 /*
146 struct RAY4
147 {
148  glm::simdVec4 m_orgX; ///< x coordinate of ray origin
149  glm::simdVec4 m_orgy; ///< y coordinate of ray origin
150  glm::simdVec4 m_orgz; ///< z coordinate of ray origin
151 
152  glm::simdVec4 m_dirX; ///< x direction of ray
153  glm::simdVec4 m_diry; ///< y direction of ray
154  glm::simdVec4 m_dirz; ///< z direction of ray
155 
156  glm::simdVec4 m_tnear; ///< Start of ray segment
157  glm::simdVec4 m_tfar; ///< End of ray segment
158 };*/
159 
160 #endif
161 
162 
163 #endif // RAY_H
SFVEC2F atNormalized(float t) const
Return the position at t.
Definition: ray.h:135
RAY2D(const SFVEC2F &o, const SFVEC2F &d)
Definition: ray.h:99
float c_xy
Definition: ray.h:73
void Init(const SFVEC3F &o, const SFVEC3F &d)
Definition: ray.cpp:35
bool IntersectSegment(const SFVEC2F &aStartA, const SFVEC2F &aEnd_minus_startA, const SFVEC2F &aStartB, const SFVEC2F &aEnd_minus_startB)
Definition: ray.cpp:181
bool IntersectSphere(const SFVEC3F &aCenter, float aRadius, float &aOutT0, float &aOutT1) const
Definition: ray.cpp:211
bool IntersectCircle(const SFVEC2F &aCenter, float aRadius, float *aOutT0, float *aOutT1, SFVEC2F *aOutNormalT0, SFVEC2F *aOutNormalT1) const
Definition: ray.cpp:319
float c_zy
Definition: ray.h:73
SFVEC2F m_Dir
Definition: ray.h:110
Definition: ray.h:62
float jbyk
Definition: ray.h:72
SFVEC3F at(float t) const
Definition: ray.h:84
RAY_CLASSIFICATION
Definition: ray.h:31
float kbyi
Definition: ray.h:72
float c_yx
Definition: ray.h:73
SFVEC2F m_Dir
Definition: ray.h:96
SFVEC2F at(float t) const
Definition: ray.h:137
SFVEC3F m_InvDir
Definition: ray.h:70
float kbyj
Definition: ray.h:72
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
RAY_CLASSIFICATION m_Classification
Definition: ray.h:68
bool IntersectSegment(const SFVEC2F &aStart, const SFVEC2F &aEnd_minus_start, float *aOutT) const
Definition: ray.cpp:262
unsigned int m_dirIsNeg[3]
Definition: ray.h:75
float m_DOT_End_minus_start
dot( m_End_minus_start, m_End_minus_start)
Definition: ray.h:113
float m_Length
Definition: ray.h:112
SFVEC2F m_End
Definition: ray.h:108
unsigned int rayID
unique ray ID - not used - dummy
Definition: ray.h:65
SFVEC2F m_InvDir
Definition: ray.h:111
SFVEC3F m_Dir
Definition: ray.h:67
float ibyj
Definition: ray.h:72
float jbyi
Definition: ray.h:72
float c_yz
Definition: ray.h:73
SFVEC3F m_Origin
Definition: ray.h:64
SFVEC2F m_Start
Definition: ray.h:107
float c_zx
Definition: ray.h:73
SFVEC2F at(float t) const
Definition: ray.h:101
Definition: ray.h:93
RAYSEG2D(const SFVEC2F &s, const SFVEC2F &e)
Definition: ray.cpp:243
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
float DistanceToPointSquared(const SFVEC2F &aPoint) const
Definition: ray.cpp:294
SFVEC2F m_InvDir
Definition: ray.h:97
float c_xz
Definition: ray.h:73
SFVEC2F m_Origin
Definition: ray.h:95
SFVEC2F m_End_minus_start
Definition: ray.h:109
float ibyk
Definition: ray.h:72
SFVEC2F at2D(float t) const
Definition: ray.h:86
Definition: ray.h:105