Skip to content

Commit 20d8870

Browse files
committed
Merge pull request #1139 from mgreter/bugfix/issue_1101
Add fix for hsla implementation
2 parents 89338a7 + 79e8d32 commit 20d8870

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

functions.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,18 @@ namespace Sass {
281281
s /= 100.0;
282282
l /= 100.0;
283283

284+
if (l < 0) l = 0;
285+
if (s < 0) s = 0;
286+
if (l > 1) l = 1;
287+
if (s > 1) s = 1;
288+
while (h < 0) h += 1;
289+
while (h > 1) h -= 1;
290+
284291
// Algorithm from the CSS3 spec: http://www.w3.org/TR/css3-color/#hsl-color.
285292
double m2;
286293
if (l <= 0.5) m2 = l*(s+1.0);
287294
else m2 = (l+s)-(l*s);
288-
double m1 = (l*2)-m2;
295+
double m1 = (l*2.0)-m2;
289296
// round the results -- consider moving this into the Color constructor
290297
double r = (h_to_rgb(m1, m2, h+1.0/3.0) * 255.0);
291298
double g = (h_to_rgb(m1, m2, h) * 255.0);

0 commit comments

Comments
 (0)