Coding: Don't make mistakes when resizing objects! Coding: Älä tee virheitä, kun kokoa esineitä! Preserve the initial ratio correctly! Säilyttää alkuperäisen suhteen oikein!
Posted on 17. Postitettu 17. Jun, 2009 by Dragos in Coding Kesäkuu, 2009 Dragos vuonna Koodi
I was tempted many times to do quick adjustments to my code, without taking into consideration some basic mathematical principles. Olen ollut taipuvainen monta kertaa tehdä nopeita muutoksia minun koodi, ottamatta huomioon joitakin matemaattisia peruskäsitteitä. For examples if a box is first of all 100px tall and 60px wide, and then I notice that this box does not fit the place where it was intended to be placed, what I did was to subtract 10 px from the width of the box, for it to fit some area, and at the same time I subtracted 10 px from the height also, thinking that doing so I kept the ratio of the initial sizes of the box. Esimerkkejä Jos laatikko on ensinnäkin 100px pitkä ja 60px leveä, ja sitten huomaan, että tämä valinta ei sovi, missä se oli tarkoitus asettaa, mitä tein oli vähennyslaskua 10 px alkaen leveys-ruutuun, se sopii joidenkin alueella, ja samalla olen vähennetään 10 px alkaen korkeudesta myös ajatella, että näin minä ajan suhde alkuperäisen koko ruutuun. In fact this is not true! Itse asiassa tämä ei ole totta!
Here's why: Tässä syy:
The ratio of the initial box is 100px/60px=1.66 Suhde alkuperäisen laatikon 100px/60px = 1,66
In the second case the ratio is: (100px-10px)/(60px-10px)=1.8 Toisessa tapauksessa suhde on: (100px-10px) / (60px-10px) = 1,8
So, if you used to apply the same technique as I did to quickly resize objects, forget about it, as it's wrong! Joten, jos käytetään soveltaa samaa tekniikkaa kuin tein nopeasti kokoa esineitä, unohtaa sen, koska se on väärin! Instead use the old method from school to determine a variable from two fractions, preserving the ratios. Sijaan käytä vanhaa menetelmää koulusta määrittää muuttujan kahteen osaan, säilyttää suhdelukuja. Back to the example above, in order to find out the new height value of the box I'd use this formula: 100px/60px=(100px-10px)/x, so x=60px*90px/100px=54px (instead of the incorrect value of 50px). Palaa esimerkiksi edellä, jotta voidaan selvittää uuden korkeus arvo ruutuun olin käyttää tätä kaavaa: 100px/60px = (100px-10px) / x, joten x = 60px * 90px/100px = 54px (eikä virheellinen arvo 50px). That's it! That's it!
No related posts. Ei aiheeseen liittyviä virkoja.












































