Tk Source Code

Check-in [eacf61ca]
Login

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

Overview
Comment:Fixes line behaviour, and a crash in polygon
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | pspjuth-canvas
Files: files | file ages | folders
SHA1: eacf61ca545a8d5fa6f6af2f782d24b339d99e79
User & Date: pspjuth 2011-04-24 23:04:09
Context
2011-04-24
23:27
Corrected index method for polygon check-in: 51fe9467 user: pspjuth tags: pspjuth-canvas
23:04
Fixes line behaviour, and a crash in polygon check-in: eacf61ca user: pspjuth tags: pspjuth-canvas
22:13
Canvas polygon experiment. This commit puts current behaviour into tests, while fixing a few crashing cases. check-in: e36fef63 user: pspjuth tags: pspjuth-canvas
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tkCanvLine.c.

1162
1163
1164
1165
1166
1167
1168



1169
1170
1171
1172
1173
1174
1175
    }

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

    if (first < 0) {
	first = 0;



    }
    if (last >= length) {
	last = length-2;
    }
    if (first > last) {
	return;
    }







>
>
>







1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
    }

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

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

Changes to generic/tkCanvPoly.c.

1173
1174
1175
1176
1177
1178
1179




1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190

1191
1192
1193
1194
1195
1196
1197
    int first,			/* Index of first character to delete. */
    int last)			/* Index of last character to delete. */
{
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;
    int count, i;
    int length = 2*(polyPtr->numPoints - polyPtr->autoClosed);





    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;
    if (count <= 0) {







>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
>







1173
1174
1175
1176
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
1202
    int first,			/* Index of first character to delete. */
    int last)			/* Index of last character to delete. */
{
    PolygonItem *polyPtr = (PolygonItem *) itemPtr;
    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;
    if (count <= 0) {

Changes to tests/canvas.test.

788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
    canvas .c
} -body {
    set id [.c create line 0 0 1 1 2 2 3 3]
    .c imove $id end 4 4
    .c coords $id
} -cleanup {
    destroy .c
    # PS: Feels like a bug. Caused by end>last
    # Deletion of "end" deletes nothing, insertion at "end" adds.
    # imove should be changed to interpret anything > last
    # as last, to give "end" a reasonable meaning.
} -result {0.0 0.0 1.0 1.0 2.0 2.0 3.0 3.0 4.0 4.0}
test canvas-18.5 {imove method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 0 1 1 2 2 3 3]
    .c imove $id 0 4 4
    .c coords $id
} -cleanup {







<
<
<
<
|







788
789
790
791
792
793
794




795
796
797
798
799
800
801
802
    canvas .c
} -body {
    set id [.c create line 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.5 {imove method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 0 1 1 2 2 3 3]
    .c imove $id 0 4 4
    .c coords $id
} -cleanup {
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
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
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213










1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
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
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370




































1371
1372
1373
1374
1375
1376
1377
    set id [.c create text  0 0 -text "012"]
    .c insert $id 4 4
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {0124}

test canvas-21.15 {insert method - lines} -setup {
    canvas .c
} -body {
    set id [.c create text  0 0 -text "012"]
    .c insert $id end 4
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {0124}

test canvas-22.1 {dchar method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 0 1 2 3 4 5]
    .c dchar $id 0 2
    .c coords $id
} -cleanup {
    destroy .c
} -result {4.0 5.0}

test canvas-22.2 {dchar method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 0 1 2 3 4 5]
    .c dchar $id 2 2
    .c coords $id
} -cleanup {
    destroy .c
} -result {0.0 1.0 4.0 5.0}

test canvas-22.3 {dchar method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 0 1 2 3 4 5]
    .c dchar $id 2 6
    .c coords $id
} -cleanup {
    destroy .c
} -result {0.0 1.0}











test canvas-22.4 {dchar method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 0 1 2 3 4 5]
    .c dchar $id 4 end
    .c coords $id
} -cleanup {
    destroy .c
} -result {0.0 1.0 2.0 3.0}

test canvas-22.5 {dchar method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 0 1 2 3 4 5]
    .c dchar $id end end
    .c coords $id
} -cleanup {
    destroy .c
    # PS: Should deleting "end" mean deleting the last one?
} -result {0.0 1.0 2.0 3.0 4.0 5.0}

test canvas-22.6 {dchar method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 0 1 2 3 4 5 6 7 8 9 10 11]
    .c dchar $id 8 4
    .c coords $id
} -cleanup {
    destroy .c
} -result {0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0}

test canvas-22.7 {dchar method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    .c dchar $id 0 2
    .c coords $id
} -cleanup {
    destroy .c
} -result {4.0 5.0}

test canvas-22.8 {dchar method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    .c dchar $id 2 2
    .c coords $id
} -cleanup {
    destroy .c
} -result {0.0 1.0 4.0 5.0}

