javax.vecmath.Point2d Java Examples

The following examples show how to use javax.vecmath.Point2d. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the bond of the given molecule that is closest to the given
 * coordinates. See comment for center(IAtomContainer atomCon, Dimension
 * areaDim, HashMap renderingCoordinates) for details on coordinate sets
 *
 * @param xPosition The x coordinate
 * @param yPosition The y coordinate
 * @param atomCon The molecule that is searched for the closest bond
 * @return The bond that is closest to the given coordinates
 */
public static IBond getClosestBond(double xPosition, double yPosition, IAtomContainer atomCon) {
    Point2d bondCenter;
    IBond closestBond = null;

    double smallestMouseDistance = -1;
    double mouseDistance;
    Iterator<IBond> bonds = atomCon.bonds().iterator();
    while (bonds.hasNext()) {
        IBond currentBond = (IBond) bonds.next();
        bondCenter = get2DCenter(currentBond.atoms());
        mouseDistance = Math.sqrt(Math.pow(bondCenter.x - xPosition, 2) + Math.pow(bondCenter.y - yPosition, 2));
        if (mouseDistance < smallestMouseDistance || smallestMouseDistance == -1) {
            smallestMouseDistance = mouseDistance;
            closestBond = currentBond;
        }
    }
    return closestBond;
}
 
Example #2
Source File: DirectBondDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void drawWedge(Point2d p1, Point2d p2, boolean isFilled, Graphics2D g) {
    Vector2d halfWidthVector = new Vector2d(p2.y - p1.y, p1.x - p2.x);
    halfWidthVector.normalize();
    halfWidthVector.scale(params.filledWedgeWidth / 2);
    Vector2d negHalfWidthVector = new Vector2d(halfWidthVector);
    negHalfWidthVector.negate();
    Point2d p2a = displace(p2, halfWidthVector);
    Point2d p2b = displace(p2, negHalfWidthVector);

    if (isFilled) {
        drawFilledWedge(p1, p2a, p2b, g);
    } else {
        drawDashedWedge2(p1, p2a, p2b, g);
    }

}
 
Example #3
Source File: DirectBondDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void drawStereo(Point2d p1, Point2d p2, Stereo stereo, Graphics2D g) {
    if (null != stereo) {
        switch (stereo) {
            case UP_OR_DOWN:
                drawWigglyLine(p1, p2, g);
                break;
            case DOWN:
                drawWedge(p1, p2, false, g);
                break;
            case DOWN_INVERTED:
                drawWedge(p2, p1, false, g);
                break;
            case UP:
                drawWedge(p1, p2, true, g);
                break;
            case UP_INVERTED:
                drawWedge(p2, p1, true, g);
                break;
            // ?
            default:
                break;
        }
    }
}
 
Example #4
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Calculates the center of mass for the <code>Atom</code>s in the
 * AtomContainer for the 2D coordinates. See comment for
 * center(IAtomContainer atomCon, Dimension areaDim, HashMap
 * renderingCoordinates) for details on coordinate sets
 *
 * @param ac AtomContainer for which the center of mass is calculated
 * @return Null, if any of the atomcontainer {@link IAtom}'s masses are null
 * @cdk.keyword center of mass
 */
public static Point2d get2DCentreOfMass(IAtomContainer ac) {
    double xsum = 0.0;
    double ysum = 0.0;

    double totalmass = 0.0;

    Iterator<IAtom> atoms = ac.atoms().iterator();
    while (atoms.hasNext()) {
        IAtom a = (IAtom) atoms.next();
        Double mass = a.getExactMass();
        if (mass == null) {
            return null;
        }
        totalmass += mass;
        xsum += mass * a.getPoint2d().x;
        ysum += mass * a.getPoint2d().y;
    }

    return new Point2d(xsum / totalmass, ysum / totalmass);
}
 
Example #5
Source File: DirectBondDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param bond
 * @param bondRingMap
 * @param g
 */
