Skip to content

Commit c489a2a

Browse files
committed
Added ThresholdFilter
1 parent ee837db commit c489a2a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

thresh.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package texture
2+
3+
// ThresholdFilter returns B if src < A, and C if equal or greater.
4+
// See also [ThresholdCombiner].
5+
type ThresholdFilter struct {
6+
Name string
7+
Src Field
8+
A, B, C float64
9+
}
10+
11+
func NewThresholdFilter(src Field, a, b, c float64) *ThresholdFilter {
12+
return &ThresholdFilter{"ThresholdFilter", src, a, b, c}
13+
}
14+
15+
// Eval2 implements the Field interface.
16+
func (f *ThresholdFilter) Eval2(x, y float64) float64 {
17+
v := f.Src.Eval2(x, y)
18+
if v < f.A {
19+
return f.B
20+
}
21+
return f.C
22+
}

0 commit comments

Comments
 (0)