diff --git a/src/JuicyGraphics.csproj b/src/JuicyGraphics.csproj index 4cbde03..dc898ef 100644 --- a/src/JuicyGraphics.csproj +++ b/src/JuicyGraphics.csproj @@ -53,6 +53,7 @@ + diff --git a/src/JuicyGraphics/math/radian.cs b/src/JuicyGraphics/math/radian.cs new file mode 100644 index 0000000..64b6373 --- /dev/null +++ b/src/JuicyGraphics/math/radian.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JuicyGraphics.Mathematics { + + struct radian { + private double _radian; + + public radian(double radians) { + _radian = radians %= (2.0 * Math.PI); + } + + public double val { + get { + return _radian; + } + set { + _radian = value; + _radian %= (2.0 * Math.PI); + } + } + + public static radian operator +(radian left, double right) { + return new radian(left.val + right); + } + + public static radian operator -(radian left, double right) { + return new radian(left.val - right); ; + } + + public static radian operator -(radian me) { + return new radian(me.val + Math.PI); + } + + public static radian operator +(radian me) { + return me; + } + + //public static bool operator <(vec2 v1, vec2 v2) { + // return v1.sumComponentSqrs() < v2.sumComponentSqrs(); + //} + + //public static bool operator >(vec2 v1, vec2 v2) { + // return v1.sumComponentSqrs() > v2.sumComponentSqrs(); + //} + + //public static bool operator <=(vec2 v1, vec2 v2) { + // return v1.sumComponentSqrs() <= v2.sumComponentSqrs(); + //} + + //public static bool operator >=(vec2 v1, vec2 v2) { + // return v1.sumComponentSqrs() >= v2.sumComponentSqrs(); + //} + + //public static bool operator ==(vec2 v1, vec2 v2) { + // return + // v1.x == v2.x && + // v1.y == v2.y; + //} + + //public static bool operator !=(vec2 v1, vec2 v2) { + // return !(v1 == v2); + //} + } +} diff --git a/src/JuicyGraphics/math/vec2.cs b/src/JuicyGraphics/math/vec2.cs index 741ac76..b5174f0 100644 --- a/src/JuicyGraphics/math/vec2.cs +++ b/src/JuicyGraphics/math/vec2.cs @@ -13,14 +13,14 @@ namespace JuicyGraphics.Mathematics { private readonly double _y; public vec2(double x, double y) { - this._x = x; - this._y = y; + _x = x; + _y = y; } public vec2(double[] xy) { if (xy.Length == 2) { - this._x = xy[0]; - this._y = xy[1]; + _x = xy[0]; + _y = xy[1]; } else { throw new ArgumentException(TWO_COMPONENTS); @@ -28,8 +28,8 @@ namespace JuicyGraphics.Mathematics { } public vec2(vec2 v1) { - this._x = v1.x; - this._y = v1.y; + _x = v1.x; + _y = v1.y; } public double x { @@ -70,20 +70,20 @@ namespace JuicyGraphics.Mathematics { public vec2 normal { get { - return this.normalize(); + return normalize(); } } public double magnitude { get { - return Math.Sqrt(this.sumComponentSqrs()); + return Math.Sqrt(sumComponentSqrs()); } } [XmlIgnore] public double[] array { get { - return new[] { this.x, this.y }; + return new[] { x, y }; } } @@ -91,9 +91,9 @@ namespace JuicyGraphics.Mathematics { get { switch (index) { case 0: - return this._x; + return _x; case 1: - return this._y; + return _y; default: throw new ArgumentException(TWO_COMPONENTS, "index"); } @@ -374,7 +374,7 @@ namespace JuicyGraphics.Mathematics { } public double abs() { - return this.magnitude; + return magnitude; } public static double sumComponents(vec2 v1) { @@ -441,44 +441,44 @@ namespace JuicyGraphics.Mathematics { } public vec2 round() { - return new vec2(Math.Round(this.x), Math.Round(this.y)); + return new vec2(Math.Round(x), Math.Round(y)); } public vec2 round(int digits) { - return new vec2(Math.Round(this.x, digits), Math.Round(this.y, digits)); + return new vec2(Math.Round(x, digits), Math.Round(y, digits)); } public vec2 round(MidpointRounding mode) { - return new vec2(Math.Round(this.x, mode), Math.Round(this.y, mode)); + return new vec2(Math.Round(x, mode), Math.Round(y, mode)); } public vec2 round(int digits, MidpointRounding mode) { - return new vec2(Math.Round(this.x, digits, mode), Math.Round(this.y, digits, mode)); + return new vec2(Math.Round(x, digits, mode), Math.Round(y, digits, mode)); } public override string ToString() { - return this.ToString(null, null); + return ToString(null, null); } public string ToVerbString() { string output = null; - if (this.isUnitVector()) { + if (isUnitVector()) { output += UNIT_VECTOR; } else { output += POSITIONAL_VECTOR; } - output += string.Format("( x={0}, y={1} )", this.x, this.y); - output += magnitude + this.magnitude; + output += string.Format("( x={0}, y={1} )", x, y); + output += magnitude + magnitude; return output; } public string ToString(string format, IFormatProvider formatProvider) { if (format == null || format == "") { - return string.Format("({0}, {1})", this.x, this.y); + return string.Format("({0}, {1})", x, y); } char firstChar = format[0]; @@ -489,20 +489,20 @@ namespace JuicyGraphics.Mathematics { } switch (firstChar) { - case 'x': return this.x.ToString(remainder, formatProvider); - case 'y': return this.y.ToString(remainder, formatProvider); + case 'x': return x.ToString(remainder, formatProvider); + case 'y': return y.ToString(remainder, formatProvider); default: return String.Format( "({0}, {1})", - this.x.ToString(format, formatProvider), - this.y.ToString(format, formatProvider)); + x.ToString(format, formatProvider), + y.ToString(format, formatProvider)); } } public override int GetHashCode() { unchecked { - var hashCode = this.x.GetHashCode(); - hashCode = (hashCode * 397) ^ this.y.GetHashCode(); + var hashCode = x.GetHashCode(); + hashCode = (hashCode * 397) ^ y.GetHashCode(); return hashCode; } } @@ -518,21 +518,21 @@ namespace JuicyGraphics.Mathematics { public bool Equals(object other, double tolerance) { if (other is vec2) { - return this.Equals((vec2)other, tolerance); + return Equals((vec2)other, tolerance); } return false; } public bool Equals(vec2 other) { return - this.x.Equals(other.x) && - this.y.Equals(other.y); + x.Equals(other.x) && + y.Equals(other.y); } public bool Equals(vec2 other, double tolerance) { return - this.x.almostEqualsWithAbsTolerance(other.x, tolerance) && - this.y.almostEqualsWithAbsTolerance(other.y, tolerance); + x.almostEqualsWithAbsTolerance(other.x, tolerance) && + y.almostEqualsWithAbsTolerance(other.y, tolerance); } public int CompareTo(vec2 other) { @@ -549,7 +549,7 @@ namespace JuicyGraphics.Mathematics { public int CompareTo(object other) { if (other is vec2) { - return this.CompareTo((vec2)other); + return CompareTo((vec2)other); } throw new ArgumentException( @@ -558,9 +558,9 @@ namespace JuicyGraphics.Mathematics { } public int CompareTo(vec2 other, double tolerance) { - var bothInfinite = double.IsInfinity(this.sumComponentSqrs()) && double.IsInfinity(other.sumComponentSqrs()); + var bothInfinite = double.IsInfinity(sumComponentSqrs()) && double.IsInfinity(other.sumComponentSqrs()); - if (this.Equals(other, tolerance) || bothInfinite) { + if (Equals(other, tolerance) || bothInfinite) { return 0; } @@ -573,7 +573,7 @@ namespace JuicyGraphics.Mathematics { public int CompareTo(object other, double tolerance) { if (other is vec2) { - return this.CompareTo((vec2)other, tolerance); + return CompareTo((vec2)other, tolerance); } throw new ArgumentException( diff --git a/src/JuicyGraphics/math/vec3.cs b/src/JuicyGraphics/math/vec3.cs index 96b56c6..9096912 100644 --- a/src/JuicyGraphics/math/vec3.cs +++ b/src/JuicyGraphics/math/vec3.cs @@ -30,6 +30,18 @@ namespace JuicyGraphics.Mathematics { } } + public vec3(vec2 v1, double z) { + _x = v1.x; + _y = v1.y; + _z = z; + } + + public vec3(double x, vec2 v1) { + _x = x; + _y = v1.x; + _z = v1.y; + } + public vec3(vec3 v1) { _x = v1.x; _y = v1.y; @@ -934,14 +946,14 @@ namespace JuicyGraphics.Mathematics { private const string NORMALIZE_NaN = "Cannot normalize a vector when it's magnitude is NaN"; private const string NORMALIZE_0 = "Cannot normalize a vector when it's magnitude is zero"; private const string NORMALIZE_Inf = "Cannot normalize a vector when it's magnitude is infinite except under special conditions"; - private const string THREE_COMPONENTS = "Array must contain exactly three components , (x,y,z)"; + private const string THREE_COMPONENTS = "Array must contain exactly three components , (x, y, z)"; private const string INTERPOLATION_RANGE = "Control parameter must be a value between 0 & 1"; private const string NON_VECTOR_COMPARISON = "Cannot compare a vec3 to a non-vec3"; private const string ARGUMENT_TYPE = "The argument provided is a type of "; private const string ARGUMENT_VALUE = "The argument provided has a value of "; private const string ARGUMENT_LENGTH = "The argument provided has a length of "; private const string NEGATIVE_magnitude = "The magnitude of a vec3 must be a positive value, (i.e. greater than 0)"; - private const string ORIGIN_VECTOR_magnitude = "Cannot change the magnitude of vec3(0,0,0)"; + private const string ORIGIN_VECTOR_magnitude = "Cannot change the magnitude of vec3(0, 0, 0)"; private const string UNIT_VECTOR = "Unit vector composing of "; private const string POSITIONAL_VECTOR = "Positional vector composing of "; diff --git a/src/JuicyGraphics/renderer/stain.cs b/src/JuicyGraphics/renderer/stain.cs index d7e7e36..03a45e5 100644 --- a/src/JuicyGraphics/renderer/stain.cs +++ b/src/JuicyGraphics/renderer/stain.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using JuicyGraphics.mathematics; -namespace Graphics { +namespace JuicyGraphics.Renderer { + using Mathematics; class stain { class edgeElement { public edgeElement() {