public void CustomTable() { TableLoader template = TableLoader.FromResource("g1_nowind"); const double velocityAccuracyInPercent = 0.005, dropAccuracyInMOA = 0.2, windageAccuracyInMOA = 0.2; var table = DragTable.Get(template.Ammunition.BallisticCoefficient.Table); template.Ammunition.BallisticCoefficient = new BallisticCoefficient(template.Ammunition.BallisticCoefficient.Value, DragTableId.GC); var cal = new TrajectoryCalculator(); ShotParameters shot = new ShotParameters() { Step = new Measurement <DistanceUnit>(50, DistanceUnit.Yard), MaximumDistance = new Measurement <DistanceUnit>(1000, DistanceUnit.Yard), SightAngle = cal.SightAngle(template.Ammunition, template.Rifle, template.Atmosphere, table), ShotAngle = template.ShotParameters?.ShotAngle, CantAngle = template.ShotParameters?.CantAngle, }; var trajectory = cal.Calculate(template.Ammunition, template.Rifle, template.Atmosphere, shot, null, table); trajectory.Length.Should().Be(template.Trajectory.Count); for (int i = 0; i < trajectory.Length; i++) { var point = trajectory[i]; var templatePoint = template.Trajectory[i]; point.Distance.In(templatePoint.Distance.Unit).Should().BeApproximately(templatePoint.Distance.Value, templatePoint.Distance.Value * velocityAccuracyInPercent, $"@{point.Distance:N0}"); point.Velocity.In(templatePoint.Velocity.Unit).Should().BeApproximately(templatePoint.Velocity.Value, templatePoint.Velocity.Value * velocityAccuracyInPercent, $"@{point.Distance:N0}"); var dropAccuracyInInch = Measurement <AngularUnit> .Convert(dropAccuracyInMOA, AngularUnit.MOA, AngularUnit.InchesPer100Yards) * templatePoint.Distance.In(DistanceUnit.Yard) / 100; var windageAccuracyInInch = Measurement <AngularUnit> .Convert(windageAccuracyInMOA, AngularUnit.MOA, AngularUnit.InchesPer100Yards) * templatePoint.Distance.In(DistanceUnit.Yard) / 100; point.Drop.In(DistanceUnit.Inch).Should().BeApproximately(templatePoint.Drop.In(DistanceUnit.Inch), dropAccuracyInInch, $"@{point.Distance:N0}"); point.Windage.In(DistanceUnit.Inch).Should().BeApproximately(templatePoint.Windage.In(DistanceUnit.Inch), windageAccuracyInInch, $"@{point.Distance:N0}"); } }
public void Custom2() { var template = TableLoader.FromResource("custom2"); using var stream = typeof(TrajectoryCalculatorTest).Assembly.GetManifestResourceStream($"BallisticCalculator.Test.resources.drg2.txt"); var table = DrgDragTable.Open(stream); const double velocityAccuracyInPercent = 0.015, dropAccuracyInMOA = 0.25; var cal = new TrajectoryCalculator(); ShotParameters shot = new ShotParameters() { Step = new Measurement <DistanceUnit>(100, DistanceUnit.Meter), MaximumDistance = new Measurement <DistanceUnit>(1500, DistanceUnit.Meter), SightAngle = cal.SightAngle(template.Ammunition, template.Rifle, template.Atmosphere, table), ShotAngle = template.ShotParameters?.ShotAngle, CantAngle = template.ShotParameters?.CantAngle, }; var winds = template.Wind == null ? null : new Wind[] { template.Wind }; var trajectory = cal.Calculate(template.Ammunition, template.Rifle, template.Atmosphere, shot, winds, table); trajectory.Length.Should().Be(template.Trajectory.Count); for (int i = 0; i < trajectory.Length; i++) { var point = trajectory[i]; var templatePoint = template.Trajectory[i]; point.Distance.In(templatePoint.Distance.Unit).Should().BeApproximately(templatePoint.Distance.Value, templatePoint.Distance.Value * velocityAccuracyInPercent, $"@{point.Distance:N0}"); point.Velocity.In(templatePoint.Velocity.Unit).Should().BeApproximately(templatePoint.Velocity.Value, templatePoint.Velocity.Value * velocityAccuracyInPercent, $"@{point.Distance:N0}"); if (i > 0) { var dropAccuracyInInch = Measurement <AngularUnit> .Convert(dropAccuracyInMOA, AngularUnit.MOA, AngularUnit.InchesPer100Yards) * templatePoint.Distance.In(DistanceUnit.Yard) / 100; point.Drop.In(DistanceUnit.Inch).Should().BeApproximately(templatePoint.Drop.In(DistanceUnit.Inch), dropAccuracyInInch, $"@{point.Distance:N0}"); } } }
public void CustomTableNotSpecifiedException() { TableLoader template = TableLoader.FromResource("g1_nowind"); template.Ammunition.BallisticCoefficient = new BallisticCoefficient(template.Ammunition.BallisticCoefficient.Value, DragTableId.GC); var cal = new TrajectoryCalculator(); ((Action)(() => cal.SightAngle(template.Ammunition, template.Rifle, template.Atmosphere))) .Should().Throw <ArgumentNullException>(); ShotParameters shot = new ShotParameters() { Step = new Measurement <DistanceUnit>(50, DistanceUnit.Yard), MaximumDistance = new Measurement <DistanceUnit>(1000, DistanceUnit.Yard), SightAngle = new Measurement <AngularUnit>(10, AngularUnit.MOA), ShotAngle = template.ShotParameters?.ShotAngle, CantAngle = template.ShotParameters?.CantAngle, }; ((Action)(() => cal.Calculate(template.Ammunition, template.Rifle, template.Atmosphere, shot, null))) .Should().Throw <ArgumentNullException>(); }
public void TrajectoryTest(string name, double velocityAccuracyInPercent, double dropAccuracyInMOA, double windageAccuracyInMOA) { TableLoader template = TableLoader.FromResource(name); var cal = new TrajectoryCalculator(); ShotParameters shot = new ShotParameters() { Step = new Measurement <DistanceUnit>(50, DistanceUnit.Yard), MaximumDistance = new Measurement <DistanceUnit>(1000, DistanceUnit.Yard), SightAngle = cal.SightAngle(template.Ammunition, template.Rifle, template.Atmosphere), ShotAngle = template.ShotParameters?.ShotAngle, CantAngle = template.ShotParameters?.CantAngle, }; var winds = template.Wind == null ? null : new Wind[] { template.Wind }; var trajectory = cal.Calculate(template.Ammunition, template.Rifle, template.Atmosphere, shot, winds); trajectory.Length.Should().Be(template.Trajectory.Count); for (int i = 0; i < trajectory.Length; i++) { var point = trajectory[i]; var templatePoint = template.Trajectory[i]; point.Distance.In(templatePoint.Distance.Unit).Should().BeApproximately(templatePoint.Distance.Value, templatePoint.Distance.Value * velocityAccuracyInPercent, $"@{point.Distance:N0}"); point.Velocity.In(templatePoint.Velocity.Unit).Should().BeApproximately(templatePoint.Velocity.Value, templatePoint.Velocity.Value * velocityAccuracyInPercent, $"@{point.Distance:N0}"); var dropAccuracyInInch = Measurement <AngularUnit> .Convert(dropAccuracyInMOA, AngularUnit.MOA, AngularUnit.InchesPer100Yards) * templatePoint.Distance.In(DistanceUnit.Yard) / 100; var windageAccuracyInInch = Measurement <AngularUnit> .Convert(windageAccuracyInMOA, AngularUnit.MOA, AngularUnit.InchesPer100Yards) * templatePoint.Distance.In(DistanceUnit.Yard) / 100; point.Drop.In(DistanceUnit.Inch).Should().BeApproximately(templatePoint.Drop.In(DistanceUnit.Inch), dropAccuracyInInch, $"@{point.Distance:N0}"); point.Windage.In(DistanceUnit.Inch).Should().BeApproximately(templatePoint.Windage.In(DistanceUnit.Inch), windageAccuracyInInch, $"@{point.Distance:N0}"); } }