OSDN Git Service

バージョン12.11の準備
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / Model / AirCorpsFighterPower.cs
1 // Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 //\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
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\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
14 \r
15 using System;\r
16 \r
17 namespace KancolleSniffer.Model\r
18 {\r
19     public class AirCorpsFighterPower\r
20     {\r
21         public Model.Range AirCombat { get; }\r
22         public Model.Range Interception { get; }\r
23         public bool Difference { get; }\r
24 \r
25         public AirCorpsFighterPower(Range fighterPower)\r
26         {\r
27             AirCombat = new Model.Range(fighterPower.Min.AirCombat, fighterPower.Max.AirCombat);\r
28             Interception = new Model.Range(fighterPower.Min.Interception, fighterPower.Max.Interception);\r
29             Difference = Interception.Min != AirCombat.Min;\r
30         }\r
31 \r
32         public struct Pair\r
33         {\r
34             public double AirCombat { get; }\r
35             public double Interception { get; }\r
36 \r
37             public Pair(double airCombat, double interception)\r
38             {\r
39                 AirCombat = airCombat;\r
40                 Interception = interception;\r
41             }\r
42 \r
43             public static Pair Max(Pair value1, Pair value2)\r
44             {\r
45                 return new Pair(Math.Max(value1.AirCombat, value2.AirCombat),\r
46                     Math.Max(value1.Interception, value2.Interception));\r
47             }\r
48 \r
49             public static Pair operator +(Pair lhs, Pair rhs)\r
50             {\r
51                 return new Pair(lhs.AirCombat + rhs.AirCombat, lhs.Interception + rhs.Interception);\r
52             }\r
53 \r
54             public static Pair operator +(Pair lhs, double rhs)\r
55             {\r
56                 return new Pair(lhs.AirCombat + rhs, lhs.Interception + rhs);\r
57             }\r
58 \r
59             public static Pair operator *(Pair lhs, Pair rhs)\r
60             {\r
61                 return new Pair(lhs.AirCombat * rhs.AirCombat, lhs.Interception * rhs.Interception);\r
62             }\r
63 \r
64             public static Pair operator *(Pair lhs, double rhs)\r
65             {\r
66                 return new Pair(lhs.AirCombat * rhs, lhs.Interception * rhs);\r
67             }\r
68 \r
69             public Pair Floor()\r
70             {\r
71                 return new Pair((int)AirCombat, (int)Interception);\r
72             }\r
73         }\r
74 \r
75         public struct Range\r
76         {\r
77             public Pair Min { get; }\r
78             public Pair Max { get; }\r
79 \r
80             private Range(Pair min, Pair max)\r
81             {\r
82                 Min = min;\r
83                 Max = max;\r
84             }\r
85 \r
86             public Range(Pair @base, RangeD range)\r
87             {\r
88                 Min = (@base + range.Min).Floor();\r
89                 Max = (@base + range.Max).Floor();\r
90             }\r
91 \r
92             public static Range operator +(Range lhs, Range rhs)\r
93             {\r
94                 return new Range(lhs.Min + rhs.Min, lhs.Max + rhs.Max);\r
95             }\r
96 \r
97             public static Range operator *(Range lhs, Pair rhs)\r
98             {\r
99                 return new Range(lhs.Min * rhs, lhs.Max * rhs);\r
100             }\r
101 \r
102             public Range Floor()\r
103             {\r
104                 return new Range(Min.Floor(), Max.Floor());\r
105             }\r
106         }\r
107     }\r
108 }