@@ 82,6 82,7 @@ Uint8 icons[][8] = {
{0xfe, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfe, 0x00},
{0x1e, 0x06, 0x0a, 0x12, 0x20, 0x40, 0x80, 0x00},
{0x06, 0x18, 0x22, 0x40, 0x42, 0x80, 0xaa, 0x00},
+ {0x02, 0x06, 0x0e, 0x1e, 0x3e, 0x7e, 0xfe, 0x00}, /* triangle */
{0x00, 0x00, 0x00, 0x82, 0x44, 0x38, 0x00, 0x00}, /* eye open */
{0x00, 0x38, 0x44, 0x92, 0x28, 0x10, 0x00, 0x00}, /* eye closed */
{0x10, 0x54, 0x28, 0xc6, 0x28, 0x54, 0x10, 0x00} /* unsaved */
@@ 384,14 385,15 @@ handle(Uint32 *dst, int x0, int y0, int r, int color)
}
int
-intpoint_inside_trigon(Point2d p, Point2d p0, Point2d p1, Point2d p2)
+intri2d(Point2d p, Point2d p0, Point2d p1, Point2d p2)
{
+ int a;
int s = p0.y * p2.x - p0.x * p2.y + (p2.y - p0.y) * p.x + (p0.x - p2.x) * p.y;
int t = p0.x * p1.y - p0.y * p1.x + (p0.y - p1.y) * p.x + (p1.x - p0.x) * p.y;
if((s < 0) != (t < 0))
return 0;
- int A = -p1.y * p2.x + p0.y * (p2.x - p1.x) + p0.x * (p1.y - p2.y) + p1.x * p2.y;
- return A < 0 ? (s <= 0 && s + t >= A) : (s >= 0 && s + t <= A);
+ a = -p1.y * p2.x + p0.y * (p2.x - p1.x) + p0.x * (p1.y - p2.y) + p1.x * p2.y;
+ return a < 0 ? (s <= 0 && s + t >= a) : (s >= 0 && s + t <= a);
}
void
@@ 408,12 410,8 @@ triangle(Uint32 *dst, int x0, int y0, int x1, int y1, int x2, int y2, int color)
int x, y;
for(y = miny; y < maxy; ++y)
for(x = minx; x < maxx; ++x)
- if(intpoint_inside_trigon(Pt2d(x, y), Pt2d(x0, y0), Pt2d(x1, y1), Pt2d(x2, y2)))
- putpixel(dst, x, y, 2);
- rectangle(dst, minx, miny, maxx, maxy, 4);
- line(dst, x0, y0, x1, y1, 1);
- line(dst, x1, y1, x2, y2, 1);
- line(dst, x2, y2, x0, y0, 1);
+ if(intri2d(Pt2d(x, y), Pt2d(x0, y0), Pt2d(x1, y1), Pt2d(x2, y2)))
+ putpixel(dst, x, y, color);
}
void
@@ 525,10 523,9 @@ drawui(Uint32 *dst)
drawicn(dst, 6 * 8, bottom, icons[4], cancast(BEZIER) ? 2 : 3, 0);
drawicn(dst, 7 * 8, bottom, icons[5], cancast(RECTANGLE) ? 2 : 3, 0);
drawicn(dst, 8 * 8, bottom, icons[1], cancast(ELLIPSE) ? 2 : 3, 0);
- drawicn(dst, 9 * 8, bottom, icons[6], cancast(TRANSLATE) ? 2 : 3, 0);
- drawicn(dst, 9 * 8, bottom, icons[6], cancast(TRIANGLE) ? 2 : 3, 0);
- drawicn(dst, 11 * 8, bottom, icons[GUIDES ? 9 : 8], GUIDES ? 1 : 2, 0);
- drawicn(dst, (HOR - 1) * 8, bottom, icons[10], doc.unsaved ? 2 : 3, 0); /* save state */
+ drawicn(dst, 9 * 8, bottom, icons[8], cancast(TRIANGLE) ? 2 : 3, 0);
+ drawicn(dst, 12 * 8, bottom, icons[GUIDES ? 10 : 9], GUIDES ? 1 : 2, 0);
+ drawicn(dst, (HOR - 1) * 8, bottom, icons[11], doc.unsaved ? 2 : 3, 0); /* save state */
}
void
@@ 828,8 825,8 @@ selectoption(int option)
case 6: cast(BEZIER); break;
case 7: cast(RECTANGLE); break;
case 8: cast(ELLIPSE); break;
- case 10: cast(TRANSLATE); break;
- case 11: savemode(&GUIDES, !GUIDES); break;
+ case 9: cast(TRIANGLE); break;
+ case 12: savemode(&GUIDES, !GUIDES); break;
}
}