[latex3-commits] [git/LaTeX3-latex3-latex3] master: l3draw: Interpolation for lines (vectors) (ccc65d2)

Joseph Wright joseph.wright at morningstar2.co.uk
Fri Feb 9 16:38:18 CET 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/ccc65d2d9032a8964d992d9877bb9ac1e87cc59e

>---------------------------------------------------------------

commit ccc65d2d9032a8964d992d9877bb9ac1e87cc59e
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Fri Feb 9 14:34:44 2018 +0000

    l3draw: Interpolation for lines (vectors)


>---------------------------------------------------------------

ccc65d2d9032a8964d992d9877bb9ac1e87cc59e
 l3trial/l3draw/l3draw-points.dtx       |   83 ++++++++++++++++++++++++++++++++
 l3trial/l3draw/l3draw.dtx              |   12 +++++
 l3trial/l3draw/testfiles/m3draw001.lvt |   21 ++++++++
 l3trial/l3draw/testfiles/m3draw001.tlg |   19 ++++++--
 4 files changed, 131 insertions(+), 4 deletions(-)

diff --git a/l3trial/l3draw/l3draw-points.dtx b/l3trial/l3draw/l3draw-points.dtx
index 0ccb391..cc1bd1c 100644
--- a/l3trial/l3draw/l3draw-points.dtx
+++ b/l3trial/l3draw/l3draw-points.dtx
@@ -463,6 +463,89 @@
 % \end{macro}
 % \end{macro}
 %
