private void removeDuplicateSegments() { for (int i = 0, size = segmentSet.size(); i < size - 1; i++) { LineSegment2d l1 = segmentSet.get(i); for (int j = i + 1; j < size; j++) { LineSegment2d l2 = segmentSet.get(j); if (l1.getBegin().equals(l2.getBegin()) && l1.getEnd().equals(l2.getEnd()) || l1.getBegin().equals(l2.getEnd()) && l1.getEnd().equals(l2.getBegin())) { // System.out.println("remove dup " + l1 + " " + l2); segmentSet.remove(j); size--; } } } }
private static PolygonList2d wallPartsToPolygon(List<WallPart> wallParts) { List<Point2d> points = new ArrayList<Point2d>(); for (WallPart p : wallParts) { if (points.size() > 0 && p.getNodes().size() > 0) { Point2d lastAdded = points.get(points.size() - 1); Point2d newToAdd = p.getNodes().get(0).point; if (lastAdded.equals(newToAdd)) { points.remove(points.size() - 1); } } for (WallNode n : p.getNodes()) { points.add(n.point); } } // if (points.size() > 1) { if (points.get(0).equals(points.get(points.size()-1))) { points.remove(points.size()-1); } else { throw new IllegalArgumentException("wall is not closed!!!"); } return new PolygonList2d(points); }
/** * Compares a atom with this atom. * * @param object of type Atom * @return true, if the atoms are equal */ @Override public boolean compare(Object object) { if (!(object instanceof IAtom)) { return false; } if (!super.compare(object)) { return false; } Atom atom = (Atom) object; // XXX: floating point comparision! if (((point2d == atom.point2d) || ((point2d != null) && (point2d.equals(atom.point2d)))) && ((point3d == atom.point3d) || ((point3d != null) && (point3d.equals(atom.point3d)))) && (Objects.equals(hydrogenCount, atom.hydrogenCount)) && (Objects.equals(stereoParity, atom.stereoParity)) && (Objects.equals(charge, atom.charge))) { return true; } return false; }
/** * Compares a atom with this atom. * * @param object of type Atom * @return true, if the atoms are equal */ @Override public boolean compare(Object object) { if (!(object instanceof IAtom)) { return false; } if (!super.compare(object)) { return false; } Atom atom = (Atom) object; // XXX: floating point comparision! if (((point2d == atom.point2d) || ((point2d != null) && (point2d.equals(atom.point2d)))) && ((point3d == atom.point3d) || ((point3d != null) && (point3d.equals(atom.point3d)))) && (Objects.equals(hydrogenCount, atom.hydrogenCount)) && (Objects.equals(stereoParity, atom.stereoParity)) && (Objects.equals(charge, atom.charge))) { return true; } return false; }
/** * Compares a atom with this atom. * * @param object of type Atom * @return true, if the atoms are equal */ @Override public boolean compare(Object object) { if (!(object instanceof IAtom)) { return false; } if (!super.compare(object)) { return false; } Atom atom = (Atom) object; if (((point2d == atom.point2d) || ((point2d != null) && (point2d.equals(atom.point2d)))) && ((point3d == atom.point3d) || ((point3d != null) && (point3d.equals(atom.point3d)))) && (Objects.equals(hydrogenCount, atom.hydrogenCount)) && (Objects.equals(stereoParity, atom.stereoParity)) && (Objects.equals(charge, atom.charge))) { return true; } return false; }
/** * Compares a atom with this atom. * * @param object of type Atom * @return true, if the atoms are equal */ @Override public boolean compare(Object object) { if (!(object instanceof IAtom)) { return false; } if (!super.compare(object)) { return false; } Atom atom = (Atom) object; if (((point2d == atom.point2d) || ((point2d != null) && (point2d.equals(atom.point2d)))) && ((point3d == atom.point3d) || ((point3d != null) && (point3d.equals(atom.point3d)))) && (Objects.equals(hydrogenCount, atom.hydrogenCount)) && (Objects.equals(stereoParity, atom.stereoParity)) && (Objects.equals(charge, atom.charge))) { return true; } return false; }
public static double getAngle(Point2d from, Point2d to) { if (from.equals(to)) return 0; double angle = Math.atan2(to.getY() - from.getY(), to.getX() - from.getX()); if (angle <= Math.PI / 2) angle += Math.PI / 2; else angle -= Math.PI * 3 / 2; return angle; } }
private double medianBondLength(Collection<IBond> bonds) { if (bonds.isEmpty()) return 1.5; int nBonds = 0; double[] lengths = new double[bonds.size()]; for (IBond bond : bonds) { Point2d p1 = bond.getBegin().getPoint2d(); Point2d p2 = bond.getEnd().getPoint2d(); // watch out for overlaid atoms (occur in multiple group Sgroups) if (!p1.equals(p2)) lengths[nBonds++] = p1.distance(p2); } Arrays.sort(lengths, 0, nBonds); return lengths[nBonds / 2]; }
private double medianBondLength(Collection<IBond> bonds) { if (bonds.isEmpty()) return 1.5; int nBonds = 0; double[] lengths = new double[bonds.size()]; for (IBond bond : bonds) { Point2d p1 = bond.getBegin().getPoint2d(); Point2d p2 = bond.getEnd().getPoint2d(); // watch out for overlaid atoms (occur in multiple group Sgroups) if (!p1.equals(p2)) lengths[nBonds++] = p1.distance(p2); } Arrays.sort(lengths, 0, nBonds); return lengths[nBonds / 2]; }
Point2d max = minMax[1]; if (min.equals(max))
if (size > 1) { if (pContour.get(0).equals(pContour.get(pContour.size()-1))) {
/** * Obtain the unit vector between two points. * * @param from the base of the vector * @param to the point of the vector * @return the unit vector */ private Point2d toUnitVector(Point2d from, Point2d to) { if (from.equals(to)) return new Point2d(0, 0); Vector2d v2d = new Vector2d(to.x - from.x, to.y - from.y); v2d.normalize(); return new Point2d(v2d); }
/** * Modifies the vertices so they are clockwise ordered. * Updates centroid, area and the bounding box. * Call this method once new vertices have been added. */ public void update() { if (isUpToDate) return; // Need to reorder the vertices so they are clockwise ordered if (numberOfVertices >= 3 && !InPlaceConvexHullCalculator2d.isConvexAndClockwise(clockwiseOrderedListOfPoints, numberOfVertices)) { numberOfVertices = InPlaceConvexHullCalculator2d.inPlaceGiftWrapConvexHull2d(clockwiseOrderedListOfPoints, numberOfVertices); } // Only two distinct vertices: trivial case else if (numberOfVertices == 2 && !clockwiseOrderedListOfPoints.get(0).equals(clockwiseOrderedListOfPoints.get(1))) { Point2d p0 = clockwiseOrderedListOfPoints.get(0); Point2d p1 = clockwiseOrderedListOfPoints.get(1); if (!(p0.getX() < p1.getX()) || ((p0.getX() == p1.getX()) && (p0.getY() > p1.getY()))) { Collections.swap(clockwiseOrderedListOfPoints, 1, 0); } } // Else, nothing to do, it's either 0 vertex, 1 vertex, 2 identical vertices, or the vertices are already clockwise ordered isUpToDate = true; updateCentroidAndArea(); updateBoundingBox(); }
/** * from http://softsurfer.com/Archive/algorithm_0111/algorithm_0111.htm#Pseudo-Code:%20Clip%20Segment-Polygon * Input: a 2D segment S from point P0 to point P1 * a 2D convex polygon W with n vertices V0,...,Vn-1,Vn=V0 */ public static boolean doesSegmentIntersectConvexPolygon2D(Point2d P0, Point2d P1, ConvexPolygon2d convexPolygon2d) { // if segment is a single point if (P0.equals(P1)) { return convexPolygon2d.isPointInside(P0); } // if either point is inside polygon if (convexPolygon2d.isPointInside(P0, .0001) || convexPolygon2d.isPointInside(P1, .0001)) return true; // if either point touches the polygon if (convexPolygon2d.pointIsOnPerimeter(P0) || convexPolygon2d.pointIsOnPerimeter(P1)) return true; return doesSegmentPassCompletelyThroughPolygon(P0, P1, convexPolygon2d); }
if (!oldCoord.equals(newCoord)) { Point2d[] coords = new Point2d[2]; coords[0] = newCoord;
IAtom highlitAtom = model.getHighlightedAtom(); IBond highlitBond = model.getHighlightedBond(); if(from.equals(startPoint)) { LogicalSelection lsel = null; boolean isAllSelected = false;
border.add(new Point2d(ppp.x, ppp.y)); if (border.get(border.size() - 1).equals(border.get(0))) { border.remove(border.size() - 1);
if(p.equals(startPoint)){