44# ifndef TREEPIC_UTILS_H
45# define TREEPIC_UTILS_H
79extern const long double sin_45;
80extern const long double cos_45;
134 long double m = (1.0*(ly1 - ly0)) / (1.0*(lx1 - lx0));
135 long double m2 = m*m;
136 long double a2 = a*a;
137 long double b2 = b*b;
138 long double R = m2 + b2/a2;
139 long double L = lx0*lx0 - b2/R;
140 long double S = 1.0/m2 + a2/b2;
141 long double M = ly0*ly0 - a2/S;
143 long double x0_2 = 2.0*lx0;
144 long double xdisc =
sqrt(4.0*lx0*lx0 - 4.0*L);
146 long double ix0 = (x0_2 + xdisc) / 2.0;
151 long double y0_2 = 2.0*ly0;
152 long double ydisc =
sqrt(4.0*ly0*ly0 - 4.0*M);
154 long double iy0 = (y0_2 - ydisc) / 2.0;
173 long double lm = (ly2 - ly1)/(lx2 - lx1);
174 long double rm = (ry2 - ry1)/(rx2 - rx1);
176 x = (lm*lx1 - rm*rx1 + ry1 - ly1)/(lm - rm);
178 long double lm_inv = 1/lm;
179 long double rm_inv = 1/rm;
181 y = (lm_inv*ly1 - rm_inv*ry1 + rx1 - lx1)/(lm_inv - rm_inv);
190 long double a = x2 - x1;
191 long double b = y2 -
y1;
193 return sqrt(a*a + b*b);
224 long double dxh = b * ((lx1 - lx0)/(ly1 - ly0));
229 long double dyv = a * ((ly1 - ly0)/(lx1 - lx0));
235 if (dxh*dxh + dyh*dyh < dxv*dxv + dyv*dyv)
249inline long double YPIC(
long double y)
257 const char * ptr = str.c_str();
259 for (
int i = 0, counter = 0;
true; )
264 for (i++; isalnum(ptr[i]) and ptr[i] not_eq
'\0'; )
268 case '$':
case '{':
case '}':
case '\n':
282 const long double& x,
const long double&
y,
283 const std::string & comment,
const std::string & str)
289 <<
"% " << comment << std::endl
290 <<
"\\put(" << x <<
","
302 const long double& x,
const long double&
y,
303 const std::string & comment,
const std::string & str)
309 <<
"% " << comment << std::endl
310 <<
"\\draw (" << x <<
"mm,"
314 <<
"mm) node { " << str <<
" }" << std::endl << std::endl;
329 long double src_x,
long double src_y,
330 long double tgt_x,
long double tgt_y,
331 bool is_dashed,
bool with_arrow, [[maybe_unused]]
bool thick =
true)
338 << tgt_x <<
"," <<
YPIC(tgt_y) <<
")";
345 long double phi =
atan( std::fabs( (tgt_y - src_y)/(tgt_x - src_x) ) );
347 long double dx1 =
l*
cos(phi - tetha);
348 long double dy1 =
l*
sin(phi - tetha);
350 long double dx2 =
l*
sin(M_PI_2 - (phi + tetha));
351 long double dy2 =
l*
cos(M_PI_2 - (phi + tetha));
366 <<
"\\path(" << tgt_x <<
"," <<
YPIC(tgt_y) <<
")("
367 << tgt_x + dx1 <<
"," <<
YPIC(tgt_y + dy1) <<
")" << std::endl
368 <<
"\\path(" << tgt_x <<
"," <<
YPIC(tgt_y) <<
")("
369 << tgt_x + dx2 <<
"," <<
YPIC(tgt_y + dy2) <<
")" << std::endl << std::endl;
373 long double src_x,
long double src_y,
374 long double tgt_x,
long double tgt_y,
375 bool is_dashed,
bool with_arrow, [[maybe_unused]]
bool thick =
true)
378 output <<
"\\draw[dashed] (";
381 output << src_x <<
"mm," <<
YPIC(src_y) <<
"mm) -- ("
382 << tgt_x <<
"mm," <<
YPIC(tgt_y) <<
"mm) ;";
389 long double phi =
atan( std::fabs( (tgt_y - src_y)/(tgt_x - src_x) ) );
391 long double dx1 =
l*
cos(phi - tetha);
392 long double dy1 =
l*
sin(phi - tetha);
394 long double dx2 =
l*
sin(M_PI_2 - (phi + tetha));
395 long double dy2 =
l*
cos(M_PI_2 - (phi + tetha));
410 <<
"\\draw (" << tgt_x <<
"," <<
YPIC(tgt_y) <<
") -- ("
411 << tgt_x + dx1 <<
"mm," <<
YPIC(tgt_y + dy1) <<
"mm) ; " << std::endl
412 <<
"\\draw (" << tgt_x <<
"mm," <<
YPIC(tgt_y) <<
"mm) -- ("
413 << tgt_x + dx2 <<
"mm," <<
YPIC(tgt_y + dy2) <<
"mm) ; " << std::endl << std::endl;
419inline long double center_string(
const std::string& str, [[maybe_unused]]
long double window_size)
433 long double x2,
long double y2)
435 if (x2 > x1 and y2 >
y1)
438 if (x2 < x1 and y2 >
y1)
443 return x2 > x1 ? 3 : 2;
451 const long double & tx,
const long double & ty,
452 const long double & d,
453 [[maybe_unused]]
const bool & left,
454 long double & mx,
long double & my)
456 const long double lx = fabsl(tx - sx);
457 const long double ly = fabsl(ty - sy);
459 const long double h = sqrtl(lx*lx + ly*ly);
462 const long double h2 =
h/2;
464 const long double alpha = atanl(ly/lx);
467 const long double beta = atanl(d/h2);
471 const long double hp = sqrtl(d*d + h2*h2);
474 const long double ab = alpha + beta;
478 const long double dx = hp*cosl(ab);
479 const long double dy = hp*sinl(ab);
Core header for the Aleph-w library.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_y1_function > > y1(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_cos_function > > cos(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_sin_function > > sin(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_sqrt_function > > sqrt(const __gmp_expr< T, U > &expr)
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_atan2_function > > atan2(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_atan_function > > atan(const __gmp_expr< T, U > &expr)
void intersection_ellipse_line(long double lx0, long double ly0, long double lx1, long double ly1, long double a, long double b, long double &dx, long double &dy)
const char *const font_wrapper
void put_string(std::ofstream &output, const long double &x, const long double &y, const std::string &comment, const std::string &str)
int compute_section(long double x1, long double y1, long double x2, long double y2)
long double font_height_in_mm
void draw_arc_tikz(std::ofstream &output, long double src_x, long double src_y, long double tgt_x, long double tgt_y, bool is_dashed, bool with_arrow, bool thick=true)
void compute_mid_point_line(const long double &sx, const long double &sy, const long double &tx, const long double &ty, const long double &d, const bool &left, long double &mx, long double &my)
bool tiny_keys
Global flag to enable tiny font size for keys/labels.
std::string input_file_name
long double string_width(const std::string &str)
void put_string_tkiz(std::ofstream &output, const long double &x, const long double &y, const std::string &comment, const std::string &str)
void intersection_line_line(long double lx1, long double ly1, long double lx2, long double ly2, long double rx1, long double ry1, long double rx2, long double ry2, long double &x, long double &y)
long double font_width_in_points
long double distance_between_points(long double x1, long double y1, long double x2, long double y2)
static const long double points_per_inch
void draw_arc(std::ofstream &output, long double src_x, long double src_y, long double tgt_x, long double tgt_y, bool is_dashed, bool with_arrow, bool thick=true)
static const long double mm_per_inch
void intersection_rectangle_line(long double lx0, long double ly0, long double lx1, long double ly1, long double a, long double b, long double &dx, long double &dy)
std::string output_file_name
static long double arrow_lenght_in_mm
static long double arrow_width_in_mm
long double font_height()
long double font_width_in_mm
size_t compute_true_len(const std::string &str)
long double YPIC(long double y)
long double center_string(const std::string &str, long double window_size)