KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <geometry/seg.h>
23
24/*
25 * A geometric line of infinite length.
26 *
27 * In terms of geometric ops, a SEG would probably do as it has the same definition,
28 * but a separate class is more explicit and also allows compile-time
29 * reasoning about the meaning of the object through the type system.
30 */
31class LINE
32{
33public:
35
36 LINE( const SEG& aSeg ) : m_seg( aSeg ) {}
37
38 LINE( const VECTOR2I& aStart, const VECTOR2I& aEnd ) : m_seg( aStart, aEnd ) {}
39
40 bool operator==( const LINE& aOther ) const { return m_seg == aOther.m_seg; }
41
45 const SEG& GetContainedSeg() const { return m_seg; }
46
47 OPT_VECTOR2I Intersect( const SEG& aOther ) const;
48 OPT_VECTOR2I Intersect( const LINE& aOther ) const;
49
53 int Distance( const VECTOR2I& aPoint ) const;
54
58 VECTOR2I NearestPoint( const VECTOR2I& aPoint ) const;
59
60private:
63};
Definition line.h:32
const SEG & GetContainedSeg() const
Gets the (one of the infinite number of) segments that the line passes through.
Definition line.h:45
VECTOR2I::extended_type ecoord
Definition line.h:34
LINE(const SEG &aSeg)
Definition line.h:36
SEG m_seg
Internally, we can represent a just a segment that the line passes through.
Definition line.h:62
int Distance(const VECTOR2I &aPoint) const
Gets the distance from the line to the given point.
Definition line.cpp:46
bool operator==(const LINE &aOther) const
Definition line.h:40
VECTOR2I NearestPoint(const VECTOR2I &aPoint) const
Gets the nearest point on the line to the given point.
Definition line.cpp:52
OPT_VECTOR2I Intersect(const SEG &aOther) const
Definition line.cpp:22
LINE(const VECTOR2I &aStart, const VECTOR2I &aEnd)
Definition line.h:38
Definition seg.h:38
VECTOR2_TRAITS< int32_t >::extended_type extended_type
Definition vector2d.h:69
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:35
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683