KiCad PCB EDA Suite
croundsegment2d.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-2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 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 _CROUNDSEGMENT2D_H_
31 #define _CROUNDSEGMENT2D_H_
32 
33 #include "cobject2d.h"
34 
35 class CROUNDSEGMENT2D : public COBJECT2D
36 {
37 
38 friend class CROUNDSEG;
39 
40 private:
42 
47 
52 
53  float m_radius;
55  float m_width;
56 
57 public:
58  CROUNDSEGMENT2D( const SFVEC2F &aStart, const SFVEC2F &aEnd, float aWidth,
59  const BOARD_ITEM &aBoardItem );
60 
61  float GetRadius() const { return m_radius; }
62  float GetRadiusSquared() const { return m_radius_squared; }
63  float GetWidth() const { return m_width; }
64  float GetLength() const { return m_segment.m_Length; }
65 
66  const SFVEC2F &GetStart() const { return m_segment.m_Start; }
67  const SFVEC2F &GetEnd() const { return m_segment.m_End; }
68  const SFVEC2F &GetEnd_minus_Start() const { return m_segment.m_End_minus_start; }
69 
70  const SFVEC2F &GetLeftStar() const { return m_leftStart; }
71  const SFVEC2F &GetLeftEnd() const { return m_leftEnd; }
73  const SFVEC2F &GetLeftDir() const { return m_leftDir; }
74 
75  const SFVEC2F &GetRightStar() const { return m_rightStart; }
76  const SFVEC2F &GetRightEnd() const { return m_rightEnd; }
78  const SFVEC2F &GetRightDir() const { return m_rightDir; }
79 
80  // Imported from COBJECT2D
81  bool Overlaps( const CBBOX2D &aBBox ) const override;
82  bool Intersects( const CBBOX2D &aBBox ) const override;
83  bool Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const override;
84  INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const override;
85  bool IsPointInside( const SFVEC2F &aPoint ) const override;
86 };
87 
88 static const float s_min_dot = (FLT_EPSILON * 4.0f) ;
89 
97 inline bool Is_segment_a_circle( const SFVEC2F &aStart, const SFVEC2F &aEnd )
98 {
99  const SFVEC2F vec = aEnd - aStart;
100 
101  return (aStart == aEnd) ||
102  // This is the same as calc the lenght squared (without the sqrt)
103  // and compare with a small value
104  ( glm::dot( vec, vec ) <= s_min_dot );
105 }
106 
107 #endif // _CROUNDSEGMENT2D_H_
SFVEC2F m_rightEndMinusStart
INTERSECTION_RESULT
Definition: cobject2d.h:38
bool Intersect(const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const override
Function Intersect.
const SFVEC2F & GetRightEnd() const
bool Intersects(const CBBOX2D &aBBox) const override
Function Intersects.
const SFVEC2F & GetStart() const
float GetRadiusSquared() const
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
float GetWidth() const
Class CBBOX manages a bounding box defined by two SFVEC2F min max points.
Definition: cbbox2d.h:40
static const float s_min_dot
const SFVEC2F & GetLeftEnd_minus_Start() const
float GetLength() const
bool Overlaps(const CBBOX2D &aBBox) const override
Function Overlaps.
bool Is_segment_a_circle(const SFVEC2F &aStart, const SFVEC2F &aEnd)
Segment_is_a_circle - check if segment start and end is very close to each other should used to check...
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
float GetRadius() const
const SFVEC2F & GetRightEnd_minus_Start() const
const SFVEC2F & GetEnd() const
float m_Length
Definition: ray.h:93
const SFVEC2F & GetLeftEnd() const
const SFVEC2F & GetRightStar() const
SFVEC2F m_End
Definition: ray.h:89
CROUNDSEGMENT2D(const SFVEC2F &aStart, const SFVEC2F &aEnd, float aWidth, const BOARD_ITEM &aBoardItem)
SFVEC2F m_leftEndMinusStart
const SFVEC2F & GetEnd_minus_Start() const
const SFVEC2F & GetLeftStar() const
SFVEC2F m_Start
Definition: ray.h:88
const SFVEC2F & GetRightDir() const
INTERSECTION_RESULT IsBBoxInside(const CBBOX2D &aBBox) const override
Function IsBBoxInside.
const SFVEC2F & GetLeftDir() const
bool IsPointInside(const SFVEC2F &aPoint) const override
SFVEC2F m_End_minus_start
Definition: ray.h:90
Definition: ray.h:86