Skip to content

Commit

Permalink
add zero offset, update dependencies, switch dependabot to notify onl…
Browse files Browse the repository at this point in the history
…y mode
  • Loading branch information
nikolaygekht committed Nov 4, 2022
1 parent 2daa06c commit 1a9bae3
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ updates:
directory: "/"
schedule:
interval: "monthly"
open-pull-requests-limit: 0
2 changes: 1 addition & 1 deletion BallisticCalculator.Debug/BallisticCalculator.Debug.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Svg" Version="3.4.3" />
<PackageReference Include="Svg" Version="3.4.4" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions BallisticCalculator.Test/BallisticCalculator.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NReco.Csv" Version="1.0.1" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
26 changes: 26 additions & 0 deletions BallisticCalculator.Test/Calculator/TrajectoryCalculatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ public void Zero1(double ballisticCoefficient, DragTableId ballisticTable, doubl
sightAngle1.In(sightAngleUnit).Should().BeApproximately(sightAngle, sightAngleAccuracy);
}

[Theory]
[InlineData(null, 5.489)]
[InlineData(0.0, 5.489)]
[InlineData(-2.0, 3.579)]
[InlineData(-0.5, 5.012)]
[InlineData(1.0, 6.444)]
public void Zero_WithOffset(double? offset, double sightAngle)
{
Ammunition ammunition = new Ammunition(
weight: new Measurement<WeightUnit>(69, WeightUnit.Grain),
muzzleVelocity: new Measurement<VelocityUnit>(2600, VelocityUnit.FeetPerSecond),
ballisticCoefficient: new BallisticCoefficient(0.355, DragTableId.G1));

Rifle rifle = new Rifle(
sight: new Sight(sightHeight: new Measurement<DistanceUnit>(3, DistanceUnit.Inch), Measurement<AngularUnit>.ZERO, Measurement<AngularUnit>.ZERO),
zero: new ZeroingParameters(distance: new Measurement<DistanceUnit>(100, DistanceUnit.Yard), ammunition: null, atmosphere: null));

if (offset != null)
rifle.Zero.VerticalOffset = DistanceUnit.Inch.New(offset.Value);

Atmosphere atmosphere = new Atmosphere(); //default atmosphere

var sightAngle1 = (new TrajectoryCalculator()).SightAngle(ammunition, rifle, atmosphere);
sightAngle1.In(AngularUnit.MOA).Should().BeApproximately(sightAngle, 5e-2);
}

