本文整理汇总了Java中java.awt.geom.Area.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java Area.isEmpty方法的具体用法?Java Area.isEmpty怎么用?Java Area.isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.Area
的用法示例。
在下文中一共展示了Area.isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hit
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Returns <code>true</code> if the rectangle (in device space) intersects
* with the shape (the interior, if <code>onStroke</code> is false,
* otherwise the stroked outline of the shape).
*
* @param rect a rectangle (in device space).
* @param s the shape.
* @param onStroke test the stroked outline only?
*
* @return A boolean.
*/
@Override
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
AffineTransform transform = getTransform();
Shape ts;
if (onStroke) {
Stroke stroke = getStroke();
ts = transform.createTransformedShape(stroke.createStrokedShape(s));
} else {
ts = transform.createTransformedShape(s);
}
if (!rect.getBounds2D().intersects(ts.getBounds2D())) {
return false;
}
Area a1 = new Area(rect);
Area a2 = new Area(ts);
a1.intersect(a2);
return !a1.isEmpty();
}
示例2: hit
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Returns {@code true} if the rectangle (in device space) intersects
* with the shape (the interior, if {@code onStroke} is false,
* otherwise the stroked outline of the shape).
*
* @param rect a rectangle (in device space).
* @param s the shape.
* @param onStroke test the stroked outline only?
*
* @return A boolean.
*/
@Override
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
Shape ts;
if (onStroke) {
ts = this.transform.createTransformedShape(
this.stroke.createStrokedShape(s));
} else {
ts = this.transform.createTransformedShape(s);
}
if (!rect.getBounds2D().intersects(ts.getBounds2D())) {
return false;
}
Area a1 = new Area(rect);
Area a2 = new Area(ts);
a1.intersect(a2);
return !a1.isEmpty();
}
示例3: addFurniture
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Adds furniture to home and updates door and window flags if they intersect with walls and magnetism is enabled.
*/
@Override
public void addFurniture(List<HomePieceOfFurniture> furniture)
{
super.addFurniture(furniture);
if (this.preferences.isMagnetismEnabled())
{
Area wallsArea = getWallsArea(false);
for (HomePieceOfFurniture piece : furniture)
{
if (piece instanceof HomeDoorOrWindow)
{
float[][] piecePoints = piece.getPoints();
Area pieceAreaIntersection = new Area(getPath(piecePoints));
pieceAreaIntersection.intersect(wallsArea);
if (!pieceAreaIntersection.isEmpty()
&& new Room(piecePoints).getArea() / getArea(pieceAreaIntersection) > 0.999)
{
((HomeDoorOrWindow) piece).setBoundToWall(true);
}
}
}
}
}
示例4: getOverlappingBiomolecules
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Get a list of all mobile biomolecules that overlap with the provided
* shape.
*
* @param testShape - Shape, in model coordinate, to test for overlap.
* @return List of molecules that overlap with the provided shape.
*/
public List<MobileBiomolecule> getOverlappingBiomolecules( Shape testShape ) {
List<MobileBiomolecule> overlappingBiomolecules = new ArrayList<MobileBiomolecule>();
// Since it is computationally expensive to test overlap with every
// shape, we do a fast bounds test first, and then the more expensive
// test when necessary.
Rectangle2D testShapeBounds = testShape.getBounds2D();
for ( MobileBiomolecule mobileBiomolecule : mobileBiomoleculeList ) {
if ( mobileBiomolecule.getShape().getBounds2D().intersects( testShapeBounds ) ) {
// Bounds overlap, see if actual shapes overlap.
Area testShapeArea = new Area( testShape );
Area biomoleculeArea = new Area( mobileBiomolecule.getShape() );
biomoleculeArea.intersect( testShapeArea );
if ( !biomoleculeArea.isEmpty() ) {
// The biomolecule overlaps with the test shape, so add it
// to the list.
overlappingBiomolecules.add( mobileBiomolecule );
}
}
}
return overlappingBiomolecules;
}
示例5: getVoltage
import java.awt.geom.Area; //导入方法依赖的package包/类
public double getVoltage( Shape leftTip, Shape rightTip ) {
Area tipIntersection = new Area( leftTip );
tipIntersection.intersect( new Area( rightTip ) );
if ( !tipIntersection.isEmpty() ) {
return 0;
}
else {
Connection red = getConnection( leftTip );
Connection black = getConnection( rightTip );
//Ignore wires & components loaded into a black box.
if ( red != null && red.isBlackBox() ) {
red = null;
}
if ( black != null && black.isBlackBox() ) {
black = null;
}
if ( red == null || black == null ) {
return Double.NaN;
}
else {
return getVoltage( red, black );//dfs from one branch to the other, counting the voltage drop.
}
}
}
示例6: isRoomItersectingWallSide
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Returns <code>true</code> if the wall points on the given <code>wallSide</code>
* intersects room area.
*/
private boolean isRoomItersectingWallSide(float[][] wallPoints, int wallSide, Area roomArea)
{
BasicStroke lineStroke = new BasicStroke(2);
Shape wallSideShape = getWallSideShape(wallPoints, wallSide);
Area wallSideTestArea = new Area(lineStroke.createStrokedShape(wallSideShape));
float wallSideTestAreaSurface = getSurface(wallSideTestArea);
wallSideTestArea.intersect(roomArea);
if (!wallSideTestArea.isEmpty())
{
float wallSideIntersectionSurface = getSurface(wallSideTestArea);
// Take into account only walls that shares a minimum surface with the room
if (wallSideIntersectionSurface > wallSideTestAreaSurface * 0.02f)
{
return true;
}
}
return false;
}
示例7: tick
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* <strong><em>tick</em></strong><br /><br />
*
*  Called every time a tick is called.<br />
*  This allows the object to update frequently<br />
*  and keep a smooth gameplay experience.<br /><br />
*
* <strong>Notes:</strong><br />
*  A list of the objects are passed through to allow checking of intersection.<br />
*  While you can avoid overriding tick, you shouldn't.<br />
*  It's okay not to call super if the object isn't a collidable,<br />
*  but the function checks to make sure it is.<br />
*  So it's good practice to do it regardless.
*
* @param objects - LinkedList of all the objects stored in the Handler.
* @since NEO.1
*/
public void tick(LinkedList<GameObject> objects){
if(collidable){
for(GameObject object : objects){
/*
* We should avoid checking for self collisions,
* because it will always return true.
*/
if(object!=this){
// Make sure the boundaries aren't null to avoid an Exception.
if(object.getBounds()!=null){
Area a = new Area(object.getBounds());
a.intersect(new Area(getBounds()));
if(!a.isEmpty()){
onCollision(object, object.getId());
}
}
}
}
}
x+=velX;
y+=velY;
}
示例8: isIntersectionEmpty
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Returns <code>true</code> if the given pieces don't intersect once the first is moved from
* (<code>deltaX</code>, <code>deltaY</code>) vector.
*/
private boolean isIntersectionEmpty(HomePieceOfFurniture piece1, HomePieceOfFurniture piece2, float deltaX,
float deltaY)
{
Area intersection = new Area(getRotatedRectangle(piece1.getX() - piece1.getWidth() / 2 + deltaX,
piece1.getY() - piece1.getDepth() / 2 + deltaY, piece1.getWidth(), piece1.getDepth(),
piece1.getAngle()));
float epsilon = 0.01f;
intersection.intersect(new Area(getRotatedRectangle(piece2.getX() - piece2.getWidth() / 2 - epsilon,
piece2.getY() - piece2.getDepth() / 2 - epsilon, piece2.getWidth() + 2 * epsilon,
piece2.getDepth() + 2 * epsilon, piece2.getAngle())));
return intersection.isEmpty();
}
示例9: isAreaLargerOnFrontOrBackSide
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Returns <code>true</code> if the intersection between the given <code>area</code> and
* the front or back sides of the rectangle defined by <code>piecePoints</code> is larger
* than with the left and right sides of this rectangle.
*/
private boolean isAreaLargerOnFrontOrBackSide(Area area, float[][] piecePoints)
{
GeneralPath pieceFrontAndBackQuarters = new GeneralPath();
pieceFrontAndBackQuarters.moveTo(piecePoints[0][0], piecePoints[0][1]);
pieceFrontAndBackQuarters.lineTo(piecePoints[2][0], piecePoints[2][1]);
pieceFrontAndBackQuarters.lineTo(piecePoints[3][0], piecePoints[3][1]);
pieceFrontAndBackQuarters.lineTo(piecePoints[1][0], piecePoints[1][1]);
pieceFrontAndBackQuarters.closePath();
Area intersectionWithFrontOrBack = new Area(area);
intersectionWithFrontOrBack.intersect(new Area(pieceFrontAndBackQuarters));
if (intersectionWithFrontOrBack.isEmpty())
{
return false;
}
else
{
GeneralPath pieceLeftAndRightQuarters = new GeneralPath();
pieceLeftAndRightQuarters.moveTo(piecePoints[0][0], piecePoints[0][1]);
pieceLeftAndRightQuarters.lineTo(piecePoints[2][0], piecePoints[2][1]);
pieceLeftAndRightQuarters.lineTo(piecePoints[1][0], piecePoints[1][1]);
pieceLeftAndRightQuarters.lineTo(piecePoints[3][0], piecePoints[3][1]);
pieceLeftAndRightQuarters.closePath();
Area intersectionWithLeftAndRight = new Area(area);
intersectionWithLeftAndRight.intersect(new Area(pieceLeftAndRightQuarters));
return getArea(intersectionWithFrontOrBack) > getArea(intersectionWithLeftAndRight);
}
}
示例10: getIntersections
import java.awt.geom.Area; //导入方法依赖的package包/类
protected Collection<java.awt.geom.Point2D> getIntersections(java.awt.geom.Line2D line, Area shape) {
Area intersectionArea = new Area(getLineShape(line));
intersectionArea.intersect(shape);
if (!intersectionArea.isEmpty()) {
Rectangle2D bounds2D = intersectionArea.getBounds2D();
HashSet<java.awt.geom.Point2D> intersections = new HashSet<>(1);
intersections.add(new java.awt.geom.Point2D.Double(bounds2D.getX(), bounds2D.getY()));
return intersections;
}
return Collections.EMPTY_SET;
}
示例11: detectJunction
import java.awt.geom.Area; //导入方法依赖的package包/类
private Junction detectJunction( Shape tipShape ) {
Junction[] junctions = getJunctions();
Junction detectedJunction = null;
for ( Junction junction : junctions ) {
Area area = new Area( junction.getShape() );
area.intersect( new Area( tipShape ) );
if ( !area.isEmpty() ) {
detectedJunction = junction;
}
}
return detectedJunction;
}
示例12: isOK
import java.awt.geom.Area; //导入方法依赖的package包/类
/** Determine if a particular scaling ratio works */
private boolean isOK(Area shape, Rectangle2D shapeBounds,Rectangle2D bounds,float ratio) {
Area area = new Area(shape);
area.transform(AffineTransform.getScaleInstance(ratio, ratio));
Rectangle2D r = ShapeBounds.getBounds(area);
area.transform(AffineTransform.getTranslateInstance(-r.getCenterX()+bounds.getCenterX(),
-r.getCenterY()+bounds.getCenterY()));
Area boundsArea = new Area(bounds);
boundsArea.subtract(area);
return boundsArea.isEmpty();
}
示例13: computeTiledROIs
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Create a collection of tiled ROIs corresponding to a specified parentROI if it is larger than sizeMax.
*
* If the parentROI is smaller, it is returned as is.
*
* @param parentROI
* @param sizePreferred
* @param sizeMax
* @param fixedSize
* @param overlap
* @return
*/
public static Collection<? extends ROI> computeTiledROIs(ROI parentROI, ImmutableDimension sizePreferred, ImmutableDimension sizeMax, boolean fixedSize, int overlap) {
PathArea pathArea = parentROI instanceof PathArea ? (PathArea)parentROI : null;
Rectangle2D bounds = AwtTools.getBounds2D(parentROI);
if (pathArea == null || (bounds.getWidth() <= sizeMax.width && bounds.getHeight() <= sizeMax.height)) {
return Collections.singletonList(parentROI);
}
List<ROI> pathROIs = new ArrayList<>();
Area area = getArea(pathArea);
double xMin = bounds.getMinX();
double yMin = bounds.getMinY();
int nx = (int)Math.ceil(bounds.getWidth() / sizePreferred.width);
int ny = (int)Math.ceil(bounds.getHeight() / sizePreferred.height);
double w = fixedSize ? sizePreferred.width : (int)Math.ceil(bounds.getWidth() / nx);
double h = fixedSize ? sizePreferred.height : (int)Math.ceil(bounds.getHeight() / ny);
// Center the tiles
xMin = (int)(bounds.getCenterX() - (nx * w * .5));
yMin = (int)(bounds.getCenterY() - (ny * h * .5));
for (int yi = 0; yi < ny; yi++) {
for (int xi = 0; xi < nx; xi++) {
double x = xMin + xi * w - overlap;
double y = yMin + yi * h - overlap;
Rectangle2D boundsTile = new Rectangle2D.Double(x, y, w + overlap*2, h + overlap*2);
// double x = xMin + xi * w;
// double y = yMin + yi * h;
//
// Rectangle2D boundsTile = new Rectangle2D.Double(x, y, w, h);
// logger.info(boundsTile);
ROI pathROI = null;
Shape shape = getShape(pathArea);
if (shape.contains(boundsTile))
pathROI = new RectangleROI(boundsTile.getX(), boundsTile.getY(), boundsTile.getWidth(), boundsTile.getHeight(), parentROI.getC(), parentROI.getZ(), parentROI.getT());
else if (pathArea instanceof RectangleROI) {
Rectangle2D bounds2 = boundsTile.createIntersection(bounds);
pathROI = new RectangleROI(bounds2.getX(), bounds2.getY(), bounds2.getWidth(), bounds2.getHeight(), parentROI.getC(), parentROI.getZ(), parentROI.getT());
}
else {
if (!area.intersects(boundsTile))
continue;
Area areaTemp = new Area(boundsTile);
areaTemp.intersect(area);
if (!areaTemp.isEmpty())
pathROI = new AWTAreaROI(areaTemp, parentROI.getC(), parentROI.getZ(), parentROI.getT());
}
if (pathROI != null)
pathROIs.add(pathROI);
x += w;
}
}
return pathROIs;
}
示例14: areTwoShapesInCollision
import java.awt.geom.Area; //导入方法依赖的package包/类
private static boolean areTwoShapesInCollision(Area firstShape, Area secondShape){
Area firstShapeCopy = new Area(firstShape);
firstShapeCopy.intersect(secondShape);
return !firstShapeCopy.isEmpty();
}
示例15: intersects
import java.awt.geom.Area; //导入方法依赖的package包/类
/**
* Do two Shapes intersect?
*
* @param shape1
* @param shape2
* @return
*/
public static final boolean intersects( Shape shape1, Shape shape2 ) {
Area area1 = new Area( shape1 );
Area area2 = new Area( shape2 );
area1.intersect( area2 );
return !area1.isEmpty();
}