mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +00:00
fix(planner): an untimed hotel bookend only closes a local day-trip loop (#2157)
Without stay times the bookend leg drew unless a carrier or a 2000 km edge stop disproved it, which is exactly the reported car trip: home five hundred kilometres away, routed back to the hotel after check-out. The disproof threshold is a day-trip distance now, and the route optimizer anchors through the same rule on desktop and mobile instead of unconditionally, so drawing and optimizing agree.
This commit is contained in:
@@ -31,6 +31,7 @@ export function optimizeDayOrder(
|
||||
dayAssignments: Assignment[],
|
||||
accommodations: Accommodation[],
|
||||
fromAccommodation: boolean,
|
||||
dayHasCarrier?: boolean,
|
||||
): OptimizedDay | null {
|
||||
const locked = new Map<number, Assignment>()
|
||||
const movable: Assignment[] = []
|
||||
@@ -41,7 +42,10 @@ export function optimizeDayOrder(
|
||||
const withCoords = movable.filter(a => a.place?.lat != null && a.place?.lng != null)
|
||||
if (withCoords.length < 2) return null
|
||||
const noCoords = movable.filter(a => a.place?.lat == null || a.place?.lng == null)
|
||||
const anchors = fromAccommodation ? getAccommodationAnchors(day, days, accommodations) : {}
|
||||
const anchors = fromAccommodation
|
||||
? getAccommodationAnchors(day, days, accommodations,
|
||||
withCoords.map(a => ({ lat: a.place!.lat!, lng: a.place!.lng! })), dayHasCarrier)
|
||||
: {}
|
||||
const optimized = optimizeRoute(
|
||||
withCoords.map(a => ({ lat: a.place!.lat!, lng: a.place!.lng!, _assignmentId: a.id })),
|
||||
anchors,
|
||||
|
||||
@@ -302,7 +302,7 @@ export function useMPlanTimeline(planner: TripPlanner) {
|
||||
if (!day) return
|
||||
const prevIds = dayAssignments.map(a => a.id)
|
||||
const result = optimizeDayOrder(
|
||||
day, days, dayAssignments, tripAccommodations, settings.optimize_from_accommodation !== false,
|
||||
day, days, dayAssignments, tripAccommodations, settings.optimize_from_accommodation !== false, dayHasCarrier,
|
||||
)
|
||||
if (!result) { toast.info(t('dayplan.toast.needTwoPlaces')); return }
|
||||
try {
|
||||
@@ -315,7 +315,7 @@ export function useMPlanTimeline(planner: TripPlanner) {
|
||||
} catch (err: unknown) {
|
||||
toast.error(err instanceof Error ? err.message : t('trip.toast.reorderError'))
|
||||
}
|
||||
}, [day, dayAssignments, days, tripAccommodations, settings, tripActions, tripId, pushUndo, updateRouteForDay, toast, t])
|
||||
}, [day, dayAssignments, days, tripAccommodations, settings, dayHasCarrier, tripActions, tripId, pushUndo, updateRouteForDay, toast, t])
|
||||
|
||||
const exportGoogleMaps = useCallback(() => {
|
||||
if (!day) return
|
||||
|
||||
@@ -172,7 +172,7 @@ export default function MDaySheet({ planner, shell }: MTripSheetsProps) {
|
||||
const optimizeDay = () => {
|
||||
if (!day || dayAssignments.length < 3) return
|
||||
const result = optimizeDayOrder(
|
||||
day, planner.days, dayAssignments, planner.tripAccommodations, optimizeFromAccommodation !== false,
|
||||
day, planner.days, dayAssignments, planner.tripAccommodations, optimizeFromAccommodation !== false, dayHasCarrier,
|
||||
)
|
||||
if (!result) return
|
||||
planner.handleReorder(day.id, result.order.map(a => a.id))
|
||||
|
||||
Reference in New Issue
Block a user