(x0, y0, x1, y1)
| 11148 | // TODO Eliminate duplicate buffering in clipBuffer and polygon.push? |
| 11149 | |
| 11150 | function clipRectangle(x0, y0, x1, y1) { |
| 11151 | |
| 11152 | function visible(x, y) { |
| 11153 | return x0 <= x && x <= x1 && y0 <= y && y <= y1; |
| 11154 | } |
| 11155 | |
| 11156 | function interpolate(from, to, direction, stream) { |
| 11157 | var a = 0, a1 = 0; |
| 11158 | if (from == null |
| 11159 | || (a = corner(from, direction)) !== (a1 = corner(to, direction)) |
| 11160 | || comparePoint(from, to) < 0 ^ direction > 0) { |
| 11161 | do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0); |
| 11162 | while ((a = (a + direction + 4) % 4) !== a1); |
| 11163 | } else { |
| 11164 | stream.point(to[0], to[1]); |
| 11165 | } |
| 11166 | } |
| 11167 | |
| 11168 | function corner(p, direction) { |
| 11169 | return abs$1(p[0] - x0) < epsilon$1 ? direction > 0 ? 0 : 3 |
| 11170 | : abs$1(p[0] - x1) < epsilon$1 ? direction > 0 ? 2 : 1 |
| 11171 | : abs$1(p[1] - y0) < epsilon$1 ? direction > 0 ? 1 : 0 |
| 11172 | : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon |
| 11173 | } |
| 11174 | |
| 11175 | function compareIntersection(a, b) { |
| 11176 | return comparePoint(a.x, b.x); |
| 11177 | } |
| 11178 | |
| 11179 | function comparePoint(a, b) { |
| 11180 | var ca = corner(a, 1), |
| 11181 | cb = corner(b, 1); |
| 11182 | return ca !== cb ? ca - cb |
| 11183 | : ca === 0 ? b[1] - a[1] |
| 11184 | : ca === 1 ? a[0] - b[0] |
| 11185 | : ca === 2 ? a[1] - b[1] |
| 11186 | : b[0] - a[0]; |
| 11187 | } |
| 11188 | |
| 11189 | return function(stream) { |
| 11190 | var activeStream = stream, |
| 11191 | bufferStream = clipBuffer(), |
| 11192 | segments, |
| 11193 | polygon, |
| 11194 | ring, |
| 11195 | x__, y__, v__, // first point |
| 11196 | x_, y_, v_, // previous point |
| 11197 | first, |
| 11198 | clean; |
| 11199 | |
| 11200 | var clipStream = { |
| 11201 | point: point, |
| 11202 | lineStart: lineStart, |
| 11203 | lineEnd: lineEnd, |
| 11204 | polygonStart: polygonStart, |
| 11205 | polygonEnd: polygonEnd |
| 11206 | }; |
| 11207 |
no test coverage detected