# Contents of /to_be_filed/webprojs/php_libraries/php_library/fboprime/tod.inc

Revision 35 - (show annotations) (download)
Sat Oct 8 23:35:33 2016 UTC (7 years, 9 months ago) by dashley
File size: 4682 byte(s)
```Initial commit.
```
 1 = \$panel_array[\$i]) && (\$hour <= \$panel_array[\$i+1])) //Must be in the panel. 46 //With integers, test above on right 47 //side of interval is correct. 48 //"a < (b+1)" is equivalent to 49 //"a <= b" when integers are involved. 50 { 51 \$decimal_time = (float)\$hour + ((float)\$minute/60.0); 52 //Convert time to decimal hours. 53 \$span = (float)(\$panel_array[\$i+1] + 1.0 - \$panel_array[\$i]); 54 //Use span to normalize. 1.0 added because panel actually goes to end of hour. 55 \$midpoint = ((float)\$panel_array[\$i] + (float)\$panel_array[\$i+1] + 1.0) / 2.0; 56 //Find the midpoint. 57 \$center_base = (\$decimal_time - \$midpoint) / \$span; 58 //Find the normalized distance from the midpoint. 59 \$center_square = \$center_base * \$center_base; 60 //Square it to get a monotonic function of distance.. Perhaps cheaper than absolute value. 61 62 if (\$center_square < \$least_center_square) //If we have a winner. 63 { 64 \$best = \$i/2; //Record the subscript. 65 \$least_center_square = \$center_square; //Record the best square. 66 } 67 } 68 } 69 70 return(\$best); 71 } 72 // 73 //-------------------------------------------------------------------------------------------------------------- 74 //For a given panel (numbered starting at 0), returns the time midpoint expressed as a T4. 75 // 76 function TOD_panel_center_t4(\$panel) 77 { 78 global \$CONFIG_SCHED_DAY_PANELS; 79 80 \$ll = \$CONFIG_SCHED_DAY_PANELS[\$panel * 2]; 81 \$ul = \$CONFIG_SCHED_DAY_PANELS[\$panel * 2 + 1]; 82 83 \$midpoint_whole = (int)((\$ll + \$ul + 1) / 2); 84 \$midpoint_frac = (\$ll + \$ul + 1) % 2; //0 if whole, 1 if half. 85 86 \$whole_string = sprintf("%02d", \$midpoint_whole); 87 88 if (\$midpoint_frac) 89 \$frac_string = "30"; 90 else 91 \$frac_string = "00"; 92 93 return(\$whole_string . \$frac_string); 94 } 95 // 96 // 97 //-------------------------------------------------------------------------------------------------------------- 98 //End of \$RCSfile: tod.inc,v \$. 99 //-------------------------------------------------------------------------------------------------------------- 100 ?>

 dashley@gmail.com ViewVC Help Powered by ViewVC 1.1.25