Permalink
Browse files

Fix the custom line cap angle calculations, to avoid a divide-by-zero…

…. Also

simplifies the angle calculation for AdjustableArrow.
  • Loading branch information...
1 parent afb6c62 commit 504b5ed306f03b50df5c684cd762985f29f5b20c @dickp dickp committed Oct 15, 2010
Showing with 21 additions and 10 deletions.
  1. +0 −6 src/adjustablearrowcap.c
  2. +21 −4 src/customlinecap.c
View
@@ -123,12 +123,6 @@ gdip_adjust_arrowcap_draw (GpGraphics *graphics, GpPen *pen, GpCustomLineCap *cu
w = arrowcap->width / 2;
h = arrowcap->height;
- /* Vertical lines need some assistance to point the arrowhead correctly */
- if ((x == otherend_x) &&
- (y < otherend_y)) {
- h = -h;
- }
-
angle = gdip_custom_linecap_angle (x, y, otherend_x, otherend_y);
cairo_save (graphics->ct);
View
@@ -153,17 +153,34 @@ gdip_custom_linecap_angle (float x, float y, float otherend_x, float otherend_y)
float slope;
double angle;
- if (y < otherend_y) {
- slope = (otherend_y - y) / (otherend_x - x);
+ if (x == otherend_x) {
+ slope = 0;
+ if (y < otherend_y) {
+ angle = PI;
+ } else {
+ angle = PI * 2;
+ }
+ } else if (y == otherend_y) {
+ slope = 0;
if (x < otherend_x) {
angle = PI/2;
} else {
angle = PI/-2;
}
} else {
- slope = (otherend_x - x) / (y - otherend_y);
- angle = 0;
+ if (y < otherend_y) {
+ slope = (otherend_y - y) / (otherend_x - x);
+ if (x < otherend_x) {
+ angle = PI/2;
+ } else {
+ angle = PI/-2;
+ }
+ } else {
+ slope = (otherend_x - x) / (y - otherend_y);
+ angle = 0;
+ }
}
+
angle += atan (slope);
return angle;

0 comments on commit 504b5ed

Please sign in to comment.