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


TypeScript Polyhedron.withChanges方法代码示例

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


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

示例1: removeCap

function removeCap(polyhedron: Polyhedron, cap: Cap) {
  return removeExtraneousVertices(
    polyhedron.withChanges(solid =>
      solid.withoutFaces(cap.faces()).addFaces([cap.boundary().vertices]),
    ),
  );
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:7,代码来源:diminish.ts

示例2: duplicateVertices

function duplicateVertices(
  polyhedron: Polyhedron,
  boundary: VEList,
  twist?: Twist,
) {
  const newVertexMapping = {};
  _.forEach(boundary.edges, (edge, i) => {
    const oppositeFace = edge.twin().face;
    _.forEach(edge.vertices, (v, j) => {
      _.set(
        newVertexMapping,
        [oppositeFace.index, v.index],
        polyhedron.numVertices() + ((i + j) % boundary.numSides),
      );
    });
  });

  return polyhedron.withChanges(solid =>
    solid
      .addVertices(boundary.vertices)
      .mapFaces(face =>
        face.vertices.map(v =>
          _.get(newVertexMapping, [face.index, v.index], v.index),
        ),
      )
      .addFaces(
        _.flatMap(boundary.edges, edge =>
          _.map(getEdgeFacePaths(edge, twist), face =>
            _.map(face, path => _.get(newVertexMapping, path, path[1])),
          ),
        ),
      ),
  );
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:34,代码来源:elongate.ts

示例3: duplicateVertices

function duplicateVertices(polyhedron: Polyhedron) {
  const mapping: NestedRecord<number, number, number> = {};
  const count = polyhedron.getVertex().adjacentFaces().length;
  _.forEach(polyhedron.vertices, v => {
    _.forEach(v.adjacentFaces(), (face, i) => {
      _.set(mapping, [face.index, v.index], i);
    });
  });

  return polyhedron.withChanges(solid => {
    return solid
      .withVertices(_.flatMap(polyhedron.vertices, v => repeat(v.value, count)))
      .mapFaces(face => {
        return _.flatMap(face.vertices, v => {
          const base = count * v.index;
          const j = mapping[face.index][v.index];
          return [base + ((j + 1) % count), base + j];
        });
      })
      .addFaces(
        _.map(polyhedron.vertices, v =>
          _.range(v.index * count, (v.index + 1) * count),
        ),
      );
  });
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:26,代码来源:truncate.ts

示例4: duplicateVertices

/**
 * Duplicate the vertices, so that each face has its own unique set of vertices,
 * and create a new face for each edge and new vertex set.
 */
function duplicateVertices(polyhedron: Polyhedron, twist?: Twist) {
  const count = polyhedron.getVertex().adjacentFaces().length;

  const newVertexMapping: NestedRecord<number, number, number> = {};
  _.forEach(polyhedron.vertices, (v, vIndex: number) => {
    // For each vertex, pick one adjacent face to be the "head"
    // for every other adjacent face, map it to a duplicated vertex
    _.forEach(v.adjacentFaces(), (f, i) => {
      _.set(newVertexMapping, [f.index, v.index], v.index * count + i);
    });
  });

  return polyhedron.withChanges(solid =>
    solid
      .withVertices(_.flatMap(polyhedron.vertices, v => repeat(v.value, count)))
      .mapFaces(face =>
        face.vertices.map(v => newVertexMapping[face.index][v.index]),
      )
      // Add a new face for each original vertex
      .addFaces(
        _.map(polyhedron.vertices, v =>
          _.range(v.index * count, (v.index + 1) * count),
        ),
      )
      // Add a new face for each original edge
      .addFaces(
        _.flatMap(polyhedron.edges, edge =>
          _.map(getEdgeFacePaths(edge, twist), face =>
            _.map(face, path => _.get(newVertexMapping, path)),
          ),
        ),
      ),
  );
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:38,代码来源:expand.ts

示例5: removeExtraneousVertices

export function removeExtraneousVertices(polyhedron: Polyhedron) {
  // Vertex indices to remove
  const vertsInFaces = _.flatMap(polyhedron.faces, 'vertices');
  const toRemove = _.filter(polyhedron.vertices, v => !v.inSet(vertsInFaces));
  const numToRemove = toRemove.length;

  // Map the `numToRemove` last vertices of the polyhedron (that don't overlap)
  // to the first few removed vertices
  const newToOld = _(polyhedron.vertices)
    .takeRight(numToRemove)
    .filter(v => !v.inSet(toRemove))
    .map((v, i) => [v.index, toRemove[i].index])
    .fromPairs()
    .value();
  const oldToNew = _.invert(newToOld);

  const newVertices = _(polyhedron.vertices)
    .map(v => polyhedron.vertices[_.get(oldToNew, v.index, v.index) as any])
    .dropRight(numToRemove)
    .value();

  return polyhedron.withChanges(solid =>
    solid
      .withVertices(newVertices)
      .mapFaces(face =>
        _.map(face.vertices, v => _.get(newToOld, v.index, v.index)),
      ),
  );
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:29,代码来源:operationUtils.ts

示例6: deduplicateVertices

export function deduplicateVertices(polyhedron: Polyhedron) {
  // group vertex indices by same
  const unique: Vertex[] = [];
  const oldToNew: Record<number, number> = {};

  _.forEach(polyhedron.vertices, (v, vIndex: number) => {
    const match = _.find(unique, point =>
      v.vec.equalsWithTolerance(point.vec, PRECISION),
    );
    if (match === undefined) {
      unique.push(v);
      oldToNew[vIndex] = vIndex;
    } else {
      oldToNew[vIndex] = match.index;
    }
  });

  if (_.isEmpty(oldToNew)) return polyhedron;

  // replace vertices that are the same
  let newFaces = _(polyhedron.faces)
    .map(face => _.uniq(face.vertices.map(v => oldToNew[v.index])))
    .filter(vIndices => vIndices.length >= 3)
    .value();

  // remove extraneous vertices
  return removeExtraneousVertices(
    polyhedron.withChanges(s => s.withFaces(newFaces)),
  );
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:30,代码来源:makeOperation.ts

示例7: doAugment

// Augment the following
function doAugment(
  polyhedron: Polyhedron,
  base: Face,
  augmentType: string,
  gyrate?: string,
) {
  const numSides = base.numSides;
  const augmentee = getAugmentee(augmentType, numSides);
  const underside = augmentee.faceWithNumSides(base.numSides);

  // Determine the orientations of the underside and the base
  const undersideRadius = underside.vertices[0].vec
    .sub(underside.centroid())
    .getNormalized();

  const baseIsAligned = isAligned(
    polyhedron,
    base,
    underside,
    isFastigium(augmentType, numSides) ? 'gyro' : gyrate,
    augmentType,
  );
  const offset = baseIsAligned ? 0 : 1;
  const baseRadius = base.vertices[offset].vec
    .sub(base.centroid())
    .getNormalized();

  // https://math.stackexchange.com/questions/624348/finding-rotation-axis-and-angle-to-align-two-oriented-vectors
  // Determine the transformation that rotates the underside orientation to the base orientation
  // TODO we probably want this as some sort of generic method
  const transformMatrix = getOrthonormalTransform(
    undersideRadius,
    underside.normal().getInverted(),
    baseRadius,
    base.normal(),
  );
  const transform = withOrigin(base.centroid(), u =>
    transformMatrix.applyTo(u),
  );

  // Scale and position the augmentee so that it lines up with the base
  const alignedVertices = augmentee.vertices.map(v => {
    return v.vec
      .sub(underside.centroid())
      .scale(base.sideLength() / augmentee.edgeLength())
      .add(base.centroid());
  });

  // Rotate the vertices so that they align with the base
  const rotatedVertices = alignedVertices.map(v => transform(v));

  const newAugmentee = augmentee.withChanges(solid =>
    solid.withVertices(rotatedVertices).withoutFaces([underside]),
  );
  return polyhedron.withChanges(solid =>
    solid.withoutFaces([base]).addPolyhedron(newAugmentee),
  );
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:59,代码来源:augment.ts

示例8: applyGyrate

function applyGyrate(polyhedron: Polyhedron, { cap }: Options) {
  // get adjacent faces
  const boundary = cap.boundary();

  // rotate the cupola/rotunda top
  const theta = TAU / boundary.numSides;

  const oldToNew = mapObject(boundary.vertices, (vertex, i) => [
    vertex.index,
    i,
  ]);

  const mockPolyhedron = polyhedron.withChanges(solid =>
    solid.addVertices(boundary.vertices).mapFaces(face => {
      if (face.inSet(cap.faces())) {
        return face;
      }
      return face.vertices.map(v => {
        return v.inSet(boundary.vertices)
          ? polyhedron.numVertices() + oldToNew[v.index]
          : v.index;
      });
    }),
  );

  const endVertices = getTransformedVertices(
    [cap],
    p =>
      withOrigin(p.normalRay(), v => v.getRotatedAroundAxis(p.normal(), theta)),
    mockPolyhedron.vertices,
  );

  // TODO the animation makes the cupola shrink and expand.
  // Make it not do that.
  return {
    animationData: {
      start: mockPolyhedron,
      endVertices,
    },
  };
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:41,代码来源:gyrate.ts

示例9: duplicateVertices

function duplicateVertices(polyhedron: Polyhedron, facesTosharpen: Face[]) {
  const offset = polyhedron.numVertices();
  const mapping: NestedRecord<number, number, any> = {};
  _.forEach(polyhedron.vertices, vertex => {
    const v = vertex.index;
    const v2 = v + offset;
    const values = [v, [v2, v], v2, [v, v2]];

    const faces = getShiftedAdjacentFaces(vertex, facesTosharpen);
    _.forEach(faces, (f, i) => {
      _.set(mapping, [f.index, v], values[i]);
    });
  });

  // Double the amount of vertices
  return polyhedron.withChanges(solid =>
    solid.addVertices(polyhedron.vertices).mapFaces(f => {
      return _.flatMapDeep(f.vertices, v => mapping[f.index][v.index]);
    }),
  );
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:21,代码来源:sharpen.ts

示例10: bisectPrismFaces

function bisectPrismFaces(
  polyhedron: Polyhedron,
  boundary: VEList,
  twist?: Twist,
) {
  const prismFaces = _.map(boundary.edges, edge => edge.twinFace());
  const newFaces = _.flatMap(boundary.edges, edge => {
    const twinFace = edge.twinFace();
    const [v1, v2, v3, v4] = pivot(
      _.map(twinFace.vertices, 'index'),
      edge.v2.index,
    );

    return twist === 'left'
      ? [[v1, v2, v4], [v2, v3, v4]]
      : [[v1, v2, v3], [v1, v3, v4]];
  });

  return polyhedron.withChanges(solid =>
    solid.withoutFaces(prismFaces).addFaces(newFaces),
  );
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:22,代码来源:turn.ts


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