Skip to content

Commit

Permalink
Merge pull request #270 from GSharker/dev/guma/address-compiler-warnings
Browse files Browse the repository at this point in the history
Refactor to address warnings.
  • Loading branch information
cesarecaoduro authored Aug 21, 2021
2 parents eed0b3c + ea1601b commit b0f19ae
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
2 changes: 0 additions & 2 deletions src/GShark/Core/BoundingBoxTree/LazyCurveBBT.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using GShark.Geometry;
using GShark.Geometry.Interfaces;
using GShark.Operation;
using System;
using System.Collections.Generic;
using GShark.ExtendedMethods;
using GShark.Geometry.Interfaces;

namespace GShark.Core.BoundingBoxTree
{
Expand Down
7 changes: 6 additions & 1 deletion src/GShark/Geometry/Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,13 @@ public bool Equals(Line other)
/// </summary>
/// <param name="obj">The curve object.</param>
/// <returns>Return true if the nurbs curves are equal.</returns>
public override bool Equals(object? obj)
public override bool Equals(object obj)
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}

if (obj is Line curve)
return Equals(curve);
return false;
Expand Down
32 changes: 25 additions & 7 deletions src/GShark/Geometry/NurbsCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using GShark.Operation.Utilities;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

Expand All @@ -18,8 +19,6 @@ namespace GShark.Geometry
/// </example>
public class NurbsCurve : ICurve, IEquatable<NurbsCurve>, ITransformable<NurbsCurve>
{
public NurbsCurve() { }

/// <summary>
/// Creates a NURBS curve.
/// </summary>
Expand Down Expand Up @@ -286,10 +285,10 @@ public NurbsCurve ClampEnds()
}

/// <summary>
/// Compares if two NURBS curves are the same.<br/>
/// Two NURBS curves are equal when the have same degree, same control points order and dimension, and same knots.
/// Compares two NURBS curves for equality.<br/>
/// Two NURBS curves are equal when the have same control points, weights, knots and degree.
/// </summary>
/// <param name="other">The NURBS curve.</param>
/// <param name="other">The other NURBS curve.</param>
/// <returns>Return true if the NURBS curves are equal.</returns>
public bool Equals(NurbsCurve? other)
{
Expand All @@ -308,12 +307,12 @@ public bool Equals(NurbsCurve? other)
return false;
}

if (!Weights.SequenceEqual(other.Weights))
if (Degree != other.Degree)
{
return false;
}

return Degree == other.Degree;
return Weights.SequenceEqual(other.Weights);
}

/// <summary>
Expand Down Expand Up @@ -347,5 +346,24 @@ public override string ToString()

return stringBuilder.ToString();
}

public override int GetHashCode()
{
var sBldr = new StringBuilder();
sBldr.Append(Degree);
sBldr.Append(Knots);

foreach (var ptStr in ControlPointLocations.Select(p => p.ToString().ToList()))
{
sBldr.Append(ptStr);
}

foreach (var wtStr in Weights.Select(w => w.ToString(CultureInfo.InvariantCulture).ToList()))
{
sBldr.Append(wtStr);
}

return sBldr.ToString().GetHashCode();
}
}
}
9 changes: 9 additions & 0 deletions src/GShark/Geometry/Vector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using GShark.ExtendedMethods;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace GShark.Geometry
{
Expand Down Expand Up @@ -294,6 +296,13 @@ public bool Equals(Vector other)
return true;
}

public override int GetHashCode()
{
var sBldr = new StringBuilder();
this.Select(d => sBldr.Append(d.ToString(CultureInfo.InvariantCulture)));
return sBldr.ToString().GetHashCode();
}

/// <summary>
/// Constructs the string representation of the vector.
/// </summary>
Expand Down

0 comments on commit b0f19ae

Please sign in to comment.