[Theory]
[InlineData("g1_nowind", 0.005, 0.2, 0.2)]
[InlineData("g1_nowind_up", 0.005, 0.4, 0.4)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace BallisticCalculator.Test.Data.Serialization
public class CalculatorSerializerTest
{
[Fact]
public void TestTrajectoryPoint()
public void Roundtrip_TrajectoryPoint()
{
var point = new TrajectoryPoint(TimeSpan.FromMilliseconds(0.5),
new Measurement<WeightUnit>(55, WeightUnit.Grain),
Expand Down Expand Up @@ -102,7 +102,7 @@ public void ReadLegacy_Incomplete()
}

[Fact]
public void RoundTrip_Ammunition1()
public void Roundtrip_Ammunition1()
{
Ammunition ammo = new Ammunition()
{
Expand All @@ -129,7 +129,7 @@ public void RoundTrip_Ammunition1()
}

[Fact]
public void RoundTrip_Ammunition2()
public void Roundtrip_Ammunition2()
{
Ammunition ammo = new Ammunition()
{
Expand All @@ -154,7 +154,7 @@ public void RoundTrip_Ammunition2()
}

[Fact]
public void RoundTrip_AmmuntionLibraryEntry()
public void Roundtrip_AmmuntionLibraryEntry()
{
AmmunitionLibraryEntry entry = new AmmunitionLibraryEntry()
{
Expand Down Expand Up @@ -195,7 +195,7 @@ public void RoundTrip_AmmuntionLibraryEntry()
}

[Fact]
public void RoundTripAtmosphere()
public void Roundtrip_Atmosphere()
{
var atmo = new Atmosphere(new Measurement<DistanceUnit>(123, DistanceUnit.Meter),
new Measurement<PressureUnit>(30.02, PressureUnit.InchesOfMercury),
Expand All @@ -216,7 +216,49 @@ public void RoundTripAtmosphere()
}

[Fact]
public void RoundTripRifle()
public void Roundtrip_ZeroParam_NullableValues()
{
var zero = new ZeroingParameters()
{
Distance = DistanceUnit.Yard.New(100)
};

SerializerRoundtrip serializer = new SerializerRoundtrip();
var xml = serializer.Serialize(zero);
var zero2 = serializer.Deserialize<ZeroingParameters>(xml);

zero2.Should().NotBeNull();
zero2.Atmosphere.Should().BeNull();
zero2.Ammunition.Should().BeNull();
zero2.VerticalOffset.Should().BeNull();
zero2.Distance.Should().Be(zero.Distance);
}

[Fact]
public void Roundtrip_ZeroParam_NoNullableValues()
{
var zero = new ZeroingParameters()
{
Distance = DistanceUnit.Yard.New(100),
VerticalOffset = DistanceUnit.Inch.New(5)

};

SerializerRoundtrip serializer = new SerializerRoundtrip();
var xml = serializer.Serialize(zero);
var zero2 = serializer.Deserialize<ZeroingParameters>(xml);

zero2.Should().NotBeNull();
zero2.Atmosphere.Should().BeNull();
zero2.Ammunition.Should().BeNull();
zero2.VerticalOffset.Should()
.NotBeNull()
.And.Be(zero.VerticalOffset);
zero2.Distance.Should().Be(zero.Distance);
}

[Fact]
public void Roundtrip_Rifle()
{
Rifle rifle = new Rifle()
{
Expand Down Expand Up @@ -278,7 +320,7 @@ public void RoundTripRifle()
}

[Fact]
public void RoundTripWind1()
public void Roundtrip_Wind1()
{
var wind = new Wind()
{
Expand All @@ -297,7 +339,7 @@ public void RoundTripWind1()
}

[Fact]
public void RoundTripWind2()
public void Roundtrip_Wind2()
{
var wind = new Wind()
{
Expand Down
15 changes: 9 additions & 6 deletions BallisticCalculator/Calculations/TrajectoryCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public Measurement<AngularUnit> SightAngle(Ammunition ammunition, Rifle rifle, A
Measurement<DistanceUnit> altDelta = new Measurement<DistanceUnit>(1, DistanceUnit.Meter);
double densityFactor = 0, drag;
Measurement<VelocityUnit> mach = new Measurement<VelocityUnit>(0, VelocityUnit.MetersPerSecond);
Measurement<DistanceUnit> verticalOffset = (rifle.Zero.VerticalOffset) ?? Measurement<DistanceUnit>.ZERO;

var sightAngle = new Measurement<AngularUnit>(150, AngularUnit.MOA);
var barrelAzimuth = new Measurement<AngularUnit>(0, AngularUnit.Radian);
Expand Down Expand Up @@ -105,11 +106,11 @@ public Measurement<AngularUnit> SightAngle(Ammunition ammunition, Rifle rifle, A

var earthGravity = (new Measurement<VelocityUnit>(Measurement<AccelerationUnit>.Convert(1, AccelerationUnit.EarthGravity, AccelerationUnit.MeterPerSecondSquare),
VelocityUnit.MetersPerSecond)).To(velocity.Unit);

var alt = alt0;
//run all the way down the range
while (rangeVector.X <= maximumRange)
{
Measurement<DistanceUnit> alt = alt0 + rangeVector.Y;
//Measurement<DistanceUnit> alt = alt0 + rangeVector.Y;

//update density and Mach velocity each 10 feet
if (MeasurementMath.Abs(lastAtAltitude - alt) > altDelta)
Expand Down Expand Up @@ -144,13 +145,15 @@ public Measurement<AngularUnit> SightAngle(Ammunition ammunition, Rifle rifle, A
new Measurement<DistanceUnit>(velocityVector.Z.In(VelocityUnit.MetersPerSecond) * deltaTime.TotalSeconds, DistanceUnit.Meter));

rangeVector += deltaRangeVector;
alt += deltaRangeVector.Y;

if (rangeVector.X >= rifle.Zero.Distance)
{
if (Math.Abs(rangeVector.Y.In(DistanceUnit.Millimeter)) < 1)
var match = rangeVector.Y - verticalOffset;
if (Math.Abs(match.In(DistanceUnit.Millimeter)) < 1)
return sightAngle;

sightAngle += new Measurement<AngularUnit>(-rangeVector.Y.In(DistanceUnit.Centimeter) / rifle.Zero.Distance.In(DistanceUnit.Meter) * 100, AngularUnit.CmPer100Meters);
sightAngle += new Measurement<AngularUnit>(-match.In(DistanceUnit.Centimeter) / rifle.Zero.Distance.In(DistanceUnit.Meter) * 100, AngularUnit.CmPer100Meters);
break;
}

Expand Down Expand Up @@ -249,12 +252,11 @@ public TrajectoryPoint[] Calculate(Ammunition ammunition, Rifle rifle, Atmospher
VelocityUnit.MetersPerSecond)).To(velocity.Unit);


var alt = alt0;

//run all the way down the range
while (rangeVector.X <= maximumRange)
{
Measurement<DistanceUnit> alt = alt0 + rangeVector.Y;

//update density and Mach velocity each 10 feet of altitude
if (MeasurementMath.Abs(lastAtAltitude - alt) > altDelta)
{
Expand Down Expand Up @@ -322,6 +324,7 @@ public TrajectoryPoint[] Calculate(Ammunition ammunition, Rifle rifle, Atmospher
new Measurement<DistanceUnit>(velocityVector.Z.In(VelocityUnit.MetersPerSecond) * deltaTime.TotalSeconds, DistanceUnit.Meter));

rangeVector += deltaRangeVector;
alt += deltaRangeVector.Y;
velocity = velocityVector.Magnitude;
time = time.Add(BallisticMath.TravelTime(deltaRangeVector.Magnitude, velocity));
}
Expand Down
9 changes: 9 additions & 0 deletions BallisticCalculator/Data/ZeroingParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public class ZeroingParameters
[BXmlProperty("zero-distance")]
public Measurement<DistanceUnit> Distance { get; set; }

/// <summary>
/// The vertical offset of the zero impact point from aim point
///
/// Positive values are up, negative values are down
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[BXmlProperty("vertical-offset", Optional = true)]
public Measurement<DistanceUnit>? VerticalOffset { get; set; }

/// <summary>
/// Default constructor
/// </summary>
Expand Down

0 comments on commit 1a9bae3

Please sign in to comment.