Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 ActionScript 3 中,是否有更短的方法可以将值剪辑到 0 到 255 之间?
value = Math.min(255, Math.max(0, value))
不,您可以轻松地创建自己的快捷功能:
function clip(val:Number, min:Number, max:Number):Number { return Math.min(max, Math.max(min, val)); }
如果您正在寻找快速的东西,以下将做:
k = (k | -int(k > 256)) & -int(k > 0) & 0xFF;