/** * Check if two bonds are crossing. * * @param beg1 first atom of first bond * @param end1 second atom of first bond * @param beg2 first atom of second bond * @param end2 first atom of second bond * @return bond is crossing */ private boolean isCrossed(Point2d beg1, Point2d end1, Point2d beg2, Point2d end2) { return Line2D.linesIntersect(beg1.x, beg1.y, end1.x, end1.y, beg2.x, beg2.y, end2.x, end2.y); }
/** * Test the Quadrilateral if it is a convex polygon. * * @return whether the diagonals intersects */ public boolean isConvex() { return Line2D.linesIntersect( p0.getCoordinate()[0], p0.getCoordinate()[1], p2.getCoordinate()[0], p2.getCoordinate()[1], p1.getCoordinate()[0], p1.getCoordinate()[1], p3.getCoordinate()[0], p3.getCoordinate()[1]); }
/** * Check if two bonds are crossing. * * @param beg1 first atom of first bond * @param end1 second atom of first bond * @param beg2 first atom of second bond * @param end2 first atom of second bond * @return bond is crossing */ private boolean isCrossed(Point2d beg1, Point2d end1, Point2d beg2, Point2d end2) { return Line2D.linesIntersect(beg1.x, beg1.y, end1.x, end1.y, beg2.x, beg2.y, end2.x, end2.y); }
private static boolean intersect(Point2D a1,Point2D a2,Point2D b1,Point2D b2) { return Line2D.linesIntersect(a1.getX(), a1.getY(), a2.getX(), a2.getY(), b1.getX(), b1.getY(), b2.getX(), b2.getY()); }
private static Map<SgroupBracket, IBond> bracketBondPairs(Collection<SgroupBracket> brackets, Collection<IBond> bonds) { Map<SgroupBracket, IBond> pairs = new HashMap<>(); for (SgroupBracket bracket : brackets) { IBond crossingBond = null; for (IBond bond : bonds) { IAtom a1 = bond.getBegin(); IAtom a2 = bond.getEnd(); if (Line2D.linesIntersect(bracket.getFirstPoint().x, bracket.getFirstPoint().y, bracket.getSecondPoint().x, bracket.getSecondPoint().y, a1.getPoint2d().x, a1.getPoint2d().y, a2.getPoint2d().x, a2.getPoint2d().y)) { // more than one... not good if (crossingBond != null) return new HashMap<>(); crossingBond = bond; } } if (crossingBond == null) return new HashMap<>(); pairs.put(bracket, crossingBond); } return pairs; }
boolean isCrossing(IBond a, IBond b) { Point2d p1 = a.getBegin().getPoint2d(); Point2d p2 = a.getEnd().getPoint2d(); Point2d p3 = b.getBegin().getPoint2d(); Point2d p4 = b.getEnd().getPoint2d(); return Line2D.linesIntersect(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y); }