void make_bitmap_label(struct variant *v, struct sym_text *text)
{
- v->width = ceil(text->tw);
- v->height = ceil(text->th);
+ int tw = ceil(text->tw);
+ int th = ceil(text->th);
+
+ double rotate_rad = text->rotate / (-180 / M_PI);
+
+ // Initially, ll = [0; 0], lr = [tw, 0], ul = [0, th], ur = [tw, th]
+ // They could be declared before but should not be initialized in code
+ // as reassigning x-coordinate affects computation of y-cordinate
+ int llx = 0;
+ int lly = 0;
+
+ int lrx = tw * cos(rotate_rad);
+ int lry = tw * sin(rotate_rad);
+
+ int ulx = th * sin(rotate_rad);
+ int uly = th * cos(rotate_rad);
+
+ int urx = tw * cos(rotate_rad) + th * sin(rotate_rad);
+ int ury = tw * sin(rotate_rad) + th * cos(rotate_rad);
+
+ int min_x = min4(llx, lrx, ulx, urx);
+ int min_y = min4(lly, lry, uly, ury);
+ int max_x = max4(llx, lrx, ulx, urx);
+ int max_y = max4(lly, lry, uly, ury);
+
+ v->width = max_x - min_x + 1;
+ v->height = max_y - min_y + 1;
v->bitmap = malloc(v->width * v->height * sizeof(bool));
- for (int i=0; i<v->height; i++)
- for (int j=0; j<v->width; j++)
+ memset(v->bitmap, 0, v->width * v->height * sizeof(bool));
+
+ for (int i=0; i<th; i++)
+ {
+ for (int j=0; j<tw; j++)
{
- v->bitmap[i*v->width + j] = 1;
+ int nx = j*cos(rotate_rad) + i*sin(rotate_rad);
+ int ny = j*sin(rotate_rad) + i*cos(rotate_rad);
+ v->bitmap[(ny-min_y)*v->width + (nx-min_x)] = 1;
}
+ }
}
void labeller_add_point(struct symbol *sym, struct osm_object *object, z_index_t zindex)
rs->request.type = REQUEST_SEGMENT;
GARY_INIT(rs->request.variants, 0);
- struct variant *v = GARY_PUSH(rs->request.variants);
- make_bitmap(v, sym);
+ if (sym)
+ {
+ struct variant *v = GARY_PUSH(rs->request.variants);
+ make_bitmap(v, sym);
+ }
return rs;
}
cut_edge(e, max2(conf_max_section_length - cur_length, 2));
}
- rs = make_new_segment(rls, e->label);
+ rs = make_new_segment(rls, NULL);
rs->label = malloc(sizeof(struct sym_text));
*((struct sym_text *) rs->label) = *((struct sym_text *) e->label);
rs->y2 = e->n2->o->y;
rs->slope = (rs->y2 - rs->y1) / (rs->x2 - rs->x1);
+ ((struct sym_text *) rs->label)->rotate = atan(rs->slope) * (-180 / M_PI);
+ struct variant *v = GARY_PUSH(rs->request.variants);
+ printf("Request %d\n", rs->request.ind);
+ make_bitmap(v, rs->label);
+
rs->zindex = e->zindex;
cur_length += e->length;