LineSegment { public boolean containsPoint(Vector point) { if (point == null) { return false; } Vector diff1 = point.subtract(startPoint); if (diff1.get(0) < 0 || diff1.get(1) < 0 || diff1.get(2) < 0) { return false; } Vector diff2 = endPoint.subtract(point); if (diff2.get(0) < 0 || diff2.get(1) < 0 || diff2.get(2) < 0) { return false; } return true; } LineSegment(Vector startPoint, Vector endPoint); Vector getStartPoint(); Vector getEndPoint(); float getLength(); Rectangle getBoundingRectangle(); LineSegment transformBy(Matrix m); boolean containsSegment(LineSegment other); boolean containsPoint(Vector point);  }
@Test public void containsPointNullTest() { LineSegment lineSegment = new LineSegment(new Vector(20.3246f, 769.4974f, 1.0f), new Vector(151.22923f, 769.4974f, 1.0f)); Assert.assertFalse(lineSegment.containsPoint(null)); }
@Test public void containsPointTest() { Vector pointToCheck = new Vector(20.3246f, 769.4974f, 1.0f); LineSegment lineSegment = new LineSegment(pointToCheck, new Vector(151.22923f, 769.4974f, 1.0f)); Assert.assertTrue(lineSegment.containsPoint(pointToCheck)); }
@Test public void notContainsPointLeftTest() { Vector pointToCheck = new Vector(100.3246f, 769.4974f, 1.0f); LineSegment lineSegment = new LineSegment(new Vector(120.3246f, 769.4974f, 1.0f), new Vector(151.22923f, 769.4974f, 1.0f)); Assert.assertFalse(lineSegment.containsPoint(pointToCheck)); }
@Test public void notContainsPointRightTest() { Vector pointToCheck = new Vector(160.3246f, 769.4974f, 1.0f); LineSegment lineSegment = new LineSegment(new Vector(120.3246f, 769.4974f, 1.0f), new Vector(151.22923f, 769.4974f, 1.0f)); Assert.assertFalse(lineSegment.containsPoint(pointToCheck)); }