/** * gets vector of 2D coordinates. * * all atoms must have coordinates COPIES coordinates so operations on * vector do not affect atomset * * @return the vector (null if missing 2D coordinates) */ public List<Real2> getVector2D() { List<CMLAtom> atoms = this.getAtoms(); List<Real2> p2Vector = new ArrayList<Real2>(); boolean ok = true; for (int i = 0; i < atoms.size(); i++) { CMLAtom atom = atoms.get(i); if (atom.getX2Attribute() == null || atom.getY2Attribute() == null) { ok = false; break; } Real2 p2 = new Real2(atom.getX2(), atom.getY2()); p2Vector.add(p2); } if (!ok) { p2Vector = null; } return p2Vector; }
/** * gets Real2 for x2 y2. * * @return the point; null if x2, etc. are unset */ public Real2 getXY2() { if (hasCoordinates(CoordinateType.TWOD)) { return new Real2(this.getX2(), this.getY2()); } return null; }
/** * translate molecule in 2D. * * @param delta2 * add to all 2D coordinates */ public void translate2D(Real2 delta2) { List<CMLAtom> atoms = this.getAtoms(); for (int i = 0; i < atoms.size(); i++) { CMLAtom atom = atoms.get(i); if (atom.getX2Attribute() != null && atom.getY2Attribute() != null) { atom.setX2(atom.getX2() + delta2.getX()); atom.setY2(atom.getY2() + delta2.getY()); } } }
/** * gets 2D coordinates as a 3D point. * * adds a z coordinate of 0.0. Result is not stored * * @return the point (null if no 2D coordinates) */ public Point3 get2DPoint3() { Point3 point = null; if (hasCoordinates(CoordinateType.TWOD)) { point = new Point3(this.getX2(), this.getY2(), 0.0); } return point; }
/** * increase x2 and y2 coordinates. * * if x2 or y2 is unset, no action (to avoid a default of zero) * * @param dx * amount to add * @param dy * amount to add */ public void increaseXY2(double dx, double dy) { if (hasCoordinates(CoordinateType.TWOD)) { this.setX2(this.getX2() + dx); this.setY2(this.getY2() + dy); } }
/** * translate molecule in 2D. * * @param delta2 * add to all 2D coordinates */ public void translate2D(Real2 delta2) { for (CMLAtom atom : getAtoms()) { if (atom.hasCoordinates(CoordinateType.TWOD)) { atom.setX2(atom.getX2() + delta2.x); atom.setY2(atom.getY2() + delta2.y); } } }
/** * transforms 2D coordinates of atom. * * if x2 or y2 is unset take no action * * @param t2 * transformation */ public void transform(Transform2 t2) { if (hasCoordinates(CoordinateType.TWOD)) { Real2 xy = new Real2(this.getX2(), this.getY2()); xy.transformBy(t2); this.setX2(xy.getX()); this.setY2(xy.getY()); } }
i = (int) (this.getX2() * factor); this.setX2(((double) i) * epsilon); i = (int) (this.getY2() * factor); this.setY2(((double) i) * epsilon);