Skip to content

Commit

Permalink
Added a parser class to read a curve from a file. Added a unit test t…
Browse files Browse the repository at this point in the history
…o make sure the parser was working as intended.
  • Loading branch information
pdz10001 committed Oct 4, 2017
1 parent 3b4a62a commit d06a883
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion curves/Hulls_Trefoil_2017_09_03.curve
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions data_objects/point.py
Original file line number Diff line number Diff line change
@@ -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

16 changes: 16 additions & 0 deletions data_objects/stick_knot.py
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions unit_tests/parser_test.py
Original file line number Diff line number Diff line change
@@ -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()
28 changes: 28 additions & 0 deletions user_interface/parser.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit d06a883

Please sign in to comment.