PimpTrizkit / PJs

Pimped Javascript - Just a library of my javascript functions, or shims. They are generally built for speed, size, versatility, and portability (copy and paste-able). Readability will be sacrificed. Because they are optimized for usage right out-of-the-box.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minor improvement to RGB_Linear_Blend

jorgecarleitao opened this issue · comments

The current code has a duplicated variable name, that some linters will complain and crash in CI mode.

I propose changing the micro linear blend to:

// Version 4.0
const RGB_Linear_Blend=(p,c0,c1)=>{
    var i=parseInt,r=Math.round,P=1-p,[a,b,c,d]=c0.split(","),[e,f,g,h]=c1.split(","),x=d||h,j=x?","+(!d?h:!h?d:r((parseFloat(d)*P+parseFloat(h)*p)*1000)/1000+")"):")";
    return"rgb"+(x?"a(":"(")+r(i(a[3]==="a"?a.slice(5):a.slice(4))*P+i(e[3]==="a"?e.slice(5):e.slice(4))*p)+","+r(i(b)*P+i(f)*p)+","+r(i(c)*P+i(g)*p)+j;
};

(i.e. replace d by j in one of the variables.

Thanks for your interest in my function!

I see what you are talking about. What I did there was to recycle a variable. d did its job and I reused it. I was just trying to minimize the amount of variable declarations. But, thats no biggie. I can make this change.

PT

Man, I screwed this one up, LOL! I messed up when I made your changes, a long time ago. I just now saw it. So I just now fixed it. Also, I fixed up the other Micro Functions so that they don't reuse variables. Also, I copied and pasted those Micro functions into their own file for the < > Code tab. Even though they are meant to only copy-and-paste one or two of them... not link the whole file.. which kind of defeats the point of being so small and copy-paste-able.