/** * Compute the 2D equivalent of this line segment. * The 2D equivalent of each end point is computed as follows: * {@code endPoint2d = endPoint1d * direction2d + zero2d}. * @param zero2d position of the 2D equivalent of an endpoint equal to zero. * @param direction2d direction toward greater values of {@code endPoint1d}. * @return the 2D equivalent of this line segment. */ public LineSegment2d toLineSegment2d(Point2d zero2d, Vector2d direction2d) { LineSegment2d lineSegment2d = new LineSegment2d(); lineSegment2d.getFirstEndpoint().scaleAdd(endpoint1, direction2d, zero2d); lineSegment2d.getSecondEndpoint().scaleAdd(endpoint2, direction2d, zero2d); return lineSegment2d; }
private void drawText(Graphics2D g, String text, Point2d c, Vector2d v, Vector2d nV) { AffineTransform originalTransform = g.getTransform(); double angle = getAngle(v); Rectangle2D textBounds = getTextBounds(g, text); double distance = textBounds.getWidth() / 2; Point2d start = new Point2d(c.x, c.y); if (angle < toRadians(90) || angle > toRadians(270)) { start.scaleAdd(distance, nV, c); } else { start.scaleAdd(distance, v, c); double angDeg = (180 + toDegrees(angle)) % 360; angle = toRadians(angDeg); } g.translate(start.x, start.y); g.rotate(angle); Font font = g.getFont(); FontRenderContext frc = g.getFontRenderContext(); GlyphVector gv = font.createGlyphVector(frc, text); int length = gv.getNumGlyphs(); for (int i = 0; i < length; i++) { g.fill(gv.getGlyphOutline(i)); } g.rotate((2 * PI) - angle); g.setTransform(originalTransform); }
private void drawText(Graphics2D g, String text, Point2d c, Vector2d v, Vector2d nV) { AffineTransform originalTransform = g.getTransform(); double angle = this.getAngle(v); Rectangle2D textBounds = this.getTextBounds(g, text); double distance = textBounds.getWidth() / 2.0; Point2d start = new Point2d(c.x, c.y); if (angle < Math.toRadians(90.0) || angle > Math.toRadians(270.0)) { start.scaleAdd(distance, (Tuple2d)nV, (Tuple2d)c); } else { start.scaleAdd(distance, (Tuple2d)v, (Tuple2d)c); double angDeg = (180.0 + Math.toDegrees(angle)) % 360.0; angle = Math.toRadians(angDeg); } g.translate(start.x, start.y); g.rotate(angle); Font font = g.getFont(); FontRenderContext frc = g.getFontRenderContext(); GlyphVector gv = font.createGlyphVector(frc, text); int length = gv.getNumGlyphs(); for (int i = 0; i < length; ++i) { g.fill(gv.getGlyphOutline(i)); } g.rotate(6.283185307179586 - angle); g.setTransform(originalTransform); }
public void drawThinArrow(Graphics2D g, Point2d c, Vector2d v, String text) { int arrowLength = this.paramsLocal.arrowLength; int arrowHeadLength = this.paramsLocal.arrowHeadLength; double arrowHeadAngleRad = Math.toRadians(this.paramsLocal.arrowHeadAngle); double arrowHeadAngleRadPrime = Math.toRadians(360.0 - this.paramsLocal.arrowHeadAngle); double cosA = Math.cos(arrowHeadAngleRad); double sinA = Math.sin(arrowHeadAngleRad); double cosAPrime = Math.cos(arrowHeadAngleRadPrime); double sinAPrime = Math.sin(arrowHeadAngleRadPrime); int halfLength = arrowLength / 2; g.setColor(Color.BLACK); Vector2d nV = new Vector2d(v); nV.negate(); Point2d tail = new Point2d(c.x, c.y); tail.scaleAdd((double)halfLength, (Tuple2d)nV, (Tuple2d)c); Point2d head = new Point2d(c); head.scaleAdd((double)halfLength, (Tuple2d)v, (Tuple2d)c); Vector2d ccwVec = new Vector2d(cosA * nV.x + sinA * nV.y, cosA * nV.y - sinA * nV.x); Vector2d cwVec = new Vector2d(cosAPrime * nV.x + sinAPrime * nV.y, cosAPrime * nV.y - sinAPrime * nV.x); Point2d headCCW = new Point2d(head.x, head.y); headCCW.scaleAdd((double)arrowHeadLength, (Tuple2d)ccwVec, (Tuple2d)head); Point2d headCW = new Point2d(head.x, head.y); headCW.scaleAdd((double)arrowHeadLength, (Tuple2d)cwVec, (Tuple2d)head); g.draw(new Line2D.Double(tail.x, tail.y, head.x, head.y)); g.draw(new Line2D.Double(head.x, head.y, headCCW.x, headCCW.y)); g.draw(new Line2D.Double(head.x, head.y, headCW.x, headCW.y)); if (text != null) { this.drawText(g, text, c, v, nV); } }
Path2D.Double path = new Path2D.Double(); path.moveTo(p1.x, p1.y); centerLinePoint.scaleAdd(gap / 2.0, (Tuple2d) line, (Tuple2d) centerLinePoint); Point2d tipPoint = new Point2d(centerLinePoint); tipPoint.scaleAdd(wiggleWidth / 2.0, (Tuple2d) perpendicular, (Tuple2d) tipPoint); for (int i = 0; i < numberOfSegments - 1; ++i) { centerLinePoint.scaleAdd(gap / 2.0, (Tuple2d) line, (Tuple2d) centerLinePoint); path.quadTo(tipPoint.x, tipPoint.y, centerLinePoint.x, centerLinePoint.y); centerLinePoint.scaleAdd(gap / 2.0, (Tuple2d) line, (Tuple2d) centerLinePoint); tipPoint = new Point2d(centerLinePoint); if (i % 2 == 0) { tipPoint.scaleAdd(wiggleWidth / 2.0, (Tuple2d) negPerp, (Tuple2d) tipPoint); continue; tipPoint.scaleAdd(wiggleWidth / 2.0, (Tuple2d) perpendicular, (Tuple2d) tipPoint);
@Override public BoundsTree layout(IAtomContainerSet atomContainerSet, Graphics2D graphics) { Font plusFont = new Font("ROMAN", 0, this.params.plusFontSize); graphics.setFont(plusFont); Rectangle2D plusBounds = super.getTextBounds(graphics, "+"); double molGap = (double)(2 * this.params.plusGap) + plusBounds.getWidth(); String atomContainerSetID = atomContainerSet.getID(); this.boundsTree = new BoundsTree(atomContainerSetID); Point2d curr = new Point2d(0.0, 0.0); int moleculeCounter = 0; for (IAtomContainer molecule : atomContainerSet.atomContainers()) { String label = molecule.getID(); label = label == null || label.equals("") ? "mol" + String.valueOf(moleculeCounter) : label + ":" + String.valueOf(moleculeCounter); BoundsTree molBounds = this.moleculeLayout.layout(molecule, label, graphics); double boundsWidth = molBounds.getWidth(); double halfBoundsWidth = boundsWidth / 2.0; curr.scaleAdd(halfBoundsWidth, (Tuple2d)this.moleculeSetAxis, (Tuple2d)curr); this.translateTo(molecule, curr.x, curr.y, molBounds); curr.scaleAdd(halfBoundsWidth, (Tuple2d)this.moleculeSetAxis, (Tuple2d)curr); curr.scaleAdd(molGap, (Tuple2d)this.moleculeSetAxis, (Tuple2d)curr); this.boundsTree.add(atomContainerSetID, molBounds); ++moleculeCounter; } return this.boundsTree; }
IAtomContainer atomContainer = atomContainers.get(index); Point2d canvasCenter = new Point2d(center); canvasCenter.scaleAdd(circleRadius, (Tuple2d)v, (Tuple2d)canvasCenter); this.createCanvas(atomContainer, canvasCenter, cellCanvas); Vector2d w = new Vector2d();
public Rectangle2D drawElectronPairs(IAtom atom, IAtomContainer container, int lonePairCount, Graphics2D g) { if (lonePairCount == 0) { return null; } Point2d atomPoint = atom.getPoint2d(); Rectangle2D atomSymbolBounds = this.getTextBounds(g, atom.getSymbol()); BitSet positions = this.labelManager.getAtomAnnotationPositions(atom); double r = this.params.electronRadius; double d = r * 2.0; for (int i = 0; i < lonePairCount; ++i) { LabelManager.AnnotationPosition position = this.labelManager.getNextSparePosition(positions); Vector2d v = this.labelManager.getVectorFromPosition(position); Vector2d leftPerp = this.labelManager.getLeftPerpendicularFromPosition(position); Vector2d rightPerp = this.labelManager.getRightPerpendicularFromPosition(position); double dx = (atomSymbolBounds.getWidth() / 2.0 + d) * v.x; double dy = (atomSymbolBounds.getHeight() / 2.0 + d) * v.y; Point2d lp = new Point2d(atomPoint.x + dx, atomPoint.y + dy); Point2d llp = new Point2d(lp); llp.scaleAdd((double) (this.params.lonePairSeparation / 2), (Tuple2d) leftPerp, (Tuple2d) llp); Point2d rlp = new Point2d(lp); rlp.scaleAdd((double) (this.params.lonePairSeparation / 2), (Tuple2d) rightPerp, (Tuple2d) 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; }
public Rectangle2D layoutElectronPairs(IAtom atom, IAtomContainer container, int lonePairCount, Graphics2D g) { if (lonePairCount == 0) { return null; } Point2d atomPoint = atom.getPoint2d(); Rectangle2D atomSymbolBounds = this.getTextBounds(g, atom.getSymbol()); BitSet positions = this.labelManager.getAtomAnnotationPositions(atom); double r = this.params.electronRadius; double d = r * 2.0; for (int i = 0; i < lonePairCount; ++i) { LabelManager.AnnotationPosition position = this.labelManager.getNextSparePosition(positions); Vector2d v = this.labelManager.getVectorFromPosition(position); Vector2d leftPerp = this.labelManager.getLeftPerpendicularFromPosition(position); Vector2d rightPerp = this.labelManager.getRightPerpendicularFromPosition(position); double dx = (atomSymbolBounds.getWidth() / 2.0 + d) * v.x; double dy = (atomSymbolBounds.getHeight() / 2.0 + d) * v.y; Point2d lp = new Point2d(atomPoint.x + dx, atomPoint.y + dy); Point2d llp = new Point2d(lp); llp.scaleAdd((double) (this.params.lonePairSeparation / 2), (Tuple2d) leftPerp, (Tuple2d) llp); Point2d rlp = new Point2d(lp); rlp.scaleAdd((double) (this.params.lonePairSeparation / 2), (Tuple2d) rightPerp, (Tuple2d) 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; }
rungCenter.interpolate((Tuple2d) d, currentDistance); Point2d p1 = new Point2d(rungCenter); p1.scaleAdd(currentWidth, (Tuple2d) perp, (Tuple2d) p1); Point2d p2 = new Point2d(rungCenter); p2.scaleAdd(currentWidth, (Tuple2d) nPerp, (Tuple2d) p2); this.drawLine(p1, p2, g); if (distance * (currentDistance + gapFactor) >= distance) {
public Rectangle(Point2d pointOnAB, Point2d cornerC, Point2d cornerD, double distToCD) { this.pointX = new Point2d(pointOnAB); this.cornerC = new Point2d(cornerC); this.cornerD = new Point2d(cornerD); Vector2d cdVec = new Vector2d((Tuple2d) cornerD); cdVec.sub((Tuple2d) cornerC); Vector2d cdVecNormalized = new Vector2d(cdVec); if (cdVec.x != 0.0 && cdVec.y != 0.0) { cdVecNormalized.normalize(); } Vector2d perp = new Vector2d(cdVecNormalized.y, -cdVecNormalized.x); this.cornerA = new Point2d(cornerD); this.cornerA.scaleAdd(distToCD, (Tuple2d) perp, (Tuple2d) this.cornerA); this.cornerB = new Point2d(cornerC); this.cornerB.scaleAdd(distToCD, (Tuple2d) perp, (Tuple2d) this.cornerB); }
pc1.scaleAdd(params.doubleMarkGap, bondVector, pc1); pc2.scaleAdd(params.doubleMarkGap, negBondVector, pc2); pp11.scaleAdd(markLength / 2, perp, pp11); Point2d pp12 = new Point2d(pc1); pp12.scaleAdd(markLength / 2, negPerp, pp12); pp21.scaleAdd(markLength / 2, perp, pp21); Point2d pp22 = new Point2d(pc2); pp22.scaleAdd(markLength / 2, negPerp, pp22);
double boundsWidth = bounds.getWidth(); double halfBoundsWidth = boundsWidth / 2.0; curr.scaleAdd(halfBoundsWidth, (Tuple2d) moleculeSetAxis, (Tuple2d) curr); this.translateTo(molecule, curr.x, curr.y, bounds); curr.scaleAdd(halfBoundsWidth, (Tuple2d) moleculeSetAxis, (Tuple2d) curr); curr.scaleAdd((double) molGap, (Tuple2d) moleculeSetAxis, (Tuple2d) curr); String moleculeLabel = molecule.getID(); if (moleculeLabel == null || moleculeLabel.equals("")) {
/** * * @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); }
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); } }
/** * @param contur * @return */ public Point2d[] rectToList(RectanglePointVector2d contur) { Point2d p1 = contur.getPoint(); Point2d p2 = new Point2d(contur.getVector()); p2.scaleAdd(contur.getWidth(), contur.getPoint()); Vector2d ort = new Vector2d(-contur.getVector().y * contur.getHeight(), contur.getVector().x * contur.getHeight()); Point2d p3 = new Point2d(p2); p3.add(ort); Point2d p4 = new Point2d(p1); p4.add(ort); Point2d[] ret = new Point2d[4]; ret[0] = p2; ret[1] = p3; ret[2] = p4; ret[3] = p1; return ret; }