java.awt.Polygon Java Examples

The following examples show how to use java.awt.Polygon. 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 File: Elixir_001_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 #2
Source File: JRPrintImageArea.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #3
Source File: TZWorld.java    From geosense with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #4
Source File: Elixir_001_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 #5
Source File: ImgUtilsTest.java    From TranskribusCore with GNU General Public License v3.0 6 votes vote down vote up
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 #6
Source File: PolygonGrabber.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
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 #7
Source File: ResizeTest.java    From Pixie with MIT License 6 votes vote down vote up
/**
 * 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 #8
Source File: GraphicsContext.java    From freerouting with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #9
Source File: TextBoxFactory.java    From stendhal with GNU General Public License v2.0 6 votes vote down vote up
/**
  * 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 #10
Source File: UnmanagedDrawImagePerformance.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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 #11
Source File: ShapeUtilities.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #12
Source File: BasicIconFactory.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 #13
Source File: X11Renderer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
        // Delegate to drawPolygon() if possible...
        if (s instanceof Polygon &&
            sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE)
        {
            Polygon p = (Polygon) s;
            drawPolygon(sg2d, p.xpoints, p.ypoints, p.npoints);
            return;
        }

        // Otherwise we will use drawPath() for
        // high-quality thin paths.
        doPath(sg2d, s, false);
    } else if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
        // REMIND: X11 can handle uniform scaled wide lines
        // and dashed lines itself if we set the appropriate
        // XGC attributes (TBD).
        ShapeSpanIterator si = LoopPipe.getStrokeSpans(sg2d, s);
        try {
            SunToolkit.awtLock();
            try {
                long xgc = validate(sg2d);
                XFillSpans(sg2d.surfaceData.getNativeOps(), xgc,
                           si, si.getNativeIterator(),
                           0, 0);
            } finally {
                SunToolkit.awtUnlock();
            }
        } finally {
            si.dispose();
        }
    } else {
        fill(sg2d, sg2d.stroke.createStrokedShape(s));
    }
}
 
Example #14
Source File: CSSBorder.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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 File: Pipe.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Expects Rectangle in world coords. */
@Override
   public boolean intersects(final Layer layer, final Rectangle r) {
	final Polygon[] pol = getSubPerimeters(layer); // transformed
	if (null == pol) return false;
	for (final Polygon p : pol) if (new Area(p).intersects(r.x, r.y, r.width, r.height)) return true;
	return false;
}
 
Example #16
Source File: SystemsBuilder.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
private BrokenLine refineBorder (BrokenLine border,
                                 SystemInfo prevSystem,
                                 SystemInfo system)
{
    // Define the inter-system yellow zone
    int yellowDy = sheet.getScale().toPixels(constants.yellowZoneHalfHeight);
    Polygon polygon = new Polygon();
    Point left = border.getPoint(0);
    Point right = border.getPoint(1);
    polygon.addPoint(left.x, left.y - yellowDy);
    polygon.addPoint(right.x, right.y - yellowDy);
    polygon.addPoint(right.x, right.y + yellowDy);
    polygon.addPoint(left.x, left.y + yellowDy);

    // Look for glyphs intersected by this yellow zone
    List<Glyph> intersected = new ArrayList<>();

    for (Glyph glyph : nest.getActiveGlyphs()) {
        if (polygon.intersects(glyph.getBounds())) {
            intersected.add(glyph);
        }
    }

    logger.debug("S#{}-{} : {}{}", prevSystem.getId(),
            system.getId(), polygon.getBounds(),
            Glyphs.toString(" inter:", intersected));

    // If the yellow zone is empty, keep the border
    // Otherwise, use the more complex approach
    if (intersected.isEmpty()) {
        return border;
    } else {
        return new BorderBuilder(sheet, prevSystem, system).buildBorder();
    }
}
 
Example #17
Source File: PolygonFade.java    From IngressAnimations with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void drawIntermediate(Graphics gr, Scale scale, double u) {
	gr.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(u*64)));
	int[] ix = new int[xs.length];
	int[] iy = new int[xs.length];
	for (int i=0; i<ix.length; i++) {
		int[] ixy = scale.toGraphics(xs[i], ys[i]);
		ix[i] = ixy[0];
		iy[i] = ixy[1];
	}
	Polygon p = new Polygon(ix, iy, ix.length);
	gr.fillPolygon(p);
}
 
