Пример #1
0
 public void calcAverageBondLength() {
   double total = 0;
   for (int i = 0; i < molecule.countBonds(); i++) {
     Bond bond = molecule.getBond(i);
     total +=
         GeometryTools.calcDistance(
             new Point2D(bond.getSource().getX(), bond.getSource().getY()),
             new Point2D(bond.getTarget().getX(), bond.getTarget().getY()));
   }
   renderer.getRendererModel().setDefaultBondLength(total / molecule.countBonds());
 }
Пример #2
0
  public Bond getClosestBond(Point2D graphCord) {
    Bond closestBond = null;
    double closestDistance = Double.MAX_VALUE;
    for (int i = 0; i < molecule.countBonds(); i++) {
      Bond currentBond = molecule.getBond(i);
      Point2D currentCenterGraph =
          realCordToGraphCord(
              new Point2D(
                  (currentBond.getSource().getX() + currentBond.getTarget().getX()) / 2,
                  (currentBond.getSource().getY() + currentBond.getTarget().getY()) / 2));

      double distance = GeometryTools.calcDistance(graphCord, currentCenterGraph);

      if (distance <= renderer.getRendererModel().getAtomRadius() && distance < closestDistance) {
        closestBond = currentBond;
        closestDistance = distance;
      }
    }

    return closestBond;
  }