summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Moore <jacksonmoore@tuta.io>2026-09-04 10:25:43 +0200
committerJackson Moore <jacksonmoore@tuta.io>2026-09-04 10:25:43 +0200
commitab20c92fb4025d447b41de5529c2380a668f4958 (patch)
tree221ad72ff48f1697bfbe45e8eaa01dbffaab85a5
parentf04282c17fa96e88e939e17d823489dbf10594e7 (diff)
Accept initial stationary TILL destinations
-rw-r--r--lua/clever_f/destination_engine.lua31
-rw-r--r--tests/run.lua37
2 files changed, 61 insertions, 7 deletions
diff --git a/lua/clever_f/destination_engine.lua b/lua/clever_f/destination_engine.lua
index 0ae2314..e3a7fc1 100644
--- a/lua/clever_f/destination_engine.lua
+++ b/lua/clever_f/destination_engine.lua
@@ -100,14 +100,22 @@ local function strict_destination(descriptor, destination, origin)
return comparison < 0
end
-local function acceptable_destination(request, destination, origin)
- if request.plan.descriptor.family == domain.Family.FIND then
- return strict_destination(request.plan.descriptor, destination, origin)
+local function acceptable_destination(
+ request,
+ destination,
+ origin,
+ allow_till_equality
+)
+ local descriptor = request.plan.descriptor
+ if strict_destination(descriptor, destination, origin) then
+ return true
end
- return true
+ return descriptor.family == domain.Family.TILL
+ and allow_till_equality
+ and domain.Position.equal(destination, origin)
end
-local function next_destination(request, origin)
+local function next_destination(request, origin, allow_till_equality)
local candidates = candidate_starts(request, origin)
while true do
@@ -122,7 +130,12 @@ local function next_destination(request, origin)
) then
local destination = target_destination(request, target_position)
if destination ~= nil
- and acceptable_destination(request, destination, origin)
+ and acceptable_destination(
+ request,
+ destination,
+ origin,
+ allow_till_equality
+ )
then
return destination
end
@@ -132,7 +145,11 @@ end
function DestinationEngine:calculate(view, origin, plan, count, first_move)
local request = calculation_inputs(view, origin, plan, count, first_move)
- local destination = next_destination(request, request.origin)
+ local destination = next_destination(
+ request,
+ request.origin,
+ request.first_move
+ )
if destination == nil then
return domain.SearchOutcome.boundary_before_any(request.origin)
end
diff --git a/tests/run.lua b/tests/run.lua
index 1f9b9da..fc89801 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -2618,6 +2618,43 @@ test("FIND requires destinations on the strict motion side", function()
)
end)
+test("First TILL moves accept an adjacent stationary destination", function()
+ local engine = destination_engine.new()
+ local forward_view = text_topology.new({ "ab" }, "utf-8")
+ local forward = motion_plan.build(
+ target_plan.build(target("b"), matching_policy()),
+ "t"
+ )
+ local forward_origin = domain.Position.new(1, 1)
+ local forward_outcome = engine:calculate(
+ forward_view,
+ forward_origin,
+ forward,
+ 1,
+ true
+ )
+ same(domain.SearchStatus.COMPLETE, forward_outcome.status)
+ same(forward_origin, forward_outcome.endpoint)
+ same(1, forward_outcome.successful_steps)
+
+ local backward_view = text_topology.new({ "ba" }, "utf-8")
+ local backward = motion_plan.build(
+ target_plan.build(target("b"), matching_policy()),
+ "T"
+ )
+ local backward_origin = domain.Position.new(1, 2)
+ local backward_outcome = engine:calculate(
+ backward_view,
+ backward_origin,
+ backward,
+ 1,
+ true
+ )
+ same(domain.SearchStatus.COMPLETE, backward_outcome.status)
+ same(backward_origin, backward_outcome.endpoint)
+ same(1, backward_outcome.successful_steps)
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then