简体   繁体   中英

Java Rectangle intersections

java会计算矩形,其中一个在其他内部作为交叉,并返回一个交叉点,当我调用交集(Rectangle)时,它是一个较小的矩形?

Returns : the largest Rectangle contained in both the specified Rectangle and in this Rectangle

As far as I understand you case, the result would be the smaller Rectangle that is contained in the larger one.

scala> import java.awt.Rectangle
import java.awt.Rectangle

scala> val big = new Rectangle(0, 0, 10, 10)
big: java.awt.Rectangle = java.awt.Rectangle[x=0,y=0,width=10,height=10]

scala> val small = new Rectangle(2, 2, 3, 3)
small: java.awt.Rectangle = java.awt.Rectangle[x=2,y=2,width=3,height=3]

scala> big.intersection(small)
res0: java.awt.Rectangle = java.awt.Rectangle[x=2,y=2,width=3,height=3]

scala> small.intersection(big)
res1: java.awt.Rectangle = java.awt.Rectangle[x=2,y=2,width=3,height=3]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM