summaryrefslogtreecommitdiffstats
path: root/generic/tkCanvUtil.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2019-03-13 19:16:12 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2019-03-13 19:16:12 (GMT)
commit913c2ffec66a261d7cea357c21cdcda60132c0a5 (patch)
tree50834dfff8ea8a4494f981b6559bbfa604ee7707 /generic/tkCanvUtil.c
parent87a95ec0329c9fd676ed4a5d9d10247eb245a4ec (diff)
downloadtk-913c2ffec66a261d7cea357c21cdcda60132c0a5.zip
tk-913c2ffec66a261d7cea357c21cdcda60132c0a5.tar.gz
tk-913c2ffec66a261d7cea357c21cdcda60132c0a5.tar.bz2
Document. Factor out basic rotation function.
Diffstat (limited to 'generic/tkCanvUtil.c')
-rw-r--r--generic/tkCanvUtil.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/generic/tkCanvUtil.c b/generic/tkCanvUtil.c
index 6ce671d..52d7bf6 100644
--- a/generic/tkCanvUtil.c
+++ b/generic/tkCanvUtil.c
@@ -1265,7 +1265,6 @@ Tk_ChangeOutlineGC(
}
return 0;
}
-
/*
*--------------------------------------------------------------
@@ -1865,6 +1864,43 @@ TkCanvTranslatePath(
}
/*
+ *--------------------------------------------------------------
+ *
+ * TkRotatePoint --
+ *
+ * Rotate a point about another point. The angle should be converted into
+ * its sine and cosine before calling this function.
+ *
+ * Results:
+ * None
+ *
+ * Side effects:
+ * The point in (*xPtr,*yPtr) is updated to be rotated about
+ * (originX,originY) by the amount given by the sine and cosine of the
+ * angle to rotate.
+ *
+ *--------------------------------------------------------------
+ */
+
+void
+TkRotatePoint(
+ double originX, double originY, /* The point about which to rotate. */
+ double sine, double cosine, /* How much to rotate? */
+ double *xPtr, double *yPtr) /* The point to be rotated. (INOUT) */
+{
+ double x = *xPtr - originX;
+ double y = *yPtr - originY;
+
+ /*
+ * Beware! The canvas coordinate space is flipped vertically, so rotations
+ * go the "wrong" way with respect to mathematics.
+ */
+
+ *xPtr = originX + x * cosine + y * sine;
+ *yPtr = originY - x * sine + y * cosine;
+}
+
+/*
* Local Variables:
* mode: c
* c-basic-offset: 4