Example #18
Source File: AbstractViewTabDisplayerUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
    public Polygon getExactTabIndication(int index) {
        // TBD - the same code is copied in ScrollableTabsUI, should be shared
        // if will not differ
//        GeneralPath indication = new GeneralPath();
        JComponent control = getDisplayer();
        int height = control.getHeight();

        TabLayoutModel tlm = getLayoutModel();

        int tabXStart = tlm.getX(index);

        int tabXEnd = tabXStart + tlm.getW(index);

        int[] xpoints = new int[4];
        int[] ypoints = new int[4];
        xpoints[0] = tabXStart;
        ypoints[0] = 0;
        xpoints[1] = tabXEnd;
        ypoints[1] = 0;
        xpoints[2] = tabXEnd;
        ypoints[2] = height - 1;
        xpoints[3] = tabXStart;
        ypoints[3] = height - 1;

        return new EqualPolygon(xpoints, ypoints);
    }
 
Example #19
Source File: BufferedRenderPipe.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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));
    }
}
 
Example #20
Source File: BackgroundComboBox.java    From energy2d with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #21
Source File: Glyphs.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Look up in a collection of glyph instances for <b>all</b> glyph
 * instances contained in a provided polygon.
 *
 * @param collection the collection of glyph instances to be browsed
 * @param polygon    the containing polygon
 * @return the glyph instances found, which may be an empty list
 */
public static Set<Glyph> containedGlyphs (Collection<? extends Glyph> collection,
                                          Polygon polygon)
{
    Set<Glyph> set = new LinkedHashSet<>();

    for (Glyph glyph : collection) {
        if (polygon.contains(glyph.getBounds())) {
            set.add(glyph);
        }
    }

    return set;
}
 
Example #22
Source File: Pipe.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
synchronized public boolean isRoughlyInside(final Layer layer, final Rectangle r) {
	final Polygon[] pols = getSubPerimeters(layer); // in world coords
	if (null == pols) return false;
	for (final Polygon pol : pols) {
		if (pol.intersects(r)) return true;
	}
	return false;
}
 
Example #23
Source File: X11Renderer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void draw(SunGraphics2D sg2d, Shape s) {
    if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
        // Delegate to drawPolygon() if possible...
        if (s instanceof Polygon &&
            sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE)
        {
            Polygon p = (Polygon) s;
            drawPolygon(sg2d, p.xpoints, p.ypoints, p.npoints);
            return;
        }

        // Otherwise we will use drawPath() for
        // high-quality thin paths.
        doPath(sg2d, s, false);
    } else if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
        // REMIND: X11 can handle uniform scaled wide lines
        // and dashed lines itself if we set the appropriate
        // XGC attributes (TBD).
        ShapeSpanIterator si = LoopPipe.getStrokeSpans(sg2d, s);
        try {
            SunToolkit.awtLock();
            try {
                long xgc = validate(sg2d);
                XFillSpans(sg2d.surfaceData.getNativeOps(), xgc,
                           si, si.getNativeIterator(),
                           0, 0);
            } finally {
                SunToolkit.awtUnlock();
            }
        } finally {
            si.dispose();
        }
    } else {
        fill(sg2d, sg2d.stroke.createStrokedShape(s));
    }
}
 
Example #24
Source File: PointFileReaderWriter.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
/** Returns a map of the form String -> Collection of polygons. */
public static Map<String, List<Polygon>> readOneToManyPolygons(final InputStream stream)
    throws IOException {
  checkNotNull(stream);

  final Map<String, List<Polygon>> mapping = new HashMap<>();
  readStream(stream, current -> readMultiplePolygons(current, mapping));
  return mapping;
}
 
Example #25
Source File: CSSBorder.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 #26
Source File: Test8004821.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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 #27
Source File: AutoPlacementFinder.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
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 #28
Source File: C3Sprite.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
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 #29
Source File: CSSBorder.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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 #30
Source File: StraightLineRouter.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
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]);
   } 
 }