AlignmentPattern.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
  2. /*
  3. * AlignmentPattern.cpp
  4. * zxing
  5. *
  6. * Created by Christian Brunschen on 13/05/2008.
  7. * Copyright 2008 ZXing authors All rights reserved.
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */
  21. #include <zxing/qrcode/detector/AlignmentPattern.h>
  22. using std::abs;
  23. using zxing::Ref;
  24. using zxing::qrcode::AlignmentPattern;
  25. AlignmentPattern::AlignmentPattern(float posX, float posY, float estimatedModuleSize) :
  26. ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize) {
  27. }
  28. bool AlignmentPattern::aboutEquals(float moduleSize, float i, float j) const {
  29. if (abs(i - getY()) <= moduleSize && abs(j - getX()) <= moduleSize) {
  30. float moduleSizeDiff = abs(moduleSize - estimatedModuleSize_);
  31. return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize_;
  32. }
  33. return false;
  34. }
  35. Ref<AlignmentPattern> AlignmentPattern::combineEstimate(float i, float j, float newModuleSize) const {
  36. float combinedX = (getX() + j) / 2.0f;
  37. float combinedY = (getY() + i) / 2.0f;
  38. float combinedModuleSize = (estimatedModuleSize_ + newModuleSize) / 2.0f;
  39. Ref<AlignmentPattern> result
  40. (new AlignmentPattern(combinedX, combinedY, combinedModuleSize));
  41. return result;
  42. }