Evaluating Code Generation with Geometric Construction Tasks

    This article explains how to evaluate the code generation capabilities of lightweight models using geometric construction tasks. It covers why geometry problems reveal model weaknesses, how to break requirements into verifiable steps, how to design scoring dimensions, a reference implementation for regular polygon vertices using trigonometry, common failure modes, and how to design fair comparison experiments between models.

    Why Geometric Construction Is a Good Test for Code Generation

    A common way to evaluate whether a model can write usable front-end code is to ask it to generate a page, such as a clock, a calculator, or a simple animation. These tasks are relatively easy, and most models can complete them, so they offer limited differentiation.

    Geometric construction tasks expose problems more effectively. They require the model to understand mathematical constraints, translate operational steps into drawing logic, and render the result as an interactive interface. Every step corresponds to a geometric fact: get one step wrong, and the picture may still look approximately right while the underlying structure is already broken.

    The value of this kind of evaluation is that it separates “looks similar” from “is correct.” A page that visually resembles the target does not guarantee the construction process meets the requirements.

    Breaking Natural Language Requirements into Verifiable Steps

    A complete construction request usually contains multiple stages: building the initial figure, locating key points, moving auxiliary tools according to rules, recording traces, and exporting an animation file. Before evaluation, each stage should be listed separately with clear pass/fail criteria.

    Three principles guide this decomposition:

    1. Every step must be observable. For example, “construct the perpendicular bisector through a given point” should produce a visible line segment whose perpendicular bisector relationship can be verified with coordinates.
    2. Every step must be checkable. For example, “the circle center is equidistant from both endpoints” can be validated numerically.
    3. Omitted parts must be filled in. Phrases like “standard operations” in the prompt require the model to fill in the details itself; evaluation should check whether the completions are reasonable rather than only inspecting the final figure.

    Once decomposed, the requirements form a checklist that can be reviewed item by item, manually or with scripts.

    Designing the Evaluation Dimensions

    Score the output across the following five dimensions, recording each separately so that a single total score does not hide specific problems.

    1. Mathematical correctness
    Check whether key point coordinates, segment relationships, and geometric constraints hold. This is the most important dimension.

    2. Step completeness
    Check whether every operation required by the prompt has a corresponding implementation, with no skipped steps or approximations substituting for actual constructions.

    3. Interaction and rendering
    Check whether the page runs properly, whether the animation is smooth, and whether the output format (such as an animation file) meets the requirements.

    4. Expression and code quality
    Check whether the code structure is clear, variable names are readable, and comments explain the geometric reasoning.

    5. Generation stability
    Sample the same prompt multiple times and observe consistency. A single success does not demonstrate stable capability.

    Latency and interrupted output should also be recorded. Long pauses, or producing only reasoning without a final output, affect real-world usability and should be tracked separately.

    Reference Implementation: Computing Regular Polygon Vertices with Trigonometry

    In a geometric construction page, the vertices of a regular polygon can be obtained by equally dividing a circle. Given circumradius r, center (cx, cy), and side count n, the coordinates of the k-th vertex are:

    • x = cx + r · cos(θk)
    • y = cy + r · sin(θk)
    • θk = 2πk / n − π/2

    Subtracting π/2 places the first vertex directly above the center.

    The following Python code demonstrates the computation and verifies that all side lengths and interior angles are equal:

    1. import math
    2. def regular_polygon(n, r, cx=0.0, cy=0.0):
    3. """Return the vertices of a regular n-gon, with the first vertex directly above the center."""
    4. points = []
    5. for k in range(n):
    6. theta = 2 * math.pi * k / n - math.pi / 2
    7. points.append((cx + r * math.cos(theta), cy + r * math.sin(theta)))
    8. return points
    9. def verify_regular(points, tol=1e-9):
    10. n = len(points)
    11. sides = []
    12. angles = []
    13. for i in range(n):
    14. p_prev = points[i - 1]
    15. p = points[i]
    16. p_next = points[(i + 1) % n]
    17. sides.append(math.dist(p, p_next))
    18. v1 = (p_prev[0] - p[0], p_prev[1] - p[1])
    19. v2 = (p_next[0] - p[0], p_next[1] - p[1])
    20. cos_a = (v1[0] * v2[0] + v1[1] * v2[1]) / (
    21. math.hypot(*v1) * math.hypot(*v2)
    22. )
    23. angles.append(math.degrees(math.acos(max(-1.0, min(1.0, cos_a)))))
    24. side_ok = max(sides) - min(sides) < tol
    25. angle_ok = max(angles) - min(angles) < 1e-6
    26. return side_ok and angle_ok, sides[0], angles[0]
    27. pts = regular_polygon(7, 100)
    28. ok, side, angle = verify_regular(pts)
    29. print(ok, round(side, 4), round(angle, 4)) # expected interior angle is about 128.5714 degrees

    This code provides a baseline for evaluation. If a model-generated regular heptagon fails a similar check on its rendered vertex coordinates, its geometric construction can be judged incorrect, even if it looks visually close.

    Note that a regular heptagon cannot be constructed exactly with compass and straightedge; this is an algebraic result. Therefore, if a task explicitly requires “compass-and-straightedge construction,” the evaluation should examine whether the model uses a legitimate construction method or merely replaces the construction process with approximate drawing. Details like this are often the key to differentiating model capability.

    Common Failure Modes

    Across many such tasks, failures typically cluster into the following categories:

    • Visually close but structurally wrong: the figure looks correct, but vertices are unevenly distributed or side lengths differ noticeably.
    • Skipped key steps: intermediate constructions required by the prompt are omitted, jumping straight to the final result.
    • Misunderstood constraints: for example, implementing “leave traces only where necessary” as keeping all traces, or conversely deleting everything.
    • Incomplete output: long reasoning followed by missing or truncated code.
    • Slow responses: intermittent generation with noticeably longer wait times than comparable tasks.

    For these issues, evaluation records should preserve the raw outputs for later review. Recording only pass/fail loses the information needed for improvement.

    Designing Comparison Experiments

    When comparing different models, control the following variables:

    1. Identical prompts, including punctuation and line breaks, to avoid wording differences affecting results.
    2. Identical runtime environments, such as the same browser version and rendering library, to reduce environmental interference.
    3. Multiple samples: record several runs per model and report success rates rather than single-run performance.
    4. Blind review: evaluators should not know the source of each output in advance, to reduce subjective bias.
    5. Consistent timing: define timing clearly, from prompt submission to complete code output.

    The experiment report should state the sample size, the judging criteria, and any anomalies excluded from the statistics. Without this information, conclusions are difficult for others to reproduce.

    Practical Recommendations for Engineering Teams

    Teams planning to use code generation in production can turn the above approach into a routine evaluation workflow:

    • Build a task set relevant to the business rather than relying only on generic examples. Geometric construction can be replaced with chart rendering, data visualization, or form validation scenarios.
    • Write mathematical or logical checks as automated scripts that run on generated outputs, reducing manual item-by-item review.
    • Set thresholds for latency and failure rates; models exceeding them should not enter the production candidate list.
    • Re-test periodically, since model behavior can change after version updates.

    This methodology does not depend on any specific product and applies to selecting and evaluating any code generation tool.

    Conclusion

    Geometric construction tasks turn abstract coding ability into verifiable mathematical results. By decomposing steps, defining multi-dimensional scoring, running numeric verification, and controlling experimental variables, teams can judge more clearly how reliable a model is on real tasks. The key is to distinguish “looks right” from “mathematically right,” and to record failures as the basis for future improvement and model selection.