Skip to content
Permalink
8377d07783
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
69 lines (54 sloc) 3.47 KB
from monotonically_formatted_curve import MonotonicallyFormattedCurve
from logger import get_logger
# TODO: Refactor the hardcoded coordinate location: 0 should be a variable x, 1 should be y, and 2 should be z
def calculate_monotonicity(monotonically_formatted_curve):
curve_name = monotonically_formatted_curve.get_name()
stick_knot_points = monotonically_formatted_curve.get_stick_knot().get_points()
# PDZ- This will hold the monotonic status for all the coordinates. 0 means no monotonicity, 1 mean monotonically increasing, and -1 mean monotonically decreasing
coordinate_monotonic_status = [0, 0, 0]
for i in range(1, len(stick_knot_points) - 1):
if i == 1:
coordinate_monotonic_status[0] = calculate_coordinate_monotonicity(0, stick_knot_points[i - 1], stick_knot_points[i])
coordinate_monotonic_status[1] = calculate_coordinate_monotonicity(1, stick_knot_points[i - 1],
stick_knot_points[i])
coordinate_monotonic_status[2] = calculate_coordinate_monotonicity(2, stick_knot_points[i - 1],
stick_knot_points[i])
else:
# PDZ- Check each monotonicity status: if it differs then just set the coordinate to 0. Otherwise, leave it alone. At the end, any that are 0 aren't monotonic
if calculate_coordinate_monotonicity(0, stick_knot_points[i - 1], stick_knot_points[i]) != coordinate_monotonic_status[0]:
coordinate_monotonic_status[0] = 0 # PDZ- X coordinate was checked
if calculate_coordinate_monotonicity(1, stick_knot_points[i - 1], stick_knot_points[i]) != coordinate_monotonic_status[1]:
coordinate_monotonic_status[1] = 0 # PDZ- Y coordinate was checked
if calculate_coordinate_monotonicity(2, stick_knot_points[i - 1], stick_knot_points[i]) != coordinate_monotonic_status[2]:
coordinate_monotonic_status[2] = 0 # PDZ- Z coordinate was checked
logger = get_logger(calculate_monotonicity.__name__)
logger.info("%s, x: %s" % (curve_name, convert_int_to_monotonicity_str(coordinate_monotonic_status[0])))
logger.info("%s, y: %s" % (curve_name, convert_int_to_monotonicity_str(coordinate_monotonic_status[1])))
logger.info("%s, z: %s" % (curve_name, convert_int_to_monotonicity_str(coordinate_monotonic_status[2])))
logger.info("End of curve\n")
def convert_int_to_monotonicity_str(value):
if value == 0:
return "no"
if value == 1:
return "Strictly Mono Increasing"
if value == -1:
return "Strictly Mono Decreasing"
return "Something wasn't quite right"
def calculate_coordinate_monotonicity(index, stick_knot_point_behind, stick_knot_point_current):
prev_coord_val = 0
current_coord_val = 0
if index == 0:
prev_coord_val = stick_knot_point_behind.get_x()
current_coord_val = stick_knot_point_current.get_x()
elif index == 1:
prev_coord_val = stick_knot_point_behind.get_y()
current_coord_val = stick_knot_point_current.get_y()
elif index == 2:
prev_coord_val = stick_knot_point_behind.get_z()
current_coord_val = stick_knot_point_current.get_z()
if prev_coord_val < current_coord_val: # PDZ- Increasing since the point is bigger
return 1
elif prev_coord_val > current_coord_val: # PDZ- Decreasing
return -1
else: # PDZ- Same point
return 0