擅长:python、mysql、java
<p>我建议<a href="https://docs.python.org/3/library/enum.html?highlight=enum#module-enum" rel="nofollow noreferrer">implementing an ^{<cd1>}</a>来定义这个。似乎是最完美的选择。简单示例:</p>
<pre><code>from enum import Enum
class ClockMotion(Enum):
Clockwise = 1
CounterClockwise = -1
@classmethod
def check_motion(cls, angle1, angle2):
if angle2 - angle1 > 0:
return cls.Clockwise
else:
return cls.CounterClockwise
</code></pre>
<p>测试:</p>
<pre><code>>>>ClockMotion.check_motion(-30, 60)
ClockMotion.Clockwise
</code></pre>
<p>对于顶点,请使用一个简单的类,因为它将具有实例值:</p>
<pre><code>class Vertex:
def __init__(self, lb, ub):
self.lb = lb
self.ub = ub
</code></pre>