public void drawBond(
        IBond bond, Map<IBond, IAtomContainer> bondRingMap, Graphics2D g) {
    Point2d p1 = bond.getAtom(0).getPoint2d();
    Point2d p2 = bond.getAtom(1).getPoint2d();
    IBond.Order order = bond.getOrder();
    IBond.Stereo stereo = bond.getStereo();
    if (stereo == NONE
            && (order == SINGLE || bond.getFlag(ISAROMATIC))) {
        drawLine(p1, p2, g);
    } else if (order == DOUBLE) {
        if (bondRingMap.containsKey(bond)) {
            drawLine(p1, p2, g);
        } else {
            drawDoubleBond(p1, p2, g);
        }
    } else if (order == TRIPLE) {
        drawTripleBond(p1, p2, g);
    } else if (stereo != NONE) {
        drawStereo(p1, p2, stereo, g);
    }
}
 
Example #6
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the geometric center of all the atoms in the atomContainer. See
 * comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap
 * renderingCoordinates) for details on coordinate sets
 *
 * @param container Description of the Parameter
 * @return the geometric center of the atoms in this atomContainer
 */
public static Point2d get2DCenter(IAtomContainer container) {
    double centerX = 0;
    double centerY = 0;
    double counter = 0;
    Iterator<IAtom> atoms = container.atoms().iterator();
    while (atoms.hasNext()) {
        IAtom atom = (IAtom) atoms.next();
        if (atom.getPoint2d() != null) {
            centerX += atom.getPoint2d().x;
            centerY += atom.getPoint2d().y;
            counter++;
        }
    }
    return new Point2d(centerX / (counter), centerY / (counter));
}
 
Example #7
Source File: JDOMUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
public static Point2d[] readBounds(final Element boundsEl) {
  if (boundsEl == null) {
    return null;
  }

  final Point2d ll = readPoint(JDOMUtils.tagLL, boundsEl);

  if (ll == null) {
    return null;
  }

  final Point2d ur = readPoint(JDOMUtils.tagUR, boundsEl);

  final Point2d[] bounds = new Point2d[2];
  bounds[0] = ll;
  bounds[1] = ur;

  return bounds;
}
 
Example #8
Source File: JDOMUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
public static Element writePointList(final String tagName, final ArrayList<Point2d> pts) {
  final StringBuffer sb = new StringBuffer();

  final int nPts = pts.size();
  int idx = 0;
  for (final Point2d pt : pts) {
    sb.append(Double.toString(pt.x));
    sb.append(",");
    sb.append(Double.toString(pt.y));

    if (idx < (nPts - 1)) {
      sb.append(",");
    }

    idx++;
  }

  return writeStringVal(tagName, sb.toString());
}
 
Example #9
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the bond of the given molecule that is closest to the given
 * coordinates. See comment for center(IAtomContainer atomCon, Dimension
 * areaDim, HashMap renderingCoordinates) for details on coordinate sets
 *
 * @param xPosition The x coordinate
 * @param yPosition The y coordinate
 * @param atomCon The molecule that is searched for the closest bond
 * @return The bond that is closest to the given coordinates
 */
public static IBond getClosestBond(int xPosition, int yPosition, IAtomContainer atomCon) {
    Point2d bondCenter;
    IBond closestBond = null;

    double smallestMouseDistance = -1;
    double mouseDistance;
    Iterator<IBond> bonds = atomCon.bonds().iterator();
    while (bonds.hasNext()) {
        IBond currentBond = (IBond) bonds.next();
        bondCenter = get2DCenter(currentBond.atoms());
        mouseDistance = Math.sqrt(Math.pow(bondCenter.x - xPosition, 2) + Math.pow(bondCenter.y - yPosition, 2));
        if (mouseDistance < smallestMouseDistance || smallestMouseDistance == -1) {
            smallestMouseDistance = mouseDistance;
            closestBond = currentBond;
        }
    }
    return closestBond;
}
 
Example #10
Source File: DirectBondDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param a
 * @param b
 * @param c
 * @param g
 */
