svg fraction correction exercice
This commit is contained in:
@@ -133,6 +133,18 @@ def overlaps(a: Box, b: Box) -> bool:
|
||||
return a.x1 < b.x2 and a.x2 > b.x1 and a.y1 < b.y2 and a.y2 > b.y1
|
||||
|
||||
|
||||
def horizontal_overlap(a: Box, b: Box) -> bool:
|
||||
return a.x1 < b.x2 and a.x2 > b.x1
|
||||
|
||||
|
||||
def vertical_gap(a: Box, b: Box) -> float:
|
||||
if a.y2 <= b.y1:
|
||||
return b.y1 - a.y2
|
||||
if b.y2 <= a.y1:
|
||||
return a.y1 - b.y2
|
||||
return 0.0
|
||||
|
||||
|
||||
def parse_data_box(node: ET.Element, ox: float, oy: float) -> Box | None:
|
||||
match = DATA_BOX_RE.match(node.attrib.get("data-box") or "")
|
||||
if not match:
|
||||
@@ -233,6 +245,16 @@ def validate_layout_collisions(path: Path, root: ET.Element, styles: dict[str, d
|
||||
f"Chevauchement autour d'une fraction: {first.kind} {first.label!r} avec {second.kind} {second.label!r}.",
|
||||
)
|
||||
)
|
||||
elif first.kind == "fraction" and second.kind == "fraction" and horizontal_overlap(first, second):
|
||||
gap = vertical_gap(first, second)
|
||||
if gap < 12:
|
||||
issues.append(
|
||||
Issue(
|
||||
"error",
|
||||
path,
|
||||
f"Marge verticale insuffisante entre fractions: {first.label!r} et {second.label!r} ({gap:.1f}px).",
|
||||
)
|
||||
)
|
||||
return issues
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user