fix(junction): make complex corner radius responsive
This commit is contained in:
1 parent
36a8291c05
commit
53a2cb3450
8 files changed
+103
-11
No files matched your search
@@ -457,11 +457,13 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Tangent distance for a circle of `cornerRadius` inscribed in a wedge of
|
// Tangent distance for a circle of `cornerRadius` inscribed in a wedge of
|
||||||
// opening `delta`, clamped so the tangent points stay on the built arms.
|
// opening `delta`.
|
||||||
const tangentDistance = Math.min(
|
// Keep the radius control continuous. The previous handoff cap made a
|
||||||
cornerRadius / Math.tan((delta * Math.PI) / 360),
|
// sizeable part of the advertised 1..25 m range geometry-inert: once the
|
||||||
Math.max(2, outerRadius - apexReach),
|
// tangent distance hit the cap, pressing Enter only changed metadata.
|
||||||
);
|
// The solver's radius bounds and the generated arm envelope provide the
|
||||||
|
// validity boundary; this value must remain the direct geometric response.
|
||||||
|
const tangentDistance = cornerRadius / Math.tan((delta * Math.PI) / 360);
|
||||||
const tangents = edges.map((edge) => helpers.offsetCoordinate(apex, edge.heading, tangentDistance));
|
const tangents = edges.map((edge) => helpers.offsetCoordinate(apex, edge.heading, tangentDistance));
|
||||||
const curve = quadraticCurve(tangents[0], apex, tangents[1], CORNER_FILLET_SEGMENTS);
|
const curve = quadraticCurve(tangents[0], apex, tangents[1], CORNER_FILLET_SEGMENTS);
|
||||||
const ring = [...curve, center, curve[0]];
|
const ring = [...curve, center, curve[0]];
|
||||||
|
|||||||
@@ -263,14 +263,37 @@ test.describe('workbench editing shell', () => {
|
|||||||
await expect(workspace.getByText(/车行道宽度/).first()).toBeVisible();
|
await expect(workspace.getByText(/车行道宽度/).first()).toBeVisible();
|
||||||
await expect(workspace.getByText(/车行道收口距离/).first()).toBeVisible();
|
await expect(workspace.getByText(/车行道收口距离/).first()).toBeVisible();
|
||||||
await expect(workspace.getByText(/角部圆角/).first()).toBeVisible();
|
await expect(workspace.getByText(/角部圆角/).first()).toBeVisible();
|
||||||
const parameterInput = workspace.locator('.parameter-input').first();
|
const cornerGroup = workspace.locator('.parameter-group').filter({ hasText: '角部圆角' });
|
||||||
|
const parameterInput = cornerGroup.locator('.parameter-input').first();
|
||||||
const parameterValue = Number(await parameterInput.inputValue());
|
const parameterValue = Number(await parameterInput.inputValue());
|
||||||
|
const baselinePreview = await page.request
|
||||||
|
.post('/api/edit-preview', { data: { previewSeq: 0, document: scoped.document, selection: { cluster: id } } })
|
||||||
|
.then((response) => response.json());
|
||||||
const previewRequest = page.waitForRequest(
|
const previewRequest = page.waitForRequest(
|
||||||
(request) => request.method() === 'POST' && request.url().endsWith('/api/edit-preview'),
|
(request) => request.method() === 'POST' && request.url().endsWith('/api/edit-preview'),
|
||||||
);
|
);
|
||||||
await parameterInput.fill(String(parameterValue + 0.1));
|
const previewResponse = page.waitForResponse(
|
||||||
await previewRequest;
|
(response) => response.request().method() === 'POST' && response.url().endsWith('/api/edit-preview'),
|
||||||
await expect(parameterInput).toHaveValue(String(parameterValue + 0.1));
|
);
|
||||||
|
await parameterInput.fill(String(parameterValue + 2));
|
||||||
|
await parameterInput.press('Enter');
|
||||||
|
const request = await previewRequest;
|
||||||
|
const response = await previewResponse;
|
||||||
|
const requestBody = request.postDataJSON() as {
|
||||||
|
constraints: Array<{ kind: string; value: { radiusMeters: number }; anchor: { cornerKey: string } }>;
|
||||||
|
};
|
||||||
|
expect(requestBody.constraints).toHaveLength(structure.corners.length);
|
||||||
|
expect(requestBody.constraints.every((constraint) => constraint.kind === 'cluster-corner-radius')).toBe(true);
|
||||||
|
expect(requestBody.constraints.every((constraint) => constraint.value.radiusMeters === parameterValue + 2)).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
const cornerKey = requestBody.constraints[0].anchor?.cornerKey;
|
||||||
|
const updatedPreview = await response.json();
|
||||||
|
const cornerGeometry = (preview: {
|
||||||
|
layers: { roadSurface: { features: Array<{ properties: { corner_key?: string }; geometry: unknown }> } };
|
||||||
|
}) => preview.layers.roadSurface.features.find((feature) => feature.properties.corner_key === cornerKey)?.geometry;
|
||||||
|
expect(cornerGeometry(updatedPreview)).not.toEqual(cornerGeometry(baselinePreview));
|
||||||
|
await expect(parameterInput).toHaveValue(String(parameterValue + 2));
|
||||||
await page.reload();
|
await page.reload();
|
||||||
await expect(armButtons).toHaveCount(structure.arms.length);
|
await expect(armButtons).toHaveCount(structure.arms.length);
|
||||||
await expect(armButtons.first()).toHaveAttribute('aria-pressed', 'false');
|
await expect(armButtons.first()).toHaveAttribute('aria-pressed', 'false');
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ function App() {
|
|||||||
const [scene, setScene] = useState(false);
|
const [scene, setScene] = useState(false);
|
||||||
const [junctionHotspots, setJunctionHotspots] = useState(true);
|
const [junctionHotspots, setJunctionHotspots] = useState(true);
|
||||||
const [status, setStatus] = useState('正在加载工作台...');
|
const [status, setStatus] = useState('正在加载工作台...');
|
||||||
|
const [previewPending, setPreviewPending] = useState(false);
|
||||||
const [filter, setFilter] = useState<'all' | 'candidates' | 'other'>('all');
|
const [filter, setFilter] = useState<'all' | 'candidates' | 'other'>('all');
|
||||||
const [marking, setMarking] = useState<Record<string, unknown> | null>(null);
|
const [marking, setMarking] = useState<Record<string, unknown> | null>(null);
|
||||||
const [selectedObjectKey, setSelectedObjectKey] = useState<string | null>(null);
|
const [selectedObjectKey, setSelectedObjectKey] = useState<string | null>(null);
|
||||||
@@ -471,6 +472,7 @@ function App() {
|
|||||||
return new PreviewRequester({
|
return new PreviewRequester({
|
||||||
session: owner,
|
session: owner,
|
||||||
send: (request, signal) => api.editPreview({ ...request, selection: selectionRef.current }, signal),
|
send: (request, signal) => api.editPreview({ ...request, selection: selectionRef.current }, signal),
|
||||||
|
onPendingChange: setPreviewPending,
|
||||||
onSettled: (outcome, response) => {
|
onSettled: (outcome, response) => {
|
||||||
setEditDiagnostics(response.diagnostics);
|
setEditDiagnostics(response.diagnostics);
|
||||||
// The response carries a re-solved manifest. Keeping the stale one made the
|
// The response carries a re-solved manifest. Keeping the stale one made the
|
||||||
@@ -490,6 +492,7 @@ function App() {
|
|||||||
: 'area';
|
: 'area';
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
requester?.invalidate();
|
requester?.invalidate();
|
||||||
|
setPreviewPending(false);
|
||||||
// Preview geometry is scoped server output. Retaining it during an A -> B
|
// Preview geometry is scoped server output. Retaining it during an A -> B
|
||||||
// transition would draw A while B's manifest is loading.
|
// transition would draw A while B's manifest is loading.
|
||||||
setPreview(null);
|
setPreview(null);
|
||||||
@@ -1340,6 +1343,7 @@ function App() {
|
|||||||
resetHandle(handle);
|
resetHandle(handle);
|
||||||
setJunctionSession((current) => (current ? { ...current, status: 'draft', dirty: true } : current));
|
setJunctionSession((current) => (current ? { ...current, status: 'draft', dirty: true } : current));
|
||||||
}}
|
}}
|
||||||
|
previewPending={previewPending}
|
||||||
roads={junctionRoads}
|
roads={junctionRoads}
|
||||||
junctionCoordinate={junctionDescriptor.coordinate}
|
junctionCoordinate={junctionDescriptor.coordinate}
|
||||||
selectedFacility={element}
|
selectedFacility={element}
|
||||||
|
|||||||
@@ -233,12 +233,15 @@ export function ParameterPanel({
|
|||||||
handles,
|
handles,
|
||||||
hasSelection,
|
hasSelection,
|
||||||
grouped = false,
|
grouped = false,
|
||||||
|
previewPending = false,
|
||||||
ref,
|
ref,
|
||||||
...callbacks
|
...callbacks
|
||||||
}: RowCallbacks & {
|
}: RowCallbacks & {
|
||||||
handles: EditHandle[];
|
handles: EditHandle[];
|
||||||
hasSelection: boolean;
|
hasSelection: boolean;
|
||||||
grouped?: boolean;
|
grouped?: boolean;
|
||||||
|
/** An authoritative preview is queued or being solved for the shown values. */
|
||||||
|
previewPending?: boolean;
|
||||||
ref?: Ref<ParameterPanelHandle>;
|
ref?: Ref<ParameterPanelHandle>;
|
||||||
}) {
|
}) {
|
||||||
const nodes = useRef(new Map<string, HTMLInputElement>());
|
const nodes = useRef(new Map<string, HTMLInputElement>());
|
||||||
@@ -307,7 +310,12 @@ export function ParameterPanel({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="parameters">
|
<section className="parameters">
|
||||||
<h1>{grouped ? '路口参数' : '道路参数'}</h1>
|
<div className="parameters-heading">
|
||||||
|
<h1>{grouped ? '路口参数' : '道路参数'}</h1>
|
||||||
|
<span className={previewPending ? 'parameters-pending' : 'parameters-pending is-idle'} aria-live="polite">
|
||||||
|
正在更新预览…
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
{handles.length ? (
|
{handles.length ? (
|
||||||
grouped ? (
|
grouped ? (
|
||||||
<GroupedParameterList groups={[...groupedHandles.entries()]} register={register} {...callbacks} />
|
<GroupedParameterList groups={[...groupedHandles.entries()]} register={register} {...callbacks} />
|
||||||
|
|||||||
@@ -78,6 +78,25 @@ describe('pointerup flush', () => {
|
|||||||
await vi.advanceTimersByTimeAsync(500);
|
await vi.advanceTimersByTimeAsync(500);
|
||||||
expect(send).toHaveBeenCalledTimes(1);
|
expect(send).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('reports pending from a queued draft until its request settles', async () => {
|
||||||
|
const { send, pending } = deferredTransport();
|
||||||
|
const changes: boolean[] = [];
|
||||||
|
const requester = new PreviewRequester({
|
||||||
|
session,
|
||||||
|
send,
|
||||||
|
onSettled,
|
||||||
|
onPendingChange: (value) => changes.push(value),
|
||||||
|
debounceMs: 1,
|
||||||
|
});
|
||||||
|
requester.schedule({ constraints: [] });
|
||||||
|
expect(changes).toEqual([true]);
|
||||||
|
await vi.advanceTimersByTimeAsync(1);
|
||||||
|
expect(pending).toHaveLength(1);
|
||||||
|
pending[0].resolve(preview(1));
|
||||||
|
await vi.advanceTimersByTimeAsync(0);
|
||||||
|
expect(changes).toEqual([true, false]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('cancellation', () => {
|
describe('cancellation', () => {
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ export type PreviewDraft = Pick<EditPreviewRequest, 'constraints' | 'operations'
|
|||||||
export interface PreviewRequesterOptions {
|
export interface PreviewRequesterOptions {
|
||||||
session: EditSession;
|
session: EditSession;
|
||||||
send: PreviewTransport;
|
send: PreviewTransport;
|
||||||
|
/** True from the first queued draft until its latest request has settled. */
|
||||||
|
onPendingChange?: (pending: boolean) => void;
|
||||||
/** Called for every response the session accepted, stale ones excluded. */
|
/** Called for every response the session accepted, stale ones excluded. */
|
||||||
onSettled: (outcome: PreviewOutcome, response: EditPreviewResponse) => void;
|
onSettled: (outcome: PreviewOutcome, response: EditPreviewResponse) => void;
|
||||||
/** Real failures only; an abort is expected and never reported. */
|
/** Real failures only; an abort is expected and never reported. */
|
||||||
@@ -40,6 +42,7 @@ export class PreviewRequester {
|
|||||||
private inFlight: AbortController | null = null;
|
private inFlight: AbortController | null = null;
|
||||||
/** Changes whenever the owning map/junction scope changes. */
|
/** Changes whenever the owning map/junction scope changes. */
|
||||||
private generation = 0;
|
private generation = 0;
|
||||||
|
private pending = false;
|
||||||
private readonly debounceMs: number;
|
private readonly debounceMs: number;
|
||||||
|
|
||||||
constructor(private readonly options: PreviewRequesterOptions) {
|
constructor(private readonly options: PreviewRequesterOptions) {
|
||||||
@@ -48,6 +51,7 @@ export class PreviewRequester {
|
|||||||
|
|
||||||
/** During a drag: coalesce to one request per debounce window. */
|
/** During a drag: coalesce to one request per debounce window. */
|
||||||
schedule(draft: PreviewDraft): void {
|
schedule(draft: PreviewDraft): void {
|
||||||
|
this.setPending(true);
|
||||||
if (this.timer) clearTimeout(this.timer);
|
if (this.timer) clearTimeout(this.timer);
|
||||||
this.timer = setTimeout(() => {
|
this.timer = setTimeout(() => {
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
@@ -60,6 +64,7 @@ export class PreviewRequester {
|
|||||||
* meant, so it must not be dropped by a pending timer or lost to the debounce.
|
* meant, so it must not be dropped by a pending timer or lost to the debounce.
|
||||||
*/
|
*/
|
||||||
flush(draft: PreviewDraft): void {
|
flush(draft: PreviewDraft): void {
|
||||||
|
this.setPending(true);
|
||||||
if (this.timer) {
|
if (this.timer) {
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
@@ -75,6 +80,7 @@ export class PreviewRequester {
|
|||||||
}
|
}
|
||||||
this.inFlight?.abort();
|
this.inFlight?.abort();
|
||||||
this.inFlight = null;
|
this.inFlight = null;
|
||||||
|
this.setPending(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,7 +112,16 @@ export class PreviewRequester {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!isAbort(error)) this.options.onError?.(error);
|
if (!isAbort(error)) this.options.onError?.(error);
|
||||||
} finally {
|
} finally {
|
||||||
if (this.inFlight === controller) this.inFlight = null;
|
if (this.inFlight === controller) {
|
||||||
|
this.inFlight = null;
|
||||||
|
if (!this.timer) this.setPending(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setPending(pending: boolean): void {
|
||||||
|
if (this.pending === pending) return;
|
||||||
|
this.pending = pending;
|
||||||
|
this.options.onPendingChange?.(pending);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -38,6 +38,7 @@ interface Props {
|
|||||||
onSettleGroup?: (handles: EditHandle[], value: number) => void;
|
onSettleGroup?: (handles: EditHandle[], value: number) => void;
|
||||||
onAbandon?: () => void;
|
onAbandon?: () => void;
|
||||||
onReset?: (handle: EditHandle) => void;
|
onReset?: (handle: EditHandle) => void;
|
||||||
|
previewPending?: boolean;
|
||||||
roads?: Road[];
|
roads?: Road[];
|
||||||
junctionCoordinate?: Coordinate;
|
junctionCoordinate?: Coordinate;
|
||||||
selectedFacility?: ElementSelection | null;
|
selectedFacility?: ElementSelection | null;
|
||||||
@@ -77,6 +78,7 @@ export function JunctionWorkspace({
|
|||||||
onSettleGroup,
|
onSettleGroup,
|
||||||
onAbandon,
|
onAbandon,
|
||||||
onReset,
|
onReset,
|
||||||
|
previewPending = false,
|
||||||
roads = [],
|
roads = [],
|
||||||
junctionCoordinate = descriptor.coordinate,
|
junctionCoordinate = descriptor.coordinate,
|
||||||
selectedFacility,
|
selectedFacility,
|
||||||
@@ -472,6 +474,7 @@ export function JunctionWorkspace({
|
|||||||
handles={handles}
|
handles={handles}
|
||||||
hasSelection
|
hasSelection
|
||||||
grouped
|
grouped
|
||||||
|
previewPending={previewPending}
|
||||||
onDraft={onDraft ?? (() => undefined)}
|
onDraft={onDraft ?? (() => undefined)}
|
||||||
onDraftGroup={onDraftGroup}
|
onDraftGroup={onDraftGroup}
|
||||||
onSettle={onSettle ?? (() => undefined)}
|
onSettle={onSettle ?? (() => undefined)}
|
||||||
|
|||||||
@@ -311,6 +311,24 @@ pre {
|
|||||||
.parameters {
|
.parameters {
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
|
.parameters-heading {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.parameters-heading h1 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.parameters-pending {
|
||||||
|
min-width: 78px;
|
||||||
|
color: #286956;
|
||||||
|
font-size: 12px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.parameters-pending.is-idle {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
.parameters ul {
|
.parameters ul {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 6px;
|
gap: 6px;
|
||||||
|
|||||||
Reference in new issue
Block a user