public void drawDashedWedge(Point2d a, Point2d b, Point2d c, Graphics2D g) {
    Stroke savedStroke = g.getStroke();
    g.setStroke(dashedWedgeStroke);
    double distance = b.distance(a);
    double gapFactor = params.dashedGapFactor;
    double gap = distance * gapFactor;
    double numberOfDashes = distance / gap;
    double d = 0;

    // draw by interpolating along the edges of the triangle
    for (int i = 0; i < numberOfDashes; i++) {
        Point2d p1 = new Point2d();
        p1.interpolate(a, b, d);
        Point2d p2 = new Point2d();
        p2.interpolate(a, c, d);

        drawLine(p1, p2, g);
        if (distance * (d + gapFactor) >= distance) {
            break;
        } else {
            d += gapFactor;
        }
    }
    g.setStroke(savedStroke);
}
 
Example #11
Source File: JDOMUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
public static ArrayList<Point2d> readPointList(final Element el) {
  final ArrayList<Point2d> pts = new ArrayList<>();

  final String ptStr = getStringVal(el);
  final StringTokenizer st = new StringTokenizer(ptStr, ",");
  while (st.hasMoreTokens()) {
    try {
      final String xStr = st.nextToken();
      final String yStr = st.nextToken();

      final double x = Double.parseDouble(xStr);
      final double y = Double.parseDouble(yStr);

      pts.add(new Point2d(x, y));
    } catch (final Exception e) {
      LOGGER.warn("error parsing point list", e);

      return null;
    }
  }

  return pts;
}
 
Example #12
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Calculates the center of the given atoms and returns it as a Point2d. See
 * comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap
 * renderingCoordinates) for details on coordinate sets
 *
 * @param atoms The Iterator of the given atoms
 * @return The center of the given atoms as Point2d
 */
public static Point2d get2DCenter(Iterator<IAtom> atoms) {
    IAtom atom;
    double xsum = 0;
    double ysum = 0;
    int length = 0;
    while (atoms.hasNext()) {
        atom = (IAtom) atoms.next();
        if (atom.getPoint2d() != null) {
            xsum += atom.getPoint2d().x;
            ysum += atom.getPoint2d().y;
        }
        ++length;
    }
    return new Point2d(xsum / (double) length, ysum / (double) length);
}
 
Example #13
Source File: ConvexHull.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
         *
         * @param pointOnAB
         * @param cornerC
         * @param cornerD
         * @param distToCD
         */
        public Rectangle(Point2d pointOnAB, Point2d cornerC, Point2d cornerD, double distToCD) {
            pointX = new Point2d(pointOnAB);
            this.cornerC = new Point2d(cornerC);
            this.cornerD = new Point2d(cornerD);
            Vector2d cdVec = new Vector2d(cornerD);
            cdVec.sub(cornerC);
            Vector2d cdVecNormalized = new Vector2d(cdVec);
            if (cdVec.x != 0 && cdVec.y != 0) {
                cdVecNormalized.normalize();
            }
            Vector2d perp = new Vector2d(cdVecNormalized.y, -cdVecNormalized.x);
//            System.out.println(
//                    pointOnAB + " " +  cornerC + " " +  cornerD + " " +  distToCD
//                    + " " +  cdVec + " " +  perp);
            cornerA = new Point2d(cornerD);
            cornerA.scaleAdd(distToCD, perp, cornerA);
            cornerB = new Point2d(cornerC);
            cornerB.scaleAdd(distToCD, perp, cornerB);
        }
 
Example #14
Source File: DirectRBLastReactionDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void drawBondChangeMarks(List<IBond> bondsChanged, Graphics2D g) {
    double markLength = params.bondMarkLength;
    for (IBond bond : bondsChanged) {
        Point2d p1 = bond.getAtom(0).getPoint2d();
        Point2d p2 = bond.getAtom(1).getPoint2d();
        Point2d center = new Point2d(p1);
        center.interpolate(p2, 0.5);

        Vector2d bondVector = new Vector2d(p1);
        bondVector.sub(p2);
        bondVector.normalize();

        Vector2d perp = new Vector2d(-bondVector.y, bondVector.x);
        Vector2d negPerp = new Vector2d(perp);
        negPerp.negate();

        Point2d pp1 = new Point2d(center);
        pp1.scaleAdd(markLength / 2, perp, pp1);
        Point2d pp2 = new Point2d(center);
        pp2.scaleAdd(markLength / 2, negPerp, pp2);

        drawLine(pp1, pp2, g);
    }
}
 
