Evaluating Code Generation Capabilities of Lightweight Models via Geometric Construction Tasks

    Geometric construction tasks provide a robust method for evaluating code generation models, requiring instruction comprehension, geometric reasoning, and frontend implementation. This article explores the practice of using a heptagon construction task to assess lightweight models, detailing task decomposition, common failure modes, evaluation dimensions, and programmatic validation methods for geometric results, process logs, and GIF export.

    1. Why Use Geometric Construction Tasks for Evaluation

    Common code generation evaluations often use algorithmic problems or API call tasks. The answers to these problems are usually unique, making it easy for models to rely on memory rather than demonstrating actual understanding versus retrieval capabilities. Geometric construction tasks are different. They require the model to simultaneously accomplish three things: understand natural language instructions with step sequences, translate geometric constraints into mathematical expressions, and use frontend technologies to present the process as an animation.

    These tasks offer two advantages. First, correctness is verifiable. Whether a shape satisfies geometric conditions can be confirmed using coordinates and distance calculations, without relying on subjective judgment. Second, the process is observable. The animation displays each operation frame by frame, allowing evaluators to see if the model followed the instructions or simply pieced together a seemingly correct final image.

    The task discussed in this article requires implementing a dynamic demonstration of “constructing a regular heptagon using a marked ruler and a compass” on a webpage, with the final result exportable as a GIF. Although it appears to be a simple drawing problem, it demands high levels of instruction following, geometric reasoning, and engineering implementation.

    2. Task Decomposition: From Text Instructions to Geometric Steps

    Before evaluation, the instructions are broken down into checkable steps. Here are the main phases involved in this task.

    1. Construct Basic Shapes: Draw a square and construct the perpendicular bisector of its base. This step requires the bisector’s position to be precise. A common error is the bisector being offset or too short.
    2. Use the Circle as a Tool: Draw a circle centered at one vertex of the square with a radius equal to the diagonal length. The radius must equal the diagonal, not the side length.
    3. Marked Ruler Constrained Movement: Place one end of the marked ruler against another vertex of the square, slide the first mark along the circle until the second mark intersects the perpendicular bisector. This step involves dynamic constraints and requires solving a position parameter to satisfy both conditions simultaneously.
    4. Complete the Omitted Compass and Straightedge Steps: Determine the center and the vertices of the regular heptagon through standard operations like finding intersections and constructing perpendicular bisectors.
    5. Trajectory and Trace Control: Moving the compass generates trajectories, but only necessary line segments should remain on the canvas; other auxiliary lines should disappear or fade.

    After decomposition, each step corresponds to a checkpoint. If the model misses any step or adds steps not required by the instructions, the evaluation will detect the issue.

    3. Common Failure Modes

    When comparing outputs from multiple models, several typical issues can be identified.

    3.1 Correct Result, Deviated Process

    This is the most critical category to watch out for. The final page indeed shows a regular heptagon, but the construction process did not follow the instructions. For example, the model might directly use trigonometric functions to calculate the vertex coordinates and draw the polygon, skipping the marked ruler and compass operations; or it might add extra auxiliary steps not present in the instructions just to close the shape.

    Such outputs are hard to identify when only looking at the final screenshot, so the evaluation must not only compare the result image but also check the process.

    3.2 Only Outputs Reasoning, No Code

    Some models spend a long time in the reasoning phase during generation, ultimately failing to produce complete code or truncating the output midway. This is an engineering-level stability issue. During evaluation, the time to first byte, total time, and whether the generation completed fully should be recorded, with a unified timeout limit set for each generation.

    3.3 Geometric Conditions Not Met Numerically

    The internal angle of a regular heptagon is approximately 128.57 degrees, or 900/7 degrees. If the generated shape visually resembles a heptagon but the side lengths or internal angles deviate significantly, it indicates an error in the model’s numerical calculations. These issues are difficult to spot with the naked eye and require programmatic calculation for verification.

    3.4 Missing Animation and Export Functions

    Some outputs can display static or dynamic graphics but encounter issues like frame dropping, color distortion, or excessively large file sizes when exporting to GIF. When evaluating the export function, check whether the frame count, frame interval, visual integrity, and file size are reasonable.

    4. Evaluation Dimension Design

    It is recommended to split the evaluation into the following six dimensions, scoring each independently to avoid masking specific issues with a single total score.

    • Instruction Adherence: Whether each step is completed in the given order and if there are any extra steps.
    • Geometric Correctness: Whether the side lengths, angles, and vertex positions of the final shape meet the conditions.
    • Process Fidelity: Whether the animation process matches the instruction description and if intermediate states are reasonable.
    • Code Runnability: Whether the code can run directly in a standard browser environment without errors.
    • Functional Completeness: Whether additional requirements like trace control, interactive demonstration, and GIF export are implemented.
    • Generation Efficiency: The time taken from sending the request to receiving the complete result, and whether interruptions occurred.

    Each test should be repeated multiple times to record the distribution of results, rather than relying on a single output. Single results are highly influenced by randomness; multiple tests are needed to reflect stable performance levels.

    5. Programmatic Verification of Geometric Results

    Manual inspection of shapes can easily miss details, so geometric conditions can be written as a program to automatically verify the vertex coordinates generated by the model. The following example calculates the vertices of a regular n-gon and checks if all sides are equal in length.

    1. // Calculate the vertices of a regular n-gon centered at (cx, cy) with radius r
    2. function regularPolygon(n, cx, cy, r, startAngle = -Math.PI / 2) {
    3. const points = [];
    4. for (let i = 0; i < n; i++) {
    5. const angle = startAngle + (2 * Math.PI * i) / n;
    6. points.push({
    7. x: cx + r * Math.cos(angle),
    8. y: cy + r * Math.sin(angle),
    9. });
    10. }
    11. return points;
    12. }
    13. // Check if the relative deviation of all side lengths is within tolerance
    14. function hasEqualSides(points, tolerance = 1e-6) {
    15. const n = points.length;
    16. const lengths = points.map((p, i) => {
    17. const q = points[(i + 1) % n];
    18. return Math.hypot(q.x - p.x, q.y - p.y);
    19. });
    20. const mean = lengths.reduce((sum, len) => sum + len, 0) / n;
    21. return lengths.every((len) => Math.abs(len - mean) / mean < tolerance);
    22. }
    23. const heptagon = regularPolygon(7, 0, 0, 100);
    24. console.log(hasEqualSides(heptagon)); // A regular heptagon should output true

    This check can only verify if the final shape is a regular heptagon; it cannot determine if the construction process is correct. Process checking requires separate methods.

    6. From Result to Process: Operation Log Verification

    A feasible approach is to record an operation tag for each construction step on the tested page, and finally compare it with the reference sequence. This can identify both missing and extra steps.

    1. // Reference construction sequence, step names defined uniformly by the evaluator
    2. const expectedSteps = [
    3. "draw_square",
    4. "draw_perpendicular_bisector",
    5. "draw_circle_E",
    6. "place_ruler_on_D",
    7. "slide_ruler_until_mark_hits_bisector",
    8. "construct_center_by_bisector",
    9. "construct_heptagon_vertices",
    10. ];
    11. // Compare the actual log with the reference sequence
    12. function checkProcess(actualLog, expected) {
    13. const missing = expected.filter((step) => !actualLog.includes(step));
    14. const extra = actualLog.filter((step) => !expected.includes(step));
    15. const outOfOrder = actualLog.length === expected.length &&
    16. actualLog.some((step, i) => step !== expected[i]);
    17. return {
    18. passed: missing.length === 0 && extra.length === 0 && !outOfOrder,
    19. missing,
    20. extra,
    21. outOfOrder,
    22. };
    23. }

    Note that the log tags are agreed upon by the evaluator within the tested code, so the evaluation guidelines should provide unified interface requirements; otherwise, different implementations cannot be compared. For pages that do not output logs as agreed, evaluators can manually check frame by frame.

    7. General Implementation Approach for GIF Export

    The basic process for exporting animations as GIF is generally the same, regardless of the specific tool, and mainly includes the following steps.

    1. Set a fixed frame rate and total duration, advancing the animation state in chronological order.
    2. Draw each frame on an offscreen canvas and read the pixel data.
    3. Quantize the pixel data into a limited palette, reducing the number of colors to control the file size.
    4. Encode each frame sequentially into GIF format data blocks, setting the display duration for each frame.
    5. Generate the file and provide it for download.

    During actual evaluation, check whether the number of frames in the exported file matches the setting, whether the lines are clear, and whether the file size is acceptable. Geometric shapes with thin lines are prone to aliasing or breaking after quantization, so the resolution can be appropriately increased or the compression level of the palette can be reduced.

    8. Conclusion and Engineering Recommendations

    Geometric construction tasks effectively reflect the comprehensive capabilities of code generation models in instruction understanding, mathematical reasoning, and frontend implementation. However, three points should be noted during evaluation.

    First, results and processes should be evaluated separately. Looking only at the final shape can easily lead to incorrect conclusions.

    Second, key metrics should be programmatic whenever possible. Side lengths, angles, and operation sequences can all be automatically verified, leaving manual review only for parts that the program cannot judge.

    Third, tests should be conducted multiple times, recording time consumption and interruptions. This data is valuable for assessing the model’s usability in actual workflows.

    If a team needs to use this type of evaluation long-term, they can compile the problems, reference sequences, validation scripts, and scoring rubrics into a standard test suite. This suite can be re-run after every model or tool update, and the results compared with historical versions to continuously track changes in code generation capabilities.