mirror of
https://github.com/netbymatt/nexrad-level-2-plot.git
synced 2026-11-28 18:28:05 -08:00
don't plot outside crop area
This commit is contained in:
1 parent
3fa526c96a
commit
7652e9fb81
3 files changed
+30
-18
No files matched your search
+12
-2
@@ -38,6 +38,10 @@ const DEFAULT_OPTIONS = {
|
||||
lineWidth: 2,
|
||||
};
|
||||
|
||||
// calculation constants
|
||||
const RAD45 = (45 * Math.PI / 180);
|
||||
const RAD90 = RAD45 * 2;
|
||||
|
||||
const draw = (data, _options) => {
|
||||
// combine options with defaults
|
||||
const options = {
|
||||
@@ -113,9 +117,15 @@ const draw = (data, _options) => {
|
||||
let lastRemainder = 0;
|
||||
|
||||
// calculate maximum bin to plot based on azimuth
|
||||
const azWrap = startAngle % (Math.PI / 2);
|
||||
const cropMaxBin = Math.ceil(Math.abs(cropTo / Math.cos(azWrap)) - 50);
|
||||
// wrap azimuth to 90° offset by -45° (% in js is remainder, the formula below make it in to modulus)
|
||||
const azWrap = (((startAngle - RAD45) % RAD90) + RAD90) % RAD90;
|
||||
// calculate a magnitude multiplier as 1/sin with 45° shift removed
|
||||
const azMagnitudeMult = 1 / Math.abs(Math.sin(azWrap + RAD45));
|
||||
const cropMaxBin = Math.ceil(Math.abs(options.cropTo / 2 * scale * azMagnitudeMult));
|
||||
|
||||
// compare max calculated value with length of radial
|
||||
const maxBin = Math.min(cropMaxBin, thisRadial.moment_data.length);
|
||||
|
||||
// plot each bin
|
||||
for (let idx = 0; idx < maxBin; idx += 1) {
|
||||
// get the value
|
||||
|
||||
Reference in new issue
Block a user