Example #15
Source File: WedgeStereoLifter.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Gets the 'full' angle (between 0&deg; and 360&deg;) between
 *
 * @param atom
 * @param partner1
 * @param partner2
 * @return
 */
private double getFullAngle(IAtom centralAtom, IAtom partner1, IAtom partner2) {
    Point2d atomP = centralAtom.getPoint2d();
    Point2d partner1P = partner1.getPoint2d();
    Point2d partner2P = partner2.getPoint2d();

    double angle1 = atan2((partner1P.y - atomP.y), (partner1P.x - atomP.x));
    double angle2 = atan2((partner2P.y - atomP.y), (partner2P.x - atomP.x));
    double angle = angle2 - angle1;
    if (angle2 < 0 && angle1 > 0 && angle2 < -(PI / 2)) {
        angle = PI + angle2 + PI - angle1;
    }
    if (angle2 > 0 && angle1 < 0 && angle1 < -(PI / 2)) {
        angle = -PI + angle2 - PI - angle1;
    }
    if (angle < 0) {
        return (2 * PI + angle);
    } else {
        return (angle);
    }
}
 
Example #16
Source File: SingleMoleculeLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param atomContainer
 * @param axis
 * @return
 */
@Override
public BoundsTree layout(IAtomContainer atomContainer, Vector2d axis) {
    // XXX axis is used here to mean center point! :( bad design....
    Point2d center = new Point2d(axis);

    if (forceRelayout || !has2DCoordinates(atomContainer)) {
        sdg.setMolecule(new AtomContainer(atomContainer), false);
        try {
            if (isConnected(atomContainer)) {
                sdg.generateCoordinates();
            } else {
                err.println("Disconnected components needs to be layout separately");
            }
        } catch (CDKException e) {
            e.printStackTrace();
        }
    }
    double scale = getScaleFactor(atomContainer, params.bondLength);
    Rectangle2D bounds = getRectangle2D(atomContainer);
    scaleMolecule(atomContainer, scale);
    translateTo(atomContainer, center.x, center.y, bounds);
    String label = atomContainer.getID();
    return new BoundsTree(label, label, bounds);
}
 
Example #17
Source File: LabelManager.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param fromPoint
 * @param toPoint
 * @return
 */
public AnnotationPosition calculateRelativePosition(Point2d fromPoint, Point2d toPoint) {
    Vector2d bondVector = new Vector2d(toPoint);
    bondVector.sub(fromPoint);
    bondVector.normalize();

    double xAng = toDegrees(bondVector.angle(POS_X));
    double yAng = toDegrees(bondVector.angle(POS_Y));
    if (xAng < 22.5 && (yAng > 67.5 && yAng < 115.5)) {
        return E;
    } else if ((xAng > 22.5 && xAng < 67.5) && (yAng > 115.5 && yAng < 155.5)) {
        return NE;
    } else if ((xAng > 67.5 && xAng < 115.5) && (yAng > 155.5)) {
        return N;
    } else if ((xAng > 115.5 && xAng < 155.5) && (yAng > 115.5 && yAng < 155.5)) {
        return NW;
    } else if (xAng > 155.5 && (yAng > 67.5 && yAng < 115.5)) {
        return W;
    } else if ((xAng > 115.5 && xAng < 155.5) && (yAng > 22.5 && yAng < 67.5)) {
        return SW;
    } else if ((xAng > 67.5 && xAng < 115.5) && yAng < 22.5) {
        return S;
    } else if ((xAng > 22.5 && xAng < 67.5) && (yAng > 22.5 && yAng < 67.5)) {
        return SE;
    }

    return E;    // whatever
}
 
