Skip to content
Snippets Groups Projects
Commit 7bc983c1 authored by Manuel Bucher's avatar Manuel Bucher
Browse files

Ausgabefunktion fuer Rechtecke geschrieben

parent 4fe692fe
No related merge requests found
...@@ -85,7 +85,7 @@ void list_push(List *this, Tile *p_tile) { ...@@ -85,7 +85,7 @@ void list_push(List *this, Tile *p_tile) {
this->min.x = min(this->min.x, p_tile->x); this->min.x = min(this->min.x, p_tile->x);
this->min.y = min(this->min.y, p_tile->y); this->min.y = min(this->min.y, p_tile->y);
this->max.x = max(this->max.x, p_tile->x); this->max.x = max(this->max.x, p_tile->x);
this->max.y = max(this->max.x, p_tile->y); this->max.y = max(this->max.y, p_tile->y);
this->num_tiles++; this->num_tiles++;
this->num_odd += (p_tile->x - p_tile->y)&1; this->num_odd += (p_tile->x - p_tile->y)&1;
} }
...@@ -106,7 +106,7 @@ void list_free(List *this) { ...@@ -106,7 +106,7 @@ void list_free(List *this) {
/** pruefen, ob genausoviele gerade und ungerade Kacheln existieren, /** pruefen, ob genausoviele gerade und ungerade Kacheln existieren,
* ohne einen Overflow zu erzeugen * ohne einen Overflow zu erzeugen
* notwendiges Kriterium fuer * notwendiges Kriterium
*/ */
bool list_necessity(List *this) { bool list_necessity(List *this) {
return this->num_tiles - this->num_odd == this->num_odd; return this->num_tiles - this->num_odd == this->num_odd;
...@@ -115,8 +115,33 @@ bool list_necessity(List *this) { ...@@ -115,8 +115,33 @@ bool list_necessity(List *this) {
/** Zurueckgeben, ob graph ein vollstaendiges Rechteck ist */ /** Zurueckgeben, ob graph ein vollstaendiges Rechteck ist */
bool list_rectangle(List *this) { bool list_rectangle(List *this) {
// verwenden von `uint64_t` um einen ueberlauf zu vermeiden // verwenden von `uint64_t` um einen ueberlauf zu vermeiden
return (uint64_t)(this->max.x - this->min.x) * (uint64_t)(this->max.y - this->min.y) return (uint64_t)(this->max.x - this->min.x+1) * (uint64_t)(this->max.y - this->min.y+1)
== (uint64_t)this->num_tiles; == (uint64_t)this->num_tiles;
}
/** Ausgeben der Liste als Rechteck
*
* Voraussetzung: notwendiges Kriterium erfuellt & es handelt sich um ein Rechteck
*/
void list_print_rectangle(List *this) {
for (uint32_t y = this->min.y;; y++) {
for (uint32_t x = this->min.x;; x+=2) {
if (x == this->max.x - 1) {
if ((y - this->min.y) % 2 == 0) {
// vertikaler Stein
printf("%u %u;%u %u\n", x, y, x, y+1);
}
break;
}
printf("%u %u;%u %u\n", x, y, x+1, y);
if (x == this->max.x) {
break;
}
}
if(y == this->max.y) {
break;
}
}
} }
typedef enum ReadResult { typedef enum ReadResult {
...@@ -355,8 +380,7 @@ int main (void) ...@@ -355,8 +380,7 @@ int main (void)
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if (list_rectangle(&tile_list)) { if (list_rectangle(&tile_list)) {
printf("Rechteck"); list_print_rectangle(&tile_list);
// TODO: Rechteck ausgabefunktion
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment