-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a parser class to read a curve from a file. Added a unit test t…
…o make sure the parser was working as intended.
- Loading branch information
Showing
7 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |