Skip to content

Commit

Permalink
#2512 - Equilibrium Half Arrows are displayed incorrect when saved t…
Browse files Browse the repository at this point in the history
…o PNG (svg) by default size (#2537)
  • Loading branch information
AliaksandrDziarkach authored Oct 10, 2024
1 parent b2771ce commit 85ecc4c
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 2 deletions.
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 @@ -11,3 +11,5 @@ 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
issue 2512 two short equilibrium half arrows
issue_2512.png rendering status: OK
141 changes: 141 additions & 0 deletions api/tests/integration/tests/rendering/reactions/issue_2512.ket
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"root": {
"nodes": [
{
"$ref": "mol0"
},
{
"$ref": "mol1"
},
{
"type": "arrow",
"data": {
"mode": "unbalanced-equilibrium-filled-half-triangle",
"pos": [
{
"x": 13.700000000000001,
"y": -7.95,
"z": 0
},
{
"x": 14.700000000000001,
"y": -7.95,
"z": 0
}
]
}
}
],
"connections": [],
"templates": []
},
"mol0": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
12.549374214363931,
-8.432470415521406,
0
]
},
{
"label": "C",
"location": [
13.55062578563607,
-8.432470415521406,
0
]
},
{
"label": "C",
"location": [
13.050050188048687,
-7.567529584478595,
0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
0,
1
]
},
{
"type": 1,
"atoms": [
1,
2
]
},
{
"type": 1,
"atoms": [
2,
0
]
}
],
"stereoFlagPosition": {
"x": 13.55062578563607,
"y": 6.567529584478595,
"z": 0
}
},
"mol1": {
"type": "molecule",
"atoms": [
{
"label": "C",
"location": [
14.774374214363931,
-8.482470415521407,
0
]
},
{
"label": "C",
"location": [
15.77562578563607,
-8.482470415521407,
0
]
},
{
"label": "C",
"location": [
15.275050188048686,
-7.6175295844785955,
0
]
}
],
"bonds": [
{
"type": 1,
"atoms": [
0,
1
]
},
{
"type": 1,
"atoms": [
1,
2
]
},
{
"type": 1,
"atoms": [
2,
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.
12 changes: 12 additions & 0 deletions api/tests/integration/tests/rendering/render_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def renderRxnfile(filename, outfile):
renderer.renderToFile(rxn, joinPathPy("out/" + png_fname, __file__))
print(checkImageSimilarity(png_fname))

print("issue 2512 two short equilibrium half arrows")
indigo.resetOptions()
indigo.setOption("ignore-stereochemistry-errors", "true")
indigo.setOption("render-background-color", "255, 255, 255")
indigo.setOption("render-output-format", "png")
fname = "issue_2512"
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()
13 changes: 11 additions & 2 deletions core/render2d/src/render_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,11 +1337,20 @@ void RenderContext::drawEquillibriumHalf(const Vec2f& p1, const Vec2f& p2, const
n.negate();
pa.addScaled(n, headwidth);
pb.addScaled(n, headwidth);
const float default_shift = headsize * 2.0f;
float shift = default_shift;
if ((len - shift * 2.0f) < default_shift)
{
if (len < default_shift * 2.0f)
shift = len / 4.0f; // too short arrow - shift will be 1/4 of arrow length, short part - 1/2
else
shift = (len - default_shift) / 2.0f; // short part of arrow will be headsize*2
}
if (is_unbalanced)
pa.addScaled(d, headsize * 2);
pa.addScaled(d, shift);
d.negate();
if (is_unbalanced)
pb.addScaled(d, headsize * 2);
pb.addScaled(d, shift);
drawHalfArrowHeader(pa, d, width, headwidth * width_scale, headsize, arrow_type);
drawBar(pb, pa, width, margin);
checkPathNonEmpty();
Expand Down

0 comments on commit 85ecc4c

Please sign in to comment.