Example #18
Source File: EarthVector.java    From geowave with Apache License 2.0 5 votes vote down vote up
/** Point2d (degrees or radians) constructor */
public EarthVector(final Point2d point, final int units) {
  if (units == DEGREES) {
    latitude = degToRad(point.y);
    longitude = degToRad(point.x);
  } else {
    latitude = point.y;
    longitude = point.x;
  }
  elevation = 0.0;

  initVector();
}
 
Example #19
Source File: AbstractDirectReactionLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @return
 */
public Point2d getArrowCenter() {
    if (arrowAxis == X) {
        return new Point2d(arrowPos, getAxisPosition());
    } else {
        return new Point2d(getAxisPosition(), arrowPos);
    }
}
 
Example #20
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the geometric length of this bond in 2D space. See comment for
 * center(IAtomContainer atomCon, Dimension areaDim, HashMap
 * renderingCoordinates) for details on coordinate sets
 *
 * @param bond Description of the Parameter
 * @return The geometric length of this bond
 */
public static double getLength2D(IBond bond) {
    if (bond.getBegin() == null || bond.getEnd() == null) {
        return 0.0;
    }
    Point2d point1 = bond.getBegin().getPoint2d();
    Point2d point2 = bond.getEnd().getPoint2d();
    if (point1 == null || point2 == null) {
        return 0.0;
    }
    return point1.distance(point2);
}
 
Example #21
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Determines the normalized vector orthogonal on the vector p1-&gt;p2.
 *
 * @param point1 Description of the Parameter
 * @param point2 Description of the Parameter
 * @return Description of the Return Value
 */
public static Vector2d calculatePerpendicularUnitVector(Point2d point1, Point2d point2) {
    Vector2d vector = new Vector2d();
    vector.sub(point2, point1);
    vector.normalize();

    // Return the perpendicular vector
    return new Vector2d(-1.0 * vector.y, vector.x);
}
 
Example #22
Source File: DirectReactionDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param reaction
 * @param g
 */
public void drawMappings(IReaction reaction, Graphics2D g) {
    g.setColor(LIGHT_GRAY);
    for (IMapping mapping : reaction.mappings()) {
        IAtom a0 = (IAtom) mapping.getChemObject(0);
        IAtom a1 = (IAtom) mapping.getChemObject(1);
        Point2d p0 = a0.getPoint2d();
        Point2d p1 = a1.getPoint2d();
        g.drawLine((int) p0.x, (int) p0.y, (int) p1.x, (int) p1.y);
    }
}
 
Example #23
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the geometric center of all the rings in this ringset. See
 * comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap
 * renderingCoordinates) for details on coordinate sets
 *
 * @param ringSet Description of the Parameter
 * @return the geometric center of the rings in this ringset
 */
public static Point2d get2DCenter(IRingSet ringSet) {
    double centerX = 0;
    double centerY = 0;
    for (int i = 0; i < ringSet.getAtomContainerCount(); i++) {
        Point2d centerPoint = get2DCenter((IRing) ringSet.getAtomContainer(i));
        centerX += centerPoint.x;
        centerY += centerPoint.y;
    }
    return new Point2d(centerX / ((double) ringSet.getAtomContainerCount()), centerY
            / ((double) ringSet.getAtomContainerCount()));
}
 
Example #24
Source File: AbstractAWTReactionLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @return
 */
public Point2d getArrowCenter() {
    Rectangle2D bounds = getBoundsTree().getRoot();
    if (arrowAxis == X) {
        return new Point2d(arrowPos, bounds.getCenterY());
    } else {
        return new Point2d(bounds.getCenterX(), arrowPos);
    }
}
 
Example #25
Source File: AtomLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param atom
 * @param container
 * @param lonePairCount
 * @param g
 * @return
 */
