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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
24
25#ifndef _ROUND_SEGMENT_2D_H_
26#define _ROUND_SEGMENT_2D_H_
27
28#include "object_2d.h"
29#include "../ray.h"
30#include "filled_circle_2d.h"
31#include <plugins/3dapi/xv3d_types.h> // SFVEC2F
32
33class BOARD_ITEM;
34
36{
37public:
38 ROUND_SEGMENT_2D( const SFVEC2F& aStart, const SFVEC2F& aEnd, float aWidth,
39 const BOARD_ITEM& aBoardItem );
40
41 float GetRadius() const { return m_radius; }
42 float GetRadiusSquared() const { return m_radius_squared; }
43 float GetWidth() const { return m_width; }
44 float GetLength() const { return m_segment.m_Length; }
45
46 const SFVEC2F& GetStart() const { return m_segment.m_Start; }
47 const SFVEC2F& GetEnd() const { return m_segment.m_End; }
48 const SFVEC2F& GetEnd_minus_Start() const { return m_segment.m_End_minus_start; }
49
50 const SFVEC2F& GetLeftStar() const { return m_leftStart; }
51 const SFVEC2F& GetLeftEnd() const { return m_leftEnd; }
53 const SFVEC2F& GetLeftDir() const { return m_leftDir; }
54
55 const SFVEC2F& GetRightStar() const { return m_rightStart; }
56 const SFVEC2F& GetRightEnd() const { return m_rightEnd; }
58 const SFVEC2F& GetRightDir() const { return m_rightDir; }
59
60 bool Overlaps( const BBOX_2D& aBBox ) const override;
61 bool Intersects( const BBOX_2D& aBBox ) const override;
62 bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
63 INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
64 bool IsPointInside( const SFVEC2F& aPoint ) const override;
65
66private:
67 friend class ROUND_SEGMENT;
68
70
75
80
81 float m_radius;
83 float m_width;
84};
85
86static const float s_min_dot = ( FLT_EPSILON * 4.0f * FLT_EPSILON * 4.0f );
87
95inline bool Is_segment_a_circle( const SFVEC2F& aStart, const SFVEC2F& aEnd )
96{
97 const SFVEC2F vec = aEnd - aStart;
98
99 // This is the same as calc the length squared (without the sqrt)
100 // and compare with a small value.
101 return (aStart == aEnd) || ( glm::dot( vec, vec ) <= s_min_dot );
102}
103
104#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:81
OBJECT_2D(OBJECT_2D_TYPE aObjType, const BOARD_ITEM &aBoardItem)
Definition object_2d.cpp:27
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
ROUND_SEGMENT_2D(const SFVEC2F &aStart, const SFVEC2F &aEnd, float aWidth, const BOARD_ITEM &aBoardItem)
friend class ROUND_SEGMENT
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
const SFVEC2F & GetRightStar() const
const SFVEC2F & GetEnd_minus_Start() const
INTERSECTION_RESULT
Definition object_2d.h:33
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:38
glm::vec2 SFVEC2F
Definition xv3d_types.h:38