-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstitch.go
48 lines (36 loc) · 1.01 KB
/
stitch.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//go:generate stringer -type=Stitch
// Package buttery provides primitives for manipulating GIF animations.
package buttery
import (
"fmt"
)
// Stitch models a loop continuity strategy.
type Stitch int
const (
// None ends the incoming sequence as-is.
None Stitch = iota
// Mirror follows the end of the incoming sequence by replaying the sequence backwards.
Mirror
// FlipH follows the end of the incoming sequence by replaying the sequence reflected horizontally.
FlipH
// FlipV follows the end of the incoming sequence by replaying the sequence reflected vertically.
FlipV
// Shuffle randomizes the incoming sequence.
Shuffle
)
// ParseStitch generates a Stitch from a string value.
func ParseStitch(s string) (*Stitch, bool) {
for i := None; i <= Shuffle; i++ {
if s == i.String() {
return &i, true
}
}
return nil, false
}
// Validate rejects out of bound values.
func (o Stitch) Validate() error {
if o < None || o > Shuffle {
return fmt.Errorf("invalid stitch value: %d", o)
}
return nil
}