Skip to content

Commit

Permalink
Deprecation fix (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
gecko0307 committed Oct 4, 2019
1 parent cadc457 commit cd67355
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 106 deletions.
22 changes: 11 additions & 11 deletions dlib/image/color.d
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,42 @@ struct Color4f
return this;
}

Color4f opAdd(float x)
Color4f opBinary(string op)(float x) if (op == "+")
{
return Color4f(this.vec + x);
}

Color4f opSub(float x)
Color4f opBinary(string op)(float x) if (op == "-")
{
return Color4f(this.vec - x);
}

Color4f opMul(float x)
Color4f opBinary(string op)(float x) if (op == "*")
{
return Color4f(this.vec * x);
}

Color4f opDiv(float x)
Color4f opBinary(string op)(float x) if (op == "/")
{
return Color4f(this.vec / x);
}

Color4f opAdd(Vector4f v)
Color4f opBinary(string op)(Vector4f v) if (op == "+")
{
return Color4f(this.vec + v);
}

Color4f opSub(Vector4f v)
Color4f opBinary(string op)(Vector4f v) if (op == "-")
{
return Color4f(this.vec - v);
}

Color4f opMul(Vector4f v)
Color4f opBinary(string op)(Vector4f v) if (op == "*")
{
return Color4f(this.vec * v);
}

Color4f opDiv(Vector4f v)
Color4f opBinary(string op)(Vector4f v) if (op == "/")
{
return Color4f(this.vec / v);
}
Expand All @@ -150,15 +150,15 @@ struct Color4f
);
}

int opCmp(ref const(Color4f) c) const
const int opCmp(ref const(Color4f) c)
{
return cast(int)((luminance() - c.luminance()) * 100);
}

alias luminance = luminance709;

