MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / Distance

Method Distance

testutil/image_hash.go:81–99  ·  view source on GitHub ↗

Distance calculates the distance between two hashes Returns error if hash types don't match

(other *ImageHash)

Source from the content-addressed store, hash-verified

79// Distance calculates the distance between two hashes
80// Returns error if hash types don't match
81func (h *ImageHash) Distance(other *ImageHash) (float32, error) {
82 if h.hashType != other.hashType {
83 return 0, fmt.Errorf("cannot compare hash type %d with %d", h.hashType, other.hashType)
84 }
85
86 switch h.hashType {
87 case HashTypeSHA256:
88 if h.sha256Hash == other.sha256Hash {
89 return 0, nil
90 }
91 return 1, nil
92
93 case HashTypeDct:
94 return h.dctHashDistance(other), nil
95
96 default:
97 return 0, fmt.Errorf("unsupported hash type: %d", h.hashType)
98 }
99}
100
101// Dump writes the hash to a writer
102// Format: [1 byte: type][variable: hash data]

Callers 10

TestDCT2HashCalcMethod · 0.80
TestSHA256HashCalcMethod · 0.80
ImageMatchesMethod · 0.80
computeDistMethod · 0.80
TestSvgSuiteMethod · 0.80
TestRotateFlipMethod · 0.80

Calls 2

dctHashDistanceMethod · 0.95
ErrorfMethod · 0.80

Tested by 9

TestDCT2HashCalcMethod · 0.64
TestSHA256HashCalcMethod · 0.64
computeDistMethod · 0.64
TestSvgSuiteMethod · 0.64
TestRotateFlipMethod · 0.64