Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
erictuvesson committed Jun 7, 2021
1 parent 84d284d commit 87ff846
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 24 deletions.
25 changes: 19 additions & 6 deletions src/Ray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,32 @@ public Ray Transform(Matrix4x4 transform)
return result;
}

public static bool operator ==(Ray left, Ray right) => (left.Position == right.Position) && (left.Direction == right.Direction);
public static bool operator !=(Ray left, Ray right) => (left.Position != right.Position) && (left.Direction != right.Direction);
public static Ray operator +(Ray left, Ray right)
=> new Ray(left.Position + right.Position, Vector3.Normalize(left.Direction + right.Direction));

public static Ray operator -(Ray left, Ray right)
=> new Ray(left.Position - right.Position, -Vector3.Normalize(left.Direction + right.Direction));

public static bool operator ==(Ray left, Ray right)
=> (left.Position == right.Position) && (left.Direction == right.Direction);

public static bool operator !=(Ray left, Ray right)
=> (left.Position != right.Position) && (left.Direction != right.Direction);

/// <inheritdoc />
public bool Equals(Ray other) => (this.Position == other.Position) && (this.Direction == other.Direction);
public bool Equals(Ray other)
=> (this.Position == other.Position) && (this.Direction == other.Direction);

/// <inheritdoc />
public override bool Equals(object obj) => (obj is Ray) && this.Equals((Ray)obj);
public override bool Equals(object obj)
=> (obj is Ray) && this.Equals((Ray)obj);

/// <inheritdoc />
public override int GetHashCode() => this.Direction.GetHashCode() ^ this.Position.GetHashCode();
public override int GetHashCode()
=> this.Direction.GetHashCode() ^ this.Position.GetHashCode();

/// <inheritdoc />
public override string ToString() => $"<Position: { Position }, Direction: { Direction }>";
public override string ToString()
=> $"<Position: {Position}, Direction: {Direction}>";
}
}
60 changes: 42 additions & 18 deletions test/RayTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,58 @@ public void ray_boundingbox()
Assert.Equal(0.0f, new Ray(center, -Vector3.UnitZ).Intersects(boundingBox));
}

[Fact]
public void ray_boundingfrustum()
{

}

[Fact]
public void ray_boundingsphere()
{

}
// [Fact]
// public void ray_boundingfrustum()
// {
//
// }
//
// [Fact]
// public void ray_boundingsphere()
// {
//
// }
//
// [Fact]
// public void ray_plane()
// {
//
// }
//
// [Fact]
// public void ray_triangle()
// {
//
// }
//
// [Fact]
// public void ray_custom_geometry()
// {
//
// }

[Fact]
public void ray_plane()
public void Operator_Additive()
{
var value1 = new Ray(new Vector3(0, 0, 0), new Vector3(1, 0, 0));
var value2 = new Ray(new Vector3(1, 0, 0), new Vector3(1, 0, 0));

var value = value1 + value2;

Assert.Equal(new Vector3(1, 0, 0), value.Position);
Assert.Equal(new Vector3(1, 0, 0), value.Direction);
}

[Fact]
public void ray_triangle()
public void Operator_Subtractive()
{
var value1 = new Ray(new Vector3(0, 0, 0), new Vector3(1, 0, 0));
var value2 = new Ray(new Vector3(1, 0, 0), new Vector3(1, 0, 0));

}

[Fact]
public void ray_custom_geometry()
{
var value = value1 - value2;

Assert.Equal(new Vector3(-1, 0, 0), value.Position);
Assert.Equal(new Vector3(-1, 0, 0), value.Direction);
}
}
}

0 comments on commit 87ff846

Please sign in to comment.