• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript paths.Path类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中app/model/paths.Path的典型用法代码示例。如果您正苦于以下问题:TypeScript Path类的具体用法?TypeScript Path怎么用?TypeScript Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Path类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: autoAddCollapsingSubPaths

export function autoAddCollapsingSubPaths(from: Path, to: Path): [Path, Path] {
  const deleteCollapsingSubPathsFn = (p: Path) => {
    return p.getSubPaths().some(s => s.isCollapsing())
      ? p
          .mutate()
          .deleteCollapsingSubPaths()
          .build()
      : p;
  };
  from = deleteCollapsingSubPathsFn(from);
  to = deleteCollapsingSubPathsFn(to);

  const numFrom = from.getSubPaths().length;
  const numTo = to.getSubPaths().length;
  if (numFrom === numTo) {
    return [from, to];
  }
  // TODO: allow the user to specify the location of collapsing paths?
  const pm = (numFrom < numTo ? from : to).mutate();
  for (let subIdx = Math.min(numFrom, numTo); subIdx < Math.max(numFrom, numTo); subIdx++) {
    const opp = numFrom < numTo ? to : from;
    const pole = opp.getPoleOfInaccessibility(subIdx);
    pm.addCollapsingSubPath(pole, opp.getSubPath(subIdx).getCommands().length);
  }
  if (numFrom < numTo) {
    from = pm.build();
  } else {
    to = pm.build();
  }
  return [from, to];
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:31,代码来源:AutoAwesome.ts


示例2:

 const deleteCollapsingSubPathsFn = (p: Path) => {
   return p.getSubPaths().some(s => s.isCollapsing())
     ? p
         .mutate()
         .deleteCollapsingSubPaths()
         .build()
     : p;
 };
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:8,代码来源:AutoAwesome.ts


示例3: autoConvert

export function autoConvert(from: Path, to: Path): [Path, Path] {
  [from, to] = autoUnconvertSubPaths(from, to);
  const numFrom = from.getSubPaths().length;
  const numTo = to.getSubPaths().length;
  for (let subIdx = 0; subIdx < Math.min(numFrom, numTo); subIdx++) {
    // Only auto convert when the number of commands in both canvases
    // are equal. Otherwise we'll wait for the user to add more points.
    [from, to] = autoConvertSubPath(from, to, subIdx);
  }
  return [from, to];
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:11,代码来源:AutoAwesome.ts


示例4: align

 const alignmentInfos = fromPaths.map(generatedFromPath => {
   const fromCmds = generatedFromPath.getSubPath(subIdx).getCommands();
   const toCmds = to.getSubPath(subIdx).getCommands();
   return {
     generatedFromPath,
     alignment: align(fromCmds, toCmds, getScoreFn),
   };
 });
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:8,代码来源:AutoAwesome.ts


示例5: interpolateValue

 // @Override
 interpolateValue(start: Path, end: Path, fraction: number) {
   if (!start || !end || !start.isMorphableWith(end) || !fraction) {
     return start;
   }
   if (fraction === 1) {
     return end;
   }
   return PathUtil.interpolate(start, end, fraction);
 }
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:10,代码来源:PathProperty.ts


示例6: autoFix

export function autoFix(from: Path, to: Path): [Path, Path] {
  [from, to] = autoUnconvertSubPaths(from, to);
  [from, to] = autoAddCollapsingSubPaths(from, to);
  [from, to] = orderSubPaths(from, to);

  const min = Math.min(from.getSubPaths().length, to.getSubPaths().length);
  for (let subIdx = 0; subIdx < min; subIdx++) {
    // Pass the command with the larger subpath as the 'from' command.
    const numFromCmds = from.getSubPath(subIdx).getCommands().length;
    const numToCmds = to.getSubPath(subIdx).getCommands().length;
    const shouldSwap = numFromCmds < numToCmds;
    if (shouldSwap) {
      [from, to] = [to, from];
    }
    [from, to] = alignSubPath(from, to, subIdx);
    if (shouldSwap) {
      [from, to] = [to, from];
    }
  }
  for (let subIdx = 0; subIdx < min; subIdx++) {
    [from, to] = permuteSubPath(from, to, subIdx);
  }
  return [from, to];
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:24,代码来源:AutoAwesome.ts


示例7: permuteSubPath

function permuteSubPath(from: Path, to: Path, subIdx: number): [Path, Path] {
  if (from.isClockwise(subIdx) !== to.isClockwise(subIdx)) {
    // Make sure the paths share the same direction.
    to = to
      .mutate()
      .reverseSubPath(subIdx)
      .build();
  }

  // Create and return a list of reversed and shifted from paths to test.
  // Each generated 'from path' will be aligned with the target 'to path'.
  const fromPaths: Path[] = [from];
  if (from.getSubPath(subIdx).isClosed()) {
    for (let i = 1; i < from.getSubPath(subIdx).getCommands().length - 1; i++) {
      // TODO: we need to find a way to reduce the number of paths to try.
      fromPaths.push(
        from
          .mutate()
          .shiftSubPathBack(subIdx, i)
          .build(),
      );
    }
  }

  let bestFromPath = from;
  let min = Infinity;
  for (const fromPath of fromPaths) {
    const fromCmds = fromPath.getSubPath(subIdx).getCommands();
    let sumOfSquares = 0;
    const toCmds = to.getSubPath(subIdx).getCommands();
    fromCmds.forEach(
      (c, cmdIdx) => (sumOfSquares += MathUtil.distance(c.end, toCmds[cmdIdx].end) ** 2),
    );
    if (sumOfSquares < min) {
      min = sumOfSquares;
      bestFromPath = fromPath;
    }
  }

  return [bestFromPath, to];
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:41,代码来源:AutoAwesome.ts


示例8: autoConvertSubPath

function autoConvertSubPath(from: Path, to: Path, subIdx: number): [Path, Path] {
  const numFrom = from.getSubPath(subIdx).getCommands().length;
  const numTo = to.getSubPath(subIdx).getCommands().length;
  if (numFrom !== numTo) {
    // Only auto convert when the number of commands in both subpaths are equal.
    return [from, to];
  }
  const fromPm = from.mutate();
  const toPm = to.mutate();
  for (let cmdIdx = 0; cmdIdx < numFrom; cmdIdx++) {
    const fromCmd = from.getCommand(subIdx, cmdIdx);
    const toCmd = to.getCommand(subIdx, cmdIdx);
    if (fromCmd.type === toCmd.type) {
      continue;
    }
    if (fromCmd.canConvertTo(toCmd.type)) {
      fromPm.convertCommand(subIdx, cmdIdx, toCmd.type);
    } else if (toCmd.canConvertTo(fromCmd.type)) {
      toPm.convertCommand(subIdx, cmdIdx, fromCmd.type);
    }
  }
  return [fromPm.build(), toPm.build()];
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:23,代码来源:AutoAwesome.ts


示例9: orderSubPaths

/**
 * Reorders the subpaths in each path to minimize the distance each shape will
 * travel during the morph.
 */
function orderSubPaths(from: Path, to: Path): [Path, Path] {
  if (from.getSubPaths().length > 8 || to.getSubPaths().length > 8) {
    // Don't attempt to order paths with many subpaths.
    return [from, to];
  }

  const shouldSwap = from.getSubPaths().length < to.getSubPaths().length;
  if (shouldSwap) {
    [from, to] = [to, from];
  }

  const fromSubPaths = from.getSubPaths();
  const toSubPaths = to.getSubPaths();

  const distances = fromSubPaths.map((f, i) => {
    return toSubPaths.map((t, j) => {
      const pole1 = from.getPoleOfInaccessibility(i);
      const pole2 = to.getPoleOfInaccessibility(j);
      return MathUtil.distance(pole1, pole2);
    });
  });

  let min = Infinity;
  let best: number[] = [];

  (function recurseFn(arr: number[], order: number[] = []) {
    if (order.length === toSubPaths.length) {
      let sum = 0;
      for (let i = 0; i < order.length; i++) {
        sum += distances[order[i]][i];
      }
      if (sum < min) {
        min = sum;
        best = order;
      }
      return;
    }
    for (let i = 0; i < arr.length; i++) {
      const [cur] = arr.splice(i, 1);
      recurseFn([...arr], [...order, cur]);
      if (arr.length) {
        arr.splice(i, 0, cur);
      }
    }
  })(_.range(fromSubPaths.length));

  const pm = from.mutate();
  for (let i = 0; i < best.length; i++) {
    const m = best[i];
    pm.moveSubPath(m, i);
    for (let j = i + 1; j < best.length; j++) {
      const n = best[j];
      if (n < m) {
        best[j]++;
      }
    }
  }
  from = pm.build();

  if (shouldSwap) {
    [from, to] = [to, from];
  }

  return [from, to];
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:69,代码来源:AutoAwesome.ts



注:本文中的app/model/paths.Path类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript paths.PathUtil类代码示例发布时间:2022-05-25
下一篇:
TypeScript layers.LayerUtil类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap