本文整理了Java中java.awt.Rectangle.intersection
方法的一些代码示例,展示了Rectangle.intersection
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rectangle.intersection
方法的具体详情如下:
包路径:java.awt.Rectangle
类名称:Rectangle
方法名:intersection
[英]Computes the intersection of this Rectangle
with the specified Rectangle
. Returns a new Rectangle
that represents the intersection of the two rectangles. If the two rectangles do not intersect, the result will be an empty rectangle.
[中]计算此Rectangle
与指定Rectangle
的交集。返回表示两个矩形相交的新Rectangle
。如果两个矩形不相交,结果将是一个空矩形。
代码示例来源:origin: shopizer-ecommerce/shopizer
public BufferedImage getCroppedImage() throws IOException {
//out if croppedArea == 0 or file is null
Rectangle goal = new Rectangle( (int)this.getCropAreaWidth(), (int) this.getCropAreaHeight());
//Then intersect it with the dimensions of your image:
Rectangle clip = goal.intersection(new Rectangle(originalFile.getWidth(), originalFile.getHeight()));
//Now, clip corresponds to the portion of bi that will fit within your goal. In this case 100 x50.
//Now get the subImage using the value of clip.
BufferedImage clippedImg = originalFile.getSubimage(clip.x, clip.y, clip.width, clip.height);
return clippedImg;
}
代码示例来源:origin: coobird/thumbnailator
/**
* Calculates the position and size of the enclosed region, relative to the
* enclosing region.
* <p>
* The portions of the enclosed region which lies outside of the enclosing
* region are ignored. Effectively, the {@link Rectangle} returned by this
* method is a intersection of the enclosing and enclose regions.
*
* @param width Width of the enclosing region.
* @param height Height of the enclosing region.
* @return Position and size of the enclosed region.
*/
public Rectangle calculate(int width, int height)
{
Dimension d = size.calculate(width, height);
Point p = position.calculate(
width, height, d.width, d.height, 0, 0, 0, 0
);
Rectangle outerRectangle = new Rectangle(0, 0, width, height);
Rectangle innerRectangle = new Rectangle(p, d);
return outerRectangle.intersection(innerRectangle);
}
代码示例来源:origin: stackoverflow.com
Rectangle rect1 = new Rectangle(100, 100, 200, 240);
Rectangle rect2 = new Rectangle(120, 80, 80, 120);
Rectangle intersection = rect1.intersection(rect2);
代码示例来源:origin: RaiMan/SikuliX2
public Element intersection(Element elem) {
Rectangle r1 = new Rectangle(x, y, w, h);
Rectangle r2 = new Rectangle(elem.x, elem.y, elem.w, elem.h);
return new Element(r1.intersection(r2));
}
代码示例来源:origin: haraldk/TwelveMonkeys
public static Rectangle getSourceRegion(final IIOParam pParam, final int pSrcWidth, final int pSrcHeight) {
Rectangle sourceRegion = new Rectangle(pSrcWidth, pSrcHeight);
// If param is present, calculate region
if (pParam != null) {
// Get intersection with source region
Rectangle region = pParam.getSourceRegion();
if (region != null) {
sourceRegion = sourceRegion.intersection(region);
}
// Scale according to subsampling offsets
int subsampleXOffset = pParam.getSubsamplingXOffset();
int subsampleYOffset = pParam.getSubsamplingYOffset();
sourceRegion.x += subsampleXOffset;
sourceRegion.y += subsampleYOffset;
sourceRegion.width -= subsampleXOffset;
sourceRegion.height -= subsampleYOffset;
}
return sourceRegion;
}
代码示例来源:origin: geotools/geotools
sourceRegion.setRect(sourceRegion.intersection(baseGridRange.toRectangle()));
sourceRegion.setBounds(new Rectangle(0, 0, Integer.MIN_VALUE, Integer.MIN_VALUE));
代码示例来源:origin: igvteam/igv
private Rectangle getDisplayableRect(Rectangle trackRectangle, Rectangle visibleRect) {
Rectangle rect = null;
if (visibleRect != null) {
Rectangle intersectedRect = trackRectangle.intersection(visibleRect);
if (intersectedRect.height > 15) {
rect = intersectedRect;
} else {
rect = new Rectangle(trackRectangle);
}
}
return rect;
}
代码示例来源:origin: igvteam/igv
private Rectangle getDisplayableRect(Rectangle trackRectangle, Rectangle visibleRect) {
Rectangle rect = null;
if (visibleRect != null) {
Rectangle intersectedRect = trackRectangle.intersection(visibleRect);
if (intersectedRect.height > 15) {
rect = intersectedRect;
} else {
rect = new Rectangle(trackRectangle);
}
}
return rect;
}
代码示例来源:origin: RaiMan/SikuliX2
begin_t = new Date().getTime();
int margin = ((int) target.getResizeFactor()) + 1;
Rectangle rSub = new Rectangle(Math.max(0, maxLocX - margin), Math.max(0, maxLocY - margin),
Math.min(target.w + 2 * margin, mBase.width()),
Math.min(target.h + 2 * margin, mBase.height()));
rSub = new Rectangle(0, 0, mBase.cols(), mBase.rows()).intersection(rSub);
Rect rectSub = new Rect(rSub.x, rSub.y, rSub.width, rSub.height);
mResult = doFindMatch(target, mBase.submat(rectSub), null);
代码示例来源:origin: bcdev/beam
Rectangle getChunkRect(Point chunkIndex) {
return new Rectangle(sceneWidth, sceneHeight).intersection(new Rectangle(
chunkIndex.x * chunkWidth, chunkIndex.y * chunkHeight,
chunkWidth, chunkHeight));
}
代码示例来源:origin: fr.avianey.apache-xmlgraphics/batik
public Shape getDirtyRegion(int srcIndex, Rectangle inputRgn) {
if (srcIndex != 0)
throw new IndexOutOfBoundsException
("Nonexistant source requested.");
// Return empty rect if they don't intersect.
if ( ! inputRgn.intersects(bounds) )
return new Rectangle();
// Changes in the input region don't propogate outside our
// bounds.
return inputRgn.intersection(bounds);
}
代码示例来源:origin: apache/batik
public Shape getDirtyRegion(int srcIndex, Rectangle inputRgn) {
if (srcIndex != 0)
throw new IndexOutOfBoundsException
("Nonexistant source requested.");
// Return empty rect if they don't intersect.
if ( ! inputRgn.intersects(bounds) )
return new Rectangle();
// Changes in the input region don't propogate outside our
// bounds.
return inputRgn.intersection(bounds);
}
代码示例来源:origin: RaiMan/SikuliX2
rect = new Rectangle(comp.getBounds());
continue;
}else {
rect.add(comp.getBounds());
}else if (relationship == INTERSECTION){
rect = rect.intersection(comp.getBounds());
代码示例来源:origin: org.apache.xmlgraphics/batik-awt-util
public Shape getDirtyRegion(int srcIndex, Rectangle inputRgn) {
if (srcIndex != 0)
throw new IndexOutOfBoundsException
("Nonexistant source requested.");
// Return empty rect if they don't intersect.
if ( ! inputRgn.intersects(bounds) )
return new Rectangle();
// Changes in the input region don't propogate outside our
// bounds.
return inputRgn.intersection(bounds);
}
代码示例来源:origin: org.apache.xmlgraphics/xmlgraphics-commons
public Shape getDirtyRegion(int srcIndex, Rectangle inputRgn) {
if (srcIndex != 0) {
throw new IndexOutOfBoundsException(
"Nonexistent source requested.");
}
// Return empty rect if they don't intersect.
if (!inputRgn.intersects(bounds)) {
return new Rectangle();
}
// Changes in the input region don't propogate outside our
// bounds.
return inputRgn.intersection(bounds);
}
代码示例来源:origin: org.apache.xmlgraphics/batik-awt-util
public Shape getDependencyRegion(int srcIndex, Rectangle outputRgn) {
if ((srcIndex < 0) || (srcIndex > srcs.size()))
throw new IndexOutOfBoundsException
("Nonexistant source requested.");
// Return empty rect if they don't intersect.
if ( ! outputRgn.intersects(bounds) )
return new Rectangle();
// We only depend on our source for stuff that is inside
// our bounds...
return outputRgn.intersection(bounds);
}
代码示例来源:origin: apache/batik
public Shape getDependencyRegion(int srcIndex, Rectangle outputRgn) {
if ((srcIndex < 0) || (srcIndex > srcs.size()))
throw new IndexOutOfBoundsException
("Nonexistant source requested.");
// Return empty rect if they don't intersect.
if ( ! outputRgn.intersects(bounds) )
return new Rectangle();
// We only depend on our source for stuff that is inside
// our bounds...
return outputRgn.intersection(bounds);
}
代码示例来源:origin: fr.avianey.apache-xmlgraphics/batik
public Shape getDependencyRegion(int srcIndex, Rectangle outputRgn) {
if ((srcIndex < 0) || (srcIndex > srcs.size()))
throw new IndexOutOfBoundsException
("Nonexistant source requested.");
// Return empty rect if they don't intersect.
if ( ! outputRgn.intersects(bounds) )
return new Rectangle();
// We only depend on our source for stuff that is inside
// our bounds...
return outputRgn.intersection(bounds);
}
代码示例来源:origin: stackoverflow.com
Rectangle rect1 = new Rectangle(20, 300, 400, 160);
Rectangle rect2 = new Rectangle(150, 60, 230, 450);
Rectangle intersection = rect1.intersection(rect2);
System.out.println(intersection);
代码示例来源:origin: org.apache.xmlgraphics/xmlgraphics-commons
public Shape getDependencyRegion(int srcIndex, Rectangle outputRgn) {
if ((srcIndex < 0) || (srcIndex > srcs.size())) {
throw new IndexOutOfBoundsException(
"Nonexistent source requested.");
}
// Return empty rect if they don't intersect.
if (!outputRgn.intersects(bounds)) {
return new Rectangle();
}
// We only depend on our source for stuff that is inside
// our bounds...
return outputRgn.intersection(bounds);
}
内容来源于网络,如有侵权,请联系作者删除!