|
2026-10-23
| ||
| 10:55 | • Closed ticket [974600ff]: Gaps in Line sections plus 6 other changes artifact: 1d05c40d user: serhiy.storchaka | |
|
2021-12-05
| ||
| 08:18 | • Closed ticket [5fb81459]: Canvas redraw region too small when inserting points to a smoothed line plus 6 other changes artifact: dfdea72d user: fvogel | |
|
2021-12-04
| ||
| 19:26 | Fix [5fb8145997]: Canvas redraw region too small when inserting points to a smoothed line check-in: 1fe355fb user: jan.nijtmans tags: core-8-6-branch | |
| 16:42 | • Ticket [5fb81459] Canvas redraw region too small when inserting points to a smoothed line status still Open with 3 other changes artifact: 691878fa user: fvogel | |
|
2021-11-05
| ||
| 21:55 | • Ticket [5fb81459]: 3 changes artifact: fe5272ad user: fvogel | |
| 21:26 | • Ticket [5fb81459]: 3 changes artifact: f170214d user: fvogel | |
|
2021-10-17
| ||
| 21:04 | • Ticket [5fb81459]: 3 changes artifact: 89a72b43 user: fvogel | |
| 20:59 | Add (theoretically) missing line. See ticket [5fb8145997] for explanations about why this line is not needed in fact, but nevertheless included. check-in: 6f0bf10e user: fvogel tags: bug-5fb8145997 | |
|
2021-10-15
| ||
| 20:39 | • Ticket [5fb81459] Canvas redraw region too small when inserting points to a smoothed line status still Open with 3 other changes artifact: 4a7d13be user: fvogel | |
| 08:50 | • Ticket [5fb81459]: 4 changes artifact: 4d5f828d user: helium | |
|
2021-10-10
| ||
| 19:38 | • Ticket [5fb81459]: 3 changes artifact: 58c7e4de user: fvogel | |
| 18:35 | • Ticket [5fb81459]: 3 changes artifact: e691f60f user: fvogel | |
| 17:59 | • Ticket [5fb81459]: 4 changes artifact: 7309acb6 user: helium | |
| 15:42 | Let comments in the optimization code point at ticket [5fb8145997] since there is such a good explanation there about how optimization has to be done. check-in: c37ad166 user: fvogel tags: bug-5fb8145997 | |
| 15:06 | Let comments in the optimization code point at ticket [5fb8145997] since there is such a good explanation there about how optimization has to be done. check-in: b3ef2dcd user: fvogel tags: bug-5fb8145997 | |
| 14:49 | • Ticket [5fb81459] Canvas redraw region too small when inserting points to a smoothed line status still Open with 3 other changes artifact: 2281199d user: fvogel | |
| 08:56 | • Ticket [5fb81459]: 4 changes artifact: ae9b2f7c user: helium | |
| 08:50 | • Ticket [5fb81459]: 4 changes artifact: 32f9e5c6 user: helium | |
| 08:47 | • Add attachment canvas-line-testbed-arrowbug.png to ticket [5fb81459] artifact: 4c32cda0 user: helium | |
| 08:42 | • Add attachment canvas-line-testbed.tcl to ticket [5fb81459] artifact: 34b34123 user: helium | |
|
2021-10-09
| ||
| 18:39 | • Ticket [5fb81459] Canvas redraw region too small when inserting points to a smoothed line status still Open with 4 other changes artifact: f64bc260 user: helium | |
| 17:10 | • Add attachment analysis-cubic-spline.png to ticket [5fb81459] artifact: 7d67ba8c user: helium | |
| 17:09 | • Add attachment analysis-cubic-spline.tcl to ticket [5fb81459] artifact: 402f312f user: helium | |
| 14:11 | • Ticket [5fb81459] Canvas redraw region too small when inserting points to a smoothed line status still Open with 3 other changes artifact: ac209ebc user: fvogel | |
|
2021-10-02
| ||
| 17:41 | • Ticket [5fb81459]: 4 changes artifact: 6a44940e user: helium | |
| 17:26 | • Add attachment canvas-line-testbed.tcl to ticket [5fb81459] artifact: 3313bd2e user: helium | |
|
2021-09-29
| ||
| 03:53 | • Ticket [5fb81459] Canvas redraw region too small when inserting points to a smoothed line status still Open with 3 other changes artifact: 9d7d1a14 user: fvogel | |
|
2021-09-28
| ||
| 09:10 | • Ticket [5fb81459]: 3 changes artifact: 02e62d3e user: fvogel | |
|
2021-09-27
| ||
| 19:47 | • Ticket [5fb81459]: 3 changes artifact: 3cf62b4d user: fvogel | |
| 19:43 | Rework optimization code when inserting or deleting points of a canvas line. This now works for both -smooth no and -smooth true (bezier), as demonstrated by the test script 'canvas-line-testbed.tcl' posted in [5fb8145997]. Case -smooth raw still needs to be fixed. check-in: 2f80202c user: fvogel tags: bug-5fb8145997 | |
| 18:12 | • Ticket [5fb81459] Canvas redraw region too small when inserting points to a smoothed line status still Open with 3 other changes artifact: e5bc6b9c user: fvogel | |
|
2021-09-26
| ||
| 10:26 | • Ticket [5fb81459]: 4 changes artifact: 15cd8fd6 user: helium | |
| 10:21 | • Add attachment canvas-line-testbed.png to ticket [5fb81459] artifact: 331e44f2 user: helium | |
| 10:20 | • Add attachment canvas-line-testbed.tcl to ticket [5fb81459] artifact: bf5fbf39 user: helium | |
|
2021-09-25
| ||
| 19:08 | • Ticket [5fb81459] Canvas redraw region too small when inserting points to a smoothed line status still Open with 4 other changes artifact: e8c3bb11 user: helium | |
| 18:57 | • Add attachment analysis-quadratic-spline.png to ticket [5fb81459] artifact: 747fbf54 user: helium | |
| 18:56 | • Add attachment analysis-quadratic-spline.tcl to ticket [5fb81459] artifact: 8e4c8d2c user: helium | |
| 11:21 | • Ticket [5fb81459] Canvas redraw region too small when inserting points to a smoothed line status still Open with 3 other changes artifact: d79dc56e user: fvogel | |
| 09:55 | • Ticket [5fb81459]: 4 changes artifact: c4337e24 user: helium | |
|
2021-09-20
| ||
| 06:30 | • Ticket [5fb81459]: 3 changes artifact: a233ee88 user: fvogel | |
|
2021-09-19
| ||
| 20:21 | • Ticket [5fb81459]: 3 changes artifact: b369a150 user: fvogel | |
| 19:57 | • Ticket [5fb81459]: 4 changes artifact: 6234e973 user: fvogel | |
| 19:32 | Fix [5fb8145997]: Canvas redraw region too small when inserting points to a smoothed line check-in: 5da2de43 user: fvogel tags: bug-5fb8145997 | |
|
2021-09-16
| ||
| 12:49 | • Ticket [5fb81459] Canvas redraw region too small when inserting points to a smoothed line status still Open with 4 other changes artifact: c1507d4e user: helium | |
|
2021-09-15
| ||
| 19:40 | • Ticket [5fb81459]: 3 changes artifact: e32dd9b2 user: fvogel | |
| 07:45 | • Ticket [5fb81459]: 5 changes artifact: 87d014cb user: helium | |
|
2021-09-14
| ||
| 19:21 | • Ticket [5fb81459]: 3 changes artifact: be149de0 user: helium | |
| 19:19 | • Add attachment bugreport-splines-explained-example.png to ticket [5fb81459] artifact: d628cdef user: helium | |
| 19:17 | • New ticket [5fb81459] Canvas redraw region too small when inserting points to a smoothed line. artifact: be5d695d user: helium | |
| Ticket UUID: | 5fb81459976c4f14c09fc18268ab4fa7a2b17316 | |||||||||||||||||||||||||||||||||||
| Title: | Canvas redraw region too small when inserting points to a smoothed line | |||||||||||||||||||||||||||||||||||
| Type: | Bug | Version: | 8.6.10 | |||||||||||||||||||||||||||||||||
| Submitter: | helium | Created on: | 2021-09-14 19:17:49 | |||||||||||||||||||||||||||||||||
| Subsystem: | 05. Canvas Items | Assigned To: | fvogel | |||||||||||||||||||||||||||||||||
| Priority: | 5 Medium | Severity: | Minor | |||||||||||||||||||||||||||||||||
| Status: | Closed | Last Modified: | 2021-12-05 08:18:29 | |||||||||||||||||||||||||||||||||
| Resolution: | Fixed | Closed By: | fvogel | |||||||||||||||||||||||||||||||||
| Closed on: | 2021-12-05 08:18:29 | |||||||||||||||||||||||||||||||||||
| Description: |
While developing a vector drawing program, I discovered that the Tk canvas does not correctly redraw a smoothed line item when coordinate pairs are added at the end of its coordinate list. Steps to reproduce: pack [canvas .canvas -width 500 -height 250]
.canvas create line 40 200 160 40 280 200 -smooth true -tag myLine
.canvas insert myLine end {400 40}
.canvas move myLine 0 0
The last step refreshes the entire line object, removing the discontinuity observed after the prior step. The following script (screenshot attached from Linux/X11) shows these steps in an animation:
#!/usr/bin/wish
# Bug observed with Tk versions 8.5.19 and 8.6.8
wm resizable . 0 0
pack [canvas .c -width 500 -height 250]
pack [label .l]
proc mark_point {x y} {
.c create oval [expr {$x-2}] [expr {$y-2}] [expr {$x+2}] [expr {$y+2}]
}
proc exec_and_show {args} {
{*}$args
.l configure -text $args
}
mark_point 40 200
mark_point 160 40
mark_point 280 200
# Both kinds of smoothing are affected, here we use "true" since it
# needs less points than "raw" for a demonstration.
exec_and_show .c create line 40 200 160 40 280 200 -smooth true -tag myLine
update
after 5000
mark_point 400 40
exec_and_show .c insert myLine end {400 40}
update
after 2000
exec_and_show .c move myLine 0 0
Note that if I use a text on the canvas itself for displaying the commands at each step, the redraw region gets bigger and the bug does not appear:
#!/usr/bin/wish
wm resizable . 0 0
pack [canvas .c -width 500 -height 250]
proc mark_point {x y} {
.c create oval [expr {$x-2}] [expr {$y-2}] [expr {$x+2}] [expr {$y+2}]
}
.c create text 250 240 -anchor center -tag text
proc exec_and_show {args} {
{*}$args
.c itemconfigure text -text $args
}
mark_point 40 200
mark_point 160 40
mark_point 280 200
exec_and_show .c create line 40 200 160 40 280 200 -smooth true -tag myLine
update
after 5000
mark_point 400 40
exec_and_show .c insert myLine end {400 40}
update
after 2000
exec_and_show .c move myLine 0 0
| |||||||||||||||||||||||||||||||||||
| User Comments: |
fvogel added on 2021-12-05 08:18:29:
Jan did the merge for me, many thanks to him. Closing this ticket now, with great thanks to the OP for his detailed analysis and help. fvogel added on 2021-12-04 16:42:13: I have tried merging the bugfix branch into core-8-6-branch and main. When merging into main there are conflicts due to the change int-->TkSizeT for some variables. I have asked Jan's help regarding this merge. fvogel added on 2021-11-05 21:55:14: [cc743eb9db] implements a better fix for this last issue. This deals with the real problem that in the last bug case, we insert at position 0, therefore when dealing with -smooth raw beforeThis is negative (value is -2) and the % (reminder) operator returns a negative result for (beforeThis % 6), which means beforeThis becomes 0 while we want beforeThis to become -4. Adding abs() solves this issue. fvogel added on 2021-11-05 21:26:48: With [cadf5106] I believe I have fixed the last known issue with the optimization code. That was when inserting points at position zero in a polygon. The problem could for instance be seen from your applicatiopn testbed with: original 145 132 124 116 129 85 160 68 205 58 283 111 additional 226 136 205 146 176 140 index 0; splinetype raw; operation insdel; type polygon or, equivalently, directly in Tcl/Tk with:
pack req Tk
pack [canvas .c -width 500 -height 315]
.c create polygon 145 132 124 116 129 85 160 68 205 58 283 111 -tag myLine -width 4 -smooth raw -fill {} -outline black
# wait for display update then paste next line
.c insert myLine 0 {226 136 205 146 176 140}
I can't trigger any issue any longer, with either line items or polygon items, for any smoothing method. If you can review this latest state I would be happy to read your comments. Thanks! fvogel added on 2021-10-17 21:04:48:
I have understood why this change (the added " The case happens when inserting at the last position of the line. Initially, Then, one adds one point at each side of the insert position, and (since Now, since we're inserting at the last position, we add a third point at the left and Later, at lines 1094-1096, To conclude, the added " That now said, I have added this extra line even if useless, because it is indeed correct in principle and it helps understanding the code. This is [6f0bf10ed3]. fvogel added on 2021-10-15 20:39:46: This should be right indeed. I'm puzzled by the fact we cannot evidence this bug by running your test tool. That's rather strange and inconsistent. helium added on 2021-10-15 08:50:00: In the meantime I managed to compile [0733eac0] and tested it. From reading the code, I noticed there is still a mistake, although I could not expose it in the testbed:
1060 if (beforeThis + 4 == length - (objc - 8)) {
1061 beforeThis -= 2;
1061+ objc += 2;
1062 }
I think that fvogel added on 2021-10-10 19:38:33: With [57d9378418] I have now implemented all your suggestions for the "raw" smoothing method (well, at least I think!). Moreover, optimization aborts when the number of points in the line or polygon is not 3n+1 or 3n respectively, or when the number of inserted/deleted points is not a multiple of 3. Finally, no optimization is attempted for custom smoothing methods. This code seems to work correctly for line items, both when inserting and deleting points. For polygon items at least, this needs debug. Indeed the following is still a wrong redraw case for instance: original 1239 403 1155 143 1276 505 1184 486 65 63 511 15 additional 1158 544 889 478 896 370 index 0; splinetype raw; operation insdel; type polygon Finally, please note that points deletion for polygons has no optimization implemented in PolygonDeleteCoords() - and never had, no idea why - for any smoothing method. fvogel added on 2021-10-10 18:35:28: Yes, I see. I have committed the changes you propose, see [ef0458d4fd]. Your test script with both arrows still refreshes fine with this change. Thanks! helium added on 2021-10-10 17:59:46: Regarding Check-in [586fde88]:
1076 - if ((linePtr->lastArrowPtr != NULL) && (beforeThis+objc >= length)) {
1076 + if ((linePtr->lastArrowPtr != NULL) && (beforeThis+objc >= length - 2)) {
I think this is not necessary, as In consequence, the very similar line 1118 could also be changed to: Note that the expressions in Finally, to help testing the above-mentioned points, I found an example that showcases the arrow redrawing bug in Tk 8.6.8 with non-smoothed lines for both arrows at the same time: original 53 54 445 267 additional 53 188 445 152 index 1; splinetype no; operation insdel; type line; arrows both fvogel added on 2021-10-10 14:49:10: Thank you for your detailed review! > Line 1086, in LineInsert: > coordPtr = linePtr->coordPtr + beforeThis + 2; > I don't understand the "+ 2" here, which appears to always exclude the > first inserted point. This is code I didn't touch. I think it was here because the arrow is supposed to always include the first point of the line in it's bounding box: the point starting the line is located "inside" the arrow. This adjustment is made in ConfigureArrows(), see lines 2228-2234 and 2271-2272 in tkCanvLine.c But this code would only be correct if beforeThis was zero. I have removed this +2 (and adjusted the loop that follows), I think you are right.
> Line 1108, in LineInsert:
> if ((linePtr->firstArrowPtr != NULL) && (beforeThis > 2)) {
> I would say it should read "< 2", so the new first arrow is included
> when the first point does belong to the "set of interest".
> See "if ((linePtr->firstArrowPtr != NULL) && (first1 < 4)) {" in
> LineDelete (line 1311), but why is there a 4 instead of a 2? I would say
> that first1 has already been decremented?
>
> Line 1118, in LineInsert:
> if ((linePtr->lastArrowPtr != NULL) && (beforeThis+objc < length-2)) {
> Same here, should be a ">= length-2".
> See "if ((linePtr->lastArrowPtr != NULL) && (last1 > length-4)) {" in
> LineDelete (line 1321), same story about the 4 instead of 2.
This is also code I didn't touch. What you say all seems correct to me, therefore I have made these changes. > Furthermore, it appears from experiments that beforeThis is always an > even number in the LineInsert procedure. But where is the code > responsible for that? It is made even in GetLineIndex(), see line 1835 in tkCanvLine.c Having beforeThis odd does not make sense because inserted values would lie between x and y of an existing point. We have the same kind of code in LineDeleteCoords() lines 1187 and 1188, so that deletion does not delete "part of a point". > There is also a comment glitch: Line 1218, in LineDeleteCoords Correct (fixed). > For the arrow handling, I came up with a particular test case that > confirms there is a bug even for non-smoothed lines. With the above changes, i.e. at [586fde882a], this bug does no longer trigger. Great! Now I will look at the "raw" and "custom" cases, based on your detailed and ultra-clear analysis (thanks!). helium added on 2021-10-10 08:56:26:
Just a small remark: There is also the possibility of custom (plug-in?) smoothing methods other than "0", "true", and "raw". We should always redraw the whole line/polygon item in case we encounter such a smoothing method. (In the present code, it executes the "optimizations" for helium added on 2021-10-10 08:50:13: I'm afraid there are still some inconsistencies in tkCanvLine.c: Line 1086, in LineInsert: Line 1108, in LineInsert: Line 1118, in LineInsert: Furthermore, it appears from experiments that There is also a comment glitch: Line 1218, in LineDeleteCoords: For the arrow handling, I came up with a particular test case that confirms there is a bug even for non-smoothed lines. (See the attachment canvas-line-testbed-arrowbug.png) Enter this in the "Test Data" field of canvas-line-testbed.tcl: original 383 78 445 267 179 177 additional 181 224 index 2; splinetype no; operation insdel; type line; arrows both Alternatively, you can trigger the bug by entering the following minimal code line-for-line into a wish shell:
pack [canvas .c -width 500 -height 339]
.c create line 383 78 445 267 179 177 -tag myLine -width 4 -smooth no -arrow both -arrowshape {20 30 10}
.c insert myLine 4 {181 224}
While generating this code with canvas-line-testbed.tcl, I found that the braces around the numbers for helium added on 2021-10-09 18:39:54:
I just uploaded my own analysis of the I already found some "ready-to-use" formulas for calculating the points affected by such an insert/delete operation. They are not as difficult as you imagined... How I found the formulas: I defined an abstract notation for segments, since comparing actual curves was not needed anymore. Each segment is written in braces containing its point numbers, e.g.: {0 1 2 3} {3 4 5 6}. Points that are inserted/deleted are written in bold. Segments that need redrawing are underlined. The variable "first" denotes the first point being inserted/deleted, and the variable "last" denotes the last point, "n" and "m" are arbitrary integers.
Summarizing the expressions into tables:
Now in the real code we have coordinate arrays, such that point 0 occupies indices 0 and 1, point 1 occupies indices 2 and 3, etc. Additionally, the insertion and deletion procedures have a slightly different formulation of variables:
For the first point to be included for redraw, we get the formula:
beforeThis | 0 (1) | 2 (3) 4 (5) 6 (7) | 8 (9) 10 (11) 12 (13) | 14 (15) 16 (17) 18 (19) | 20 ...
out | 0 (0) | 0 (0) 0 (0) 0 (0) | 6 (6) 6 (6) 6 (6) | 12 (12) 12 (12) 12 (12) | 18 ...
For the number of points to be included for redraw, we see in the example cases that always four additional points are underlined besides those in bold. Therefore the formula is as simple as
For the last point to be included for redraw, we get: last | 0 (1) 2 (3) 4 (5) | 6 (7) 8 (9) 10 (11) | 12 (13) 14 (15) 16 (17) | 18 ... last1 | 6 (6) 6 (6) 6 (6) | 12 (12) 12 (12) 12 (12) | 18 (18) 18 (18) 18 (18) | 24 ... If the corrections for plain line/polygon items with For For I would recommend you to integrate these rather easy formulas into the code, but I would also say that we should do a full redraw in any case involving a "degenerate" line (not 3n+1 points) or polygon (not 3n points). There would still be some optimization potential, such as not including the points that precede the insertion/deletion location when something else than a multiple of 3 points is inserted/deleted. But I doubt that these "degenerate" cases are useful for anyone. I don't know if really nobody has detected the bug before me, since it is so easy to work around it with a fvogel added on 2021-10-09 14:11:58: Thanks a lot for this test application, it is very very helpful! With [b541b73a] I have fixed the last (I hope) bug for Also, I have taken your remark into account regarding comments. Now the helium added on 2021-10-02 17:41:05:
I just uploaded a version of the test script which allows switching between lines and polygons and has a Modify mode (in addition to the previous Insert/Delete) for testing the Additionally I went through your code, i.e. the whole fvogel added on 2021-09-29 03:53:37:
I have modified the test script to deal with polygons instead of lines (easy: only the threee [canvas create] lines need to be changed). Results: with the current state of he bugfix branch I couldn't trigger an issue with either fvogel added on 2021-09-28 09:10:43: It just occurred to me that we probably have the same problem with polygons, not just lines. The optimization code is there as well. Can the test tool easily be upgraded to deal with both polygons or lines? fvogel added on 2021-09-27 19:47:23:
I have reworked my fix, see [2f80202c43]. This now works for both Case fvogel added on 2021-09-27 18:12:44: This test program is very useful, it exceeds any expectations (read: dreams!) I had. Many thanks, it will be very useful! I had only a cursive look so far at what it allows, but I will definitely spend more time on it. Did I say "thank you" already? Thank you !! helium added on 2021-09-26 10:26:17: Now I attached a demo testbed application that exposes the point insertion/deletion bug through an animation (insert - redraw - delete - redraw), while all control points can be moved by using the mouse. The pre-configured case, also seen in the screenshot, is particularly nasty, as here the second point of a curve is affected (not the first or last as discussed before). I hope that this program is useful, as it took me some 3:30 hours to develop :) helium added on 2021-09-25 19:08:12: I just finished translating my pen-and-paper analysis of the redraw situation for "-smooth true" quadratic bézier splines into a Tk script that draws the analysis on a static canvas. A screenshot rendering is also attached. From a high-level perspective (I still have not studied the code in-depth, maybe it does already what I describe here), the routines for inserting, deleting, and moving points should perform the following: Insertion of point i -------------------- * Insert point at index i into the points list * Take points i-2, i-1, i, i+1, i+2 into the bounding box * If i==0: Take point i+3 (=3) into the bounding box * If i==length-1: Take point i-3 into the bounding box Deletion of point i ------------------- * BBox &= i-2, i-1, i, i+1, i+2 * If i==0: BBox &= i+3 * If i==N-1: BBox &= i-3 * Delete point at index i from the points list Movement of point i ------------------- * BBox &= i-2, i-1, i, i+1, i+2 * Edit point at index i in the points list * BBox &= i (new point) These procedures operate on a single point but should be easily generalized for operating on a list of adjacent points. fvogel added on 2021-09-25 11:21:03: Thanks for your feedback. Your analysis matches mine regarding the -smooth true case. If you look at my fix you will see this. Regarding the -smooth raw case, I didn't analyze it so far but you're certainly right. The optimization code currently does not distinguish between beziers (true) and raw modes, which probably means we have problems with -smooth raw. I didn't try this case so far, if you could narrow down what the issues are with raw mode that would certainly help. helium added on 2021-09-25 09:55:03:
This weekend I'll take some time to compile and test your new code and maybe produce a kind of test-bed application. I found that my vector drawing demo (work in progress, temporary link) is not suitable for extensive testing as its points-manipulation tool draws little markers at the control points of selected lines, so the canvas always redraws the full curve together with the markers. In the meantime, I did my own analysis of what parts of a Anyway, when considering the package require Tk
pack [canvas .canvas -width 500 -height 350]
set coords [list 63 248 96 166 218 329 307 299 402 295 410 80 335 147 275 192 220 101 293 37]
.canvas create line $coords -smooth raw -width 3 -fill #0f0
.canvas create line $coords -smooth raw -tag myLine
update; after 2000
.canvas insert myLine 4 {157 247.5}
update; after 2000
.canvas move myLine 0 0
How should we proceed in this case? A lazy solution would be to always redraw the whole line if fvogel added on 2021-09-20 06:30:00: We have the same problem when deleting points from a canvas line, as demonstrated by: package require Tk pack [canvas .canvas -width 500 -height 250] .canvas create line 40 200 160 40 280 200 400 40 -smooth true -tag myLine .canvas dchars myLine 7 See the fix [71ccd957ba] in branch bug-5fb8145997. Needs testing as well. fvogel added on 2021-09-19 20:21:37: Oh, one last thing: only *smoothed* lines need to be tested. fvogel added on 2021-09-19 19:57:59: Analysis of the issue: When inserting a new point in a canvas line, the optimization code I have pointed out earlier selects what part of the canvas (what bounding box) needs to be redrawn. This is based on the fact smoothed canvas lines are implemented as a set of splines, each of them using three points of the line. The optimization code avoids redrawing of the whole canvas when inserting a line point by computing a minimal redraw box. This box is the smallest rectangle that includes two points before the inserted point and two points following the inserted point. This should be enough because only the splines neighbouring the inserted points need to be redrawn. And this is the case except when the inserted point is too close from one of the line ends. Indeed, TkMakeBezierCurve() computes different spline control points at the lines ends than for other areas of the line. Therefore, when the inserted point is close to one of the line ends, the first (or last) spline must be redrawn in addition to what the optimization code already was including in it's redraw box. I have implemented this change in [5da2de43e8] and it fixes the problem for me. And now here is what you can do to help: please test this extensively. Your vector drawing program should be a good way to confirm it works. Please try many many cases, both simple (3 points in the line, insert a 4th point at each possible position) and more complex (many points in the line, insert at different positions both close to and far from each line end). Look for any regressions as well. And report your findings here. Thanks! helium added on 2021-09-16 12:49:32:
Many thanks for looking at this issue! I also read through tkCanvLine.c and its "optimization code" - I still have not taken enough time to fully understand it. Anyway, I reproduced the bug on Windows 10 (Tk 8.6.9 installed via Git for Windows 2.20.1), which is no wonder since it comes from platform-independent code. fvogel added on 2021-09-15 19:40:28: The culprit is the optimization code here. The bounding box of what needs to be redrawn upon item insertion does not seem to be correct. helium added on 2021-09-15 07:45:56: I also confirmed the bug on Tk 8.6.10 (Linux/X11). | |||||||||||||||||||||||||||||||||||
Attachments:
- canvas-line-testbed-arrowbug.png [download] added by helium on 2021-10-10 08:47:00. [details]
- canvas-line-testbed.tcl [download] added by helium on 2021-10-10 08:42:11. [details]
- analysis-cubic-spline.png [download] added by helium on 2021-10-09 17:10:58. [details]
- analysis-cubic-spline.tcl [download] added by helium on 2021-10-09 17:09:57. [details]
- canvas-line-testbed.png [download] added by helium on 2021-09-26 10:21:38. [details]
- analysis-quadratic-spline.png [download] added by helium on 2021-09-25 18:57:35. [details]
- analysis-quadratic-spline.tcl [download] added by helium on 2021-09-25 18:56:04. [details]
- bugreport-splines-explained-example.png [download] added by helium on 2021-09-14 19:19:17. [details]
