forked from makiuchi-d/gozxing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alignment_pattern.go
34 lines (28 loc) · 938 Bytes
/
alignment_pattern.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package detector
import (
"math"
"github.com/kaxap/gozxing"
)
type AlignmentPattern struct {
gozxing.ResultPoint
estimatedModuleSize float64
}
func NewAlignmentPattern(posX, posY, estimatedModuleSize float64) *AlignmentPattern {
return &AlignmentPattern{
gozxing.NewResultPoint(posX, posY),
estimatedModuleSize,
}
}
func (a *AlignmentPattern) AboutEquals(moduleSize, i, j float64) bool {
if math.Abs(i-a.GetY()) <= moduleSize && math.Abs(j-a.GetX()) <= moduleSize {
moduleSizeDiff := math.Abs(moduleSize - a.estimatedModuleSize)
return moduleSizeDiff <= 1.0 || moduleSizeDiff <= a.estimatedModuleSize
}
return false
}
func (a *AlignmentPattern) CombineEstimate(i, j, newModuleSize float64) *AlignmentPattern {
combinedX := (a.GetX() + j) / 2
combinedY := (a.GetY() + i) / 2
combinedModuleSize := (a.estimatedModuleSize + newModuleSize) / 2
return NewAlignmentPattern(combinedX, combinedY, combinedModuleSize)
}