KiCad PCB EDA Suite
Loading...
Searching...
No Matches
constraint_system_2d.cpp
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 3
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
21
22#include <algorithm>
23#include <cassert>
24
25#include <GCS.h>
26
27
29 m_solver( std::make_unique<GCS::System>() )
30{
31}
32
33
38
39
40void CONSTRAINT_SYSTEM_2D::SetCoordinateFrame( const VECTOR2I& aOrigin, double aScale )
41{
42 assert( aScale > 0.0 );
43
44 m_originX = aOrigin.x;
45 m_originY = aOrigin.y;
46 m_scale = aScale;
47 m_inverseScale = 1.0 / aScale;
48}
49
50
51double CONSTRAINT_SYSTEM_2D::NormalizeX( int aIU ) const
52{
53 return ( aIU - m_originX ) * m_inverseScale;
54}
55
56
57double CONSTRAINT_SYSTEM_2D::NormalizeY( int aIU ) const
58{
59 return ( aIU - m_originY ) * m_inverseScale;
60}
61
62
63double CONSTRAINT_SYSTEM_2D::DenormalizeX( double aNormalized ) const
64{
65 return aNormalized * m_scale + m_originX;
66}
67
68
69double CONSTRAINT_SYSTEM_2D::DenormalizeY( double aNormalized ) const
70{
71 return aNormalized * m_scale + m_originY;
72}
73
74
76{
77 m_parameters.push_back( aValue );
78 return static_cast<int>( m_parameters.size() ) - 1;
79}
80
81
83{
84 return m_parameters.at( aIndex );
85}
86
87
88const double& CONSTRAINT_SYSTEM_2D::Parameter( int aIndex ) const
89{
90 return m_parameters.at( aIndex );
91}
92
93
95{
96 return &m_parameters.at( aIndex );
97}
98
99
104
105
107{
108 if( aSnapshot.size() != m_parameters.size() )
109 return false;
110
111 std::copy( aSnapshot.begin(), aSnapshot.end(), m_parameters.begin() );
112 return true;
113}
114
115
117{
118 if( aSnapshot.size() > m_parameters.size() )
119 return false;
120
121 std::copy( aSnapshot.begin(), aSnapshot.end(), m_parameters.begin() );
122 return true;
123}
124
125
127{
128 m_solver->clear();
129 m_parameters.clear();
130}
131
132
134{
135 return *m_solver;
136}
137
138
139const GCS::System& CONSTRAINT_SYSTEM_2D::Solver() const
140{
141 return *m_solver;
142}
bool RestorePrefix(const SNAPSHOT &aSnapshot)
double DenormalizeY(double aNormalized) const
double NormalizeY(int aIU) const
bool Restore(const SNAPSHOT &aSnapshot)
void SetCoordinateFrame(const VECTOR2I &aOrigin, double aScale)
double NormalizeX(int aIU) const
std::vector< double > SNAPSHOT
double & Parameter(int aIndex)
int AddParameter(double aValue)
double DenormalizeX(double aNormalized) const
std::deque< double > m_parameters
std::unique_ptr< GCS::System > m_solver
double * ParameterPointer(int aIndex)
STL namespace.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683