Commit 1bbd78f3 authored by Meade's avatar Meade

Added version 8.0.0. See README.md for changes.

parent 3f2645e5
Pipeline #30638420 failed with stage
in 6 minutes and 5 seconds
## New In 8.0.0
* Created `enumImplementations.rs`, which includes a massive
improvement in how we go from a `String` coming from gtk to our enums.
* Got rid of the binary search in `increaseABV`, because we weren't actually using it.
We couldn't because of the initial problem of not being able to invert the formula algebraically.
We did change the while loop into a parallel iterator using `rayon`. It now runs on as many
cores as your computer has.
* We also parallelised other loops which caused a huge performance increase.
* Created `structImplementations.rs` and cleaned up the `match` statement
in `grainToABV.rs`.
* Updated `BrewStilleryIcon.svg` to be a path so it renders correctly on all systems.
* Changed `grainToGravity()` to be called `mashToGravity()`
* Updated `BrewStillery.css` to highlight ComboBoxes
* Updated and added more tests.
## New In 7.0.0
* Implemented `binary_search_by()` in `increaseABV`, which greatly increases efficiency.
* `const` all the thiiings!!! Anything that could be made a constant was in this release.
......
This diff is collapsed.
[package]
name = "BrewStillery"
version = "7.0.0"
version = "8.0.0"
authors = ["Meade <thedarkula2049@gmail.com>", "Emily <marleybrush5@gmail.com>"]
description = "BrewStillery is a brewer's, vintner's, and distiller's calculator. It has a multitude of great functions, such as calculating ABV, determining carbonation, and total sparge water needed."
# documentation to come
# documentation = "..."
homepage = "https://monkeylog.in"
repository = "https://github.com/MonkeyLog/BrewStillery"
repository = "https://gitlab.com/MonkeyLog/BrewStillery"
readme = "README.md"
keywords = ["beer", "wine", "champagne", "distilling", "calculator"]
categories = ["science", "gui"]
......@@ -16,12 +16,13 @@ license = "AGPL-3.0"
maintenance = { status = "actively-developed" }
[dependencies.gtk]
version = "0.4.1"
version = "0.5.0"
features = ["v3_22"]
[dependencies]
gdk = "0.8.0"
gio = "0.4.0"
gdk = "0.9.0"
gio = "0.5.0"
rayon = "1.0.2"
[features]
default = []
......@@ -29,6 +30,6 @@ default = []
[profile.dev]
[profile.release]
opt-level = 3
opt-level = "z"
codegen-units = 1
lto = true
\ No newline at end of file
......@@ -4,11 +4,20 @@ It has a multitude of great functions, such as calculating ABV, determining carb
Written in Rust, using GTK3
## New In 7.0.0
* Implemented `binary_search_by()` in `increaseABV`, which greatly increases efficiency.
* `const` all the thiiings!!! Anything that could be made a constant was in this release.
* Slight restructuring of where things are located (like structs and enums).
* Fixed brix ranges in `if` statements.
## New In 8.0.0
* Created `enumImplementations.rs`, which includes a massive
improvement in how we go from a `String` coming from gtk to our enums.
* Got rid of the binary search in `increaseABV`, because we weren't actually using it.
We couldn't because of the initial problem of not being able to invert the formula algebraically.
We did change the while loop into a parallel iterator using `rayon`. It now runs on as many
cores as your computer has.
* We also parallelised other loops which caused a huge performance increase.
* Created `structImplementations.rs` and cleaned up the `match` statement
in `grainToABV.rs`.
* Updated `BrewStilleryIcon.svg` to be a path so it renders correctly on all systems.
* Changed `grainToGravity()` to be called `mashToGravity()`
* Updated `BrewStillery.css` to highlight ComboBoxes
* Updated and added more tests.
## Full Changelog
* [Available Here](CHANGELOG.md)
......
This diff is collapsed.
......@@ -16,7 +16,7 @@
version="1.1"
id="svg24"
inkscape:version="0.92.2 2405546, 2018-03-11"
sodipodi:docname="BrewStilleryIcon2.svg">
sodipodi:docname="BrewStilleryIcon.svg">
<defs
id="defs18">
<inkscape:perspective
......@@ -162,16 +162,16 @@
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.4142136"
inkscape:cx="276.70765"
inkscape:cx="278.12186"
inkscape:cy="246.90718"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
units="px"
inkscape:window-width="1920"
inkscape:window-height="1002"
inkscape:window-height="1000"
inkscape:window-x="0"
inkscape:window-y="26"
inkscape:window-y="27"
inkscape:window-maximized="1"
inkscape:snap-global="false"
scale-x="0.1">
......@@ -187,7 +187,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
......@@ -8100,27 +8100,23 @@
</g>
</g>
</g>
<text
xml:space="preserve"
<g
aria-label="B"
style="font-style:normal;font-weight:normal;font-size:32.909935px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;opacity:1;fill:#445500;fill-opacity:1;stroke:none;stroke-width:0.82274836"
x="27.639158"
y="264.98581"
id="text13236"><tspan
sodipodi:role="line"
id="tspan13234"
x="27.639158"
y="264.98581"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:338.61831665px;font-family:Aldine;-inkscape-font-specification:Aldine;fill:#445500;stroke-width:0.82274836">B</tspan></text>
<text
xml:space="preserve"
id="text13236">
<path
d="m 36.443234,255.84311 q -5.079274,-0.33861 -7.110984,-7.78822 -1.693092,-7.4496 -1.354473,-19.63986 0.677236,-12.19026 3.047564,-27.7667 2.708947,-15.57644 6.09513,-32.16874 3.386183,-16.5923 7.110985,-32.50736 3.724801,-16.25368 6.772366,-29.12117 3.386183,-13.206119 5.417893,-22.010195 2.370328,-8.804076 2.708947,-10.835786 0.338618,-2.03171 3.047565,-3.386183 3.047564,-1.354474 6.772366,-2.03171 3.724801,-1.015855 7.110985,-1.015855 3.724801,-0.338619 5.079274,-0.338619 3.386183,0 6.433748,0.677237 3.386183,0.677237 6.09513,2.03171 2.708947,1.354473 4.06342,4.06342 1.693091,2.708946 1.693091,6.772366 -1.015855,4.402038 -3.386183,12.528878 -2.370328,7.788217 -5.417893,17.269537 -3.047565,9.48131 -6.09513,18.624 -3.047564,9.1427 -5.079274,15.57645 -2.03171,6.43374 -2.708947,9.14269 -0.338618,2.37033 2.03171,-2.03171 6.772366,-12.52888 14.899206,-25.73499 8.46546,-13.54473 17.26953,-23.36466 8.80408,-9.819936 17.94677,-14.221974 9.48132,-4.740656 18.62401,0.338619 7.44961,4.063419 7.78822,11.513025 0.67724,7.11098 -3.04756,15.57644 -3.7248,8.12684 -9.81993,16.5923 -6.09513,8.12684 -11.85164,14.56059 -5.07928,5.75651 -11.17441,11.1744 -6.09513,5.41789 -12.86749,9.81993 11.1744,2.70895 17.60815,8.46546 6.43375,5.75651 9.14269,13.54473 3.04757,9.48131 1.35448,19.30125 -0.33862,5.07927 -1.6931,10.15854 -1.35447,4.74066 -3.38618,9.48132 -3.38618,8.46546 -10.83578,17.60815 -7.44961,8.80408 -16.25368,13.88335 -8.80408,5.07928 -17.946775,4.06342 -9.142694,-1.35447 -15.91506,-12.8675 -2.708947,-5.41789 -3.724802,-10.49716 -0.677237,-5.07928 -0.677237,-9.48132 v -0.67723 q 0.677237,-3.7248 3.724802,-3.04757 1.693092,0 2.708946,1.01586 1.354474,1.01585 1.354474,2.70894 v 0.33862 q -0.677237,7.44961 3.047565,15.91506 5.079274,8.46546 9.481312,8.46546 4.402039,0 8.12684,-5.07927 3.724802,-5.07928 6.772366,-13.54474 3.047569,-8.80407 5.079279,-17.60815 2.03171,-8.80407 3.04756,-16.25368 1.35447,-7.4496 1.35447,-10.49717 0,-6.77236 -3.7248,-10.49716 -3.7248,-4.06342 -7.788219,-6.43375 -3.724801,-2.70895 -5.756511,-4.40204 -1.693091,-2.03171 2.03171,-5.07927 0.677237,-0.33862 1.015855,-0.33862 0.677237,-0.33862 2.03171,-1.01586 1.693091,-1.01585 3.724805,-2.03171 2.03171,-1.01585 3.7248,-2.70894 5.41789,-4.74066 11.1744,-12.52888 5.75651,-7.78822 10.49717,-15.57644 4.74066,-7.78823 8.12684,-14.56059 3.38618,-7.11099 4.40204,-10.49717 5.41789,-19.97848 -11.85164,-11.174404 -6.77237,3.386184 -14.22197,12.867494 -7.11099,9.1427 -14.221972,20.3171 -6.772366,10.83579 -12.528878,21.67157 -5.756511,10.49717 -9.481312,16.25368 -2.708947,4.06342 -5.417894,12.19026 -2.708946,8.12684 -5.756511,17.94677 -3.047565,9.48132 -6.433748,19.63986 -3.047565,10.15855 -6.772366,18.62401 -3.386183,8.46546 -7.449603,13.88335 -3.724802,5.4179 -7.788222,5.75651 z"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:338.61831665px;font-family:Aldine;-inkscape-font-specification:Aldine;fill:#445500;stroke-width:0.82274836"
id="path1534" />
</g>
<g
aria-label="S"
style="font-style:normal;font-weight:normal;font-size:32.909935px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;opacity:1;fill:#445500;fill-opacity:1;stroke:none;stroke-width:0.82274836"
x="132.39406"
y="292.3757"
id="text13240"><tspan
sodipodi:role="line"
id="tspan13238"
x="132.39406"
y="292.3757"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:338.61831665px;font-family:Aldine;-inkscape-font-specification:Aldine;fill:#445500;stroke-width:0.82274836">S</tspan></text>
id="text13240">
<path
d="m 193.00674,92.929513 q 8.80407,-0.677236 16.25368,1.693092 7.78822,2.03171 12.86749,8.126835 4.40204,6.09513 5.75651,13.54474 1.6931,7.4496 1.01586,14.8992 -0.67724,7.44961 -3.38618,14.56059 -2.70895,7.11099 -6.77237,12.52888 -2.03171,2.70895 -5.41789,1.01585 -1.01586,-0.67723 -1.35448,-2.37032 -0.33862,-1.6931 0.33862,-2.70895 3.38618,-4.40204 5.75651,-10.49717 2.70895,-6.43375 3.38619,-12.8675 0.67723,-6.77236 -1.01586,-13.20611 -1.35447,-6.43375 -5.75651,-11.1744 -7.11099,-6.09513 -13.54473,-3.72481 -6.43375,2.37033 -10.83579,9.48132 -4.40204,7.11098 -5.41789,16.93091 -1.01586,9.81993 3.04756,18.62401 4.40204,9.48131 9.81993,24.71914 5.75651,15.23782 9.81993,32.50736 4.40204,16.93091 5.4179,33.86183 1.35447,16.93091 -3.38619,29.79841 -4.40203,12.52888 -16.25367,19.30124 -11.51303,6.43375 -33.52322,2.70895 -3.38618,-1.01585 -7.78822,-3.04756 -4.06342,-2.37033 -8.12684,-6.09513 -3.7248,-3.72481 -6.77237,-9.1427 -2.70894,-5.41789 -3.7248,-12.86749 -1.35447,-9.81994 3.38619,-17.94678 5.07927,-8.12684 11.1744,-13.88335 7.11099,-6.43374 16.93092,-11.85164 1.69309,-1.01585 3.04756,-0.33862 1.35447,0.67724 2.37033,2.03171 1.69309,3.04757 -1.35447,5.07928 -17.94677,9.14269 -24.0419,19.30124 -5.75652,10.15855 -4.74066,18.62401 1.35447,8.12684 7.4496,12.8675 6.09513,4.74065 12.8675,3.04756 7.11098,-1.69309 12.19026,-11.51302 5.41789,-9.81993 4.40204,-30.81427 -0.67724,-10.49717 -4.74066,-24.38052 -3.7248,-14.22197 -7.78822,-29.12117 -4.06342,-15.23783 -6.77237,-30.13703 -2.70894,-14.89921 -0.67723,-27.08947 2.03171,-12.19026 10.15854,-20.3171 8.12684,-8.465455 25.735,-10.158547 z"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:338.61831665px;font-family:Aldine;-inkscape-font-specification:Aldine;fill:#445500;stroke-width:0.82274836"
id="path1537" />
</g>
</g>
</svg>
......@@ -7,69 +7,6 @@ pub const FINAL_BRIX_IDEAL: f64 = 4.1480675;
// when finalBrix is unknown, this constant is ideal. it is the average of all BJCP styles
//const fn validBrixRange() -> [f64; 65] {
// let mut validBrixRange: [f64; 65] = [0.0; 65];
//
// validBrixRange[0] = 4.1480675;
//
// for index in 1..65 {
// validBrixRange[index] = validBrixRange[index - 1] + 0.435186445;
// }
//
// validBrixRange
//}
//
//const VALID_BRIX_RANGE: [f64; 65] = validBrixRange();
// this will change to the above const fn when it is stabilised
// we will also make the range much larger since we don't have to do it by hand. probably
// something along the line of 1300
// This constant is the range of valid brix values divided by 64. It spans from 4.1480675 to 32.0
// stepped in 0.435186445 increments.
//pub const VALID_BRIX_RANGE: [f64; 65] = [4.1480675, 4.5833, 5.0184, 5.4536, 5.8888, 6.324, 6.7592,
// 7.1944, 7.6296, 8.0647, 8.4999, 8.9351, 9.3703, 9.8055, 10.2407, 10.6759, 11.1111, 11.5462,
// 11.9814, 12.4166, 12.8518, 13.287, 13.7222, 14.1574, 14.5925, 15.0277, 15.4629, 15.8981,
// 16.3333, 16.7685, 17.2037, 17.6388, 18.074, 18.5092, 18.9444, 19.3796, 19.8148, 20.25, 20.6852,
// 21.1203, 21.5555, 21.9907, 22.4259, 22.8611, 23.2963, 23.7315, 24.1666, 24.6018, 25.037,
// 25.4722, 25.9074, 26.3426, 26.7778, 27.2129, 27.6481, 28.0833, 28.5185, 28.9537, 29.3889,
// 29.8241, 30.2593, 30.6944, 31.1296, 31.5648, 32.0];
//const fn increaseABVRange() -> [f64; 65] {
// let mut increaseABVRange: [f64; 65] = [0.0; 65];
//
// for index in 0..65 {
// increaseABVRange[index] = realABVAndAttenuation(VALID_BRIX_RANGE[index], FINAL_BRIX_IDEAL).0;
// }
//
// increaseABVRange
//}
//
//const INCREASE_ABV_RANGE: [f64; 65] = increaseABVRange();
//
// this will change to the above const fn when it is stabilised
// we will also make the range much larger since we don't have to do it by hand. probably
// something along the line of 1300
pub const INCREASE_ABV_RANGE: [f64; 65] = [-0.1348856155168731, 0.20586246761765334,
0.5403883178643303, 0.8691933787858869, 1.1925297585800612, 1.5107344751707097,
1.824151601109058, 2.133132001641415, 2.4380330904114156, 2.7391497954226844, 3.036990307286312,
3.331860779077896, 3.624142736241799, 3.91422330556268, 4.202495082675534, 4.489356019261316,
4.7752093302447625, 5.060397913058511, 5.345466323601995, 5.630767614763457, 5.916725536618083,
6.203768949919566, 6.492331860245709, 6.782853474518989, 7.075710661797258, 7.371487821851506,
7.670573317934343, 7.9734281866281576, 8.280519297040431, 8.592319549466605, 8.909308099127761,
9.2318957748972, 9.56072320243907, 9.89621642909807, 10.238882381640952, 10.589235751309095,
10.947799377006664, 11.315104656642905, 11.691691987103164, 12.078021270151682,
12.474829810938145, 12.882600294130459, 13.301914099322984, 13.733364251490372,
14.177556043212824, 14.635107689117666, 15.106541005822404, 15.592718722725715,
16.094195355613905, 16.61164801191682, 17.145770496135004, 17.69727416958545, 18.26688884647521,
18.855226282659537, 19.463326322877748, 20.091846861303424, 20.741601228216282,
21.41342625449159, 22.108183399420824, 22.82675991958092, 23.570070079484363,
24.338876684430492, 25.134505021041107, 25.957784353371128, 26.809749938584304];
pub const ZERO_RGBA: RGBA = RGBA {
red: 255.0,
green: 255.0,
......
use gtk;
use gtk::prelude::*;
use std::fmt;
use std::str::FromStr;
use enums::generalEnums::{imperialOrMetric, grainTypes, glassTypes};
impl FromStr for imperialOrMetric {
type Err = String;
fn from_str(inputString: &str) -> Result<Self, Self::Err> {
match inputString {
"imperialGB" => Ok(imperialOrMetric::ImperialGB),
"imperialUS" => Ok(imperialOrMetric::ImperialUS),
"metric" => Ok(imperialOrMetric::Metric),
_ => Err(String::from("A ComboBoxText with imperialOrMetric has a misspelling")),
}
}
}
pub trait comboBoxTextImperialOrMetric {
fn imperialOrMetricFromComboBoxText(&self) -> Result<imperialOrMetric, String>;
}
impl comboBoxTextImperialOrMetric for gtk::ComboBoxText {
fn imperialOrMetricFromComboBoxText(&self) -> Result<imperialOrMetric, String> {
self.get_active_id()
.expect("In a call to imperialOrMetricFromComboBoxText(), .get_active_id() failed")
.parse::<imperialOrMetric>()
}
}
impl fmt::Display for grainTypes {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match *self {
grainTypes::TwoRow => write!(formatter, "2-Row"),
grainTypes::SixRow => write!(formatter, "6-Row"),
grainTypes::Black => write!(formatter, "Black"),
grainTypes::Caramel60 => write!(formatter, "Caramel 60"),
grainTypes::Caramel80 => write!(formatter, "Caramel 80"),
grainTypes::Caramel120 => write!(formatter, "Caramel 120"),
grainTypes::Chocolate => write!(formatter, "Chocolate"),
grainTypes::Corn => write!(formatter, "Corn"),
grainTypes::Dextrine => write!(formatter, "Dextrine"),
grainTypes::Oat => write!(formatter, "Oat"),
grainTypes::Rice => write!(formatter, "Rice"),
grainTypes::Rye => write!(formatter, "Rye"),
grainTypes::Wheat => write!(formatter, "Wheat"),
}
}
}
impl grainTypes {
pub fn grainGravity(self) -> f64 {
match self {
grainTypes::TwoRow => 1.037,
grainTypes::SixRow => 1.035,
grainTypes::Black => 1.025,
grainTypes::Caramel60 => 1.034,
grainTypes::Caramel80 => 1.034,
grainTypes::Caramel120 => 1.033,
grainTypes::Chocolate => 1.034,
grainTypes::Corn => 1.037,
grainTypes::Dextrine => 1.033,
grainTypes::Oat => 1.034,
grainTypes::Rice => 1.032,
grainTypes::Rye => 1.036,
grainTypes::Wheat => 1.036,
}
}
pub fn grainLovibond(self) -> f64 {
match self {
grainTypes::TwoRow => 1.8,
grainTypes::SixRow => 1.8,
grainTypes::Black => 500.0,
grainTypes::Caramel60 => 60.0,
grainTypes::Caramel80 => 80.0,
grainTypes::Caramel120 => 120.0,
grainTypes::Chocolate => 350.0,
grainTypes::Corn => 1.3,
grainTypes::Dextrine => 1.5,
grainTypes::Oat => 1.0,
grainTypes::Rice => 1.0,
grainTypes::Rye => 2.0,
grainTypes::Wheat => 1.6,
}
}
}
impl FromStr for grainTypes {
type Err = String;
fn from_str(inputString: &str) -> Result<Self, Self::Err> {
match inputString {
"2-Row" => Ok(grainTypes::TwoRow),
"6-Row" => Ok(grainTypes::SixRow),
"Black" => Ok(grainTypes::Black),
"Caramel 60" => Ok(grainTypes::Caramel60),
"Caramel 80" => Ok(grainTypes::Caramel80),
"Caramel 120" => Ok(grainTypes::Caramel120),
"Chocolate" => Ok(grainTypes::Chocolate),
"Corn" => Ok(grainTypes::Corn),
"Dextrine" => Ok(grainTypes::Dextrine),
"Oat" => Ok(grainTypes::Oat),
"Rice" => Ok(grainTypes::Rice),
"Rye" => Ok(grainTypes::Rye),
"Wheat" => Ok(grainTypes::Wheat),
_ => Err(String::from("A ComboBoxText with grainTypes has a misspelling")),
}
}
}
pub trait comboBoxTextGrainTypes {
fn grainTypesFromComboBoxText(&self) -> Result<grainTypes, String>;
}
impl comboBoxTextGrainTypes for gtk::ComboBoxText {
fn grainTypesFromComboBoxText(&self) -> Result<grainTypes, String> {
self.get_active_id()
.expect("In a call to grainTypesFromComboBoxText(), .get_active_id() failed")
.parse::<grainTypes>()
}
}
impl fmt::Display for glassTypes {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match *self {
glassTypes::DimplePint => write!(formatter, "Dimple Pint"),
glassTypes::NonickPint => write!(formatter, "Nonick Pint"),
glassTypes::TulipPint => write!(formatter, "Tulip Pint"),
glassTypes::Pilsner => write!(formatter, "Pilsner"),
glassTypes::Mafs => write!(formatter, "Maß"),
glassTypes::DimpleHalfPint => write!(formatter, "Dimple Half Pint"),
glassTypes::NonickHalfPint => write!(formatter, "Nonick Half Pint"),
glassTypes::TulipHalfPint => write!(formatter, "Tulip Half Pint"),
}
}
}
impl glassTypes {
pub fn glassSize(self) -> f64 {
match self {
// Value is in centimeters
glassTypes::DimplePint => 9.8,
glassTypes::NonickPint => 9.0,
glassTypes::TulipPint => 8.5,
glassTypes::Pilsner => 8.0,
// We will switch to proper characters when this issue is stabilised:
// https://github.com/rust-lang/rust/issues/28979
// glassTypes::Maß => 10.5,
glassTypes::Mafs => 10.5,
glassTypes::DimpleHalfPint => 8.0,
glassTypes::NonickHalfPint => 7.0,
glassTypes::TulipHalfPint => 7.2,
}
}
}
impl FromStr for glassTypes {
type Err = String;
fn from_str(inputString: &str) -> Result<Self, Self::Err> {
match inputString {
"Dimple Pint" => Ok(glassTypes::DimplePint),
"Nonick Pint" => Ok(glassTypes::NonickPint),
"Tulip Pint" => Ok(glassTypes::TulipPint),
"Pilsner" => Ok(glassTypes::Pilsner),
"Maß" => Ok(glassTypes::Mafs),
"Dimple Half Pint" => Ok(glassTypes::DimpleHalfPint),
"Nonick Half Pint" => Ok(glassTypes::NonickHalfPint),
"Tulip Half Pint" => Ok(glassTypes::TulipHalfPint),
_ => Err(String::from("A ComboBoxText with glassTypes has a misspelling")),
}
}
}
pub trait comboBoxTextglassTypes {
fn glassTypesFromComboBoxText(&self) -> Result<glassTypes, String>;
}
impl comboBoxTextglassTypes for gtk::ComboBoxText {
fn glassTypesFromComboBoxText(&self) -> Result<glassTypes, String> {
self.get_active_id()
.expect("In a call to glassTypesFromComboBoxText(), .get_active_id() failed")
.parse::<glassTypes>()
}
}
\ No newline at end of file
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum imperialOrMetric {
imperialGB,
imperialUS,
metric,
ImperialGB,
ImperialUS,
Metric,
}
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum grainTypes {
TwoRow,
SixRow,
Black,
Caramel60,
Caramel80,
Caramel120,
Chocolate,
Corn,
Dextrine,
Oat,
Rice,
Rye,
Wheat,
}
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum glassTypes {
DimplePint,
NonickPint,
TulipPint,
Pilsner,
// We will switch to proper characters when this issue is stabilised:
// https://github.com/rust-lang/rust/issues/28979
// Maß,
Mafs,
DimpleHalfPint,
NonickHalfPint,
TulipHalfPint,
}
\ No newline at end of file
pub mod generalEnums;
\ No newline at end of file
pub mod generalEnums;
pub mod enumImplementations;
\ No newline at end of file
......@@ -2,74 +2,94 @@ use gtk;
use gtk::prelude::*;
use functions::commonFunctions::{inputMatching, singleInput};
use enums::generalEnums::imperialOrMetric;
use enums::enumImplementations::comboBoxTextImperialOrMetric;
pub fn champagneCarbonationPrep(champagneCarbonationBuilder: &gtk::Builder) {
let champagneCarbonationVolume: gtk::Entry = champagneCarbonationBuilder.get_object("champagneCarbonationVolume").expect("champagneCarbonationPrep(), champagneCarbonationVolume");
let champagneCarbonationVolumeBuffer: String = champagneCarbonationVolume.get_text().expect("champagneCarbonationPrep(), champagneCarbonationVolumeBuffer");
let champagneCarbonationVolume: gtk::Entry = champagneCarbonationBuilder
.get_object("champagneCarbonationVolume")
.expect("champagneCarbonationPrep(), champagneCarbonationVolume");
let champagneCarbonationVolumeBuffer: String = champagneCarbonationVolume.get_text()
.expect("champagneCarbonationPrep(), champagneCarbonationVolumeBuffer");
let champagneVolume: f64 = champagneCarbonationVolumeBuffer.validInput();
let champagneCarbonationSugar: gtk::Entry = champagneCarbonationBuilder.get_object("champagneCarbonationSugar").expect("champagneCarbonationPrep(), champagneCarbonationSugar");
let champagneCarbonationSugar: gtk::Entry = champagneCarbonationBuilder
.get_object("champagneCarbonationSugar")
.expect("champagneCarbonationPrep(), champagneCarbonationSugar");
let champagneCarbonationUnits: gtk::ComboBoxText = champagneCarbonationBuilder
.get_object("champagneCarbonationUnits")
.expect("champagneCarbonationPrep(), champagneCarbonationUnits");
let champagneCarbonationUnits: gtk::ComboBoxText = champagneCarbonationBuilder.get_object("champagneCarbonationUnits").expect("champagneCarbonationPrep(), champagneCarbonationUnits");
let champagneCarbonationUnitsBuffer: String = champagneCarbonationUnits.get_active_id().expect("champagneCarbonationPrep(), champagneCarbonationUnitsBuffer");
let imperialOrMetric: imperialOrMetric = champagneCarbonationUnitsBuffer.unitMatch();
let champagneCarbonationUnitsEnum: imperialOrMetric = champagneCarbonationUnits
.imperialOrMetricFromComboBoxText()
.expect("champagneCarbonationPrep(), champagneCarbonationUnitsEnum");
if champagneVolume.is_nan() {
champagneCarbonationSugar.set_text("Enter a number");
} else if champagneVolume <= 0.0 {
champagneCarbonationSugar.set_text("Enter a positive number");
} else {
let totalSugar: f64 = champagneCarbonationMaths(champagneVolume, imperialOrMetric);
champagneOutput(totalSugar, imperialOrMetric, champagneCarbonationBuilder)
let totalSugar: f64 = champagneCarbonationMaths(champagneVolume, champagneCarbonationUnitsEnum);
champagneOutput(totalSugar, champagneCarbonationUnitsEnum, champagneCarbonationBuilder)
}
}
pub fn champagneCarbonationMaths(champagneVolume: f64, imperialOrMetric: imperialOrMetric) -> f64 {
let mut totalSugar: f64 = 0.0;
pub fn champagneCarbonationMaths(champagneVolume: f64,
champagneCarbonationUnitsEnum: imperialOrMetric) -> f64 {
if imperialOrMetric == imperialOrMetric::imperialGB {
totalSugar = champagneVolume.gallonsGBToGallonsUS().volumeToSugarChampagne();
} else if imperialOrMetric == imperialOrMetric::imperialUS {
totalSugar = champagneVolume.volumeToSugarChampagne();
} else if imperialOrMetric == imperialOrMetric::metric {
totalSugar = champagneVolume.litresToGallonsUS().volumeToSugarChampagne().poundsToKilos();
match champagneCarbonationUnitsEnum {
imperialOrMetric::ImperialGB => {
champagneVolume.gallonsGBToGallonsUS().volumeToSugarChampagne()
}
imperialOrMetric::ImperialUS => {
champagneVolume.volumeToSugarChampagne()
}
imperialOrMetric::Metric => {
champagneVolume.litresToGallonsUS().volumeToSugarChampagne().poundsToKilos()
}
}
totalSugar
}
pub fn champagneCarbonationFormatting(totalSugar: f64, imperialOrMetric: imperialOrMetric) -> String {
let mut sugar: String = String::from("");
pub fn champagneCarbonationFormatting(totalSugar: f64,
champagneCarbonationUnitsEnum: imperialOrMetric) -> String {
if imperialOrMetric == imperialOrMetric::imperialGB || imperialOrMetric == imperialOrMetric::imperialUS {
if totalSugar < 0.995 {
sugar = format!("{:.2} oz", totalSugar.remainingOunces());
} else if totalSugar >= 0.995 && totalSugar < 1.005 {
sugar = format!("{:.0} lb", totalSugar);
} else if totalSugar.trunc() as i64 == 1 && totalSugar.remainingOunces() < 15.995 {
sugar = format!("{:.0} lb {:.2} oz", totalSugar.trunc(), totalSugar.remainingOunces());
} else if totalSugar.fract() == 0.0 || totalSugar.remainingOunces() < 0.005 || totalSugar.remainingOunces() >= 15.995 {
sugar = format!("{:.0} lbs", totalSugar);
} else {
sugar = format!("{:.0} lbs {:.2} oz", totalSugar.trunc(), totalSugar.remainingOunces());
match champagneCarbonationUnitsEnum {
imperialOrMetric::ImperialGB | imperialOrMetric::ImperialUS => {
if totalSugar < 0.995 {
format!("{:.2} oz", totalSugar.remainingOunces())
} else if totalSugar >= 0.995 && totalSugar < 1.005 {
format!("{:.0} lb", totalSugar)
} else if totalSugar.trunc() as i64 == 1 && totalSugar.remainingOunces() < 15.995 {
format!("{:.0} lb {:.2} oz", totalSugar.trunc(), totalSugar.remainingOunces())
} else if totalSugar.fract() == 0.0 || totalSugar.remainingOunces() < 0.005 ||
totalSugar.remainingOunces() >= 15.995 {
format!("{:.0} lbs", totalSugar)
} else {
format!("{:.0} lbs {:.2} oz", totalSugar.trunc(), totalSugar.remainingOunces())
}
}
} else if imperialOrMetric == imperialOrMetric::metric {
if totalSugar >= 0.995 && totalSugar < 1.005 {
sugar = format!("{:.0} kilo", totalSugar);
} else if totalSugar.fract() >= 0.995 || totalSugar.fract() < 0.005 {
sugar = format!("{:.0} kilos", totalSugar);
} else {
sugar = format!("{:.2} kilos", totalSugar);
imperialOrMetric::Metric => {
if totalSugar >= 0.995 && totalSugar < 1.005 {
format!("{:.0} kilo", totalSugar)
} else if totalSugar.fract() >= 0.995 || totalSugar.fract() < 0.005 {
format!("{:.0} kilos", totalSugar)
} else {
format!("{:.2} kilos", totalSugar)
}
}
}
sugar
}
fn champagneOutput(totalSugar: f64, imperialOrMetric: imperialOrMetric, champagneCarbonationBuilder: &gtk::Builder) {
let champagneCarbonationSugar: gtk::Entry = champagneCarbonationBuilder.get_object("champagneCarbonationSugar").expect("champagneCarbonationPrep(), champagneCarbonationSugar");
fn champagneOutput(totalSugar: f64, champagneCarbonationUnitsEnum: imperialOrMetric,
champagneCarbonationBuilder: &gtk::Builder) {
let champagneCarbonationSugar: gtk::Entry = champagneCarbonationBuilder
.get_object("champagneCarbonationSugar")
.expect("champagneCarbonationPrep(), champagneCarbonationSugar");
let sugar: String = champagneCarbonationFormatting(totalSugar, imperialOrMetric);
let sugar: String = champagneCarbonationFormatting(totalSugar, champagneCarbonationUnitsEnum);
champagneCarbonationSugar.set_text(&sugar);
}
\ No newline at end of file
......@@ -2,7 +2,6 @@ use std::f64::consts::E;
use gtk;
use std::f64::NAN;
use structs::generalStructs::colourOverlay;
use enums::generalEnums::imperialOrMetric;
pub trait allOverlays {
fn new(&self) -> colourOverlay;
......@@ -29,10 +28,6 @@ impl allOverlays for gtk::Builder {
pub trait inputMatching {
fn validInput(&self) -> f64;
fn grainGravity(&self) -> f64;
fn grainLovibond(&self) -> f64;
fn glassSize(&self) -> f64;
fn unitMatch(&self) -> imperialOrMetric;
}
impl inputMatching for str {
......@@ -42,72 +37,6 @@ impl inputMatching for str {
Err(_) => NAN,
}
}
fn grainGravity(&self) -> f64 {
match self {
"2-Row" => 1.037,
"6-Row" => 1.035,
"Black" => 1.025,
"Caramel 60" => 1.034,
"Caramel 80" => 1.034,
"Caramel 120" => 1.033,
"Chocolate" => 1.034,
"Corn" => 1.037,
"Dextrine" => 1.033,
"Oat" => 1.034,
"Rice" => 1.032,
"Rye" => 1.036,