MCPcopy Create free account
hub / github.com/MapServer/MapServer / calc_miter

Method calc_miter

renderers/agg/include/agg_math_stroke.h:210–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208 //-----------------------------------------------------------------------
209 template<class VC>
210 void math_stroke<VC>::calc_miter(VC& vc,
211 const vertex_dist& v0,
212 const vertex_dist& v1,
213 const vertex_dist& v2,
214 double dx1, double dy1,
215 double dx2, double dy2,
216 line_join_e lj,
217 double mlimit,
218 double dbevel)
219 {
220 double xi = v1.x;
221 double yi = v1.y;
222 double di = 1;
223 double lim = m_width_abs * mlimit;
224 bool miter_limit_exceeded = true; // Assume the worst
225 bool intersection_failed = true; // Assume the worst
226
227 if(calc_intersection(v0.x + dx1, v0.y - dy1,
228 v1.x + dx1, v1.y - dy1,
229 v1.x + dx2, v1.y - dy2,
230 v2.x + dx2, v2.y - dy2,
231 &xi, &yi))
232 {
233 // Calculation of the intersection succeeded
234 //---------------------
235 di = calc_distance(v1.x, v1.y, xi, yi);
236 if(di <= lim)
237 {
238 // Inside the miter limit
239 //---------------------
240 add_vertex(vc, xi, yi);
241 miter_limit_exceeded = false;
242 }
243 intersection_failed = false;
244 }
245 else
246 {
247 // Calculation of the intersection failed, most probably
248 // the three points lie one straight line.
249 // First check if v0 and v2 lie on the opposite sides of vector:
250 // (v1.x, v1.y) -> (v1.x+dx1, v1.y-dy1), that is, the perpendicular
251 // to the line determined by vertices v0 and v1.
252 // This condition determines whether the next line segments continues
253 // the previous one or goes back.
254 //----------------
255 double x2 = v1.x + dx1;
256 double y2 = v1.y - dy1;
257 if((cross_product(v0.x, v0.y, v1.x, v1.y, x2, y2) < 0.0) ==
258 (cross_product(v1.x, v1.y, v2.x, v2.y, x2, y2) < 0.0))
259 {
260 // This case means that the next segment continues
261 // the previous one (straight line)
262 //-----------------
263 add_vertex(vc, v1.x + dx1, v1.y - dy1);
264 miter_limit_exceeded = false;
265 }
266 }
267

Callers

nothing calls this directly

Calls 3

calc_intersectionFunction · 0.85
calc_distanceFunction · 0.85
cross_productFunction · 0.85

Tested by

no test coverage detected