55 double len0,
len, sum = 0;
56 double diff_x, diff_y, diff_x0, diff_y0;
57 double cos_theta, cos_max = -10;
59 diff_x0 = end.
x-meeting.
x;
60 diff_y0 = end.
y-meeting.
y;
61 len0 = sum = hypot(diff_x0, diff_y0);
65 diff_x = p.x - meeting.
x;
66 diff_y = p.y - meeting.
y;
67 len = hypot(diff_x, diff_y);
69 cos_theta = (diff_x0 * diff_x + diff_y0 * diff_y)
70 / std::max(
len * len0, 0.00001);
71 cos_max = std::max(cos_max, cos_theta);
75 return sum*(cos_max + angle_param);
100 point_t first, second, third, fourth, diff, meeting;
101 double value1, value2, value3, value4;
111 if (angle_param < 1){
167 }
while (fabs(value1 - value4) / (std::min(value1, value4) + 1e-10) > prec
226double ink(
const std::vector<pedge> &edges,
int numEdges,
int *pick,
233 double cend = 0, cbegin = 0;
244 for (i = 0; i < numEdges; i++) {
245 const pedge &e = pick ? edges[pick[i]] : edges[i];
246 const std::vector<double> &x = e.
x;
250 (*ink0) += hypot(source.
x - target.
x, source.
y - target.
y);
267 std::vector<point_t> sources;
268 std::vector<point_t> targets;
269 for (i = 0; i < numEdges; i++) {
270 const pedge &e = pick ? edges[pick[i]] : edges[i];
271 const std::vector<double> &x = e.
x;
272 sources.push_back(
point_t{x[0], x[1]});
280 cbegin = std::max(cbegin,
project_to_line(sources[i], begin, end, angle));
285 if (angle > 0 && angle <
M_PI){
286 if (cbegin + cend > 1 || cbegin > 1 || cend > 1){
288 inkUsed = 1000*(*ink0);
292 cbegin = std::max(0.0, cbegin);
296 cend = std::max(0.0, cend);
301 inkUsed =
bestInk(sources, begin, mid, eps, meet1, angle_param)
302 +
bestInk(targets, end, mid, eps, meet2, angle_param);
double ink(const std::vector< pedge > &edges, int numEdges, int *pick, double *ink0, point_t *meet1, point_t *meet2, double angle_param, double angle)
static double bestInk(const std::vector< point_t > &points, point_t begin, point_t end, double prec, point_t *meet, double angle_param)