Skip to content

kernel: bbox/polygon geometry as a pydantic discriminated union (replaces Annotation.geometry: dict) - #72

Merged
JArmandoAnaya merged 1 commit into
mainfrom
task/10-geometry-union
Jul 26, 2026
Merged

kernel: bbox/polygon geometry as a pydantic discriminated union (replaces Annotation.geometry: dict)#72
JArmandoAnaya merged 1 commit into
mainfrom
task/10-geometry-union

Conversation

@JArmandoAnaya

Copy link
Copy Markdown
Contributor

Replaces Annotation.geometry: dict[str, object] with a real discriminated union on type.

What landed

  • kernel/domain/geometry.pyBboxGeometry {x, y, width, height}, PolygonGeometry {points: [[x, y], ...]}, ClassificationGeometry {}, joined as Geometry = Annotated[..., Field(discriminator="type")].
  • The discriminator values are GeometryType members, not parallel string literals, so annotation.geometry.type is directly comparable to a schema's allowed geometries — AnnotationService (kernel: AnnotationService — schema-validated writes (hard reject: unknown class, disallowed geometry, missing required attribute), provenance, UUID identity #7) needs no translation layer.
  • Variants are frozen=True, extra="forbid": a bbox payload carrying points is rejected rather than silently validating.
  • Model-level rejections: non-positive width/height (a zero-area box is as meaningless as a negative one), polygons with fewer than three points, and payloads naming a GeometryType that has no model yet (mask, polyline, the 3D variants).
  • Self-intersection is deliberately not validated in M1 — documented on the model.
  • tests/kernel/test_annotation.py's fixture used abbreviated w/h; updated to width/height.

Scope note

Acceptance criterion 2 names AnnotationService and allowed_geometries, which belong to #7 and #6 respectively and do not exist yet (kernel/services/ is empty; LabelClass carries a singular geometry). It is satisfied here at the model level — the union makes the check a plain membership test, proven by a test against the existing LabelClass.geometry. No service was created; #7 still owns the enforcement.

Gates

Gate Result
uv run pytest 40 passed (29 baseline + 11 new)
uv run ruff check . All checks passed
uv run ruff format --check . 54 files already formatted
uv run mypy src/visionset/kernel no issues in 27 files
uv run mypy src/visionset no issues in 37 files
uv run lint-imports 2 contracts kept, 0 broken
scripts/export_openapi.py no drift (no route references Annotation)

Frontend untouched, so frontend gates are not implicated.

Closes #10

Replaces Annotation.geometry: dict[str, object] with a real union discriminated
on `type`: BboxGeometry, PolygonGeometry and ClassificationGeometry.

The discriminator values are GeometryType members rather than parallel string
literals, so a schema's allowed geometries and an annotation's geometry are
directly comparable — AnnotationService (#7) needs no translation layer.

Variants are frozen and forbid extra fields, so a bbox payload carrying polygon
keys is rejected instead of silently validating. Non-positive width/height and
polygons with fewer than three points are rejected at the model level;
self-intersection is explicitly not validated in M1.
@JArmandoAnaya
JArmandoAnaya merged commit fe833fb into main Jul 26, 2026
3 checks passed
@JArmandoAnaya
JArmandoAnaya deleted the task/10-geometry-union branch July 26, 2026 09:47
JArmandoAnaya added a commit that referenced this pull request Aug 21, 2026
…#72)

Replaces Annotation.geometry: dict[str, object] with a real union discriminated
on `type`: BboxGeometry, PolygonGeometry and ClassificationGeometry.

The discriminator values are GeometryType members rather than parallel string
literals, so a schema's allowed geometries and an annotation's geometry are
directly comparable — AnnotationService (#7) needs no translation layer.

Variants are frozen and forbid extra fields, so a bbox payload carrying polygon
keys is rejected instead of silently validating. Non-positive width/height and
polygons with fewer than three points are rejected at the model level;
self-intersection is explicitly not validated in M1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kernel: bbox/polygon geometry as a pydantic discriminated union (replaces Annotation.geometry: dict)

1 participant