From f95f63ffd1a3aa83b6137108c4cb5fcaded6c997 Mon Sep 17 00:00:00 2001 From: CoCoSol007 Date: Wed, 14 Feb 2024 15:26:45 +0100 Subject: [PATCH] change min and max --- Cargo.lock | 7 +++++++ crates/border-wars/Cargo.toml | 1 + crates/border-wars/src/hex.rs | 21 +++------------------ 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04d3d7d..58bf08f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1317,6 +1317,7 @@ dependencies = [ "bevy", "bevy_egui", "num", + "partial-min-max", ] [[package]] @@ -3328,6 +3329,12 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "partial-min-max" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6448add382c60bbbc64f9dab41309a12ec530c05191601042f911356ac09758c" + [[package]] name = "paste" version = "1.0.14" diff --git a/crates/border-wars/Cargo.toml b/crates/border-wars/Cargo.toml index 389e9b0..5f2e0a0 100644 --- a/crates/border-wars/Cargo.toml +++ b/crates/border-wars/Cargo.toml @@ -14,3 +14,4 @@ workspace = true bevy = "0.12.1" bevy_egui = "0.24.0" num = "0.4.1" +partial-min-max = "0.4.0" diff --git a/crates/border-wars/src/hex.rs b/crates/border-wars/src/hex.rs index 5d7adcc..492afd9 100644 --- a/crates/border-wars/src/hex.rs +++ b/crates/border-wars/src/hex.rs @@ -5,25 +5,10 @@ use std::hash::Hash; use std::ops; use num::Signed; +use partial_min_max::{max, min}; /// Represents a number that can be used in a hexagonal grid. -pub trait HexNumber: Signed + PartialEq + Copy + PartialOrd { - /// Returns the minimum value between `self` and `other`. - fn min(&self, other: Self) -> Self { - if *self < other { - return *self; - } - other - } - - /// Returns the maximum value between `self` and `other`. - fn max(&self, other: Self) -> Self { - if *self > other { - return *self; - } - other - } -} +pub trait HexNumber: Signed + PartialEq + Copy + PartialOrd {} impl HexNumber for T {} /// Represents a position in a hexagonal grid. @@ -99,7 +84,7 @@ impl HexPosi pub fn range(&self, range: T) -> HashSet { let mut result_positions = HashSet::new(); for q in num::range_inclusive(-range, range) { - for r in num::range_inclusive((-range).max(-q - range), range.min(-q + range)) { + for r in num::range_inclusive(max(-range, -q - range), min(range, -q + range)) { result_positions.insert(Self { q, r }); } }