java.awt.Polygon.contains()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(182)

本文整理了Java中java.awt.Polygon.contains()方法的一些代码示例,展示了Polygon.contains()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Polygon.contains()方法的具体详情如下:
包路径:java.awt.Polygon
类名称:Polygon
方法名:contains

Polygon.contains介绍

[英]Determines whether the specified coordinates are inside this Polygon.
[中]确定指定的坐标是否在此Polygon内。

代码示例

代码示例来源:origin: stackoverflow.com

import java.awt.Polygon;

public class JavaTest {

 public static void main(final String[] args) {

  final Polygon polygon = new Polygon();
  polygon.addPoint(-10, -10);
  polygon.addPoint(-10, 10);
  polygon.addPoint(10, 10);
  polygon.addPoint(10, -10);

  System.out.println(polygon.contains(0, 0));

 }

}

代码示例来源:origin: runelite/runelite

private void renderTileTooltip(Graphics2D graphics, Tile tile)
{
  Polygon poly = Perspective.getCanvasTilePoly(client, tile.getLocalLocation());
  if (poly != null && poly.contains(client.getMouseCanvasPosition().getX(), client.getMouseCanvasPosition().getY()))
  {
    toolTipManager.add(new Tooltip("World Location: " + tile.getWorldLocation().getX() + ", " + tile.getWorldLocation().getY() + ", " + client.getPlane()));
    OverlayUtil.renderPolygon(graphics, poly, GREEN);
  }
}

代码示例来源:origin: stackoverflow.com

