當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fp.isFinite函數代碼示例

本文整理匯總了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 };
      },
開發者ID:wikipathways,項目名稱:gpml2pvjson-js,代碼行數:59,代碼來源:group.ts

示例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 };
}
開發者ID:wikipathways,項目名稱:gpml2pvjson-js,代碼行數:53,代碼來源:edge.ts

示例3:

 .filter(dims => !isFinite(dims[1]));
開發者ID:wikipathways,項目名稱:gpml2pvjson-js,代碼行數:1,代碼來源:group.ts

示例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;

//.........這裏部分代碼省略.........
開發者ID:wikipathways,項目名稱:gpml2pvjson-js,代碼行數:101,代碼來源:group.ts

示例5: validateOrientation

export function validateOrientation(orientation: Orientation): boolean {
  return !!orientation && isFinite(orientation[0]) && isFinite(orientation[1]);
}
開發者ID:wikipathways,項目名稱:gpml2pvjson-js,代碼行數:3,代碼來源:orientation.ts


注:本文中的lodash/fp.isFinite函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。