= \$panel_array[\$i]) && (\$hour <= \$panel_array[\$i+1])) //Must be in the panel. //With integers, test above on right //side of interval is correct. //"a < (b+1)" is equivalent to //"a <= b" when integers are involved. { \$decimal_time = (float)\$hour + ((float)\$minute/60.0); //Convert time to decimal hours. \$span = (float)(\$panel_array[\$i+1] + 1.0 - \$panel_array[\$i]); //Use span to normalize. 1.0 added because panel actually goes to end of hour. \$midpoint = ((float)\$panel_array[\$i] + (float)\$panel_array[\$i+1] + 1.0) / 2.0; //Find the midpoint. \$center_base = (\$decimal_time - \$midpoint) / \$span; //Find the normalized distance from the midpoint. \$center_square = \$center_base * \$center_base; //Square it to get a monotonic function of distance.. Perhaps cheaper than absolute value. if (\$center_square < \$least_center_square) //If we have a winner. { \$best = \$i/2; //Record the subscript. \$least_center_square = \$center_square; //Record the best square. } } } return(\$best); } // //-------------------------------------------------------------------------------------------------------------- //For a given panel (numbered starting at 0), returns the time midpoint expressed as a T4. // function TOD_panel_center_t4(\$panel) { global \$CONFIG_SCHED_DAY_PANELS; \$ll = \$CONFIG_SCHED_DAY_PANELS[\$panel * 2]; \$ul = \$CONFIG_SCHED_DAY_PANELS[\$panel * 2 + 1]; \$midpoint_whole = (int)((\$ll + \$ul + 1) / 2); \$midpoint_frac = (\$ll + \$ul + 1) % 2; //0 if whole, 1 if half. \$whole_string = sprintf("%02d", \$midpoint_whole); if (\$midpoint_frac) \$frac_string = "30"; else \$frac_string = "00"; return(\$whole_string . \$frac_string); } // // //-------------------------------------------------------------------------------------------------------------- //End of \$RCSfile: tod.inc,v \$. //-------------------------------------------------------------------------------------------------------------- ?>