Skip to content

Commit

Permalink
fix(style): Completely changed .editorconfig and executed code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanRynne committed Nov 1, 2020
1 parent e26d245 commit 9f42941
Show file tree
Hide file tree
Showing 102 changed files with 2,153 additions and 1,542 deletions.
516 changes: 111 additions & 405 deletions .editorconfig

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions src/Collections/Interval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public Interval(double start, double end)
this.End = end;
}


/// <summary>
/// Initializes a new instance of the <see cref="Interval" /> struct from another interval.
/// </summary>
Expand All @@ -30,6 +31,7 @@ public Interval(double start, double end)
public Interval(Interval interval)
: this(interval.Start, interval.End) { }


/// <summary>
/// Gets a new unit interval.
/// </summary>
Expand All @@ -40,21 +42,13 @@ public Interval(Interval interval)
/// Gets or sets the starting value of the interval.
/// </summary>
/// <value>Value will always be lower unless interval is inverted.</value>
public double Start
{
get;
set;
}
public double Start { get; set; }

/// <summary>
/// Gets or sets the ending value of the interval.
/// </summary>
/// <value>Value will always be the biggest unless interval is inverted.</value>
public double End
{
get;
set;
}
public double End { get; set; }

/// <summary>
/// Gets the space between the start and end of the interval.
Expand All @@ -66,6 +60,7 @@ public double End
/// </summary>
public bool HasInvertedDirection => this.Length < 0;


/// <summary>
/// Crop a number so that it's contained on the given interval.
/// </summary>
Expand All @@ -81,6 +76,7 @@ public static double CropNumber(double number, Interval interval)
return number;
}


/// <summary>
/// Remap a number from one interval to another.
/// </summary>
Expand All @@ -93,23 +89,27 @@ public static double RemapNumber(double number, Interval fromInterval, Interval
var cropped = fromInterval.Contains(number) ? number : fromInterval.Crop(number);
var proportion = (cropped - fromInterval.Start) / Math.Abs(fromInterval.Length);

return toInterval.Start + (toInterval.Length * proportion);
return toInterval.Start + toInterval.Length * proportion;
}


/// <summary>
/// Crop a number so that it is contained inside this interval.
/// </summary>
/// <param name="number">Number to crop.</param>
/// <returns>Cropped number.</returns>
public double Crop(double number) => CropNumber(number, this);


/// <summary>
/// Remap a number from this interval to a given one.
/// </summary>
/// <param name="number">Number to remap.</param>
/// <param name="toInterval">Interval to remap number to.</param>
/// <returns>Remapped number inside given interval.</returns>
public double Remap(double number, Interval toInterval) => RemapNumber(number, this, toInterval);
public double Remap(double number, Interval toInterval) =>
RemapNumber(number, this, toInterval);


/// <summary>
/// Remap a number from this interval to a unit interval.
Expand All @@ -118,13 +118,15 @@ public static double RemapNumber(double number, Interval fromInterval, Interval
/// <returns>Value remaped from 0 to 1.</returns>
public double RemapToUnit(double number) => this.Remap(number, Unit);


/// <summary>
/// Remap a number from a unit interval to this interval.
/// </summary>
/// <param name="number">Number to remap.</param>
/// <returns>Remapped number.</returns>
public double RemapFromUnit(double number) => Unit.Remap(number, this);


/// <summary>
/// Check if a number is contained inside this interval.
/// </summary>
Expand All @@ -137,6 +139,7 @@ public bool Contains(double number)
return min <= number && number <= max;
}


/// <summary>
/// Swap the Start and End values of this interval.
/// </summary>
Expand Down
36 changes: 30 additions & 6 deletions src/Collections/Matrix{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,29 @@ public class Matrix<T>
// https://codereview.stackexchange.com/questions/194732/class-matrix-implementation
private T[,] data;


/// <summary>
/// Initializes a new instance of the <see cref="Matrix{T}" /> class.
/// </summary>
/// <param name="n">Size of the square Matrix.</param>
public Matrix(int n) => this.data = new T[n, n];


/// <summary>
/// Initializes a new instance of the <see cref="Matrix{T}" /> class of the specified size.
/// </summary>
/// <param name="n">Column size.</param>
/// <param name="m">Row size.</param>
public Matrix(int n, int m) => this.data = new T[n, m];


/// <summary>
/// Initializes a new instance of the <see cref="Matrix{T}" /> class from a 2D array.
/// </summary>
/// <param name="data">2D array of data.</param>
public Matrix(T[,] data) => this.data = data;


/// <summary>
/// Gets columns.
/// </summary>
Expand All @@ -52,6 +56,7 @@ public class Matrix<T>
/// <param name="column">Column.</param>
public ref T this[int row, int column] => ref this.data[row, column];


/// <summary>
/// Get the row of a matrix at the specified index.
/// </summary>
Expand All @@ -66,6 +71,7 @@ public T[] Row(int n)
return row;
}


