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


TypeScript Path.getSubPaths方法代码示例

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


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

示例3:

 const deleteCollapsingSubPathsFn = (p: Path) => {
   return p.getSubPaths().some(s => s.isCollapsing())
     ? p
         .mutate()
         .deleteCollapsingSubPaths()
         .build()
     : p;
 };
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:8,代码来源: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: 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.getSubPaths方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。