![]() ![]() It’s well-structured, documented, and expressive. Let’s take a moment to appreciate this function as it’s written. return calling instance to original location ![]() Shortest = min(iw_distance, iw_distance_up, iw_distance_down) Shortest = min(iw_distance, iw_distance_left, iw_distance_right) ![]() Iw_distance_up_left, iw_distance_up_right, iw_distance_down_left, iw_distance_down_right) Shortest = min(iw_distance, iw_distance_up, iw_distance_down, iw_distance_left, iw_distance_right, Iw_distance_down = distance_to_object(obj) Iw_distance_up = distance_to_object(obj) Iw_distance_right = distance_to_object(obj) Iw_distance_left = distance_to_object(obj) Iw_distance_up_right = distance_to_object(obj) Iw_distance_down_right = distance_to_object(obj) Iw_distance_down_left = distance_to_object(obj) Iw_distance_up_left = distance_to_object(obj) If do_wrap_h & do_wrap_v //wrap vertical and horizontal keep track of original location of target object Var x1, y1, x2, y2, range_width, range_height, do_wrap_h, do_wrap_v Iw_distance_up_left, iw_distance_up_right, iw_distance_down_left, iw_distance_down_right Var iw_distance, iw_distance_up, iw_distance_down, iw_distance_left, iw_distance_right, get the distance from the nine virtual positions /Compares all relevant points for the iw_object and returns the nearest distance, taking the wrap range into target_obj id of the target object to determine the distance x1 left x boundary of wrap y1 top y boundary of wrap x2 right x boundary of wrap y2 bottom y boundary of wrap do_wrap_h set whether the horizontal wrap is on (true) or off do_wrap_v set whether the vertical wrap is on (true) or off (false) /iw_distance_to_object(target_obj, x1, y1, x2, y2, do_wrap_h, Returns the distance_to_object from an improve_wrap object calling this function to another instance. The first implementation works, in that it correctly does what it’s supposed to do, but I never released it, because I wasn’t satisfied that it was good enough code to ship. It’s a function that returns the shortest distance (taking into account the wrap capabilities of the calling object) between the calling instance and a target object. This example comes from my iMprOVE_WRAP asset. Today I wanted to share two versions of a function that I wrote, in order to show how my iterative approach to software development works when I am doing code optimization to improve performance.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |