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

Function ShiftLine

micropolis-activity/src/tk/tk3d.c:853–925  ·  view source on GitHub ↗
(p1Ptr, p2Ptr, distance, p3Ptr)

Source from the content-addressed store, hash-verified

851 * ShiftLine --
852 *
853 * Given two points on a line, compute a point on a
854 * new line that is parallel to the given line and
855 * a given distance away from it.
856 *
857 * Results:
858 * None.
859 *
860 * Side effects:
861 * None.
862 *
863 *--------------------------------------------------------------
864 */
865
866static void
867ShiftLine(p1Ptr, p2Ptr, distance, p3Ptr)
868 XPoint *p1Ptr; /* First point on line. */
869 XPoint *p2Ptr; /* Second point on line. */
870 int distance; /* New line is to be this many
871 * units to the left of original
872 * line, when looking from p1 to
873 * p2. May be negative. */
874 XPoint *p3Ptr; /* Store coords of point on new
875 * line here. */
876{
877 int dx, dy, dxNeg, dyNeg;
878
879 /*
880 * The table below is used for a quick approximation in
881 * computing the new point. An index into the table
882 * is 128 times the slope of the original line (the slope
883 * must always be between 0 and 1). The value of the table
884 * entry is 128 times the amount to displace the new line
885 * in y for each unit of perpendicular distance. In other
886 * words, the table maps from the tangent of an angle to
887 * the inverse of its cosine. If the slope of the original
888 * line is greater than 1, then the displacement is done in
889 * x rather than in y.
890 */
891
892 static int shiftTable[129];
893
894 /*
895 * Initialize the table if this is the first time it is
896 * used.
897 */
898
899 if (shiftTable[0] == 0) {
900 int i;
901 double tangent, cosine;
902
903 for (i = 0; i <= 128; i++) {
904 tangent = i/128.0;
905 cosine = 128/cos(atan(tangent)) + .5;
906 shiftTable[i] = cosine;
907 }
908 }
909
910 *p3Ptr = *p1Ptr;

Callers 1

Tk_Draw3DPolygonFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected