public void TruncateRayForInvalidPosition_Test() { var ray = new AcousticRay(new Vector3(0, 0, 0), new Vector3(1, 5, 7)); var newRay = ray.TruncateRay(5, new Vector3(1, 5, 7)); Assert.IsTrue(newRay.Source == new Vector3(0, 0, 0) && newRay.MicrophonePosition == new Vector3(1, 5f, 7)); Assert.IsTrue(newRay.CollisionPoints.Count == 0 && newRay.AcousticMaterials.Count == 0); }
public void RayDistance_Test() { var ray = new AcousticRay(new Vector3(0, 0, 0), new Vector3(1, 5, 7)); ray.CollisionPoints.Add(new Vector3(1, 5, 3)); ray.CollisionPoints.Add(new Vector3(1, 2, 6)); Assert.IsTrue(Math.Abs(ray.GetDistance() - 13.32) < 1e-2); }
public void CollisionPoints_Test() { var origin = new Vector3(0, 0, 0); var microphone = new Vector3(1, 5, 3); var firstRay = new AcousticRay(origin, microphone); var secondRay = new AcousticRay(origin, microphone); var thirdRay = new AcousticRay(origin, microphone); var firstRayVectors = new List <Vector3>() { new Vector3(1, 2, 3), new Vector3(1, 2, 4), new Vector3(1, 3, 3), new Vector3(1, 5.02f, 3) }; var secondRayVectors = new List <Vector3>() { new Vector3(1, 2, 3), new Vector3(1, 2, 4), new Vector3(1, 2, 5) }; var thirdRayVectors = new List <Vector3>() { new Vector3(1, 2, 5), new Vector3(1, 3, 5), new Vector3(1, 4, 5), new Vector3(1, 5, 5), new Vector3(1, 6, 3.002f) }; foreach (var vec in firstRayVectors) { firstRay.CollisionPoints.Add(vec); } foreach (var vec in secondRayVectors) { secondRay.CollisionPoints.Add(vec); } foreach (var vec in thirdRayVectors) { thirdRay.CollisionPoints.Add(vec); } Assert.IsTrue(firstRay.CollisionPoints.Count == 4 && secondRay.CollisionPoints.Count == 3 && thirdRay.CollisionPoints.Count == 5); }
public void DistanceForZeroCollisionPoints_Test() { var origin = new Vector3(0, 0, 0); var microphones = new List <MicrophoneSphere>() { new MicrophoneSphere(new Vector3(1, 5, 3), 0.5f) }; var firstRay = new AcousticRay(origin, microphones[0].Center); var rays = new List <AcousticRay> { firstRay }; Assert.IsTrue(Math.Abs(rays[0].GetDistance() - 5.92) < 1e-2); }
public void DistanceForMultipleCollisionPoints_Test() { var origin = new Vector3(0, 0, 0); var microphones = new List <MicrophoneSphere>() { new MicrophoneSphere(new Vector3(1, 5, 3), 0.5f) }; var firstRay = new AcousticRay(origin, microphones[0].Center); var firstRayVectors = new List <Vector3>() { new Vector3(1, 2, 3), new Vector3(1, 2, 4), new Vector3(1, 3, 3), new Vector3(1, 5.02f, 3) }; foreach (var vec in firstRayVectors) { firstRay.CollisionPoints.Add(vec); } var rays = new List <AcousticRay> { firstRay }; var raysDictionary = new Dictionary <int, List <AcousticRay> >(); raysDictionary[microphones[0].Id] = rays; var distanceCalculator = new DistanceCalculator(raysDictionary, microphones); distanceCalculator.ComputeDistances(); var distancesResults = new List <float>() { 3.74f, 4.74f, 6.15f, 8.17f, 8.19f }; Assert.IsTrue(Math.Abs(distancesResults[4] - raysDictionary[microphones[0].Id][0].GetDistance()) < 1e-2); }
public void TimeForMultipleCollisionPoints_Test() { var origin = new Vector3(0, 0, 0); var microphones = new List <MicrophoneSphere>() { new MicrophoneSphere(new Vector3(1, 5, 3), 0.5f) }; var firstRay = new AcousticRay(origin, microphones[0].Center); var firstRayVectors = new List <Vector3>() { new Vector3(1, 2, 3), new Vector3(1, 2, 4), new Vector3(1, 3, 3), new Vector3(1, 5.02f, 3) }; foreach (var vec in firstRayVectors) { firstRay.CollisionPoints.Add(vec); } var rays = new List <AcousticRay> { firstRay }; var raysDictionary = new Dictionary <int, List <AcousticRay> >(); raysDictionary[microphones[0].Id] = rays; var distanceCalculator = new DistanceCalculator(raysDictionary, microphones); distanceCalculator.ComputeDistances(); var times = TimeCalculator.GetTime(raysDictionary, microphones); Assert.IsTrue(Math.Abs(times[microphones[0].Id][0] - 0.0238) < 1e-3); }
public void TruncateRayUsualCase_Test() { var ray = new AcousticRay(new Vector3(0, 0, 0), new Vector3(1, 5, 7)); ray.CollisionPoints.Add(new Vector3(1, 5, 3)); ray.CollisionPoints.Add(new Vector3(1, 2, 6)); ray.CollisionPoints.Add(new Vector3(1, 5, 16)); ray.CollisionPoints.Add(new Vector3(1, 2, 20)); var gameObject = new GameObject(); gameObject.AddComponent <AcousticMaterial>(); ray.AcousticMaterials.Add(gameObject.GetComponent <AcousticMaterial>()); ray.AcousticMaterials.Add(gameObject.GetComponent <AcousticMaterial>()); ray.AcousticMaterials.Add(gameObject.GetComponent <AcousticMaterial>()); ray.AcousticMaterials.Add(gameObject.GetComponent <AcousticMaterial>()); var microphonePos = new Vector3(1, 5.02f, 16); var newRay = ray.TruncateRay(3, microphonePos); Assert.IsTrue(newRay.Source == new Vector3(0, 0, 0) && newRay.MicrophonePosition == new Vector3(1, 5.02f, 16)); Assert.IsTrue(newRay.CollisionPoints.Count == 3 && newRay.AcousticMaterials.Count == 3); }
public void RayDistanceZeroCollisionPoints_Test() { var ray = new AcousticRay(new Vector3(0, 0, 0), new Vector3(1, 5, 7)); Assert.IsTrue(Math.Abs(ray.GetDistance() - 8.66) < 1e-2); }