diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-11 23:46:13 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-11 23:46:13 +0300 |
commit | d36cabcc327d586a13d30c53c579927a4837e4a3 (patch) | |
tree | f25ce540ecad8a9a046c35bf29aae68ceac930b2 /src/ui/util.c | |
parent | 25417c357d46f3ba65d7ac1ef460d52ccea41a9b (diff) |
Integer range utilities
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 9aa634bc..0af33138 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -62,6 +62,19 @@ int keyMods_Sym(int kmods) { | |||
62 | return kmods; | 62 | return kmods; |
63 | } | 63 | } |
64 | 64 | ||
65 | iRangei intersect_Rangei(iRangei a, iRangei b) { | ||
66 | if (a.end < b.start || a.start > b.end) { | ||
67 | return (iRangei){ 0, 0 }; | ||
68 | } | ||
69 | return (iRangei){ iMax(a.start, b.start), iMin(a.end, b.end) }; | ||
70 | } | ||
71 | |||
72 | iRangei union_Rangei(iRangei a, iRangei b) { | ||
73 | if (isEmpty_Rangei(a)) return b; | ||
74 | if (isEmpty_Rangei(b)) return a; | ||
75 | return (iRangei){ iMin(a.start, b.start), iMax(a.end, b.end) }; | ||
76 | } | ||
77 | |||
65 | /*-----------------------------------------------------------------------------------------------*/ | 78 | /*-----------------------------------------------------------------------------------------------*/ |
66 | 79 | ||
67 | void init_Click(iClick *d, iAnyObject *widget, int button) { | 80 | void init_Click(iClick *d, iAnyObject *widget, int button) { |