本文整理汇总了TypeScript中lodash/fp.isFinite函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isFinite函数的具体用法?TypeScript isFinite怎么用?TypeScript isFinite使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isFinite函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
function(
{ runningDimensions, topLeftCorner, bottomRightCorner },
entity: PvjsonSingleFreeNode | PvjsonEdge
) {
const { zIndex } = entity;
const zIndexIsFinite = isFinite(zIndex);
const runningDimensionsZIndexIsFinite = isFinite(
runningDimensions.zIndex
);
if (zIndexIsFinite && runningDimensionsZIndexIsFinite) {
runningDimensions.zIndex = Math.min(zIndex, runningDimensions.zIndex);
} else if (zIndexIsFinite) {
runningDimensions.zIndex = zIndex;
}
if (isPvjsonEdge(entity)) {
const points = entity.points;
// If entity is an edge
const firstPoint = points[0];
const firstPointX = firstPoint.x;
const firstPointY = firstPoint.y;
const lastPoint = points[points.length - 1];
const lastPointX = lastPoint.x;
const lastPointY = lastPoint.y;
topLeftCorner.x = Math.min(topLeftCorner.x, firstPointX, lastPointX);
topLeftCorner.y = Math.min(topLeftCorner.y, firstPointY, lastPointY);
bottomRightCorner.x = Math.max(
bottomRightCorner.x,
firstPointX,
lastPointX
);
bottomRightCorner.y = Math.max(
bottomRightCorner.y,
firstPointY,
lastPointY
);
} else {
// If entity is a node
topLeftCorner.x = Math.min(topLeftCorner.x, entity.x);
topLeftCorner.y = Math.min(topLeftCorner.y, entity.y);
bottomRightCorner.x = Math.max(
bottomRightCorner.x,
entity.x + entity.width
);
bottomRightCorner.y = Math.max(
bottomRightCorner.y,
entity.y + entity.height
);
}
runningDimensions.x = topLeftCorner.x - padding - strokeWidth;
runningDimensions.y = topLeftCorner.y - padding - strokeWidth;
runningDimensions.width =
bottomRightCorner.x - topLeftCorner.x + 2 * (padding + strokeWidth);
runningDimensions.height =
bottomRightCorner.y - topLeftCorner.y + 2 * (padding + strokeWidth);
return { runningDimensions, topLeftCorner, bottomRightCorner };
},
示例2: getOffsetAndOrientationScalarsAlongAxis
/**
* getOffsetAndOrientationScalarsAlongAxis
*
* @param relValue {number}
* @param axis {string}
* @param referencedEntity
* @return {OffsetOrientationAndPositionScalarsAlongAxis}
*/
function getOffsetAndOrientationScalarsAlongAxis(
positionScalar: number,
relativeOffsetScalar: number,
axis: "x" | "y",
// TODO are we correctly handling the case of a group as the referenced
// entity? Do we have the group width and height yet to properly calculate
// this?
referencedEntity: PvjsonNode
): OffsetOrientationAndPositionScalarsAlongAxis {
let offsetScalar =
relativeOffsetScalar *
(axis === "x" ? referencedEntity.width : referencedEntity.height);
// TODO WP536 has a referenced entity that lacks width/height. Why?
// The referenced entity was a group.
// Is the problem that the group was nested?
// Or is it a problem with the order of evaluation of entities (trying to
// parse a dependent entity before its dependencies were parsed)?
if (!isFinite(offsetScalar)) {
throw new Error(
`
Got non-finite value ${offsetScalar} for offsetScalar
along ${axis} axis for
getOffsetAndOrientationScalarsAlongAxis(
positionScalar=${positionScalar},
relativeOffsetScalar=${relativeOffsetScalar},
referencedEntity=
${JSON.stringify(referencedEntity, null, " ")}
)
`
);
}
// orientationScalar here refers to the initial direction the edge takes as
// it moves away from the entity to which it is attached.
let orientationScalar;
if (positionScalar === 0) {
orientationScalar = -1;
} else if (positionScalar === 1) {
orientationScalar = 1;
} else {
orientationScalar = 0;
}
return { offsetScalar, orientationScalar, positionScalar };
}
示例3:
.filter(dims => !isFinite(dims[1]));
示例4: getGroupDimensions
export function getGroupDimensions(
padding: number,
strokeWidth: number,
containedEntities: PvjsonEntity[]
): NodeDimensions {
if (containedEntities.length === 0) {
console.warn(`Warning: Empty group observed.`);
return {
x: 0,
y: 0,
width: 0,
height: 0,
zIndex: 0
};
} else if (!isFinite(padding)) {
throw new Error("Invalid padding value: ${padding}");
} else if (!isFinite(strokeWidth)) {
throw new Error("Invalid strokeWidth value: ${strokeWidth}");
}
const dimensions = containedEntities
.filter(entity => isPvjsonSingleFreeNode(entity) || isPvjsonEdge(entity))
.reduce(
function(
{ runningDimensions, topLeftCorner, bottomRightCorner },
entity: PvjsonSingleFreeNode | PvjsonEdge
) {
const { zIndex } = entity;
const zIndexIsFinite = isFinite(zIndex);
const runningDimensionsZIndexIsFinite = isFinite(
runningDimensions.zIndex
);
if (zIndexIsFinite && runningDimensionsZIndexIsFinite) {
runningDimensions.zIndex = Math.min(zIndex, runningDimensions.zIndex);
} else if (zIndexIsFinite) {
runningDimensions.zIndex = zIndex;
}
if (isPvjsonEdge(entity)) {
const points = entity.points;
// If entity is an edge
const firstPoint = points[0];
const firstPointX = firstPoint.x;
const firstPointY = firstPoint.y;
const lastPoint = points[points.length - 1];
const lastPointX = lastPoint.x;
const lastPointY = lastPoint.y;
topLeftCorner.x = Math.min(topLeftCorner.x, firstPointX, lastPointX);
topLeftCorner.y = Math.min(topLeftCorner.y, firstPointY, lastPointY);
bottomRightCorner.x = Math.max(
bottomRightCorner.x,
firstPointX,
lastPointX
);
bottomRightCorner.y = Math.max(
bottomRightCorner.y,
firstPointY,
lastPointY
);
} else {
// If entity is a node
topLeftCorner.x = Math.min(topLeftCorner.x, entity.x);
topLeftCorner.y = Math.min(topLeftCorner.y, entity.y);
bottomRightCorner.x = Math.max(
bottomRightCorner.x,
entity.x + entity.width
);
bottomRightCorner.y = Math.max(
bottomRightCorner.y,
entity.y + entity.height
);
}
runningDimensions.x = topLeftCorner.x - padding - strokeWidth;
runningDimensions.y = topLeftCorner.y - padding - strokeWidth;
runningDimensions.width =
bottomRightCorner.x - topLeftCorner.x + 2 * (padding + strokeWidth);
runningDimensions.height =
bottomRightCorner.y - topLeftCorner.y + 2 * (padding + strokeWidth);
return { runningDimensions, topLeftCorner, bottomRightCorner };
},
{
topLeftCorner: {
x: Infinity,
y: Infinity
},
bottomRightCorner: {
x: 0,
y: 0
},
runningDimensions: {
zIndex: Infinity
}
} as {
topLeftCorner: Corner;
bottomRightCorner: Corner;
runningDimensions: NodeDimensions;
}
).runningDimensions;
//.........这里部分代码省略.........
示例5: validateOrientation
export function validateOrientation(orientation: Orientation): boolean {
return !!orientation && isFinite(orientation[0]) && isFinite(orientation[1]);
}