KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_bezier.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21#include <bezier_curves.h>
22
23
25
26
27static void checkVecClose( const VECTOR2D& aActual, const VECTOR2D& aExpected )
28{
29 constexpr double tol = 1e-9;
30
31 BOOST_CHECK_SMALL( aActual.x - aExpected.x, tol );
32 BOOST_CHECK_SMALL( aActual.y - aExpected.y, tol );
33}
34
35
36BOOST_AUTO_TEST_CASE( SplitPreservesEndpoints )
37{
38 const BEZIER<double> curve( { 0.0, 0.0 }, { 30.0, 90.0 }, { 70.0, -40.0 },
39 { 100.0, 0.0 } );
42
43 curve.Split( 0.35, left, right );
44
45 checkVecClose( left.Start, curve.Start );
46 checkVecClose( left.End, curve.PointAt( 0.35 ) );
47 checkVecClose( right.Start, left.End );
48 checkVecClose( right.End, curve.End );
49}
50
51
52BOOST_AUTO_TEST_CASE( SubCurvePreservesOriginalParameterization )
53{
54 const BEZIER<double> curve( { 0.0, 0.0 }, { 30.0, 90.0 }, { 70.0, -40.0 },
55 { 100.0, 0.0 } );
56 const double t0 = 0.2;
57 const double t1 = 0.8;
58 const BEZIER<double> subCurve = curve.SubCurve( t0, t1 );
59
60 checkVecClose( subCurve.Start, curve.PointAt( t0 ) );
61 checkVecClose( subCurve.End, curve.PointAt( t1 ) );
62 checkVecClose( subCurve.PointAt( 0.5 ), curve.PointAt( t0 + ( t1 - t0 ) * 0.5 ) );
63}
64
65
Generic cubic Bezier representation.
VECTOR2< NumericType > Start
constexpr BEZIER SubCurve(double aT0, double aT1) const
Extract a sub-curve from aT0 to aT1 using de Casteljau subdivision.
VECTOR2< NumericType > End
constexpr VECTOR2< NumericType > PointAt(double aT) const
Evaluate the Bezier curve at a given t value.
BOOST_AUTO_TEST_CASE(SplitPreservesEndpoints)
static void checkVecClose(const VECTOR2D &aActual, const VECTOR2D &aExpected)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
VECTOR2< double > VECTOR2D
Definition vector2d.h:682