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

AlignmentPattern.cs 2.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2007 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. using System;
  17. namespace ZXing.QrCode.Internal
  18. {
  19. /// <summary> <p>Encapsulates an alignment pattern, which are the smaller square patterns found in
  20. /// all but the simplest QR Codes.</p>
  21. ///
  22. /// </summary>
  23. /// <author> Sean Owen
  24. /// </author>
  25. /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
  26. /// </author>
  27. public sealed class AlignmentPattern : ResultPoint
  28. {
  29. private float estimatedModuleSize;
  30. internal AlignmentPattern(float posX, float posY, float estimatedModuleSize)
  31. : base(posX, posY)
  32. {
  33. this.estimatedModuleSize = estimatedModuleSize;
  34. }
  35. /// <summary> <p>Determines if this alignment pattern "about equals" an alignment pattern at the stated
  36. /// position and size -- meaning, it is at nearly the same center with nearly the same size.</p>
  37. /// </summary>
  38. internal bool aboutEquals(float moduleSize, float i, float j)
  39. {
  40. if (Math.Abs(i - Y) <= moduleSize && Math.Abs(j - X) <= moduleSize)
  41. {
  42. float moduleSizeDiff = Math.Abs(moduleSize - estimatedModuleSize);
  43. return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize;
  44. }
  45. return false;
  46. }
  47. /// <summary>
  48. /// Combines this object's current estimate of a finder pattern position and module size
  49. /// with a new estimate. It returns a new {@code FinderPattern} containing an average of the two.
  50. /// </summary>
  51. /// <param name="i">The i.</param>
  52. /// <param name="j">The j.</param>
  53. /// <param name="newModuleSize">New size of the module.</param>
  54. /// <returns></returns>
  55. internal AlignmentPattern combineEstimate(float i, float j, float newModuleSize)
  56. {
  57. float combinedX = (X + j) / 2.0f;
  58. float combinedY = (Y + i) / 2.0f;
  59. float combinedModuleSize = (estimatedModuleSize + newModuleSize) / 2.0f;
  60. return new AlignmentPattern(combinedX, combinedY, combinedModuleSize);
  61. }
  62. }
  63. }