Tk Source Code

Check-in [a038b01f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Corrected dchars method for polygon
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | pspjuth-canvas
Files: files | file ages | folders
SHA1: a038b01f0df219475d4b94e372df0270e493aa80
User & Date: pspjuth 2011-04-25 00:28:16
Context
2012-08-26
17:07
merge trunk Leaf check-in: eddc3ffd user: pspjuth tags: pspjuth-canvas
2011-04-25
00:28
Corrected dchars method for polygon check-in: a038b01f user: pspjuth tags: pspjuth-canvas
2011-04-24
23:27
Corrected index method for polygon check-in: 51fe9467 user: pspjuth tags: pspjuth-canvas
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tkCanvPoly.c.

1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
	    || !objc || objc&1) {
	return;
    }
    length = 2*(polyPtr->numPoints - polyPtr->autoClosed);
    if (length == 0) {
	beforeThis = 0;
    }
    while (beforeThis > length) {
	beforeThis -= length;
    }
    while (beforeThis < 0) {
	beforeThis += length;
    }
    newCoordPtr = ckalloc(sizeof(double) * (length + 2 + objc));
    for (i=0; i<beforeThis; i++) {
	newCoordPtr[i] = polyPtr->coordPtr[i];
    }
    for (i=0; i<objc; i++) {
	if (Tcl_GetDoubleFromObj(NULL, objv[i],







|
|

|
|







1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
	    || !objc || objc&1) {
	return;
    }
    length = 2*(polyPtr->numPoints - polyPtr->autoClosed);
    if (length == 0) {
	beforeThis = 0;
    }
    if (beforeThis > length) {
	beforeThis = length;
    }
    if (beforeThis < 0) {
	beforeThis = 0;
    }
    newCoordPtr = ckalloc(sizeof(double) * (length + 2 + objc));
    for (i=0; i<beforeThis; i++) {
	newCoordPtr[i] = polyPtr->coordPtr[i];
    }
    for (i=0; i<objc; i++) {
	if (Tcl_GetDoubleFromObj(NULL, objv[i],
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
    int count, i;
    int length = 2*(polyPtr->numPoints - polyPtr->autoClosed);

    if (length == 0) {
	first = 0;
	last = 0;
    } else {
	while (first >= length) {
	    first -= length;
	}
	while (first < 0) {
	    first += length;
	}
	while (last >= length) {
	    last -= length;
	}
	while (last < 0) {
	    last += length;
	}
    }

    first &= -2;
    last &= -2;

    count = last + 2 - first;







|
|

|
|

|
|

|
|







1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
    int count, i;
    int length = 2*(polyPtr->numPoints - polyPtr->autoClosed);

    if (length == 0) {
	first = 0;
	last = 0;
    } else {
	if (first >= length) {
	    first = length - 2;
	}
	if (first < 0) {
	    first = 0;
	}
	if (last >= length) {
	    last = length - 2;
	}
	if (last < 0) {
	    last = 0;
	}
    }

    first &= -2;
    last &= -2;

    count = last + 2 - first;
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
    }

    if (last >= first) {
	for (i=last+2; i<length; i++) {
	    polyPtr->coordPtr[i-count] = polyPtr->coordPtr[i];
	}
    } else {
	for (i=last; i<=first; i++) {
	    polyPtr->coordPtr[i-last] = polyPtr->coordPtr[i];
	}
    }
    polyPtr->coordPtr[length-count] = polyPtr->coordPtr[0];
    polyPtr->coordPtr[length-count+1] = polyPtr->coordPtr[1];
    polyPtr->numPoints -= count/2;
    ComputePolygonBbox(canvas, polyPtr);
}







|
|







1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
    }

    if (last >= first) {
	for (i=last+2; i<length; i++) {
	    polyPtr->coordPtr[i-count] = polyPtr->coordPtr[i];
	}
    } else {
	for (i=last+2; i<=first; i++) {
	    polyPtr->coordPtr[i-last-2] = polyPtr->coordPtr[i];
	}
    }
    polyPtr->coordPtr[length-count] = polyPtr->coordPtr[0];
    polyPtr->coordPtr[length-count+1] = polyPtr->coordPtr[1];
    polyPtr->numPoints -= count/2;
    ComputePolygonBbox(canvas, polyPtr);
}

Changes to tests/canvas.test.

529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
test canvas-11.3 {canvas poly dchars, bug 3291543} {
    # This would crash
    destroy .c
    pack [canvas .c]
    .c create polygon 0 0 0 10 10 0
    .c dchars 1 2 end
    .c coords 1
} {}

test canvas-12.1 {canvas mm obj, patch SF-403327, 102471} -setup {
    destroy .c
    pack [canvas .c]
} -body {
    set qx [expr {1.+1.}] 
    # qx has type double and no string representation 







|







529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
test canvas-11.3 {canvas poly dchars, bug 3291543} {
    # This would crash
    destroy .c
    pack [canvas .c]
    .c create polygon 0 0 0 10 10 0
    .c dchars 1 2 end
    .c coords 1
} {0.0 0.0}

test canvas-12.1 {canvas mm obj, patch SF-403327, 102471} -setup {
    destroy .c
    pack [canvas .c]
} -body {
    set qx [expr {1.+1.}] 
    # qx has type double and no string representation 
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
    canvas .c
} -body {
    set id [.c create polygon 0 0 1 1 2 2 3 3]
    .c imove $id end 4 4
    .c coords $id
} -cleanup {
    destroy .c
    # PS: Most definitely a bug. Caused by end!=last
    # Also affected by the inconsistenecy between insert and delete in polygon
    # imove should be changed to interpret anything > last
    # as last, to give "end" a reasonable meaning.
} -result {1.0 1.0 4.0 4.0 2.0 2.0 3.0 3.0}
test canvas-18.9 {imove method - errors} -setup {
    canvas .c
} -body {
    set id [.c create line 0 0 1 1 2 2 3 3]
    .c imove $id foobar 4 4
} -cleanup {
    destroy .c







<
<
<
<
|







824
825
826
827
828
829
830




831
832
833
834
835
836
837
838
    canvas .c
} -body {
    set id [.c create polygon 0 0 1 1 2 2 3 3]
    .c imove $id end 4 4
    .c coords $id
} -cleanup {
    destroy .c




} -result {0.0 0.0 1.0 1.0 2.0 2.0 4.0 4.0}
test canvas-18.9 {imove method - errors} -setup {
    canvas .c
} -body {
    set id [.c create line 0 0 1 1 2 2 3 3]
    .c imove $id foobar 4 4
} -cleanup {
    destroy .c
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5 6 7]
    .c rchars $id 2 end {10 11 12 13 14 15}
    .c coords $id
} -cleanup {
    destroy .c
    # PS: Since "dchars 2 end" deletes all, 0.0 1.0 is missing
} -result {10.0 11.0 12.0 13.0 14.0 15.0}
test canvas-19.7 {rchars method - text} -setup {
    canvas .c
} -body {
    set id [.c create text 0 0 -text abcde]
    .c rchars $id 1 3 XYZ
    .c itemcget $id -text
} -cleanup {







<
|







921
922
923
924
925
926
927

928
929
930
931
932
933
934
935
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5 6 7]
    .c rchars $id 2 end {10 11 12 13 14 15}
    .c coords $id
} -cleanup {
    destroy .c

} -result {0.0 1.0 10.0 11.0 12.0 13.0 14.0 15.0}
test canvas-19.7 {rchars method - text} -setup {
    canvas .c
} -body {
    set id [.c create text 0 0 -text abcde]
    .c rchars $id 1 3 XYZ
    .c itemcget $id -text
} -cleanup {
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    .c dchars $id 2 6
    .c coords $id
} -cleanup {
    destroy .c
    # PS: This should keep 0 1, dchars wrapping semantics removes all
} -result {}

