本文整理汇总了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);
}
开发者ID:FarmBot,项目名称:Farmbot-Web-API,代码行数:9,代码来源:actions.ts
示例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),
});
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:14,代码来源:ColorProperty.ts
示例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))
}
}
开发者ID:socoolxin,项目名称:battle-city,代码行数:8,代码来源:Timing.ts
示例4: parseLevel
export function parseLevel(level: Level|number|string): Level {
level = +level;
if (isNaN(level)) {
return 0;
}
return _.clamp(+level, 0, 16) as Level;
}
开发者ID:bgotink,项目名称:IngressIdentity,代码行数:8,代码来源:util.ts
示例5:
export function createItemStack<I extends Item>(
item: I, stackAmount: number, maxStackAmount = stackAmount
): ItemStack<I> {
return {
item,
maxStackAmount,
stackAmount: _.clamp(stackAmount, 0, maxStackAmount)
};
}
开发者ID:zthomae,项目名称:xanadu,代码行数:9,代码来源:item.ts
示例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
)
});
};
开发者ID:cryptobuks,项目名称:tandem,代码行数:11,代码来源:index.ts
示例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)});
}
};
开发者ID:UnlitStudio,项目名称:PlazaPlus,代码行数:12,代码来源:colorLerp.ts
示例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;
}
开发者ID:zthomae,项目名称:xanadu,代码行数:22,代码来源:stats.ts
示例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;
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:14,代码来源:NumberProperty.ts
示例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;
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:15,代码来源:NumberProperty.ts
注:本文中的lodash.clamp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论