@mapbox/mapbox-gl-style-spec 14.15.0-beta.1 → 14.15.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapbox/mapbox-gl-style-spec",
3
- "version": "14.15.0-beta.1",
3
+ "version": "14.15.0-beta.2",
4
4
  "description": "a specification for mapbox gl styles",
5
5
  "author": "Mapbox",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
package/util/color.ts CHANGED
@@ -206,46 +206,41 @@ export abstract class RenderColor {
206
206
 
207
207
  if (this.premultiplied) {
208
208
  if (a === 0) return [0, 0, 0, 0];
209
-
210
- r /= a;
211
- g /= a;
212
- b /= a;
209
+ const invA = 1 / a; // Single division, then multiply
210
+ r *= invA;
211
+ g *= invA;
212
+ b *= invA;
213
213
  }
214
214
 
215
- const red = Math.min(Math.max(r, 0.0), 1.0);
216
- const green = Math.min(Math.max(g, 0.0), 1.0);
217
- const blue = Math.min(Math.max(b, 0.0), 1.0);
215
+ const red = Math.min(Math.max(r, 0), 1);
216
+ const green = Math.min(Math.max(g, 0), 1);
217
+ const blue = Math.min(Math.max(b, 0), 1);
218
218
 
219
219
  const min = Math.min(red, green, blue);
220
220
  const max = Math.max(red, green, blue);
221
+ const delta = max - min;
221
222
 
222
- const l = (min + max) / 2;
223
+ const l = (min + max) * 0.5;
223
224
 
224
- if (min === max) {
225
+ if (delta === 0) {
225
226
  return [0, 0, l * 100, a];
226
227
  }
227
228
 
228
- const delta = max - min;
229
-
230
229
  const s = l > 0.5 ? delta / (2 - max - min) : delta / (max + min);
231
230
 
232
- let h = 0;
233
- if (max === red) {
234
- h = (green - blue) / delta + (green < blue ? 6 : 0);
235
- } else if (max === green) {
236
- h = (blue - red) / delta + 2;
237
- } else if (max === blue) {
238
- h = (red - green) / delta + 4;
231
+ let h: number;
232
+ switch (max) {
233
+ case red:
234
+ h = ((green - blue) / delta + (green < blue ? 6 : 0)) * 60;
235
+ break;
236
+ case green:
237
+ h = ((blue - red) / delta + 2) * 60;
238
+ break;
239
+ default: // blue
240
+ h = ((red - green) / delta + 4) * 60;
239
241
  }
240
242
 
241
- h *= 60;
242
-
243
- return [
244
- Math.min(Math.max(h, 0), 360),
245
- Math.min(Math.max(s * 100, 0), 100),
246
- Math.min(Math.max(l * 100, 0), 100),
247
- a
248
- ];
243
+ return [h, s * 100, l * 100, a];
249
244
  }
250
245
 
251
246
  /**