63 double bc = ( b.
x * b.
x + b.
y * b.
y ) / 2.0;
64 double cd = ( -d.
x * d.
x - d.
y * d.
y ) / 2.0;
65 double det = -b.
x * d.
y + d.
x * b.
y;
67 if( fabs( det ) < 1.0e-6 )
71 aCenter->
x = ( -bc * d.
y - cd * b.
y ) * det;
72 aCenter->
y = ( b.
x * cd + d.
x * bc ) * det;
84 double yDelta_21 = aMid.
y - aStart.
y;
85 double xDelta_21 = aMid.
x - aStart.
x;
86 double yDelta_32 = aEnd.
y - aMid.
y;
87 double xDelta_32 = aEnd.
x - aMid.
x;
92 if( ( ( xDelta_21 == 0.0 ) && ( yDelta_32 == 0.0 ) )
93 || ( ( yDelta_21 == 0.0 ) && ( xDelta_32 == 0.0 ) ) )
95 center.x = ( aStart.
x + aEnd.
x ) / 2.0;
96 center.y = ( aStart.
y + aEnd.
y ) / 2.0;
107 double aSlope = yDelta_21 / xDelta_21;
108 double bSlope = yDelta_32 / xDelta_32;
110 if( aSlope == bSlope )
116 center.x = ( aStart.
x + aMid.
x ) / 2.0;
117 center.y = ( aStart.
y + aMid.
y ) / 2.0;
130 center.x = ( aSlope * bSlope * ( aStart.
y - aEnd.
y ) + bSlope * ( aStart.
x + aMid.
x )
131 - aSlope * ( aMid.
x + aEnd.
x ) )
132 / ( 2 * ( bSlope - aSlope ) );
137 + ( aStart.
y + aMid.
y ) / 2.0 );
142 ( ( ( aMid.
x + aEnd.
x ) / 2.0 -
center.x ) / bSlope + ( aMid.
y + aEnd.
y ) / 2.0 );
166 std::vector<TEST_CALC_ARC_CENTER_CASE> calc_center_cases = {
170 const double tolerance = 1.0;
199 double crs = ( calcCenter - start ).EuclideanNorm();
200 double crm = ( calcCenter - mid ).EuclideanNorm();
201 double cre = ( calcCenter -
end ).EuclideanNorm();
203 double cavg = ( crs + crm + cre ) / 3.0;
205 if(
std::abs( crs - cavg ) > tolerance ||
std::abs( crm - cavg ) > tolerance
206 ||
std::abs( cre - cavg ) > tolerance )
208 msg <<
"CalcArcCenter failed.";
210 msg <<
"\nstart: " << entry.istart.Format();
211 msg <<
"\nmid: " << entry.imid.Format();
212 msg <<
"\nend: " << entry.iend.Format();
215 msg <<
"\nCalculated center: " << wxString::Format(
"%.15f", calcCenter.
x ) <<
", "
216 << wxString::Format(
"%.15f", calcCenter.
y );
218 msg <<
"\n Avg radius: " << wxString::Format(
"%.15f", cavg );
219 msg <<
"\nStart radius: " << wxString::Format(
"%.15f", crs );
220 msg <<
"\n Mid radius: " << wxString::Format(
"%.15f", crm );
221 msg <<
"\n End radius: " << wxString::Format(
"%.15f", cre );
225 EDA_ANGLE angStart( start - calcCenter );
234 RotatePoint( newMid, calcCenter, -angCenter / 2.0 );
237 msg <<
"\nNew mid: " << wxString::Format(
"%.15f", newMid.
x ) <<
", "
238 << wxString::Format(
"%.15f", newMid.
y );
240 msg <<
"\nNew end: " << wxString::Format(
"%.15f", newEnd.
x ) <<
", "
241 << wxString::Format(
"%.15f", newEnd.
y );
244 double endsDist = ( newEnd -
end ).EuclideanNorm();
246 msg <<
"\nNew end is off by " << wxString::Format(
"%.15f", endsDist );
254 double r0_rs = ( ref0Center - start ).EuclideanNorm();
255 double r0_rm = ( ref0Center - mid ).EuclideanNorm();
256 double r0_rre = ( ref0Center -
end ).EuclideanNorm();
258 double r0_ravg = ( r0_rs + r0_rm + r0_rre ) / 3.0;
260 msg <<
"\nReference0 center: " << wxString::Format(
"%.15f", ref0Center.
x ) <<
", "
261 << wxString::Format(
"%.15f", ref0Center.
y );
263 msg <<
"\nRef0 Avg radius: " << wxString::Format(
"%.15f", r0_ravg );
264 msg <<
"\nRef0 Start radius: " << wxString::Format(
"%.15f", r0_rs );
265 msg <<
"\nRef0 Mid radius: " << wxString::Format(
"%.15f", r0_rm );
266 msg <<
"\nRef0 End radius: " << wxString::Format(
"%.15f", r0_rre );
273 double r1_rs = ( ref1Center - start ).EuclideanNorm();
274 double r1_rm = ( ref1Center - mid ).EuclideanNorm();
275 double r1_rre = ( ref1Center -
end ).EuclideanNorm();
277 double r1_ravg = ( r1_rs + r1_rm + r1_rre ) / 3.0;
279 msg <<
"\nReference1 center: " << wxString::Format(
"%.15f", ref1Center.
x ) <<
", "
280 << wxString::Format(
"%.15f", ref1Center.
y );
282 msg <<
"\nRef1 Avg radius: " << wxString::Format(
"%.15f", r1_ravg );
283 msg <<
"\nRef1 Start radius: " << wxString::Format(
"%.15f", r1_rs );
284 msg <<
"\nRef1 Mid radius: " << wxString::Format(
"%.15f", r1_rm );
285 msg <<
"\nRef1 End radius: " << wxString::Format(
"%.15f", r1_rre );
323 for(
size_t i = 0; i < 16; i++ )
324 BOOST_CHECK( zero.Value8[i] == 0 );
328 for(
size_t i = 0; i < 16; i++ )
329 BOOST_CHECK( zero_h->
Value8[i] == 0 );
334 h.
Value64[0] = 0x00CDEF0123456789ULL;
335 h.
Value64[1] = 0x56789ABCDEF01234ULL;
337 BOOST_CHECK( h != zero );
340 BOOST_CHECK( b != zero );
342 BOOST_CHECK( b == h );
343 BOOST_CHECK( h == b );
357 std::vector<std::vector<int32_t>> data;
359 for(
size_t i = 0; i < 10; i++ )
361 std::vector<int32_t>& vec = data.emplace_back();
363 size_t vecSize = rand() % 128;
365 for(
size_t j = 0; j < vecSize; j++ )
366 vec.emplace_back( rand() );
371 for(
const std::vector<int32_t>& vec : data )
375 for(
const int32_t val : vec )
384 BOOST_CHECK( h128 == orig128 );
397#if defined( _MSC_VER )
398 #define FORCE_INLINE __forceinline
400 #define ROTL64( x, y ) _rotl64( x, y )
401 #define BIG_CONSTANT( x ) ( x )
404 #define FORCE_INLINE inline __attribute__( ( always_inline ) )
405 inline uint64_t
rotl64( uint64_t x, int8_t r )
407 return ( x << r ) | ( x >> ( 64 - r ) );
409 #define ROTL64( x, y ) rotl64( x, y )
410 #define BIG_CONSTANT( x ) ( x##LLU )
431 const uint32_t
seed,
void * out )
433 const uint8_t * data = (
const uint8_t*)key;
434 const int nblocks = len / 16;
445 const uint64_t * blocks = (
const uint64_t *)(data);
447 for(
int i = 0; i < nblocks; i++)
452 k1 *= c1; k1 =
ROTL64(k1,31); k1 *= c2; h1 ^= k1;
454 h1 =
ROTL64(h1,27); h1 += h2; h1 = h1*5+0x52dce729;
456 k2 *= c2; k2 =
ROTL64(k2,33); k2 *= c1; h2 ^= k2;
458 h2 =
ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
464 const uint8_t * tail = (
const uint8_t*)(data + nblocks*16);
471 case 15: k2 ^= ((uint64_t)tail[14]) << 48;
472 case 14: k2 ^= ((uint64_t)tail[13]) << 40;
473 case 13: k2 ^= ((uint64_t)tail[12]) << 32;
474 case 12: k2 ^= ((uint64_t)tail[11]) << 24;
475 case 11: k2 ^= ((uint64_t)tail[10]) << 16;
476 case 10: k2 ^= ((uint64_t)tail[ 9]) << 8;
477 case 9: k2 ^= ((uint64_t)tail[ 8]) << 0;
478 k2 *= c2; k2 =
ROTL64(k2,33); k2 *= c1; h2 ^= k2;
480 case 8: k1 ^= ((uint64_t)tail[ 7]) << 56;
481 case 7: k1 ^= ((uint64_t)tail[ 6]) << 48;
482 case 6: k1 ^= ((uint64_t)tail[ 5]) << 40;
483 case 5: k1 ^= ((uint64_t)tail[ 4]) << 32;
484 case 4: k1 ^= ((uint64_t)tail[ 3]) << 24;
485 case 3: k1 ^= ((uint64_t)tail[ 2]) << 16;
486 case 2: k1 ^= ((uint64_t)tail[ 1]) << 8;
487 case 1: k1 ^= ((uint64_t)tail[ 0]) << 0;
488 k1 *= c1; k1 =
ROTL64(k1,31); k1 *= c2; h1 ^= k1;
494 h1 ^= len; h2 ^= len;
505 ((uint64_t*)out)[0] = h1;
506 ((uint64_t*)out)[1] = h2;
A streaming C++ equivalent for MurmurHash3_x64_128.
FORCE_INLINE void add(const std::string &input)
FORCE_INLINE HASH_128 digest()
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
A storage class for 128-bit hash value.
std::string ToString() const
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
FORCE_INLINE uint64_t fmix64(uint64_t k)
uint64_t rotl64(uint64_t x, int8_t r)
static const VECTOR2D Ref1CalcArcCenter(const VECTOR2D &aStart, const VECTOR2D &aMid, const VECTOR2D &aEnd)
FORCE_INLINE uint64_t getblock64(const uint64_t *p, int i)
void MurmurHash3_x64_128(const void *key, const int len, const uint32_t seed, void *out)
static bool Ref0CircleCenterFrom3Points(const VECTOR2D &p1, const VECTOR2D &p2, const VECTOR2D &p3, VECTOR2D *aCenter)
Test suite for KiCad math code.
BOOST_AUTO_TEST_CASE(TestCalcArcCenter3Pts)
Declare the test suite.
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_CHECK_EQUAL(result, "25.4")
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
bool InterceptsPositiveX(double aStartAngle, double aEndAngle)
Test if an arc from aStartAngle to aEndAngle crosses the positive X axis (0 degrees).
bool InterceptsNegativeX(double aStartAngle, double aEndAngle)
Test if an arc from aStartAngle to aEndAngle crosses the negative X axis (180 degrees).
const VECTOR2I CalcArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc or circle given three points on its circumference.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D