HHullspring
Workflows

Coding workflows · Integer convex hulls

03
Built around your work

A concrete starting point

Build a counterclockwise convex hull from at most 1000 integer points, starting at the lexicographically smallest point. Check empty input, duplicates and collinear points, retaining only extreme endpoints and rejecting fractional coordinates.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Integer convex hulls

A concrete starting point
def convex_hull(points):
    if type(points) is not list or len(points) > 1000:
        raise ValueError("hull.input")
    if any(type(p) not in (tuple, list) or len(p) != 2 or
           any(type(v) is not int for v in p) for p in points):
        raise ValueError("hull.point")
    ordered = sorted(set(map(tuple, points)))
    if len(ordered) <= 1:
        return ordered
    def turn(a,b,c):
        return (b[0]-a[0])*(c[1]-a[1])-(b[1]-a[1])*(c[0]-a[0])
    def chain(sequence):
        out = []
        for p in sequence:
            while len(out) >= 2 and turn(out[-2],out[-1],p) <= 0:
                out.pop()
            out.append(p)
        return out
    return chain(ordered)[:-1]+chain(reversed(ordered))[:-1]

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