74 |
return fabs(c.x * (b.y - a.y) + b.x * (a.y - c.y) + a.x * (c.y - b.y)); |
return fabs(c.x * (b.y - a.y) + b.x * (a.y - c.y) + a.x * (c.y - b.y)); |
75 |
} |
} |
76 |
|
|
77 |
|
|
78 |
|
inline double power(double x, double y) { |
79 |
|
return x < 0 ? -pow(-x,y) : pow(x,y); |
80 |
|
} |
81 |
|
|
82 |
|
inline vector<ZPt> getEllipse(int n, float pow0 = 2.0, float pow1 = 2.0) { |
83 |
|
vector<ZPt> vert(n); |
84 |
|
for (int i = 0; i < n; i++) { |
85 |
|
float a = i * 2*M_PI / n; |
86 |
|
vert[i] = ZPt(power(cos(a), 2 / pow0), |
87 |
|
power(sin(a), 2 / pow1), 0); |
88 |
|
} |
89 |
|
return vert; |
90 |
|
} |
91 |
|
|
92 |
|
template <class Coords> |
93 |
|
void transform(Coords &coords2, vector<ZPt> &pt) { |
94 |
|
for (unsigned i = 0; i < pt.size(); i++) |
95 |
|
pt[i] = coords2.transform(pt[i]); |
96 |
|
} |
97 |
|
|
98 |
|
inline vector<ZVec> computeNorms(vector<ZPt> &pt, unsigned n) { |
99 |
|
vector<ZVec> norm(n + 1); |
100 |
|
for (unsigned i = 0; i <= n; i++) { |
101 |
|
ZVec v1 = (pt[(i+1) % n] - pt[i % n]).cw90().normalize(); |
102 |
|
ZVec v2 = (pt[i % n] - pt[(i+n-1) % n]).cw90().normalize(); |
103 |
|
|
104 |
|
norm[i] = (v1 + v2).normalize(); |
105 |
|
norm[i] *= 1.0 / v1.dot(norm[i]); |
106 |
|
} |
107 |
|
return norm; |
108 |
|
} |
109 |
|
|
110 |
/** Draws an irregular edge. |
/** Draws an irregular edge. |
111 |
* The edge specified in paper coordinates. |
* The edge specified in paper coordinates. |
112 |
* |
* |