Java Code Examples for java.awt.Polygon
The following examples show how to use
java.awt.Polygon. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jdk8u_jdk Source File: UnmanagedDrawImagePerformance.java License: GNU General Public License v2.0 | 6 votes |
private static long test(Image bi, Image vi, AffineTransform atfm) { final Polygon p = new Polygon(); p.addPoint(0, 0); p.addPoint(SIZE, 0); p.addPoint(0, SIZE); p.addPoint(SIZE, SIZE); p.addPoint(0, 0); Graphics2D g2d = (Graphics2D) vi.getGraphics(); g2d.clip(p); g2d.transform(atfm); g2d.setComposite(AlphaComposite.SrcOver); final long start = System.nanoTime(); g2d.drawImage(bi, 0, 0, null); final long time = System.nanoTime() - start; g2d.dispose(); return time; }
Example 2
Source Project: TranskribusCore Source File: ImgUtilsTest.java License: GNU General Public License v3.0 | 6 votes |
private static void testBorderRemoval() throws IOException, JAXBException{ File testImg = new File("/mnt/dea_scratch/TRP/test/I._ZvS_1902_4.Q/ZS-I-1902-198 (1).jpg"); File testXml = new File("/mnt/dea_scratch/TRP/test/I._ZvS_1902_4.Q/page/ZS-I-1902-198 (1).xml"); // Open the image. // BufferedImage baseImage = ImageIO.read(testImg); PcGtsType pc = PageXmlUtils.unmarshal(testXml); final CoordsType coords = pc.getPage().getPrintSpace().getCoords(); // build printspace polygon Polygon p = PageXmlUtils.buildPolygon(coords); String outPng = "/tmp/output.png"; File out = ImgUtils.killBorder(testImg, p, outPng); // File bin = NcsrTools.binarize(out, new File("/tmp/bin.tiff")); // // File reg = NcsrTools.segmentRegions(out, bin, new File("/tmp/reg.xml")); // File lines = NcsrTools.segmentLines(bin, reg, new File("/tmp/output.xml")); }
Example 3
Source Project: freerouting Source File: GraphicsContext.java License: GNU General Public License v3.0 | 6 votes |
/** * Fill the interior of the polygon shape represented by p_points. */ public void fill_shape(FloatPoint[] p_points, Graphics p_g, Color p_color, double p_translucency_factor) { if (p_color == null) { return; } Graphics2D g2 = (Graphics2D)p_g; Polygon draw_polygon = new Polygon(); for(int i= 0; i < p_points.length; i++) { Point2D curr_corner = coordinate_transform.board_to_screen(p_points[i]); draw_polygon.addPoint((int)Math.round(curr_corner.getX()), (int)Math.round(curr_corner.getY())); } g2.setColor(p_color); set_translucency(g2, p_translucency_factor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.fill(draw_polygon); }
Example 4
Source Project: jasperreports Source File: JRPrintImageArea.java License: GNU Lesser General Public License v3.0 | 6 votes |
private Shape createAWTPolygon() { if (coordinates == null || coordinates.length == 0 || coordinates.length % 2 != 0) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_POLYGON_COORDINATES_ERROR, (Object[])null); } Polygon polygon = new Polygon(); int i; for (i = 0; i < coordinates.length - 2; i += 2) { polygon.addPoint(coordinates[i], coordinates[i + 1]); } if (coordinates[i] != coordinates[0] || coordinates[i + 1] != coordinates[1]) { polygon.addPoint(coordinates[i], coordinates[i + 1]); } return polygon; }
Example 5
Source Project: Pixie Source File: ResizeTest.java License: MIT License | 6 votes |
/** * Test of resizedToOriginal for polygon method, of class Resize. * * No further tests are done because the resize of the polygon points is * done based on resizedToOriginal for values methods. */ @Test public void testResizedToOriginal_Polygon_01() { final String testDescription = "----------resizedToOriginalPolygon_01----------\n" + " Summary: Test of resizedToOriginal(Polygon) method, of class Resize\n" + " Description: Check there is no exception when processing null input. Input value null, the resize is set to (1.0, 1.0).\n" + " Pre-conditions: none\n" + " Conditions: none\n" + " Expected result: It shall output null; no errors or exceptions shall occur.\n"; System.out.println(testDescription); Polygon polyResized = null; Resize instance = new Resize(1.0, 1.0); Polygon expResult = null; Polygon result = instance.resizedToOriginal(polyResized); assertEquals(expResult, result); }
Example 6
Source Project: astor Source File: ShapeUtilities.java License: GNU General Public License v2.0 | 6 votes |
/** * Tests two polygons for equality. If both are <code>null</code> this * method returns <code>true</code>. * * @param p1 polygon 1 (<code>null</code> permitted). * @param p2 polygon 2 (<code>null</code> permitted). * * @return A boolean. */ public static boolean equal(Polygon p1, Polygon p2) { if (p1 == null) { return (p2 == null); } if (p2 == null) { return false; } if (p1.npoints != p2.npoints) { return false; } if (!Arrays.equals(p1.xpoints, p2.xpoints)) { return false; } if (!Arrays.equals(p1.ypoints, p2.ypoints)) { return false; } return true; }
Example 7
Source Project: stendhal Source File: TextBoxFactory.java License: GNU General Public License v2.0 | 6 votes |
/** * Draw a chat bubble. * * @param g2d * @param fillColor the bacground color of the bubble * @param outLineColor the color of the bubble outline * @param width width of the bubble body * @param height height of the bubble */ private void drawBubble(final Graphics2D g2d, final Color fillColor, final Color outLineColor, final int width, final int height) { /* * There's an one pixel difference in how sun java and openjdk * do drawRoundRect, so we use fillRoundRect for both the * outline and the fill to have pretty bubbles on both */ g2d.setColor(outLineColor); g2d.fillRoundRect(BUBBLE_OFFSET, 0, width, height, ARC_DIAMETER, ARC_DIAMETER); g2d.setColor(fillColor); g2d.fillRoundRect(BUBBLE_OFFSET + 1, 1, width - 2, height - 2, ARC_DIAMETER, ARC_DIAMETER); // The bubble handle final Polygon p = new Polygon(); p.addPoint(BUBBLE_OFFSET + 1, MARGIN_WIDTH + 1); p.addPoint(0, LINE_HEIGHT); p.addPoint(BUBBLE_OFFSET + 1, LINE_HEIGHT / 2 + MARGIN_WIDTH); g2d.fillPolygon(p); g2d.setColor(outLineColor); g2d.drawLine(0, LINE_HEIGHT, BUBBLE_OFFSET, MARGIN_WIDTH + 1); g2d.drawLine(0, LINE_HEIGHT, BUBBLE_OFFSET, LINE_HEIGHT / 2 + MARGIN_WIDTH); }
Example 8
Source Project: triplea Source File: PolygonGrabber.java License: GNU General Public License v3.0 | 6 votes |
private boolean doesPolygonContainAnyBlackInside( final Polygon poly, final BufferedImage imageCopy, final Graphics imageCopyGraphics) { // we would like to just test if each point is both black and contained within the polygon, // but contains counts // the borders, so we have to turn the border edges a different color (then later back to // black again) using a // copy of the image imageCopyGraphics.setColor(Color.GREEN); imageCopyGraphics.drawPolygon(poly.xpoints, poly.ypoints, poly.npoints); final Rectangle rect = poly.getBounds(); for (int x = rect.x; x < rect.x + rect.width; x++) { for (int y = rect.y; y < rect.y + rect.height; y++) { if (isBlack(x, y, imageCopy) && poly.contains(new Point(x, y))) { imageCopyGraphics.setColor(Color.BLACK); imageCopyGraphics.drawPolygon(poly.xpoints, poly.ypoints, poly.npoints); return true; } } } imageCopyGraphics.setColor(Color.BLACK); imageCopyGraphics.drawPolygon(poly.xpoints, poly.ypoints, poly.npoints); return false; }
Example 9
Source Project: coming Source File: Elixir_001_t.java License: MIT License | 6 votes |
/** * Tests two shapes for equality. If both shapes are <code>null</code>, * this method will return <code>true</code>. * <p> * In the current implementation, the following shapes are supported: * <code>Ellipse2D</code>, <code>Line2D</code> and <code>Rectangle2D</code> * (implicit). * * @param s1 the first shape (<code>null</code> permitted). * @param s2 the second shape (<code>null</code> permitted). * * @return A boolean. */ public static boolean equal(Shape s1, Shape s2) { if (s1 instanceof Line2D && s2 instanceof Line2D) { return equal((Line2D) s1, (Line2D) s2); } else if (s1 instanceof Ellipse2D && s2 instanceof Ellipse2D) { return equal((Ellipse2D) s1, (Ellipse2D) s2); } else if (s1 instanceof Arc2D && s2 instanceof Arc2D) { return equal((Arc2D) s1, (Arc2D) s2); } else if (s1 instanceof Polygon && s2 instanceof Polygon) { return equal((Polygon) s1, (Polygon) s2); } else if (s1 instanceof GeneralPath && s2 instanceof GeneralPath) { return equal((GeneralPath) s1, (GeneralPath) s2); } else { // this will handle Rectangle2D... return ObjectUtilities.equal(s1, s2); } }
Example 10
Source Project: geosense Source File: TZWorld.java License: Apache License 2.0 | 6 votes |
/** * Determine if a (lat,lon) point is contained in this extent */ public boolean contains(double lat, double lon) { int ilat = integerize(lat); int ilon = integerize(lon); if (!bbox.contains(ilon, ilat)) return false; if (excludes != null) for (Polygon exclude : excludes) if (exclude.contains(ilon, ilat)) return false; if (includes != null) for (Polygon include : includes) if (include.contains(ilon, ilat)) return true; return false; }
Example 11
Source Project: coming Source File: Elixir_001_s.java License: MIT License | 6 votes |
/** * Tests two shapes for equality. If both shapes are <code>null</code>, * this method will return <code>true</code>. * <p> * In the current implementation, the following shapes are supported: * <code>Ellipse2D</code>, <code>Line2D</code> and <code>Rectangle2D</code> * (implicit). * * @param s1 the first shape (<code>null</code> permitted). * @param s2 the second shape (<code>null</code> permitted). * * @return A boolean. */ public static boolean equal(Shape s1, Shape s2) { if (s1 instanceof Line2D && s2 instanceof Line2D) { return equal((Line2D) s1, (Line2D) s2); } else if (s1 instanceof Ellipse2D && s2 instanceof Ellipse2D) { return equal((Ellipse2D) s1, (Ellipse2D) s2); } else if (s1 instanceof Arc2D && s2 instanceof Arc2D) { return equal((Arc2D) s1, (Arc2D) s2); } else if (s1 instanceof Polygon && s2 instanceof Polygon) { return equal((Polygon) s1, (Polygon) s2); } else if (s1 instanceof GeneralPath && s2 instanceof GeneralPath) { return equal((GeneralPath) s1, (GeneralPath) s2); } else { // this will handle Rectangle2D... return ObjectUtilities.equal(s1, s2); } }
Example 12
Source Project: energy2d Source File: BackgroundComboBox.java License: GNU Lesser General Public License v3.0 | 5 votes |
public void paintIcon(Component c, Graphics g, int x, int y) { int w = getIconWidth(); int h = getIconHeight(); Polygon triangle = new Polygon(); triangle.addPoint(x, y); triangle.addPoint(x + w, y); triangle.addPoint(x + w / 2, y + h); g.setColor(popButton.isEnabled() ? SystemColor.textText : SystemColor.textInactiveText); g.fillPolygon(triangle); }
Example 13
Source Project: openjdk-jdk8u Source File: Test8004821.java License: GNU General Public License v2.0 | 5 votes |
private static void test(final Graphics2D g, final int[] arr) { g.drawPolygon(arr, arr, arr.length); g.drawPolygon(new Polygon(arr, arr, arr.length)); g.fillPolygon(arr, arr, arr.length); g.fillPolygon(new Polygon(arr, arr, arr.length)); g.drawPolyline(arr, arr, arr.length); }
Example 14
Source Project: TencentKona-8 Source File: CSSBorder.java License: GNU General Public License v2.0 | 5 votes |
public void paint(Polygon shape, Graphics g, Color color, int side) { Rectangle r = shape.getBounds(); int length = r.height * factor; int[] lengthPattern = { length, length }; Color[] colorPattern = { color, null }; paintStrokes(r, g, View.X_AXIS, lengthPattern, colorPattern); }
Example 15
Source Project: runelite Source File: OverlayUtil.java License: BSD 2-Clause "Simplified" License | 5 votes |
public static void renderActorOverlay(Graphics2D graphics, Actor actor, String text, Color color) { Polygon poly = actor.getCanvasTilePoly(); if (poly != null) { renderPolygon(graphics, poly, color); } Point textLocation = actor.getCanvasTextLocation(graphics, text, actor.getLogicalHeight() + 40); if (textLocation != null) { renderTextLocation(graphics, textLocation, text, color); } }
Example 16
Source Project: TencentKona-8 Source File: CSSBorder.java License: GNU General Public License v2.0 | 5 votes |
public void paint(Polygon shape, Graphics g, Color color, int side) { Rectangle r = shape.getBounds(); int length = Math.max(r.height / 2, 1); int[] lengthPattern = { length, length }; Color[] colorPattern = ((side + 1) % 4 < 2) == (type == Value.GROOVE) ? new Color[] { getShadowColor(color), getLightColor(color) } : new Color[] { getLightColor(color), getShadowColor(color) }; paintStrokes(r, g, View.Y_AXIS, lengthPattern, colorPattern); }
Example 17
Source Project: jdk8u-dev-jdk Source File: CSSBorder.java License: GNU General Public License v2.0 | 5 votes |
public void paint(Polygon shape, Graphics g, Color color, int side) { Rectangle r = shape.getBounds(); int length = r.height * factor; int[] lengthPattern = { length, length }; Color[] colorPattern = { color, null }; paintStrokes(r, g, View.X_AXIS, lengthPattern, colorPattern); }
Example 18
Source Project: rcrs-server Source File: Geometry.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public static Area getClearArea(Human agent, int targetX, int targetY, int clearLength, int clearRad) { Vector2D agentToTarget = new Vector2D(targetX - agent.getX(), targetY - agent.getY()); if (agentToTarget.getLength() > clearLength) agentToTarget = agentToTarget.normalised().scale(clearLength); agentToTarget = agentToTarget.normalised().scale(agentToTarget.getLength() + 510); Vector2D backAgent = (new Vector2D(agent.getX(), agent.getY())) .add(agentToTarget.normalised().scale(-510)); Line2D line = new Line2D(backAgent.getX(), backAgent.getY(), agentToTarget.getX(), agentToTarget.getY()); Vector2D dir = agentToTarget.normalised().scale(clearRad); Vector2D perpend1 = new Vector2D(-dir.getY(), dir.getX()); Vector2D perpend2 = new Vector2D(dir.getY(), -dir.getX()); rescuecore2.misc.geometry.Point2D points[] = new rescuecore2.misc.geometry.Point2D[] { line.getOrigin().plus(perpend1), line.getEndPoint().plus(perpend1), line.getEndPoint().plus(perpend2), line.getOrigin().plus(perpend2) }; int[] xPoints = new int[points.length]; int[] yPoints = new int[points.length]; for (int i = 0; i < points.length; i++) { xPoints[i] = (int) points[i].getX(); yPoints[i] = (int) points[i].getY(); } return new Area(new Polygon(xPoints, yPoints, points.length)); }
Example 19
Source Project: jdk8u60 Source File: BasicIconFactory.java License: GNU General Public License v2.0 | 5 votes |
public void paintIcon(Component c, Graphics g, int x, int y) { Polygon p = new Polygon(); p.addPoint(x, y); p.addPoint(x+getIconWidth(), y+getIconHeight()/2); p.addPoint(x, y+getIconHeight()); g.fillPolygon(p); }
Example 20
Source Project: TrakEM2 Source File: M.java License: GNU General Public License v3.0 | 5 votes |
/** Converts all points in @param area to ints by casting. */ static public final Area areaInInts(final Area area) { final Area a = new Area(); for (final Polygon pol : M.getPolygons(area)) { a.exclusiveOr(new Area(pol)); } return a; }
Example 21
Source Project: plugins Source File: CannonOverlay.java License: GNU General Public License v3.0 | 5 votes |
/** * Draw the double hit spots on a 6 by 6 grid around the cannon * * @param startTile The position of the cannon */ private void drawDoubleHitSpots(Graphics2D graphics, LocalPoint startTile, Color color) { for (int x = -3; x <= 3; x++) { for (int y = -3; y <= 3; y++) { if (y != 1 && x != 1 && y != -1 && x != -1) { continue; } //Ignore center square if (y >= -1 && y <= 1 && x >= -1 && x <= 1) { continue; } int xPos = startTile.getX() - (x * LOCAL_TILE_SIZE); int yPos = startTile.getY() - (y * LOCAL_TILE_SIZE); LocalPoint marker = new LocalPoint(xPos, yPos); Polygon poly = Perspective.getCanvasTilePoly(client, marker); if (poly == null) { continue; } OverlayUtil.renderPolygon(graphics, poly, color); } } }
Example 22
Source Project: clipper-java Source File: PolygonCanvas.java License: Boost Software License 1.0 | 5 votes |
private Polygon createPolygonFromPath( Path p ) { final int[] x = new int[p.size()]; final int[] y = new int[p.size()]; for (int i = p.size() - 1; i >= 0; i--) { final LongPoint ip = p.get( i ); x[i] = (int) (ip.getX() * zoom) + cur.x - origin.x; y[i] = (int) (ip.getY() * zoom) + cur.y - origin.y; } return new Polygon( x, y, p.size() ); }
Example 23
Source Project: magarena Source File: SplitterButton.java License: GNU General Public License v3.0 | 5 votes |
private Polygon getDownTriangle(final int x) { final int y = (getHeight() - TRIANGLE_HEIGHT) / 2; final Polygon p = new Polygon(); p.addPoint(x, y + 1); p.addPoint(x + (TRIANGLE_WIDTH / 2), getHeight() - y); p.addPoint(x + TRIANGLE_WIDTH, y + 1); return p; }
Example 24
Source Project: netbeans Source File: NimbusEditorTabCellRenderer.java License: Apache License 2.0 | 5 votes |
public void paintInterior(Graphics g, Component c) { NimbusEditorTabCellRenderer ren = (NimbusEditorTabCellRenderer) c; Polygon p = getInteriorPolygon(c); Rectangle bounds = p.getBounds(); int yDiff = getHeightDifference(ren); paintTabBackground(g, 0, c, bounds.x, bounds.y + yDiff, bounds.width, bounds.height - yDiff); }
Example 25
Source Project: pdfxtk Source File: StraightLineRouter.java License: Apache License 2.0 | 5 votes |
public void setupEdges(GraphPanel panel, GraphEdge[] edges, Component[] nodes) { for(int i = 0; i < edges.length; i++) { GraphEdge edge = edges[i]; int[] x = {(int)(edge.startport.x * edge.startcmp.getWidth()) + edge.startcmp.getX(), (int)(edge.endport.x * edge.endcmp.getWidth()) + edge.endcmp.getX()}; int[] y = {(int)(edge.startport.y * edge.startcmp.getHeight()) + edge.startcmp.getY(), (int)(edge.endport.y * edge.endcmp.getHeight()) + edge.endcmp.getY()}; edge.polyline = new Polygon(x, y, 2); double angle = Awt.getAngle(x[0], y[0], x[1], y[1]) + PI2; for(int j = 0; j < edge.markers.length; j++) GraphEdgeUtils.setupMTrans(edge, j, angle, x[0], y[0], x[1], y[1]); } }
Example 26
Source Project: openjdk-8-source Source File: CSSBorder.java License: GNU General Public License v2.0 | 5 votes |
public void paint(Polygon shape, Graphics g, Color color, int side) { Rectangle r = shape.getBounds(); int length = Math.max(r.height / 3, 1); int[] lengthPattern = { length, length }; Color[] colorPattern = { color, null }; paintStrokes(r, g, View.Y_AXIS, lengthPattern, colorPattern); }
Example 27
Source Project: megamek Source File: C3Sprite.java License: GNU General Public License v2.0 | 5 votes |
private void makePoly() { // make a polygon final Point a = bv.getHexLocation(entityE.getPosition()); final Point t = this.bv.getHexLocation(entityM.getPosition()); final double an = (entityE.getPosition().radian( entityM.getPosition()) + (Math.PI * 1.5)) % (Math.PI * 2); // angle final double lw = this.bv.scale * BoardView1.C3_LINE_WIDTH; // line width c3Poly = new Polygon(); c3Poly.addPoint( a.x + (int) ((this.bv.scale * (BoardView1.HEX_W / 2)) - (int) Math .round(Math.sin(an) * lw)), a.y + (int) ((this.bv.scale * (BoardView1.HEX_H / 2)) + (int) Math .round(Math.cos(an) * lw))); c3Poly.addPoint( a.x + (int) ((this.bv.scale * (BoardView1.HEX_W / 2)) + (int) Math .round(Math.sin(an) * lw)), a.y + (int) ((this.bv.scale * (BoardView1.HEX_H / 2)) - (int) Math .round(Math.cos(an) * lw))); c3Poly.addPoint( t.x + (int) ((this.bv.scale * (BoardView1.HEX_W / 2)) + (int) Math .round(Math.sin(an) * lw)), t.y + (int) ((this.bv.scale * (BoardView1.HEX_H / 2)) - (int) Math .round(Math.cos(an) * lw))); c3Poly.addPoint( t.x + (int) ((this.bv.scale * (BoardView1.HEX_W / 2)) - (int) Math .round(Math.sin(an) * lw)), t.y + (int) ((this.bv.scale * (BoardView1.HEX_H / 2)) + (int) Math .round(Math.cos(an) * lw))); }
Example 28
Source Project: triplea Source File: AutoPlacementFinder.java License: GNU General Public License v3.0 | 5 votes |
private List<Point> getPlacementsStartingAtTopLeft( final Collection<Polygon> countryPolygons, final Rectangle bounding, final Point center, final Collection<Polygon> containedCountryPolygons) { final List<Rectangle2D> placementRects = new ArrayList<>(); final List<Point> placementPoints = new ArrayList<>(); final Rectangle2D place = new Rectangle2D.Double(center.x, center.y, placeHeight, placeWidth); for (int x = bounding.x + 1; x < bounding.width + bounding.x; x++) { for (int y = bounding.y + 1; y < bounding.height + bounding.y; y++) { isPlacement( countryPolygons, containedCountryPolygons, placementRects, placementPoints, place, x, y); } if (placementPoints.size() > 50) { break; } } if (placementPoints.isEmpty()) { final int defaultx = center.x - (placeHeight / 2); final int defaulty = center.y - (placeWidth / 2); placementPoints.add(new Point(defaultx, defaulty)); } return placementPoints; }
Example 29
Source Project: openjdk-jdk8u-backup Source File: Test8004821.java License: GNU General Public License v2.0 | 5 votes |
private static void test(final Graphics2D g, final int[] arr) { g.drawPolygon(arr, arr, arr.length); g.drawPolygon(new Polygon(arr, arr, arr.length)); g.fillPolygon(arr, arr, arr.length); g.fillPolygon(new Polygon(arr, arr, arr.length)); g.drawPolyline(arr, arr, arr.length); }
Example 30
Source Project: jdk8u-dev-jdk Source File: CSSBorder.java License: GNU General Public License v2.0 | 5 votes |
public void paint(Polygon shape, Graphics g, Color color, int side) { Rectangle r = shape.getBounds(); int length = Math.max(r.height / 2, 1); int[] lengthPattern = { length, length }; Color[] colorPattern = ((side + 1) % 4 < 2) == (type == Value.GROOVE) ? new Color[] { getShadowColor(color), getLightColor(color) } : new Color[] { getLightColor(color), getShadowColor(color) }; paintStrokes(r, g, View.Y_AXIS, lengthPattern, colorPattern); }