[latex3-commits] [git/LaTeX3-latex3-latex3] master: l3draw: Normalised vector should work with zero length (a034d24aa)
Joseph Wright
joseph.wright at morningstar2.co.uk
Tue Aug 20 12:53:32 CEST 2019
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/a034d24aaeeaa53b975a73e4008d7c23e9f84357
>---------------------------------------------------------------
commit a034d24aaeeaa53b975a73e4008d7c23e9f84357
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Tue Aug 20 11:06:19 2019 +0100
l3draw: Normalised vector should work with zero length
To match pgf but also as an error here is not helpful.
>---------------------------------------------------------------
a034d24aaeeaa53b975a73e4008d7c23e9f84357
l3experimental/CHANGELOG.md | 5 +++
l3experimental/l3draw/l3draw-points.dtx | 21 ++++++++--
l3experimental/l3draw/l3draw.dtx | 3 +-
l3experimental/l3draw/testfiles/m3draw001.lvt | 2 +
l3experimental/l3draw/testfiles/m3draw001.tlg | 1 +
l3experimental/l3draw/testfiles/m3draw008.lvt | 48 ++++++++++++++++++++++
.../testfiles/m3draw008.tlg} | 0
7 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/l3experimental/CHANGELOG.md b/l3experimental/CHANGELOG.md
index 75b250898..5fbaccf3f 100644
--- a/l3experimental/CHANGELOG.md
+++ b/l3experimental/CHANGELOG.md
@@ -7,6 +7,11 @@ this project uses date-based 'snapshot' version identifiers.
## [Unreleased]
+### Changed
+
+- `\draw_unit_vector:n` returns a vertical vector when the length is
+ zero (see #609)
+
### Fixed
- Corrected behaviour of catcode tables (see #610)
diff --git a/l3experimental/l3draw/l3draw-points.dtx b/l3experimental/l3draw/l3draw-points.dtx
index bea0fc8ac..cb94dd715 100644
--- a/l3experimental/l3draw/l3draw-points.dtx
+++ b/l3experimental/l3draw/l3draw-points.dtx
@@ -216,24 +216,37 @@
%
% \begin{macro}[EXP]{\draw_point_unit_vector:n}
% \begin{macro}[EXP]{\@@_point_unit_vector:nn}
-% Only a single point expression so the expansion is done here. The
-% outcome is the normalised vector from $(0,0)$ in the direction of
+% \begin{macro}[EXP]{\@@_point_unit_vector:nnn}
+% The outcome is the normalised vector from $(0,0)$ in the direction of
% the point, \emph{i.e.}
% \[
% P_{x} = \frac{x}{\sqrt{x^{2} + y^{2}}} \quad
% P_{y} = \frac{y}{\sqrt{x^{2} + y^{2}}}
% \]
+% except where the length is zero, in which case a vertical vector is
+% returned.
% \begin{macrocode}
\cs_new:Npn \draw_point_unit_vector:n #1
{ \@@_point_process:nn { \@@_point_unit_vector:nn } {#1} }
\cs_new:Npn \@@_point_unit_vector:nn #1#2
{
- \@@_point_to_dim:n
- { ( #1 , #2 ) / (sqrt(#1 * #1 + #2 * #2)) }
+ \exp_args:Nf \@@_point_unit_vector:nnn
+ { \fp_eval:n { (sqrt(#1 * #1 + #2 * #2)) } }
+ {#1} {#2}
+ }
+\cs_new:Npn \@@_point_unit_vector:nnn #1#2#3
+ {
+ \fp_compare:nNnTF {#1} = \c_zero_fp
+ { 0pt, 1pt }
+ {
+ \@@_point_to_dim:n
+ { ( #2 , #3 ) / #1 }
+ }
}
% \end{macrocode}
% \end{macro}
% \end{macro}
+% \end{macro}
%
% \subsection{Intersection calculations}
%
diff --git a/l3experimental/l3draw/l3draw.dtx b/l3experimental/l3draw/l3draw.dtx
index e3169af18..bdea0f2f3 100644
--- a/l3experimental/l3draw/l3draw.dtx
+++ b/l3experimental/l3draw/l3draw.dtx
@@ -421,7 +421,8 @@
% \cs{draw_point_unit_vector:n} \Arg{point}
% \end{syntax}
% Expands to the co-ordinates of a unit vector in the direction of the
-% \meta{point} from the origin.
+% \meta{point} from the origin. If the \meta{point} is at the origin,
+% a vertical unit vector is returned
% \end{function}
%
% \begin{function}[EXP]{\draw_point_transform:n}
diff --git a/l3experimental/l3draw/testfiles/m3draw001.lvt b/l3experimental/l3draw/testfiles/m3draw001.lvt
index 99a989f7f..5b7a59860 100644
--- a/l3experimental/l3draw/testfiles/m3draw001.lvt
+++ b/l3experimental/l3draw/testfiles/m3draw001.lvt
@@ -30,6 +30,8 @@
\NEWLINE
\draw_point_unit_vector:n
{ \draw_point_vec:nn { -2 } { 1 } }
+ \NEWLINE
+ \draw_point_unit_vector:n { 0 , 0 }
}
\TESTEXP { \draw_point_intersect_lines:nnnn }
diff --git a/l3experimental/l3draw/testfiles/m3draw001.tlg b/l3experimental/l3draw/testfiles/m3draw001.tlg
index e556eb0d2..8da9fb23d 100644
--- a/l3experimental/l3draw/testfiles/m3draw001.tlg
+++ b/l3experimental/l3draw/testfiles/m3draw001.tlg
@@ -12,6 +12,7 @@ TEST 2: \draw_point_unit_vector:n
============================================================
0.894427190999916pt,0.447213595499958pt
-0.894427190999916pt,0.447213595499958pt
+0pt,1pt
============================================================
============================================================
TEST 3: \draw_point_intersect_lines:nnnn
diff --git a/l3experimental/l3draw/testfiles/m3draw008.lvt b/l3experimental/l3draw/testfiles/m3draw008.lvt
new file mode 100644
index 000000000..c5e7c97cb
--- /dev/null
+++ b/l3experimental/l3draw/testfiles/m3draw008.lvt
@@ -0,0 +1,48 @@
+\documentclass{minimal}
+\input{regression-test}
+
+\RequirePackage[enable-debug]{expl3}
+\RequirePackage{l3draw}
+\ExplSyntaxOn
+\debug_on:n { check-declarations , deprecation , log-functions }
+\ExplSyntaxOff
+
+\AUTHOR{Joseph Wright}
+
+\ExplSyntaxOn
+
+\cs_set_protected:Npn \test:n #1
+ {
+ \hbox_set:Nn \l_tmpa_box
+ {
+ \draw_begin:
+ #1
+ \draw_end:
+ }
+ \box_show:N \l_tmpa_box
+ }
+
+\TEST { Arcing ~ corners ~ with ~ and ~ without ~ closing }
+ {
+ \OMIT
+ \cs_set_protected:Npn \test:N #1
+ {
+ \draw_path_corner_arc:nn { 3pt } { 3pt }
+ \draw_path_moveto:n { 0cm, 0cm }
+ \int_step_inline:nnnn { 30 } { 60 } { 330 }
+ {
+ \draw_path_lineto:n
+ { \draw_point_polar:nn { 2cm } { ##1 } }
+ \draw_path_lineto:n
+ { \draw_point_polar:nn { 2cm } { ##1 + 30 } }
+ \draw_path_lineto:n { 0pt, 0pt }
+ }
+ #1
+ \draw_path_use_clear:n { stroke }
+ }
+ \TIMO
+ \test:n { \test:N \scan_stop: }
+ \test:n { \test:N \draw_path_close: }
+ }
+
+\END
diff --git a/l3experimental/l3graphics/l3graphics.glo b/l3experimental/l3draw/testfiles/m3draw008.tlg
similarity index 100%
copy from l3experimental/l3graphics/l3graphics.glo
copy to l3experimental/l3draw/testfiles/m3draw008.tlg
More information about the latex3-commits
mailing list