test canvas-22.10 {dchars method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    .c dchars $id 4 end
    .c coords $id
} -cleanup {
    destroy .c
    # PS: This should also keep 2 3, dchars wrapping semantics disturbs
} -result {0.0 1.0}

test canvas-22.11 {dchars method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    .c dchars $id end end
    .c coords $id
} -cleanup {
    destroy .c
    # PS: Wrapping causes "end" to point at beginning.
} -result {2.0 3.0 4.0 5.0}

test canvas-22.12 {dchars method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5 6 7 8 9]
    .c dchars $id 8 4
    .c coords $id
} -cleanup {
    destroy .c
    # PS: WTF? Even if this is considered to be wrapping past
    # end, 6.0 7.0 should be the result
} -result {4.0 5.0}

test canvas-22.13 {dchars method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5 6 7 8 9 10 11]
    .c dchars $id 8 2
    .c coords $id
} -cleanup {
    destroy .c
    # PS: WTF? Even if this is considered to be wrapping past
    # end, 4.0 5.0 6.0 7.0 should be the result
} -result {2.0 3.0 4.0 5.0}

test canvas-22.14 {dchars method - text} -setup {
    canvas .c
} -body {
    set id [.c create text 0 0 -text "012"]
    .c dchars $id 0 1
    .c itemcget $id -text







<
|









<
|









<
|









<
<
|









<
|
<







1253
1254
1255
1256
1257
1258
1259

1260
1261
1262
1263
1264
1265
1266
1267
1268
1269

1270
1271
1272
1273
1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285
1286
1287
1288
1289


1290
1291
1292
1293
1294
1295
1296
1297
1298
1299

1300

1301
1302
1303
1304
1305
1306
1307
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    .c dchars $id 2 6
    .c coords $id
} -cleanup {
    destroy .c

} -result {0.0 1.0}

test canvas-22.10 {dchars method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    .c dchars $id 4 end
    .c coords $id
} -cleanup {
    destroy .c

} -result {0.0 1.0 2.0 3.0}

test canvas-22.11 {dchars method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    .c dchars $id end end
    .c coords $id
} -cleanup {
    destroy .c

} -result {0.0 1.0 2.0 3.0}

test canvas-22.12 {dchars method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5 6 7 8 9]
    .c dchars $id 8 4
    .c coords $id
} -cleanup {
    destroy .c


} -result {6.0 7.0}

test canvas-22.13 {dchars method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5 6 7 8 9 10 11]
    .c dchars $id 8 2
    .c coords $id
} -cleanup {
    destroy .c

} -result {4.0 5.0 6.0 7.0}


test canvas-22.14 {dchars method - text} -setup {
    canvas .c
} -body {
    set id [.c create text 0 0 -text "012"]
    .c dchars $id 0 1
    .c itemcget $id -text