/// <summary>
/// Get the column of a matrix at the specified index.
/// </summary>
Expand All @@ -80,34 +86,47 @@ public T[] Column(int m)
return col;
}


// ----- ORDERING METHODS -----


/// <summary>
/// Turns columns into rows and rows into columns.
/// </summary>
public void FlipMatrix() => throw
// TODO: Implement FlipMatrix()
new NotImplementedException();
// TODO: Implement FlipMatrix()
new NotImplementedException();


/// <summary>
/// Increment Matrix column size by a specified amount.
/// It accepts both increasing and decreasing the size.
/// </summary>
/// <param name="incrementN">Positive or negative increment.</param>
public void IncrementColumns(int incrementN) => this.ResizeMatrix(ref this.data, this.N + incrementN, this.M);
public void IncrementColumns(int incrementN) => this.ResizeMatrix(
ref this.data,
this.N + incrementN,
this.M);


/// <summary>
/// Increment Matrix row size by a specified amount.
/// It accepts both increasing and decreasing the size.
/// </summary>
/// <param name="incrementM">Positive or negative increment.</param>
public void IncrementRows(int incrementM) => this.ResizeMatrix(ref this.data, this.N, this.M + incrementM);
public void IncrementRows(int incrementM) => this.ResizeMatrix(
ref this.data,
this.N,
this.M + incrementM);


/// <summary>
/// Increase or decrease the matrix size symetrically.
/// </summary>
/// <param name="symetricIncrement">Symetric increase/decrease.</param>
public void IncrementMatrixSize(int symetricIncrement) => this.IncrementMatrixSize(symetricIncrement, symetricIncrement);
public void IncrementMatrixSize(int symetricIncrement) =>
this.IncrementMatrixSize(symetricIncrement, symetricIncrement);


/// <summary>
/// Increase or decrease the column size of the matrix.
Expand All @@ -120,6 +139,7 @@ public void IncrementMatrixSize(int columnIncrement, int rowIncrement)
this.IncrementRows(rowIncrement);
}


/// <summary>
/// Obtains all neighbour entities surrounding the specified matrix coordinates.
/// </summary>
Expand All @@ -135,6 +155,7 @@ public List<T> GetAllNeighboursAt(int column, int row)
return neighbours;
}


/// <summary>
/// Obtains corner neighbour entities surrounding the specified matrix coordinates.
/// </summary>
Expand All @@ -145,6 +166,7 @@ public List<T> GetAllNeighboursAt(int column, int row)
// TODO: Implement GetCornerNeighboursOfEntityAt()
new NotImplementedException();


/// <summary>
/// Obtains contiguous neighbour entities surrounding the specified matrix coordinates.
/// </summary>
Expand All @@ -155,10 +177,12 @@ public List<T> GetAllNeighboursAt(int column, int row)
// TODO: Implement GetContiguousNeighboursOfEntityAt()
new NotImplementedException();


