feat(docinfo): add path area to Document Info (#6965)

- Add Unit::format_area(self, pt2: f64) -> String to format area in document units.
- Add pathArea (pt²) to document.info output and insert Path Area row in Objects section.
- Calculate compound path net enclosed area using fill rules (Non-Zero / Even-Odd), subtracting holes.
- Exclude guides and open paths, and avoid double-counting on nested compound paths.
- Update progress evidence and entries in docs/gaps.md and docs/target-app-parity.md (identifying Path Area as a VectorCraft addition beyond reference panel).
This commit is contained in:
ruchirguitar
2026-11-25 09:49:32 +05:30
parent 9d050d2b01
commit b887ddf843
5 changed files with 167 additions and 5 deletions
+12
View File
@@ -291,3 +291,15 @@ fn q_and_ha_suffixes_do_not_take_other_units_suffixes() {
// A suffix after math covers the whole expression, as for the other units.
assert!((Unit::Points.parse("26/2 q").unwrap() - Unit::Q.to_pt(13.0)).abs() < 1e-9);
}
#[test]
fn format_area_formats_and_trims_cleanly() {
assert_eq!(Unit::Points.format_area(100.0), "100 pt²");
assert_eq!(Unit::Inches.format_area(4.5 * 72.0 * 72.0), "4.5 in²");
let mm_side = Unit::Millimeters.to_pt(1.0);
assert_eq!(Unit::Millimeters.format_area(12.5 * mm_side * mm_side), "12.5 mm²");
assert_eq!(Unit::Points.format_area(0.0), "0 pt²");
assert_eq!(Unit::Points.format_area(-10.0), "0 pt²");
assert_eq!(Unit::Points.format_area(f64::NAN), "0 pt²");
assert_eq!(Unit::Points.format_area(f64::INFINITY), "0 pt²");
}
+13
View File
@@ -154,6 +154,19 @@ impl Unit {
pub fn format(self, pt: f64) -> String {
format!("{} {}", self.number(pt), self.suffix())
}
/// Format an area in square points into this unit (e.g. `12.5 mm²`, `4.5 in²`, `100 pt²`).
pub fn format_area(self, pt2: f64) -> String {
if !pt2.is_finite() || pt2 <= 0.0 {
return format!("0 {}²", self.suffix());
}
let side = self.from_pt(1.0);
let val = pt2 * side * side;
let decimals = if matches!(self, Unit::Points | Unit::Pixels | Unit::Picas | Unit::Q | Unit::Ha) { 3 } else { 4 };
let s = format!("{:.*}", decimals, val);
let s = s.trim_end_matches('0').trim_end_matches('.');
let s = if s == "-0" || s.is_empty() { "0" } else { s };
format!("{s} {}²", self.suffix())
}
/// [`Unit::format`] without the suffix (`12.5`), for narrow fields.
pub fn number(self, pt: f64) -> String {
// Three decimals for the small units (`595.276 pt`), four for the large ones (`8.2677 in`,
File diff suppressed because one or more lines are too long
+4 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long