test canvas-22.9 {dchar method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    .c dchar $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 {dchar method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    .c dchar $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 {dchar method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    .c dchar $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 {dchar method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5 6 7 8 9]
    .c dchar $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 {dchar method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5 6 7 8 9 10 11]
    .c dchar $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 {dchar method - text} -setup {
    canvas .c
} -body {
    set id [.c create text 0 0 -text "012"]
    .c dchar $id 0 1
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {2}

test canvas-22.15 {dchar method - text} -setup {
    canvas .c
} -body {
    set id [.c create text  0 0 -text "012"]
    .c dchar $id 1 1
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {02}

test canvas-22.16 {dchar method - text} -setup {
    canvas .c
} -body {
    set id [.c create text  0 0 -text "012"]
    .c dchar $id 1 3
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {0}

test canvas-22.17 {dchar method - lines} -setup {
    canvas .c
} -body {
    set id [.c create text  0 0 -text "012"]
    .c dchar $id 2 end
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {01}

test canvas-22.18 {dchar method - lines} -setup {
    canvas .c
} -body {
    set id [.c create text  0 0 -text "012345"]
    .c dchar $id 4 2
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {012345}





































test canvas-23.1 {coords method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 0 1 2 3 4 5]
    .c coords $id 6 7 8 9
    .c coords $id







|









|



|





|



|





|



|





>
>
>
>
>
>
>
>
>
>
|



|





|
<
<
<
<
<
<
<
<
<
<
<



|





|



|





|



|





|



|






|



|






|



|






|



|







|



|







|



|





|



|





|



|





|



|





|



|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
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
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230











1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
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
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
    set id [.c create text  0 0 -text "012"]
    .c insert $id 4 4
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {0124}

test canvas-21.15 {insert method - text} -setup {
    canvas .c
} -body {
    set id [.c create text  0 0 -text "012"]
    .c insert $id end 4
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {0124}

test canvas-22.1 {dchars method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 0 1 2 3 4 5]
    .c dchars $id 0 2
    .c coords $id
} -cleanup {
    destroy .c
} -result {4.0 5.0}

test canvas-22.2 {dchars method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 0 1 2 3 4 5]
    .c dchars $id 2 2
    .c coords $id
} -cleanup {
    destroy .c
} -result {0.0 1.0 4.0 5.0}

test canvas-22.3 {dchars method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 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.4 {dchars method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 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.5 {dchars method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 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.6 {dchars method - lines} -setup {











    canvas .c
} -body {
    set id [.c create line 0 1 2 3 4 5 6 7 8 9 10 11]
    .c dchars $id 8 4
    .c coords $id
} -cleanup {
    destroy .c
} -result {0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0}

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

test canvas-22.8 {dchars method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    .c dchars $id 2 2
    .c coords $id
} -cleanup {
    destroy .c
} -result {0.0 1.0 4.0 5.0}

test canvas-22.9 {dchars method - polygon} -setup {
    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
} -cleanup {
    destroy .c
} -result {2}

test canvas-22.15 {dchars method - text} -setup {
    canvas .c
} -body {
    set id [.c create text  0 0 -text "012"]
    .c dchars $id 1 1
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {02}

test canvas-22.16 {dchars method - text} -setup {
    canvas .c
} -body {
    set id [.c create text  0 0 -text "012"]
    .c dchars $id 1 3
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {0}

test canvas-22.17 {dchars method - text} -setup {
    canvas .c
} -body {
    set id [.c create text  0 0 -text "012"]
    .c dchars $id 2 end
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {01}

test canvas-22.18 {dchars method - text} -setup {
    canvas .c
} -body {
    set id [.c create text  0 0 -text "012345"]
    .c dchars $id 4 2
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result {012345}

test canvas-22.19 {dchars method - line} -setup {
    canvas .c
} -body {
    set id [.c create line 0 1 2 3 4 5]
    # Double deletion
    .c dchars $id 0 4
    .c dchars $id 0 4
    .c coords $id
} -cleanup {
    destroy .c
} -result {}

test canvas-22.20 {dchars method - polygon} -setup {
    canvas .c
} -body {
    set id [.c create polygon 0 1 2 3 4 5]
    # Double deletion
    .c dchars $id 0 4
    .c dchars $id 0 4
    .c coords $id
} -cleanup {
    destroy .c
} -result {}

test canvas-22.21 {dchars method - text} -setup {
    canvas .c
} -body {
    set id [.c create text  0 0 -text "012"]
    # Double deletion
    .c dchars $id 0 2
    .c dchars $id 0 2
    .c itemcget $id -text
} -cleanup {
    destroy .c
} -result ""

test canvas-23.1 {coords method - lines} -setup {
    canvas .c
} -body {
    set id [.c create line 0 1 2 3 4 5]
    .c coords $id 6 7 8 9
    .c coords $id