Preparing your design workspace

Loading the problem and your saved attempt…

Design a Shape Transformation Engine

Model a drawing's shapes and implement geometric transformations in the order a user requests them.

The reported interview task was to design and code a small geometry engine for drawing shapes and applying geometric transformations. The report did not give a complete specification. The following rules are authored practice assumptions.

For this exercise, assume one user works with an in-memory 2D drawing. The user can create a shape, receive its unique ID, apply transformations to that shape, and read its current drawable state. Begin with polylines and circles, while leaving room for other shape kinds.

A polyline has at least two points; a circle has a center and a positive radius. Shape input is validated before it is stored.

Apply translation by dx and dy, scaling by sx and sy, and rotation by degrees. Each operation acts on the currently displayed shape in world coordinates, in request order. Scaling and rotation use the world origin as their pivot. Positive rotation is counterclockwise.

Scale factors may be zero or negative; non-uniform scaling must work, including when it makes a circle appear as an ellipse.

Reject non-finite input, an invalid shape, a missing shape ID, or a non-finite composed transform with an explicit failure. A rejected operation must leave stored state unchanged. A read must not let its caller mutate the drawing through an alias. Use a small tolerance when testing floating-point coordinates.

Design the responsibilities, public contracts, and one success/failure flow. Then implement the central transform, composition, and shape-update behavior in a language of your choice or precise pseudocode. You may stub validated geometry creation and drawing.

GUI code, persistence, inverse transforms, concurrent editing, and a complete renderer are outside scope. A follow-up introduces one new shape kind whose local geometry and drawing logic are already supplied.