/// <summary>
/// Resizes any given 2 dimensional array.
/// It accepts smaller and bigger array outputs.
/// Obtained from: https://stackoverflow.com/questions/6539571/how-to-resize-multidimensional-2d-array-in-c .
/// Obtained from:
/// https://stackoverflow.com/questions/6539571/how-to-resize-multidimensional-2d-array-in-c .
/// </summary>
/// <param name="original">2D Array to resize.</param>
/// <param name="newCoNum">Number of resulting columns in the array.</param>
Expand Down
15 changes: 12 additions & 3 deletions src/Curves/Geodesics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ public static class Geodesics
/// <param name="maxIter">Maximum iterations.</param>
/// <param name="geodesic">Geodesic curves.</param>
/// <returns>True if successful.</returns>
public static bool StartDir(MeshPoint meshPoint, Vector3d vector, Mesh mesh, int maxIter, out List<Point3d> geodesic)
public static bool StartDir(
MeshPoint meshPoint,
Vector3d vector,
Mesh mesh,
int maxIter,
out List<Point3d> geodesic)
{
// Get initial face on the mesh
var initialFace = mesh.Faces[meshPoint.FaceIndex];
Expand Down Expand Up @@ -48,8 +53,12 @@ public static bool StartDir(MeshPoint meshPoint, Vector3d vector, Mesh mesh, int
var nextFace = halfEdge.Twin.Face;

// Flip vector to next face
var perpVector = Vector3d.CrossProduct(thisDirection, MeshGeometry.FaceNormal(thisFace));
var nextVector = Vector3d.CrossProduct(MeshGeometry.FaceNormal(nextFace), perpVector);
var perpVector = Vector3d.CrossProduct(
thisDirection,
MeshGeometry.FaceNormal(thisFace));
var nextVector = Vector3d.CrossProduct(
MeshGeometry.FaceNormal(nextFace),
perpVector);

// Assign iteration variables to current
thisPoint = nextPoint;
Expand Down
39 changes: 26 additions & 13 deletions src/Curves/LevelSets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ public static class LevelSets
/// <param name="levels">List of level values to be computed.</param>
/// <param name="mesh">The mesh to compute the level-sets in.</param>
/// <param name="levelSets">Resulting level sets.</param>
public static void ComputeLevels(string valueKey, List<double> levels, Mesh mesh, out List<List<Line>> levelSets)
public static void ComputeLevels(
string valueKey,
List<double> levels,
Mesh mesh,
out List<List<Line>> levelSets)
{
var resultLines = new List<List<Line>>();

for (var i = 0; i < levels.Count; i++)
resultLines.Add(new List<Line>());

var iter = 0;
foreach (var face in mesh.Faces)
{
var count = 0;
Expand All @@ -34,13 +37,12 @@ public static void ComputeLevels(string valueKey, List<double> levels, Mesh mesh

count++;
}

iter++;
}

levelSets = resultLines;
}


/// <summary>
/// Compute the level on a specified face.
/// </summary>
Expand All @@ -52,16 +54,23 @@ public static void ComputeLevels(string valueKey, List<double> levels, Mesh mesh
public static bool GetFaceLevel(string valueKey, double level, MeshFace face, out Line line)
{
var adj = face.AdjacentVertices();
var vertexValues = new List<double> {adj[0].UserValues[valueKey], adj[1].UserValues[valueKey], adj[2].UserValues[valueKey]};
var vertexValues = new List<double>
{
adj[0].UserValues[valueKey],
adj[1].UserValues[valueKey],
adj[2].UserValues[valueKey]
};

var above = new List<int>();
var below = new List<int>();

for (var i = 0; i < vertexValues.Count; i++)
{
if (vertexValues[i] < level)
below.Add(i);
else
above.Add(i);
}

if (above.Count == 3 || below.Count == 3)
{
Expand All @@ -74,20 +83,23 @@ public static bool GetFaceLevel(string valueKey, double level, MeshFace face, ou
var intersectionPoints = new List<Point3d>();

foreach (var i in above)
foreach (var j in below)
{
var diff = vertexValues[i] - vertexValues[j];
var desiredDiff = level - vertexValues[j];
var unitizedDistance = desiredDiff / diff;
var edgeV = adj[i] - adj[j];
var levelPoint = adj[j] + (edgeV * unitizedDistance);
intersectionPoints.Add(levelPoint);
foreach (var j in below)
{
var diff = vertexValues[i] - vertexValues[j];
var desiredDiff = level - vertexValues[j];
var unitizedDistance = desiredDiff / diff;
var edgeV = adj[i] - adj[j];
var levelPoint = adj[j] + edgeV * unitizedDistance;
intersectionPoints.Add(levelPoint);
}
}

line = new Line(intersectionPoints[0], intersectionPoints[1]);
return true;
}


/// <summary>
/// Compute the gradient on a given mesh given some per-vertex values.
/// </summary>
Expand All @@ -103,6 +115,7 @@ public static List<Vector3d> ComputeGradientField(string valueKey, Mesh mesh)
return gradientField;
}


/// <summary>
/// Compute the gradient on a given mesh face given some per-vertex values.
/// </summary>
Expand All @@ -121,7 +134,7 @@ public static Vector3d ComputeFaceGradient(string valueKey, MeshFace face)
var gk = adjacentVertices[2].UserValues[valueKey];

var faceNormal = face.Normal / (2 * face.Area);
var rotatedGradient = ((gi * (k - j)) + (gj * (i - k)) + (gk * (j - i))) / (2 * face.Area);
var rotatedGradient = (gi * (k - j) + gj * (i - k) + gk * (j - i)) / (2 * face.Area);
var gradient = rotatedGradient.Cross(faceNormal);

return gradient;
Expand Down
Loading

0 comments on commit 9f42941

Please sign in to comment.