KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
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 "filled_circle_2d.h"
35#include <plugins/3dapi/xv3d_types.h> // SFVEC2F
36
37class BOARD_ITEM;
38
40{
41public:
42 ROUND_SEGMENT_2D( const SFVEC2F& aStart, const SFVEC2F& aEnd, float aWidth,
43 const BOARD_ITEM& aBoardItem );
44
45 float GetRadius() const { return m_radius; }
46 float GetRadiusSquared() const { return m_radius_squared; }
47 float GetWidth() const { return m_width; }
48 float GetLength() const { return m_segment.m_Length; }
49
50 const SFVEC2F& GetStart() const { return m_segment.m_Start; }
51 const SFVEC2F& GetEnd() const { return m_segment.m_End; }
53
54 const SFVEC2F& GetLeftStar() const { return m_leftStart; }
55 const SFVEC2F& GetLeftEnd() const { return m_leftEnd; }
57 const SFVEC2F& GetLeftDir() const { return m_leftDir; }
58
59 const SFVEC2F& GetRightStar() const { return m_rightStart; }
60 const SFVEC2F& GetRightEnd() const { return m_rightEnd; }
62 const SFVEC2F& GetRightDir() const { return m_rightDir; }
63
64 bool Overlaps( const BBOX_2D& aBBox ) const override;
65 bool Intersects( const BBOX_2D& aBBox ) const override;
66 bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
67 INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
68 bool IsPointInside( const SFVEC2F& aPoint ) const override;
69
70private:
71 friend class ROUND_SEGMENT;
72
74
79
84
85 float m_radius;
87 float m_width;
88};
89
90static const float s_min_dot = ( FLT_EPSILON * 4.0f * FLT_EPSILON * 4.0f );
91
99inline bool Is_segment_a_circle( const SFVEC2F& aStart, const SFVEC2F& aEnd )
100{
101 const SFVEC2F vec = aEnd - aStart;
102
103 // This is the same as calc the length squared (without the sqrt)
104 // and compare with a small value.
105 return (aStart == aEnd) || ( glm::dot( vec, vec ) <= s_min_dot );
106}
107
108#endif // _ROUND_SEGMENT_2D_H_
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
bool IsPointInside(const SFVEC2F &aPoint) const override
const SFVEC2F & GetLeftEnd() const
const SFVEC2F & GetRightEnd() const
const SFVEC2F & GetLeftStar() const
const SFVEC2F & GetLeftDir() const
const SFVEC2F & GetEnd() const
float GetRadius() const
bool Overlaps(const BBOX_2D &aBBox) const override
Test if the box overlaps the object.
bool Intersect(const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const override
const SFVEC2F & GetLeftEnd_minus_Start() const
float GetWidth() const
float GetLength() const
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 & GetRightEnd_minus_Start() const
float GetRadiusSquared() const
bool Intersects(const BBOX_2D &aBBox) const override
a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅)
const SFVEC2F & GetStart() const
const SFVEC2F & GetRightDir() const
SFVEC2F m_rightEndMinusStart
const SFVEC2F & GetRightStar() const
SFVEC2F m_leftEndMinusStart
const SFVEC2F & GetEnd_minus_Start() const
INTERSECTION_RESULT
Definition: object_2d.h:37
static const float s_min_dot
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:42
Definition: ray.h:106
float m_Length
Definition: ray.h:112
SFVEC2F m_End_minus_start
Definition: ray.h:109
SFVEC2F m_Start
Definition: ray.h:107
SFVEC2F m_End
Definition: ray.h:108
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42