You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ZXQRCodeFinderPattern.m 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2012 ZXing authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "ZXQRCodeFinderPattern.h"
  17. @implementation ZXQRCodeFinderPattern
  18. - (id)initWithPosX:(float)posX posY:(float)posY estimatedModuleSize:(float)estimatedModuleSize {
  19. return [self initWithPosX:posX posY:posY estimatedModuleSize:estimatedModuleSize count:1];
  20. }
  21. - (id)initWithPosX:(float)posX posY:(float)posY estimatedModuleSize:(float)estimatedModuleSize count:(int)count {
  22. if (self = [super initWithX:posX y:posY]) {
  23. _estimatedModuleSize = estimatedModuleSize;
  24. _count = count;
  25. }
  26. return self;
  27. }
  28. /*
  29. - (void)incrementCount {
  30. self.count++;
  31. }
  32. */
  33. - (BOOL)aboutEquals:(float)moduleSize i:(float)i j:(float)j {
  34. if (fabsf(i - [self y]) <= moduleSize && fabsf(j - [self x]) <= moduleSize) {
  35. float moduleSizeDiff = fabsf(moduleSize - self.estimatedModuleSize);
  36. return moduleSizeDiff <= 1.0f || moduleSizeDiff <= self.estimatedModuleSize;
  37. }
  38. return NO;
  39. }
  40. - (ZXQRCodeFinderPattern *)combineEstimateI:(float)i j:(float)j newModuleSize:(float)newModuleSize {
  41. int combinedCount = self.count + 1;
  42. float combinedX = (self.count * self.x + j) / combinedCount;
  43. float combinedY = (self.count * self.y + i) / combinedCount;
  44. float combinedModuleSize = (self.count * self.estimatedModuleSize + newModuleSize) / combinedCount;
  45. return [[ZXQRCodeFinderPattern alloc] initWithPosX:combinedX
  46. posY:combinedY
  47. estimatedModuleSize:combinedModuleSize
  48. count:combinedCount];
  49. }
  50. @end