diff --git a/curves/Hulls_Trefoil_2017_09_03.curve b/curves/Hulls_Trefoil_2017_09_03.curve index 31ea6a2..19d0e01 100644 --- a/curves/Hulls_Trefoil_2017_09_03.curve +++ b/curves/Hulls_Trefoil_2017_09_03.curve @@ -1,6 +1,6 @@ % Original Trefoil Control Points 0, 4831838208, 10737418240 --8053063680, -51002736640, -26843545600 +-8053063680, -51002736640, -26843545600 % Test inline comment 21474836480, 42949672960, -10737418240 5368709120, -32212254720, 31138512896 -32212254720, 16106127360, 10737418240 diff --git a/generator/__init__.py b/data_objects/__init__.py similarity index 100% rename from generator/__init__.py rename to data_objects/__init__.py diff --git a/generator/generator.py b/data_objects/generator.py similarity index 100% rename from generator/generator.py rename to data_objects/generator.py diff --git a/data_objects/point.py b/data_objects/point.py new file mode 100644 index 0000000..cb1f020 --- /dev/null +++ b/data_objects/point.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +""" +@author Peter Zaffetti 2017 +""" + + +class Point: + + def __init__(self, x_val, y_val, z_val): + self.x_val = x_val + self.y_val = y_val + self.z_val = z_val + + def __eq__(self, other): + """Override the default Equals behavior""" + if isinstance(other, self.__class__): + return self.x_val == other.x_val and self.y_val == other.y_val and self.z_val == other.z_val + return False + diff --git a/data_objects/stick_knot.py b/data_objects/stick_knot.py new file mode 100644 index 0000000..e735457 --- /dev/null +++ b/data_objects/stick_knot.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +""" +@author Peter Zaffetti 2017 +""" +from point import Point + + + +class StickKnot: + + def __init__(self, knot_points_arr=None): + self.knot_points = knot_points_arr + pass + + def get_points(self): + return self.knot_points \ No newline at end of file diff --git a/unit_tests/parser_test.py b/unit_tests/parser_test.py new file mode 100644 index 0000000..7ae371d --- /dev/null +++ b/unit_tests/parser_test.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +""" +@author Peter Zaffetti 2017 +""" +import unittest +from user_interface.parser import parse_curve_file +from data_objects.point import Point + + +class ParserUnitTest(unittest.TestCase): + + def test_parser(self): + test_knot = parse_curve_file("../curves/Hulls_Trefoil_2017_09_03.curve") + points = test_knot.get_points() + + self.assertTrue(points[0] == Point(0, 4831838208, 10737418240)) + self.assertTrue(points[1] == Point(-8053063680, -51002736640, -26843545600)) + self.assertTrue(points[2] == Point(21474836480, 42949672960, -10737418240)) + self.assertTrue(points[3] == Point(5368709120, -32212254720, 31138512896)) + self.assertTrue(points[4] == Point(-32212254720, 16106127360, 10737418240)) + self.assertTrue(points[5] == Point(21474836480, -32212254720, -32212254720)) + self.assertTrue(points[6] == Point(0, 4831838208, 10737418240)) + + +if __name__ == '__main__': + unittest.main() diff --git a/user_interface/parser.py b/user_interface/parser.py new file mode 100644 index 0000000..dd573d0 --- /dev/null +++ b/user_interface/parser.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +""" +@author Peter Zaffetti 2017 +""" +from data_objects.point import Point +from data_objects.stick_knot import StickKnot + + +def parse_curve_file(filename="test.curve"): + curve_file = open(filename, "r") + stick_knot_points = list() + + for line in curve_file: + if line.startswith("%"): + continue + comment_split_line = line.split("%") + point_values = comment_split_line[0] + comma_split_point_values = point_values.split(",") + + if len(comma_split_point_values) != 3: + raise Exception("The curve file is not formatted properly") + else: + x_val = float(comma_split_point_values[0]) + y_val = float(comma_split_point_values[1]) + z_val = float(comma_split_point_values[2]) + stick_knot_points.append(Point(x_val, y_val, z_val)) + + return StickKnot(stick_knot_points) \ No newline at end of file