From 74fdd2568e3f0d09260d3ba7805640245e3df731 Mon Sep 17 00:00:00 2001 From: dvdrw Date: Tue, 12 May 2026 15:38:08 +0200 Subject: [PATCH] refactor: change room offset_{x,y} to just {x,y} --- lib/localiser/domain/schema/room.ex | 10 +++++----- lib/localiser/localisation/filter/particle.ex | 4 ++-- lib/localiser/localisation/room/server.ex | 10 +++++----- lib/localiser/localisation/sensor/server.ex | 8 ++++---- lib/localiser/localisation/tag/filter.ex | 4 ++-- lib/localiser/web/schemas.ex | 6 +++--- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/localiser/domain/schema/room.ex b/lib/localiser/domain/schema/room.ex index 75f4754..4e37ead 100644 --- a/lib/localiser/domain/schema/room.ex +++ b/lib/localiser/domain/schema/room.ex @@ -7,10 +7,10 @@ defmodule Localiser.Domain.Schema.Room do schema "rooms" do field :name, :string - field :width, :float - field :height, :float - field :offset_x, :float - field :offset_y, :float + field :width, :float, default: 1.0 + field :height, :float, default: 1.0 + field :x, :float, default: 0.0 + field :y, :float, default: 0.0 belongs_to :floor, Floor has_many :sensors, Sensor @@ -21,7 +21,7 @@ defmodule Localiser.Domain.Schema.Room do @doc false def changeset(room, attrs) do room - |> cast(attrs, [:name, :floor_id, :width, :height, :offset_x, :offset_y]) + |> cast(attrs, [:name, :floor_id, :width, :height, :x, :y]) |> validate_required([:name, :floor_id]) |> assoc_constraint(:floor) end diff --git a/lib/localiser/localisation/filter/particle.ex b/lib/localiser/localisation/filter/particle.ex index 535ced2..be97509 100644 --- a/lib/localiser/localisation/filter/particle.ex +++ b/lib/localiser/localisation/filter/particle.ex @@ -334,8 +334,8 @@ defmodule Localiser.Localisation.Filter.Particle do defp derive_bounds(rooms) do coords = Enum.flat_map(rooms, fn r -> - ox = r.offset_x || 0.0 - oy = r.offset_y || 0.0 + ox = r.x || 0.0 + oy = r.y || 0.0 w = r.width || 0.0 h = r.height || 0.0 [{ox, oy}, {ox + w, oy + h}] diff --git a/lib/localiser/localisation/room/server.ex b/lib/localiser/localisation/room/server.ex index 9f3ca24..044cb3a 100644 --- a/lib/localiser/localisation/room/server.ex +++ b/lib/localiser/localisation/room/server.ex @@ -3,7 +3,7 @@ defmodule Localiser.Localisation.Room.Server do @pubsub Localiser.PubSub - defstruct [:id, :name, :offset_x, :offset_y, :width, :height, occupants: MapSet.new()] + defstruct [:id, :name, :x, :y, :width, :height, occupants: MapSet.new()] def start_link(room) do GenServer.start_link(__MODULE__, room, name: via(room.id)) @@ -32,8 +32,8 @@ defmodule Localiser.Localisation.Room.Server do state = %__MODULE__{ id: room.id, name: room.name, - offset_x: room.offset_x || 0.0, - offset_y: room.offset_y || 0.0, + x: room.x || 0.0, + y: room.y || 0.0, width: room.width || 0.0, height: room.height || 0.0 } @@ -71,8 +71,8 @@ defmodule Localiser.Localisation.Room.Server do def handle_info({:room_updated, %{id: id} = room}, %{id: id} = state) do {:noreply, %{state | name: room.name, - offset_x: room.offset_x || 0.0, - offset_y: room.offset_y || 0.0, + x: room.x || 0.0, + y: room.y || 0.0, width: room.width || 0.0, height: room.height || 0.0 }} diff --git a/lib/localiser/localisation/sensor/server.ex b/lib/localiser/localisation/sensor/server.ex index f595122..b893161 100644 --- a/lib/localiser/localisation/sensor/server.ex +++ b/lib/localiser/localisation/sensor/server.ex @@ -56,8 +56,8 @@ defmodule Localiser.Localisation.Sensor.Server do state = %__MODULE__{ sensor_id: sensor.sensor_id, sensor_db_id: sensor.id, - floor_x: (room.offset_x || 0.0) + (sensor.x || 0.0), - floor_y: (room.offset_y || 0.0) + (sensor.y || 0.0), + floor_x: (room.x || 0.0) + (sensor.x || 0.0), + floor_y: (room.y || 0.0) + (sensor.y || 0.0), rssi_ref: rssi_ref, path_loss_exp: path_loss_exp } @@ -114,8 +114,8 @@ defmodule Localiser.Localisation.Sensor.Server do # Position updated (sensor dragged in layout). @impl true def handle_info({:sensor_enrolled, %Sensor{sensor_id: sid} = sensor, room}, %{sensor_id: sid} = state) do - floor_x = (room.offset_x || 0.0) + (sensor.x || 0.0) - floor_y = (room.offset_y || 0.0) + (sensor.y || 0.0) + floor_x = (room.x || 0.0) + (sensor.x || 0.0) + floor_y = (room.y || 0.0) + (sensor.y || 0.0) {:noreply, %{state | floor_x: floor_x, floor_y: floor_y}} end diff --git a/lib/localiser/localisation/tag/filter.ex b/lib/localiser/localisation/tag/filter.ex index 296a1b8..692de2f 100644 --- a/lib/localiser/localisation/tag/filter.ex +++ b/lib/localiser/localisation/tag/filter.ex @@ -121,8 +121,8 @@ defmodule Localiser.Localisation.Tag.Filter do defp find_room(rooms, x, y) do Enum.find(rooms, fn room -> - ox = room.offset_x || 0.0 - oy = room.offset_y || 0.0 + ox = room.x || 0.0 + oy = room.y || 0.0 x >= ox and x < ox + (room.width || 0.0) and y >= oy and y < oy + (room.height || 0.0) end) diff --git a/lib/localiser/web/schemas.ex b/lib/localiser/web/schemas.ex index ad44506..c3399e4 100644 --- a/lib/localiser/web/schemas.ex +++ b/lib/localiser/web/schemas.ex @@ -250,10 +250,10 @@ defmodule Localiser.Web.Schemas do title: "SensorPlaceParams", type: :object, properties: %{ room_id: %Schema{type: :integer}, - x: %Schema{type: :number, format: :float}, - y: %Schema{type: :number, format: :float} + offset_x: %Schema{type: :number, format: :float}, + offset_y: %Schema{type: :number, format: :float} }, - required: [:room_id, :x, :y] + required: [:room_id, :offset_x, :offset_y] }) end