@@ -562,22 +562,19 @@ PointF intersect(const RegressionLine& l1, const RegressionLine& l2)
562
562
return {x, y};
563
563
}
564
564
565
- class EdgeTracer
565
+ struct BitMatrixAccessor
566
566
{
567
- const BitMatrix& image;
568
- PointI p; // current position
569
- PointF d; // current direction
567
+ const BitMatrix* image;
570
568
571
- enum class StepResult { FOUND, OPEN_END, CLOSED_END };
569
+ BitMatrixAccessor ( const BitMatrix& image) : image(&image) {}
572
570
573
571
bool isIn (PointI p) const
574
572
{
575
573
const int b = 0 ;
576
- return b <= p.x && p.x < image. width ()-b &&
577
- b <= p.y && p.y < image. height ()-b;
574
+ return b <= p.x && p.x < image-> width ()-b &&
575
+ b <= p.y && p.y < image-> height ()-b;
578
576
}
579
577
bool isIn (PointF p) const { return isIn (round (p)); }
580
- bool isIn () const { return isIn (p); }
581
578
582
579
class Value
583
580
{
@@ -596,12 +593,23 @@ class EdgeTracer
596
593
auto q = round (p);
597
594
if (!isIn (q))
598
595
return {};
599
- return {image. get (q.x , q.y )};
596
+ return {image-> get (q.x , q.y )};
600
597
}
601
598
602
599
bool blackAt (PointF p) const { return getAt (p).isBlack (); }
603
600
bool whiteAt (PointF p) const { return getAt (p).isWhite (); }
604
601
bool isEdge (PointF pos, PointF dir) const { return whiteAt (pos) && blackAt (pos + dir); }
602
+ };
603
+
604
+ class EdgeTracer : BitMatrixAccessor
605
+ {
606
+ PointI p; // current position
607
+ PointF d; // current direction
608
+
609
+ enum class StepResult { FOUND, OPEN_END, CLOSED_END };
610
+
611
+ using BitMatrixAccessor::isIn;
612
+ bool isIn () const { return isIn (p); }
605
613
606
614
StepResult traceStep (PointF dEdge, int maxStepSize, bool goodDirection)
607
615
{
@@ -635,18 +643,7 @@ class EdgeTracer
635
643
}
636
644
637
645
public:
638
- EdgeTracer (const BitMatrix& img, PointF p, PointF d) : image(img), p(p), d(d) {}
639
- EdgeTracer& operator =(const EdgeTracer& other)
640
- {
641
- assert (&image == &other.image );
642
- p = other.p ;
643
- d = other.d ;
644
- return *this ;
645
- }
646
- EdgeTracer (const EdgeTracer&) = default ;
647
- ~EdgeTracer () = default ;
648
- EdgeTracer (EdgeTracer&&) noexcept (true ) = default ;
649
- EdgeTracer& operator =(EdgeTracer&&) = default ;
646
+ EdgeTracer (const BitMatrix& img, PointI p, PointF d) : BitMatrixAccessor(img), p(p), d(d) {}
650
647
651
648
bool step (int s = 1 )
652
649
{
@@ -808,7 +805,7 @@ static DetectorResult DetectNew(const BitMatrix& image, bool tryRotate)
808
805
#else
809
806
for (auto startDirection : {PointF (-1 , 0 ), PointF (-1 , 0 ), PointF (1 , 0 ), PointF (0 , -1 ), PointF (0 , 1 )}) {
810
807
#endif
811
- EdgeTracer startTracer (image, PointF ( image.width ()/2 , image.height ()/2 ) , startDirection);
808
+ EdgeTracer startTracer (image, { image.width ()/2 , image.height ()/2 } , startDirection);
812
809
while (startTracer.step ()) {
813
810
// go forward until we reach a white/black border
814
811
if (!startTracer.isEdgeBehind ())
0 commit comments