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

Function TextToPoint

micropolis-activity/src/tk/tkcvtext.c:974–1035  ·  view source on GitHub ↗

ARGSUSED */

(canvasPtr, itemPtr, pointPtr)

Source from the content-addressed store, hash-verified

972 * are pointPtr[0] and pointPtr[1] is inside the arc. If the
973 * point isn't inside the arc then the return value is the
974 * distance from the point to the arc.
975 *
976 * Side effects:
977 * None.
978 *
979 *--------------------------------------------------------------
980 */
981
982 /* ARGSUSED */
983static double
984TextToPoint(canvasPtr, itemPtr, pointPtr)
985 Tk_Canvas *canvasPtr; /* Canvas containing itemPtr. */
986 Tk_Item *itemPtr; /* Item to check against point. */
987 double *pointPtr; /* Pointer to x and y coordinates. */
988{
989 TextItem *textPtr = (TextItem *) itemPtr;
990 register TextLine *linePtr;
991 int i;
992 double xDiff, yDiff, dist, minDist;
993
994 /*
995 * Treat each line in the text item as a rectangle, compute the
996 * distance to that rectangle, and take the minimum of these
997 * distances. Perform most of the calculations in integer pixel
998 * units, since that's how the dimensions of the text are defined.
999 */
1000
1001 minDist = -1.0;
1002 for (linePtr = textPtr->linePtr, i = textPtr->numLines;
1003 i > 0; linePtr++, i--) {
1004
1005 /*
1006 * If the point is inside the line's rectangle, then can
1007 * return immediately.
1008 */
1009
1010 if ((pointPtr[0] >= linePtr->x1)
1011 && (pointPtr[0] <= linePtr->x2)
1012 && (pointPtr[1] >= linePtr->y1)
1013 && (pointPtr[1] <= linePtr->y2)) {
1014 return 0.0;
1015 }
1016
1017 /*
1018 * Point is outside line's rectangle; compute distance to nearest
1019 * side.
1020 */
1021
1022 if (pointPtr[0] < linePtr->x1) {
1023 xDiff = linePtr->x1 - pointPtr[0];
1024 } else if (pointPtr[0] > linePtr->x2) {
1025 xDiff = pointPtr[0] - linePtr->x2;
1026 } else {
1027 xDiff = 0;
1028 }
1029
1030 if (pointPtr[1] < linePtr->y1) {
1031 yDiff = linePtr->y1 - pointPtr[1];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected