1 // Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
17 namespace KancolleSniffer.Model
\r
21 public int Min { get; }
\r
22 public int Max { get; }
\r
24 public Range(int min, int max)
\r
27 throw new ArgumentException();
\r
32 public Range(double min, double max)
\r
35 throw new ArgumentException();
\r
40 public Range(double base_, RangeD range)
\r
42 Min = (int)(base_ + range.Min);
\r
43 Max = (int)(base_ + range.Max);
\r
46 public static Range operator +(Range lhs, Range rhs)
\r
48 return new Range(lhs.Min + rhs.Min, lhs.Max + rhs.Max);
\r
51 public override bool Equals(object other)
\r
53 if (!(other is Range range))
\r
55 return Max == range.Max && Min == range.Min;
\r
58 public override int GetHashCode()
\r
63 public static bool operator ==(Range lhs, Range rhs)
\r
65 return lhs.Equals(rhs);
\r
68 public static bool operator !=(Range lhs, Range rhs)
\r
70 return !(lhs == rhs);
\r
73 public bool Diff => Min != Max;
\r
75 public string RangeString => $"{Min}~{Max}";
\r
78 public struct RangeD
\r
80 public double Min { get; }
\r
81 public double Max { get; }
\r
83 public RangeD(double min, double max)
\r
86 throw new ArgumentException();
\r
91 public RangeD Sqrt() => new RangeD(Math.Sqrt(Min), Math.Sqrt(Max));
\r
93 public static RangeD operator +(RangeD lhs, double rhs)
\r
95 return new RangeD(lhs.Min + rhs, lhs.Max + rhs);
\r
98 public static explicit operator Range(RangeD range)
\r
100 return new Range((int)range.Min, (int)range.Max);
\r