Skip to content

Commit

Permalink
#2444 - Preview: the thickness of the arrow is incorrect when saving…
Browse files Browse the repository at this point in the history
… to png(svg)

Add code to set arrow and plus width same as bond. Add UT.
  • Loading branch information
AliaksandrDziarkach committed Oct 3, 2024
1 parent 9a5332e commit 2e3af98
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/tests/integration/ref/rendering/render_reactions.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ epoxy.png rendering status: OK
Done
issue 2457 wrong chiral label position
issue_2457.png rendering status: OK
issue 2444 wrong arrow and plus width
issue_2444.png rendering status: OK
196 changes: 196 additions & 0 deletions api/tests/integration/tests/rendering/reactions/issue_2444.ket
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
{
"root": {
"nodes": [
{
"$ref": "mol0"
},
{
"$ref": "mol1"
},
{
"$ref": "mol2"
},
{
"$ref": "mol3"
},
{
"type": "arrow",
"data": {
"mode": "equilibrium-filled-half-bow",
"pos": [
{
"x": 21.700001256913012,
"y": -10.68125,
"z": 0
},
{
"x": 23.700000753998914,
"y": -10.68125,
"z": 0
}
]
}
},
{
"type": "plus",
"location": [
18.45000140359629,
-10.68125,
0
],
"prop": {}
},
{
"type": "plus",
"location": [
26.94999941522297,
-10.68125,
0
],
"prop": {}
}
],
"connections": [],
"templates": []
},
"mol0": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
16.200001485086997,
-10.68125,
0
]
},
{
"label": "C",
"location": [
17.20000134538864,
-10.68125,
0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
0,
1
]
}
],
"stereoFlagPosition": {
"x": 17.20000134538864,
"y": 9.68125,
"z": 0
}
},
"mol1": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
19.70000116378077,
-10.68125,
0
]
},
{
"label": "C",
"location": [
20.70000121034689,
-10.68125,
0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
0,
1
]
}
],
"stereoFlagPosition": {
"x": 20.70000121034689,
"y": 9.68125,
"z": 0
}
},
"mol2": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
24.700000800565036,
-10.68125,
0
]
},
{
"label": "C",
"location": [
25.700000847131154,
-10.68125,
0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
0,
1
]
}
],
"stereoFlagPosition": {
"x": 25.700000847131154,
"y": 9.68125,
"z": 0
}
},
"mol3": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
28.199997983314788,
-10.68125,
0
]
},
{
"label": "C",
"location": [
29.19999802988091,
-10.68125,
0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
0,
1
]
}
],
"stereoFlagPosition": {
"x": 29.19999802988091,
"y": 9.68125,
"z": 0
}
}
}
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.
13 changes: 13 additions & 0 deletions api/tests/integration/tests/rendering/render_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ def renderRxnfile(filename, outfile):
renderer.renderToFile(rxn, joinPathPy("out/" + png_fname, __file__))
print(checkImageSimilarity(png_fname))

print("issue 2444 wrong arrow and plus width")
indigo.resetOptions()
indigo.setOption("ignore-stereochemistry-errors", "true")
indigo.setOption("render-background-color", "255, 255, 255")
indigo.setOption("render-output-format", "png")
indigo.setOption("render-bond-thickness", "10")
fname = "issue_2444"
png_fname = fname + ".png"
ket_fname = joinPathPy("reactions/%s.ket" % fname, __file__)
rxn = indigo.loadReactionFromFile(ket_fname)
renderer.renderToFile(rxn, joinPathPy("out/" + png_fname, __file__))
print(checkImageSimilarity(png_fname))

if isIronPython():
renderer.Dispose()
indigo.Dispose()
6 changes: 5 additions & 1 deletion core/render2d/src/render_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ void RenderSettings::init(float relativeThickness, float bondLineWidthFactor, Ac
bondLineWidth = bondLineWidthFactor * unit;
bondSpace = 2.5f * unit;
stereoBondSpace = bondSpace;
hashSpacing = -1;

float label_font_size = unit * 12;
if (acs != nullptr)
Expand Down Expand Up @@ -377,7 +378,10 @@ void RenderSettings::init(float relativeThickness, float bondLineWidthFactor, Ac
layoutMarginHorizontal = 0.4f;
layoutMarginVertical = 0.6f;
plusSize = 0.5;
metaLineWidth = 1.0 / 16;
if (acs != nullptr && acs->bondThicknessAngstrom > 0)
metaLineWidth = bondLineWidth; // new behavior: plus and arrow width same as bond width
else
metaLineWidth = 1.0 / 16;
arrowLength = 3 * plusSize;
arrowHeadWidth = plusSize / 2;
arrowHeadSize = plusSize / 2;
Expand Down

0 comments on commit 2e3af98

Please sign in to comment.