[latex3-commits] [git/LaTeX3-latex3-latex3] master: l3draw: Line intersection (4d9c8e6)

Joseph Wright joseph.wright at morningstar2.co.uk
Wed Feb 7 18:50:51 CET 2018


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

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

commit 4d9c8e6660a005d215199a3ed8ba7c2bc92b7a95
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Wed Feb 7 17:50:51 2018 +0000

    l3draw: Line intersection
    
    The mthod here is different to pgf as it needs to
    be expandable, and as expressions tend to support
    a different approach.


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

4d9c8e6660a005d215199a3ed8ba7c2bc92b7a95
 l3trial/l3draw/l3draw-points.dtx |   75 ++++++++++++++++++++++++++++++++++++++
 l3trial/l3draw/l3draw.dtx        |    7 +++-
 2 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/l3trial/l3draw/l3draw-points.dtx b/l3trial/l3draw/l3draw-points.dtx
index d2064b0..2728c04 100644
--- a/l3trial/l3draw/l3draw-points.dtx
+++ b/l3trial/l3draw/l3draw-points.dtx
@@ -94,6 +94,9 @@
 \cs_generate_variant:Nn \@@_point_expand_auxiii:nnnnN { ffff }
 %    \end{macrocode}
 % \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
 %
 % \subsection{Co-ordinates}	
 %
@@ -162,6 +165,78 @@
 % \end{macro}
 % \end{macro}
 %
+% \subsection{Intersection calculations}
+%
+% \begin{macro}[EXP]{\draw_point_linejoin:nnnn}
+% \begin{macro}[EXP]{\@@_point_linejoin:nnnnnn}
+% \begin{macro}[EXP]{\@@_point_linejoin:nnnnnnnn}
+% \begin{macro}[EXP]
+%   {\@@_point_linejoin_aux:nnnnnn, \@@_point_linejoin_aux:ffffff}
+% \begin{macro}[EXP]
+%   {\@@_point_linejoin_aux:fnnnnnn, \@@_point_linejoin_aux:fnnnnnn}
+%    The intersection point~$P$ between a line joining points $(x_{1}, y_{1})$
+%    and $(x_{2}, y_{2})$ with a second line joining points $(x_{3}, y_{3})$
+%    and $(x_{4}, y_{4})$ can be calculated using the formulae
+%    \[
+%      P_{x} =
+%          \frac{(x_{1}y_{2} - y_{1}x_{2})(x_{3} - x_{4})
+%            - (x_{3}y_{4} - y_{3}x_{4})(x_{1} - x_{2})}
+%          {(x_{1} - x_{2})(y_{3} - y_{4}) - (y_{1} - y_{2})(x_{3} - x_{4})}
+%    \]
+%    and
+%    \[
+%      P_{y} =
+%          \frac{(x_{1}y_{2} - y_{1}x_{2})(y_{3} - y_{5})
+%          - (x_{3}y_{4} - y_{3}x_{4})(y_{1} - y_{2})}
+%          {(x_{1} - x_{2})(y_{3} - y_{4}) - (y_{1} - y_{2})(x_{3} - x_{4})} 
+%    \]
+%    The work therefore comes down to expanding the incoming data, then
+%    pre-calculating as many parts as possible before the final work to find
+%    the intersection. (Expansion and argument re-ordering is much less work
+%    than additional floating point calculations.)
+%    \begin{macrocode}
+\cs_new:Npn \draw_point_linejoin:nnnn #1#2#3#4
+  {
+    \@@_point_expand:nnN {#1} {#2}
+      \@@_point_linejoin:nnnnnn
+      {#3} {#4}
+  }
+\cs_new:Npn \@@_point_linejoin:nnnnnn #1#2#3#4#5#6
+  {
+    \@@_point_expand:nnN {#5} {#6}
+      \@@_point_linejoin:nnnnnnnn
+      {#1} {#2} {#3} {#4}
+  }
+\cs_new:Npn \@@_point_linejoin:nnnnnn #1#2#3#4#5#6#7#8
+  {
+    \@@_point_linejoin_aux:ffffff
+      { \fp_eval:n { #1 * #4 - #2 * #3 } }
+      { \fp_eval:n { #5 * #8 - #6 * #7 } }
+      { \fp_eval:n { #1 - #3 } }
+      { \fp_eval:n { #5 - #7 } }
+      { \fp_eval:n { #2 - #4 } }
+      { \fp_eval:n { #6 - #8 } }
+  }
+\cs_new:Npn \@@_point_linejoin_aux:nnnnnn #1#2#3#4#5#6
+  {
+    \@@_point_linejoin_aux:fnnnnn
+      { \fp_eval:n { #3 * #6 - #5 * #4 } }
+      {#1} {#2} {#3} {#4} {#5} {#6}
+  }
+\cs_generate_variant:Nn \@@_point_linejoin_aux:nnnnnn { ffffff }
+\cs_new:Npn \@@_point_linejoin_aux:nnnnnnn #1#2#3#4#5#6#7
+  {
+    { \fp_to_dim:n { (#2 * #5 - #3 * #6 ) / #1 } }
+    { \fp_to_dim:n { (#2 * #7 - #3 * #6 ) / #1 } }
+  }
+\cs_generate_variant:Nn \@@_point_linejoin_aux:nnnnnnn { f }
+%    \end{macrocode}
+% \end{macro}
+% \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 b880c8c..465afa8 100644
--- a/l3trial/l3draw/l3draw.dtx
+++ b/l3trial/l3draw/l3draw.dtx
@@ -63,7 +63,7 @@
 %
 % \begin{function}[EXP]{\draw_point_coord:nn}
 %   \begin{syntax}
-%     \cs{draw_coord:nn} \marg{x} \marg{y}
+%     \cs{draw_point_coord:nn} \marg{x} \marg{y}
 %   \end{syntax}
 %
 % \begin{function}[EXP]{\draw_set_xvec:n, \draw_set_yvec:n, \draw_set_zvec:n}
@@ -77,6 +77,11 @@
 %     \cs{draw_point_vec:nnn} \marg{xscale} \marg{yscale} \mag{zscale}
 %   \end{syntax}
 %
+% \begin{function}[EXP]{\draw_point_linejoin:nnnn}
+%   \begin{syntax}
+%     \cs{draw_point_linejoin:nn} \marg{P1} \marg{P2} \marg{P3} \marg{P4}
+%   \end{syntax}
+%
 % \end{documentation}
 %
 % \begin{implementation}





More information about the latex3-commits mailing list