MCPcopy Create free account
hub / github.com/SimHacker/micropolis / RectToPoint

Function RectToPoint

micropolis-activity/src/tk/tkrectov.c:542–621  ·  view source on GitHub ↗

ARGSUSED */

(canvasPtr, itemPtr, pointPtr)

Source from the content-addressed store, hash-verified

540 * occupied by the outline.
541 *
542 * Side effects:
543 * None.
544 *
545 *--------------------------------------------------------------
546 */
547
548 /* ARGSUSED */
549static double
550RectToPoint(canvasPtr, itemPtr, pointPtr)
551 Tk_Canvas *canvasPtr; /* Canvas containing item. */
552 Tk_Item *itemPtr; /* Item to check against point. */
553 double *pointPtr; /* Pointer to x and y coordinates. */
554{
555 register RectOvalItem *rectPtr = (RectOvalItem *) itemPtr;
556 double xDiff, yDiff, x1, y1, x2, y2, inc, tmp;
557
558 /*
559 * Generate a new larger rectangle that includes the border
560 * width, if there is one.
561 */
562
563 x1 = rectPtr->bbox[0];
564 y1 = rectPtr->bbox[1];
565 x2 = rectPtr->bbox[2];
566 y2 = rectPtr->bbox[3];
567 if (rectPtr->outlineGC != None) {
568 inc = rectPtr->width/2.0;
569 x1 -= inc;
570 y1 -= inc;
571 x2 += inc;
572 y2 += inc;
573 }
574
575 /*
576 * If the point is inside the rectangle, handle specially:
577 * distance is 0 if rectangle is filled, otherwise compute
578 * distance to nearest edge of rectangle and subtract width
579 * of edge.
580 */
581
582 if ((pointPtr[0] >= x1) && (pointPtr[0] < x2)
583 && (pointPtr[1] >= y1) && (pointPtr[1] < y2)) {
584 if ((rectPtr->fillGC != None) || (rectPtr->outlineGC == None)) {
585 return 0.0;
586 }
587 xDiff = pointPtr[0] - x1;
588 tmp = x2 - pointPtr[0];
589 if (tmp < xDiff) {
590 xDiff = tmp;
591 }
592 yDiff = pointPtr[1] - y1;
593 tmp = y2 - pointPtr[1];
594 if (tmp < yDiff) {
595 yDiff = tmp;
596 }
597 if (yDiff < xDiff) {
598 xDiff = yDiff;
599 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected