#include <j2k/Fred/Basic.hpp>#include <math.h>Go to the source code of this file.
Functions | |
| int | Scale (double XMin, double XMax, int N, double *SMin, double *Step) |
|
||||||||||||||||||||||||
|
Definition at line 9 of file Scale.hpp. 00010 {
00011 int negScale; // Negative scale flag
00012 int nbScaleSub; // Number of scale subintervals
00013 double initStep; // Initial step
00014 double scaleStep; // Scaled step
00015 double temp; // Temporary value
00016 double scaleFactor; // Scaling back factor
00017 double scaleMax; // Scale maximum value
00018 int t; // teration counter
00019 int i; // Neat step counter
00020
00021 // Neat steps
00022 int Steps[] = {
00023 10, 12, 15, 16, 20, 25, 30, 40, 50, 60, 75, 80, 100, 120, 150};
00024
00025 int NS = sizeof(Steps) / sizeof(Steps[0]);
00026
00027 // Some checks
00028 if ( XMin > XMax ) {
00029 temp = XMin;
00030 XMin = XMax;
00031 XMax = temp;
00032 }
00033
00034 if ( XMin == XMax ) {
00035 if ( XMin == 0.0 ) {
00036 XMax = 1.0;
00037 } else {
00038 XMax = XMin + fabs(XMin) / 10.0;
00039 }
00040 }
00041
00042 // Reduce to postive scale case if possible
00043 if ( XMax <= 0 ) {
00044 negScale = 1;
00045 temp = XMin;
00046 XMin = -XMax;
00047 XMax = -temp;
00048 } else {
00049 negScale = 0;
00050 }
00051
00052 if ( N < 2 ) {
00053 N = 2;
00054 }
00055
00056 nbScaleSub = N - 1;
00057
00058 for (t = 0; t < 3; t++) {
00059 // Compute intial and scaled steps
00060 intStep = (XMax - XMin) / nbScaleSub;
00061 scaleStep = intStep;
00062
00063 for (; scaleStep < 10.0; scaleStep *= 10.0);
00064 for (; scaleStep > 100.0; scaleStep /= 10.0);
00065
00066 // Find a sutable neat step
00067 for (i = 0; i < NS && scaleStep > Steps [i]; i++);
00068 scaleFactor = intStep / scaleStep;
00069
00070 // Compute step and scale minimum value
00071 do {
00072 *Step = scaleFactor * Steps [i];
00073 *SMin = floor (XMin / *Step) * *Step;
00074 scaleMax = *SMin + nbScaleSub * *Step;
00075
00076 if (XMax <= scaleMax) { // Function max is in the range: work done
00077 if (negScale) *SMin = -scaleMax;
00078 *Step *= nbScaleSub / (N - 1);
00079 return 1;
00080 }
00081
00082 i++;
00083
00084 } while (i < NS);
00085
00086 // Double number of intervals
00087 nbScaleSub *= 2;
00088 }
00089
00090 // Could not solve the problem
00091 return 0;
00092 }
|
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001