int usage(int retval, bool brief) {
  if (brief)
    ( retval ? std::cerr : std::cout ) << "Usage:\n"
"    IntersectTool [ -c | -n | -i | -o | [ -R maxdist ] [ -e a f] [ -E ] [\n"
"    -w ] [ -p prec ] [ --comment-delimiter commentdelim ] [ --version | -h\n"
"    | --help ] [ --input-file infile | --input-string instring ] [\n"
"    --line-separator linesep ] [ --output-file outfile ]\n"
"\n"
"For full documentation type:\n"
"    IntersectTool --help\n"
"or visit:\n"
"    https://geographiclib.sourceforge.io/C++/2.7/IntersectTool.1.html\n";
  else
    ( retval ? std::cerr : std::cout ) << "Man page:\n"
"\n"
"SYNOPSIS\n"
"       IntersectTool [ -c | -n | -i | -o | [ -R maxdist ] [ -e a f] [ -E ] [\n"
"       -w ] [ -p prec ] [ --comment-delimiter commentdelim ] [ --version | -h\n"
"       | --help ] [ --input-file infile | --input-string instring ] [\n"
"       --line-separator linesep ] [ --output-file outfile ]\n"
"\n"
"DESCRIPTION\n"
"       IntersectTool finds the intersection of two geodesics X and Y.  The\n"
"       geodesics may either be specified as a location and an azimuth, latX\n"
"       lonX aziX, or as the shortest geodesic segment between two locations,\n"
"       latX1 lonX1 and latX2 lonX2.  The intersection is then specified as the\n"
"       displacements, x and y, along the geodesics X and Y from the starting\n"
"       points to the intersection.  In the case of the intersection of\n"
"       geodesic segments, the starting point is first point specified for X or\n"
"       Y.\n"
"\n"
"       Usually this tool returns the closest intersection defined as the one\n"
"       that minimizes the \"L1\" distance, |x| + |y|.  However, it is possible\n"
"       to specify an \"origin\" x0 and y0 when determining closeness so that the\n"
"       intersection which minimizes |x - x0| + |y - y0| is returned.\n"
"\n"
"       In the case of intersecting segments the origin is taken to be the\n"
"       midpoints of the segments; x0 is half the distance from X1 to X2.  In\n"
"       addition a flag is returned specifying whether the intersection is\n"
"       \"within\" the segments.\n"
"\n"
"       The tool also returns a \"coincidence indicator\" c.  This is typically\n"
"       0.  However if the geodesics lie on top of one another at the point of\n"
"       intersection, then c is set to 1, if they are parallel, and -1, if they\n"
"       are antiparallel.\n"
"\n"
"       IntersectTool operates in one of three modes:\n"
"\n"
"       1.  With the -c option (the default), IntersectTool accepts lines on\n"
"           the standard input containing latX lonX aziX latY lonY aziY,\n"
"           specifying two geodesic lines X and Y, and prints the location of\n"
"           the closest intersection x y c on standard output.\n"
"\n"
"       2.  With the -n option, IntersectTool accepts lines on the standard\n"
"           input containing latX lonX aziX aziY aziY, specifying a point where\n"
"           two geodesic lines X and Y intersect, and prints the location of\n"
"           the next closest intersection x y c on standard output.\n"
"\n"
"       3.  With the -i option, IntersectTool accepts lines on the standard\n"
"           input containing latX1 lonX1 latX2 lonX2 latY1 lonY1 latY2 lonY2,\n"
"           specifying two geodesic segments X1-X2 and Y1-Y2, and prints x y c\n"
"           k on standard output.  Here k is a flag in [-4,4] specifying\n"
"           whether the intersection is within the segments (0) or not\n"
"           (non-zero).  x and y give the distances from X1 and Y1\n"
"           respectively.  k is set to 3 kx + ky where kx = -1 if x < 0, 0 if 0\n"
"           <= x <= sx, 1 if sx < x, and similarly for ky; sx is the length of\n"
"           the segment X1-X2.\n"
"\n"
"       4.  With the -o option, IntersectTool accepts lines on the standard\n"
"           input containing latX lonX aziX latY lonY aziY x0 y0, specifying\n"
"           two geodesic lines X and Y and two offsets, and prints x y c on\n"
"           standard output where [x, y] is the intersection closest to [x0,\n"
"           y0].\n"
"\n"
"OPTIONS\n"
"       -c  find the closest intersection (see 1 above).\n"
"\n"
"       -n  find the intersection closest to a given intersection (see 2\n"
"           above).\n"
"\n"
"       -i  find the intersection of two geodesic segments (see 3 above).\n"
"\n"
"       -o  find the closest intersection with an offset.\n"
"\n"
"       -R maxdist\n"
"           modifies the four modes to return all the intersections within an\n"
"           L1 distance, maxdist, of the relevant origin: [0, 0] for -c and -n,\n"
"           the midpoints of the segments for -i, and [x0, y0] for -o.  For\n"
"           each intersection, x y c z is printed on standard output.  Here z\n"
"           is the L1 distance of the intersection from the origin and the\n"
"           intersections are sorted by the distances.  A line \"nan nan 0 nan\"\n"
"           is added after the intersections, so that the output can be\n"
"           associated with the correct lines of the input.  The number of\n"
"           intersections scales as (maxdist/(pi a))^2.\n"
"\n"
"       -C  check the intersections.  For each computed intersection, print on\n"
"           standard error a line latX lonX latY lonY sXY giving the computed\n"
"           positions of the intersections points on X and Y and the distance\n"
"           between them.  If -w is specified, the longitude is given before\n"
"           the latitude.\n"
"\n"
"       -e a f\n"
"           specify the ellipsoid via the equatorial radius, a and the\n"
"           flattening, f.  Setting f = 0 results in a sphere.  Specify f < 0\n"
"           for a prolate ellipsoid.  A simple fraction, e.g., 1/297, is\n"
"           allowed for f.  By default, the WGS84 ellipsoid is used, a =\n"
"           6378137 m, f = 1/298.257223563.\n"
"\n"
"       -E  use \"exact\" algorithms (based on elliptic integrals) for the\n"
"           geodesic calculations.  These are more accurate than the (default)\n"
"           series expansions for |f| > 0.02.\n"
"\n"
"       -w  on input, longitude precedes latitude (except that on input this\n"
"           can be overridden by a hemisphere designator, N, S, E, W).\n"
"\n"
"       -p prec\n"
"           set the output precision to prec (default 3); prec is the precision\n"
"           relative to 1 m.  See \"PRECISION\".\n"
"\n"
"       --comment-delimiter commentdelim\n"
"           set the comment delimiter to commentdelim (e.g., \"#\" or \"//\").  If\n"
"           set, the input lines will be scanned for this delimiter and, if\n"
"           found, the delimiter and the rest of the line will be removed prior\n"
"           to processing and subsequently appended to the output line\n"
"           (separated by a space).\n"
"\n"
"       --version\n"
"           print version and exit.\n"
"\n"
"       -h  print usage and exit.\n"
"\n"
"       --help\n"
"           print full documentation and exit.\n"
"\n"
"       --input-file infile\n"
"           read input from the file infile instead of from standard input; a\n"
"           file name of \"-\" stands for standard input.\n"
"\n"
"       --input-string instring\n"
"           read input from the string instring instead of from standard input.\n"
"           All occurrences of the line separator character (default is a\n"
"           semicolon) in instring are converted to newlines before the reading\n"
"           begins.\n"
"\n"
"       --line-separator linesep\n"
"           set the line separator character to linesep.  By default this is a\n"
"           semicolon.\n"
"\n"
"       --output-file outfile\n"
"           write output to the file outfile instead of to standard output; a\n"
"           file name of \"-\" stands for standard output.\n"
"\n"
"INPUT\n"
"       IntersectTool measures all angles in degrees and all lengths in meters.\n"
"       On input angles (latitude, longitude, azimuth) can be as decimal\n"
"       degrees or degrees, minutes, seconds.  For example, \"40d30\", \"40d30'\",\n"
"       \"40:30\", \"40.5d\", and 40.5 are all equivalent.  By default, latitude\n"
"       precedes longitude for each point (the -w flag switches this\n"
"       convention); however either may be given first by appending (or\n"
"       prepending) N or S to the latitude and E or W to the longitude.\n"
"       Azimuths are measured clockwise from north; however this may be\n"
"       overridden with E or W.\n"
"\n"
"       For details on the allowed formats for angles, see the \"GEOGRAPHIC\n"
"       COORDINATES\" section of GeoConvert(1).\n"
"\n"
"PRECISION\n"
"       prec gives precision of the output with prec = 0 giving 1 m precision,\n"
"       prec = 3 giving 1 mm precision, etc.  prec is the number of digits\n"
"       after the decimal point for lengths.  The latitude and longitude\n"
"       printed to standard error with the -C option are given in decimal\n"
"       degrees with prec + 5 digits after the decimal point.  The minimum\n"
"       value of prec is 0 and the maximum is 10.\n"
"\n"
"ERRORS\n"
"       An illegal line of input will print an error message to standard output\n"
"       beginning with \"ERROR:\" and causes IntersectTool to return an exit code\n"
"       of 1.  However, an error does not cause IntersectTool to terminate;\n"
"       following lines will be converted.\n"
"\n"
"ACCURACY\n"
"       This tool will give nearly full double precision accuracy for |f| <\n"
"       0.02.  If the -E option is given, full accuracy is achieved for -1/4 <\n"
"       f < 1/5.  The tool had not been tested outside this range.\n"
"\n"
"EXAMPLES\n"
"       A vessel leaves Plymouth 50N 4W on a geodesic path with initial heading\n"
"       147.7W.  When will it first cross the equator?\n"
"\n"
"          echo 50N 4W 147.7W 0 0 90 | IntersectTool -c -p 0 -C\n"
"\n"
"          6058049 -3311253 0\n"
"          0.00000 -29.74549 -0.00000 -29.74549 0\n"
"\n"
"       Answer: after 6058km at longitude 29.7W.  When will it cross the date\n"
"       line, longitude 180E?  Here we need to use -R because there a closer\n"
"       intersection on the prime meridian:\n"
"\n"
"          echo 50N 4W 147.7W 0 180 0 | IntersectTool -c -p 0 -C -R 2.6e7\n"
"\n"
"          -494582 14052230 0 14546812\n"
"          53.69260 0.00000 53.69260 0.00000 0\n"
"          19529110 -5932344 0 25461454\n"
"          -53.51867 180.00000 -53.51867 180.00000 0\n"
"          nan nan 0 nan\n"
"          nan nan nan nan nan\n"
"\n"
"       We want the second result: after 19529 km at latitude 53.5S.\n"
"\n"
"SEE ALSO\n"
"       GeoConvert(1), GeodSolve(1).\n"
"\n"
"       This solution for intersections is described in C. F. F. Karney,\n"
"       Geodesic intersections, J. Surveying Eng. 150(3), 04024005:1-9 (2024),\n"
"       DOI: <https://doi.org/10.1061/JSUED2.SUENG-1483>; preprint\n"
"       <https://arxiv.org/abs/2308.00495>.  It is based on the work of S.\n"
"       Baseldga and J. C. Martinez-Llario, Intersection and point-to-line\n"
"       solutions for geodesics on the ellipsoid, Stud. Geophys. Geod. 62,\n"
"       353-363 (2018); DOI: <https://doi.org/10.1007/s11200-017-1020-z>;\n"
"\n"
"AUTHOR\n"
"       IntersectTool was written by Charles Karney.\n"
"\n"
"HISTORY\n"
;
  return retval;
}
