43 static_assert( vi_1_2.x == 1 );
44 static_assert( vi_1_2.y == 2 );
48 static_assert( vi_3_5 ==
VECTOR2I( 3, 5 ) );
51 static_assert( vi_3_5 > vi_1_2 );
52 static_assert( vi_1_2 < vi_3_5 );
53 static_assert( vi_1_2 != vi_3_5 );
54 static_assert( vi_1_2 <= vi_1_2 );
55 static_assert( vi_1_2 >= vi_1_2 );
57 static_assert( vi_1_2.SquaredDistance( vi_3_5 ) == 4 + 9 );
64 constexpr VECTOR2D vd_1_2{ 1.0, 2.0 };
65 constexpr VECTOR2D vd_3_4{ 3.0, 4.0 };
67 static_assert( vd_1_2 ==
VECTOR2D( 1.0, 2.0 ) );
68 static_assert( vd_1_2 != vd_3_4 );
69 static_assert( vd_1_2 < vd_3_4 );
70 static_assert( vd_1_2 <= vd_3_4 );
71 static_assert( vd_3_4 > vd_1_2 );
117 BOOST_CHECK_EQUAL( vint,
VECTOR2I( vdouble ) );
118 BOOST_CHECK_EQUAL( vint,
VECTOR2I( vlong ) );
119 BOOST_CHECK_EQUAL( vint,
VECTOR2I( vfloat ) );
120 BOOST_CHECK_EQUAL( vint,
VECTOR2I( vunsigned ) );
122 BOOST_CHECK_EQUAL( vdouble,
VECTOR2D( vint ) );
123 BOOST_CHECK_EQUAL( vdouble,
VECTOR2D( vlong ) );
124 BOOST_CHECK_EQUAL( vdouble,
VECTOR2D( vfloat ) );
125 BOOST_CHECK_EQUAL( vdouble,
VECTOR2D( vunsigned ) );
127 BOOST_CHECK_EQUAL( vlong,
VECTOR2L( vint ) );
128 BOOST_CHECK_EQUAL( vlong,
VECTOR2L( vdouble ) );
129 BOOST_CHECK_EQUAL( vlong,
VECTOR2L( vfloat ) );
130 BOOST_CHECK_EQUAL( vlong,
VECTOR2L( vunsigned ) );
144 vdouble = vdouble - 1;
147 vunsigned = vunsigned - 1;
149 BOOST_CHECK_EQUAL( vint,
VECTOR2I( 3, 2 ) );
150 BOOST_CHECK_EQUAL( vdouble,
VECTOR2D( 3.0, 2.0 ) );
151 BOOST_CHECK_EQUAL( vlong,
VECTOR2L( 3, 2 ) );
156 vint = vint - (unsigned)1;
157 vdouble = vdouble - (unsigned)1;
158 vlong = vlong - (unsigned)1;
159 vfloat = vfloat - (unsigned)1;
160 vunsigned = vunsigned - (unsigned)1;
162 BOOST_CHECK_EQUAL( vint,
VECTOR2I( 2, 1 ) );
163 BOOST_CHECK_EQUAL( vdouble,
VECTOR2D( 2.0, 1.0 ) );
164 BOOST_CHECK_EQUAL( vlong,
VECTOR2L( 2, 1 ) );
169 vdouble = vdouble - 5.0;
171 vfloat = vfloat - 5.0;
172 vunsigned = vunsigned - 5.0;
174 BOOST_CHECK_EQUAL( vint,
VECTOR2I( -3, -4 ) );
175 BOOST_CHECK_EQUAL( vdouble,
VECTOR2D( -3.0, -4.0 ) );
176 BOOST_CHECK_EQUAL( vlong,
VECTOR2L( -3, -4 ) );
188 vdouble = vdouble - 1;
191 vunsigned = vunsigned - 1;
193 BOOST_CHECK_EQUAL( vint,
VECTOR2I( -5, -4 ) );
194 BOOST_CHECK_EQUAL( vdouble,
VECTOR2D( -5.0, -4.0 ) );
195 BOOST_CHECK_EQUAL( vlong,
VECTOR2L( -5, -4 ) );
200 vdouble = vdouble - 1u;
202 vfloat = vfloat - 1u;
204 BOOST_CHECK_EQUAL( vint,
VECTOR2I( -6, -5 ) );
205 BOOST_CHECK_EQUAL( vdouble,
VECTOR2D( -6.0, -5.0 ) );
206 BOOST_CHECK_EQUAL( vlong,
VECTOR2L( -6, -5 ) );
209 auto add = vint + vdouble;
210 BOOST_CHECK_EQUAL( add,
VECTOR2D( -12.0, -10.0 ) );
212 auto sub = vint - 2 * vlong;
213 BOOST_CHECK_EQUAL( sub.x, 6 );
214 BOOST_CHECK_EQUAL( sub.y, 5 );
216 vunsigned =
VECTOR2<unsigned>( std::numeric_limits<unsigned>::max(), std::numeric_limits<unsigned>::max() );
218 BOOST_CHECK_EQUAL( vint.
x, std::numeric_limits<int>::max() );
221 BOOST_CHECK_EQUAL( vunsigned.
x, 0 );
constexpr extended_type Cross(const VECTOR2< T > &aVector) const
Compute cross product of self with aVector.
constexpr extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
constexpr extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Constexpr)
Test suite for KiCad math code.
BOOST_TEST(v2.Cross(v1)==1)
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
constexpr const VECTOR2< T > & LexicographicalMin(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
VECTOR2< int64_t > VECTOR2L
constexpr int LexicographicalCompare(const VECTOR2< T > &aA, const VECTOR2< T > &aB)