Skip to content

Add support for remaining divided cell types in `svg.c`

Description

This MR adds support for the remaining divided types, in svg.c:

Divided type Symbol
divided_up_right
divided_up_left
divided_plus
divided_cross 🗙

It also fixes an alignment issue with the existing dividers: divided_horiz and divided_vert.

Support for divided types

Here's roughly how the SVGs I added work.

divided_up_right

  1. To begin, define the divider to be identical to divided_horiz.
  2. Set the divider's width to = length of the diagonal / hypotenuse of the cell; width = sqrt(2) * cell_size.
  3. Rotate the divider -45°, about the center of the cell; center = (cell_size/2, cell_size/2). The divider pokes out the top-right corner of the cell, because it's longer than cell_size.
  4. In order to push the divider back into the cell, translate it towards the bottom left corner. translate(-amount, 0) works, because the translation moves the divider parallel to its width (which in this case is diagonally). The amount to move it = the amount that the divider's length exceeds the cell length by, divided by 2: (sqrt(2)*cell_size - cell_size) / 2. This puts an even amount of "excess" length on both sides of the divider.
  5. Translate the divider vertically by height / 2 (half the thickness of the divider). So the translation becomes: translate(-amount, -height/2) See Fix alignment issue below.

divided_up_left

Same as divided_up_right, just positive 45° rotation instead.

divided_plus

divided_horiz and divided_vert combined into a <g> container.

divided_cross

divided_up_right and divided_up_left combined into a <g> container.

Fix alignment issue

Before this MR, divided_horiz and divided_vert were not perfectly aligned to the center of the cell. They were both off by half the thickness of the divider.

Let's use divided_horiz as an example. divided_horiz has x=0, y=cell_size/2. This means that the top-left corner of the rectangle is at (0, cell_size/2). So any thickness (height) that the divider has will appear below (0, cell_size/2)--below the center of the cell. Example.

To fix this, we have to translate it by the amount that it's offset by, which is half the height. Example.

Related Issues

Fixes the FIXME in svg.c that says to handle the rest of the divided types.

Visual Diff (if any)

With some testing code applied:

Alignment comparison with and without this patch applied:

IPUZ files for testing

https://gitlab.gnome.org/-/snippets/6945

Improved divided-test.ipuz (adds solutions, so Crosswords player doesn't instantly end game): https://gitlab.gnome.org/-/snippets/6953

Edited by Victor Ma

Merge request reports

Loading