All problems

Marquetry cutout areas become negative when vertex order is reversed

Level 1 · node · Correctness · Using signed polygon area as physical area

Scenario

A fictional marquetry studio displays the material area required for each cutout represented by a simple polygon. Tracing the same cutout in the opposite direction sometimes changes its preview area to a negative value. Review the area calculation function and the cutout list entry point.

Requirements

estimate(pieces) receives arrays of vertices for each cutout and returns their areas in input order. Vertices are finite integer coordinate pairs [x,y] listed along a simple polygon boundary clockwise or counterclockwise. The final vertex connects to the first. Area is nonnegative and independent of direction; fewer than three vertices or collinear vertices give zero. Do not mutate the input.

Acceptance criteria

  • Calculate the correct areas of counterclockwise rectangles and triangles.
  • Return the same area when the same cutout is listed clockwise.
  • Calculate physical area for concave cutouts and cutouts away from the origin.
  • Handle empty input and degenerate cutouts while preserving input order and original coordinates.