Exemple #1
0
void Metalayout::getBoundRect (Vec2f& min, Vec2f& max, BaseMolecule& mol)
{
   if (mol.vertexCount() == 0)
   {
      min.zero();
      max.zero();
      return;
   }
   const Vec3f& v0 = mol.getAtomXyz(mol.vertexBegin());
   Vec2f::projectZ(min, v0);
   Vec2f::projectZ(max, v0);
   Vec2f v2;
   for (int i = mol.vertexBegin(); i < mol.vertexEnd(); i = mol.vertexNext(i))
   {
      Vec2f::projectZ(v2, mol.getAtomXyz(i));
      min.min(v2);
      max.max(v2);
   }
}
Exemple #2
0
void _getBounds (RenderParams& params, BaseMolecule &mol, Vec2f &min, Vec2f &max, float &scale)
{
   // Compute average bond length
   float avg_bond_length = 1;
   if (mol.edgeCount() > 0)
   {
      float bond_length_sum = 0;
      for (int i = mol.edgeBegin(); i != mol.edgeEnd(); i = mol.edgeNext(i))
      {
         const Edge& edge = mol.getEdge(i);
         const Vec3f &p1 = mol.getAtomXyz(edge.beg);
         const Vec3f &p2 = mol.getAtomXyz(edge.end);
         bond_length_sum += Vec3f::dist(p1, p2);
      }
      avg_bond_length = bond_length_sum / mol.edgeCount();
   }

   float bond_length = 1;
   if (params.cnvOpt.bondLength > 0)
      bond_length = params.cnvOpt.bondLength / 100.0f;

   scale = bond_length / avg_bond_length;

   for (int i = mol.vertexBegin(); i != mol.vertexEnd(); i = mol.vertexNext(i))
   {
      Vec3f &p = mol.getAtomXyz(i);
      Vec2f p2(p.x, p.y);

      if (i == mol.vertexBegin())
         min = max = p2;
      else
      {
         min.min(p2);
         max.max(p2);
      }
   }

   min.scale(scale);
   max.scale(scale);
}