Evaluating Code Generation with Geometric Construction Tasks: A Practical Method
Geometric construction tasks are an effective way to evaluate code generation beyond basic syntax correctness. This article explains why they work, how to design verifiable multi-step tasks, and walks through a regular heptagon construction example—including mathematical background, checkpoint decomposition, trace control, and animation export. It also covers scoring dimensions, validation logic with sample pseudocode, and practical engineering tips for building a reliable evaluation pipeline.
Why Use Geometric Construction to Evaluate Code Generation
Frontend visualization tasks are a common way to test code generation capabilities. A page that opens correctly only proves the basic syntax is sound. To judge whether a model truly understands the requirements, you need to see whether it can translate mathematical constraints, step-by-step instructions, and interaction details into code at the same time. Geometric construction fits these conditions well: every step has a clear mathematical meaning, results can be verified numerically, and deviations are easy to detect with scripts or by eye.
Such tasks also distinguish “looks right” from “is right.” A page whose output closely resembles the target figure may have taken shortcuts unrelated to the prescribed method. Evaluation therefore needs to check both the final image and whether the process follows the required approach.
Three Principles of Task Design
1. Verifiability. Every requirement should be convertible into a decidable condition. For example, “all vertices lie on the same circle” can be checked by computing each vertex’s distance to the center and testing whether the error is within a threshold. Requirements that cannot be verified, such as “the visual result is aesthetically pleasing,” should be listed separately as subjective items and excluded from automated scoring.
2. Stepwise constraints. Break the problem into ordered sub-steps, each leaving inspectable intermediate results. For instance, construct a square first, then the perpendicular bisector of the bottom edge, and finally determine the circle’s center and radius. If something goes wrong, you can pinpoint the failing step instead of getting only a binary “pass” or “fail.”
3. Observable output. Require the result to be presented as a web page with support for exporting an animation file. The output format is itself part of the test: it checks whether the model can turn a geometric process into a working dynamic effect.
Example: Constructing a Regular Heptagon
Mathematical Background
A regular heptagon cannot be constructed exactly with only an unmarked straightedge and compass. This follows from Gauss’s work on which regular polygons are constructible: a regular polygon is constructible with straightedge and compass only when its number of sides is a power of 2 times distinct Fermat primes, and 7 does not satisfy this condition. If a marked ruler is allowed—moved so that its markings slide along specified paths and pass through specified points—the construction becomes possible. This technique is known as a neusis construction. The “two-marked ruler” in the task refers to a ruler with two marks, and its movement rules determine whether the construction holds.
Sub-task Decomposition
Suggested checkpoints:
- The square’s four vertex coordinates are correct and all four sides have equal length;
- The perpendicular bisector of the bottom edge passes through the edge’s midpoint and is perpendicular to it;
- The circle centered at the bottom-right vertex with radius equal to the diagonal length is drawn correctly;
- The first mark of the marked ruler slides along the circle while the second mark intersects the perpendicular bisector;
- The subsequent construction points derived from the intersection satisfy the vertex distribution of a regular heptagon.
Each checkpoint corresponds to coordinates or line segments readable from the page, so items can be scored individually.
Trace Control
The task requires “leaving traces only where necessary.” This means the animation must distinguish two kinds of elements: construction results that remain on screen, and auxiliary elements used only during the motion. During evaluation, count the lines and paths in the page. If large numbers of irrelevant auxiliary lines persist, the model has not understood the trace constraint.
Animation Export
Exporting a GIF is an independent engineering requirement. Check three things: whether the file is generated, whether animation frames are in correct chronological order, and whether the exported content matches what the page displays. An export failure or blank output should be recorded as incomplete.
Evaluation Dimensions and Judgment Methods
4.1 Instruction compliance. Compare the output against each requirement and record how many are fulfilled. Completion rate is the most direct metric, but it does not capture dependencies between requirements, so it should be read together with the geometric checks below.
4.2 Geometric correctness. Verify results numerically. Core metrics include consistency of vertex distances to the center, side-length consistency, and adjacent-side angles. Each interior angle of a regular heptagon is (7−2)×180°/7, roughly 128.57°, with an exterior angle of about 51.43°. Error thresholds should be fixed in advance—for example, a relative error no greater than one percent.
4.3 Process consistency. Distinguish “correct figure” from “correct method.” If the task prescribes a specific construction and the implementation instead computes vertex coordinates directly from a formula, deduct points on the process dimension even if the figure is perfectly correct, and note this in the report.
4.4 Interaction and stability. Record whether the page loads correctly in mainstream browsers, whether the animation stutters, and whether cases occur where the model produces only reasoning content with no final output. The pass rate over multiple runs of the same task is more informative than a single result.
Example Judgment Logic
The following pseudocode shows a basic validation flow for a regular polygon; vertices must be provided in order:
function checkRegularPolygon(vertices, n, tol):if count(vertices) != n: return FAILcenter = average(vertices)radii = [distance(v, center) for v in vertices]sides = [distance(vertices[i], vertices[(i + 1) % n]) for i in range(n)]meanR = average(radii)meanS = average(sides)if max(radii) - min(radii) > tol * meanR: return FAILif max(sides) - min(sides) > tol * meanS: return FAILif abs(meanS - 2 * meanR * sin(pi / n)) > tol * meanS: return FAILreturn PASS
The last check uses the relationship between a regular polygon’s side length and its circumradius, s = 2R·sin(π/n), which rules out cases where vertices lie on the circle but are unevenly distributed.
Engineering Practices
- Fix the evaluation set. Use the same set of tasks over the long term to enable longitudinal comparisons across time periods.
- Record latency in stages. Measure both the time from request submission to the first visible output and the time to the complete result.
- Categorize failure causes. Classify failures as empty output, syntax errors, geometric errors, process deviation, and so on. Categorized statistics point to improvement directions better than a single overall score.
- Run multiple times. Run each task at least several times and track the pass rate and result variance.
- Manual spot checks. Automated judgment cannot cover all visual details, such as line thickness and label placement, so manual review is needed as a supplement.
Common Pitfalls
- Treating visual similarity as correctness. A figure that looks like a regular heptagon does not mean the prescribed steps were followed.
- Inferring overall capability from a single sample. The result on one task only reflects performance on that task, not all scenarios.
- Ignoring latency. A correct result that takes too long still hurts the user experience in practice, so it should be evaluated alongside correctness.