// ITU-R Rec. BT.709
float luminance709() const
const float luminance709()
{
return (
vec.arrayof[0] * 0.2126f +
Expand All @@ -168,7 +168,7 @@ struct Color4f
}

// ITU-R Rec. BT.601
float luminance601() const
const float luminance601()
{
return (
vec.arrayof[0] * 0.3f +
Expand Down
26 changes: 13 additions & 13 deletions dlib/math/complex.d
Original file line number Diff line number Diff line change
Expand Up @@ -52,59 +52,59 @@ struct Complex(T)
im = 0.0;
}

Complex!(T) opUnary(string s) () if (s == "-")
Complex!(T) opUnary(string op) () if (op == "-")
{
return Complex!(T)(re, -im);
}

Complex!(T) opAdd(Complex!(T) c)
Complex!(T) opBinary(string op)(Complex!(T) c) if (op == "+")
{
return Complex!(T)(re + c.re, im + c.im);
}

Complex!(T) opSub(Complex!(T) c)
Complex!(T) opBinary(string op)(Complex!(T) c) if (op == "-")
{
return Complex!(T)(re - c.re, im - c.im);
}

Complex!(T) opMul(Complex!(T) c)
Complex!(T) opBinary(string op)(Complex!(T) c) if (op == "*")
{
return Complex!(T)(
re * c.re - im * c.im,
re * c.im + im * c.re);
}

Complex!(T) opDiv(Complex!(T) c)
Complex!(T) opBinary(string op)(Complex!(T) c) if (op == "/")
{
T denominator = c.re * c.re + c.im * c.im;
return Complex!(T)(
(re * c.re + im * c.im) / denominator,
(im * c.re - re * c.im) / denominator);
}

Complex!(T) opAddAssign(Complex!(T) c)
Complex!(T) opOpAssign(string op)(Complex!(T) c) if (op == "+")
{
re += c.re;
im += c.im;
return this;
}

Complex!(T) opSubAssign(Complex!(T) c)
Complex!(T) opOpAssign(string op)(Complex!(T) c) if (op == "-")
{
re -= c.re;
im -= c.im;
return this;
}

Complex!(T) opMulAssign(Complex!(T) c)
Complex!(T) opOpAssign(string op)(Complex!(T) c) if (op == "*")
{
T temp = re;
re = re * c.re - im * c.im;
im = im * c.re + temp * c.im;
return this;
}

Complex!(T) opDivAssign(Complex!(T) c)
Complex!(T) opOpAssign(string op)(Complex!(T) c) if (op == "/")
{
T denominator = c.re * c.re + c.im * c.im;
T temp = re;
Expand All @@ -113,22 +113,22 @@ struct Complex(T)
return this;
}

Complex!(T) opAdd(T scalar)
Complex!(T) opBinary(string op)(T scalar) if (op == "+")
{
return Complex!(T)(re + scalar, im + scalar);
}

Complex!(T) opSub(T scalar)
Complex!(T) opBinary(string op)(T scalar) if (op == "-")
{
return Complex!(T)(re + scalar, im + scalar);
}

Complex!(T) opMul(T scalar)
Complex!(T) opBinary(string op)(T scalar) if (op == "*")
{
return Complex!(T)(re * scalar, im * scalar);
}

Complex!(T) opDiv(T scalar)
Complex!(T) opBinary(string op)(T scalar) if (op == "/")
{
return Complex!(T)(re / scalar, im / scalar);
}
Expand Down
46 changes: 23 additions & 23 deletions dlib/math/dual.d
Original file line number Diff line number Diff line change
Expand Up @@ -68,92 +68,92 @@ struct Dual(T)
return this;
}

Dual!(T) opAdd(in T x) const
const Dual!(T) opBinary(string op)(in T x) if (op == "+")
{
return this + Dual!(T)(x);
}

Dual!(T) opSub(in T x) const
const Dual!(T) opBinary(string op)(in T x) if (op == "-")
{
return this - Dual!(T)(x);
}

Dual!(T) opMul(in T x) const
const Dual!(T) opBinary(string op)(in T x) if (op == "*")
{
return this * Dual!(T)(x);
}

Dual!(T) opDiv(in T x) const
const Dual!(T) opBinary(string op)(in T x) if (op == "/")
{
return this / Dual!(T)(x);
}

Dual!(T) opUnary (string s)() const if (s == "-")
const Dual!(T) opUnary(string s)() if (s == "-")
{
return Dual!(T)(-re, -du);
}

Dual!(T) opAdd(in Dual!(T) x) const
const Dual!(T) opBinary(string op)(in Dual!(T) x) if (op == "+")
{
return Dual!(T)(
re + x.re,
du + x.du
);
}

Dual!(T) opSub(in Dual!(T) x) const
const Dual!(T) opBinary(string op)(in Dual!(T) x) if (op == "-")
{
return Dual!(T)(
re - x.re,
du - x.du
);
}

Dual!(T) opMul(in Dual!(T) x) const
const Dual!(T) opBinary(string op)(in Dual!(T) x) if (op == "*")
{
return Dual!(T)(
re * x.re,
re * x.du + du * x.re
);
}

Dual!(T) opDiv(in Dual!(T) x) const
const Dual!(T) opBinary(string op)(in Dual!(T) x) if (op == "/")
{
return Dual!(T)(
re / x.re,
(re * x.du - du * x.re) / (x.re * x.re)
);
}

Dual!(T) opAddAssign(in Dual!(T) x)
Dual!(T) opOpAssign(string op)(in Dual!(T) x) if (op == "+")
{
re += x.re;
du += x.du;
return this;
}

Dual!(T) opSubAssign(in Dual!(T) x)
Dual!(T) opOpAssign(string op)(in Dual!(T) x) if (op == "-")
{
re -= x.re;
du -= x.du;
return this;
}

Dual!(T) opMulAssign(in Dual!(T) x)
Dual!(T) opOpAssign(string op)(in Dual!(T) x) if (op == "*")
{
re *= x.re,
du = re * x.du + du * x.re;
return this;
}

Dual!(T) opDivAssign(in Dual!(T) x)
Dual!(T) opOpAssign(string op)(in Dual!(T) x) if (op == "/")
{
re /= x.re,
du = (re * x.du - du * x.re) / (x.re * x.re);
return this;
}

Dual!(T) sqrt() const
const Dual!(T) sqrt()
{
T tmp = std.math.sqrt(re);
return Dual!(T)(
Expand All @@ -162,47 +162,47 @@ struct Dual(T)
);
}

Dual!(T) opBinaryRight(string op)(in T v) const if (op == "+")
const Dual!(T) opBinaryRight(string op)(in T v) if (op == "+")
{
return Dual!(T)(v) + this;
}

Dual!(T) opBinaryRight(string op)(in T v) const if (op == "-")
const Dual!(T) opBinaryRight(string op)(in T v) if (op == "-")
{
return Dual!(T)(v) - this;
}

Dual!(T) opBinaryRight(string op)(in T v) const if (op == "*")
const Dual!(T) opBinaryRight(string op)(in T v) if (op == "*")
{
return Dual!(T)(v) * this;
}

Dual!(T) opBinaryRight(string op)(in T v) const if (op == "/")
const Dual!(T) opBinaryRight(string op)(in T v) if (op == "/")
{
return Dual!(T)(v) / this;
}

int opCmp(in double s) const
const int opCmp(in double s)
{
return cast(int)((re - s) * 100);
}

Dual!(T) sin() const
const Dual!(T) sin()
{
return Dual!(T)(.sin(re), du * .cos(re));
}

Dual!(T) cos() const
const Dual!(T) cos()
{
return Dual!(T)(.cos(re), -du * .sin(re));
}

Dual!(T) exp() const
const Dual!(T) exp()
{
return Dual!(T)(.exp(re), du * .exp(re));
}

Dual!(T) pow(T k) const
const Dual!(T) pow(T k)
{
return Dual!(T)(re^^k, k * (re^^(k-1)) * du);
}
Expand Down
6 changes: 3 additions & 3 deletions dlib/math/dualquaternion.d
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ struct DualQuaternion(T)
return DualQuaternion!(T)(q1.conj, q2.conj * -1.0);
}

DualQuaternion!(T) opMul(DualQuaternion!(T) d)
DualQuaternion!(T) opBinary(string op)(DualQuaternion!(T) d) if (op == "*")
{
return DualQuaternion!(T)(q1 * d.q1, q1 * d.q2 + q2 * d.q1);
}

DualQuaternion!(T) opAdd(DualQuaternion!(T) d)
DualQuaternion!(T) opBinary(string op)(DualQuaternion!(T) d) if (op == "+")
{
return DualQuaternion!(T)(q1 + d.q1, q2 + d.q2);
}

DualQuaternion!(T) opSub(DualQuaternion!(T) d)
DualQuaternion!(T) opBinary(string op)(DualQuaternion!(T) d) if (op == "-")
{
return DualQuaternion!(T)(q1 - d.q1, q2 - d.q2);
}
Expand Down
Loading

0 comments on commit cd67355

Please sign in to comment.