KiCad PCB EDA Suite
round_segment_2d.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-2020 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 
29 #ifndef _ROUND_SEGMENT_2D_H_
30 #define _ROUND_SEGMENT_2D_H_
31 
32 #include "object_2d.h"
33 #include "../ray.h"
34 #include <plugins/3dapi/xv3d_types.h> // SFVEC2F
35 
36 class BOARD_ITEM;
37 
39 {
40 public:
41  ROUND_SEGMENT_2D( const SFVEC2F& aStart, const SFVEC2F& aEnd, float aWidth,
42  const BOARD_ITEM& aBoardItem );
43 
44  float GetRadius() const { return m_radius; }
45  float GetRadiusSquared() const { return m_radius_squared; }
46  float GetWidth() const { return m_width; }
47  float GetLength() const { return m_segment.m_Length; }
48 
49  const SFVEC2F& GetStart() const { return m_segment.m_Start; }
50  const SFVEC2F& GetEnd() const { return m_segment.m_End; }
52 
53  const SFVEC2F& GetLeftStar() const { return m_leftStart; }
54  const SFVEC2F& GetLeftEnd() const { return m_leftEnd; }
56  const SFVEC2F& GetLeftDir() const { return m_leftDir; }
57 
58  const SFVEC2F& GetRightStar() const { return m_rightStart; }
59  const SFVEC2F& GetRightEnd() const { return m_rightEnd; }
61  const SFVEC2F& GetRightDir() const { return m_rightDir; }
62 
63  bool Overlaps( const BBOX_2D& aBBox ) const override;
64  bool Intersects( const BBOX_2D& aBBox ) const override;
65  bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
66  INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
67  bool IsPointInside( const SFVEC2F& aPoint ) const override;
68 
69 private:
70  friend class ROUND_SEGMENT;
71 
73 
78 
83 
84  float m_radius;
86  float m_width;
87 };
88 
89 static const float s_min_dot = ( FLT_EPSILON * 4.0f * FLT_EPSILON * 4.0f );
90 
98 inline bool Is_segment_a_circle( const SFVEC2F& aStart, const SFVEC2F& aEnd )
99 {
100  const SFVEC2F vec = aEnd - aStart;
101 
102  // This is the same as calc the length squared (without the sqrt)
103  // and compare with a small value.
104  return (aStart == aEnd) || ( glm::dot( vec, vec ) <= s_min_dot );
105 }
106 
107 #endif // _ROUND_SEGMENT_2D_H_
float GetRadiusSquared() const
bool Intersects(const BBOX_2D &aBBox) const override
a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
float GetRadius() const
SFVEC2F m_rightEndMinusStart
bool Overlaps(const BBOX_2D &aBBox) const override
Test if the box overlaps the object.
INTERSECTION_RESULT IsBBoxInside(const BBOX_2D &aBBox) const override
Test this object if it's completely outside, intersects, or is completely inside aBBox.
const SFVEC2F & GetLeftEnd_minus_Start() const
bool IsPointInside(const SFVEC2F &aPoint) const override
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
INTERSECTION_RESULT
Definition: object_2d.h:36
const SFVEC2F & GetLeftEnd() const
const SFVEC2F & GetEnd() const
const SFVEC2F & GetLeftStar() const
float m_Length
Definition: ray.h:117
const SFVEC2F & GetRightDir() const
SFVEC2F m_End
Definition: ray.h:113
bool Is_segment_a_circle(const SFVEC2F &aStart, const SFVEC2F &aEnd)
Check if segment start and end is very close to each other.
Manage a bounding box defined by two SFVEC2F min max points.
Definition: bbox_2d.h:41
float GetLength() const
SFVEC2F m_leftEndMinusStart
SFVEC2F m_Start
Definition: ray.h:112
const SFVEC2F & GetRightEnd_minus_Start() const
ROUND_SEGMENT_2D(const SFVEC2F &aStart, const SFVEC2F &aEnd, float aWidth, const BOARD_ITEM &aBoardItem)
static const float s_min_dot
bool Intersect(const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const override
const SFVEC2F & GetLeftDir() const
const SFVEC2F & GetRightEnd() const
const SFVEC2F & GetEnd_minus_Start() const
const SFVEC2F & GetStart() const
SFVEC2F m_End_minus_start
Definition: ray.h:114
float GetWidth() const
const SFVEC2F & GetRightStar() const
Definition: ray.h:110