gbranden pushed a commit to branch master
in repository groff.

commit 4109dfedea521c33b9c5b12b21dd8de3b6f138f6
Author: G. Branden Robinson <g.branden.robin...@gmail.com>
AuthorDate: Sat Jul 5 11:54:20 2025 -0500

    [pic]: Adjust polygon feature (Savannah #67250).
    
    Adopt the term "reference points" for object-relative locators, and
    rename the `.p[oint]` specimen thereof to `.mid[point]`.
    
    * src/preproc/pic/lex.cpp (get_token_after_dot):
    * src/preproc/pic/yex.cpp: Rename `DOT_P` symbol/token to `DOT_MID`.
    * src/preproc/pic/lex.cpp (get_token_after_dot): Recognize `mid` and
      `midpoint`, rather than `p` and `point`, as token `DOT_MID` instead of
      `DOT_P`.
    
    Fixes <https://savannah.gnu.org/bugs/?67250>.  Thanks to Doug McIlroy
    for the discussion.
---
 ChangeLog                  | 16 +++++++++++++
 doc/pic.ms                 | 59 +++++++++++++++++++++++++++++-----------------
 src/preproc/pic/lex.cpp    | 31 +++++++++++++++++-------
 src/preproc/pic/object.cpp |  2 +-
 src/preproc/pic/pic.1.man  | 56 +++++++++++++++++++++++++++++++++----------
 src/preproc/pic/pic.ypp    |  8 +++----
 6 files changed, 124 insertions(+), 48 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4c7b76190..c53818342 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2025-07-05  G. Branden Robinson <g.branden.robin...@gmail.com>
+
+       [pic]: Adjust new polygon feature.  Adopt the term "reference
+       points" for object-relative locators, and rename the `.p[oint]`
+       specimen thereof to `.mid[point]`.
+
+       * src/preproc/pic/lex.cpp (get_token_after_dot):
+       * src/preproc/pic/yex.cpp: Rename `DOT_P` symbol/token to
+       `DOT_MID`.
+       * src/preproc/pic/lex.cpp (get_token_after_dot): Recognize `mid`
+       and `midpoint`, rather than `p` and `point`, as token `DOT_MID`
+       instead of `DOT_P`.
+
+       Fixes <https://savannah.gnu.org/bugs/?67250>.  Thanks to Doug
+       McIlroy for the discussion.
+
 2025-07-03  G. Branden Robinson <g.branden.robin...@gmail.com>
 
        * src/utils/addftinfo/addftinfo.cpp (usage): Summarize purpose
diff --git a/doc/pic.ms b/doc/pic.ms
index 7f2ba58c2..76a58439e 100644
--- a/doc/pic.ms
+++ b/doc/pic.ms
@@ -655,9 +655,9 @@ GNU \fBgpic\fP supports arbitrary polygons constructed with 
the same syntax as m
 .KS
 .PS
 POLY: polygon up 1 then down 0.5 right 1;
-"up 1" rjust at POLY.p`1' + (-0.1, 0.0);
-"down 0.5 right 1" ljust at POLY.p`2' + (0.0, 0.1);
-"automatically drawn" ljust at POLY.p`3' + (0.0, -0.1);
+"up 1" rjust at POLY.mid`1' + (-0.1, 0.0);
+"down 0.5 right 1" ljust at POLY.mid`2' + (0.0, 0.1);
+"automatically drawn" ljust at POLY.mid`3' + (0.0, -0.1);
 .PE
 .CE "5: \fBpolygon up 1 then down 0.5 right 1\fP"
 .LP
@@ -1284,14 +1284,31 @@ critical(spline right 1 then up right then left then 
left 1);
 .NH 4
 Locations Relative to Polygons
 .PP
-Polygons have three types of named points: (\fB.vertex\fP, \fB.ver\fP, 
\fB.v\fP), (\fB.point\fP, \fB.p\fP), and (\fB.center\fP, \fB.c\fP).
-They can also be used without leading dots in the \fBof\fP prefix form.
-The center of a polygon is the centroid, and may give unexpected results for 
non-simple polygons.
-.PP
-\fB.v\fP and \fB.p\fP locate the vertices and mid-points of the edges, 
respectively. They can be used in the forms \fB.v\fP \fIexpr\fR
-, or \fB.v\fP \[ga]\fIexpr\fR\[aq].
-The latter is required when the vertex/point expression is followed by an 
additional expression,
-as \fBpic\fP will otherwise attempt to reduce them to a single expression.
+Polygons have three types of reference points:
+.I vertices
+(\fB.vertex\fP, \fB.ver\fP, \fB.v\fP),
+.I midpoints
+of edges between the vertices
+(\fB.midpoint\fP, \fB.mid\fP),
+and a
+.I center
+(\fB.center\fP, \fB.c\fP).
+Reference points can be used
+without leading dots in the \fBof\fP prefix form.
+The center of a polygon is the centroid,
+and may give unexpected results for non-simple polygons.
+.PP
+GNU
+.B pic
+numbers vertices and midpoints in drawing order starting from
+.B 1 .
+Express them in the forms \fB.v\fP \fIexpr\fR
+or
+\fB.v\fP \[ga]\fIexpr\fR\[aq].
+The latter is required when the vertex/point expression is followed
+by an additional expression,
+as \fBpic\fP otherwise attempts to reduce them
+to a single expression.
 For example,
 .IP
 .KS
@@ -1300,7 +1317,7 @@ For example,
 for i = 1 to n do {
    circle rad 0.05 fill 1 at last polygon.vi
 }
-circle rad 0.05 fill 1 at last polygon.p \[ga]1\[aq] + (0.0,0.1)
+circle rad 0.05 fill 1 at last polygon.mid \[ga]1\[aq] + (0.0,0.1)
 .DE
 .R
 .KE
@@ -1313,14 +1330,14 @@ define vertices {
                dot(VER.c);     "\fB.center\fP" at VER.center + (0.0, 0.1)
                for i = 1 to $2 do {
                        dot(VER.vi);
-                       dot(VER.pi);
+                       dot(VER.midi);
                }
                "\fB.v1\fP" at VER.v`1' + (-0.1, -0.1);
                "\fB.v2\fP" at VER.v`2' + (-0.1, 0.1);
                "\fB.v3\fP" at VER.v`3' + (0.1, 0.1);
-               "\fB.p1\fP" at VER.p`1' + (-0.1, 0.1);
-               "\fB.p2\fP" at VER.p`2' + (0.1, 0.1);
-               "\fB.p3\fP" at VER.p`3' + (0.1, -0.1);
+               "\fB.mid1\fP" at VER.mid`1' + (-0.1, 0.1);
+               "\fB.mid2\fP" at VER.mid`2' + (0.1, 0.1);
+               "\fB.mid3\fP" at VER.mid`3' + (0.1, -0.1);
        ]
 }
 vertices(polygon up 1 then down 0.5 right 1, 3);
@@ -3137,9 +3154,9 @@ There are lots of different ways to specify positions:
 <place> ::=
   <label>
   <label> <corner>
-  <label> <vertex>
+  <label> <reference-point>
   <corner> [of] <label>
-  <vertex> of <label>
+  <reference-point> of <label>
   Here
 .R
 .DE
@@ -3165,11 +3182,11 @@ There are lots of different ways to specify positions:
 .DE
 .DS
 .CW
-<vertex> ::=
+<reference-point> ::=
   .v[er[tex]] <expr>
   .v[er[tex]] \[ga] <expr> \[aq]
-  .p[oint] <expr>
-  .p[oint] \[ga] <expr> \[aq]
+  .mid[point] <expr>
+  .mid[point] \[ga] <expr> \[aq]
 .R
 .DE
 .DS
diff --git a/src/preproc/pic/lex.cpp b/src/preproc/pic/lex.cpp
index 43131c6a8..d81781031 100644
--- a/src/preproc/pic/lex.cpp
+++ b/src/preproc/pic/lex.cpp
@@ -892,28 +892,41 @@ int get_token_after_dot(int c)
     }
     context_buffer = ".v";
     return DOT_V;
-  case 'p':
+  case 'm':
     input_stack::get_char();
     c = input_stack::peek_char();
-    if (c == 'o') {
+    if (c == 'i') {
       input_stack::get_char();
       c = input_stack::peek_char();
-      if (c == 'i') {
+      if (c == 'd') {
        input_stack::get_char();
        c = input_stack::peek_char();
-       if (c == 'n') {
+       if (c == 'p') {
          input_stack::get_char();
          c = input_stack::peek_char();
-         if (c == 't') {
+         if (c == 'o') {
            input_stack::get_char();
-           context_buffer = ".point";
-           return DOT_P;
+           c = input_stack::peek_char();
+           if (c == 'i') {
+             input_stack::get_char();
+             c = input_stack::peek_char();
+             if (c == 'n') {
+               input_stack::get_char();
+               c = input_stack::peek_char();
+               if (c == 't') {
+                 input_stack::get_char();
+                 context_buffer = ".midpoint";
+                 return DOT_MID;
+               }
+             }
+           }
          }
        }
+       context_buffer = ".mid";
+       return DOT_MID;
       }
     }
-    context_buffer = ".p";
-    return DOT_P;
+    // fall through
   default:
     context_buffer = '.';
     return '.';
diff --git a/src/preproc/pic/object.cpp b/src/preproc/pic/object.cpp
index b5c98d9db..a8e079be0 100644
--- a/src/preproc/pic/object.cpp
+++ b/src/preproc/pic/object.cpp
@@ -1474,7 +1474,7 @@ protected:
   int vertex_number;
 public:
   polygon_object(const position &s, const position &e, position *, int);
-  position point();            // Select center point between two vertices
+  position point();            // Select midpoint between two vertices
   position vertex();           // Select vertex
   position center();           // Calculate centroid of the polygon
   void set_vertex_number(int);
diff --git a/src/preproc/pic/pic.1.man b/src/preproc/pic/pic.1.man
index 26357d7ed..97157079f 100644
--- a/src/preproc/pic/pic.1.man
+++ b/src/preproc/pic/pic.1.man
@@ -1329,26 +1329,52 @@ and
 .B \%shaded
 attributes may be used.
 .
-The final drawing position and direction are specified by the last
-user-specified line segment.
+The last user-specified line segment determines the polygon's
+final drawing position and direction.
+.
 For example,
 draw and fill a triangle
 with the following.
-.IP
+.
+.
+.RS
+.P
 .EX
 polygon up 1 then right 1 down 0.5 fill 0.5
 .EE
-.LP
-To position polygons,
-two new suffixes are available:
-.RB \[lq] .v
+.RE
+.
+.
+.P
+Two reference point suffixes permit the positioning
+of drawing elements relative to a polygon.
+.
+.RB \[lq] .vertex
 .IR expr \[rq]
-for locating the vertices,
+locates the vertices,
 and
-.RB \[lq] .p
+.RB \[lq] .midpoint
 .IR expr \[rq]
-for locating the center points of edges.
+for locating the midpoints of edges.
 .
+GNU
+.B pic
+numbers vertices and midpoints in drawing order starting from
+.B 1 .
+.
+You can abbreviate
+.B \%.vertex
+as
+.B .v
+or
+.BR .ver ,
+and
+.B \%.midpoint
+as
+.BR .mid .
+.
+.
+.P
 For example,
 .IP
 .EX
@@ -1364,9 +1390,13 @@ arrow down from last polygon.v4
 .P
 creates and correctly places a flowchart decision diamond.
 .
-.B .c
-is also available but the compass points will not work as expected and
-should not be used with polygons.
+.
+.P
+.B \%.center
+.RB ( .c )
+is also available,
+but compass points do not work as expected
+and should not be used with polygons.
 .
 .
 .\" ====================================================================
diff --git a/src/preproc/pic/pic.ypp b/src/preproc/pic/pic.ypp
index 69c99ca43..b34749d7a 100644
--- a/src/preproc/pic/pic.ypp
+++ b/src/preproc/pic/pic.ypp
@@ -179,7 +179,7 @@ char *do_sprintf(const char *fmt, const double *v, int nv);
 %token DOT_NW
 %token DOT_SW
 %token DOT_C
-%token DOT_P
+%token DOT_MID
 %token DOT_V
 %token DOT_START
 %token DOT_END
@@ -275,7 +275,7 @@ parses properly. */
 
 /* these must have higher precedence than CHOP so that 'label %prec CHOP'
 works */
-%left DOT_N DOT_E DOT_W DOT_S DOT_NE DOT_SE DOT_NW DOT_SW DOT_C DOT_P DOT_V
+%left DOT_N DOT_E DOT_W DOT_S DOT_NE DOT_SE DOT_NW DOT_SW DOT_C DOT_MID DOT_V
 %left DOT_START DOT_END TOP BOTTOM LEFT_CORNER RIGHT_CORNER
 %left UPPER LOWER NORTH SOUTH EAST WEST CENTER START END
 
@@ -1571,13 +1571,13 @@ vertex:
                  $$.crn = &object::vertex;
                  $$.vertex_number = $3;
                }
-       | DOT_P expr
+       | DOT_MID expr
                {
                  $$.crn = &object::point;
                  $$.vertex_number = $2;
                  $$.is_edge = 1;
                }
-       | DOT_P '`' expr '\''
+       | DOT_MID '`' expr '\''
                {
                  $$.crn = &object::point;
                  $$.vertex_number = $3;


_______________________________________________
groff-commit mailing list
groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to