Skip to content

Commit

Permalink
#2447 - Preview: single up and single down bonds are displayed incor…
Browse files Browse the repository at this point in the history
…rect when save to PNG(svg)

Fix code.Add UT
  • Loading branch information
AliaksandrDziarkach committed Oct 3, 2024
1 parent 9a5332e commit 027f889
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 8 deletions.
2 changes: 2 additions & 0 deletions api/tests/integration/ref/rendering/acs_style.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
acs_style_default.png rendering status: OK
****** Changed ACS settings *****
acs_style_changed.png rendering status: OK
****** Issue 2447 wrong stereobond width *****
issue_2447.png rendering status: OK
21 changes: 20 additions & 1 deletion api/tests/integration/tests/rendering/acs_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,31 @@
indigo.setOption("bond-length", "1.2")
indigo.setOption("bond-length-unit", "inch")
indigo.setOption("render-bond-spacing", "0.5")
indigo.setOption("render-hash-spacing", "15")
indigo.setOption("render-hash-spacing", "10")
indigo.setOption("render-stereo-bond-width", "30")
indigo.setOption("render-font-size", "20")
renderer.renderToFile(mol, joinPathPy("out/acs_style_changed.png", __file__))
print(checkImageSimilarity("acs_style_changed.png"))

print("****** Issue 2447 wrong stereobond width *****")
indigo.resetOptions()
indigo.setOption("render-output-format", "png")
indigo.setOption("ignore-stereochemistry-errors", "true")
indigo.setOption("bond-length-unit", "px")
indigo.setOption("bond-length", "40")
indigo.setOption("render-bond-thickness", "2")
indigo.setOption("render-bond-thickness-unit", "px")
indigo.setOption("render-stereo-bond-width", "6")
indigo.setOption("render-stereo-bond-width-unit", "px")
indigo.setOption("render-hash-spacing", "1.2")
indigo.setOption("render-hash-spacing-unit", "px")
name = "issue_2447"
fname = name + ".ket"
mol = indigo.loadMoleculeFromFile(joinPathPy("molecules/" + fname, __file__))
pngname = name + ".png"
renderer.renderToFile(mol, joinPathPy("out/" + pngname, __file__))
print(checkImageSimilarity(pngname))

if isIronPython():
renderer.Dispose()
indigo.Dispose()
142 changes: 142 additions & 0 deletions api/tests/integration/tests/rendering/molecules/issue_2447.ket
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"root": {
"nodes": [
{
"$ref": "mol0"
}
],
"connections": [],
"templates": []
},
"mol0": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
9.625074417174607,
-10.015150847871434,
0
]
},
{
"label": "C",
"location": [
9.624589229177204,
-8.284849152128567,
0
]
},
{
"label": "C",
"location": [
9.124966888850187,
-9.148362490508761,
0
],
"stereoLabel": "abs"
},
{
"label": "C",
"location": [
10.625532067822148,
-8.284849152128567,
0
]
},
{
"label": "C",
"location": [
10.630020056798138,
-10.015150847871434,
0
]
},
{
"label": "C",
"location": [
11.125033111149811,
-9.146179144520442,
0
],
"stereoLabel": "abs"
},
{
"label": "C",
"location": [
8.12496707469278,
-9.147752830642434,
0
]
},
{
"label": "C",
"location": [
12.125025670104101,
-9.142321420314348,
0
]
}
],
"bonds": [
{
"type": 2,
"atoms": [
2,
0
]
},
{
"type": 1,
"atoms": [
0,
4
]
},
{
"type": 2,
"atoms": [
4,
5
]
},
{
"type": 1,
"atoms": [
5,
3
]
},
{
"type": 2,
"atoms": [
3,
1
]
},
{
"type": 1,
"atoms": [
1,
2
]
},
{
"type": 1,
"atoms": [
2,
6
],
"stereo": 6
},
{
"type": 1,
"atoms": [
5,
7
],
"stereo": 1
}
]
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion core/render2d/src/render_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void RenderSettings::init(float relativeThickness, float bondLineWidthFactor, Ac
if (acs->stereoBondWidthAngstrom > 0)
stereoBondSpace = acs->stereoBondWidthAngstrom / 2.0f;
if (acs->hashSpacingAngstrom > 0)
hashSpacing = acs->hashSpacingAngstrom;
hashSpacing = acs->hashSpacingAngstrom + bondLineWidth;
}
static constexpr float TWO_DIV_THREE = 2.0f / 3.0f;
fzz[FONT_SIZE_LABEL] = label_font_size;
Expand Down
7 changes: 3 additions & 4 deletions core/render2d/src/render_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,11 @@ RenderContext::RenderContext(const RenderOptions& ropt, float relativeThickness,
if (ropt.fontSizeSub > 0)
acs.fontSizeSubAngstrom = UnitsOfMeasure::convertToPx(ropt.fontSizeSub, ropt.fontSizeSubUnit, ropt.ppi) / ropt.bond_length_px;
if (ropt.bondThickness > 0)
acs.bondThicknessAngstrom = UnitsOfMeasure::convertToPx(ropt.bondThickness, ropt.bondThicknessUnit, ropt.ppi) / LayoutOptions::DEFAULT_BOND_LENGTH_PX;
acs.bondThicknessAngstrom = UnitsOfMeasure::convertToPx(ropt.bondThickness, ropt.bondThicknessUnit, ropt.ppi) / ropt.bond_length_px;
if (ropt.stereoBondWidth > 0)
acs.stereoBondWidthAngstrom =
UnitsOfMeasure::convertToPx(ropt.stereoBondWidth, ropt.stereoBondWidthUnit, ropt.ppi) / LayoutOptions::DEFAULT_BOND_LENGTH_PX;
acs.stereoBondWidthAngstrom = UnitsOfMeasure::convertToPx(ropt.stereoBondWidth, ropt.stereoBondWidthUnit, ropt.ppi) / ropt.bond_length_px;
if (ropt.hashSpacing > 0)
acs.hashSpacingAngstrom = UnitsOfMeasure::convertToPx(ropt.hashSpacing, ropt.hashSpacingUnit, ropt.ppi) / LayoutOptions::DEFAULT_BOND_LENGTH_PX;
acs.hashSpacingAngstrom = UnitsOfMeasure::convertToPx(ropt.hashSpacing, ropt.hashSpacingUnit, ropt.ppi) / ropt.bond_length_px;
if (ropt.bondSpacing > 0)
acs.bondSpacing = ropt.bondSpacing;
_settings.init(relativeThickness, bondLineWidthFactor, &acs);
Expand Down
5 changes: 3 additions & 2 deletions core/render2d/src/render_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4015,13 +4015,14 @@ void MoleculeRenderInternal::_bondSingle(BondDescr& bd, const BondEnd& be1, cons
else if (bd.stereodir == BOND_DOWN)
{
int constexpr min_count = 4;
if (_settings.hashSpacing > 0 && (int)(len / _settings.hashSpacing) > min_count)
auto count = len / (_settings.hashSpacing > 0 ? _settings.hashSpacing : (lw * 2));
if (_settings.hashSpacing > 0 && count > min_count)
{
_cw.fillQuadStripesSpacing(r0, l0, r, l, _settings.hashSpacing);
}
else
{
int stripeCnt = std::max((int)((len) / lw / 2), min_count);
int stripeCnt = std::max((int)count, min_count);
_cw.fillQuadStripes(r0, l0, r, l, stripeCnt);
}
}
Expand Down

0 comments on commit 027f889

Please sign in to comment.