Using svg.js, I have drawn a (game) board, which is essentially a group of hexagon shaped paths. After all hexes are added, I would like to rotate the whole group by -60 degrees, and then read out a minimal, rectangular box that encompasses the resulting (visual) shape.
Appearance of the board and the box (hand-drawn in red) I want:
But I can't figure out how to get the red box; all I ever get seem to be boxes around the blue shape (which is of course the bbox of the whole group, itself rotated):
Some hints I found were to use an outer group (containing in turn the group that collects the fields); rotate the inner group, and get bbox() from the outer group; unfortunately, this changed nothing. Alternatively, some sources on the web suggested to use rbox() instead, but that again changed nothing, and isn't even in the documentation of svg.js 3.0.
For completeness the code that does the related things, even though this matter seems to be a more general issue. I realize I could circumvent the problem by avoiding the rotation in the first place, but I'd like to find a solution that allows to adress a series of similar cases without manual tweaking.
draw_board() {
let grp = this.canvas.group();
for (let field of this.fields) {
field.hex_display = grp.use(hexsym).size(this.w*this.hex_scale,this.h*this.hex_scale)
.center(field.cx,field.cy)
.addClass("hex_field")
.addClass(this.color);
}
let count = this.field.length;
let clipper = this.canvas.clip().path()
.M(...this.center(0,0))
.L(...this.center(0,count-1))
.L(...this.center(count-1,count-1))
.L(...this.center(count-1,0))
.Z();
grp.clipWith(clipper);
grp.rotate(-60);
let bb = grp.bbox();
this.canvas.viewbox(bb.x,bb.y,bb.w,bb.h)
}
Any pointers how to approach this?