Skip to content

Commit

Permalink
Use new PbrResults struct for PBR results
Browse files Browse the repository at this point in the history
  • Loading branch information
steveno committed Aug 29, 2017
1 parent 121a447 commit e84f445
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
22 changes: 11 additions & 11 deletions src/PbrDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ public class Balistica.PbrDialog : Gtk.Dialog {
*/
[GtkCallback]
public void btnCalculate_clicked() {
double pbr_results[4] = LibBalistica.PBR.pbr (d,
double.parse (drag_coeff.get_text ()),
double.parse (initial_vel.get_text ()),
double.parse (sight_height.get_text ()),
double.parse (vital_zone_sz.get_text ())) ;

results.buffer.text = "Near Zero: " + pbr_results[0].to_string () + " yards\n" ;
results.buffer.text += "Far Zero: " + pbr_results[1].to_string () + " yards\n" ;
results.buffer.text += "Minimum PBR: " + pbr_results[2].to_string () + " yards\n" ;
results.buffer.text += "Maximum PBR: " + pbr_results[3].to_string () + " yards\n\n" ;
results.buffer.text += "Sight-in at 100 yards: " + pbr_results[4].to_string () + " inches high" ;
LibBalistica.PbrResult pbr_result = LibBalistica.PBR.pbr (d,
double.parse (drag_coeff.get_text ()),
double.parse (initial_vel.get_text ()),
double.parse (sight_height.get_text ()),
double.parse (vital_zone_sz.get_text ())) ;

results.buffer.text = "Near Zero: %.2f yards\n".printf (pbr_result.near_zero) ;
results.buffer.text += "Far Zero: %.2f yards\n".printf (pbr_result.far_zero) ;
results.buffer.text += "Minimum PBR: %.2f yards\n".printf (pbr_result.min_pbr) ;
results.buffer.text += "Maximum PBR: %.2f yards\n\n".printf (pbr_result.max_pbr) ;
results.buffer.text += "Sight-in at 100 yards: %.2f inches high".printf (pbr_result.sight_in_height) ;
}

}
11 changes: 11 additions & 0 deletions src/libbalistica/libbalistica.vala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ namespace LibBalistica{
public double vertical_velocity ;
}

/**
* Return value for a PBR optimization results
*/
public struct PbrResult {
public double near_zero ;
public double far_zero ;
public double min_pbr ;
public double max_pbr ;
public double sight_in_height ;
}

/**
* The different drag functions you are allowed to pick from
*/
Expand Down
24 changes: 10 additions & 14 deletions src/libbalistica/pbr.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ namespace LibBalistica{
* must remain in, e.g. the point impact must always be within a
* two inch diameter circle.
*
* @return An array of 5 doubles consisting of the near zero, far zero, min pbr,
* max pbr, and sight-in height at 100 yards.
* @return A LibBalistica.PbrResult struct containing our five results.
*/
public static double[] pbr(DragFunction Drag, double DragCoefficient, double Vi, double SightHeight, double VitalSize) {
double result[4] ;
public static LibBalistica.PbrResult pbr(DragFunction Drag, double DragCoefficient, double Vi, double SightHeight, double VitalSize) {
LibBalistica.PbrResult result = LibBalistica.PbrResult () ;

double t = 0 ;
double dt = 0.5 / Vi ;
double v = 0 ;
Expand Down Expand Up @@ -170,16 +170,12 @@ namespace LibBalistica{
}
}

// Near zero
result[0] = zero / 3 ;
// Far zero
result[1] = farzero / 3 ;
// Minimum PBR
result[2] = min_pbr_range / 3 ;
// Maximum PBR
result[3] = max_pbr_range / 3 ;
// Sight-in at 100 yards (in 100ths of an inch)
result[4] = tin100 ;
result.near_zero = zero / 3 ;
result.far_zero = farzero / 3 ;
result.min_pbr = min_pbr_range / 3 ;
result.max_pbr = max_pbr_range / 3 ;
// At 100 yards (in 100ths of an inch)
result.sight_in_height = tin100 ;

return result ;
}
Expand Down

0 comments on commit e84f445

Please # to comment.