Skip to content

Commit

Permalink
Balanced road speeds
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-hanzal committed Jan 31, 2025
1 parent a0b8b7f commit a1b24ce
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions apps/pico/src/app/derivean/service/withBuildingGraph.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Graph from "graphology";
import { sql } from "kysely";
import type { WithTransaction } from "~/app/derivean/db/WithTransaction";

export namespace withBuildingGraph {
Expand Down Expand Up @@ -31,7 +32,11 @@ export const withBuildingGraph = async ({
const buildings = await tx
.selectFrom("Building as b")
.innerJoin("Land as l", "l.id", "b.landId")
.select(["b.id", "b.x", "b.y"])
.select([
"b.id",
(eb) => sql<number>`${eb.ref("b.x")} + ${eb.ref("l.x")}`.as("x"),
(eb) => sql<number>`${eb.ref("b.y")} + ${eb.ref("l.y")}`.as("y"),
])
.where("b.userId", "=", userId)
.where("l.mapId", "=", mapId)
.execute();
Expand All @@ -45,12 +50,13 @@ export const withBuildingGraph = async ({
const buildingWaypoints = await tx
.selectFrom("Building_Waypoint as bw")
.innerJoin("Building as b", "b.id", "bw.buildingId")
.innerJoin("Land as l", "l.id", "b.landId")
.innerJoin("Waypoint as w", "w.id", "bw.waypointId")
.select([
"bw.buildingId",
"bw.waypointId",
"b.x as buildingX",
"b.y as buildingY",
(eb) => sql<number>`${eb.ref("b.x")} + ${eb.ref("l.x")}`.as("buildingX"),
(eb) => sql<number>`${eb.ref("b.y")} + ${eb.ref("l.y")}`.as("buildingY"),
"w.x as waypointX",
"w.y as waypointY",
])
Expand Down Expand Up @@ -115,12 +121,6 @@ export const withBuildingGraph = async ({
(waypointX - buildingX) ** 2 + (waypointY - buildingY) ** 2,
);

/**
* TODO Building and waypoints are in different spaces, thus lengths are not correct:
* - Building lives inside a land (so it has relative coordinates)
* - Waypoints lives in a map (so it has absolute coordinates)
*/

graph.addEdge(buildingId, waypointId, {
type: "building-waypoint",
length,
Expand Down

0 comments on commit a1b24ce

Please sign in to comment.