| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include "tkInt.h" |
| 19 |
#include "tkPort.h" |
| 20 |
#include "tkCanvases.h" |
| 21 |
|
| 22 |
#undef MIN |
| 23 |
#define MIN(a,b) (((a) < (b)) ? (a) : (b)) |
| 24 |
#undef MAX |
| 25 |
#define MAX(a,b) (((a) > (b)) ? (a) : (b)) |
| 26 |
#ifndef PI |
| 27 |
# define PI 3.14159265358979323846 |
| 28 |
#endif |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
double |
| 49 |
TkLineToPoint(end1Ptr, end2Ptr, pointPtr) |
| 50 |
double end1Ptr[2]; |
| 51 |
double end2Ptr[2]; |
| 52 |
double pointPtr[2]; |
| 53 |
{ |
| 54 |
double x, y; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
if (end1Ptr[0] == end2Ptr[0]) { |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
x = end1Ptr[0]; |
| 69 |
if (end1Ptr[1] >= end2Ptr[1]) { |
| 70 |
y = MIN(end1Ptr[1], pointPtr[1]); |
| 71 |
y = MAX(y, end2Ptr[1]); |
| 72 |
} else { |
| 73 |
y = MIN(end2Ptr[1], pointPtr[1]); |
| 74 |
y = MAX(y, end1Ptr[1]); |
| 75 |
} |
| 76 |
} else if (end1Ptr[1] == end2Ptr[1]) { |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
y = end1Ptr[1]; |
| 83 |
if (end1Ptr[0] >= end2Ptr[0]) { |
| 84 |
x = MIN(end1Ptr[0], pointPtr[0]); |
| 85 |
x = MAX(x, end2Ptr[0]); |
| 86 |
} else { |
| 87 |
x = MIN(end2Ptr[0], pointPtr[0]); |
| 88 |
x = MAX(x, end1Ptr[0]); |
| 89 |
} |
| 90 |
} else { |
| 91 |
double m1, b1, m2, b2; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
m1 = (end2Ptr[1] - end1Ptr[1])/(end2Ptr[0] - end1Ptr[0]); |
| 101 |
b1 = end1Ptr[1] - m1*end1Ptr[0]; |
| 102 |
m2 = -1.0/m1; |
| 103 |
b2 = pointPtr[1] - m2*pointPtr[0]; |
| 104 |
x = (b2 - b1)/(m1 - m2); |
| 105 |
y = m1*x + b1; |
| 106 |
if (end1Ptr[0] > end2Ptr[0]) { |
| 107 |
if (x > end1Ptr[0]) { |
| 108 |
x = end1Ptr[0]; |
| 109 |
y = end1Ptr[1]; |
| 110 |
} else if (x < end2Ptr[0]) { |
| 111 |
x = end2Ptr[0]; |
| 112 |
y = end2Ptr[1]; |
| 113 |
} |
| 114 |
} else { |
| 115 |
if (x > end2Ptr[0]) { |
| 116 |
x = end2Ptr[0]; |
| 117 |
y = end2Ptr[1]; |
| 118 |
} else if (x < end1Ptr[0]) { |
| 119 |
x = end1Ptr[0]; |
| 120 |
y = end1Ptr[1]; |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
return hypot(pointPtr[0] - x, pointPtr[1] - y); |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
int |
| 153 |
TkLineToArea(end1Ptr, end2Ptr, rectPtr) |
| 154 |
double end1Ptr[2]; |
| 155 |
|
| 156 |
double end2Ptr[2]; |
| 157 |
|
| 158 |
double rectPtr[4]; |
| 159 |
|
| 160 |
|
| 161 |
{ |
| 162 |
int inside1, inside2; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
inside1 = (end1Ptr[0] >= rectPtr[0]) && (end1Ptr[0] <= rectPtr[2]) |
| 170 |
&& (end1Ptr[1] >= rectPtr[1]) && (end1Ptr[1] <= rectPtr[3]); |
| 171 |
inside2 = (end2Ptr[0] >= rectPtr[0]) && (end2Ptr[0] <= rectPtr[2]) |
| 172 |
&& (end2Ptr[1] >= rectPtr[1]) && (end2Ptr[1] <= rectPtr[3]); |
| 173 |
if (inside1 != inside2) { |
| 174 |
return 0; |
| 175 |
} |
| 176 |
if (inside1 & inside2) { |
| 177 |
return 1; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
if (end1Ptr[0] == end2Ptr[0]) { |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
if (((end1Ptr[1] >= rectPtr[1]) ^ (end2Ptr[1] >= rectPtr[1])) |
| 193 |
&& (end1Ptr[0] >= rectPtr[0]) |
| 194 |
&& (end1Ptr[0] <= rectPtr[2])) { |
| 195 |
return 0; |
| 196 |
} |
| 197 |
} else if (end1Ptr[1] == end2Ptr[1]) { |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
if (((end1Ptr[0] >= rectPtr[0]) ^ (end2Ptr[0] >= rectPtr[0])) |
| 203 |
&& (end1Ptr[1] >= rectPtr[1]) |
| 204 |
&& (end1Ptr[1] <= rectPtr[3])) { |
| 205 |
return 0; |
| 206 |
} |
| 207 |
} else { |
| 208 |
double m, x, y, low, high; |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
m = (end2Ptr[1] - end1Ptr[1])/(end2Ptr[0] - end1Ptr[0]); |
| 217 |
if (end1Ptr[0] < end2Ptr[0]) { |
| 218 |
low = end1Ptr[0]; high = end2Ptr[0]; |
| 219 |
} else { |
| 220 |
low = end2Ptr[0]; high = end1Ptr[0]; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
y = end1Ptr[1] + (rectPtr[0] - end1Ptr[0])*m; |
| 228 |
if ((rectPtr[0] >= low) && (rectPtr[0] <= high) |
| 229 |
&& (y >= rectPtr[1]) && (y <= rectPtr[3])) { |
| 230 |
return 0; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
y += (rectPtr[2] - rectPtr[0])*m; |
| 238 |
if ((y >= rectPtr[1]) && (y <= rectPtr[3]) |
| 239 |
&& (rectPtr[2] >= low) && (rectPtr[2] <= high)) { |
| 240 |
return 0; |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
if (end1Ptr[1] < end2Ptr[1]) { |
| 248 |
low = end1Ptr[1]; high = end2Ptr[1]; |
| 249 |
} else { |
| 250 |
low = end2Ptr[1]; high = end1Ptr[1]; |
| 251 |
} |
| 252 |
x = end1Ptr[0] + (rectPtr[1] - end1Ptr[1])/m; |
| 253 |
if ((x >= rectPtr[0]) && (x <= rectPtr[2]) |
| 254 |
&& (rectPtr[1] >= low) && (rectPtr[1] <= high)) { |
| 255 |
return 0; |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
x += (rectPtr[3] - rectPtr[1])/m; |
| 263 |
if ((x >= rectPtr[0]) && (x <= rectPtr[2]) |
| 264 |
&& (rectPtr[3] >= low) && (rectPtr[3] <= high)) { |
| 265 |
return 0; |
| 266 |
} |
| 267 |
} |
| 268 |
return -1; |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
int |
| 293 |
TkThickPolyLineToArea(coordPtr, numPoints, width, capStyle, joinStyle, rectPtr) |
| 294 |
double *coordPtr; |
| 295 |
|
| 296 |
int numPoints; |
| 297 |
double width; |
| 298 |
int capStyle; |
| 299 |
|
| 300 |
int joinStyle; |
| 301 |
|
| 302 |
double *rectPtr; |
| 303 |
{ |
| 304 |
double radius, poly[10]; |
| 305 |
int count; |
| 306 |
int changedMiterToBevel; |
| 307 |
|
| 308 |
|
| 309 |
int inside; |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
radius = width/2.0; |
| 317 |
inside = -1; |
| 318 |
|
| 319 |
if ((coordPtr[0] >= rectPtr[0]) && (coordPtr[0] <= rectPtr[2]) |
| 320 |
&& (coordPtr[1] >= rectPtr[1]) && (coordPtr[1] <= rectPtr[3])) { |
| 321 |
inside = 1; |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
changedMiterToBevel = 0; |
| 332 |
for (count = numPoints; count >= 2; count--, coordPtr += 2) { |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
if (((capStyle == CapRound) && (count == numPoints)) |
| 341 |
|| ((joinStyle == JoinRound) && (count != numPoints))) { |
| 342 |
poly[0] = coordPtr[0] - radius; |
| 343 |
poly[1] = coordPtr[1] - radius; |
| 344 |
poly[2] = coordPtr[0] + radius; |
| 345 |
poly[3] = coordPtr[1] + radius; |
| 346 |
if (TkOvalToArea(poly, rectPtr) != inside) { |
| 347 |
return 0; |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
if (count == numPoints) { |
| 358 |
TkGetButtPoints(coordPtr+2, coordPtr, width, |
| 359 |
capStyle == CapProjecting, poly, poly+2); |
| 360 |
} else if ((joinStyle == JoinMiter) && !changedMiterToBevel) { |
| 361 |
poly[0] = poly[6]; |
| 362 |
poly[1] = poly[7]; |
| 363 |
poly[2] = poly[4]; |
| 364 |
poly[3] = poly[5]; |
| 365 |
} else { |
| 366 |
TkGetButtPoints(coordPtr+2, coordPtr, width, 0, poly, poly+2); |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
if ((joinStyle == JoinBevel) || changedMiterToBevel) { |
| 376 |
poly[8] = poly[0]; |
| 377 |
poly[9] = poly[1]; |
| 378 |
if (TkPolygonToArea(poly, 5, rectPtr) != inside) { |
| 379 |
return 0; |
| 380 |
} |
| 381 |
changedMiterToBevel = 0; |
| 382 |
} |
| 383 |
} |
| 384 |
if (count == 2) { |
| 385 |
TkGetButtPoints(coordPtr, coordPtr+2, width, |
| 386 |
capStyle == CapProjecting, poly+4, poly+6); |
| 387 |
} else if (joinStyle == JoinMiter) { |
| 388 |
if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, |
| 389 |
(double) width, poly+4, poly+6) == 0) { |
| 390 |
changedMiterToBevel = 1; |
| 391 |
TkGetButtPoints(coordPtr, coordPtr+2, width, 0, poly+4, |
| 392 |
poly+6); |
| 393 |
} |
| 394 |
} else { |
| 395 |
TkGetButtPoints(coordPtr, coordPtr+2, width, 0, poly+4, poly+6); |
| 396 |
} |
| 397 |
poly[8] = poly[0]; |
| 398 |
poly[9] = poly[1]; |
| 399 |
if (TkPolygonToArea(poly, 5, rectPtr) != inside) { |
| 400 |
return 0; |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
if (capStyle == CapRound) { |
| 410 |
poly[0] = coordPtr[0] - radius; |
| 411 |
poly[1] = coordPtr[1] - radius; |
| 412 |
poly[2] = coordPtr[0] + radius; |
| 413 |
poly[3] = coordPtr[1] + radius; |
| 414 |
if (TkOvalToArea(poly, rectPtr) != inside) { |
| 415 |
return 0; |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
return inside; |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
double |
| 442 |
TkPolygonToPoint(polyPtr, numPoints, pointPtr) |
| 443 |
double *polyPtr; |
| 444 |
|
| 445 |
|
| 446 |
int numPoints; |
| 447 |
double *pointPtr; |
| 448 |
{ |
| 449 |
double bestDist; |
| 450 |
|
| 451 |
int intersections; |
| 452 |
|
| 453 |
|
| 454 |
int count; |
| 455 |
register double *pPtr; |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
bestDist = 1.0e36; |
| 468 |
intersections = 0; |
| 469 |
|
| 470 |
for (count = numPoints, pPtr = polyPtr; count > 1; count--, pPtr += 2) { |
| 471 |
double x, y, dist; |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
if (pPtr[2] == pPtr[0]) { |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
x = pPtr[0]; |
| 487 |
if (pPtr[1] >= pPtr[3]) { |
| 488 |
y = MIN(pPtr[1], pointPtr[1]); |
| 489 |
y = MAX(y, pPtr[3]); |
| 490 |
} else { |
| 491 |
y = MIN(pPtr[3], pointPtr[1]); |
| 492 |
y = MAX(y, pPtr[1]); |
| 493 |
} |
| 494 |
} else if (pPtr[3] == pPtr[1]) { |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
y = pPtr[1]; |
| 501 |
if (pPtr[0] >= pPtr[2]) { |
| 502 |
x = MIN(pPtr[0], pointPtr[0]); |
| 503 |
x = MAX(x, pPtr[2]); |
| 504 |
if ((pointPtr[1] < y) && (pointPtr[0] < pPtr[0]) |
| 505 |
&& (pointPtr[0] >= pPtr[2])) { |
| 506 |
intersections++; |
| 507 |
} |
| 508 |
} else { |
| 509 |
x = MIN(pPtr[2], pointPtr[0]); |
| 510 |
x = MAX(x, pPtr[0]); |
| 511 |
if ((pointPtr[1] < y) && (pointPtr[0] < pPtr[2]) |
| 512 |
&& (pointPtr[0] >= pPtr[0])) { |
| 513 |
intersections++; |
| 514 |
} |
| 515 |
} |
| 516 |
} else { |
| 517 |
double m1, b1, m2, b2; |
| 518 |
int lower; |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
m1 = (pPtr[3] - pPtr[1])/(pPtr[2] - pPtr[0]); |
| 528 |
b1 = pPtr[1] - m1*pPtr[0]; |
| 529 |
m2 = -1.0/m1; |
| 530 |
b2 = pointPtr[1] - m2*pointPtr[0]; |
| 531 |
x = (b2 - b1)/(m1 - m2); |
| 532 |
y = m1*x + b1; |
| 533 |
if (pPtr[0] > pPtr[2]) { |
| 534 |
if (x > pPtr[0]) { |
| 535 |
x = pPtr[0]; |
| 536 |
y = pPtr[1]; |
| 537 |
} else if (x < pPtr[2]) { |
| 538 |
x = pPtr[2]; |
| 539 |
y = pPtr[3]; |
| 540 |
} |
| 541 |
} else { |
| 542 |
if (x > pPtr[2]) { |
| 543 |
x = pPtr[2]; |
| 544 |
y = pPtr[3]; |
| 545 |
} else if (x < pPtr[0]) { |
| 546 |
x = pPtr[0]; |
| 547 |
y = pPtr[1]; |
| 548 |
} |
| 549 |
} |
| 550 |
lower = (m1*pointPtr[0] + b1) > pointPtr[1]; |
| 551 |
if (lower && (pointPtr[0] >= MIN(pPtr[0], pPtr[2])) |
| 552 |
&& (pointPtr[0] < MAX(pPtr[0], pPtr[2]))) { |
| 553 |
intersections++; |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
dist = hypot(pointPtr[0] - x, pointPtr[1] - y); |
| 563 |
if (dist < bestDist) { |
| 564 |
bestDist = dist; |
| 565 |
} |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
if (intersections & 0x1) { |
| 574 |
return 0.0; |
| 575 |
} |
| 576 |
return bestDist; |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
int |
| 600 |
TkPolygonToArea(polyPtr, numPoints, rectPtr) |
| 601 |
double *polyPtr; |
| 602 |
|
| 603 |
|
| 604 |
int numPoints; |
| 605 |
register double *rectPtr; |
| 606 |
|
| 607 |
|
| 608 |
{ |
| 609 |
int state; |
| 610 |
|
| 611 |
|
| 612 |
int count; |
| 613 |
register double *pPtr; |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
state = TkLineToArea(polyPtr, polyPtr+2, rectPtr); |
| 622 |
if (state == 0) { |
| 623 |
return 0; |
| 624 |
} |
| 625 |
for (pPtr = polyPtr+2, count = numPoints-1; count >= 2; |
| 626 |
pPtr += 2, count--) { |
| 627 |
if (TkLineToArea(pPtr, pPtr+2, rectPtr) != state) { |
| 628 |
return 0; |
| 629 |
} |
| 630 |
} |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
if (state == 1) { |
| 640 |
return 1; |
| 641 |
} |
| 642 |
if (TkPolygonToPoint(polyPtr, numPoints, rectPtr) == 0.0) { |
| 643 |
return 0; |
| 644 |
} |
| 645 |
return -1; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
double |
| 673 |
TkOvalToPoint(ovalPtr, width, filled, pointPtr) |
| 674 |
double ovalPtr[4]; |
| 675 |
|
| 676 |
|
| 677 |
double width; |
| 678 |
int filled; |
| 679 |
|
| 680 |
double pointPtr[2]; |
| 681 |
{ |
| 682 |
double xDelta, yDelta, scaledDistance, distToOutline, distToCenter; |
| 683 |
double xDiam, yDiam; |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
xDelta = (pointPtr[0] - (ovalPtr[0] + ovalPtr[2])/2.0); |
| 692 |
yDelta = (pointPtr[1] - (ovalPtr[1] + ovalPtr[3])/2.0); |
| 693 |
distToCenter = hypot(xDelta, yDelta); |
| 694 |
scaledDistance = hypot(xDelta / ((ovalPtr[2] + width - ovalPtr[0])/2.0), |
| 695 |
yDelta / ((ovalPtr[3] + width - ovalPtr[1])/2.0)); |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
if (scaledDistance > 1.0) { |
| 710 |
return (distToCenter/scaledDistance) * (scaledDistance - 1.0); |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
if (filled) { |
| 722 |
return 0.0; |
| 723 |
} |
| 724 |
if (scaledDistance > 1E-10) { |
| 725 |
distToOutline = (distToCenter/scaledDistance) * (1.0 - scaledDistance) |
| 726 |
- width; |
| 727 |
} else { |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
xDiam = ovalPtr[2] - ovalPtr[0]; |
| 735 |
yDiam = ovalPtr[3] - ovalPtr[1]; |
| 736 |
if (xDiam < yDiam) { |
| 737 |
distToOutline = (xDiam - width)/2; |
| 738 |
} else { |
| 739 |
distToOutline = (yDiam - width)/2; |
| 740 |
} |
| 741 |
} |
| 742 |
|
| 743 |
if (distToOutline < 0.0) { |
| 744 |
return 0.0; |
| 745 |
} |
| 746 |
return distToOutline; |
| 747 |
} |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
int |
| 770 |
TkOvalToArea(ovalPtr, rectPtr) |
| 771 |
register double *ovalPtr; |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
register double *rectPtr; |
| 776 |
|
| 777 |
|
| 778 |
{ |
| 779 |
double centerX, centerY, radX, radY, deltaX, deltaY; |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
if ((rectPtr[0] <= ovalPtr[0]) && (rectPtr[2] >= ovalPtr[2]) |
| 787 |
&& (rectPtr[1] <= ovalPtr[1]) && (rectPtr[3] >= ovalPtr[3])) { |
| 788 |
return 1; |
| 789 |
} |
| 790 |
if ((rectPtr[2] < ovalPtr[0]) || (rectPtr[0] > ovalPtr[2]) |
| 791 |
|| (rectPtr[3] < ovalPtr[1]) || (rectPtr[1] > ovalPtr[3])) { |
| 792 |
return -1; |
| 793 |
} |
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
centerX = (ovalPtr[0] + ovalPtr[2])/2; |
| 804 |
centerY = (ovalPtr[1] + ovalPtr[3])/2; |
| 805 |
radX = (ovalPtr[2] - ovalPtr[0])/2; |
| 806 |
radY = (ovalPtr[3] - ovalPtr[1])/2; |
| 807 |
|
| 808 |
deltaY = rectPtr[1] - centerY; |
| 809 |
if (deltaY < 0.0) { |
| 810 |
deltaY = centerY - rectPtr[3]; |
| 811 |
if (deltaY < 0.0) { |
| 812 |
deltaY = 0; |
| 813 |
} |
| 814 |
} |
| 815 |
deltaY /= radY; |
| 816 |
deltaY *= deltaY; |
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
deltaX = (rectPtr[0] - centerX)/radX; |
| 823 |
deltaX *= deltaX; |
| 824 |
if ((deltaX + deltaY) <= 1.0) { |
| 825 |
return 0; |
| 826 |
} |
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
deltaX = (rectPtr[2] - centerX)/radX; |
| 833 |
deltaX *= deltaX; |
| 834 |
if ((deltaX + deltaY) <= 1.0) { |
| 835 |
return 0; |
| 836 |
} |
| 837 |
|
| 838 |
deltaX = rectPtr[0] - centerX; |
| 839 |
if (deltaX < 0.0) { |
| 840 |
deltaX = centerX - rectPtr[2]; |
| 841 |
if (deltaX < 0.0) { |
| 842 |
deltaX = 0; |
| 843 |
} |
| 844 |
} |
| 845 |
deltaX /= radX; |
| 846 |
deltaX *= deltaX; |
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
deltaY = (rectPtr[1] - centerY)/radY; |
| 853 |
deltaY *= deltaY; |
| 854 |
if ((deltaX + deltaY) < 1.0) { |
| 855 |
return 0; |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
deltaY = (rectPtr[3] - centerY)/radY; |
| 863 |
deltaY *= deltaY; |
| 864 |
if ((deltaX + deltaY) < 1.0) { |
| 865 |
return 0; |
| 866 |
} |
| 867 |
|
| 868 |
return -1; |
| 869 |
} |
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
void |
| 890 |
TkIncludePoint(itemPtr, pointPtr) |
| 891 |
register Tk_Item *itemPtr; |
| 892 |
|
| 893 |
double *pointPtr; |
| 894 |
|
| 895 |
{ |
| 896 |
int tmp; |
| 897 |
|
| 898 |
tmp = (int) (pointPtr[0] + 0.5); |
| 899 |
if (tmp < itemPtr->x1) { |
| 900 |
itemPtr->x1 = tmp; |
| 901 |
} |
| 902 |
if (tmp > itemPtr->x2) { |
| 903 |
itemPtr->x2 = tmp; |
| 904 |
} |
| 905 |
tmp = (int) (pointPtr[1] + 0.5); |
| 906 |
if (tmp < itemPtr->y1) { |
| 907 |
itemPtr->y1 = tmp; |
| 908 |
} |
| 909 |
if (tmp > itemPtr->y2) { |
| 910 |
itemPtr->y2 = tmp; |
| 911 |
} |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
void |
| 936 |
TkBezierScreenPoints(canvas, control, numSteps, xPointPtr) |
| 937 |
Tk_Canvas canvas; |
| 938 |
|
| 939 |
double control[]; |
| 940 |
|
| 941 |
|
| 942 |
int numSteps; |
| 943 |
|
| 944 |
register XPoint *xPointPtr; |
| 945 |
{ |
| 946 |
int i; |
| 947 |
double u, u2, u3, t, t2, t3; |
| 948 |
|
| 949 |
for (i = 1; i <= numSteps; i++, xPointPtr++) { |
| 950 |
t = ((double) i)/((double) numSteps); |
| 951 |
t2 = t*t; |
| 952 |
t3 = t2*t; |
| 953 |
u = 1.0 - t; |
| 954 |
u2 = u*u; |
| 955 |
u3 = u2*u; |
| 956 |
Tk_CanvasDrawableCoords(canvas, |
| 957 |
(control[0]*u3 + 3.0 * (control[2]*t*u2 + control[4]*t2*u) |
| 958 |
+ control[6]*t3), |
| 959 |
(control[1]*u3 + 3.0 * (control[3]*t*u2 + control[5]*t2*u) |
| 960 |
+ control[7]*t3), |
| 961 |
&xPointPtr->x, &xPointPtr->y); |
| 962 |
} |
| 963 |
} |
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
void |
| 987 |
TkBezierPoints(control, numSteps, coordPtr) |
| 988 |
double control[]; |
| 989 |
|
| 990 |
|
| 991 |
int numSteps; |
| 992 |
|
| 993 |
register double *coordPtr; |
| 994 |
{ |
| 995 |
int i; |
| 996 |
double u, u2, u3, t, t2, t3; |
| 997 |
|
| 998 |
for (i = 1; i <= numSteps; i++, coordPtr += 2) { |
| 999 |
t = ((double) i)/((double) numSteps); |
| 1000 |
t2 = t*t; |
| 1001 |
t3 = t2*t; |
| 1002 |
u = 1.0 - t; |
| 1003 |
u2 = u*u; |
| 1004 |
u3 = u2*u; |
| 1005 |
coordPtr[0] = control[0]*u3 |
| 1006 |
+ 3.0 * (control[2]*t*u2 + control[4]*t2*u) + control[6]*t3; |
| 1007 |
coordPtr[1] = control[1]*u3 |
| 1008 |
+ 3.0 * (control[3]*t*u2 + control[5]*t2*u) + control[7]*t3; |
| 1009 |
} |
| 1010 |
} |
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
int |
| 1039 |
TkMakeBezierCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints) |
| 1040 |
Tk_Canvas canvas; |
| 1041 |
|
| 1042 |
double *pointPtr; |
| 1043 |
|
| 1044 |
int numPoints; |
| 1045 |
int numSteps; |
| 1046 |
|
| 1047 |
|
| 1048 |
XPoint xPoints[]; |
| 1049 |
|
| 1050 |
|
| 1051 |
double dblPoints[]; |
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
{ |
| 1058 |
int closed, outputPoints, i; |
| 1059 |
int numCoords = numPoints*2; |
| 1060 |
double control[8]; |
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
if (!pointPtr) { |
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
return 1 + numPoints * numSteps; |
| 1074 |
} |
| 1075 |
|
| 1076 |
outputPoints = 0; |
| 1077 |
if ((pointPtr[0] == pointPtr[numCoords-2]) |
| 1078 |
&& (pointPtr[1] == pointPtr[numCoords-1])) { |
| 1079 |
closed = 1; |
| 1080 |
control[0] = 0.5*pointPtr[numCoords-4] + 0.5*pointPtr[0]; |
| 1081 |
control[1] = 0.5*pointPtr[numCoords-3] + 0.5*pointPtr[1]; |
| 1082 |
control[2] = 0.167*pointPtr[numCoords-4] + 0.833*pointPtr[0]; |
| 1083 |
control[3] = 0.167*pointPtr[numCoords-3] + 0.833*pointPtr[1]; |
| 1084 |
control[4] = 0.833*pointPtr[0] + 0.167*pointPtr[2]; |
| 1085 |
control[5] = 0.833*pointPtr[1] + 0.167*pointPtr[3]; |
| 1086 |
control[6] = 0.5*pointPtr[0] + 0.5*pointPtr[2]; |
| 1087 |
control[7] = 0.5*pointPtr[1] + 0.5*pointPtr[3]; |
| 1088 |
if (xPoints != NULL) { |
| 1089 |
Tk_CanvasDrawableCoords(canvas, control[0], control[1], |
| 1090 |
&xPoints->x, &xPoints->y); |
| 1091 |
TkBezierScreenPoints(canvas, control, numSteps, xPoints+1); |
| 1092 |
xPoints += numSteps+1; |
| 1093 |
} |
| 1094 |
if (dblPoints != NULL) { |
| 1095 |
dblPoints[0] = control[0]; |
| 1096 |
dblPoints[1] = control[1]; |
| 1097 |
TkBezierPoints(control, numSteps, dblPoints+2); |
| 1098 |
dblPoints += 2*(numSteps+1); |
| 1099 |
} |
| 1100 |
outputPoints += numSteps+1; |
| 1101 |
} else { |
| 1102 |
closed = 0; |
| 1103 |
if (xPoints != NULL) { |
| 1104 |
Tk_CanvasDrawableCoords(canvas, pointPtr[0], pointPtr[1], |
| 1105 |
&xPoints->x, &xPoints->y); |
| 1106 |
xPoints += 1; |
| 1107 |
} |
| 1108 |
if (dblPoints != NULL) { |
| 1109 |
dblPoints[0] = pointPtr[0]; |
| 1110 |
dblPoints[1] = pointPtr[1]; |
| 1111 |
dblPoints += 2; |
| 1112 |
} |
| 1113 |
outputPoints += 1; |
| 1114 |
} |
| 1115 |
|
| 1116 |
for (i = 2; i < numPoints; i++, pointPtr += 2) { |
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
if ((i == 2) && !closed) { |
| 1124 |
control[0] = pointPtr[0]; |
| 1125 |
control[1] = pointPtr[1]; |
| 1126 |
control[2] = 0.333*pointPtr[0] + 0.667*pointPtr[2]; |
| 1127 |
control[3] = 0.333*pointPtr[1] + 0.667*pointPtr[3]; |
| 1128 |
} else { |
| 1129 |
control[0] = 0.5*pointPtr[0] + 0.5*pointPtr[2]; |
| 1130 |
control[1] = 0.5*pointPtr[1] + 0.5*pointPtr[3]; |
| 1131 |
control[2] = 0.167*pointPtr[0] + 0.833*pointPtr[2]; |
| 1132 |
control[3] = 0.167*pointPtr[1] + 0.833*pointPtr[3]; |
| 1133 |
} |
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
if ((i == (numPoints-1)) && !closed) { |
| 1142 |
control[4] = .667*pointPtr[2] + .333*pointPtr[4]; |
| 1143 |
control[5] = .667*pointPtr[3] + .333*pointPtr[5]; |
| 1144 |
control[6] = pointPtr[4]; |
| 1145 |
control[7] = pointPtr[5]; |
| 1146 |
} else { |
| 1147 |
control[4] = .833*pointPtr[2] + .167*pointPtr[4]; |
| 1148 |
control[5] = .833*pointPtr[3] + .167*pointPtr[5]; |
| 1149 |
control[6] = 0.5*pointPtr[2] + 0.5*pointPtr[4]; |
| 1150 |
control[7] = 0.5*pointPtr[3] + 0.5*pointPtr[5]; |
| 1151 |
} |
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
if (((pointPtr[0] == pointPtr[2]) && (pointPtr[1] == pointPtr[3])) |
| 1161 |
|| ((pointPtr[2] == pointPtr[4]) |
| 1162 |
&& (pointPtr[3] == pointPtr[5]))) { |
| 1163 |
if (xPoints != NULL) { |
| 1164 |
Tk_CanvasDrawableCoords(canvas, control[6], control[7], |
| 1165 |
&xPoints[0].x, &xPoints[0].y); |
| 1166 |
xPoints++; |
| 1167 |
} |
| 1168 |
if (dblPoints != NULL) { |
| 1169 |
dblPoints[0] = control[6]; |
| 1170 |
dblPoints[1] = control[7]; |
| 1171 |
dblPoints += 2; |
| 1172 |
} |
| 1173 |
outputPoints += 1; |
| 1174 |
continue; |
| 1175 |
} |
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
if (xPoints != NULL) { |
| 1183 |
TkBezierScreenPoints(canvas, control, numSteps, xPoints); |
| 1184 |
xPoints += numSteps; |
| 1185 |
} |
| 1186 |
if (dblPoints != NULL) { |
| 1187 |
TkBezierPoints(control, numSteps, dblPoints); |
| 1188 |
dblPoints += 2*numSteps; |
| 1189 |
} |
| 1190 |
outputPoints += numSteps; |
| 1191 |
} |
| 1192 |
return outputPoints; |
| 1193 |
} |
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
void |
| 1214 |
TkMakeBezierPostscript(interp, canvas, pointPtr, numPoints) |
| 1215 |
Tcl_Interp *interp; |
| 1216 |
|
| 1217 |
Tk_Canvas canvas; |
| 1218 |
|
| 1219 |
double *pointPtr; |
| 1220 |
|
| 1221 |
int numPoints; |
| 1222 |
{ |
| 1223 |
int closed, i; |
| 1224 |
int numCoords = numPoints*2; |
| 1225 |
double control[8]; |
| 1226 |
char buffer[200]; |
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
if ((pointPtr[0] == pointPtr[numCoords-2]) |
| 1235 |
&& (pointPtr[1] == pointPtr[numCoords-1])) { |
| 1236 |
closed = 1; |
| 1237 |
control[0] = 0.5*pointPtr[numCoords-4] + 0.5*pointPtr[0]; |
| 1238 |
control[1] = 0.5*pointPtr[numCoords-3] + 0.5*pointPtr[1]; |
| 1239 |
control[2] = 0.167*pointPtr[numCoords-4] + 0.833*pointPtr[0]; |
| 1240 |
control[3] = 0.167*pointPtr[numCoords-3] + 0.833*pointPtr[1]; |
| 1241 |
control[4] = 0.833*pointPtr[0] + 0.167*pointPtr[2]; |
| 1242 |
control[5] = 0.833*pointPtr[1] + 0.167*pointPtr[3]; |
| 1243 |
control[6] = 0.5*pointPtr[0] + 0.5*pointPtr[2]; |
| 1244 |
control[7] = 0.5*pointPtr[1] + 0.5*pointPtr[3]; |
| 1245 |
sprintf(buffer, "%.15g %.15g moveto\n%.15g %.15g %.15g %.15g %.15g %.15g curveto\n", |
| 1246 |
control[0], Tk_CanvasPsY(canvas, control[1]), |
| 1247 |
control[2], Tk_CanvasPsY(canvas, control[3]), |
| 1248 |
control[4], Tk_CanvasPsY(canvas, control[5]), |
| 1249 |
control[6], Tk_CanvasPsY(canvas, control[7])); |
| 1250 |
} else { |
| 1251 |
closed = 0; |
| 1252 |
control[6] = pointPtr[0]; |
| 1253 |
control[7] = pointPtr[1]; |
| 1254 |
sprintf(buffer, "%.15g %.15g moveto\n", |
| 1255 |
control[6], Tk_CanvasPsY(canvas, control[7])); |
| 1256 |
} |
| 1257 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
for (i = numPoints-2, pointPtr += 2; i > 0; i--, pointPtr += 2) { |
| 1265 |
control[2] = 0.333*control[6] + 0.667*pointPtr[0]; |
| 1266 |
control[3] = 0.333*control[7] + 0.667*pointPtr[1]; |
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
if ((i == 1) && !closed) { |
| 1275 |
control[6] = pointPtr[2]; |
| 1276 |
control[7] = pointPtr[3]; |
| 1277 |
} else { |
| 1278 |
control[6] = 0.5*pointPtr[0] + 0.5*pointPtr[2]; |
| 1279 |
control[7] = 0.5*pointPtr[1] + 0.5*pointPtr[3]; |
| 1280 |
} |
| 1281 |
control[4] = 0.333*control[6] + 0.667*pointPtr[0]; |
| 1282 |
control[5] = 0.333*control[7] + 0.667*pointPtr[1]; |
| 1283 |
|
| 1284 |
sprintf(buffer, "%.15g %.15g %.15g %.15g %.15g %.15g curveto\n", |
| 1285 |
control[2], Tk_CanvasPsY(canvas, control[3]), |
| 1286 |
control[4], Tk_CanvasPsY(canvas, control[5]), |
| 1287 |
control[6], Tk_CanvasPsY(canvas, control[7])); |
| 1288 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 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 |
int |
| 1316 |
TkGetMiterPoints(p1, p2, p3, width, m1, m2) |
| 1317 |
double p1[]; |
| 1318 |
|
| 1319 |
double p2[]; |
| 1320 |
|
| 1321 |
double p3[]; |
| 1322 |
|
| 1323 |
double width; |
| 1324 |
double m1[]; |
| 1325 |
|
| 1326 |
double m2[]; |
| 1327 |
|
| 1328 |
{ |
| 1329 |
double theta1; |
| 1330 |
double theta2; |
| 1331 |
double theta; |
| 1332 |
|
| 1333 |
double theta3; |
| 1334 |
|
| 1335 |
double dist; |
| 1336 |
double deltaX, deltaY; |
| 1337 |
|
| 1338 |
|
| 1339 |
double p1x, p1y, p2x, p2y, p3x, p3y; |
| 1340 |
static double elevenDegrees = (11.0*2.0*PI)/360.0; |
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
p1x = floor(p1[0]+0.5); |
| 1349 |
p1y = floor(p1[1]+0.5); |
| 1350 |
p2x = floor(p2[0]+0.5); |
| 1351 |
p2y = floor(p2[1]+0.5); |
| 1352 |
p3x = floor(p3[0]+0.5); |
| 1353 |
p3y = floor(p3[1]+0.5); |
| 1354 |
|
| 1355 |
if (p2y == p1y) { |
| 1356 |
theta1 = (p2x < p1x) ? 0 : PI; |
| 1357 |
} else if (p2x == p1x) { |
| 1358 |
theta1 = (p2y < p1y) ? PI/2.0 : -PI/2.0; |
| 1359 |
} else { |
| 1360 |
theta1 = atan2(p1y - p2y, p1x - p2x); |
| 1361 |
} |
| 1362 |
if (p3y == p2y) { |
| 1363 |
theta2 = (p3x > p2x) ? 0 : PI; |
| 1364 |
} else if (p3x == p2x) { |
| 1365 |
theta2 = (p3y > p2y) ? PI/2.0 : -PI/2.0; |
| 1366 |
} else { |
| 1367 |
theta2 = atan2(p3y - p2y, p3x - p2x); |
| 1368 |
} |
| 1369 |
theta = theta1 - theta2; |
| 1370 |
if (theta > PI) { |
| 1371 |
theta -= 2*PI; |
| 1372 |
} else if (theta < -PI) { |
| 1373 |
theta += 2*PI; |
| 1374 |
} |
| 1375 |
if ((theta < elevenDegrees) && (theta > -elevenDegrees)) { |
| 1376 |
return 0; |
| 1377 |
} |
| 1378 |
dist = 0.5*width/sin(0.5*theta); |
| 1379 |
if (dist < 0.0) { |
| 1380 |
dist = -dist; |
| 1381 |
} |
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
theta3 = (theta1 + theta2)/2.0; |
| 1389 |
if (sin(theta3 - (theta1 + PI)) < 0.0) { |
| 1390 |
theta3 += PI; |
| 1391 |
} |
| 1392 |
deltaX = dist*cos(theta3); |
| 1393 |
m1[0] = p2x + deltaX; |
| 1394 |
m2[0] = p2x - deltaX; |
| 1395 |
deltaY = dist*sin(theta3); |
| 1396 |
m1[1] = p2y + deltaY; |
| 1397 |
m2[1] = p2y - deltaY; |
| 1398 |
return 1; |
| 1399 |
} |
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
void |
| 1439 |
TkGetButtPoints(p1, p2, width, project, m1, m2) |
| 1440 |
double p1[]; |
| 1441 |
|
| 1442 |
double p2[]; |
| 1443 |
|
| 1444 |
double width; |
| 1445 |
int project; |
| 1446 |
|
| 1447 |
double m1[]; |
| 1448 |
|
| 1449 |
double m2[]; |
| 1450 |
|
| 1451 |
{ |
| 1452 |
double length; |
| 1453 |
double deltaX, deltaY; |
| 1454 |
|
| 1455 |
width *= 0.5; |
| 1456 |
length = hypot(p2[0] - p1[0], p2[1] - p1[1]); |
| 1457 |
if (length == 0.0) { |
| 1458 |
m1[0] = m2[0] = p2[0]; |
| 1459 |
m1[1] = m2[1] = p2[1]; |
| 1460 |
} else { |
| 1461 |
deltaX = -width * (p2[1] - p1[1]) / length; |
| 1462 |
deltaY = width * (p2[0] - p1[0]) / length; |
| 1463 |
m1[0] = p2[0] + deltaX; |
| 1464 |
m2[0] = p2[0] - deltaX; |
| 1465 |
m1[1] = p2[1] + deltaY; |
| 1466 |
m2[1] = p2[1] - deltaY; |
| 1467 |
if (project) { |
| 1468 |
m1[0] += deltaY; |
| 1469 |
m2[0] += deltaY; |
| 1470 |
m1[1] -= deltaX; |
| 1471 |
m2[1] -= deltaX; |
| 1472 |
} |
| 1473 |
} |
| 1474 |
} |