+% \subsection{Interpolation on a line (vector) or arc}
+%
+% \begin{macro}[EXP]{\draw_point_line_part:nnn}
+% \begin{macro}[EXP]{\@@_point_line_part:nnnnn}
+% \begin{macro}[EXP]
+%   {
+%     \@@_point_line_part_aux:nnnnn,
+%     \@@_point_line_part_aux:fnnnn,
+%   }
+% \begin{macro}[EXP]
+%   {
+%     \@@_point_line_part_aux:nnnnnn,
+%     \@@_point_line_part_aux:fnnnnn,
+%   }
+%   Simple maths after expansion.
+%    \begin{macrocode}
+\cs_new:Npn \draw_point_line_part:nnn #1#2#3
+  {
+    \@@_point_expand:nnN {#2} {#3}
+      \@@_point_line_part:nnnnn
+      {#1}
+  }
+\cs_new:Npn \@@_point_line_part:nnnnn #1#2#3#4#5
+  {
+    \@@_point_line_part_aux:fnnnn { \fp_eval:n {#5} }
+      {#1} {#2} {#3} {#4}
+  }
+\cs_new:Npn \@@_point_line_part_aux:nnnnn #1#2#3#4#5
+  {
+    \@@_point_line_part_aux:fnnnnn { \fp_eval:n { 1 - #1 } }
+      {#1} {#2} {#3} {#4} {#5}
+  }
+\cs_generate_variant:Nn \@@_point_line_part_aux:nnnnn { f }
+\cs_new:Npn \@@_point_line_part_aux:nnnnnn #1#2#3#4#5#6
+  {
+    { \fp_to_dim:n { #2 * #3 + #1 * #5 } }
+    { \fp_to_dim:n { #2 * #4 + #1 * #6 } }
+  }
+\cs_generate_variant:Nn \@@_point_line_part_aux:nnnnnn { f }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}[EXP]{\draw_point_line_distance:nnn}
+% \begin{macro}[EXP]{\@@_point_line_distance:nnnnn}
+% \begin{macro}[EXP]
+%   {
+%     \@@_point_line_distance_aux:nnnnn,
+%     \@@_point_line_distance_aux:fnnnn,
+%   }
+% \begin{macro}[EXP]
+%   {
+%     \@@_point_line_distance_aux:nnnnnn,
+%     \@@_point_line_distance_aux:fnnnnn,
+%   }
+%   Same idea but using the normalised length to obtain the scale factor.
+%    \begin{macrocode}
+\cs_new:Npn \draw_point_line_distance:nnn #1#2#3
+  {
+    \@@_point_expand:nnN {#2} {#3}
+      \@@_point_line_distance:nnnnn
+      {#1}
+  }
+\cs_new:Npn \@@_point_line_distance:nnnnn #1#2#3#4#5
+  {
+    \@@_point_line_distance_aux:fnnnn
+      { \fp_eval:n { (#5) / sqrt ( ( #3 - #1 ) ^ 2 + ( #4 - #2 ) ^ 2 ) } }
+      {#1} {#2} {#3} {#4}
+  }
+\cs_new:Npn \@@_point_line_distance_aux:nnnnn #1#2#3#4#5
+  {
+    { \fp_to_dim:n { #2 + #1 * #4 } }
+    { \fp_to_dim:n { #3 + #1 * #5 } }
+  }
+\cs_generate_variant:Nn \@@_point_line_distance_aux:nnnnn { f }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
 % \subsection{Vector support}
 %
 % As well as co-ordinates relative to the drawing 
diff --git a/l3trial/l3draw/l3draw.dtx b/l3trial/l3draw/l3draw.dtx
index 7ca9775..559beb4 100644
--- a/l3trial/l3draw/l3draw.dtx
+++ b/l3trial/l3draw/l3draw.dtx
@@ -130,6 +130,18 @@
 %   % Note interface, cf. pgf
 % \end{function}
 %
+% \begin{function}[EXP]{\draw_point_line_part:nnn}
+%   \begin{syntax}
+%     \cs{draw_point_line_part:nnn} \marg{part} \marg{point expr1} \marg{point expr2}
+%   \end{syntax}
+% \end{function}
+%
+% \begin{function}[EXP]{\draw_point_line_distance:nnn}
+%   \begin{syntax}
+%     \cs{draw_point_line_distance:nnn} \marg{distance} \marg{point expr1} \marg{point expr2}
+%   \end{syntax}
+% \end{function}
+%
 % \end{documentation}
 %
 % \begin{implementation}
diff --git a/l3trial/l3draw/testfiles/m3draw001.lvt b/l3trial/l3draw/testfiles/m3draw001.lvt
index dbf5fb8..a530c8e 100644
--- a/l3trial/l3draw/testfiles/m3draw001.lvt
+++ b/l3trial/l3draw/testfiles/m3draw001.lvt
@@ -98,6 +98,27 @@
       { 1 }
   }
 
+\TESTEXP { \draw_point_line_part:nnn }
+  {
+    \draw_point_line_part:nnn
+      { 0.5 }
+      { \draw_point_vec_coord:nn { 0 } { 1 } }
+      { \draw_point_vec_coord:nn { 2 } { 3 } }
+  }
+
+\TESTEXP { \draw_point_line_distance:nnn }
+  {
+    \draw_point_line_distance:nnn
+      { 2pt }
+      { \draw_point_vec_coord:nn { 0 } { 1 } }
+      { \draw_point_vec_coord:nn { 2 } { 3 } }
+    \NEWLINE
+    \draw_point_line_distance:nnn
+      { 3pt }
+      { \draw_point_vec_coord:nn { 2 } { 3 } }
+      { \draw_point_vec_coord:nn { 0 } { 1 } }
+  }
+
 \TEST { \draw_set_<axis>vec:n }
   {
     \exp_args:Nx \tl_show:n { \draw_point_vec_coord:nnn { 1 } { 1 } { 1 } }
diff --git a/l3trial/l3draw/testfiles/m3draw001.tlg b/l3trial/l3draw/testfiles/m3draw001.tlg
index 85a3364..dbf2f62 100644
--- a/l3trial/l3draw/testfiles/m3draw001.tlg
+++ b/l3trial/l3draw/testfiles/m3draw001.tlg
@@ -51,7 +51,18 @@ TEST 8: \draw_point_intersect_circles:nnnnn
 {-0.00001237523567pt}{-0.00001237523569pt}
 ============================================================
 ============================================================
-TEST 9: \draw_set_ <axis>vec:n
+TEST 9: \draw_point_line_part:nnn 
+============================================================
+{28.45274353027344pt}{56.90548706054688pt}
+============================================================
+============================================================
+TEST 10: \draw_point_line_distance:nnn 
+============================================================
+{1.414213562373095pt}{30.57406387383308pt}
+{56.90548706054688pt}{86.41889076260014pt}
+============================================================
+============================================================
+TEST 11: \draw_set_ <axis>vec:n
 ============================================================
 > {17.49859619140625pt}{17.49859619140625pt}.
 <recently read> }
@@ -67,7 +78,7 @@ l. ...  }
 l. ...  }
 ============================================================
 ============================================================
-TEST 10: \draw_point_vec_coord:nn 
+TEST 12: \draw_point_vec_coord:nn 
 ============================================================
 {0pt}{0pt}
 {28.45274353027344pt}{28.45274353027344pt}
@@ -75,7 +86,7 @@ TEST 10: \draw_point_vec_coord:nn
 {28.45274353027344pt}{28.45274353027344pt}
 ============================================================
 ============================================================
-TEST 11: \draw_point_vec_coord:nnn 
+TEST 13: \draw_point_vec_coord:nnn 
 ============================================================
 {0pt}{0pt}
 {-10.95414733886719pt}{-10.95414733886719pt}
@@ -83,7 +94,7 @@ TEST 11: \draw_point_vec_coord:nnn
 {-10.95414733886719pt}{17.49859619140625pt}
 ============================================================
 ============================================================
-TEST 12: \draw_point_vec_polar:nn 
+TEST 14: \draw_point_vec_polar:nn 
 ============================================================
 {49.28159740916025pt}{28.45274353027344pt}
 {24.64079870458013pt}{28.45274353027344pt}





More information about the latex3-commits mailing list