-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathutil.go
81 lines (70 loc) · 1.63 KB
/
util.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2013-2025 Utkan Güngördü <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"bytes"
"github.com/gotk3/gotk3/gdk"
"github.com/salviati/gomics/archive"
"runtime"
)
func min(a, b int) int {
if a < b {
return a
}
return b
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func wrap(val, low, mod int) int {
val %= mod
if val < low {
val = mod + val
}
return val
}
func clamp(val, low, high float64) float64 {
if val < low {
val = low
} else if val > high {
val = high
}
return val
}
func fit(sw, sh, fw, fh int) (int, int) {
r := float64(sw) / float64(sh)
var nw, nh float64
if float64(fw) >= float64(fh)*r {
nw, nh = float64(fh)*r, float64(fh)
} else {
nw, nh = float64(fw), float64(fw)/r
}
return int(nw), int(nh)
}
func gc() {
// TODO do some checks?
runtime.GC()
runtime.GC()
}
func mustLoadPixbuf(data []byte) *gdk.Pixbuf {
pixbuf, err := archive.LoadPixbuf(bytes.NewBuffer(data), true)
if err != nil {
panic(err.Error())
}
return pixbuf
}