Permalink
Browse files

Merge branch 'master' of github.com:SiegeLord/DUtil

  • Loading branch information...
2 parents c0e3e94 + 1d40d67 commit 4fdefe2176348e83f45c11266c166f4b30ff80b5 @SiegeLord committed Mar 12, 2012
Showing with 61 additions and 17 deletions.
  1. +6 −6 dutil/ArrayMath.d
  2. +12 −11 dutil/General.d
  3. +43 −0 dutil/Plot.d
View
@@ -72,27 +72,27 @@ T[] map(alias func, T)(T[] arr, T[] ret = null)
return ret;
}
-private template map_fun(char[] ar_fun_name, char[] fun_name)
+private template map_fun(const(char)[] ar_fun_name, const(char)[] fun_name)
{
- const char[] map_fun =
+ enum map_fun =
"T[] " ~ ar_fun_name ~ "(T)(T[] arr, T[] ret = null)
{
return map!(" ~ fun_name ~ ")(arr, ret);
}";
}
-private template reduce_fun(char[] ar_fun_name, char[] fun_name)
+private template reduce_fun(const(char)[] ar_fun_name, const(char)[] fun_name)
{
- const char[] reduce_fun =
+ enum reduce_fun =
"T " ~ ar_fun_name ~ "(T)(T[] arr)
{
return reduce!(" ~ fun_name ~ ")(arr);
}";
}
-private template zip_fun(char[] ar_fun_name, char[] fun_name)
+private template zip_fun(const(char)[] ar_fun_name, const(char)[] fun_name)
{
- const char[] zip_fun =
+ enum zip_fun =
"T[] " ~ ar_fun_name ~ "(T)(T[] arr, T[] ret = null)
{
return zip!(" ~ fun_name ~ ")(arr, ret);
View
@@ -34,8 +34,8 @@ import tango.io.stream.Text;
import tango.io.Stdout;
import tango.stdc.stringz;
-private char[] c_str_buf;
-char* c_str(char[] dstr)
+private __gshared char[] c_str_buf;
+const(char)* c_str(const(char)[] dstr)
{
if(dstr.length >= c_str_buf.length)
c_str_buf.length = dstr.length + 1;
@@ -56,22 +56,22 @@ T[] deep_dup(T)(T[] arr)
return ret;
}
-range_fruct!(T) range(T)(T end)
+range_fruct!(T) range(T)(const(T) end)
{
range_fruct!(T) ret;
ret.end = end;
return ret;
}
-range_fruct!(T) range(T)(T start, T end)
+range_fruct!(T) range(T)(const(T) start, const(T) end)
{
range_fruct!(T) ret;
ret.start = start;
ret.end = end;
return ret;
}
-range_fruct!(T) range(T)(T start, T end, T step)
+range_fruct!(T) range(T)(const(T) start, const(T) end, const(T) step)
{
range_fruct!(T) ret;
ret.start = start;
@@ -82,7 +82,7 @@ range_fruct!(T) range(T)(T start, T end, T step)
struct range_fruct(T)
{
- int opApply(int delegate(ref T ii) dg)
+ int opApply(scope int delegate(ref T ii) dg)
{
for(T ii = start; ii < end; ii += step)
{
@@ -97,9 +97,9 @@ struct range_fruct(T)
T step = 1;
}
-char[] GetGitRevisionHash()
+const(char)[] GetGitRevisionHash()
{
- char[] ret;
+ const(char)[] ret;
try
{
auto git = new Process(true, "git rev-parse HEAD");
@@ -115,16 +115,17 @@ char[] GetGitRevisionHash()
return ret;
}
-char[] Prop(char[] type, char[] name, char[] get_attr = "", char[] set_attr = "")()
+@property
+const(char)[] Prop(const(char)[] type, const(char)[] name, const(char)[] get_attr = "", const(char)[] set_attr = "")()
{
return
- get_attr ~ "
+ "@property " ~ get_attr ~ "
" ~ type ~ " " ~ name ~ "()
{
return " ~ name ~ "Val;
}
- " ~ set_attr ~ "
+ @property " ~ set_attr ~ "
void " ~ name ~ "(" ~ type ~ " val)
{
" ~ name ~ "Val = val;
View
@@ -0,0 +1,43 @@
+module dutil.Plot;
+
+import tango.math.Math;
+
+import gnuplot;
+
+void CubeHelix(double gray, out double red, out double green, out double blue, double gamma = 1.0,
+ double s = 0.5, double r = -1.5, double h = 1.0, double min_x = 0.2, double max_x = 1.0)
+{
+ double color_func(double p0, double p1, double x)
+ {
+ // Apply gamma factor to emphasise low or high intensity values
+ auto xg = pow((x * (max_x - min_x) + min_x), gamma);
+
+ // Calculate amplitude and angle of deviation from the black
+ // to white diagonal in the plane of constant
+ // perceived intensity.
+ auto a = h * xg * (1 - xg) / 2;
+
+ auto phi = 2 * PI * (s / 3 + r * x);
+
+ return xg + a * (p0 * cos(phi) + p1 * sin(phi));
+ }
+
+ red = color_func(-0.14861, 1.78277, gray);
+ green = color_func(-0.29227, -0.90649, gray);
+ blue = color_func(1.97294, 0.0, gray);
+}
+
+void SetCubeHelix(C3DPlot plot, size_t num_divs = 100)
+{
+ assert(num_divs > 1);
+ size_t n = 0;
+ bool cube_helix_good(out double gray, out double r, out double g, out double b)
+ {
+ gray = (cast(double)n) / (num_divs - 1);
+ CubeHelix(gray, r, g, b, 1.0, 0.5, -0.8, 2, 0.2, 1);
+ n++;
+ return n < num_divs;
+ }
+
+ plot.Palette(&cube_helix_good);
+}

0 comments on commit 4fdefe2

Please sign in to comment.