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


C++ Point2::scale方法代码示例

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


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

示例1: mutate

Fracture* VertPositionMutation::mutate(Fracture* fracture) {
  // get all verts that are not corners
  Array<Vertex*>* nonCorner = new Array<Vertex*>();
  for(int i=0;i<fracture->getVerts()->getSize();i++)
    if(!fracture->getVerts()->get(i)->getIsCorner())
      nonCorner->add(fracture->getVerts()->get(i));
  int numVerts = nonCorner->getSize();
  if(!numVerts) // if only corners return the original fracture
    return fracture;
  // get a random non-boundary vert
  int randVert = RNG::RandomInt(numVerts);
  Vertex* ranVert = nonCorner->get(randVert);
  // get the move amount and distance before making a jump
  real moveLimit = EvolutionSettings::getInstance()->getMaxMovePercent();
  real distBeforeJump = EvolutionSettings::getInstance()->getDistBeforeJump();
  if(ranVert->getBoundary()) {
    // move along boundary line
    Array<Edge*>* boundaryEdges = new Array<Edge*>();
    for(int i=0;i<ranVert->getEdges()->getSize();i++)
      if(ranVert->getEdges()->get(i)->getIsBoundary())
        boundaryEdges->add(ranVert->getEdges()->get(i));
    // choose a random edge to move by
    int randDir = RNG::RandomInt(boundaryEdges->getSize());
    Edge* edgeToMoveBy = boundaryEdges->get(randDir);
    // get the edge length
    real length = edgeToMoveBy->length();
    // if the length is too small move the other direction
    // in the future this is going to check if it can jump i.e
    // it will jump around a corner.
    if(length < distBeforeJump) {
      for(int i=0;i<boundaryEdges->getSize();i++) {
        // this should always work since there should be at least
        // two boundary edges attached
        if(boundaryEdges->get(i)!=edgeToMoveBy) {
          edgeToMoveBy = boundaryEdges->get(i);
          i = boundaryEdges->getSize();
        }
      }
      // recheck length and abort if the check fails
      real length = edgeToMoveBy->length();
      if(length < distBeforeJump)
        return fracture;
    }
    // get a random mutation value
    real mutateScale = RNG::RandomFloat(moveLimit);
    // Get the two points on the edge to move on
    Point2 firstPoint = ranVert->getLocation();
    Point2 secondPoint = edgeToMoveBy->getOtherPoint(ranVert->getID());
    // calculate the vert's new location
    Point2 slope = secondPoint.minus(firstPoint);
    slope.scale(mutateScale);
    Point2 newLoc = firstPoint.add(slope);
    // set the new location
    ranVert->setLocation(newLoc);
    // tell the verts edges about its new location
    ranVert->updateEdges();
    // clean up
    while(boundaryEdges->getSize())
      boundaryEdges->removeLast();
    delete boundaryEdges;
  } else {
    // maybe implement move along edges ???
    // move about faces using barycentric coordinates
    // get the faces containing the point
    Array<Face*>* facesWithVert = fracture->getFacesWithVertex(ranVert);
    // create a face containing all points around the vert
    Face* faceToMutateAround = new Face();
    for(int i=0;i<facesWithVert->getSize();i++) {
      Face* tmp = facesWithVert->get(i);
      for(int j=0;j<tmp->getEdges()->getSize();j++)
        if(!tmp->getEdges()->get(j)->eitherMatch(ranVert->getID()))
          faceToMutateAround->getEdges()->add(tmp->getEdges()->get(j)->copy());
      for(int j=0;j<tmp->getVerts()->getSize();j++)
        if(tmp->getVerts()->get(j)->getID() != ranVert->getID())
          faceToMutateAround->getVerts()->add(tmp->getVerts()->get(j)->copy(faceToMutateAround->getEdges()));
    }
    // create the container for the generated Tris
    Array<Tri*>* generatedTris = new Array<Tri*>();
    // detect if the face is convex or not
    faceToMutateAround->detectIfConvex();
    if(faceToMutateAround->getIsConvex()) {
      // TODO :: Do this the more efficient way
      // convex case mutation (easy)
      // generate tris
      for(int i=0;i<faceToMutateAround->getEdges()->getSize();i++)
        generatedTris->add(new Tri(faceToMutateAround->getEdges()->get(i),ranVert->getLocation(),ranVert->getID()));
      // create barycentric coordinates for mutation (2 * #tris)
      // TODO :: Combine this with the case below
      int numBarys = generatedTris->getSize()*2;
      real barys[numBarys];
      for(int i=0;i<numBarys;i++)
        barys[i] = RNG::RandomFloat(moveLimit);
      // apply mutations
      Point2 newPos;
      newPos.xpos = 0.0;
      newPos.ypos = 0.0;
      int pointID = ranVert->getID();
      for(int i=0;i<generatedTris->getSize();i++) {
        // get new position
        real baryOne = barys[i*2];
//.........这里部分代码省略.........
开发者ID:ZackMisso,项目名称:FractureEvolutionResearch,代码行数:101,代码来源:vertPositionMutation.cpp


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