public Rectangle2D layoutElectronPairs(
        IAtom atom, IAtomContainer container,
        int lonePairCount, Graphics2D g) {
    if (lonePairCount == 0) {
        return null;
    }

    Point2d atomPoint = atom.getPoint2d();
    Rectangle2D atomSymbolBounds = getTextBounds(g, atom.getSymbol());
    BitSet positions = labelManager.getAtomAnnotationPositions(atom);

    double r = params.electronRadius;
    double d = r * 2;
    for (int i = 0; i < lonePairCount; i++) {
        AnnotationPosition position = labelManager.getNextSparePosition(positions);
        Vector2d v = labelManager.getVectorFromPosition(position);
        Vector2d leftPerp = labelManager.getLeftPerpendicularFromPosition(position);
        Vector2d rightPerp = labelManager.getRightPerpendicularFromPosition(position);

        double dx = ((atomSymbolBounds.getWidth() / 2) + d) * v.x;
        double dy = ((atomSymbolBounds.getHeight() / 2) + d) * v.y;

        Point2d lp = new Point2d(atomPoint.x + dx, atomPoint.y + dy);
        Point2d llp = new Point2d(lp);
        llp.scaleAdd(params.lonePairSeparation / 2, leftPerp, llp);
        Point2d rlp = new Point2d(lp);
        rlp.scaleAdd(params.lonePairSeparation / 2, rightPerp, rlp);

        g.fill(new Ellipse2D.Double(llp.x - r, llp.y - r, d, d));
        g.fill(new Ellipse2D.Double(rlp.x - r, rlp.y - r, d, d));

        positions.set(position.ordinal());
    }
    return null;
}
 
Example #26
Source File: GridCanvasGenerator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param atomContainers
 * @param cellCanvas
 */
@Override
public void layout(List<IAtomContainer> atomContainers, Dimension cellCanvas) {
    double w = cellCanvas.width;
    double h = cellCanvas.height;
    double centerX = w / 2;
    double centerY = h / 2;
    int colCounter = 0;
    int rowCounter = 0;
    for (IAtomContainer atomContainer : atomContainers) {
        createCanvas(atomContainer, new Point2d(centerX, centerY), cellCanvas);
        colCounter++;
        if (colCounter < cols) {
            centerX += w;
        } else {
            centerY += h;
            centerX = w / 2;
            colCounter = 0;
            rowCounter++;
        }

        if (rowCounter > rows) {
            err.println("WARNING : Row limit exceeded");
        }
    }
    size = new Dimension(cols * cellCanvas.width, rows * cellCanvas.height);
}
 
Example #27
Source File: AtomLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Rectangle2D layoutText(String text, Point2d p, Graphics2D g) {
    Rectangle2D stringBounds = getTextBounds(g, text);
    double sW2 = stringBounds.getWidth() / 2;
    double sH2 = stringBounds.getHeight() / 2;
    double x = p.x - sW2;
    double y = p.y - sH2;
    return new Rectangle2D.Double(x, y, sW2 * 2, sH2 * 2);
}
 
Example #28
Source File: AtomLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Rectangle2D layoutChiralSymbol(IAtom atom, IStereoAndConformation chirality, Graphics2D g) {
    String text = "(-)";
    Point2d p = atom.getPoint2d();
    if (null != chirality) {
        switch (chirality) {
            case NONE:
                return new Rectangle2D.Double(p.x, p.y, 0, 0);
            case R:
                text = "(R)";
                break;
            case S:
                text = "(S)";
                break;
            case E:
                text = "(E)";
                break;
            case Z:
                text = "(Z)";
                break;
            default:
                text = "(-)";
                break;
        }
    }
    g.setFont(chiralSymbolFont);
    return layoutText(text, p, g);
}
 
Example #29
Source File: JDOMUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static Point2d readPoint2d(final String tagName, final Element parentEl) {
  final Element ptEl = parentEl.getChild(tagName);

  if (ptEl == null) {
    return null;
  } else {
    final double x = getDoubleVal(ptEl, JDOMUtils.tagX);
    final double y = getDoubleVal(ptEl, JDOMUtils.tagY);

    return new Point2d(x, y);
  }
}
 
Example #30
Source File: ConvexHull.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private double getAngle(Point2d ref, Point2d point) {
//        double angle = Math.atan((point.y - ref.y) / (point.x - ref.x));
//        if (angle < 0) angle += Math.PI;
//        return angle;
        Vector2d rp = new Vector2d(ref);
        rp.sub(point);
        rp.normalize();
        return X_AXIS.angle(rp);
    }