From 507a668cb014605291fc9092d325e293f629e6ef Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Thu, 21 Jul 2016 21:48:41 -0400 Subject: [PATCH] I'm not sure what Pythagoras did to Steve, buuuut This actually could use a bit of stating in words, imo. And I don't feel like we need to repeat the function so close to the original code containing it. --- src/ch05-00-structs.md | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/ch05-00-structs.md b/src/ch05-00-structs.md index b623fe39d..7574d6ca8 100644 --- a/src/ch05-00-structs.md +++ b/src/ch05-00-structs.md @@ -56,21 +56,18 @@ Point 2: (12, 0) Distance: 13 ``` -Let's take a quick look at `distance()` before we move forward: +Let's take a quick look at `distance()` before we move forward. To find the +distance between two points, we can use the Pythagorean Theorem. The theorem is +named after Pythagoras, who was the first person to mathematically prove this +formula. The details aren't that important; just know the theorem says that the +formula for the distance between two points is equal to: -```rust -fn distance(x1: f64, y1: f64, x2: f64, y2: f64) -> f64 { - let x_squared = f64::powi(x2 - x1, 2); - let y_squared = f64::powi(y2 - y1, 2); +- squaring the distance between the points horizontally (the "x" direction) +- squaring the distance between the points vertically (the "y" direction) +- adding those together +- and taking the square root of that. - f64::sqrt(x_squared + y_squared) -} -``` - -To find the distance between two points, we can use the Pythagorean Theorem. -The theorem is named after Pythagoras, who was the first person to mathematically -prove this formula. The details aren't that important, to be honest. There's a few -things that we haven't discussed yet, though. +So that's what we're implementing here. ```rust,ignore f64::powi(2.0, 3)