public Path2D makeEllipse(Complex G1, Complex G2, int m, double xOffset, double yOffset) { Path2D path = new Path2D.Float(); int recPoints = Math.max(minReconstructionSamples, G.length * 3); for (int i = 0; i < recPoints; i++) { double t = (double) i / recPoints; Complex p1 = this.getEllipsePoint(G1, G2, m, t); double xt = p1.re(); double yt = p1.im(); if (i == 0) { path.moveTo(xt + xOffset, yt + yOffset); } else { path.lineTo(xt + xOffset, yt + yOffset); } } path.closePath(); return path; }
public int print( Graphics graphics, PageFormat format, int index ) { Graphics2D g2d = (Graphics2D)graphics; double scalex = g2d.getTransform().getScaleX(); double scaley = g2d.getTransform().getScaleY(); double centerx = ( format.getImageableX() + ( format.getImageableWidth() / 2 ) ) * scalex; double centery = ( format.getImageableY() + ( format.getImageableHeight() / 2 ) ) * scaley; // The following 2 lines cause an error when printing in landscape. g2d.scale( 1 / scalex, 1 / scaley ); g2d.translate( centerx, centery ); Path2D.Double path = new Path2D.Double(); path.moveTo( -scalex * 72, -scaley * 72 ); path.lineTo( -scalex * 72, scaley * 72 ); path.lineTo( scalex * 72, scaley * 72 ); path.lineTo( scalex * 72, -scaley * 72 ); path.closePath(); g2d.draw( path ); return index == 0 ? PAGE_EXISTS : NO_SUCH_PAGE; }
static void testAddClose(Path2D pathA, boolean isEmpty) { try { addClose(pathA); } catch (IllegalPathStateException ipse) { if (isEmpty) { log("testAddClose: passed " + "(expected IllegalPathStateException catched)."); return; } else { throw ipse; } } if (isEmpty) { throw new IllegalStateException("IllegalPathStateException not thrown !"); } log("testAddClose: passed."); }
static void testAddLine(Path2D pathA, boolean isEmpty) { try { addLines(pathA); } catch (IllegalPathStateException ipse) { if (isEmpty) { log("testAddLine: passed " + "(expected IllegalPathStateException catched)."); return; } else { throw ipse; } } if (isEmpty) { throw new IllegalStateException("IllegalPathStateException not thrown !"); } log("testAddLine: passed."); }
public void paintState(Graphics2D g2, ASVConfig s) { if (s == null) { return; } Path2D.Float path = new Path2D.Float(); List<Point2D> points = s.getASVPositions(); Point2D p = points.get(0); path.moveTo(p.getX(), p.getY()); for (int i = 1; i < points.size(); i++) { p = points.get(i); path.lineTo(p.getX(), p.getY()); } path.transform(transform); g2.draw(path); if (animating || !displayingSolution) { p = transform.transform(points.get(0), null); Color color = g2.getColor(); Stroke stroke = g2.getStroke(); g2.setColor(Color.BLACK); g2.setStroke(new BasicStroke(1)); g2.draw(new Ellipse2D.Double(p.getX() - 4, p.getY() - 4, 8, 8)); g2.setColor(color); g2.setStroke(stroke); } }
static void testGetBounds(Path2D pathA, Path2D pathB) { final Rectangle rA = pathA.getBounds(); final Rectangle rB = pathB.getBounds(); if (!rA.equals(rB)) { throw new IllegalStateException("Bounds are not equals [" + rA + "|" + rB + "] !"); } final Rectangle2D r2dA = pathA.getBounds2D(); final Rectangle2D r2dB = pathB.getBounds2D(); if (!equalsRectangle2D(r2dA, r2dB)) { throw new IllegalStateException("Bounds2D are not equals [" + r2dA + "|" + r2dB + "] !"); } log("testGetBounds: passed."); }
Path2D.Float getPath2D() { // resolve reference: Path2D.Float p2d = (refPath2D != null) ? refPath2D.get() : null; // create a new Path2D ? if (p2d == null) { p2d = new Path2D.Float(Path2D.WIND_NON_ZERO, INITIAL_EDGES_COUNT); // 32K // update weak reference: refPath2D = new WeakReference<Path2D.Float>(p2d); } // reset the path anyway: p2d.reset(); return p2d; }
void doShape(SunGraphics2D sg2d, Shape s, boolean isfill) { Path2D.Float p2df; int transX; int transY; if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) { if (s instanceof Path2D.Float) { p2df = (Path2D.Float)s; } else { p2df = new Path2D.Float(s); } transX = sg2d.transX; transY = sg2d.transY; } else { p2df = new Path2D.Float(s, sg2d.transform); transX = 0; transY = 0; } try { doShape((GDIWindowSurfaceData)sg2d.surfaceData, sg2d.getCompClip(), sg2d.composite, sg2d.eargb, transX, transY, p2df, isfill); } catch (ClassCastException e) { throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData); } }
/** * Draws a sequence of connected lines defined by * arrays of <i>x</i> and <i>y</i> coordinates. * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point. * The figure is not closed if the first point * differs from the last point. * @param xPoints an array of <i>x</i> points * @param yPoints an array of <i>y</i> points * @param nPoints the total number of points * @see java.awt.Graphics#drawPolygon(int[], int[], int) * @since 1.1 */ public void drawPolyline(int xPoints[], int yPoints[], int nPoints) { if (nPoints == 2) { draw(new Line2D.Float(xPoints[0], yPoints[0], xPoints[1], yPoints[1])); } else if (nPoints > 2) { Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD, nPoints); path.moveTo(xPoints[0], yPoints[0]); for(int i = 1; i < nPoints; i++) { path.lineTo(xPoints[i], yPoints[i]); } draw(path); } }
static void testAddCubic(Path2D pathA, boolean isEmpty) { try { addCubics(pathA); } catch (IllegalPathStateException ipse) { if (isEmpty) { log("testAddCubic: passed " + "(expected IllegalPathStateException catched)."); return; } else { throw ipse; } } if (isEmpty) { throw new IllegalStateException("IllegalPathStateException not thrown !"); } log("testAddCubic: passed."); }
private Map<Object, List<Fibre>> polygonClustering(final List<Path2D.Double> polygons, final Integer defaultPolygon, final List<Fibre> input, final List<String> attributes, final Map<OperationErrorCode, String> errors, final OperationContext context) { Map<Object, List<Fibre>> result; result = new ConcurrentHashMap<Object, List<Fibre>>(); input.stream().forEach(le -> { List<Double> values = LoomQueryUtils.convertAttributesToNumbers(attributes, le, errors, context); int polygonIndex = this.findContainer(polygons, defaultPolygon, values.get(0), values.get(1)); if (result.get(polygonIndex) == null) { result.put(polygonIndex, new LinkedList<Fibre>()); } result.get(polygonIndex).add(le); }); return result; }
public static void main(String[] argv) throws Exception { BufferedImage im = getWhiteImage(30, 30); Graphics2D g2 = (Graphics2D)im.getGraphics(); g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); g2.setRenderingHint(KEY_STROKE_CONTROL, VALUE_STROKE_PURE); g2.setStroke(new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); g2.setBackground(Color.white); g2.setColor(Color.black); Path2D p = getPath(0, 0, 20); g2.draw(p); if (!(new Color(im.getRGB(20, 19))).equals(Color.black)) { throw new Exception("This pixel should be black"); } }
private void doPath(SunGraphics2D sg2d, Shape s, boolean isFill) { Path2D.Float p2df; int transx, transy; if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) { if (s instanceof Path2D.Float) { p2df = (Path2D.Float)s; } else { p2df = new Path2D.Float(s); } transx = sg2d.transX; transy = sg2d.transY; } else { p2df = new Path2D.Float(s, sg2d.transform); transx = 0; transy = 0; } SunToolkit.awtLock(); try { long xgc = validate(sg2d); XDoPath(sg2d, sg2d.surfaceData.getNativeOps(), xgc, transx, transy, p2df, isFill); } finally { SunToolkit.awtUnlock(); } }
void doShape(SunGraphics2D sg2d, Shape s, boolean isfill) { Path2D.Float p2df; int transX; int transY; if (sg2d.transformState <= sg2d.TRANSFORM_INT_TRANSLATE) { if (s instanceof Path2D.Float) { p2df = (Path2D.Float)s; } else { p2df = new Path2D.Float(s); } transX = sg2d.transX; transY = sg2d.transY; } else { p2df = new Path2D.Float(s, sg2d.transform); transX = 0; transY = 0; } try { doShape((GDIWindowSurfaceData)sg2d.surfaceData, sg2d.getCompClip(), sg2d.composite, sg2d.eargb, transX, transY, p2df, isfill); } catch (ClassCastException e) { throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData); } }
static void testAddQuad(Path2D pathA, boolean isEmpty) { try { addQuads(pathA); } catch (IllegalPathStateException ipse) { if (isEmpty) { log("testAddQuad: passed " + "(expected IllegalPathStateException catched)."); return; } else { throw ipse; } } if (isEmpty) { throw new IllegalStateException("IllegalPathStateException not thrown !"); } log("testAddQuad: passed."); }
public void draw(SunGraphics2D sg2d, Shape s) { if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) { if (s instanceof Polygon) { if (sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE) { Polygon p = (Polygon)s; drawPolygon(sg2d, p.xpoints, p.ypoints, p.npoints); return; } } Path2D.Float p2df; int transx, transy; if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) { if (s instanceof Path2D.Float) { p2df = (Path2D.Float)s; } else { p2df = new Path2D.Float(s); } transx = sg2d.transX; transy = sg2d.transY; } else { p2df = new Path2D.Float(s, sg2d.transform); transx = 0; transy = 0; } drawPath(sg2d, p2df, transx, transy); } else if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) { ShapeSpanIterator si = LoopPipe.getStrokeSpans(sg2d, s); try { fillSpans(sg2d, si, 0, 0); } finally { si.dispose(); } } else { fill(sg2d, sg2d.stroke.createStrokedShape(s)); } }
public static Path2D convertPolylineToPath(final IMapObject mapObject) { if (mapObject == null || mapObject.getPolyline() == null || mapObject.getPolyline().getPoints().isEmpty()) { return null; } Path2D path = new Path2D.Float(); path.moveTo(mapObject.getLocation().getX(), mapObject.getLocation().getY()); for (int i = 1; i < mapObject.getPolyline().getPoints().size(); i++) { Point2D point = mapObject.getPolyline().getPoints().get(i); path.lineTo(mapObject.getLocation().getX() + point.getX(), mapObject.getLocation().getY() + point.getY()); } return path; }
@Override protected Shape getDropIndication( TopComponent draggedTC, Point location ) { location = SwingUtilities.convertPoint( getComponent(), location, getTabDisplayer() ); Path2D res = new Path2D.Double(); Rectangle tabRect = getTabDisplayer().dropIndication( draggedTC, location ); if( null != tabRect ) { tabRect = SwingUtilities.convertRectangle( getTabDisplayer(), tabRect, container ); res.append( tabRect, false ); } res.append( container.getContentArea(), false ); return res; }
/** * Creates the shape for a single part of the intermediate bar. * * @param x * @param width * @param h * @param verticval * @return */ private Path2D createIntermediateShape(double x, double width, double h) { int offset = 10; Path2D path = new Path2D.Double(); path.append(new Line2D.Double(x, h, x + offset, 0), true); path.append(new Line2D.Double(x + offset, 0, x + width + offset, 0), true); path.append(new Line2D.Double(x + width + offset, 0, x + width, h), true); path.append(new Line2D.Double(x + width, h, x, h), true); return path; }
public static boolean drawPath(DrawHandler dhnd, Path2D.Float p2df, int transX, int transY) { return doProcessPath(new DrawProcessHandler(dhnd, noopEndSubPathHandler), p2df, transX, transY); }
public void DrawPath(SunGraphics2D sg2d, SurfaceData sData, int transx, int transy, Path2D.Float p2df) { PixelWriter pw = GeneralRenderer.createSolidPixelWriter(sg2d, sData); ProcessPath.drawPath( new PixelWriterDrawHandler(sData, pw, sg2d.getCompClip(), sg2d.strokeHint), p2df, transx, transy ); }
private Path2D drawArrow(int x1, int y1, int x2, int y2) { Path2D context = new Path2D.Float(); int headlen = 10; // length of head in pixels double angle = Math.atan2(y2 - y1, x2 - x1); context.moveTo(x1, y1); context.lineTo(x2, y2); context.lineTo(x2 - headlen * Math.cos(angle - Math.PI / 6), y2 - headlen * Math.sin(angle - Math.PI / 6)); context.moveTo(x2, y2); context.lineTo(x2 - headlen * Math.cos(angle + Math.PI / 6), y2 - headlen * Math.sin(angle + Math.PI / 6)); context.closePath(); return context; }
/** * Creates a new GraphicsJLabel */ public GraphicsJLabel() { super(); myPath = new Path2D.Double(); xx = new double[]{0, 0, 0}; yy = new double[]{0, 0, 0}; }
static void testFlattening(Path2D pathA, Path2D pathB) { final PathIterator itA = pathA.getPathIterator(at, FLATNESS); final PathIterator itB = pathB.getPathIterator(at, FLATNESS); float[] coordsA = new float[6]; float[] coordsB = new float[6]; int n = 0; for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) { int typeA = itA.currentSegment(coordsA); int typeB = itB.currentSegment(coordsB); if (typeA != typeB) { throw new IllegalStateException("Path-segment[" + n + "] " + "type are not equals [" + typeA + "|" + typeB + "] !"); } // Take care of floating-point precision: if (!equalsArrayEps(coordsA, coordsB, getLength(typeA))) { throw new IllegalStateException("Path-segment[" + n + "] coords" + " are not equals [" + Arrays.toString(coordsA) + "|" + Arrays.toString(coordsB) + "] !"); } } if (!itA.isDone() || !itB.isDone()) { throw new IllegalStateException("Paths do not have same lengths !"); } log("testFlattening: " + n + " segments."); }
/** Creates a diamond shape inscribed in the bounds given in the parameters. */ private Shape createDiamondShape(double x, double y, double width, double height) { GeneralPath result = new GeneralPath(Path2D.WIND_NON_ZERO, 5); result.moveTo(x + width / 2, y); result.lineTo(x + width, y + height / 2); result.lineTo(x + width / 2, y + height); result.lineTo(x, y + height / 2); result.closePath(); return result; }
private void paintYPin(Graphics2D g, int number) { double y = top; for (int i = 0; i < number; i++) { y += yBounds[i].getSize().getHeight(); } g.setColor(Color.black); double max = 6; g.setPaint(new GradientPaint(new Point2D.Double(LEFT - max, y - max), Color.green, new Point2D.Double(LEFT + max, y + max), Color.black)); GeneralPath path1 = new GeneralPath(Path2D.WIND_EVEN_ODD, 4); GeneralPath path2 = new GeneralPath(Path2D.WIND_EVEN_ODD, 4); path1.moveTo(LEFT - 5, y); path1.lineTo(LEFT - 5 - max, y + max / 2); path1.lineTo(LEFT - 5 - max, y - max / 2); path1.lineTo(LEFT - 5, y); path2.moveTo(5 + LEFT + width, y); path2.lineTo(5 + LEFT + width + max, y + max / 2); path2.lineTo(5 + LEFT + width + max, y - max / 2); path2.lineTo(5 + LEFT + width, y); g.fill(path1); g.setPaint(new GradientPaint(new Point2D.Double(LEFT + width - max, y - max), Color.black, new Point2D.Double(LEFT + max + width, y + max), Color.green)); g.fill(path2); g.setColor(Color.gray); g.draw(path1); g.draw(path2); }
/** * Малює кінець стрілки. * * @param g Область для виводу стрілки. * @param x Координата x кінця стрілки. * @param y Координата y кінця стрілки. * @param type Напрямок направленості стрілки, MovingPanel.RIGHT,... */ public void paintArrowEnd(final Graphics2D g, double x1, double y1, final double xD, final double yD, int type) { final float x = (float) xD; final float y = (float) yD; final GeneralPath t = new GeneralPath(Path2D.WIND_EVEN_ODD, 3); t.moveTo(x, y); final float arrowWidth = (float) movingArea .getIDoubleOrdinate(ARROW_WIDTH); final float arrowHeight = (float) movingArea .getIDoubleOrdinate(ARROW_HEIGHT); type = MovingPanel.getOpposite(type); switch (type) { case MovingPanel.BOTTOM: { t.lineTo(x - arrowWidth, y - arrowHeight); t.lineTo(x + arrowWidth, y - arrowHeight); } break; case MovingPanel.RIGHT: { t.lineTo(x - arrowHeight, y - arrowWidth); t.lineTo(x - arrowHeight, y + arrowWidth); } break; case MovingPanel.TOP: { t.lineTo(x - arrowWidth, y + arrowHeight); t.lineTo(x + arrowWidth, y + arrowHeight); } break; case MovingPanel.LEFT: { t.lineTo(x + arrowHeight, y - arrowWidth); t.lineTo(x + arrowHeight, y + arrowWidth); } break; } t.closePath(); g.fill(t); }
@Deprecated public static Roi makePolygon(Point2D[] points, double strokeWidth, Color color) { Path2D poly = new Path2D.Double(); if (points.length > 0) { poly.moveTo(points[0].getX(), points[0].getY()); for (int i = 1; i < points.length; i++) { poly.lineTo(points[i].getX(), points[i].getY()); } poly.closePath(); } Roi shapeRoi = new ShapeRoi(poly); shapeRoi.setStrokeWidth(strokeWidth); shapeRoi.setStrokeColor(color); return shapeRoi; }
/** * Create a widened path as specified by the parameters. * <p> * The specified {@code src} {@link Shape} is widened according * to the specified attribute parameters as per the * {@link BasicStroke} specification. * * @param src the source path to be widened * @param width the width of the widened path as per {@code BasicStroke} * @param caps the end cap decorations as per {@code BasicStroke} * @param join the segment join decorations as per {@code BasicStroke} * @param miterlimit the miter limit as per {@code BasicStroke} * @param dashes the dash length array as per {@code BasicStroke} * @param dashphase the initial dash phase as per {@code BasicStroke} * @return the widened path stored in a new {@code Shape} object * @since 1.7 */ @Override public Shape createStrokedShape(Shape src, float width, int caps, int join, float miterlimit, float[] dashes, float dashphase) { final DRendererContext rdrCtx = getRendererContext(); try { // initialize a large copyable Path2D to avoid a lot of array growing: final Path2D.Double p2d = rdrCtx.getPath2D(); strokeTo(rdrCtx, src, null, width, NormMode.OFF, caps, join, miterlimit, dashes, dashphase, rdrCtx.transformerPC2D.wrapPath2d(p2d) ); // Use Path2D copy constructor (trim) return new Path2D.Double(p2d); } finally { // recycle the DRendererContext instance returnRendererContext(rdrCtx); } }
public void FillPath(SunGraphics2D sg2d, SurfaceData sData, int transx, int transy, Path2D.Float p2df) { PixelWriter pw = GeneralRenderer.createXorPixelWriter(sg2d, sData); ProcessPath.fillPath( new PixelWriterDrawHandler(sData, pw, sg2d.getCompClip(), sg2d.strokeHint), p2df, transx, transy); }
public void DrawPath(SunGraphics2D sg2d, SurfaceData sData, int transx, int transy, Path2D.Float p2df) { PixelWriter pw = GeneralRenderer.createXorPixelWriter(sg2d, sData); ProcessPath.drawPath( new PixelWriterDrawHandler(sData, pw, sg2d.getCompClip(), sg2d.strokeHint), p2df, transx, transy ); }
public static boolean fillPath(DrawHandler dhnd, Path2D.Float p2df, int transX, int transY) { FillProcessHandler fhnd = new FillProcessHandler(dhnd); if (!doProcessPath(fhnd, p2df, transX, transY)) { return false; } FillPolygon(fhnd, p2df.getWindingRule()); return true; }
public static void main(final String[] args) { final Path2D path1 = new Path2D.Double(Path2D.WIND_EVEN_ODD, 0); path1.moveTo(10, 10); path1.lineTo(20, 20); final Path2D path2 = new Path2D.Float(Path2D.WIND_EVEN_ODD, 0); path2.moveTo(10, 10); path2.lineTo(20, 20); }
static void testIterator(Path2D pathA, Path2D pathB) { final PathIterator itA = pathA.getPathIterator(at); final PathIterator itB = pathB.getPathIterator(at); float[] coordsA = new float[6]; float[] coordsB = new float[6]; int n = 0; for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) { int typeA = itA.currentSegment(coordsA); int typeB = itB.currentSegment(coordsB); if (typeA != typeB) { throw new IllegalStateException("Path-segment[" + n + "] " + "type are not equals [" + typeA + "|" + typeB + "] !"); } // Take care of floating-point precision: if (!equalsArrayEps(coordsA, coordsB, getLength(typeA))) { throw new IllegalStateException("Path-segment[" + n + "] coords" + " are not equals [" + Arrays.toString(coordsA) + "|" + Arrays.toString(coordsB) + "] !"); } } if (!itA.isDone() || !itB.isDone()) { throw new IllegalStateException("Paths do not have same lengths !"); } log("testIterator: " + n + " segments."); }
protected void fillPath(SunGraphics2D sg2d, Path2D.Float p2df, int transx, int transy) { rq.lock(); try { validateContext(sg2d); drawHandler.validate(sg2d); drawHandler.startFillPath(); ProcessPath.fillPath(drawHandler, p2df, transx, transy); drawHandler.endFillPath(); } finally { rq.unlock(); } }
protected void drawPath(SunGraphics2D sg2d, Path2D.Float p2df, int transx, int transy) { rq.lock(); try { validateContext(sg2d); drawHandler.validate(sg2d); ProcessPath.drawPath(drawHandler, p2df, transx, transy); } finally { rq.unlock(); } }