|
237 | 237 | }
|
238 | 238 |
|
239 | 239 | fn norm(self) -> f64 {
|
240 |
| - let squared_norm = self.real.powi(2) + self.imaginary.powi(2); |
241 |
| - squared_norm.sqrt() |
| 240 | + self.real.abs() + self.imaginary.abs() |
242 | 241 | }
|
243 | 242 | ```
|
244 | 243 | ]
|
|
262 | 261 |
|
263 | 262 | #text(size: 21pt)[
|
264 | 263 | ```rust
|
265 |
| - trait Add { |
266 |
| - fn add(self, other: Self) -> Self; |
| 264 | + trait MyAdd { |
| 265 | + fn my_add(self, other: Self) -> Self; |
267 | 266 | }
|
268 | 267 | ```
|
269 | 268 | ]
|
|
274 | 273 |
|
275 | 274 | #text(size: 21pt)[
|
276 | 275 | ```rust
|
277 |
| - impl Add for ComplexNumber { |
278 |
| - fn add(self, other: Self) -> Self { |
| 276 | + impl MyAdd for ComplexNumber { |
| 277 | + fn my_add(self, other: Self) -> Self { |
279 | 278 | Self {
|
280 | 279 | real: self.real + other.real,
|
281 | 280 | imaginary: self.imaginary + other.imaginary,
|
|
468 | 467 | + Refactor ```rust PixelColor::new()``` to return ```rust Result<Self, String>```
|
469 | 468 | - ```rust new()``` should return ```rust Err``` if a color channel is ```rust < 0``` or ```rust > 1```
|
470 | 469 | - ```rust String``` represents an error message e.g., ```rust String::from("foo")```
|
471 |
| - + Change return type of ```rust main()``` to ```rust Result<(), String>``` and ```rust return Ok(())``` |
| 470 | + + Change return type of ```rust main()``` to ```rust Result<(), String>``` and return ```rust Ok(())``` |
472 | 471 | + Handle the result of ```rust PixelColor::new()``` with pattern matching
|
473 | 472 | - Save ```rust Ok``` in the variable
|
474 | 473 | - Print ```rust Err``` message and return error from ```rust main()```
|
|
621 | 620 | - Store red pixel if ```rust x == y```, else black
|
622 | 621 | - Create an image of size 20x10 in ```rust main()``` using this function
|
623 | 622 | + ```rust fn is_red(self) -> bool``` should now take ```rust self``` by reference (```rust &self```)
|
624 |
| - + Iterate over pixels by index, find red pixels, store them in a collection |
| 623 | + + Create new function, iterate over pixels by index, find red pixels, store them in a collection |
625 | 624 | - ```rust fn get_red_positions(image: &Vec<Vec<PixelColor>>) -> Vec<(usize, usize)>```
|
626 | 625 | + Add ```rust #[derive(Debug)]``` to ```rust PixelColor```
|
627 | 626 | + Use ```rust dbg!(positions);``` to print the resulting collection
|
|
0 commit comments