diff --git a/cpp/core/src/zxing/aztec/detector/Detector.cpp b/cpp/core/src/zxing/aztec/detector/Detector.cpp index 5d5f74132..e46b49dd5 100644 --- a/cpp/core/src/zxing/aztec/detector/Detector.cpp +++ b/cpp/core/src/zxing/aztec/detector/Detector.cpp @@ -140,26 +140,26 @@ ArrayRef< Ref > Detector::getMatrixCornerPoints(std::vector > bullEyeCornerPoints) { float ratio = (2 * nbLayers_ + (nbLayers_ > 4 ? 1 : 0) + (nbLayers_ - 4) / 8) / (2.0f * nbCenterLayers_); - int dx = bullEyeCornerPoints[0]->x - bullEyeCornerPoints[2]->x; + int dx = bullEyeCornerPoints[0]->getX() - bullEyeCornerPoints[2]->getX(); dx += dx > 0 ? 1 : -1; - int dy = bullEyeCornerPoints[0]->y - bullEyeCornerPoints[2]->y; + int dy = bullEyeCornerPoints[0]->getY() - bullEyeCornerPoints[2]->getY(); dy += dy > 0 ? 1 : -1; - int targetcx = math_utils::round(bullEyeCornerPoints[2]->x - ratio * dx); - int targetcy = math_utils::round(bullEyeCornerPoints[2]->y - ratio * dy); + int targetcx = math_utils::round(bullEyeCornerPoints[2]->getX() - ratio * dx); + int targetcy = math_utils::round(bullEyeCornerPoints[2]->getY() - ratio * dy); - int targetax = math_utils::round(bullEyeCornerPoints[0]->x + ratio * dx); - int targetay = math_utils::round(bullEyeCornerPoints[0]->y + ratio * dy); + int targetax = math_utils::round(bullEyeCornerPoints[0]->getX() + ratio * dx); + int targetay = math_utils::round(bullEyeCornerPoints[0]->getY() + ratio * dy); - dx = bullEyeCornerPoints[1]->x - bullEyeCornerPoints[3]->x; + dx = bullEyeCornerPoints[1]->getX() - bullEyeCornerPoints[3]->getX(); dx += dx > 0 ? 1 : -1; - dy = bullEyeCornerPoints[1]->y - bullEyeCornerPoints[3]->y; + dy = bullEyeCornerPoints[1]->getY() - bullEyeCornerPoints[3]->getY(); dy += dy > 0 ? 1 : -1; - int targetdx = math_utils::round(bullEyeCornerPoints[3]->x - ratio * dx); - int targetdy = math_utils::round(bullEyeCornerPoints[3]->y - ratio * dy); - int targetbx = math_utils::round(bullEyeCornerPoints[1]->x + ratio * dx); - int targetby = math_utils::round(bullEyeCornerPoints[1]->y + ratio * dy); + int targetdx = math_utils::round(bullEyeCornerPoints[3]->getX() - ratio * dx); + int targetdy = math_utils::round(bullEyeCornerPoints[3]->getY() - ratio * dy); + int targetbx = math_utils::round(bullEyeCornerPoints[1]->getX() + ratio * dx); + int targetby = math_utils::round(bullEyeCornerPoints[1]->getY() + ratio * dy); if (!isValid(targetax, targetay) || !isValid(targetbx, targetby) || @@ -269,21 +269,21 @@ std::vector > Detector::getBullEyeCornerPoints(Refx - pind->x; - int dy = pina->y - pinc->y; + int dx = pina->getX() - pind->getX(); + int dy = pina->getY() - pinc->getY(); - int targetcx = math_utils::round(pinc->x - ratio * dx); - int targetcy = math_utils::round(pinc->y - ratio * dy); - int targetax = math_utils::round(pina->x + ratio * dx); - int targetay = math_utils::round(pina->y + ratio * dy); + int targetcx = math_utils::round(pinc->getX() - ratio * dx); + int targetcy = math_utils::round(pinc->getY() - ratio * dy); + int targetax = math_utils::round(pina->getX() + ratio * dx); + int targetay = math_utils::round(pina->getY() + ratio * dy); - dx = pinb->x - pind->x; - dy = pinb->y - pind->y; + dx = pinb->getX() - pind->getX(); + dy = pinb->getY() - pind->getY(); - int targetdx = math_utils::round(pind->x - ratio * dx); - int targetdy = math_utils::round(pind->y - ratio * dy); - int targetbx = math_utils::round(pinb->x + ratio * dx); - int targetby = math_utils::round(pinb->y + ratio * dy); + int targetdx = math_utils::round(pind->getX() - ratio * dx); + int targetdy = math_utils::round(pind->getY() - ratio * dy); + int targetbx = math_utils::round(pinb->getX() + ratio * dx); + int targetby = math_utils::round(pinb->getY() + ratio * dy); if (!isValid(targetax, targetay) || !isValid(targetbx, targetby) || @@ -429,11 +429,11 @@ Ref Detector::sampleLine(Ref p1, Refx - p1->x)/d; - float dy = moduleSize * float(p2->y - p1->y)/d; + float dx = moduleSize * float(p2->getX() - p1->getX())/d; + float dy = moduleSize * float(p2->getY() - p1->getY())/d; - float px = float(p1->x); - float py = float(p1->y); + float px = float(p1->getX()); + float py = float(p1->getY()); for (int i = 0; i < size; i++) { if (image_->get(math_utils::round(px), math_utils::round(py))) res->set(i); @@ -450,10 +450,10 @@ bool Detector::isWhiteOrBlackRectangle(Ref p1, Ref p4) { int corr = 3; - p1 = new Point(p1->x - corr, p1->y + corr); - p2 = new Point(p2->x - corr, p2->y - corr); - p3 = new Point(p3->x + corr, p3->y - corr); - p4 = new Point(p4->x + corr, p4->y + corr); + p1 = new Point(p1->getX() - corr, p1->getY() + corr); + p2 = new Point(p2->getX() - corr, p2->getY() - corr); + p3 = new Point(p3->getX() + corr, p3->getY() - corr); + p4 = new Point(p4->getX() + corr, p4->getY() + corr); int cInit = getColor(p4, p1); @@ -485,15 +485,15 @@ bool Detector::isWhiteOrBlackRectangle(Ref p1, int Detector::getColor(Ref p1, Ref p2) { float d = distance(p1, p2); - float dx = (p2->x - p1->x) / d; - float dy = (p2->y - p1->y) / d; + float dx = (p2->getX() - p1->getX()) / d; + float dy = (p2->getY() - p1->getY()) / d; int error = 0; - float px = float(p1->x); - float py = float(p1->y); + float px = float(p1->getX()); + float py = float(p1->getY()); - bool colorModel = image_->get(p1->x, p1->y); + bool colorModel = image_->get(p1->getX(), p1->getY()); for (int i = 0; i < d; i++) { px += dx; @@ -514,8 +514,8 @@ int Detector::getColor(Ref p1, Ref p2) } Ref Detector::getFirstDifferent(Ref init, bool color, int dx, int dy) { - int x = init->x + dx; - int y = init->y + dy; + int x = init->getX() + dx; + int y = init->getY() + dy; while (isValid(x, y) && image_->get(x, y) == color) { x += dx; @@ -545,5 +545,5 @@ bool Detector::isValid(int x, int y) { } float Detector::distance(Ref a, Ref b) { - return sqrtf((float)((a->x - b->x) * (a->x - b->x) + (a->y - b->y) * (a->y - b->y))); + return sqrtf((float)((a->getX() - b->getX()) * (a->getX() - b->getX()) + (a->getY() - b->getY()) * (a->getY() - b->getY()))); } diff --git a/cpp/core/src/zxing/aztec/detector/Detector.h b/cpp/core/src/zxing/aztec/detector/Detector.h index 200a6a203..65414adbd 100644 --- a/cpp/core/src/zxing/aztec/detector/Detector.h +++ b/cpp/core/src/zxing/aztec/detector/Detector.h @@ -34,21 +34,24 @@ namespace zxing { namespace aztec { class Point : public Counted { -public: - int x; - int y; + private: + const int x; + const int y; + public: Ref toResultPoint() { return Ref(new ResultPoint(float(x), float(y))); } - Point(int ax, int ay):x(ax),y(ay) {}; - + Point(int ax, int ay) : x(ax), y(ay) {} + + int getX() const { return x; } + int getY() const { return y; } }; class Detector : public Counted { -private: + private: Ref image_; bool compact_; @@ -78,7 +81,7 @@ private: bool isValid(int x, int y); static float distance(Ref a, Ref b); -public: + public: Detector(Ref image); Ref detect(); };