svg fraction correction exercice

This commit is contained in:
2026-05-12 21:06:49 +02:00
parent 06bc8e3cf4
commit 7e82f1c0a5
18 changed files with 59 additions and 37 deletions

View File

@@ -18,7 +18,7 @@ STYLE = """
.h2{font-family:"Trebuchet MS",Verdana,sans-serif;font-size:28px;font-weight:800;fill:#074f4b}
.body{font-family:"Trebuchet MS",Verdana,sans-serif;font-size:24px;fill:#1d3038}
.small{font-family:"Trebuchet MS",Verdana,sans-serif;font-size:20px;fill:#2d4148}
.frac{font-family:"Trebuchet MS",Verdana,sans-serif;font-size:52px;font-weight:800;fill:#074f4b}
.frac{font-family:"Trebuchet MS",Verdana,sans-serif;font-size:36px;font-weight:800;fill:#074f4b}
.op{font-family:"Trebuchet MS",Verdana,sans-serif;font-size:34px;font-weight:800;fill:#074f4b}
.blank{stroke:#7fa79d;stroke-width:3;stroke-dasharray:10 10}
.axis{stroke:#26383d;stroke-width:4;stroke-linecap:round}
@@ -44,10 +44,10 @@ def fraction(x: int, y: int, n: str | int, d: str | int, size: int = 52) -> str:
cx = width / 2
return (
f'<g transform="translate({x} {y})" class="math-expression fraction-g" '
f'data-math="fraction" data-box="-8 -52 {width + 16} 110">'
f'<text x="{cx:g}" y="-25" text-anchor="middle" class="frac">{escape(n_text)}</text>'
f'data-math="fraction" data-box="-10 -48 {width + 20} 110">'
f'<text x="{cx:g}" y="-24" text-anchor="middle" class="frac">{escape(n_text)}</text>'
f'<line x1="0" y1="8" x2="{width}" y2="8" stroke="#074f4b" stroke-width="4" stroke-linecap="round" />'
f'<text x="{cx:g}" y="62" text-anchor="middle" class="frac">{escape(d_text)}</text>'
f'<text x="{cx:g}" y="58" text-anchor="middle" class="frac">{escape(d_text)}</text>'
"</g>"
)
@@ -103,7 +103,7 @@ def number_line(x: int, y: int, parts: int, point: int | None = None, width: int
def svg_01() -> str:
c1 = "".join(
fraction(58, y, n, d) + line(190, y + 8, 360, y + 8)
for y, (n, d) in zip([145, 255, 365, 475], [(1, 2), (3, 4), (5, 8), (7, 10)])
for y, (n, d) in zip([125, 247, 369, 491], [(1, 2), (3, 4), (5, 8), (7, 10)])
)
c2 = "".join(
fraction(58, y, n, d) + text(175, y - 22, "Numerateur :", "small") + line(320, y - 22, 385, y - 22)

View File

@@ -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