29 std::optional<double> aValue = std::nullopt )
32 std::vector<PCB_SHAPE*> mod;
45void run(
const char* aName,
bool aExpectConflict,
const std::function<
void(
BOARD& )>& aBuild )
52 BOOST_CHECK_MESSAGE( ( !d.
conflicting.empty() ) == aExpectConflict,
53 aName <<
": expected " << ( aExpectConflict ?
"conflict" :
"clean" )
65 run(
"parallel(2 seg)",
false,
70 author( b, T::PARALLEL, { whole( s1 ), whole( s2 ) } );
72 run(
"perpendicular(2 seg)",
false,
77 author( b, T::PERPENDICULAR, { whole( s1 ), whole( s2 ) } );
79 run(
"horizontal(1 seg)",
false,
83 author( b, T::HORIZONTAL, { whole( s ) } );
85 run(
"vertical(1 seg)",
false,
89 author( b, T::VERTICAL, { whole( s ) } );
91 run(
"collinear(2 seg)",
false,
96 author( b, T::COLLINEAR, { whole( s1 ), whole( s2 ) } );
98 run(
"equal_length(2 seg)",
false,
103 author( b, T::EQUAL_LENGTH, { whole( s1 ), whole( s2 ) } );
105 run(
"fixed_length(1 seg)",
false,
109 author( b, T::FIXED_LENGTH, { whole( s ) }, 10.0 *
MM );
111 run(
"angular(2 seg)",
false,
116 author( b, T::ANGULAR_DIMENSION, { whole( s1 ), whole( s2 ) }, 90.0 );
118 run(
"concentric(2 circ)",
false,
123 author( b, T::CONCENTRIC, { whole( c1 ), whole( c2 ) } );
125 run(
"equal_radius(2 circ)",
false,
130 author( b, T::EQUAL_RADIUS, { whole( c1 ), whole( c2 ) } );
132 run(
"fixed_radius(1 circ)",
false,
136 author( b, T::FIXED_RADIUS, { whole( c ) }, 8.0 *
MM );
138 run(
"tangent(line,circ)",
false,
143 author( b, T::TANGENT, { whole( s ), whole( c ) } );
145 run(
"tangent(2 circ)",
false,
150 author( b, T::TANGENT, { whole( c1 ), whole( c2 ) } );
154 run(
"parallel+perpendicular",
true,
159 author( b, T::PARALLEL, { whole( s1 ), whole( s2 ) } );
160 author( b, T::PERPENDICULAR, { whole( s1 ), whole( s2 ) } );
162 run(
"horizontal+vertical",
true,
166 author( b, T::HORIZONTAL, { whole( s ) } );
167 author( b, T::VERTICAL, { whole( s ) } );
169 run(
"collinear+perpendicular",
true,
174 author( b, T::COLLINEAR, { whole( s1 ), whole( s2 ) } );
175 author( b, T::PERPENDICULAR, { whole( s1 ), whole( s2 ) } );
177 run(
"equal_radius+two fixed_radius",
true,
182 author( b, T::EQUAL_RADIUS, { whole( c1 ), whole( c2 ) } );
183 author( b, T::FIXED_RADIUS, { whole( c1 ) }, 5.0 *
MM );
184 author( b, T::FIXED_RADIUS, { whole( c2 ) }, 9.0 *
MM );
188 run(
"horiz+horiz+parallel(redundant)",
false,
193 author( b, T::HORIZONTAL, { whole( s1 ) } );
194 author( b, T::HORIZONTAL, { whole( s2 ) } );
195 author( b, T::PARALLEL, { whole( s1 ), whole( s2 ) } );
199 run(
"perpendicular(locked+free)",
false,
205 author( b, T::PERPENDICULAR, { whole( lk ), whole( fr ) } );
207 run(
"parallel+perp(locked+free)",
true,
213 author( b, T::PARALLEL, { whole( lk ), whole( fr ) } );
214 author( b, T::PERPENDICULAR, { whole( lk ), whole( fr ) } );
227 auto tangentErr = [&]()
229 SEG seg( line->GetStart(), line->GetEnd() );
233 BOOST_CHECK_LE( tangentErr(), 5000.0 );
236 BOOST_CHECK_GT( tangentErr(), 1 *
MM );
238 std::vector<PCB_SHAPE*> shapes{ circ }, mod;
244 BOOST_CHECK_LE( tangentErr(), 5000.0 );
258 auto parallelErr = [&]()
260 VECTOR2I da = a->GetEnd() - a->GetStart();
262 double cross = (double) da.
x *
dc.y - (
double) da.
y *
dc.x;
266 BOOST_CHECK_LE( parallelErr(), 1e-3 );
269 BOOST_CHECK_GT( parallelErr(), 0.1 );
271 std::vector<PCB_SHAPE*> shapes{ c }, mod;
279 BOOST_CHECK_LE( parallelErr(), 0.05 );
295 std::ranges::fill( state, std::numeric_limits<double>::quiet_NaN() );
307 locked->SetLocked(
true );
317 for(
double param : adapter.
Snapshot() )
329 const VECTOR2I s1End = s1->GetEnd();
330 const VECTOR2I s2Start = s2->GetStart();
331 const VECTOR2I s2End = s2->GetEnd();
CONSTRAINT_DIAGNOSIS ApplyConstraintImmediately(BOARD *aBoard, const PCB_CONSTRAINT *aConstraint, std::vector< PCB_SHAPE * > *aModified, const std::function< void(BOARD_ITEM *)> &aBeforeModify, const std::set< KIID > &aFixedShapes)
Solve a just-created constraint's cluster so the geometry snaps to satisfy it (SolidWorks-style),...
void ReSolveShapeClusters(BOARD *aBoard, const std::vector< PCB_SHAPE * > &aShapes, std::vector< PCB_SHAPE * > *aModified, const std::function< void(BOARD_ITEM *)> &aBeforeModify)
Re-solve the clusters of shapes edited outside the solver, e.g.
BOARD_CONSTRAINT_DIAGNOSTICS DiagnoseBoardConstraints(BOARD *aBoard)
Diagnose every constraint cluster on the board (validate only – geometry is not changed) and return t...
Translates KiCad board geometry to and from the planegcs solver (issue #2329).
SNAPSHOT Snapshot() const
bool Solve(const CONSTRAINT_MEMBER &aDragged, const VECTOR2I &aCursor, bool aStabilize=false, const std::set< KIID > &aEdited={}, const std::optional< std::pair< CONSTRAINT_MEMBER, VECTOR2I > > &aCoDragged=std::nullopt, bool aHoldDraggedRigid=false)
Solve the system, pinning a dragged anchor to a cursor position.
bool CurrentRelationsSatisfied() const
CONSTRAINT_SYSTEM_2D::SNAPSHOT SNAPSHOT
bool Restore(const SNAPSHOT &aSnapshot)
bool Build(const std::vector< PCB_SHAPE * > &aShapes, const std::vector< PCB_CONSTRAINT * > &aConstraints, const std::set< KIID > *aFixedShapes=nullptr, const std::vector< PCB_DIMENSION_BASE * > &aDimensions={}, const std::vector< PAD * > &aPads={})
Translate a cluster into a planegcs system.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
void SetLocked(bool aLocked) override
Information pertinent to a Pcbnew printed circuit board.
const CONSTRAINTS & Constraints() const
Geometric constraints (#2329) owned by this board.
A geometric constraint between board items (issue #2329).
void SetDriving(bool aDriving)
int LineDistance(const VECTOR2I &aP, bool aDetermineSide=false) const
Return the closest Euclidean distance between point aP and the line defined by the ends of segment (t...
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
Test utilities for timestamps.
PCB_SHAPE * addSegment(BOARD &aBoard, const VECTOR2I &aStart, const VECTOR2I &aEnd)
PCB_SHAPE * addCircle(BOARD &aBoard, const VECTOR2I &aCenter, int aRadius)
PCB_CONSTRAINT * addConstraint(BOARD &aBoard, PCB_CONSTRAINT_TYPE aType, const std::vector< CONSTRAINT_MEMBER > &aMembers, std::optional< double > aValue=std::nullopt)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
@ WHOLE
The item as a whole (a segment as a line, a circle).
@ START
First endpoint of a segment or arc.
PCB_CONSTRAINT_TYPE
The geometric relationship a PCB_CONSTRAINT enforces between its members.
@ TANGENT
A line and a curve, or two curves, touch tangentially.
@ PERPENDICULAR
Two segments are perpendicular.
@ HORIZONTAL
A segment (or two points) is horizontal.
@ PARALLEL
Two segments are parallel.
Board-wide diagnostics for the constraint overlay and info bar.
std::vector< KIID > conflicting
One participant in a constraint: a referenced board item plus the feature of that item that participa...
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(Sweep)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
DATABASE_CONNECTION dc(odbcBackend(cs))
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
VECTOR2< int32_t > VECTOR2I