Skip to content

Commit

Permalink
exponentiation and let refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Jan 23, 2024
1 parent 06771bb commit 9baaa67
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 29 deletions.
12 changes: 3 additions & 9 deletions src/frontends/leaflet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,13 @@ const leafletLayer = (options: LeafletLayerOptions = {}): any => {
ctx.save();
ctx.fillStyle = this.debug;
ctx.font = "600 12px sans-serif";
ctx.fillText(coords.z + " " + coords.x + " " + coords.y, 4, 14);
ctx.fillText(`${coords.z} ${coords.x} ${coords.y}`, 4, 14);

ctx.font = "12px sans-serif";
let ypos = 28;
for (const [k, v] of prepared_tilemap) {
const dt = v[0].data_tile;
ctx.fillText(
k + (k ? " " : "") + dt.z + " " + dt.x + " " + dt.y,
4,
ypos,
);
ctx.fillText(`${k + (k ? " " : "") + dt.z} ${dt.x} ${dt.y}`, 4, ypos);
ypos += 14;
}

Expand Down Expand Up @@ -376,9 +372,7 @@ const leafletLayer = (options: LeafletLayerOptions = {}): any => {
sourceName ? "/" : ""
} ${result.layerName}</b> ${result.feature.id || ""}</div>`;
for (const prop in result.feature.props) {
content =
content +
`<div style="font-size:0.9em">${prop} = ${result.feature.props[prop]}</div>`;
content = `${content}<div style="font-size:0.9em">${prop} = ${result.feature.props[prop]}</div>`;
}
firstRow = false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/frontends/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class Static {
// the origin of the painter call in global Z coordinates
const origin = normalized_center
.clone()
.mult(Math.pow(2, display_zoom) * 256)
.mult(2 ** display_zoom * 256)
.sub(new Point(width / 2, height / 2));

// the bounds of the painter call in global Z coordinates
Expand Down Expand Up @@ -203,7 +203,7 @@ export class Static {
);
const dt = prepared_tile.data_tile;
ctx.fillText(
k + (k ? " " : "") + dt.z + " " + dt.x + " " + dt.y,
`${k + (k ? " " : "") + dt.z} ${dt.x} ${dt.y}`,
prepared_tile.origin.x + 4,
prepared_tile.origin.y + 14 * (1 + idx),
);
Expand Down
3 changes: 1 addition & 2 deletions src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ export class Index {
if (existing[3] === added[3]) {
keys_for_ds++;
const dist = Math.sqrt(
Math.pow(+existing[0] - +added[0], 2) +
Math.pow(+existing[1] - +added[1], 2),
(+existing[0] - +added[0]) ** 2 + (+existing[1] - +added[1]) ** 2,
);
if (dist > max_dist) {
max_dist = dist;
Expand Down
22 changes: 9 additions & 13 deletions src/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const linelabel = (
targetLen: number,
): LabelableSegment[] => {
const chunks = [];
let a,
b,
c,
i = 0,
n = 0,
d = 0;
let a;
let b;
let c;
let i = 0;
let n = 0;
let d = 0;
let abmag = 0;
let bcmag = 0;
let abx = 0;
Expand All @@ -33,9 +33,7 @@ const linelabel = (

if (pts.length < 2) return [];
if (pts.length === 2) {
d = Math.sqrt(
Math.pow(pts[1].x - pts[0].x, 2) + Math.pow(pts[1].y - pts[0].y, 2),
);
d = Math.sqrt((pts[1].x - pts[0].x) ** 2 + (pts[1].y - pts[0].y) ** 2);

return [
{
Expand All @@ -48,9 +46,7 @@ const linelabel = (
];
}

abmag = Math.sqrt(
Math.pow(pts[1].x - pts[0].x, 2) + Math.pow(pts[1].y - pts[0].y, 2),
);
abmag = Math.sqrt((pts[1].x - pts[0].x) ** 2 + (pts[1].y - pts[0].y) ** 2);
for (i = 1, n = pts.length - 1; i < n; i++) {
a = pts[i - 1];
b = pts[i];
Expand Down Expand Up @@ -145,7 +141,7 @@ export function lineCells(a: Point, b: Point, length: number, spacing: number) {
// determine function of line
const dx = b.x - a.x;
const dy = b.y - a.y;
const dist = Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));
const dist = Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2);

const retval = [];
// starting from the anchor, generate square cells,
Expand Down
2 changes: 1 addition & 1 deletion src/symbolizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function computeInterpolationFactor(
const progress = z - stops[idx][0];
if (difference === 0) return 0;
if (base === 1) return progress / difference;
return (base ** progress - 1) / (Math.pow(base, difference) - 1);
return (base ** progress - 1) / (base ** difference - 1);
}

export function exp(base: number, stops: number[][]): (z: number) => number {
Expand Down
3 changes: 1 addition & 2 deletions src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ export class View {
display_zoom: number,
bounds: any,
): Array<TileTransform> {
const fractional =
Math.pow(2, display_zoom) / Math.pow(2, Math.ceil(display_zoom));
const fractional = 2 ** display_zoom / 2 ** Math.ceil(display_zoom);
const needed = [];
let scale = 1;
const dim = this.tileCache.tileSize;
Expand Down

0 comments on commit 9baaa67

Please sign in to comment.