More docs
This commit is contained in:
parent
04fed97deb
commit
7ffba9a295
4 changed files with 283 additions and 2 deletions
|
|
@ -5,6 +5,10 @@ from services.primitives.float_type import Float
|
|||
|
||||
|
||||
class PointCartesian:
|
||||
"""
|
||||
Implements services for the point cartesian LTM.
|
||||
Implementation is done in terms of Python data structures
|
||||
"""
|
||||
def __init__(self, model: UUID, state: State):
|
||||
type_model_id = state.read_dict(state.read_root(), "PointCartesian")
|
||||
self.type_model = UUID(state.read_value(type_model_id))
|
||||
|
|
@ -14,27 +18,66 @@ class PointCartesian:
|
|||
self.point = None
|
||||
|
||||
def create_point(self, x: float, y: float):
|
||||
"""
|
||||
Creates a point.
|
||||
|
||||
Args:
|
||||
x: x coordinate
|
||||
y: y coordinate
|
||||
|
||||
Returns:
|
||||
Nothing.
|
||||
"""
|
||||
if self.point is None:
|
||||
self.point = (x, y)
|
||||
else:
|
||||
raise RuntimeError("A PointCartesian model can contain at most 1 point.")
|
||||
|
||||
def read_point(self):
|
||||
"""
|
||||
Reads point.
|
||||
|
||||
Returns:
|
||||
Textual representation of the point data.
|
||||
"""
|
||||
if self.point is None:
|
||||
raise RuntimeError("No point found in model.")
|
||||
else:
|
||||
return f"(X = {self.point[0]}, Y = {self.point[1]})"
|
||||
|
||||
def delete_point(self):
|
||||
"""
|
||||
Deletes point.
|
||||
|
||||
Returns:
|
||||
Nothing.
|
||||
"""
|
||||
self.point = None
|
||||
|
||||
def apply_movement(self, delta_x: float, delta_y: float):
|
||||
"""
|
||||
Moves point.
|
||||
|
||||
Args:
|
||||
delta_x: change in x dimension
|
||||
delta_y: change in y dimension
|
||||
|
||||
Returns:
|
||||
Nothing.
|
||||
"""
|
||||
if self.point is not None:
|
||||
self.point = (self.point[0] + delta_x, self.point[1] + delta_y)
|
||||
else:
|
||||
raise RuntimeError("No point found in model.")
|
||||
|
||||
def to_bottom(self):
|
||||
"""
|
||||
Converts implementation specific model representation to
|
||||
canonical representation.
|
||||
|
||||
Returns:
|
||||
Nothing.
|
||||
"""
|
||||
bottom = Bottom(self.state)
|
||||
# clear residual model
|
||||
for element in bottom.read_outgoing_elements(self.model):
|
||||
|
|
@ -69,6 +112,13 @@ class PointCartesian:
|
|||
bottom.create_edge(c2_link, ltm_point_link, "Morphism")
|
||||
|
||||
def from_bottom(self):
|
||||
"""
|
||||
Converts canonical representation to
|
||||
implementation specific model representation.
|
||||
|
||||
Returns:
|
||||
Nothing.
|
||||
"""
|
||||
bottom = Bottom(self.state)
|
||||
keys = bottom.read_keys(self.model)
|
||||
x_key, = filter(lambda k: k.endswith(".c1"), keys)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue