本文整理汇总了TypeScript中lodash.clamp函数的典型用法代码示例。如果您正苦于以下问题:TypeScript clamp函数的具体用法?TypeScript clamp怎么用?TypeScript clamp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clamp函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: movePlant
export function movePlant(payload: MovePlantProps) {
const tr = payload.plant;
const update = defensiveClone(payload.plant).body;
update.x += payload.deltaX;
update.y += payload.deltaY;
update.x = clamp(update.x, 0, payload.gridSize.x);
update.y = clamp(update.y, 0, payload.gridSize.y);
return edit(tr, update);
}
示例2: interpolateValue
// @Override
interpolateValue(start: string, end: string, f: number) {
if (!start || !end) {
return undefined;
}
const s = ColorUtil.parseAndroidColor(start);
const e = ColorUtil.parseAndroidColor(end);
return ColorUtil.toAndroidString({
r: _.clamp(Math.round(MathUtil.lerp(s.r, e.r, f)), 0, 0xff),
g: _.clamp(Math.round(MathUtil.lerp(s.g, e.g, f)), 0, 0xff),
b: _.clamp(Math.round(MathUtil.lerp(s.b, e.b, f)), 0, 0xff),
a: _.clamp(Math.round(MathUtil.lerp(s.a, e.a, f)), 0, 0xff),
});
}
示例3: while
static *tween(duration: number, effectFactory: (t: number) => Effect) {
let accumulation = 0
while (accumulation < duration) {
const { delta }: actions.Tick = yield take(actions.A.Tick)
accumulation += delta
yield effectFactory(clamp(accumulation / duration, 0, 1))
}
}
示例4: parseLevel
export function parseLevel(level: Level|number|string): Level {
level = +level;
if (isNaN(level)) {
return 0;
}
return _.clamp(+level, 0, 16) as Level;
}
示例5:
export function createItemStack<I extends Item>(
item: I, stackAmount: number, maxStackAmount = stackAmount
): ItemStack<I> {
return {
item,
maxStackAmount,
stackAmount: _.clamp(stackAmount, 0, maxStackAmount)
};
}
示例6: getWorkspaceById
const setStageZoom = (state: ApplicationState, workspaceId: string, zoom: number, smooth: boolean = true) => {
const workspace = getWorkspaceById(state, workspaceId);
return updateWorkspaceStage(state, workspace.$id, {
smooth,
translate: centerTransformZoom(
workspace.stage.translate, workspace.stage.container.getBoundingClientRect(),
clamp(zoom, MIN_ZOOM, MAX_ZOOM),
workspace.stage.mousePosition
)
});
};
示例7: function
export default function(t: number, cols: tinycolorInstance[], hsv?: boolean) {
var c = cols.length - 1; t = t * c; if (c === 0) return cols[0];
var i = _.clamp(Math.floor(t), 0, c-1); t = t - i;
var a = cols[i], b = cols[i+1], lerp = function(s: number, e: number) { return (1-t)*s+t*e; };
if (hsv) {
let s = a.toHsv(), e = b.toHsv();
return tinycolor({h: lerp(s.h, e.h), s: lerp(s.s, e.s), v: lerp(s.v, e.v)});
} else {
let s = a.toRgb(), e = b.toRgb();
return tinycolor({r: lerp(s.r, e.r), g: lerp(s.g, e.g), b: lerp(s.b, e.b)});
}
};
示例8: changeStats
export function changeStats(
stats: Stats, changes: PartialStats,
min: Stats = { health: 0, agility: 0, intelligence: 0, strength: 0 },
max: Stats = { health: Infinity, agility: Infinity, intelligence: Infinity, strength: Infinity }
): Stats {
const completeChange = partialStatsToCompleteStats(changes);
stats.health = _.clamp(
stats.health + completeChange.health, min.health, max.health
);
stats.strength = _.clamp(
stats.strength + completeChange.strength, min.strength, max.strength
);
stats.intelligence = _.clamp(
stats.intelligence + completeChange.intelligence, min.intelligence, max.intelligence
);
stats.agility = _.clamp(
stats.agility + completeChange.agility, min.agility, max.agility
);
return stats;
}
示例9: setEditableValue
// @Override
setEditableValue(model: any, propertyName: string, value: string | number | undefined) {
if (typeof value !== 'number') {
value = parseFloat(value);
}
if (isNaN(value)) {
return;
}
value = _.clamp(value, this.min, this.max);
if (this.isInteger) {
value = Math.floor(value);
}
model[propertyName] = value;
}
示例10: setter
// @Override
protected setter(model: any, propertyName: string, value: string | number | undefined) {
if (typeof value === 'string') {
value = Number(value);
}
if (typeof value === 'number') {
if (!isNaN(value)) {
value = _.clamp(value, this.min, this.max);
if (this.isInteger) {
value = Math.floor(value);
}
}
}
model[`${propertyName}_`] = value;
}