private void intersectBoundsWithMatte(RectF rect, Matrix matrix) { if (!hasMatteOnThisLayer()) { return; } if (layerModel.getMatteType() == Layer.MatteType.Invert) { // We can't trim the bounds if the mask is inverted since it extends all the way to the // composition bounds. return; } //noinspection ConstantConditions matteBoundsRect.set(0f, 0f, 0f, 0f); matteLayer.getBounds(matteBoundsRect, matrix, true); boolean intersects = rect.intersect(matteBoundsRect); if (!intersects) { rect.set(0f, 0f, 0f, 0f); } }
boolean intersects = rect.intersect(maskBoundsRect); if (!intersects) { rect.set(0f, 0f, 0f, 0f);
private boolean objectsCollide(GameObject a, GameObject b) { if (a.dead || b.dead || !a.collides || !b.collides) { return false; } getColliderBounds(a, mRect1); getColliderBounds(b, mRect2); return mRect1.intersect(mRect2); }
@Override public void onDraw( Canvas canvas ) { Paint paint1 = new Paint( Paint.ANTI_ALIAS_FLAG ) Paint paint2 = new Paint() paint2.setXfermode( new PorterDuffXfermode( Mode.SRC_IN ) ) Drawable drawable = getDrawable() RectF rectangle = new RectF() rectangle.set( drawable.getBounds() ) getImageMatrix.mapRect( rectangle ) rectangle.offset( getPaddingLeft(), getPaddingTop() ) // Prevent radius being drawn out of canvas bounds rectangle.intersect( new RectF( 0, 0, canvas.getWidth(), canvas.getHeight() ) ) int restore = canvas.saveLayer( rectangle, null, Canvas.ALL_SAVE_FLAG ) canvas.drawRoundRect( rectangle, radius.getValue(), radius.getValue(), paint1 ) canvas.saveLayer( rectangle, paint2, Canvas.ALL_SAVE_FLAG ) super.onDraw( canvas ) canvas.restoreToCount( restore ) }
r.intersect(0, 0, width, height);
@Override public void onDraw(Canvas canvas) { canvas.drawColor(0XFFFFFFFF); if (rectFB1 != null) { rectFB1.set(xB1Center - (boardWidth / 2), yB1Center + (boardHeight / 2), xB1Center + (boardWidth / 2), yB1Center - (boardHeight / 2)); canvas.drawOval(rectFB1, paintB1); } if (rectFB2 != null) { rectFB2.set(xB2Center - (boardWidth / 2), yB2Center + (boardHeight / 2), xB2Center + (boardWidth / 2), yB2Center - (boardHeight / 2)); canvas.drawOval(rectFB2, paintB2); } if (Ball.rectFBall != null) { Ball.rectFBall.set(xBallCenter - radius, yBallCenter - radius, xBallCenter + radius, yBallCenter + radius); canvas.drawOval(Ball.rectFBall, paintBall); } if (rectFB1 != null) { if (rectFBall.intersect(rectFB1)) { collide(1); } else if (rectFBall.intersect(rectFB2)) { collide(2); } } }
public boolean isViewTouchingTrash(View v){ RectF trashRect = Tools.viewToRect(findViewById(R.id.trash)); RectF vRect = Tools.viewToRect(v); return trashRect.intersect(vRect); }
private void moveEdges(float deltaX, float deltaY) { RectF cropped = getCropBoundsDisplayed(); if (movingEdges == MOVE_BLOCK) { // Move the whole cropped bounds within the photo display bounds. deltaX = (deltaX > 0) ? Math.min(displayBounds.right - cropped.right, deltaX) : Math.max(displayBounds.left - cropped.left, deltaX); deltaY = (deltaY > 0) ? Math.min(displayBounds.bottom - cropped.bottom, deltaY) : Math.max(displayBounds.top - cropped.top, deltaY); cropped.offset(deltaX, deltaY); } else { // Adjust cropped bound dimensions within the photo display bounds. float minWidth = MIN_CROP_WIDTH_HEIGHT * displayBounds.width() / getPhotoWidth(); float minHeight = MIN_CROP_WIDTH_HEIGHT * displayBounds.height() / getPhotoHeight(); if ((movingEdges & MOVE_LEFT) != 0) { cropped.left = Math.min(cropped.left + deltaX, cropped.right - minWidth); } if ((movingEdges & MOVE_TOP) != 0) { cropped.top = Math.min(cropped.top + deltaY, cropped.bottom - minHeight); } if ((movingEdges & MOVE_RIGHT) != 0) { cropped.right = Math.max(cropped.right + deltaX, cropped.left + minWidth); } if ((movingEdges & MOVE_BOTTOM) != 0) { cropped.bottom = Math.max(cropped.bottom + deltaY, cropped.top + minHeight); } cropped.intersect(displayBounds); } mapPhotoRect(cropped, cropBounds); refreshByCropChange(true); }
/** * Place the minimap current rectangle considering the minimap bounds * the zoom level, and the current X/Y offsets */ private void calculateMinimapAreaBounds() { if (minimapBounds == null) { return; } if (zoom == 1f) { miniMapRequired = false; } else { // Calculates the bounds of the current displayed area float x = (-currentXOffset - toCurrentScale(currentFilteredPage * optimalPageWidth)) // / toCurrentScale(optimalPageWidth) * minimapBounds.width(); float width = getWidth() / toCurrentScale(optimalPageWidth) * minimapBounds.width(); float y = -currentYOffset / toCurrentScale(optimalPageHeight) * minimapBounds.height(); float height = getHeight() / toCurrentScale(optimalPageHeight) * minimapBounds.height(); minimapScreenBounds = new RectF(minimapBounds.left + x, minimapBounds.top + y, // minimapBounds.left + x + width, minimapBounds.top + y + height); minimapScreenBounds.intersect(minimapBounds); miniMapRequired = true; } }