[latex3-commits] [git/LaTeX3-latex3-latex3] master: l3draw: Interpolation on a curve (fe57023)
Joseph Wright
joseph.wright at morningstar2.co.uk
Sat Feb 10 10:08:48 CET 2018
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/fe57023bf7d0d50a3c96389f6e56d537a199febe
>---------------------------------------------------------------
commit fe57023bf7d0d50a3c96389f6e56d537a199febe
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Sat Feb 10 09:08:48 2018 +0000
l3draw: Interpolation on a curve
This works, so I think all point operations are doable!
>---------------------------------------------------------------
fe57023bf7d0d50a3c96389f6e56d537a199febe
l3trial/l3draw/l3draw-points.dtx | 148 ++++++++++++++++++++++++++++++++
l3trial/l3draw/testfiles/m3draw001.lvt | 10 +++
l3trial/l3draw/testfiles/m3draw001.tlg | 15 ++--
3 files changed, 168 insertions(+), 5 deletions(-)
diff --git a/l3trial/l3draw/l3draw-points.dtx b/l3trial/l3draw/l3draw-points.dtx
index 5bbfa74..560faa0 100644
--- a/l3trial/l3draw/l3draw-points.dtx
+++ b/l3trial/l3draw/l3draw-points.dtx
@@ -638,6 +638,154 @@
% \end{macro}
% \end{macro}
%
+% \begin{macro}[EXP]{\draw_point_interpolate_curve:nnnnn}
+% \begin{macro}[EXP]{\draw_point_interpolate_curve_auxi:nnnnnnn}
+% \begin{macro}[EXP]{\draw_point_interpolate_curve_auxii:nnnnnnnnn}
+% \begin{macro}[EXP]
+% {
+% \draw_point_interpolate_curve_auxiii:nnnnnnnnn,
+% \draw_point_interpolate_curve_auxiii:fnnnnnnnn,
+% }
+% \begin{macro}[EXP]
+% {
+% \draw_point_interpolate_curve_auxiv:nnnnnn,
+% \draw_point_interpolate_curve_auxiv:fnnnnn,
+% }
+% \begin{macro}[EXP]{\draw_point_interpolate_curve_auxv:nnnnnn}
+% \begin{macro}[EXP]
+% {
+% \draw_point_interpolate_curve_auxvi:nnw,
+% \draw_point_interpolate_curve_auxvi:ffw,
+% }
+% \begin{macro}[EXP]{\draw_point_interpolate_curve_auxvii:n}
+% \begin{macro}[EXP]{\draw_point_interpolate_curve_auxviii:nnnnnnnn}
+% \begin{macro}[EXP]
+% {
+% \draw_point_interpolate_curve_auxix:nnnnnn,
+% \draw_point_interpolate_curve_auxix:ffnnnn,
+% }
+% Here we start with a proportion of the curve ($p$) and four points
+% \begin{enumerate}
+% \item The initial point $(x_{1},y_{1})$
+% \item The first control point $(x_{2},y_{2})$
+% \item The second control point $(x_{3},y_{3})$
+% \item The final point $(x_{4},y_{4})$
+% \end{enumerate}
+% The first phase is to expand out all of these values.
+% \begin{macrocode}
+\cs_new:Npn \draw_point_interpolate_curve:nnnnnn #1#2#3#4#5
+ {
+ \@@_point_expand:nnN {#2} {#3}
+ \@@_point_interpolate_curve_auxi:nnnnnnn
+ {#1} {#4} {#5}
+ }
+\cs_new:Npn \@@_point_interpolate_curve_auxi:nnnnnnn #1#2#3#4#5#6#7
+ {
+ \@@_point_expand:nnN {#6} {#7}
+ \@@_point_interpolate_curve_auxii:nnnnnnnnn
+ {#5} {#1} {#2} {#3} {#4}
+ }
+\cs_new:Npn \@@_point_interpolate_curve_auxii:nnnnnnnnn #1#2#3#4#5#6#7#8#9
+ {
+ \@@_point_interpolate_curve_auxiii:fnnnnnnnn
+ { \fp_eval:n {#5} }
+ {#6} {#7} {#8} {#9} {#1} {#2} {#3} {#4}
+ }
+% \end{macrocode}
+% At this stage, everything is fully expanded and back in the input order.
+% The approach to finding the required point is iterative. We carry out
+% three phases. In phase one, we need all of the input co-ordinates
+% \begin{align*}
+% x_{1}' &= (1 - p)x_{1} + px_{2} \\
+% y_{1}' &= (1 - p)y_{1} + py_{2} \\
+% x_{2}' &= (1 - p)x_{2} + px_{3} \\
+% y_{2}' &= (1 - p)y_{2} + py_{3} \\
+% x_{3}' &= (1 - p)x_{3} + px_{4} \\
+% y_{3}' &= (1 - p)y_{3} + py_{4}
+% \end{align*}
+% In the second stage, we can drop the final point
+% \begin{align*}
+% x_{1}'' &= (1 - p)x_{1}' + px_{2}' \\
+% y_{1}'' &= (1 - p)y_{1}' + py_{2}' \\
+% x_{2}'' &= (1 - p)x_{2}' + px_{3}' \\
+% y_{2}'' &= (1 - p)y_{2}' + py_{3}'
+% \end{align*}
+% and for the final stage only need one set of calculations
+% \begin{align*}
+% P_{x} &= (1 - p)x_{1}'' + px_{2}'' \\
+% P_{y} &= (1 - p)y_{1}'' + py_{2}''
+% \end{align*}
+% Of course, this does mean a lot of calculations and expansion!
+% \begin{macrocode}
+\cs_new:Npn \@@_point_interpolate_curve_auxiii:nnnnnnnnn #1#2#3#4#5#6#7#8#9
+ {
+ \@@_point_interpolate_curve_auxiv:fnnnnn
+ { \fp_eval:n { 1 - #1 } }
+ {#1}
+ { {#2} {#3} } { {#4} {#5} } { {#6} {#7} } { {#8} {#9} }
+ }
+\cs_generate_variant:Nn \@@_point_interpolate_curve_auxiii:nnnnnnnnn { f }
+% \begin{macrocode}
+% We need to do the first cycle, but haven't got enough arguments to keep
+% everything in play at once. So her ewe use a but of argument re-ordering
+% and a single auxiliary to get the job done.
+% \begin{macrocode}
+\cs_new:Npn \@@_point_interpolate_curve_auxiv:nnnnnn #1#2#3#4#5#6
+ {
+ \@@_point_interpolate_curve_auxv:nnnnnn {#1} {#2} #3 #4
+ \@@_point_interpolate_curve_auxv:nnnnnn {#1} {#2} #4 #5
+ \@@_point_interpolate_curve_auxv:nnnnnn {#1} {#2} #5 #6
+ \prg_do_nothing:
+ \@@_point_interpolate_curve_auxvii:n { {#1} {#2} }
+ }
+\cs_generate_variant:Nn \@@_point_interpolate_curve_auxiv:nnnnnn { f }
+\cs_new:Npn \@@_point_interpolate_curve_auxv:nnnnnn #1#2#3#4#5#6
+ {
+ \@@_point_interpolate_curve_auxvi:ffw
+ { \fp_eval:n { #1 * #3 + #2 * #5 } }
+ { \fp_eval:n { #1 * #4 + #2 * #6 } }
+ }
+\cs_new:Npn \@@_point_interpolate_curve_auxvi:nnw
+ #1#2#3 \prg_do_nothing: #4#5
+ {
+ #3
+ \prg_do_nothing:
+ #4 { #5 {#1} {#2} }
+ }
+\cs_generate_variant:Nn \@@_point_interpolate_curve_auxvi:nnw { ff }
+% \begin{macrocode}
+% Get the arguments back into the right places and to the second and
+% third cycles directly.
+% \begin{macrocode}
+\cs_new:Npn \@@_point_interpolate_curve_auxvii:n #1
+ { \@@_point_interpolate_curve_auxviii:nnnnnnnn #1 }
+\cs_new:Npn \@@_point_interpolate_curve_auxviii:nnnnnnnn #1#2#3#4#5#6#7#8
+ {
+ \@@_point_interpolate_curve_auxix:ffffnn
+ { \fp_eval:n { #1 * #5 + #2 * #3 } }
+ { \fp_eval:n { #1 * #6 + #2 * #4 } }
+ { \fp_eval:n { #1 * #7 + #2 * #5 } }
+ { \fp_eval:n { #1 * #8 + #2 * #6 } }
+ {#1} {#2}
+ }
+\cs_new:Npn \@@_point_interpolate_curve_auxix:nnnnnn #1#2#3#4#5#6
+ {
+ { \fp_to_dim:n { #5 * #3 + #6 * #1 } }
+ { \fp_to_dim:n { #5 * #4 + #6 * #2 } }
+ }
+\cs_generate_variant:Nn \@@_point_interpolate_curve_auxix:nnnnnn { ffff }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \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/testfiles/m3draw001.lvt b/l3trial/l3draw/testfiles/m3draw001.lvt
index f214972..6d0c3e2 100644
--- a/l3trial/l3draw/testfiles/m3draw001.lvt
+++ b/l3trial/l3draw/testfiles/m3draw001.lvt
@@ -119,6 +119,16 @@
{ \draw_point_vec_coord:nn { 0 } { 1 } }
}
+\TESTEXP { \draw_point_interpolate_curve:nnnnnn }
+ {
+ \draw_point_interpolate_curve:nnnnnn
+ { 0.5 }
+ { \draw_point_vec_coord:nn { 0 } { 1 } }
+ { \draw_point_vec_coord:nn { 1 } { 1 } }
+ { \draw_point_vec_coord:nn { 1 } { 1 } }
+ { \draw_point_vec_coord:nn { 2 } { 3 } }
+ }
+
\TESTEXP { \draw_point_interpolate_arc:nnnnnn }
{
\draw_point_interpolate_arc:nnnnnn
diff --git a/l3trial/l3draw/testfiles/m3draw001.tlg b/l3trial/l3draw/testfiles/m3draw001.tlg
index af3bd98..0f31001 100644
--- a/l3trial/l3draw/testfiles/m3draw001.tlg
+++ b/l3trial/l3draw/testfiles/m3draw001.tlg
@@ -62,12 +62,17 @@ TEST 10: \draw_point_interpolate_distance:nnn
{56.90548706054688pt}{86.41889076260014pt}
============================================================
============================================================
-TEST 11: \draw_point_interpolate_arc:nnnnnn
+TEST 11: \draw_point_interpolate_curve:nnnnnn
+============================================================
+{28.45274353027344pt}{35.5659294128418pt}
+============================================================
+============================================================
+TEST 12: \draw_point_interpolate_arc:nnnnnn
============================================================
{52.44956684602254pt}{43.74041050993108pt}
============================================================
============================================================
-TEST 12: \draw_set_ <axis>vec:n
+TEST 13: \draw_set_ <axis>vec:n
============================================================
> {17.49859619140625pt}{17.49859619140625pt}.
<recently read> }
@@ -83,7 +88,7 @@ l. ... }
l. ... }
============================================================
============================================================
-TEST 13: \draw_point_vec_coord:nn
+TEST 14: \draw_point_vec_coord:nn
============================================================
{0pt}{0pt}
{28.45274353027344pt}{28.45274353027344pt}
@@ -91,7 +96,7 @@ TEST 13: \draw_point_vec_coord:nn
{28.45274353027344pt}{28.45274353027344pt}
============================================================
============================================================
-TEST 14: \draw_point_vec_coord:nnn
+TEST 15: \draw_point_vec_coord:nnn
============================================================
{0pt}{0pt}
{-10.95414733886719pt}{-10.95414733886719pt}
@@ -99,7 +104,7 @@ TEST 14: \draw_point_vec_coord:nnn
{-10.95414733886719pt}{17.49859619140625pt}
============================================================
============================================================
-TEST 15: \draw_point_vec_polar:nn
+TEST 16: \draw_point_vec_polar:nn
============================================================
{49.28159740916025pt}{28.45274353027344pt}
{24.64079870458013pt}{28.45274353027344pt}
More information about the latex3-commits
mailing list