/** * Clip all segments at screen to make sure we don't have to render huge coordinates. This is * especially important for fill the GeneralPath. */ private void addClippedSegments() { geogebra.common.awt.GRectangle viewRect = AwtFactory.prototype.newRectangle(0, 0, view.getWidth(), view.getHeight()); MyPoint curP = null, prevP; int size = pathPoints.size(); for (int i = 0; i < size; i++) { prevP = curP; curP = pathPoints.get(i); if (!curP.getLineTo() || prevP == null) { // moveTo point, make sure it is only slightly outside screen geogebra.common.awt.GPoint2D p = getPointCloseToScreen(curP.getX(), curP.getY()); addToGeneralPath(p, false); } else { // clip line at screen addClippedLine(prevP, curP, viewRect); } } if (needClosePath) { // line from last point to first point addClippedLine(curP, pathPoints.get(0), viewRect); gp.closePath(); } }
private void addSimpleSegments() { int size = pathPoints.size(); for (int i = 0; i < size; i++) { MyPoint curP = pathPoints.get(i); addToGeneralPath(curP, curP.getLineTo()); } if (needClosePath) gp.closePath(); }
private void updateBounds(MyPoint p) { if (bounds == null) { bounds = AwtFactory.prototype.newRectangle(); bounds.setBounds((int) p.getX(), (int) p.getY(), 0, 0); } if (Math.abs(p.getX()) > largestCoord) largestCoord = Math.abs(p.getX()); if (Math.abs(p.getY()) > largestCoord) largestCoord = Math.abs(p.getY()); bounds.add(p.getX(), p.getY()); }
private void addClippedLine( MyPoint prevP, MyPoint curP, geogebra.common.awt.GRectangle viewRect) { // check if both points on screen if (viewRect.contains(prevP) && viewRect.contains(curP)) { // draw line to point addToGeneralPath(curP, true); return; } // at least one point is not on screen: clip line at screen geogebra.common.awt.GPoint2D[] clippedPoints = ClipLine.getClipped( prevP.getX(), prevP.getY(), curP.getX(), curP.getY(), -10, view.getWidth() + 10, -10, view.getHeight() + 10); if (clippedPoints != null) { // we have two intersection points with the screen // get closest clip point to prevP int first = 0; int second = 1; if (clippedPoints[first].distance(prevP.getX(), prevP.getY()) > clippedPoints[second].distance(prevP.getX(), prevP.getY())) { first = 1; second = 0; } // draw line to first clip point addToGeneralPath(clippedPoints[first], true); // draw line between clip points: this ensures high quality // rendering // which Java2D doesn't deliver with the regular float GeneralPath // and huge coords addToGeneralPath(clippedPoints[second], true); // draw line to end point if not already there addToGeneralPath(getPointCloseToScreen(curP.getX(), curP.getY()), true); } else { // line is off screen // draw line to off screen end point addToGeneralPath(getPointCloseToScreen(curP.getX(), curP.getY()), true); } }