March 05, 2021, 07:12:01 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Like stats
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] Box, Box2 (bb & bmax) by CS_TBL [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Box, Box2 (bb & bmax) by CS_TBL [ 1+ years ago ] (Read 493 times)
BlitzBot
Jr. Member
Posts: 1
Total likes: 0
[bb] Box, Box2 (bb & bmax) by CS_TBL [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:42 AM »
Title :
Box, Box2 (bb & bmax)
Author :
CS_TBL
Posted :
1+ years ago
Description :
Box is a normal modulo, to keep any value within the 0..modulo range, but including negative values!
Box2 is nearly the same, except that it keeps a value within the given lo..hi range.
hm... example
if this is the range for box2: -4,2 then this is what the values -5..5 give:
1
-4
-3
-2
-1
0
1
-4
-3
-2
-1
Box works similary, except that its range is always 0..modulo, so -5..5 at a Box(<value>,3)would look like:
1
2
0
1
2
0
1
2
0
1
2
People who work with banks, pixmaps and other memchunks that can't go beyond the bounds will prolly see most use of all this, esp. when used for drawing graphics in such.
Code :
Code: BlitzBasic
bmax:
Function
Box:
Int
(
value:
Int
,modulo:
Int
)
If
modulo<
1
modulo=
1
Return
(
(
value
Mod
modulo
)
+modulo
)
Mod
modulo
End Function
Function
Box2:
Int
(
value:
Int
,lo:
Int
,hi:
Int
)
Local
o:
Int
If
lo>hi
o=lo
lo=hi
hi=o
EndIf
Local
Modulo:
Int
=hi-lo
value:-lo
If
modulo<
1
modulo=
1
Return
lo+
(
(
value
Mod
modulo
)
+modulo
)
Mod
modulo
End Function
non-bmax:
Function
Box
(
value,modulo
)
If
modulo<
1
modulo=
1
Return
(
(
value
Mod
modulo
)
+modulo
)
Mod
modulo
End Function
Function
Box2
(
value,lo,hi
)
If
lo>hi
o=lo
lo=hi
hi=o
EndIf
Modulo=hi-lo
value=value-lo
If
modulo<
1
modulo=
1
Return
lo+
(
(
value
Mod
modulo
)
+modulo
)
Mod
modulo
End Function
Comments :
N(Posted 1+ years ago)
I think this is known as 'clamping', actually.Or maybe 'looping' if the term wasn't already reserved for, well, loops.Hm... I still like clamping, since it's clamping the value within a range.
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] Box, Box2 (bb & bmax) by CS_TBL [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal