AreaOfInterest extends GraphicalContext<BorderPane> { static Double[] calculateRectangle(final Point2D[] point2D) { double leftPoint = point2D[0].getX(); double rightPoint = point2D[0].getX(); double topPoint = point2D[0].getY(); double bottomPoint = point2D[0].getY(); for (int i = 1; i < point2D.length; i++) { if (point2D[i].getX() < leftPoint) { leftPoint = point2D[i].getX(); } if (point2D[i].getX() > rightPoint) { rightPoint = point2D[i].getX(); } if (point2D[i].getY() > topPoint) { topPoint = point2D[i].getY(); } if (point2D[i].getY() < bottomPoint) { bottomPoint = point2D[i].getY(); } } final Double[] squarePoints = new Double[8]; final int bias = 15; squarePoints[0] = leftPoint - bias; squarePoints[1] = topPoint + bias; squarePoints[2] = rightPoint + bias; squarePoints[3] = topPoint + bias; squarePoints[4] = rightPoint + bias; squarePoints[5] = bottomPoint - bias; squarePoints[6] = leftPoint - bias; squarePoints[7] = bottomPoint - bias; return squarePoints; } AreaOfInterest(final GazePlay gazePlay, final Stats stats); @Override ObservableList<Node> getChildren();  }
@Test void shouldCalculateRectangle() { Point2D[] input = new Point2D[]{ new Point2D(706.0, 685.0), new Point2D(710.0, 670.0), new Point2D(708.0, 690.0) }; Double[] expected = new Double[]{ 706.0 - 15, 690.0 + 15, 710.0 + 15, 690.0 + 15, 710.0 + 15, 670.0 - 15, 706.0 - 15, 670.0 - 15 }; Double[] actual = AreaOfInterest.calculateRectangle(input); assertArrayEquals(expected, actual); }