public static boolean linesIntersect(Line line1, Line line2) { if (!(line1.equals(line2))) { double x1 = line1.getX1(); double y1 = line1.getY1(); double x2 = line1.getX2(); double y2 = line1.getY2(); double x3 = line2.getX1(); double y3 = line2.getY1(); double x4 = line2.getX2(); double y4 = line2.getY2(); return Line2D.linesIntersect(x1, y1, x2, y2, x3, y3, x4, y4); } else { return false; } }
/** * Returns the index of the line of the loaded document corresponding to l * * @require l is not null * @ensure Result is the index of the line of the loaded document corresponding to l. If the * document contains no such line, return -1. */ private int getLineIndex(Line l) { /* * docIterator holds the document's iterator so that we may loop * over each line in the document. */ Iterator<Line> docIterator = document.iterator(); /* line holds the current line in the document */ Line line; for (int i = 0; docIterator.hasNext(); i++) { line = docIterator.next(); if (line.equals(l)) { return i; } } return -1; }
@Test public void testEquals() { final Line line1 = Line.valueOf(11, 22, 33, 44); final Line line2 = Line.valueOf(11, 22, 33, 44); final Line line3 = Line.valueOf(1, 2, 3, 4); final Line nullLine = null; assertFalse(line1.equals(nullLine)); assertFalse(line2.equals(nullLine)); assertFalse(line3.equals(nullLine)); assertFalse(line1.equals(new Object())); assertFalse(line2.equals(new Object())); assertFalse(line3.equals(new Object())); assertThat(line1, equalTo(line2)); assertThat(line1, not(equalTo(line3))); assertThat(line2, not(equalTo(line3))); }