Class PhysicalRectangle
java.lang.Object
io.leandev.appfuse.measure.PhysicalRectangle
代表具有物理單位的矩形區域
與 Rectangle 不同,此類別使用 Length 物件來表示座標和尺寸,
提供更強的類型安全性和單位轉換支援。
使用範例:
PhysicalRectangle rect = new PhysicalRectangle(
Length.ofCentimeter(0),
Length.ofCentimeter(0),
Length.ofCentimeter(21),
Length.ofCentimeter(29.7)
);
double area = rect.getArea(Length.Unit.MILLIMETER); // 面積(平方毫米)
boolean fits = rect.fits(Paper.A4); // 是否適合 A4 紙張
-
Constructor Summary
ConstructorsConstructorDescriptionPhysicalRectangle(Length x, Length y, Length width, Length height) 建立具有物理單位的矩形 -
Method Summary
Modifier and TypeMethodDescriptionbooleanboolean檢查此矩形是否適合指定的紙張尺寸(不考慮位置)boolean檢查此矩形是否適合指定的紙張尺寸(包含邊距)doublegetArea(Length.Unit unit) 計算矩形面積doublegetPerimeter(Length.Unit unit) 計算矩形周長getWidth()getX()getY()inthashCode()static PhysicalRectangle使用指定紙張尺寸建立矩形(從原點開始)toRectangle(Length.Unit unit) 將矩形轉換為指定單位的 Rectangle<Double>toString()
-
Constructor Details
-
PhysicalRectangle
建立具有物理單位的矩形- Parameters:
x- 左上角 X 座標y- 左上角 Y 座標width- 寬度(必須為正數)height- 高度(必須為正數)- Throws:
IllegalArgumentException- 如果任何參數為 null 或寬高為非正數
-
-
Method Details
-
ofPaper
使用指定紙張尺寸建立矩形(從原點開始)- Parameters:
paper- 紙張規格- Returns:
- 對應紙張尺寸的矩形
-
getX
-
getY
-
getWidth
-
getHeight
-
getArea
-
getPerimeter
-
fits
檢查此矩形是否適合指定的紙張尺寸(不考慮位置)- Parameters:
paper- 紙張規格- Returns:
- 如果寬度和高度都不超過紙張尺寸則返回 true
-
fits
-
toRectangle
將矩形轉換為指定單位的 Rectangle<Double>- Parameters:
unit- 目標單位- Returns:
- 轉換後的 Rectangle
-
equals
-
hashCode
-
toString
-