@@ -99,44 +99,38 @@ void calcMap(void) {
9999
100100 // If slit pupil is enabled, override iris area of polarDist map.
101101 if (slitPupilRadius > 0 ) {
102- // This is a bit ugly in that it makes repeated passes over the polarDist
103- // array, drawing (and redrawing) the intersection of two overlapping
104- // circles...I wasn't able to come up with an approach that gives a
105- // single correct answer at each pixel (surely it's possible, I'm just
106- // lousy at this kind of math). Also, lots of floating-point math.
107- // This is only needed once at startup, so it's not a complete disaster.
108- int i;
109- for (i=0 ; i<127 ; i++) {
110- float ratio = i / 128.0 ; // 0.0 (open) to just-under-1.0 (slit) (>= 1.0 will cause trouble)
111- // Interpolate a point between top of iris and top of slit pupil, based on ratio
112- float y1 = iRad - (iRad - slitPupilRadius) * ratio;
113- // (x1 is 0 and thus dropped from equation below)
114- // And another point between right of iris and center of eye, inverse ratio
115- float x2 = iRad * (1.0 - ratio);
116- // (y2 is also zero, same deal)
117- // Find X coordinate of center of circle that crosses above two points
118- // and has Y at 0.0
119- float xc = (x2 * x2 - y1 * y1) / (2 * x2);
120- // Distance from center of circle to right edge
121- dx = x2 - xc;
122- float r2 = dx * dx; // center-to-right distance squared
123- // Iterate over each pixel in the iris section of the polar map...
124- for (y=0 ; y < mapRadius; y++) {
125- dy = y + 0.5 ; // Distance to center, Y component
126- dy2 = dy * dy;
127- for (x=0 ; x < mapRadius; x++) {
128- dx = x + 0.5 ; // Distance to center point, X component
129- d2 = dx * dx + dy2; // Distance to center, squared
130- if (d2 <= irisRadius2) { // If inside iris...
131- xp = x + 0.5 ;
132- dx = xp - xc; // X component of...
133- d2 = dx * dx + dy2; // Distance from pixel to left 'xc' point
134- if (d2 <= r2) { // If point is within the first circle...
135- dx = xp + xc; // X component of...
136- d2 = dx * dx + dy2; // Distance from pixel to right 'xc' point
137- if (d2 <= r2) { // If point is also within the second circle...
138- polarDist[y * mapRadius + x] = (int8_t )(-1 - i); // Set to distance 'i'
139- }
102+ // Iterate over each pixel in the iris section of the polar map...
103+ for (y=0 ; y < mapRadius; y++) {
104+ dy = y + 0.5 ; // Distance to center, Y component
105+ dy2 = dy * dy;
106+ for (x=0 ; x < mapRadius; x++) {
107+ dx = x + 0.5 ; // Distance to center point, X component
108+ d2 = dx * dx + dy2; // Distance to center, squared
109+ if (d2 <= irisRadius2) { // If inside iris...
110+ xp = x + 0.5 ;
111+ // This is a bit ugly in that it iteratively calculates the
112+ // polarDist value...trial and error. It should be possible to
113+ // algebraically simplify this and find the single polarDist
114+ // point for a given pixel, but I've not worked that out yet.
115+ // This is only needed once at startup, not a complete disaster.
116+ for (int i=126 ; i>=0 ; i--) {
117+ float ratio = i / 128.0 ; // 0.0 (open) to just-under-1.0 (slit) (>= 1.0 will cause trouble)
118+ // Interpolate a point between top of iris and top of slit pupil, based on ratio
119+ float y1 = iRad - (iRad - slitPupilRadius) * ratio;
120+ // (x1 is 0 and thus dropped from equation below)
121+ // And another point between right of iris and center of eye, inverse ratio
122+ float x2 = iRad * (1.0 - ratio);
123+ // (y2 is also zero, same deal)
124+ // Find X coordinate of center of circle that crosses above two points
125+ // and has Y at 0.0
126+ float xc = (x2 * x2 - y1 * y1) / (2 * x2);
127+ dx = x2 - xc; // Distance from center of circle to right edge
128+ float r2 = dx * dx; // center-to-right distance squared
129+ dx = xp - xc; // X component of...
130+ d2 = dx * dx + dy2; // Distance from pixel to left 'xc' point
131+ if (d2 <= r2) { // If point is within circle...
132+ polarDist[y * mapRadius + x] = (int8_t )(-1 - i); // Set to distance 'i'
133+ break ;
140134 }
141135 }
142136 }
0 commit comments