Evaluating Code Generation with Geometric Construction Tasks: A Test Methodology

    Geometric construction problems offer a rigorous way to evaluate LLM code generation beyond simple "does it run" checks. This article explains how to decompose construction tasks into testable subtasks, build a scoring rubric, verify geometric correctness numerically, and design effective prompts, turning subjective impressions into reproducible engineering practice.

    Why Test Code Generation with Geometric Construction Problems

    When evaluating code generation, a common approach is to ask a model to produce a web page or an animation. These tasks are easy to set up but offer limited differentiation. Many models can draw static shapes, yet fail to handle constraints, motion trajectories, and output formats correctly. A result that merely runs does not prove the model actually understood the problem.

    Geometric construction tasks fill this gap. Every step in a compass-and-straightedge construction carries strict mathematical meaning: concepts like perpendicular bisectors, circles, and intersection points each correspond to well-defined coordinate relationships. As long as the problem spells out the steps clearly, correctness can be verified numerically, without relying on subjective human judgment.

    Decomposing the Task: Breaking a Composite Problem into Testable Subtasks

    A complete construction problem typically involves four categories of requirements:

    1. Basic shape construction: a square, its diagonals, the perpendicular bisector of the base, circles, and intersection points.
    2. Constrained motion: using a marked ruler with two scales (a two-mark ruler), slide one scale mark along a circle until the second mark passes through a specified position.
    3. Trajectory and trace control: record the trajectory of a moving point during the animation, keeping only the necessary auxiliary lines and traces.
    4. Result output: export the animation as a widely supported animated GIF.

    Each category can be tested and scored independently. If a model completes only the first category, it has mastered basic drawing. If it fails the second, the problem usually lies in its understanding of constraints. Only by decomposing composite tasks can you locate the exact boundaries of a model’s capabilities.

    Building Evaluation Dimensions and a Scoring Rubric

    Use a rubric like the following to score outputs:

    Dimension What to Check Points
    Basic geometry Correct square, perpendicular bisector, and circle center 20
    Constrained motion Scale mark moves along the circle and stops at the target condition 25
    Trajectory traces Trajectory is complete, no leftover auxiliary lines 15
    Interactive animation Smooth motion, continuity between adjacent frames 15
    Export function Generates a frame-by-frame animated GIF 15
    Code quality Runs as a single file, no errors, no external dependencies 100 total scaled to 10

    Each dimension’s weight should match the difficulty of that part of the problem. Constrained motion is the core of this particular task, so it carries the highest score.

    Replacing Visual Inspection with Numerical Verification

    Geometric correctness can be checked through coordinate calculations. The following example provides two basic functions: one computes the distance from a point to a line, and the other checks whether a point lies on the perpendicular bisector of a segment within a tolerance.

    1. import math
    2. def point_to_line_distance(p, a, b):
    3. """Compute the distance from point p to line ab"""
    4. x0, y0 = p
    5. x1, y1 = a
    6. x2, y2 = b
    7. num = abs((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1)
    8. den = math.hypot(y2 - y1, x2 - x1)
    9. if den == 0:
    10. raise ValueError("a and b must not coincide")
    11. return num / den
    12. def on_perpendicular_bisector(pt, p1, p2, tol=1e-3):
    13. """Check whether pt lies on the perpendicular bisector of segment p1p2"""
    14. return abs(math.dist(pt, p1) - math.dist(pt, p2)) <= tol

    Usage: require the page to expose the coordinates of key points on a global object so a test script can read them, then have the script call the functions above to verify each condition. A tolerance of roughly one-thousandth of the canvas size works well — large enough to filter out floating-point error, small enough to catch obvious positional mistakes.

    Common Failure Modes

    • Rendering only the final state: the page shows the finished figure but implements no motion.
    • Misunderstood constraints: the scale mark moves along the wrong path or stops at the wrong position.
    • Failed trace control: all auxiliary lines are kept, or the trajectory is missing.
    • Numerical precision issues: approximate coordinate calculations accumulate error, pushing intersection points off target.
    • Missing output step: the animation plays, but cannot be exported as an animated GIF.

    Each failure mode points to a different fix. Evaluation reports should record each category of problem separately, rather than issuing a simple pass/fail verdict.

    Prompt Design Principles

    1. Order the steps: describe the construction in sequence, specifying the input and output of each step.
    2. Fix the coordinate system: state the canvas size, origin position, and units so the model doesn’t make its own assumptions.
    3. Clarify what may be omitted: when the task says “fill in the omitted construction steps,” specify which steps must appear in the animation.
    4. State the acceptance criteria: tell the model which traces must be kept and which must be hidden.

    The more specific the prompt, the easier the output is to compare against expected results. But excessive specificity undermines the test’s diagnostic value. A good balance is to specify the steps and acceptance criteria while leaving the concrete implementation to the model.

    Interpreting Test Results

    A single run is subject to randomness. After sampling the same prompt multiple times, compute a pass rate and record the model version, sampling parameters, and runtime environment. One problem reflects only a specific capability and cannot represent overall performance. To compare models, combine multiple problem types — such as data processing, API calls, bug fixing, and long-context comprehension — into a complementary evaluation set.

    For development teams, the most practical deliverable is a reproducible library of test cases, each containing a prompt, expected numerical results, scoring rules, and automation scripts. Such a library can run continuously as models iterate, helping teams catch capability regressions when switching model versions.

    Summary

    The value of geometric construction tasks is that they turn “looks like it works” into “can be verified.” Combining task decomposition, quantified scoring dimensions, and automated verification moves code generation evaluation from subjective impressions toward reproducible engineering practice.