summaryrefslogtreecommitdiffstats
path: root/generic/tkTrig.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkTrig.c')
-rw-r--r--generic/tkTrig.c766
1 files changed, 379 insertions, 387 deletions
diff --git a/generic/tkTrig.c b/generic/tkTrig.c
index f3561b1..4dbf755 100644
--- a/generic/tkTrig.c
+++ b/generic/tkTrig.c
@@ -1,18 +1,17 @@
-/*
+/*
* tkTrig.c --
*
- * This file contains a collection of trigonometry utility
- * routines that are used by Tk and in particular by the
- * canvas code. It also has miscellaneous geometry functions
- * used by canvases.
+ * This file contains a collection of trigonometry utility routines that
+ * are used by Tk and in particular by the canvas code. It also has
+ * miscellaneous geometry functions used by canvases.
*
* Copyright (c) 1992-1994 The Regents of the University of California.
* Copyright (c) 1994-1997 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkTrig.c,v 1.5 2004/08/19 14:41:52 dkf Exp $
+ * RCS: @(#) $Id: tkTrig.c,v 1.6 2005/08/18 18:32:38 dkf Exp $
*/
#include <stdio.h>
@@ -36,9 +35,8 @@
* Compute the distance from a point to a finite line segment.
*
* Results:
- * The return value is the distance from the line segment
- * whose end-points are *end1Ptr and *end2Ptr to the point
- * given by *pointPtr.
+ * The return value is the distance from the line segment whose
+ * end-points are *end1Ptr and *end2Ptr to the point given by *pointPtr.
*
* Side effects:
* None.
@@ -55,9 +53,9 @@ TkLineToPoint(end1Ptr, end2Ptr, pointPtr)
double x, y;
/*
- * Compute the point on the line that is closest to the
- * point. This must be done separately for vertical edges,
- * horizontal edges, and other edges.
+ * Compute the point on the line that is closest to the point. This must
+ * be done separately for vertical edges, horizontal edges, and other
+ * edges.
*/
if (end1Ptr[0] == end2Ptr[0]) {
@@ -92,10 +90,10 @@ TkLineToPoint(end1Ptr, end2Ptr, pointPtr)
double m1, b1, m2, b2;
/*
- * The edge is neither horizontal nor vertical. Convert the
- * edge to a line equation of the form y = m1*x + b1. Then
- * compute a line perpendicular to this edge but passing
- * through the point, also in the form y = m2*x + b2.
+ * The edge is neither horizontal nor vertical. Convert the edge to a
+ * line equation of the form y = m1*x + b1. Then compute a line
+ * perpendicular to this edge but passing through the point, also in
+ * the form y = m2*x + b2.
*/
m1 = (end2Ptr[1] - end1Ptr[1])/(end2Ptr[0] - end1Ptr[0]);
@@ -135,14 +133,14 @@ TkLineToPoint(end1Ptr, end2Ptr, pointPtr)
*
* TkLineToArea --
*
- * Determine whether a line lies entirely inside, entirely
- * outside, or overlapping a given rectangular area.
+ * Determine whether a line lies entirely inside, entirely outside, or
+ * overlapping a given rectangular area.
*
* Results:
- * -1 is returned if the line given by end1Ptr and end2Ptr
- * is entirely outside the rectangle given by rectPtr. 0 is
- * returned if the polygon overlaps the rectangle, and 1 is
- * returned if the polygon is entirely inside the rectangle.
+ * -1 is returned if the line given by end1Ptr and end2Ptr is entirely
+ * outside the rectangle given by rectPtr. 0 is returned if the polygon
+ * overlaps the rectangle, and 1 is returned if the polygon is entirely
+ * inside the rectangle.
*
* Side effects:
* None.
@@ -152,19 +150,19 @@ TkLineToPoint(end1Ptr, end2Ptr, pointPtr)
int
TkLineToArea(end1Ptr, end2Ptr, rectPtr)
- double end1Ptr[2]; /* X and y coordinates for one endpoint
- * of line. */
- double end2Ptr[2]; /* X and y coordinates for other endpoint
- * of line. */
+ double end1Ptr[2]; /* X and y coordinates for one endpoint of
+ * line. */
+ double end2Ptr[2]; /* X and y coordinates for other endpoint of
+ * line. */
double rectPtr[4]; /* Points to coords for rectangle, in the
- * order x1, y1, x2, y2. X1 must be no
- * larger than x2, and y1 no larger than y2. */
+ * order x1, y1, x2, y2. X1 must be no larger
+ * than x2, and y1 no larger than y2. */
{
int inside1, inside2;
/*
- * First check the two points individually to see whether they
- * are inside the rectangle or not.
+ * First check the two points individually to see whether they are inside
+ * the rectangle or not.
*/
inside1 = (end1Ptr[0] >= rectPtr[0]) && (end1Ptr[0] <= rectPtr[2])
@@ -179,17 +177,16 @@ TkLineToArea(end1Ptr, end2Ptr, rectPtr)
}
/*
- * Both points are outside the rectangle, but still need to check
- * for intersections between the line and the rectangle. Horizontal
- * and vertical lines are particularly easy, so handle them
- * separately.
+ * Both points are outside the rectangle, but still need to check for
+ * intersections between the line and the rectangle. Horizontal and
+ * vertical lines are particularly easy, so handle them separately.
*/
if (end1Ptr[0] == end2Ptr[0]) {
/*
* Vertical line.
*/
-
+
if (((end1Ptr[1] >= rectPtr[1]) ^ (end2Ptr[1] >= rectPtr[1]))
&& (end1Ptr[0] >= rectPtr[0])
&& (end1Ptr[0] <= rectPtr[2])) {
@@ -199,7 +196,7 @@ TkLineToArea(end1Ptr, end2Ptr, rectPtr)
/*
* Horizontal line.
*/
-
+
if (((end1Ptr[0] >= rectPtr[0]) ^ (end2Ptr[0] >= rectPtr[0]))
&& (end1Ptr[1] >= rectPtr[1])
&& (end1Ptr[1] <= rectPtr[3])) {
@@ -207,59 +204,63 @@ TkLineToArea(end1Ptr, end2Ptr, rectPtr)
}
} else {
double m, x, y, low, high;
-
+
/*
- * Diagonal line. Compute slope of line and use
- * for intersection checks against each of the
- * sides of the rectangle: left, right, bottom, top.
+ * Diagonal line. Compute slope of line and use for intersection
+ * checks against each of the sides of the rectangle: left, right,
+ * bottom, top.
*/
-
+
m = (end2Ptr[1] - end1Ptr[1])/(end2Ptr[0] - end1Ptr[0]);
if (end1Ptr[0] < end2Ptr[0]) {
- low = end1Ptr[0]; high = end2Ptr[0];
+ low = end1Ptr[0];
+ high = end2Ptr[0];
} else {
- low = end2Ptr[0]; high = end1Ptr[0];
+ low = end2Ptr[0];
+ high = end1Ptr[0];
}
-
+
/*
* Left edge.
*/
-
+
y = end1Ptr[1] + (rectPtr[0] - end1Ptr[0])*m;
if ((rectPtr[0] >= low) && (rectPtr[0] <= high)
&& (y >= rectPtr[1]) && (y <= rectPtr[3])) {
return 0;
}
-
+
/*
* Right edge.
*/
-
+
y += (rectPtr[2] - rectPtr[0])*m;
if ((y >= rectPtr[1]) && (y <= rectPtr[3])
&& (rectPtr[2] >= low) && (rectPtr[2] <= high)) {
return 0;
}
-
+
/*
* Bottom edge.
*/
-
+
if (end1Ptr[1] < end2Ptr[1]) {
- low = end1Ptr[1]; high = end2Ptr[1];
+ low = end1Ptr[1];
+ high = end2Ptr[1];
} else {
- low = end2Ptr[1]; high = end1Ptr[1];
+ low = end2Ptr[1];
+ high = end1Ptr[1];
}
x = end1Ptr[0] + (rectPtr[1] - end1Ptr[1])/m;
if ((x >= rectPtr[0]) && (x <= rectPtr[2])
&& (rectPtr[1] >= low) && (rectPtr[1] <= high)) {
return 0;
}
-
+
/*
* Top edge.
*/
-
+
x += (rectPtr[3] - rectPtr[1])/m;
if ((x >= rectPtr[0]) && (x <= rectPtr[2])
&& (rectPtr[3] >= low) && (rectPtr[3] <= high)) {
@@ -274,14 +275,13 @@ TkLineToArea(end1Ptr, end2Ptr, rectPtr)
*
* TkThickPolyLineToArea --
*
- * This procedure is called to determine whether a connected
- * series of line segments lies entirely inside, entirely
- * outside, or overlapping a given rectangular area.
+ * This function is called to determine whether a connected series of
+ * line segments lies entirely inside, entirely outside, or overlapping a
+ * given rectangular area.
*
* Results:
- * -1 is returned if the lines are entirely outside the area,
- * 0 if they overlap, and 1 if they are entirely inside the
- * given area.
+ * -1 is returned if the lines are entirely outside the area, 0 if they
+ * overlap, and 1 if they are entirely inside the given area.
*
* Side effects:
* None.
@@ -292,8 +292,8 @@ TkLineToArea(end1Ptr, end2Ptr, rectPtr)
/* ARGSUSED */
int
TkThickPolyLineToArea(coordPtr, numPoints, width, capStyle, joinStyle, rectPtr)
- double *coordPtr; /* Points to an array of coordinates for
- * the polyline: x0, y0, x1, y1, ... */
+ double *coordPtr; /* Points to an array of coordinates for the
+ * polyline: x0, y0, x1, y1, ... */
int numPoints; /* Total number of points at *coordPtr. */
double width; /* Width of each line segment. */
int capStyle; /* How are end-points of polyline drawn?
@@ -304,15 +304,14 @@ TkThickPolyLineToArea(coordPtr, numPoints, width, capStyle, joinStyle, rectPtr)
{
double radius, poly[10];
int count;
- int changedMiterToBevel; /* Non-zero means that a mitered corner
- * had to be treated as beveled after all
- * because the angle was < 11 degrees. */
- int inside; /* Tentative guess about what to return,
- * based on all points seen so far: one
- * means everything seen so far was
- * inside the area; -1 means everything
- * was outside the area. 0 means overlap
- * has been found. */
+ int changedMiterToBevel; /* Non-zero means that a mitered corner had to
+ * be treated as beveled after all because the
+ * angle was < 11 degrees. */
+ int inside; /* Tentative guess about what to return, based
+ * on all points seen so far: one means
+ * everything seen so far was inside the area;
+ * -1 means everything was outside the area.
+ * 0 means overlap has been found. */
radius = width/2.0;
inside = -1;
@@ -323,19 +322,16 @@ TkThickPolyLineToArea(coordPtr, numPoints, width, capStyle, joinStyle, rectPtr)
}
/*
- * Iterate through all of the edges of the line, computing a polygon
- * for each edge and testing the area against that polygon. In
- * addition, there are additional tests to deal with rounded joints
- * and caps.
+ * Iterate through all of the edges of the line, computing a polygon for
+ * each edge and testing the area against that polygon. In addition, there
+ * are additional tests to deal with rounded joints and caps.
*/
changedMiterToBevel = 0;
for (count = numPoints; count >= 2; count--, coordPtr += 2) {
-
/*
- * If rounding is done around the first point of the edge
- * then test a circular region around the point with the
- * area.
+ * If rounding is done around the first point of the edge then test a
+ * circular region around the point with the area.
*/
if (((capStyle == CapRound) && (count == numPoints))
@@ -350,9 +346,9 @@ TkThickPolyLineToArea(coordPtr, numPoints, width, capStyle, joinStyle, rectPtr)
}
/*
- * Compute the polygonal shape corresponding to this edge,
- * consisting of two points for the first point of the edge
- * and two points for the last point of the edge.
+ * Compute the polygonal shape corresponding to this edge, consisting
+ * of two points for the first point of the edge and two points for
+ * the last point of the edge.
*/
if (count == numPoints) {
@@ -367,10 +363,10 @@ TkThickPolyLineToArea(coordPtr, numPoints, width, capStyle, joinStyle, rectPtr)
TkGetButtPoints(coordPtr+2, coordPtr, width, 0, poly, poly+2);
/*
- * If the last joint was beveled, then also check a
- * polygon comprising the last two points of the previous
- * polygon and the first two from this polygon; this checks
- * the wedges that fill the beveled joint.
+ * If the last joint was beveled, then also check a polygon
+ * comprising the last two points of the previous polygon and the
+ * first two from this polygon; this checks the wedges that fill
+ * the beveled joint.
*/
if ((joinStyle == JoinBevel) || changedMiterToBevel) {
@@ -403,8 +399,7 @@ TkThickPolyLineToArea(coordPtr, numPoints, width, capStyle, joinStyle, rectPtr)
}
/*
- * If caps are rounded, check the cap around the final point
- * of the line.
+ * If caps are rounded, check the cap around the final point of the line.
*/
if (capStyle == CapRound) {
@@ -428,10 +423,9 @@ TkThickPolyLineToArea(coordPtr, numPoints, width, capStyle, joinStyle, rectPtr)
* Compute the distance from a point to a polygon.
*
* Results:
- * The return value is 0.0 if the point referred to by
- * pointPtr is within the polygon referred to by polyPtr
- * and numPoints. Otherwise the return value is the
- * distance of the point from the polygon.
+ * The return value is 0.0 if the point referred to by pointPtr is within
+ * the polygon referred to by polyPtr and numPoints. Otherwise the return
+ * value is the distance of the point from the polygon.
*
* Side effects:
* None.
@@ -441,14 +435,14 @@ TkThickPolyLineToArea(coordPtr, numPoints, width, capStyle, joinStyle, rectPtr)
double
TkPolygonToPoint(polyPtr, numPoints, pointPtr)
- double *polyPtr; /* Points to an array coordinates for
- * closed polygon: x0, y0, x1, y1, ...
- * The polygon may be self-intersecting. */
+ double *polyPtr; /* Points to an array coordinates for closed
+ * polygon: x0, y0, x1, y1, ... The polygon
+ * may be self-intersecting. */
int numPoints; /* Total number of points at *polyPtr. */
double *pointPtr; /* Points to coords for point. */
{
- double bestDist; /* Closest distance between point and
- * any edge in polygon. */
+ double bestDist; /* Closest distance between point and any edge
+ * in polygon. */
int intersections; /* Number of edges in the polygon that
* intersect a ray extending vertically
* upwards from the point to infinity. */
@@ -456,13 +450,12 @@ TkPolygonToPoint(polyPtr, numPoints, pointPtr)
register double *pPtr;
/*
- * Iterate through all of the edges in the polygon, updating
- * bestDist and intersections.
+ * Iterate through all of the edges in the polygon, updating bestDist and
+ * intersections.
*
- * TRICKY POINT: when computing intersections, include left
- * x-coordinate of line within its range, but not y-coordinate.
- * Otherwise if the point lies exactly below a vertex we'll
- * count it as two intersections.
+ * TRICKY POINT: when computing intersections, include left x-coordinate
+ * of line within its range, but not y-coordinate. Otherwise if the point
+ * lies exactly below a vertex we'll count it as two intersections.
*/
bestDist = 1.0e36;
@@ -472,10 +465,9 @@ TkPolygonToPoint(polyPtr, numPoints, pointPtr)
double x, y, dist;
/*
- * Compute the point on the current edge closest to the point
- * and update the intersection count. This must be done
- * separately for vertical edges, horizontal edges, and
- * other edges.
+ * Compute the point on the current edge closest to the point and
+ * update the intersection count. This must be done separately for
+ * vertical edges, horizontal edges, and other edges.
*/
if (pPtr[2] == pPtr[0]) {
@@ -516,13 +508,13 @@ TkPolygonToPoint(polyPtr, numPoints, pointPtr)
}
} else {
double m1, b1, m2, b2;
- int lower; /* Non-zero means point below line. */
+ int lower; /* Non-zero means point below line. */
/*
- * The edge is neither horizontal nor vertical. Convert the
- * edge to a line equation of the form y = m1*x + b1. Then
- * compute a line perpendicular to this edge but passing
- * through the point, also in the form y = m2*x + b2.
+ * The edge is neither horizontal nor vertical. Convert the edge
+ * to a line equation of the form y = m1*x + b1. Then compute a
+ * line perpendicular to this edge but passing through the point,
+ * also in the form y = m2*x + b2.
*/
m1 = (pPtr[3] - pPtr[1])/(pPtr[2] - pPtr[0]);
@@ -556,8 +548,8 @@ TkPolygonToPoint(polyPtr, numPoints, pointPtr)
}
/*
- * Compute the distance to the closest point, and see if that
- * is the best distance seen so far.
+ * Compute the distance to the closest point, and see if that is the
+ * best distance seen so far.
*/
dist = hypot(pointPtr[0] - x, pointPtr[1] - y);
@@ -567,8 +559,8 @@ TkPolygonToPoint(polyPtr, numPoints, pointPtr)
}
/*
- * We've processed all of the points. If the number of intersections
- * is odd, the point is inside the polygon.
+ * We've processed all of the points. If the number of intersections is
+ * odd, the point is inside the polygon.
*/
if (intersections & 0x1) {
@@ -582,14 +574,14 @@ TkPolygonToPoint(polyPtr, numPoints, pointPtr)
*
* TkPolygonToArea --
*
- * Determine whether a polygon lies entirely inside, entirely
- * outside, or overlapping a given rectangular area.
+ * Determine whether a polygon lies entirely inside, entirely outside, or
+ * overlapping a given rectangular area.
*
* Results:
- * -1 is returned if the polygon given by polyPtr and numPoints
- * is entirely outside the rectangle given by rectPtr. 0 is
- * returned if the polygon overlaps the rectangle, and 1 is
- * returned if the polygon is entirely inside the rectangle.
+ * -1 is returned if the polygon given by polyPtr and numPoints is
+ * entirely outside the rectangle given by rectPtr. 0 is returned if the
+ * polygon overlaps the rectangle, and 1 is returned if the polygon is
+ * entirely inside the rectangle.
*
* Side effects:
* None.
@@ -599,13 +591,13 @@ TkPolygonToPoint(polyPtr, numPoints, pointPtr)
int
TkPolygonToArea(polyPtr, numPoints, rectPtr)
- double *polyPtr; /* Points to an array coordinates for
- * closed polygon: x0, y0, x1, y1, ...
- * The polygon may be self-intersecting. */
+ double *polyPtr; /* Points to an array coordinates for closed
+ * polygon: x0, y0, x1, y1, ... The polygon
+ * may be self-intersecting. */
int numPoints; /* Total number of points at *polyPtr. */
register double *rectPtr; /* Points to coords for rectangle, in the
- * order x1, y1, x2, y2. X1 and y1 must
- * be lower-left corner. */
+ * order x1, y1, x2, y2. X1 and y1 must be
+ * lower-left corner. */
{
int state; /* State of all edges seen so far (-1 means
* outside, 1 means inside, won't ever be
@@ -614,9 +606,8 @@ TkPolygonToArea(polyPtr, numPoints, rectPtr)
register double *pPtr;
/*
- * Iterate over all of the edges of the polygon and test them
- * against the rectangle. Can quit as soon as the state becomes
- * "intersecting".
+ * Iterate over all of the edges of the polygon and test them against the
+ * rectangle. Can quit as soon as the state becomes "intersecting".
*/
state = TkLineToArea(polyPtr, polyPtr+2, rectPtr);
@@ -631,10 +622,10 @@ TkPolygonToArea(polyPtr, numPoints, rectPtr)
}
/*
- * If all of the edges were inside the rectangle we're done.
- * If all of the edges were outside, then the rectangle could
- * still intersect the polygon (if it's entirely enclosed).
- * Call TkPolygonToPoint to figure this out.
+ * If all of the edges were inside the rectangle we're done. If all of the
+ * edges were outside, then the rectangle could still intersect the
+ * polygon (if it's entirely enclosed). Call TkPolygonToPoint to figure
+ * this out.
*/
if (state == 1) {
@@ -651,17 +642,16 @@ TkPolygonToArea(polyPtr, numPoints, rectPtr)
*
* TkOvalToPoint --
*
- * Computes the distance from a given point to a given
- * oval, in canvas units.
+ * Computes the distance from a given point to a given oval, in canvas
+ * units.
*
* Results:
- * The return value is 0 if the point given by *pointPtr is
- * inside the oval. If the point isn't inside the
- * oval then the return value is approximately the distance
- * from the point to the oval. If the oval is filled, then
- * anywhere in the interior is considered "inside"; if
- * the oval isn't filled, then "inside" means only the area
- * occupied by the outline.
+ * The return value is 0 if the point given by *pointPtr is inside the
+ * oval. If the point isn't inside the oval then the return value is
+ * approximately the distance from the point to the oval. If the oval is
+ * filled, then anywhere in the interior is considered "inside"; if the
+ * oval isn't filled, then "inside" means only the area occupied by the
+ * outline.
*
* Side effects:
* None.
@@ -672,21 +662,22 @@ TkPolygonToArea(polyPtr, numPoints, rectPtr)
/* ARGSUSED */
double
TkOvalToPoint(ovalPtr, width, filled, pointPtr)
- double ovalPtr[4]; /* Pointer to array of four coordinates
- * (x1, y1, x2, y2) defining oval's bounding
+ double ovalPtr[4]; /* Pointer to array of four coordinates (x1,
+ * y1, x2, y2) defining oval's bounding
* box. */
double width; /* Width of outline for oval. */
int filled; /* Non-zero means oval should be treated as
- * filled; zero means only consider outline. */
+ * filled; zero means only consider
+ * outline. */
double pointPtr[2]; /* Coordinates of point. */
{
double xDelta, yDelta, scaledDistance, distToOutline, distToCenter;
double xDiam, yDiam;
/*
- * Compute the distance between the center of the oval and the
- * point in question, using a coordinate system where the oval
- * has been transformed to a circle with unit radius.
+ * Compute the distance between the center of the oval and the point in
+ * question, using a coordinate system where the oval has been transformed
+ * to a circle with unit radius.
*/
xDelta = (pointPtr[0] - (ovalPtr[0] + ovalPtr[2])/2.0);
@@ -695,16 +686,14 @@ TkOvalToPoint(ovalPtr, width, filled, pointPtr)
scaledDistance = hypot(xDelta / ((ovalPtr[2] + width - ovalPtr[0])/2.0),
yDelta / ((ovalPtr[3] + width - ovalPtr[1])/2.0));
-
/*
- * If the scaled distance is greater than 1 then it means no
- * hit. Compute the distance from the point to the edge of
- * the circle, then scale this distance back to the original
- * coordinate system.
+ * If the scaled distance is greater than 1 then it means no hit. Compute
+ * the distance from the point to the edge of the circle, then scale this
+ * distance back to the original coordinate system.
*
- * Note: this distance isn't completely accurate. It's only
- * an approximation, and it can overestimate the correct
- * distance when the oval is eccentric.
+ * Note: this distance isn't completely accurate. It's only an
+ * approximation, and it can overestimate the correct distance when the
+ * oval is eccentric.
*/
if (scaledDistance > 1.0) {
@@ -712,11 +701,11 @@ TkOvalToPoint(ovalPtr, width, filled, pointPtr)
}
/*
- * Scaled distance less than 1 means the point is inside the
- * outer edge of the oval. If this is a filled oval, then we
- * have a hit. Otherwise, do the same computation as above
- * (scale back to original coordinate system), but also check
- * to see if the point is within the width of the outline.
+ * Scaled distance less than 1 means the point is inside the outer edge of
+ * the oval. If this is a filled oval, then we have a hit. Otherwise, do
+ * the same computation as above (scale back to original coordinate
+ * system), but also check to see if the point is within the width of the
+ * outline.
*/
if (filled) {
@@ -727,9 +716,9 @@ TkOvalToPoint(ovalPtr, width, filled, pointPtr)
- width;
} else {
/*
- * Avoid dividing by a very small number (it could cause an
- * arithmetic overflow). This problem occurs if the point is
- * very close to the center of the oval.
+ * Avoid dividing by a very small number (it could cause an arithmetic
+ * overflow). This problem occurs if the point is very close to the
+ * center of the oval.
*/
xDiam = ovalPtr[2] - ovalPtr[0];
@@ -752,14 +741,14 @@ TkOvalToPoint(ovalPtr, width, filled, pointPtr)
*
* TkOvalToArea --
*
- * Determine whether an oval lies entirely inside, entirely
- * outside, or overlapping a given rectangular area.
+ * Determine whether an oval lies entirely inside, entirely outside, or
+ * overlapping a given rectangular area.
*
* Results:
- * -1 is returned if the oval described by ovalPtr is entirely
- * outside the rectangle given by rectPtr. 0 is returned if the
- * oval overlaps the rectangle, and 1 is returned if the oval
- * is entirely inside the rectangle.
+ * -1 is returned if the oval described by ovalPtr is entirely outside
+ * the rectangle given by rectPtr. 0 is returned if the oval overlaps the
+ * rectangle, and 1 is returned if the oval is entirely inside the
+ * rectangle.
*
* Side effects:
* None.
@@ -771,17 +760,17 @@ int
TkOvalToArea(ovalPtr, rectPtr)
register double *ovalPtr; /* Points to coordinates definining the
* bounding rectangle for the oval: x1, y1,
- * x2, y2. X1 must be less than x2 and y1
- * less than y2. */
+ * x2, y2. X1 must be less than x2 and y1 less
+ * than y2. */
register double *rectPtr; /* Points to coords for rectangle, in the
- * order x1, y1, x2, y2. X1 and y1 must
- * be lower-left corner. */
+ * order x1, y1, x2, y2. X1 and y1 must be
+ * lower-left corner. */
{
double centerX, centerY, radX, radY, deltaX, deltaY;
/*
- * First, see if oval is entirely inside rectangle or entirely
- * outside rectangle.
+ * First, see if oval is entirely inside rectangle or entirely outside
+ * rectangle.
*/
if ((rectPtr[0] <= ovalPtr[0]) && (rectPtr[2] >= ovalPtr[2])
@@ -794,11 +783,10 @@ TkOvalToArea(ovalPtr, rectPtr)
}
/*
- * Next, go through the rectangle side by side. For each side
- * of the rectangle, find the point on the side that is closest
- * to the oval's center, and see if that point is inside the
- * oval. If at least one such point is inside the oval, then
- * the rectangle intersects the oval.
+ * Next, go through the rectangle side by side. For each side of the
+ * rectangle, find the point on the side that is closest to the oval's
+ * center, and see if that point is inside the oval. If at least one such
+ * point is inside the oval, then the rectangle intersects the oval.
*/
centerX = (ovalPtr[0] + ovalPtr[2])/2;
@@ -874,8 +862,8 @@ TkOvalToArea(ovalPtr, rectPtr)
*
* TkIncludePoint --
*
- * Given a point and a generic canvas item header, expand
- * the item's bounding box if needed to include the point.
+ * Given a point and a generic canvas item header, expand the item's
+ * bounding box if needed to include the point.
*
* Results:
* None.
@@ -889,10 +877,10 @@ TkOvalToArea(ovalPtr, rectPtr)
/* ARGSUSED */
void
TkIncludePoint(itemPtr, pointPtr)
- register Tk_Item *itemPtr; /* Item whose bounding box is
- * being calculated. */
- double *pointPtr; /* Address of two doubles giving
- * x and y coordinates of point. */
+ register Tk_Item *itemPtr; /* Item whose bounding box is being
+ * calculated. */
+ double *pointPtr; /* Address of two doubles giving x and y
+ * coordinates of point. */
{
int tmp;
@@ -917,15 +905,14 @@ TkIncludePoint(itemPtr, pointPtr)
*
* TkBezierScreenPoints --
*
- * Given four control points, create a larger set of XPoints
- * for a Bezier curve based on the points.
+ * Given four control points, create a larger set of XPoints for a Bezier
+ * curve based on the points.
*
* Results:
* The array at *xPointPtr gets filled in with numSteps XPoints
- * corresponding to the Bezier spline defined by the four
- * control points. Note: no output point is generated for the
- * first input point, but an output point *is* generated for
- * the last input point.
+ * corresponding to the Bezier spline defined by the four control points.
+ * Note: no output point is generated for the first input point, but an
+ * output point *is* generated for the last input point.
*
* Side effects:
* None.
@@ -935,14 +922,11 @@ TkIncludePoint(itemPtr, pointPtr)
void
TkBezierScreenPoints(canvas, control, numSteps, xPointPtr)
- Tk_Canvas canvas; /* Canvas in which curve is to be
- * drawn. */
- double control[]; /* Array of coordinates for four
- * control points: x0, y0, x1, y1,
- * ... x3 y3. */
- int numSteps; /* Number of curve points to
- * generate. */
- register XPoint *xPointPtr; /* Where to put new points. */
+ Tk_Canvas canvas; /* Canvas in which curve is to be drawn. */
+ double control[]; /* Array of coordinates for four control
+ * points: x0, y0, x1, y1, ... x3 y3. */
+ int numSteps; /* Number of curve points to generate. */
+ register XPoint *xPointPtr; /* Where to put new points. */
{
int i;
double u, u2, u3, t, t2, t3;
@@ -968,15 +952,14 @@ TkBezierScreenPoints(canvas, control, numSteps, xPointPtr)
*
* TkBezierPoints --
*
- * Given four control points, create a larger set of points
- * for a Bezier curve based on the points.
+ * Given four control points, create a larger set of points for a Bezier
+ * curve based on the points.
*
* Results:
- * The array at *coordPtr gets filled in with 2*numSteps
- * coordinates, which correspond to the Bezier spline defined
- * by the four control points. Note: no output point is
- * generated for the first input point, but an output point
- * *is* generated for the last input point.
+ * The array at *coordPtr gets filled in with 2*numSteps coordinates,
+ * which correspond to the Bezier spline defined by the four control
+ * points. Note: no output point is generated for the first input point,
+ * but an output point *is* generated for the last input point.
*
* Side effects:
* None.
@@ -986,12 +969,10 @@ TkBezierScreenPoints(canvas, control, numSteps, xPointPtr)
void
TkBezierPoints(control, numSteps, coordPtr)
- double control[]; /* Array of coordinates for four
- * control points: x0, y0, x1, y1,
- * ... x3 y3. */
- int numSteps; /* Number of curve points to
- * generate. */
- register double *coordPtr; /* Where to put new points. */
+ double control[]; /* Array of coordinates for four control
+ * points: x0, y0, x1, y1, ... x3 y3. */
+ int numSteps; /* Number of curve points to generate. */
+ register double *coordPtr; /* Where to put new points. */
{
int i;
double u, u2, u3, t, t2, t3;
@@ -1015,22 +996,21 @@ TkBezierPoints(control, numSteps, coordPtr)
*
* TkMakeBezierCurve --
*
- * Given a set of points, create a new set of points that fit
- * parabolic splines to the line segments connecting the original
- * points. Produces output points in either of two forms.
+ * Given a set of points, create a new set of points that fit parabolic
+ * splines to the line segments connecting the original points. Produces
+ * output points in either of two forms.
*
- * Note: the name of this procedure should *not* be taken to
- * mean that it interprets the input points as directly defining
- * Bezier curves. Rather, it internally computes a Bezier curve
- * representation of each parabolic spline segment. (These
- * Bezier curves are then flattened to produce the points
- * filled into the output arrays.)
+ * Note: the name of this function should *not* be taken to mean that it
+ * interprets the input points as directly defining Bezier curves.
+ * Rather, it internally computes a Bezier curve representation of each
+ * parabolic spline segment. (These Bezier curves are then flattened to
+ * produce the points filled into the output arrays.)
*
* Results:
- * Either or both of the xPoints or dblPoints arrays are filled
- * in. The return value is the number of points placed in the
- * arrays. Note: if the first and last points are the same, then
- * a closed curve is generated.
+ * Either or both of the xPoints or dblPoints arrays are filled in. The
+ * return value is the number of points placed in the arrays. Note: if
+ * the first and last points are the same, then a closed curve is
+ * generated.
*
* Side effects:
* None.
@@ -1040,39 +1020,39 @@ TkBezierPoints(control, numSteps, coordPtr)
int
TkMakeBezierCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
- Tk_Canvas canvas; /* Canvas in which curve is to be
- * drawn. */
- double *pointPtr; /* Array of input coordinates: x0,
- * y0, x1, y1, etc.. */
- int numPoints; /* Number of points at pointPtr. */
- int numSteps; /* Number of steps to use for each
- * spline segments (determines
- * smoothness of curve). */
- XPoint xPoints[]; /* Array of XPoints to fill in (e.g.
- * for display. NULL means don't
- * fill in any XPoints. */
- double dblPoints[]; /* Array of points to fill in as
- * doubles, in the form x0, y0,
- * x1, y1, .... NULL means don't
- * fill in anything in this form.
- * Caller must make sure that this
- * array has enough space. */
+ Tk_Canvas canvas; /* Canvas in which curve is to be drawn. */
+ double *pointPtr; /* Array of input coordinates: x0, y0, x1, y1,
+ * etc.. */
+ int numPoints; /* Number of points at pointPtr. */
+ int numSteps; /* Number of steps to use for each spline
+ * segments (determines smoothness of
+ * curve). */
+ XPoint xPoints[]; /* Array of XPoints to fill in (e.g. for
+ * display). NULL means don't fill in any
+ * XPoints. */
+ double dblPoints[]; /* Array of points to fill in as doubles, in
+ * the form x0, y0, x1, y1, .... NULL means
+ * don't fill in anything in this form.
+ * Caller must make sure that this array has
+ * enough space. */
{
int closed, outputPoints, i;
int numCoords = numPoints*2;
double control[8];
/*
- * If the curve is a closed one then generate a special spline
- * that spans the last points and the first ones. Otherwise
- * just put the first point into the output.
+ * If the curve is a closed one then generate a special spline that spans
+ * the last points and the first ones. Otherwise just put the first point
+ * into the output.
*/
if (!pointPtr) {
- /* Of pointPtr == NULL, this function returns an upper limit.
- * of the array size to store the coordinates. This can be
- * used to allocate storage, before the actual coordinates
- * are calculated. */
+ /*
+ * Of pointPtr == NULL, this function returns an upper limit of the
+ * array size to store the coordinates. This can be used to allocate
+ * storage, before the actual coordinates are calculated.
+ */
+
return 1 + numPoints * numSteps;
}
@@ -1118,9 +1098,8 @@ TkMakeBezierCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
for (i = 2; i < numPoints; i++, pointPtr += 2) {
/*
- * Set up the first two control points. This is done
- * differently for the first spline of an open curve
- * than for other cases.
+ * Set up the first two control points. This is done differently for
+ * the first spline of an open curve than for other cases.
*/
if ((i == 2) && !closed) {
@@ -1136,9 +1115,8 @@ TkMakeBezierCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
}
/*
- * Set up the last two control points. This is done
- * differently for the last spline of an open curve
- * than for other cases.
+ * Set up the last two control points. This is done differently for
+ * the last spline of an open curve than for other cases.
*/
if ((i == (numPoints-1)) && !closed) {
@@ -1154,10 +1132,9 @@ TkMakeBezierCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
}
/*
- * If the first two points coincide, or if the last
- * two points coincide, then generate a single
- * straight-line segment by outputting the last control
- * point.
+ * If the first two points coincide, or if the last two points
+ * coincide, then generate a single straight-line segment by
+ * outputting the last control point.
*/
if (((pointPtr[0] == pointPtr[2]) && (pointPtr[1] == pointPtr[3]))
@@ -1200,15 +1177,14 @@ TkMakeBezierCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
*
* TkMakeRawCurve --
*
- * Interpret the given set of points as the raw knots and
- * control points defining a sequence of cubic Bezier curves.
- * Create a new set of points that fit these Bezier curves.
- * Output points are produced in either of two forms.
+ * Interpret the given set of points as the raw knots and control points
+ * defining a sequence of cubic Bezier curves. Create a new set of points
+ * that fit these Bezier curves. Output points are produced in either of
+ * two forms.
*
* Results:
- * Either or both of the xPoints or dblPoints arrays are filled
- * in. The return value is the number of points placed in the
- * arrays.
+ * Either or both of the xPoints or dblPoints arrays are filled in. The
+ * return value is the number of points placed in the arrays.
*
* Side effects:
* None.
@@ -1218,44 +1194,41 @@ TkMakeBezierCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
int
TkMakeRawCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
- Tk_Canvas canvas; /* Canvas in which curve is to be
- * drawn. */
- double *pointPtr; /* Array of input coordinates: x0,
- * y0, x1, y1, etc.. */
- int numPoints; /* Number of points at pointPtr. */
- int numSteps; /* Number of steps to use for each
- * curve segment (determines
- * smoothness of curve). */
- XPoint xPoints[]; /* Array of XPoints to fill in (e.g.
- * for display. NULL means don't
- * fill in any XPoints. */
- double dblPoints[]; /* Array of points to fill in as
- * doubles, in the form x0, y0,
- * x1, y1, .... NULL means don't
- * fill in anything in this form.
- * Caller must make sure that this
- * array has enough space. */
+ Tk_Canvas canvas; /* Canvas in which curve is to be drawn. */
+ double *pointPtr; /* Array of input coordinates: x0, y0, x1, y1,
+ * etc.. */
+ int numPoints; /* Number of points at pointPtr. */
+ int numSteps; /* Number of steps to use for each curve
+ * segment (determines smoothness of
+ * curve). */
+ XPoint xPoints[]; /* Array of XPoints to fill in (e.g. for
+ * display). NULL means don't fill in any
+ * XPoints. */
+ double dblPoints[]; /* Array of points to fill in as doubles, in
+ * the form x0, y0, x1, y1, .... NULL means
+ * don't fill in anything in this form.
+ * Caller must make sure that this array has
+ * enough space. */
{
int outputPoints, i;
int numSegments = (numPoints+1)/3;
double *segPtr;
/*
- * The input describes a curve with s Bezier curve segments if
- * there are 3s+1, 3s, or 3s-1 input points. In the last two
- * cases, 1 or 2 initial points from the first curve segment
- * are reused as defining points also for the last curve segment.
- * In the case of 3s input points, this will automatically close
- * the curve.
+ * The input describes a curve with s Bezier curve segments if there are
+ * 3s+1, 3s, or 3s-1 input points. In the last two cases, 1 or 2 initial
+ * points from the first curve segment are reused as defining points also
+ * for the last curve segment. In the case of 3s input points, this will
+ * automatically close the curve.
*/
if (!pointPtr) {
/*
- * If pointPtr == NULL, this function returns an upper limit.
- * of the array size to store the coordinates. This can be
- * used to allocate storage, before the actual coordinates
- * are calculated.
+ * If pointPtr == NULL, this function returns an upper limit of the
+ * array size to store the coordinates. This can be used to allocate
+ * storage, before the actual coordinates are calculated.
*/
+
return 1 + numSegments * numSteps;
}
@@ -1273,18 +1246,19 @@ TkMakeRawCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
outputPoints += 1;
/*
- * The next loop handles all curve segments except one that
- * overlaps the end of the list of coordinates.
+ * The next loop handles all curve segments except one that overlaps the
+ * end of the list of coordinates.
*/
for (i=numPoints,segPtr=pointPtr ; i>=4 ; i-=3,segPtr+=6) {
if (segPtr[0]==segPtr[2] && segPtr[1]==segPtr[3] &&
segPtr[4]==segPtr[6] && segPtr[5]==segPtr[7]) {
/*
- * The control points on this segment are equal to
- * their neighbouring knots, so this segment is just
- * a straight line. A single point is sufficient.
+ * The control points on this segment are equal to their
+ * neighbouring knots, so this segment is just a straight line. A
+ * single point is sufficient.
*/
+
if (xPoints != NULL) {
Tk_CanvasDrawableCoords(canvas, segPtr[6], segPtr[7],
&xPoints->x, &xPoints->y);
@@ -1300,6 +1274,7 @@ TkMakeRawCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
/*
* This is a generic Bezier curve segment.
*/
+
if (xPoints != NULL) {
TkBezierScreenPoints(canvas, segPtr, numSteps, xPoints);
xPoints += numSteps;
@@ -1313,17 +1288,17 @@ TkMakeRawCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
}
/*
- * If at this point i>1, then there is some point which has not
- * yet been used. Make another curve segment.
+ * If at this point i>1, then there is some point which has not yet been
+ * used. Make another curve segment.
*/
- if (i>1) {
+ if (i > 1) {
int j;
double control[8];
/*
- * Copy the relevant coordinates to control[], so that
- * it can be passed as a unit to e.g. TkBezierPoints.
+ * Copy the relevant coordinates to control[], so that it can be
+ * passed as a unit to e.g. TkBezierPoints.
*/
for (j=0; j<2*i; j++) {
@@ -1340,10 +1315,11 @@ TkMakeRawCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
if (control[0]==control[2] && control[1]==control[3] &&
control[4]==control[6] && control[5]==control[7]) {
/*
- * The control points on this segment are equal to
- * their neighbouring knots, so this segment is just
- * a straight line. A single point is sufficient.
+ * The control points on this segment are equal to their
+ * neighbouring knots, so this segment is just a straight line. A
+ * single point is sufficient.
*/
+
if (xPoints != NULL) {
Tk_CanvasDrawableCoords(canvas, control[6], control[7],
&xPoints->x, &xPoints->y);
@@ -1359,6 +1335,7 @@ TkMakeRawCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
/*
* This is a generic Bezier curve segment.
*/
+
if (xPoints != NULL) {
TkBezierScreenPoints(canvas, control, numSteps, xPoints);
xPoints += numSteps;
@@ -1379,12 +1356,12 @@ TkMakeRawCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
*
* TkMakeBezierPostscript --
*
- * This procedure generates Postscript commands that create
- * a path corresponding to a given Bezier curve.
+ * This function generates Postscript commands that create a path
+ * corresponding to a given Bezier curve.
*
* Results:
- * None. Postscript commands to generate the path are appended
- * to the interp's result.
+ * None. Postscript commands to generate the path are appended to the
+ * interp's result.
*
* Side effects:
* None.
@@ -1394,13 +1371,13 @@ TkMakeRawCurve(canvas, pointPtr, numPoints, numSteps, xPoints, dblPoints)
void
TkMakeBezierPostscript(interp, canvas, pointPtr, numPoints)
- Tcl_Interp *interp; /* Interpreter in whose result the
- * Postscript is to be stored. */
- Tk_Canvas canvas; /* Canvas widget for which the
- * Postscript is being generated. */
- double *pointPtr; /* Array of input coordinates: x0,
- * y0, x1, y1, etc.. */
- int numPoints; /* Number of points at pointPtr. */
+ Tcl_Interp *interp; /* Interpreter in whose result the Postscript
+ * is to be stored. */
+ Tk_Canvas canvas; /* Canvas widget for which the Postscript is
+ * being generated. */
+ double *pointPtr; /* Array of input coordinates: x0, y0, x1, y1,
+ * etc.. */
+ int numPoints; /* Number of points at pointPtr. */
{
int closed, i;
int numCoords = numPoints*2;
@@ -1408,9 +1385,9 @@ TkMakeBezierPostscript(interp, canvas, pointPtr, numPoints)
char buffer[200];
/*
- * If the curve is a closed one then generate a special spline
- * that spans the last points and the first ones. Otherwise
- * just put the first point into the path.
+ * If the curve is a closed one then generate a special spline that spans
+ * the last points and the first ones. Otherwise just put the first point
+ * into the path.
*/
if ((pointPtr[0] == pointPtr[numCoords-2])
@@ -1439,8 +1416,8 @@ TkMakeBezierPostscript(interp, canvas, pointPtr, numPoints)
Tcl_AppendResult(interp, buffer, (char *) NULL);
/*
- * Cycle through all the remaining points in the curve, generating
- * a curve section for each vertex in the linear path.
+ * Cycle through all the remaining points in the curve, generating a curve
+ * section for each vertex in the linear path.
*/
for (i = numPoints-2, pointPtr += 2; i > 0; i--, pointPtr += 2) {
@@ -1448,9 +1425,8 @@ TkMakeBezierPostscript(interp, canvas, pointPtr, numPoints)
control[3] = 0.333*control[7] + 0.667*pointPtr[1];
/*
- * Set up the last two control points. This is done
- * differently for the last spline of an open curve
- * than for other cases.
+ * Set up the last two control points. This is done differently for
+ * the last spline of an open curve than for other cases.
*/
if ((i == 1) && !closed) {
@@ -1476,14 +1452,14 @@ TkMakeBezierPostscript(interp, canvas, pointPtr, numPoints)
*
* TkMakeRawCurvePostscript --
*
- * This procedure interprets the input points as the raw knot
- * and control points for a curve composed of Bezier curve
- * segments, just like TkMakeRawCurve. It generates Postscript
- * commands that create a path corresponding to this given curve.
+ * This function interprets the input points as the raw knot and control
+ * points for a curve composed of Bezier curve segments, just like
+ * TkMakeRawCurve. It generates Postscript commands that create a path
+ * corresponding to this given curve.
*
* Results:
- * None. Postscript commands to generate the path are appended
- * to the interp's result.
+ * None. Postscript commands to generate the path are appended to the
+ * interp's result.
*
* Side effects:
* None.
@@ -1493,13 +1469,13 @@ TkMakeBezierPostscript(interp, canvas, pointPtr, numPoints)
void
TkMakeRawCurvePostscript(interp, canvas, pointPtr, numPoints)
- Tcl_Interp *interp; /* Interpreter in whose result the
- * Postscript is to be stored. */
- Tk_Canvas canvas; /* Canvas widget for which the
- * Postscript is being generated. */
- double *pointPtr; /* Array of input coordinates: x0,
- * y0, x1, y1, etc.. */
- int numPoints; /* Number of points at pointPtr. */
+ Tcl_Interp *interp; /* Interpreter in whose result the Postscript
+ * is to be stored. */
+ Tk_Canvas canvas; /* Canvas widget for which the Postscript is
+ * being generated. */
+ double *pointPtr; /* Array of input coordinates: x0, y0, x1, y1,
+ * etc.. */
+ int numPoints; /* Number of points at pointPtr. */
{
int i;
double *segPtr;
@@ -1514,24 +1490,25 @@ TkMakeRawCurvePostscript(interp, canvas, pointPtr, numPoints)
Tcl_AppendResult(interp, buffer, (char *) NULL);
/*
- * Loop through all the remaining points in the curve, generating
- * a straight line or curve section for every three of them.
+ * Loop through all the remaining points in the curve, generating a
+ * straight line or curve section for every three of them.
*/
for (i=numPoints-1,segPtr=pointPtr ; i>=3 ; i-=3,segPtr+=6) {
if (segPtr[0]==segPtr[2] && segPtr[1]==segPtr[3] &&
segPtr[4]==segPtr[6] && segPtr[5]==segPtr[7]) {
/*
- * The control points on this segment are equal to
- * their neighbouring knots, so this segment is just
- * a straight line.
+ * The control points on this segment are equal to their
+ * neighbouring knots, so this segment is just a straight line.
*/
+
sprintf(buffer, "%.15g %.15g lineto\n",
segPtr[6], Tk_CanvasPsY(canvas, segPtr[7]));
} else {
/*
* This is a generic Bezier curve segment.
*/
+
sprintf(buffer, "%.15g %.15g %.15g %.15g %.15g %.15g curveto\n",
segPtr[2], Tk_CanvasPsY(canvas, segPtr[3]),
segPtr[4], Tk_CanvasPsY(canvas, segPtr[5]),
@@ -1541,12 +1518,11 @@ TkMakeRawCurvePostscript(interp, canvas, pointPtr, numPoints)
}
/*
- * If there are any points left that haven't been used,
- * then build the last segment and generate Postscript in
- * the same way for that.
+ * If there are any points left that haven't been used, then build the
+ * last segment and generate Postscript in the same way for that.
*/
- if (i>0) {
+ if (i > 0) {
int j;
double control[8];
@@ -1559,11 +1535,17 @@ TkMakeRawCurvePostscript(interp, canvas, pointPtr, numPoints)
if (control[0]==control[2] && control[1]==control[3] &&
control[4]==control[6] && control[5]==control[7]) {
- /* Straight line */
+ /*
+ * Straight line.
+ */
+
sprintf(buffer, "%.15g %.15g lineto\n",
control[6], Tk_CanvasPsY(canvas, control[7]));
} else {
- /* Bezier curve segment */
+ /*
+ * Bezier curve segment.
+ */
+
sprintf(buffer, "%.15g %.15g %.15g %.15g %.15g %.15g curveto\n",
control[2], Tk_CanvasPsY(canvas, control[3]),
control[4], Tk_CanvasPsY(canvas, control[5]),
@@ -1578,16 +1560,14 @@ TkMakeRawCurvePostscript(interp, canvas, pointPtr, numPoints)
*
* TkGetMiterPoints --
*
- * Given three points forming an angle, compute the
- * coordinates of the inside and outside points of
- * the mitered corner formed by a line of a given
- * width at that angle.
+ * Given three points forming an angle, compute the coordinates of the
+ * inside and outside points of the mitered corner formed by a line of a
+ * given width at that angle.
*
* Results:
- * If the angle formed by the three points is less than
- * 11 degrees then 0 is returned and m1 and m2 aren't
- * modified. Otherwise 1 is returned and the points at
- * m1 and m2 are filled in with the positions of the points
+ * If the angle formed by the three points is less than 11 degrees then 0
+ * is returned and m1 and m2 aren't modified. Otherwise 1 is returned and
+ * the points at m1 and m2 are filled in with the positions of the points
* of the mitered corner.
*
* Side effects:
@@ -1604,29 +1584,28 @@ TkGetMiterPoints(p1, p2, p3, width, m1, m2)
* for mitered joint. */
double p3[]; /* Points to x- and y-coordinates of point
* after vertex. */
- double width; /* Width of line. */
- double m1[]; /* Points to place to put "left" vertex
- * point (see as you face from p1 to p2). */
+ double width; /* Width of line. */
+ double m1[]; /* Points to place to put "left" vertex point
+ * (see as you face from p1 to p2). */
double m2[]; /* Points to place to put "right" vertex
* point. */
{
double theta1; /* Angle of segment p2-p1. */
double theta2; /* Angle of segment p2-p3. */
- double theta; /* Angle between line segments (angle
- * of joint). */
- double theta3; /* Angle that bisects theta1 and
- * theta2 and points to m1. */
+ double theta; /* Angle between line segments (angle of
+ * joint). */
+ double theta3; /* Angle that bisects theta1 and theta2 and
+ * points to m1. */
double dist; /* Distance of miter points from p2. */
- double deltaX, deltaY; /* X and y offsets cooresponding to
- * dist (fudge factors for bounding
- * box). */
+ double deltaX, deltaY; /* X and y offsets cooresponding to dist
+ * (fudge factors for bounding box). */
double p1x, p1y, p2x, p2y, p3x, p3y;
static double elevenDegrees = (11.0*2.0*PI)/360.0;
/*
- * Round the coordinates to integers to mimic what happens when the
- * line segments are displayed; without this code, the bounding box
- * of a mitered line can be miscomputed greatly.
+ * Round the coordinates to integers to mimic what happens when the line
+ * segments are displayed; without this code, the bounding box of a
+ * mitered line can be miscomputed greatly.
*/
p1x = floor(p1[0]+0.5);
@@ -1643,6 +1622,7 @@ TkGetMiterPoints(p1, p2, p3, width, m1, m2)
} else {
theta1 = atan2(p1y - p2y, p1x - p2x);
}
+
if (p3y == p2y) {
theta2 = (p3x > p2x) ? 0 : PI;
} else if (p3x == p2x) {
@@ -1650,23 +1630,26 @@ TkGetMiterPoints(p1, p2, p3, width, m1, m2)
} else {
theta2 = atan2(p3y - p2y, p3x - p2x);
}
+
theta = theta1 - theta2;
if (theta > PI) {
theta -= 2*PI;
} else if (theta < -PI) {
theta += 2*PI;
}
+
if ((theta < elevenDegrees) && (theta > -elevenDegrees)) {
return 0;
}
+
dist = 0.5*width/sin(0.5*theta);
if (dist < 0.0) {
dist = -dist;
}
/*
- * Compute theta3 (make sure that it points to the left when
- * looking from p1 to p2).
+ * Compute theta3 (make sure that it points to the left when looking from
+ * p1 to p2).
*/
theta3 = (theta1 + theta2)/2.0;
@@ -1679,6 +1662,7 @@ TkGetMiterPoints(p1, p2, p3, width, m1, m2)
deltaY = dist*sin(theta3);
m1[1] = p2y + deltaY;
m2[1] = p2y - deltaY;
+
return 1;
}
@@ -1687,13 +1671,13 @@ TkGetMiterPoints(p1, p2, p3, width, m1, m2)
*
* TkGetButtPoints --
*
- * Given two points forming a line segment, compute the
- * coordinates of two endpoints of a rectangle formed by
- * bloating the line segment until it is width units wide.
+ * Given two points forming a line segment, compute the coordinates of
+ * two endpoints of a rectangle formed by bloating the line segment until
+ * it is width units wide.
*
* Results:
- * There is no return value. M1 and m2 are filled in to
- * correspond to m1 and m2 in the diagram below:
+ * There is no return value. M1 and m2 are filled in to correspond to m1
+ * and m2 in the diagram below:
*
* ----------------* m1
* |
@@ -1701,9 +1685,9 @@ TkGetMiterPoints(p1, p2, p3, width, m1, m2)
* |
* ----------------* m2
*
- * M1 and m2 will be W units apart, with p2 centered between
- * them and m1-m2 perpendicular to p1-p2. However, if
- * "project" is true then m1 and m2 will be as follows:
+ * M1 and m2 will be W units apart, with p2 centered between them and
+ * m1-m2 perpendicular to p1-p2. However, if "project" is true then m1
+ * and m2 will be as follows:
*
* -------------------* m1
* p2 |
@@ -1725,11 +1709,11 @@ TkGetButtPoints(p1, p2, width, project, m1, m2)
* before vertex. */
double p2[]; /* Points to x- and y-coordinates of vertex
* for mitered joint. */
- double width; /* Width of line. */
+ double width; /* Width of line. */
int project; /* Non-zero means project p2 by an additional
* width/2 before computing m1 and m2. */
- double m1[]; /* Points to place to put "left" result
- * point, as you face from p1 to p2. */
+ double m1[]; /* Points to place to put "left" result point,
+ * as you face from p1 to p2. */
double m2[]; /* Points to place to put "right" result
* point. */
{
@@ -1756,3 +1740,11 @@ TkGetButtPoints(p1, p2, width, project, m1, m2)
}
}
}
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 4
+ * fill-column: 78
+ * End:
+ */