diff --git a/cli_application.py b/cli_application.py old mode 100755 new mode 100644 index 237f1d4..4d16962 --- a/cli_application.py +++ b/cli_application.py @@ -15,7 +15,7 @@ class CliApplication(cmd.Cmd): def __init__(self, application_path=None, application_name="generator", args=None): self.logger = get_logger(__name__) - self.curve_paths = os.path.join(application_path, "curves") + self.curve_paths = os.path.join(application_path, "test_curves") self.arguments = args self.parse_cmd_args(self.arguments) sys.exit(1) diff --git a/data_objects/point.py b/data_objects/point.py index 214292b..37fb142 100644 --- a/data_objects/point.py +++ b/data_objects/point.py @@ -5,11 +5,17 @@ def distance_between_points(start_point, end_point): + """ + Calculate the distance oif the line segment between the start and end Points + :param start_point: Point + :param end_point: Point + :return: double: The distance between the two provided Points + """ x = end_point.get_x() - start_point.get_x() y = end_point.get_y() - start_point.get_y() z = end_point.get_z() - start_point.get_z() - return float((x * x + y * y + z * z) ** (1 / 2)) + return (x * x + y * y + z * z) ** 0.5 class Point: @@ -20,17 +26,17 @@ def __init__(self, x_val, y_val, z_val): self.z_val = z_val def __eq__(self, other): - """Override the default Equals behavior""" + """Override the default Equals behavior to compare the X, Y, and Z values""" 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 def get_x(self): - return self.x_val + return float(self.x_val) def get_y(self): - return self.y_val + return float(self.y_val) def get_z(self): - return self.z_val + return float(self.z_val) diff --git a/subdivision_generator_orig.py b/subdivision_generator_orig.py index 1038849..f3f9e05 100644 --- a/subdivision_generator_orig.py +++ b/subdivision_generator_orig.py @@ -87,7 +87,7 @@ def distanceBetweenTwoPoints(startPoint, endPoint): z = endPoint[2] - startPoint[2] # return math.sqrt( x*x + y*y + z*z) - return (x * x + y * y + z * z) ** (1 / 2) + return (x * x + y * y + z * z) ** (0.5) ''' A function used to reduce a line segment between the startPoint and the endPoint diff --git a/curves/Hulls_Trefoil_2017_09_03.curve b/test_curves/Hulls_Trefoil_2017_09_03.curve similarity index 100% rename from curves/Hulls_Trefoil_2017_09_03.curve rename to test_curves/Hulls_Trefoil_2017_09_03.curve diff --git a/curves/Hulls_Trefoil_2017_09_03.txt b/test_curves/Hulls_Trefoil_2017_09_03.txt similarity index 100% rename from curves/Hulls_Trefoil_2017_09_03.txt rename to test_curves/Hulls_Trefoil_2017_09_03.txt diff --git a/curves/Hulls_Unknot_2017_09_03.curve b/test_curves/Hulls_Unknot_2017_09_03.curve similarity index 100% rename from curves/Hulls_Unknot_2017_09_03.curve rename to test_curves/Hulls_Unknot_2017_09_03.curve diff --git a/curves/Hulls_Unknot_2017_09_03.txt b/test_curves/Hulls_Unknot_2017_09_03.txt similarity index 100% rename from curves/Hulls_Unknot_2017_09_03.txt rename to test_curves/Hulls_Unknot_2017_09_03.txt diff --git a/curves/TJP-4_1_stick-unknot-halved-1.curve b/test_curves/TJP-4_1_stick-unknot-halved-1.curve similarity index 100% rename from curves/TJP-4_1_stick-unknot-halved-1.curve rename to test_curves/TJP-4_1_stick-unknot-halved-1.curve diff --git a/curves/TJP-4_1_stick-unknot-halved-2.curve b/test_curves/TJP-4_1_stick-unknot-halved-2.curve similarity index 100% rename from curves/TJP-4_1_stick-unknot-halved-2.curve rename to test_curves/TJP-4_1_stick-unknot-halved-2.curve diff --git a/curves/TJP-4_1_stick-unknot-halved-3.curve b/test_curves/TJP-4_1_stick-unknot-halved-3.curve similarity index 100% rename from curves/TJP-4_1_stick-unknot-halved-3.curve rename to test_curves/TJP-4_1_stick-unknot-halved-3.curve diff --git a/curves/TJP-4_1_stick-unknot.curve b/test_curves/TJP-4_1_stick-unknot.curve similarity index 100% rename from curves/TJP-4_1_stick-unknot.curve rename to test_curves/TJP-4_1_stick-unknot.curve diff --git a/curves/TJP-4_1_stick-unknot_TEST.curve b/test_curves/TJP-4_1_stick-unknot_TEST.curve similarity index 100% rename from curves/TJP-4_1_stick-unknot_TEST.curve rename to test_curves/TJP-4_1_stick-unknot_TEST.curve diff --git a/curves/TJP-4th-C1-high-precision.curve b/test_curves/TJP-4th-C1-high-precision.curve similarity index 100% rename from curves/TJP-4th-C1-high-precision.curve rename to test_curves/TJP-4th-C1-high-precision.curve diff --git a/curves/test.curve b/test_curves/test.curve similarity index 100% rename from curves/test.curve rename to test_curves/test.curve diff --git a/unit_tests/parser_test.py b/unit_tests/parser_test.py index 774df6e..0c02974 100644 --- a/unit_tests/parser_test.py +++ b/unit_tests/parser_test.py @@ -10,7 +10,7 @@ class ParserUnitTest(unittest.TestCase): def test_parser(self): - test_knot = parse_curve_file("../curves/Hulls_Trefoil_2017_09_03.curve") + test_knot = parse_curve_file("../test_curves/Hulls_Trefoil_2017_09_03.curve") points = test_knot.get_points() self.assertTrue(points[0] == Point(0, 4831838208, 10737418240)) @@ -21,6 +21,124 @@ def test_parser(self): self.assertTrue(points[5] == Point(21474836480, -32212254720, -32212254720)) self.assertTrue(points[6] == Point(0, 4831838208, 10737418240)) + def test_parser_with_high_precision_curve(self): + test_knot = parse_curve_file("../test_curves/TJP-4th-C1-high-precision.curve") + points = test_knot.get_points() + + self.assertTrue(points[0] == Point(1.28318923, -2.84316645, -2.25593748)) + self.assertTrue(points[1] == Point(1.139367593750000, -2.831090593750000, -2.293403687500000)) + self.assertTrue(points[2] == Point(0.971135187500000, -2.330181187500000, -2.079607375000000)) + self.assertTrue(points[3] == Point(0.802902781250000, -1.829271781250000, -1.865811062500000)) + self.assertTrue(points[4] == Point(0.634670375000000, -1.328362375000000, -1.652014750000000)) + self.assertTrue(points[5] == Point(0.466437968750000, -0.827452968750000, -1.438218437500000)) + self.assertTrue(points[6] == Point(0.298205562500000, -0.326543562500000, -1.224422125000000)) + self.assertTrue(points[7] == Point(0.129973156250000, 0.174365843750000, -1.010625812500000)) + self.assertTrue(points[8] == Point(-0.038259250000000, 0.675275250000000, -0.796829500000000)) + self.assertTrue(points[9] == Point(-0.206491656250000, 1.176184656250000, -0.583033187500000)) + self.assertTrue(points[10] == Point(-0.374724062500000, 1.677094062500000, -0.369236875000000)) + self.assertTrue(points[11] == Point(-0.542956468750000, 2.178003468750000, -0.155440562500000)) + self.assertTrue(points[12] == Point(-0.711188875000000, 2.678912875000000, 0.058355750000000)) + self.assertTrue(points[13] == Point(-0.879421281250000, 3.179822281250000, 0.272152062500000)) + self.assertTrue(points[14] == Point(-1.047653687500000, 3.680731687500000, 0.485948375000000)) + self.assertTrue(points[15] == Point(-1.215886093750000, 4.181641093750000, 0.699744687500000)) + self.assertTrue(points[16] == Point(-1.384118500000000, 4.682550500000000, 0.913541000000000)) + self.assertTrue(points[17] == Point(-1.50375, 4.13635, 1.02434)) + self.assertTrue(points[18] == Point(-1.62339, 3.59015, 1.13513)) + self.assertTrue(points[19] == Point(-1.74303, 3.04394, 1.24592)) + self.assertTrue(points[20] == Point(-1.86266, 2.49774, 1.35671)) + self.assertTrue(points[21] == Point(-1.9823, 1.95154, 1.4675)) + self.assertTrue(points[22] == Point(-2.10194, 1.40534, 1.57829)) + self.assertTrue(points[23] == Point(-2.22157, 0.859137, 1.68908)) + self.assertTrue(points[24] == Point(-2.34121, 0.312934, 1.79987)) + self.assertTrue(points[25] == Point(-2.46084, -0.233267, 1.91066)) + self.assertTrue(points[26] == Point(-2.58048, -0.779468, 2.02145)) + self.assertTrue(points[27] == Point(-2.70012, -1.32567, 2.13224)) + self.assertTrue(points[28] == Point(-2.81976, -1.87187, 2.24303)) + self.assertTrue(points[29] == Point(-2.9394, -2.41807, 2.35382)) + self.assertTrue(points[30] == Point(-3.05903, -2.96428, 2.46461)) + self.assertTrue(points[31] == Point(-3.17867, -3.51048, 2.5754)) + self.assertTrue(points[32] == Point(-3.2983075,-4.0566825,2.686189)) + self.assertTrue(points[33] == Point(-3.09987, -3.63013, 2.36433)) + self.assertTrue(points[34] == Point(-2.90143, -3.20357, 2.04247)) + self.assertTrue(points[35] == Point(-2.70299, -2.77701, 1.72061)) + self.assertTrue(points[36] == Point(-2.50455, -2.35045, 1.39875)) + self.assertTrue(points[37] == Point(-2.30611, -1.92389, 1.07689)) + self.assertTrue(points[38] == Point(-2.10767, -1.49733, 0.755026)) + self.assertTrue(points[39] == Point(-1.90924, -1.07077, 0.433165)) + self.assertTrue(points[40] == Point(-1.7108, -0.644214, 0.111303)) + self.assertTrue(points[41] == Point(-1.51236, -0.217655, -0.210558)) + self.assertTrue(points[42] == Point(-1.31393, 0.208903, -0.532419)) + self.assertTrue(points[43] == Point(-1.11549, 0.635462, -0.854279)) + self.assertTrue(points[44] == Point(-0.91705, 1.06202, -1.17614)) + self.assertTrue(points[45] == Point(-0.718613, 1.48858, -1.498)) + self.assertTrue(points[46] == Point(-0.520175, 1.91514, -1.81986)) + self.assertTrue(points[47] == Point(-0.321737, 2.3417, -2.14172)) + self.assertTrue(points[48] == Point(-0.1232995,2.768254,-2.463584)) + self.assertTrue(points[49] == Point(0.128657, 2.3119, -2.23296)) + self.assertTrue(points[50] == Point(0.380613, 1.85555, -2.00234)) + self.assertTrue(points[51] == Point(0.632569, 1.3992, -1.77172)) + self.assertTrue(points[52] == Point(0.884525, 0.942852, -1.5411)) + self.assertTrue(points[53] == Point(1.13648, 0.486501, -1.31047)) + self.assertTrue(points[54] == Point(1.38844, 0.0301505, -1.07985)) + self.assertTrue(points[55] == Point(1.64039, -0.4262, -0.849228)) + self.assertTrue(points[56] == Point(1.89235, -0.882551, -0.618607)) + self.assertTrue(points[57] == Point(2.14431, -1.3389, -0.387985)) + self.assertTrue(points[58] == Point(2.39626, -1.79525, -0.157363)) + self.assertTrue(points[59] == Point(2.64821, -2.2516, 0.0732595)) + self.assertTrue(points[60] == Point(2.90017, -2.70795, 0.303882)) + self.assertTrue(points[61] == Point(3.15212, -3.1643, 0.534504)) + self.assertTrue(points[62] == Point(3.40408, -3.62065, 0.765126)) + self.assertTrue(points[63] == Point(3.65604, -4.077, 0.995748)) + self.assertTrue(points[64] == Point(3.9079915,-4.533357,1.2263705)) + self.assertTrue(points[65] == Point(3.41775, -4.27741, 1.08826)) + self.assertTrue(points[66] == Point(2.9275, -4.02147, 0.950154)) + self.assertTrue(points[67] == Point(2.43725, -3.76553, 0.812045)) + self.assertTrue(points[68] == Point(1.947, -3.50958, 0.673937)) + self.assertTrue(points[69] == Point(1.45675, -3.25364, 0.535829)) + self.assertTrue(points[70] == Point(0.966502, -2.9977, 0.39772)) + self.assertTrue(points[71] == Point(0.476253, -2.74175, 0.259611)) + self.assertTrue(points[72] == Point(-0.0139957, -2.48581, 0.121503)) + self.assertTrue(points[73] == Point(-0.504244, -2.22986, -0.0166055)) + self.assertTrue(points[74] == Point(-0.994493, -1.97392, -0.154714)) + self.assertTrue(points[75] == Point(-1.48474, -1.71798, -0.292822)) + self.assertTrue(points[76] == Point(-1.97499, -1.46204, -0.430931)) + self.assertTrue(points[77] == Point(-2.46524, -1.2061, -0.56904)) + self.assertTrue(points[78] == Point(-2.95549, -0.950156, -0.707148)) + self.assertTrue(points[79] == Point(-3.44574, -0.694214, -0.845257)) + self.assertTrue(points[80] == Point(-3.935983,-0.438272,-0.983365)) + self.assertTrue(points[81] == Point(-3.48885, -0.142371, -0.789876)) + self.assertTrue(points[82] == Point(-3.04171, 0.153529, -0.596387)) + self.assertTrue(points[83] == Point(-2.59457, 0.449429, -0.402898)) + self.assertTrue(points[84] == Point(-2.14744, 0.745329, -0.209409)) + self.assertTrue(points[85] == Point(-1.7003, 1.04123, -0.01592)) + self.assertTrue(points[86] == Point(-1.25317, 1.33713, 0.177569)) + self.assertTrue(points[87] == Point(-0.806037, 1.63303, 0.371058)) + self.assertTrue(points[88] == Point(-0.358904, 1.92893, 0.564547)) + self.assertTrue(points[89] == Point(0.0882295, 2.22483, 0.758035)) + self.assertTrue(points[90] == Point(0.535363, 2.52073, 0.951523)) + self.assertTrue(points[91] == Point(0.982496, 2.81663, 1.14501)) + self.assertTrue(points[92] == Point(1.42963, 3.11253, 1.3385)) + self.assertTrue(points[93] == Point(1.87677, 3.40843, 1.53199)) + self.assertTrue(points[94] == Point(2.3239, 3.70433, 1.72548)) + self.assertTrue(points[95] == Point(2.77104, 4.00023, 1.91897)) + self.assertTrue(points[96] == Point(3.218174000000000, 4.296123000000000, 2.112459500000000)) + self.assertTrue(points[97] == Point(3.098763125000000, 3.819365312500000, 1.823730781250000)) + self.assertTrue(points[98] == Point(2.979352250000000, 3.342607625000000, 1.535002062500000)) + self.assertTrue(points[99] == Point(2.859941375000000, 2.865849937500000, 1.246273343750000)) + self.assertTrue(points[100] == Point(2.740530500000000, 2.389092250000000, 0.957544625000000)) + self.assertTrue(points[101] == Point(2.621119625000000, 1.912334562500000, 0.668815906250000)) + self.assertTrue(points[102] == Point(2.501708750000000, 1.435576875000000, 0.380087187500000)) + self.assertTrue(points[103] == Point(2.382297875000000, 0.958819187500000, 0.091358468750000)) + self.assertTrue(points[104] == Point(2.262887000000000, 0.482061500000000, -0.197370250000000)) + self.assertTrue(points[105] == Point(2.143476125000000, 0.005303812500000, -0.486098968750000)) + self.assertTrue(points[106] == Point(2.024065250000000, -0.471453875000000, -0.774827687500000)) + self.assertTrue(points[107] == Point(1.904654375000000, -0.948211562500000, -1.063556406250000)) + self.assertTrue(points[108] == Point(1.785243500000000, -1.424969250000000, -1.352285125000000)) + self.assertTrue(points[109] == Point(1.665832625000000, -1.901726937500000, -1.641013843750000)) + self.assertTrue(points[110] == Point(1.546421750000000, -2.378484625000000, -1.929742562500000)) + self.assertTrue(points[111] == Point(1.427010875000000, -2.855242312500000, -2.218471281250000)) + self.assertTrue(points[112] == Point(1.28318923, -2.84316645, -2.25593748)) + if __name__ == '__main__': unittest.main() diff --git a/unit_tests/point_test.py b/unit_tests/point_test.py index 7745e0c..6cbe78c 100644 --- a/unit_tests/point_test.py +++ b/unit_tests/point_test.py @@ -4,9 +4,11 @@ """ import unittest from data_objects.point import Point, distance_between_points +from unit_test_helper import is_within_epsilon class PointTest(unittest.TestCase): + epsilon = .0001 origin_test_point = Point(0, 0, 0) test_point = Point(12, 8, 4) @@ -18,7 +20,13 @@ def test_getters(self): def test_distance_between_points(self): """Test the distance from the origin to 12, 8 , 4 -> it should be about 14.96662954""" distance = distance_between_points(self.origin_test_point, self.test_point) - self.assertTrue( distance == 14.96662954) + self.assertTrue(is_within_epsilon(distance, 14.96662954, self.epsilon), "The actual distance is: {0:0.10f}".format(distance)) + + distance = distance_between_points(self.origin_test_point, self.origin_test_point) + self.assertTrue(is_within_epsilon(distance, 0.0, self.epsilon), "The actual distance is: {0:0.10f}".format(distance)) + + distance = distance_between_points(self.test_point, self.test_point) + self.assertTrue(is_within_epsilon(distance, 0.0, self.epsilon), "The actual distance is: {0:0.10f}".format(distance)) if __name__ == "__main__": diff --git a/unit_tests/unit_test_helper.py b/unit_tests/unit_test_helper.py new file mode 100644 index 0000000..d6db742 --- /dev/null +++ b/unit_tests/unit_test_helper.py @@ -0,0 +1,9 @@ +""" +A file containing static helper functions for Unit Tests +@author Peter Zaffetti +10/16/2017 +""" + + +def is_within_epsilon(expected_value, actual_value, epsilon): + return expected_value + epsilon >= actual_value >= expected_value - epsilon