@@ -330,19 +330,19 @@ public:
330
330
331
331
const Scalar fa = 1 . / 360.0 ;
332
332
333
- if (fuzzy (max, min))
333
+ if (fuzzyCompare (max, min))
334
334
hsv[0 ] = 0 ;
335
- else if (fuzzy (max, srgb[0 ]))
335
+ else if (fuzzyCompare (max, srgb[0 ]))
336
336
hsv[0 ] = 60.0 * (0 + (srgb[1 ] - srgb[2 ]) * delMax);
337
- else if (fuzzy (max, srgb[1 ]))
337
+ else if (fuzzyCompare (max, srgb[1 ]))
338
338
hsv[0 ] = 60.0 * (2 + (srgb[2 ] - srgb[0 ]) * delMax);
339
- else if (fuzzy (max, srgb[2 ]))
339
+ else if (fuzzyCompare (max, srgb[2 ]))
340
340
hsv[0 ] = 60.0 * (4 + (srgb[0 ] - srgb[1 ]) * delMax);
341
341
342
342
if (hsv[0 ] < 0.0 )
343
343
hsv[0 ] += 360.0 ;
344
344
345
- if (fuzzy (max, 0.0 ))
345
+ if (fuzzyCompare (max, 0.0 ))
346
346
{
347
347
hsv[1 ] = 0.0 ;
348
348
}
@@ -496,34 +496,6 @@ public:
496
496
lab2rgb (v, rgb);
497
497
}
498
498
499
- private:
500
- const std::array<Scalar, 3U > illuminant;
501
-
502
- static Scalar f (Scalar t)
503
- {
504
- return (t > std::pow <Scalar>(6 . / 29 ., 3 .))
505
- ? std::pow <Scalar>(t, 1 . / 3 .)
506
- : (1 . / 3 .) * std::pow <Scalar>(29 . / 6 ., 2 .) * t + (4 . / 29 .);
507
- }
508
-
509
- static Scalar fi (Scalar t)
510
- {
511
- return (t > 6 . / 29 .)
512
- ? std::pow <Scalar>(t, 3 .)
513
- : 3 . * std::pow <Scalar>(6 . / 29 ., 2 .) * (t - (4 . / 29 .));
514
- }
515
-
516
- /* *
517
- * @brief Simple fuzzy comparison of floating point values.
518
- *
519
- * @return true
520
- * @return false
521
- */
522
- static bool fuzzy (const Scalar a, const Scalar b)
523
- {
524
- return std::fabs (a - b) < std::numeric_limits<Scalar>::epsilon ();
525
- }
526
-
527
499
/* *
528
500
* @brief Compute difference of two given colors.
529
501
*
@@ -572,7 +544,7 @@ private:
572
544
Scalar hpsample = std::atan2 (bsample, apsample);
573
545
if (hpsample < 0 )
574
546
hpsample += 2 . * Pi;
575
- if (fuzzy ((fabs (apsample) + fabs (bsample)), 0 .))
547
+ if (fuzzyCompare ((fabs (apsample) + fabs (bsample)), 0 .))
576
548
hpsample = 0 .;
577
549
578
550
Scalar dL = (Lsample - Lstd);
@@ -585,7 +557,7 @@ private:
585
557
if (dhp < -Pi)
586
558
dhp += 2 . * Pi;
587
559
// set chroma difference to zero if the product of chromas is zero
588
- if (fuzzy (Cpprod, 0 .))
560
+ if (fuzzyCompare (Cpprod, 0 .))
589
561
dhp = 0 .;
590
562
591
563
// Note that the defining equations actually need
@@ -613,7 +585,7 @@ private:
613
585
614
586
// Check if one of the chroma values is zero, in which case set
615
587
// mean hue to the sum which is equivalent to other value
616
- if (fuzzy (Cpprod, 0 .))
588
+ if (fuzzyCompare (Cpprod, 0 .))
617
589
hp = hpsample + hpstd;
618
590
619
591
Scalar Lpm502 = (Lp - 50 .) * (Lp - 50 .);
@@ -635,6 +607,36 @@ private:
635
607
return std::sqrt (std::pow ((dL / Sl), 2 .) + std::pow ((dC / Sc), 2 .) +
636
608
std::pow ((dH / Sh), 2 .) + RT * (dC / Sc) * (dH / Sh));
637
609
}
610
+
611
+ private:
612
+ const std::array<Scalar, 3U > illuminant;
613
+
614
+ static Scalar f (Scalar t)
615
+ {
616
+ return (t > std::pow <Scalar>(6 . / 29 ., 3 .))
617
+ ? std::pow <Scalar>(t, 1 . / 3 .)
618
+ : (1 . / 3 .) * std::pow <Scalar>(29 . / 6 ., 2 .) * t + (4 . / 29 .);
619
+ }
620
+
621
+ static Scalar fi (Scalar t)
622
+ {
623
+ return (t > 6 . / 29 .)
624
+ ? std::pow <Scalar>(t, 3 .)
625
+ : 3 . * std::pow <Scalar>(6 . / 29 ., 2 .) * (t - (4 . / 29 .));
626
+ }
627
+
628
+ /* *
629
+ * @brief Simple fuzzyCompare comparison of floating point values.
630
+ *
631
+ * @return true
632
+ * @return false
633
+ */
634
+ static bool fuzzyCompare (const Scalar a, const Scalar b)
635
+ {
636
+ constexpr auto FuzzynessFactor = 10.0 ;
637
+ return std::fabs (a - b) <
638
+ (FuzzynessFactor * std::numeric_limits<Scalar>::epsilon ());
639
+ }
638
640
};
639
641
640
642
} // namespace color
0 commit comments