Habe mit einer radian-Klasse angefangen

This commit is contained in:
mono 2019-02-25 22:49:19 +01:00
parent 3f536bd103
commit f0f1dda18e
5 changed files with 122 additions and 40 deletions

View File

@ -53,6 +53,7 @@
<ItemGroup>
<Compile Include="JuicyGraphics\math\doubleExtentions.cs" />
<Compile Include="JuicyGraphics\math\normalizeVectorException.cs" />
<Compile Include="JuicyGraphics\math\radian.cs" />
<Compile Include="JuicyGraphics\math\vec2.cs" />
<Compile Include="JuicyGraphics\math\vec3.cs" />
<Compile Include="JuicyGraphics\renderer\graphicalObjects\gridBackground.cs" />

View File

@ -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);
//}
}
}

View File

@ -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(

View File

@ -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 ";

View File

@ -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() {