super.mouseClicked(me);
if (poly.contains(me.getPoint())) {
  System.out.println("Clicked polygon");

代码示例来源:origin: org.apache.airavata/airavata-xbaya-gui

/**
 * @see org.apache.airavata.xbaya.ui.graph.NodeGUI#isIn(java.awt.Point)
 */
@Override
protected boolean isIn(Point point) {
  return this.polygon.contains(point);
}

代码示例来源:origin: org.softsmithy.lib/lib-core

/**
 * Determines if the specified coordinates are inside this Star. For the
 * definition of insideness, see the class comments of Shape.
 *
 * @param x  x-coordinate
 * @param y  y-coordinate
 * @return   true if the Star contains the specified coordinates; false
 *      otherwise.
 */

public boolean contains(double x, double y) {
  return fPolygon.contains(x, y);
}

代码示例来源:origin: org.apache.airavata/airavata-xbaya-gui

/**
 * @see org.apache.airavata.xbaya.ui.graph.NodeGUI#isIn(java.awt.Point)
 */
@Override
protected boolean isIn(Point point) {
  return this.polygon.contains(point);
}

代码示例来源:origin: org.apache.airavata/airavata-xbaya-gui

/**
 * @see org.apache.airavata.xbaya.ui.graph.NodeGUI#isIn(java.awt.Point)
 */
@Override
protected boolean isIn(Point point) {
  return this.polygon.contains(point);
}

代码示例来源:origin: org.softsmithy.lib/lib-core

/**
 * Tests if the interior of this Star entirely contains the specified
 * Rectangle2D.
 *
 * @param r  the specified Rectangle2D
 * @return   true if this Star entirely contains the specified Rectangle2D;
 *      false otherwise.
 * @see      #contains(double, double, double, double)
 */
public boolean contains(Rectangle2D r) {
  return fPolygon.contains(r);
}

代码示例来源:origin: org.apache.airavata/airavata-xbaya-gui

/**
 * @see edu.indiana.extreme.xbaya.graph.gui.NodeGUI#isIn(java.awt.Point)
 */
@Override
protected boolean isIn(Point point) {
  return this.polygon.contains(point);
}

代码示例来源:origin: org.softsmithy.lib/softsmithy-lib-awt

/**
 * Tests if a specified Point2D is inside the boundary of this Star.
 *
 * @param p  a specified Point2D
 * @return   true if this Star contains the specified Point2D; false
 *      otherwise.
 * @see      #contains(double x, double y)
 */

@Override
public boolean contains(Point2D p) {
  return fPolygon.contains(p);
}

代码示例来源:origin: MegaMek/megamek

/**
 * Return true if the point is inside our polygon
 */
@Override
public boolean isInside(Point point) {
  return c3Poly.contains(point.x - bounds.x, point.y - bounds.y);
}

代码示例来源:origin: MegaMek/megamek

private boolean intersects(Shape sh, int x, int y) {
  if (sh instanceof Rectangle) {
    Rectangle r = (Rectangle) sh;
    return r.contains(x, y);
  } else if (sh instanceof Polygon) {
    Polygon p = (Polygon) sh;
    return p.contains(x, y);
  }
  return false;
}

代码示例来源:origin: stackoverflow.com

public void mouseClicked(MouseEvent e) {
...
  Polygon[] triArray = triangles.toArray(new Polygon[triangles.size()]);
  startDrag = new Point(e.getX(), e.getY());
  for (Polygon p:triArray){
  if (p.contains(startDrag)) //Polygon has a 'contains(Point)' method
      triangles.remove (p);
  }
....

代码示例来源:origin: stackoverflow.com

public void mouseMoved(MouseEvent e) {
  startDrag = new Point(e.getX(), e.getY());
  Cursor cursor = Cursor.getDefaultCursor();
  //you have a List<Polygon>, so you can use this enhanced for loop
  for (Polygon p : triangles) { 
   if (p.contains(startDrag)) {//Polygon has a 'contains(Point)' method
     cursor = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
     break; //you've found a hit, break from the loop 
   }
  }
  setCursor(cursor);
}// end mouseMoved

代码示例来源:origin: stackoverflow.com

public static void main(String[] args)
{
  Polygon p = new Polygon();
  p.addPoint(1, 1);
  p.addPoint(3, 1);
  p.addPoint(2, 2);
  System.out.println(p.contains(2, 1));
  System.out.println(p.contains(2.5, 1));
  System.out.println(p.contains(2.9999, 1));
  System.out.println(p.contains(2.9999, 1.00));
}

代码示例来源:origin: Audiveris/audiveris

@Override
public boolean contains (int x,
             int y)
{
  return getPolygon().contains(x, y);
}

代码示例来源:origin: net.imagej/ij

public boolean contains(int x, int y) {
  if (getStrokeWidth()>1) {
    if ((x==x1&&y==y1) || (x==x2&&y==y2))
      return true;
    else
      return getPolygon().contains(x,y);
  } else
    return false;
}

代码示例来源:origin: triplea-game/triplea

private static boolean isRectangleContainedInTerritory(final Rectangle rectangle, final Territory territory,
  final MapData mapData) {
 final List<Polygon> polygons = mapData.getPolygons(territory.getName());
 for (final Polygon polygon : polygons) {
  if (polygon.contains(rectangle)) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: com.github.davidmoten/grumpy-core

public final boolean isWithin(List<Position> positions) {
  Polygon polygon = new Polygon();
  for (Position p : positions) {
    polygon.addPoint(degreesToArbitraryInteger(p.lon), degreesToArbitraryInteger(p.lat));
  }
  int x = degreesToArbitraryInteger(this.lon);
  int y = degreesToArbitraryInteger(this.lat);
  return polygon.contains(x, y);
}

代码示例来源:origin: au.gov.amsa.risky/geo-analyzer

public final boolean isWithin(List<Position> positions) {
  Polygon polygon = new Polygon();
  for (Position p : positions) {
    polygon.addPoint(degreesToArbitraryInteger(p.lon),
        degreesToArbitraryInteger(p.lat));
  }
  int x = degreesToArbitraryInteger(this.lon);
  int y = degreesToArbitraryInteger(this.lat);
  return polygon.contains(x, y);
}

相关文章