Skip to content

Kristiyan-Todorov/rs-rectangle-transform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rectangle Transform

Generates the requested number of adjacent vertical rectangles of random width and height, sharing the same base, and recreates the outline of theoverall shape using the minimum number of horizontal rectangles.

Transform algorithm

  • sort the source rectangles by height and iterate over them:
    • rectangle with the lowest height is always used as base;
    • lookup left and right for all adjacent rectangles higher than the current one:
      • if there are any:
        • get all the rectangles generated by previous iterations that include the current's x coordinate in order to calculate height and y coordinate.
        • left most rectangle is used to get x coordinate;
        • width is the sum of all of the adjacent rectangles' widths, including the current one
      • if there are none:
        • get the highest adjacent to calculate y coordinate and height. Width and x coordinate are persisted.

Usage

Start application

  cargo run --release

image

Open web page

image

Input number of rectangles and click

Note: Graphics are intentionally offset, see generated file for accurate coordinates

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published