[latex3-commits] [git/LaTeX3-latex3-latex3] master: Add support for "wave" color model (384c6cba3)
Joseph Wright
joseph.wright at morningstar2.co.uk
Mon Aug 10 18:31:03 CEST 2020
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/384c6cba330b9907d0b987c5a0eb72652f9129bd
>---------------------------------------------------------------
commit 384c6cba330b9907d0b987c5a0eb72652f9129bd
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Mon Aug 10 17:31:03 2020 +0100
Add support for "wave" color model
>---------------------------------------------------------------
384c6cba330b9907d0b987c5a0eb72652f9129bd
l3experimental/CHANGELOG.md | 1 +
l3experimental/l3color/l3color.dtx | 76 ++++++++++++++++++++
l3experimental/l3color/testfiles/m3color002.lvt | 13 ++++
l3experimental/l3color/testfiles/m3color002.tlg | 95 ++++++++++++++++++++++++-
4 files changed, 182 insertions(+), 3 deletions(-)
diff --git a/l3experimental/CHANGELOG.md b/l3experimental/CHANGELOG.md
index 062521591..b2a6f8303 100644
--- a/l3experimental/CHANGELOG.md
+++ b/l3experimental/CHANGELOG.md
@@ -10,6 +10,7 @@ this project uses date-based 'snapshot' version identifiers.
### Added
- Support for `Gray` color model
- Support for `hsb` color model
+- Support for `wave` color model
## [2020-08-07]
diff --git a/l3experimental/l3color/l3color.dtx b/l3experimental/l3color/l3color.dtx
index fc75e5f00..8601156ff 100644
--- a/l3experimental/l3color/l3color.dtx
+++ b/l3experimental/l3color/l3color.dtx
@@ -91,6 +91,8 @@
% single six-digit hexadecimal number
% \item \texttt{RGB} Red-green-blue color, with three axes, one for each of
% the components, values as integers from $0$ to $255$
+% \item \texttt{wave} Light wavelength, a real number in the range
+% $380$ to $780$ (nanometres)
% \end{itemize}
% All interface models are internally stored as |rgb|.
%
@@ -868,6 +870,8 @@
% \@@_parse_model_Hsb:w, \@@_parse_model_HSB:w,
% \@@_parse_model_HTML:w, \@@_parse_model_RGB:w
% }
+% \begin{macro}[EXP]{\@@_parse_model_wave:nn}
+% \begin{macro}[EXP]{\@@_parse_model_wave:nnnn}
% \begin{macrocode}
\cs_new:Npn \@@_parse_model_Gray:w #1 , #2 \s_@@_stop
{ { gray } { \fp_eval:n { #1 / 15 } } }
@@ -948,6 +952,78 @@
}
}
% \end{macrocode}
+% Following the description in the \pkg{xcolor} manual, we use the conversion to
+% \texttt{rgb} with $\gamma = 1.0$. We do \emph{not} go via \texttt{hsb} as for
+% us that is not a core model. The first step is to calculate $f$, allowing for
+% the color being out-of-visible range and so black.
+% \begin{macrocode}
+\cs_new:Npn \@@_parse_model_wave:w #1 , #2 \s_@@_stop
+ {
+ { rgb }
+ {
+ \bool_lazy_or:nnTF
+ { \fp_compare_p:nNn {#1} < { 380 } }
+ { \fp_compare_p:nNn {#1} > { 780 } }
+ { 0 , 0 , 0 }
+ {
+ \exp_args:Ne \@@_parse_model_wave:nn
+ {
+ \fp_compare:nNnTF {#1} < { 420 }
+ { \fp_eval:n { 0.3 + 0.7 * (#1 - 380) / 40 } }
+ {
+ \fp_compare:nNnTF {#1} > { 700 }
+ { \fp_eval:n { 0.3 + 0.7 * (780 - #1) / 80 } }
+ { 1 }
+ }
+ }
+ {#1}
+ }
+ }
+ }
+\cs_new:Npn \@@_parse_model_wave:nn #1#2
+ {
+ \fp_compare:nNnTF {#2} < { 440 }
+ {
+ \@@_parse_model_wave:nnnn {#1} { ( 440 - #2 ) / 60 } { 0 } { 1 }
+ }
+ {
+ \fp_compare:nNnTF {#2} < { 490 }
+ {
+ \@@_parse_model_wave:nnnn {#1} { 0 } { ( #2 - 440 ) / 50 } { 1 }
+ }
+ {
+ \fp_compare:nNnTF {#2} < { 510 }
+ {
+ \@@_parse_model_wave:nnnn {#1} { 0 } { 1 }
+ { ( 510 - #2 ) / 20 }
+ }
+ {
+ \fp_compare:nNnTF {#2} < { 580 }
+ {
+ \@@_parse_model_wave:nnnn {#1}
+ { ( #2 - 510 ) / 70 } { 1 } { 0 }
+ }
+ {
+ \fp_compare:nNnTF {#2} < { 645 }
+ {
+ \@@_parse_model_wave:nnnn {#1} { 1 }
+ { ( 645 - #2 ) / 65 } { 0 }
+ }
+ { \@@_parse_model_wave:nnnn {#1} { 1 } { 0 } { 0 } }
+ }
+ }
+ }
+ }
+ }
+\cs_new:Npn \@@_parse_model_wave:nnnn #1#2#3#4
+ {
+ \fp_eval:n { #1 * #2 } ,
+ \fp_eval:n { #1 * #3 } ,
+ \fp_eval:n { #1 * #4 }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
% \end{macro}
%
% \subsection{Selecting colors (and color models)}
diff --git a/l3experimental/l3color/testfiles/m3color002.lvt b/l3experimental/l3color/testfiles/m3color002.lvt
index bbcacc624..18c4d4f40 100644
--- a/l3experimental/l3color/testfiles/m3color002.lvt
+++ b/l3experimental/l3color/testfiles/m3color002.lvt
@@ -56,6 +56,19 @@
\color_show:n { foo1 }
}
+\TEST { wave~model }
+ {
+ \clist_map_inline:nn
+ {
+ 200 , 380 , 400 , 410 , 440 , 480 , 490 , 500 , 510 ,
+ 540 , 580 , 600 , 645 , 700 , 740 , 780 , 800
+ }
+ {
+ \color_set:nnn { foo1 } { wave } {#1}
+ \color_show:n { foo1 }
+ }
+ }
+
\TEST { Integer/integer-like~models }
{
\color_set:nnn { foo1 } { HSB } { 30 , 10 , 10 }
diff --git a/l3experimental/l3color/testfiles/m3color002.tlg b/l3experimental/l3color/testfiles/m3color002.tlg
index efea2746e..30ac03daa 100644
--- a/l3experimental/l3color/testfiles/m3color002.tlg
+++ b/l3experimental/l3color/testfiles/m3color002.tlg
@@ -81,7 +81,96 @@ The color foo1 has the properties:
l. ... }
============================================================
============================================================
-TEST 4: Integer/integer-like models
+TEST 4: wave model
+============================================================
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0,0,0.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0.3,0,0.3.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0.4333333333333333,0,0.65.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0.4125,0,0.825.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0,0,1.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0,0.8,1.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0,1,1.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0,1,0.5.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0,1,0.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0.4285714285714286,1,0.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 1,1,0.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 1,0.6923076923076923,0.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 1,0,0.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 1,0,0.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0.65,0,0.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0.3,0,0.
+<recently read> }
+l. ... }
+The color foo1 has the properties:
+> model => rgb
+> rgb => 0,0,0.
+<recently read> }
+l. ... }
+============================================================
+============================================================
+TEST 5: Integer/integer-like models
============================================================
The color foo1 has the properties:
> model => rgb
@@ -102,7 +191,7 @@ The color foo2 has the properties:
l. ... }
============================================================
============================================================
-TEST 5: Exporting colors
+TEST 6: Exporting colors
============================================================
> \l_tmpa_tl={rgb}{0.0 0.0 1.0}.
<recently read> }
@@ -154,7 +243,7 @@ l. ... }
l. ... }
============================================================
============================================================
-TEST 6: Exporting color: errors
+TEST 7: Exporting color: errors
============================================================
! LaTeX3 Error: Unknown export format 'mumble'.
For immediate help type H <return>.
More information about the latex3-commits
mailing list.