KiCad PCB EDA Suite
Loading...
Searching...
No Matches
half_line.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <optional>
23
24#include <geometry/seg.h>
25#include <math/box2.h>
26
27/*
28 * A geometric half-line of infinite length, starting at a given point and extending infinitely.
29 * A.k.a. a ray.
30 *
31 * In terms of geometric ops, a SEG would probably do in most cases, as it
32 * has the same definition, but a separate class is more explicit and also
33 * allows compile-time reasoning about the meaning of the object through
34 * the type system.
35 */
37{
38public:
43 HALF_LINE( const SEG& aSeg ) : m_seg( aSeg ) {}
44
45 HALF_LINE( const VECTOR2I& aStart, const VECTOR2I& aOtherContainedPoint ) :
46 m_seg( aStart, aOtherContainedPoint )
47 {
48 }
49
53 const VECTOR2I& GetStart() const { return m_seg.A; }
54
58 const VECTOR2I& GetContainedPoint() const { return m_seg.B; }
59
60 bool Contains( const VECTOR2I& aPoint ) const;
61
62 OPT_VECTOR2I Intersect( const SEG& aSeg ) const;
63
64 OPT_VECTOR2I Intersect( const HALF_LINE& aOther ) const;
65
71 VECTOR2I NearestPoint( const VECTOR2I& aPoint ) const;
72
76 bool operator==( const HALF_LINE& aOther ) const { return m_seg == aOther.m_seg; }
77
83 const SEG& GetContainedSeg() const { return m_seg; }
84
85private:
88};
89
90
91std::optional<SEG> ClipHalfLineToBox( const HALF_LINE& aRay, const BOX2I& aBox );
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
OPT_VECTOR2I Intersect(const SEG &aSeg) const
Definition half_line.cpp:53
const SEG & GetContainedSeg() const
Gets the (one of the infinite number of) segments that the ray passes through.
Definition half_line.h:83
const VECTOR2I & GetStart() const
Get the start point of the ray.
Definition half_line.h:53
HALF_LINE(const SEG &aSeg)
Construct a ray from a segment - the ray will start at the segment's A point and extend infinitely in...
Definition half_line.h:43
const VECTOR2I & GetContainedPoint() const
Get one (of the infinite number) of points that the ray passes through.
Definition half_line.h:58
SEG m_seg
Internally, we can represent a just a segment that the ray passes through.
Definition half_line.h:87
HALF_LINE(const VECTOR2I &aStart, const VECTOR2I &aOtherContainedPoint)
Definition half_line.h:45
bool Contains(const VECTOR2I &aPoint) const
Definition half_line.cpp:37
VECTOR2I NearestPoint(const VECTOR2I &aPoint) const
Get the nearest point on the ray to the given point.
bool operator==(const HALF_LINE &aOther) const
Based on the ray being identically defined.
Definition half_line.h:76
Definition seg.h:38
std::optional< SEG > ClipHalfLineToBox(const HALF_LINE &aRay, const BOX2I &aBox)
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:35
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683