diff --git a/api/tests/integration/ref/rendering/acs_style.py.out b/api/tests/integration/ref/rendering/acs_style.py.out index dd300aca25..185ea4d51a 100644 --- a/api/tests/integration/ref/rendering/acs_style.py.out +++ b/api/tests/integration/ref/rendering/acs_style.py.out @@ -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 diff --git a/api/tests/integration/tests/rendering/acs_style.py b/api/tests/integration/tests/rendering/acs_style.py index b01501a4e9..656e04e0c3 100644 --- a/api/tests/integration/tests/rendering/acs_style.py +++ b/api/tests/integration/tests/rendering/acs_style.py @@ -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() diff --git a/api/tests/integration/tests/rendering/molecules/issue_2447.ket b/api/tests/integration/tests/rendering/molecules/issue_2447.ket new file mode 100644 index 0000000000..b2bcbde01e --- /dev/null +++ b/api/tests/integration/tests/rendering/molecules/issue_2447.ket @@ -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 + } + ] + } +} \ No newline at end of file diff --git a/api/tests/integration/tests/rendering/ref/linux/issue_2447.png b/api/tests/integration/tests/rendering/ref/linux/issue_2447.png new file mode 100644 index 0000000000..5f39c5de1d Binary files /dev/null and b/api/tests/integration/tests/rendering/ref/linux/issue_2447.png differ diff --git a/api/tests/integration/tests/rendering/ref/mac/issue_2447.png b/api/tests/integration/tests/rendering/ref/mac/issue_2447.png new file mode 100644 index 0000000000..5f39c5de1d Binary files /dev/null and b/api/tests/integration/tests/rendering/ref/mac/issue_2447.png differ diff --git a/api/tests/integration/tests/rendering/ref/win/issue_2447.png b/api/tests/integration/tests/rendering/ref/win/issue_2447.png new file mode 100644 index 0000000000..5f39c5de1d Binary files /dev/null and b/api/tests/integration/tests/rendering/ref/win/issue_2447.png differ diff --git a/core/render2d/render_common.h b/core/render2d/render_common.h index 37883f66c9..7f061df6ee 100644 --- a/core/render2d/render_common.h +++ b/core/render2d/render_common.h @@ -443,7 +443,7 @@ namespace indigo float graphItemSignLineWidth; float graphItemPlusEdge; float stereoBondSpace; - float hashSpacing; + float hashSpacing = -1; float fzz[FONT_SIZE_COUNT]; diff --git a/core/render2d/src/render_common.cpp b/core/render2d/src/render_common.cpp index d87beeadf8..e2b315b91c 100644 --- a/core/render2d/src/render_common.cpp +++ b/core/render2d/src/render_common.cpp @@ -310,7 +310,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; diff --git a/core/render2d/src/render_context.cpp b/core/render2d/src/render_context.cpp index 89652247b2..fac7dc2613 100644 --- a/core/render2d/src/render_context.cpp +++ b/core/render2d/src/render_context.cpp @@ -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); diff --git a/core/render2d/src/render_internal.cpp b/core/render2d/src/render_internal.cpp index b1ff4b3352..878c850400 100644 --- a/core/render2d/src/render_internal.cpp +++ b/core/render2d/src/render_internal.cpp @@ -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); } }