当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Path.getSubPath方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5:

 const applySplitsFn = (path: Path, gapGroups: ReadonlyTable<CmdInfo>) => {
   const splitOps: Array<{
     readonly subIdx: number;
     readonly cmdIdx: number;
     readonly ts: number[];
   }> = [];
   const numPaths = path.getSubPath(subIdx).getCommands().length;
   for (let i = gapGroups.length - 1; i >= 0; i--) {
     const gapGroup = gapGroups[i];
     // Clamp the index between 1 and numCommands - 1 to account for cases
     // where the alignment algorithm attempts to append new commands to the
     // front and back of the sequence.
     const cmdIdx = _.clamp(_.last(gapGroup).nextCmdIdx, 1, numPaths - 1);
     const ts = gapGroup.map((unused, gapIdx) => (gapIdx + 1) / (gapGroup.length + 1));
     splitOps.push({ subIdx, cmdIdx, ts });
   }
   PathUtil.sortPathOps(splitOps);
   const mutator = path.mutate();
   for (const { cmdIdx, ts } of splitOps) {
     mutator.splitCommand(subIdx, cmdIdx, ...ts);
   }
   return mutator.build();
 };
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:23,代码来源:AutoAwesome.ts


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