javascript - Objects being pushed to a list have just 1 property value changed some how after all objects have been pushed -


i've got code runs x in xlength, z in zlength, , if want include y axis, y in ylength.

then object created position x,y,z , pushed array.

now what's happening is, first loop on y values done, position.y value of last pushed object, , subsequent objects, changes it's assigned value final value of position.y of y in ylength loop. object's position.y value linked position.y value of y in ylength loop, how work?

here's code:

in case, props.includey == true

props.position.type == 'center'

i tried var y = yhere trick fixes promise resolution in loops use increment value in resolve function.

but fear bug more nasty...

this.rendercoverage = function(props) {         /* include @param-object faces calculated          * include @param-interger resolution size of squares evaluated          * include @param-array[string] lights array of light id's want calculate coverage          */         props.class = props.class || 'floorcoverage'         this.coverage[props.class] = []         if (!props.yplane) {             props.yplane = 0         }         (var x = 0; x < math.floor(this.width / props.resolution); x++) {             (var z = 0; z < math.floor(this.depth / props.resolution); z++) {                 var position = {}                 position.type = props.position.type || 'normal'                 if (props.position) {                     if (props.position.type == 'center') {                         position.x = ((x * props.resolution) + props.resolution / 2) + ((this.width) - (math.floor(this.width / props.resolution) * props.resolution)) / 2                         if (!props.includey) {                             position.y = props.yplane + (props.resolution / 2)                         }                         position.z = ((z * props.resolution) + (props.resolution / 2)) + ((this.depth) - (math.floor(this.depth / props.resolution) * props.resolution)) / 2                     } else {                         position.x = (x * props.resolution)                         position.z = (z * props.resolution)                         position.y = props.yplane                     }                 }                 if (props.includey) {                     (var yhere = 0; yhere < math.floor(this.height / props.resolution); yhere++) {                         var y = yhere                         if (position.type == 'center') {                             position.y = ((y * props.resolution) + (props.resolution) / 2)                             console.log("this position.y value is: ")                             console.log(position.y)                         } else {                             position.y = (y * props.resolution) + props.yplane                         }                         var coveragesquare = new cube({                             width: props.squaresize || 0.05,                             height: props.squaresize || 0.05,                             depth: props.squaresize || 0.05,                             sides: props.sides || ["bottom", "front", "top", "left", "right", "back"],                             group: 'coverage',                             class: props.class || 'floorcoverage',                             id: (props.class + math.round(math.random() * 1000) + "r" || 'floorcoverage') + 'x' + x + "y" + y + "z" + z + math.round(math.random() * 1000) + "r",                             parent: this.object,                             position: position,                             type: props.type || '3d'                          })                         coveragesquare.lightsources = []                         console.log("this position has pushing this.coverage[props.class]: ")                         console.log(coveragesquare.position.y)                         this.coverage[props.class].push(coveragesquare)                         console.log("this position.y of item in list pushed")                         console.log(this.coverage[props.class][0].position.y)                         console.log("this object pushed");                         console.log(this.coverage[props.class][0])                      }                 } else {                     var coveragesquare = new cube({                         width: props.squaresize || props.resolution || 0.05,                         height: props.squaresize || props.resolution || 0.05,                         depth: props.squaresize || props.resolution || 0.05,                         sides: props.sides || ["bottom", "front", "top", "left", "right", "back"],                         group: 'coverage',                         class: props.class || 'floorcoverage',                         id: (props.class + math.round(math.random() * 1000) + "r" || 'floorcoverage') + 'x' + x + "y" + math.round(position.y) + "z" + z + math.round(math.random() * 100),                         parent: this.object,                         position: position,                         type: props.type || '3d'                     })                     coveragesquare.lightsources = []                     this.coverage[props.class].push(coveragesquare)                  }                 // console.log(this.coverage[props.class])             }         }         if (props.calclumens !== false) {              (var point = 0; point < this.coverage[props.class].length; point++) {                 this.coverage[props.class][point].lumenspsqm = 0                 (var light = 0; light < this.lights.length; light++) {                     (var diode = 0; diode < this.lights[light].leds.diodes.length; diode++) {                         // if(this.lights[light].position.type ){                         //                         // }                         var tempdiode = this.lights[light].leds.diodes[diode]                             // console.log({                             //     diode: tempdiode,                             //     x: this.coverage[props.class][point].position.x,                             //     y: this.coverage[props.class][point].position.y,                             //     z: this.coverage[props.class][point].position.z,                          // })                         if (this.coverage[props.class][point].position.type == 'center') {                             // console.log("this y position use calculate coverage")                             // console.log(this.coverage[props.class][point]);                             var position = this.coverage[props.class][point].position                                 // console.log("why y in position same")                                 // console.log(position);                             var result = coverageat({                                 diode: tempdiode,                                 x: position.x,                                 y: position.y,                                 z: position.z,                              })                             this.coverage[props.class][point].lightsources.push(tempdiode)                             this.coverage[props.class][point].lumenspsqm += result                                 // console.log("what these results")                                 // console.log(result)                          } else {                             var results = []                             (var num = 0; num < 4; num++) {                                 if (num == 0) {                                     var xadjustment = (this.coverage[props.class][point].width / 2)                                     var zadjustment = (this.coverage[props.class][point].depth / 2)                                 } else if (num == 1) {                                     var xadjustment = (this.coverage[props.class][point].width / 2) * -1                                     var zadjustment = (this.coverage[props.class][point].depth / 2)                                 } else if (num == 2) {                                     var xadjustment = (this.coverage[props.class][point].width / 2)                                     var zadjustment = (this.coverage[props.class][point].depth / 2) * -1                                 } else if (num == 3) {                                     var xadjustment = (this.coverage[props.class][point].width / 2) * -1                                     var zadjustment = (this.coverage[props.class][point].depth / 2) * -1                                 }                                 results.push(coverageat({                                     diode: tempdiode,                                     x: this.coverage[props.class][point].position.x + xadjustment,                                     y: this.coverage[props.class][point].position.y,                                     z: this.coverage[props.class][point].position.z + zadjustment,                                 }))                             }                             var averageof = (results.reduce((a, b) => + b, 0)) / results.length                             this.coverage[props.class][point].lightsources.push(tempdiode)                              this.coverage[props.class][point].lumenspsqm += averageof                             if (this.coverage[props.class][point].id == 'floorgridx5y0z3') {}                         }                     }                     this.coverage[props.class][point].lumens = this.coverage[props.class][point].lumenspsqm * ((this.coverage[props.class][point].width * this.coverage[props.class][point].depth))                 }                 var str = '<div class="floorgriddata" id="' + this.coverage[props.class][point].id + 'data" style="transform: rotatex(0deg) translate3d(-50%, -' + 40 * 2 + 'px, -30px)"><div class="data">lux: ' + math.round(this.coverage[props.class][point].lumenspsqm) + '</div><div class="data">lumens: ' + math.round(this.coverage[props.class][point].lumens) + '</div></div>'                     // var html = $.parsehtml(str)                  // var $dataelement = $('<div>', {id:this.coverage[props.class][point].id+"data", class:'floorgriddata'})                 $("#" + this.coverage[props.class][point].id + ' #' + this.coverage[props.class][point].sides[0]).append(str)                     // this.coverage[props.class][point]             }             var highestnum = 0             (var point = 0; point < this.coverage[props.class].length; point++) {                 if (this.coverage[props.class][point].lumenspsqm > highestnum) {                     highestnum = this.coverage[props.class][point].lumenspsqm                 }             }             (var point = 0; point < this.coverage[props.class].length; point++) {                 if (this.coverage[props.class][point].id == 'floorgridx5y0z3') {}                 if (highestnum > 0) {                     $('#' + this.coverage[props.class][point].scene.id + ' #' + this.coverage[props.class][point].id + ' .face').css({                         // background   : '#ffffff',                         opacity: this.coverage[props.class][point].lumenspsqm / (highestnum * 2)                     })                 } else {                     $('#' + this.coverage[props.class][point].scene.id + ' #' + this.coverage[props.class][point].id + ' .face').css({                         // background   : '#ffffff',                         opacity: 1                     })                  }             }         }        } 

the coverageat function just:

function coverageat(props) {     /**     input     coverage area @props.length x @props.width     , x, y , h coordinates of light above plane     */     /* not needed more     output:     produces grid of data filled radiation levels @ points     */     this.energyatpoint = function(h, x, y) {         var lmpsqm = constantofproportionality * ((math.pow(h, 1 + 3.8317)) / math.pow(math.sqrt(math.pow(x, 2) + math.pow(y, 2) + math.pow(h, 2)), 3 + 3.8317))         return lmpsqm     }     var lightheight = props.diode.position.oy - props.y     if (lightheight < 0) {         return 0     } else {         var lightcrowz = math.sqrt(math.pow(props.diode.position.oz - props.z, 2))         var lightcrowx = math.sqrt(math.pow(props.diode.position.ox - props.x, 2))         var lightcrow = math.sqrt(math.pow(lightcrowz, 2) * math.pow(lightcrowx, 2))         var anglefromled = math.atan(lightcrow / lightheight)         var constantofproportionality = 2.56          return this.energyatpoint(lightheight, lightcrow, 0)     }   } 

and screenshot should verify behaviour: https://gyazo.com/a2c97409589dacea6ee622d827715fd0

i hope can spot bug.....


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -