From 6384048fb5c085bc8111e8f979647d41f7279f20 Mon Sep 17 00:00:00 2001
From: Tangent Wantwight <tangent128@gmail.com>
Date: Sat, 13 Jan 2024 11:34:37 -0500
Subject: [PATCH] consolidate xy into method

---
 island/grid.ts | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/island/grid.ts b/island/grid.ts
index 2207d99..07dbb48 100644
--- a/island/grid.ts
+++ b/island/grid.ts
@@ -1,21 +1,9 @@
 import { Prng, mulberry32 } from "../lib/prng";
 
-type Lookup2d = (x: number, y: number) => number;
-function dim(width: number, height: number): Lookup2d {
-  return function xy(x: number, y: number) {
-    return (
-      (((x % width) + width) % width) +
-      width * (((y % height) + height) % height)
-    );
-  };
-}
-
 export class IslandGrid {
   data: number[];
   rng: Prng;
 
-  xy: Lookup2d;
-
   basePos: number;
   lobePos1: number;
   lobePos2: number;
@@ -25,7 +13,6 @@ export class IslandGrid {
   constructor(public width: number, public height: number, seed: number) {
     this.data = Array(width * height).fill(0);
     this.rng = mulberry32(seed);
-    this.xy = dim(width, height);
 
     this.basePos = this.data.length >> 1;
     this.lobePos1 = this.xy(
@@ -38,6 +25,13 @@ export class IslandGrid {
     );
   }
 
+  public xy(x: number, y: number): number {
+    return (
+      (((x % this.width) + this.width) % this.width) +
+      this.width * (((y % this.height) + this.height) % this.height)
+    );
+  }
+
   public get(x: number, y: number): number {
     return this.data[this.xy(x, y)];
   }