Skip to content

Commit ba1fa1b

Browse files
committed
Revert "feat: Add slot registration and spatial indexing for hit detection"
This reverts commit 70fbfd0.
1 parent 5171dec commit ba1fa1b

File tree

9 files changed

+26
-562
lines changed

9 files changed

+26
-562
lines changed

src/lib/litegraph/src/LGraph.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
} from '@/lib/litegraph/src/constants'
77
import type { UUID } from '@/lib/litegraph/src/utils/uuid'
88
import { createUuidv4, zeroUuid } from '@/lib/litegraph/src/utils/uuid'
9-
import { layoutStore } from '@/renderer/core/layout/store/LayoutStore'
109

1110
import type { DragAndScaleState } from './DragAndScale'
1211
import { LGraphCanvas } from './LGraphCanvas'
@@ -2246,8 +2245,6 @@ export class LGraph
22462245
// Drop broken links, and ignore reroutes with no valid links
22472246
if (!reroute.validateLinks(this._links, this.floatingLinks)) {
22482247
this.reroutes.delete(reroute.id)
2249-
// Clean up layout store
2250-
layoutStore.deleteRerouteLayout(String(reroute.id))
22512248
}
22522249
}
22532250

src/lib/litegraph/src/LGraphCanvas.ts

Lines changed: 17 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
type LinkRenderContext,
77
LitegraphLinkAdapter
88
} from '@/renderer/core/canvas/litegraph/LitegraphLinkAdapter'
9-
import { layoutStore } from '@/renderer/core/layout/store/LayoutStore'
109

1110
import { CanvasPointer } from './CanvasPointer'
1211
import type { ContextMenu } from './ContextMenu'
@@ -2198,14 +2197,11 @@ export class LGraphCanvas
21982197
this.processSelect(node, e, true)
21992198
} else if (this.links_render_mode !== LinkRenderType.HIDDEN_LINK) {
22002199
// Reroutes
2201-
// Try layout store first, fallback to old method
2202-
const rerouteLayout = layoutStore.queryRerouteAtPoint({
2203-
x: e.canvasX,
2204-
y: e.canvasY
2205-
})
2206-
const reroute = rerouteLayout
2207-
? graph.getReroute(Number(rerouteLayout.id))
2208-
: graph.getRerouteOnPos(e.canvasX, e.canvasY, this.#visibleReroutes)
2200+
const reroute = graph.getRerouteOnPos(
2201+
e.canvasX,
2202+
e.canvasY,
2203+
this.#visibleReroutes
2204+
)
22092205
if (reroute) {
22102206
if (e.altKey) {
22112207
pointer.onClick = (upEvent) => {
@@ -2406,21 +2402,16 @@ export class LGraphCanvas
24062402
this.ctx.lineWidth = this.connections_width + 7
24072403
const dpi = Math.max(window?.devicePixelRatio ?? 1, 1)
24082404

2409-
// Try layout store for link hit testing first
2410-
const hitLinkId = layoutStore.queryLinkAtPoint({ x, y }, this.ctx)
2411-
24122405
for (const linkSegment of this.renderedPaths) {
24132406
const centre = linkSegment._pos
24142407
if (!centre) continue
24152408

2416-
// Check if this link was hit (using layout store or fallback to old method)
2417-
const isLinkHit = hitLinkId
2418-
? String(linkSegment.id) === hitLinkId
2419-
: linkSegment.path &&
2420-
this.ctx.isPointInStroke(linkSegment.path, x * dpi, y * dpi)
2421-
24222409
// If we shift click on a link then start a link from that input
2423-
if ((e.shiftKey || e.altKey) && isLinkHit) {
2410+
if (
2411+
(e.shiftKey || e.altKey) &&
2412+
linkSegment.path &&
2413+
this.ctx.isPointInStroke(linkSegment.path, x * dpi, y * dpi)
2414+
) {
24242415
this.ctx.lineWidth = lineWidth
24252416

24262417
if (e.shiftKey && !e.altKey) {
@@ -3148,27 +3139,8 @@ export class LGraphCanvas
31483139
// For input/output hovering
31493140
// to store the output of isOverNodeInput
31503141
const pos: Point = [0, 0]
3151-
3152-
// Try to use layout store for hit testing first, fallback to old method
3153-
let inputId: number = -1
3154-
let outputId: number = -1
3155-
3156-
const slotLayout = layoutStore.querySlotAtPoint({ x, y })
3157-
if (slotLayout && slotLayout.nodeId === String(node.id)) {
3158-
if (slotLayout.type === 'input') {
3159-
inputId = slotLayout.index
3160-
pos[0] = slotLayout.position.x
3161-
pos[1] = slotLayout.position.y
3162-
} else {
3163-
outputId = slotLayout.index
3164-
pos[0] = slotLayout.position.x
3165-
pos[1] = slotLayout.position.y
3166-
}
3167-
} else {
3168-
// Fallback to old method
3169-
inputId = isOverNodeInput(node, x, y, pos)
3170-
outputId = isOverNodeOutput(node, x, y, pos)
3171-
}
3142+
const inputId = isOverNodeInput(node, x, y, pos)
3143+
const outputId = isOverNodeOutput(node, x, y, pos)
31723144
const overWidget = node.getWidgetOnPos(x, y, true) ?? undefined
31733145

31743146
if (!node.mouseOver) {
@@ -5054,7 +5026,6 @@ export class LGraphCanvas
50545026
node._setConcreteSlots()
50555027
if (!node.collapsed) {
50565028
node.arrange()
5057-
node.registerSlots() // Register slots for hit detection
50585029
}
50595030
// Skip all node body/widget/title rendering. Vue overlay handles visuals.
50605031
return
@@ -5146,7 +5117,6 @@ export class LGraphCanvas
51465117
node._setConcreteSlots()
51475118
if (!node.collapsed) {
51485119
node.arrange()
5149-
node.registerSlots() // Register slots for hit detection
51505120
node.drawSlots(ctx, {
51515121
fromSlot: this.linkConnector.renderLinks[0]?.fromSlot as
51525122
| INodeOutputSlot
@@ -5161,7 +5131,6 @@ export class LGraphCanvas
51615131

51625132
this.drawNodeWidgets(node, null, ctx)
51635133
} else if (this.render_collapsed_slots) {
5164-
node.registerSlots() // Register slots for collapsed nodes too
51655134
node.drawCollapsedSlots(ctx)
51665135
}
51675136

@@ -5553,19 +5522,6 @@ export class LGraphCanvas
55535522
}
55545523
reroute.draw(ctx, this._pattern)
55555524

5556-
// Register reroute layout with layout store for hit testing
5557-
layoutStore.updateRerouteLayout(String(reroute.id), {
5558-
id: String(reroute.id),
5559-
position: { x: reroute.pos[0], y: reroute.pos[1] },
5560-
radius: 8, // Reroute.radius
5561-
bounds: {
5562-
x: reroute.pos[0] - 8,
5563-
y: reroute.pos[1] - 8,
5564-
width: 16,
5565-
height: 16
5566-
}
5567-
})
5568-
55695525
// Never draw slots when the pointer is down
55705526
if (!this.pointer.isDown) reroute.drawSlots(ctx)
55715527
}
@@ -6084,8 +6040,6 @@ export class LGraphCanvas
60846040
: segment.id
60856041
if (linkId !== undefined) {
60866042
graph.removeLink(linkId)
6087-
// Clean up layout store
6088-
layoutStore.deleteLinkLayout(String(linkId))
60896043
}
60906044
break
60916045
}
@@ -8163,18 +8117,11 @@ export class LGraphCanvas
81638117

81648118
// Check for reroutes
81658119
if (this.links_render_mode !== LinkRenderType.HIDDEN_LINK) {
8166-
// Try layout store first, fallback to old method
8167-
const rerouteLayout = layoutStore.queryRerouteAtPoint({
8168-
x: event.canvasX,
8169-
y: event.canvasY
8170-
})
8171-
const reroute = rerouteLayout
8172-
? this.graph.getReroute(Number(rerouteLayout.id))
8173-
: this.graph.getRerouteOnPos(
8174-
event.canvasX,
8175-
event.canvasY,
8176-
this.#visibleReroutes
8177-
)
8120+
const reroute = this.graph.getRerouteOnPos(
8121+
event.canvasX,
8122+
event.canvasY,
8123+
this.#visibleReroutes
8124+
)
81788125
if (reroute) {
81798126
menu_info.unshift(
81808127
{

src/lib/litegraph/src/LGraphNode.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {
33
type SlotPositionContext,
44
calculateInputSlotPos,
55
calculateInputSlotPosFromSlot,
6-
calculateOutputSlotPos,
7-
registerNodeSlots
6+
calculateOutputSlotPos
87
} from '@/renderer/core/canvas/litegraph/SlotCalculations'
98

109
import type { DragAndScale } from './DragAndScale'
@@ -4110,13 +4109,6 @@ export class LGraphNode
41104109
this.#arrangeWidgetInputSlots()
41114110
}
41124111

4113-
/**
4114-
* Register all slots with the layout store for hit detection
4115-
*/
4116-
registerSlots(): void {
4117-
registerNodeSlots(String(this.id), this.#getSlotPositionContext())
4118-
}
4119-
41204112
/**
41214113
* Draws a progress bar on the node.
41224114
* @param ctx The canvas context to draw on

src/lib/litegraph/src/LLink.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
SUBGRAPH_INPUT_ID,
33
SUBGRAPH_OUTPUT_ID
44
} from '@/lib/litegraph/src/constants'
5-
import { layoutStore } from '@/renderer/core/layout/store/LayoutStore'
65

76
import type { LGraphNode, NodeId } from './LGraphNode'
87
import type { Reroute, RerouteId } from './Reroute'
@@ -460,13 +459,9 @@ export class LLink implements LinkSegment, Serialisable<SerialisableLLink> {
460459
reroute.linkIds.delete(this.id)
461460
if (!keepReroutes && !reroute.totalLinks) {
462461
network.reroutes.delete(reroute.id)
463-
// Clean up layout store
464-
layoutStore.deleteRerouteLayout(String(reroute.id))
465462
}
466463
}
467464
network.links.delete(this.id)
468-
// Clean up layout store
469-
layoutStore.deleteLinkLayout(String(this.id))
470465
}
471466

472467
/**

src/renderer/core/canvas/litegraph/LitegraphLinkAdapter.ts

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {
3838
calculateOutputSlotPos
3939
} from '@/renderer/core/canvas/litegraph/SlotCalculations'
4040
import { layoutStore } from '@/renderer/core/layout/store/LayoutStore'
41-
import type { LinkLayout } from '@/renderer/core/layout/types'
4241

4342
export interface LinkRenderContext {
4443
// Canvas settings
@@ -140,25 +139,6 @@ export class LitegraphLinkAdapter {
140139

141140
// Store path for hit detection
142141
link.path = path
143-
144-
// Register link layout with layout store
145-
if (path && linkData.centerPos) {
146-
const linkLayout: LinkLayout = {
147-
id: String(link.id),
148-
path,
149-
bounds: this.calculateLinkBounds(
150-
linkData.startPoint,
151-
linkData.endPoint,
152-
linkData.controlPoints
153-
),
154-
centerPos: linkData.centerPos,
155-
sourceNodeId: String(link.origin_id),
156-
targetNodeId: String(link.target_id),
157-
sourceSlot: link.origin_slot,
158-
targetSlot: link.target_slot
159-
}
160-
layoutStore.updateLinkLayout(String(link.id), linkLayout)
161-
}
162142
}
163143

164144
/**
@@ -454,25 +434,6 @@ export class LitegraphLinkAdapter {
454434
linkSegment._centreAngle = linkData.centerAngle
455435
}
456436
}
457-
458-
// Register link layout with layout store if this is a real link
459-
if (link && path && linkData.centerPos) {
460-
const linkLayout: LinkLayout = {
461-
id: String(link.id),
462-
path,
463-
bounds: this.calculateLinkBounds(
464-
linkData.startPoint,
465-
linkData.endPoint,
466-
linkData.controlPoints
467-
),
468-
centerPos: linkData.centerPos,
469-
sourceNodeId: String(link.origin_id),
470-
targetNodeId: String(link.target_id),
471-
sourceSlot: link.origin_slot,
472-
targetSlot: link.target_slot
473-
}
474-
layoutStore.updateLinkLayout(String(link.id), linkLayout)
475-
}
476437
}
477438
}
478439

@@ -561,38 +522,4 @@ export class LitegraphLinkAdapter {
561522
// Render using pure renderer
562523
this.pathRenderer.drawDraggingLink(ctx, dragData, pathContext)
563524
}
564-
565-
/**
566-
* Calculate bounding box for a link
567-
*/
568-
private calculateLinkBounds(
569-
startPoint: Point,
570-
endPoint: Point,
571-
controlPoints?: Point[]
572-
): { x: number; y: number; width: number; height: number } {
573-
// Start with endpoints
574-
let minX = Math.min(startPoint.x, endPoint.x)
575-
let maxX = Math.max(startPoint.x, endPoint.x)
576-
let minY = Math.min(startPoint.y, endPoint.y)
577-
let maxY = Math.max(startPoint.y, endPoint.y)
578-
579-
// Include control points if present (for spline links)
580-
if (controlPoints) {
581-
for (const cp of controlPoints) {
582-
minX = Math.min(minX, cp.x)
583-
maxX = Math.max(maxX, cp.x)
584-
minY = Math.min(minY, cp.y)
585-
maxY = Math.max(maxY, cp.y)
586-
}
587-
}
588-
589-
// Add some padding for hit detection
590-
const padding = 10
591-
return {
592-
x: minX - padding,
593-
y: minY - padding,
594-
width: maxX - minX + 2 * padding,
595-
height: maxY - minY + 2 * padding
596-
}
597-
}
598525
}

src/renderer/core/canvas/litegraph/SlotCalculations.ts

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import type {
1313
} from '@/lib/litegraph/src/interfaces'
1414
import { LiteGraph } from '@/lib/litegraph/src/litegraph'
1515
import { isWidgetInputSlot } from '@/lib/litegraph/src/node/slotUtils'
16-
import { layoutStore } from '@/renderer/core/layout/store/LayoutStore'
17-
import type { SlotLayout } from '@/renderer/core/layout/types'
1816

1917
export interface SlotPositionContext {
2018
/** Node's X position in graph coordinates */
@@ -231,60 +229,3 @@ function calculateVueSlotPosition(
231229

232230
return [nodeX + slotCenterX, nodeY + slotCenterY]
233231
}
234-
235-
/**
236-
* Register slot layout with the layout store for hit testing
237-
* @param nodeId The node ID
238-
* @param slotIndex The slot index
239-
* @param isInput Whether this is an input slot
240-
* @param position The slot position in graph coordinates
241-
*/
242-
export function registerSlotLayout(
243-
nodeId: string,
244-
slotIndex: number,
245-
isInput: boolean,
246-
position: Point
247-
): void {
248-
const slotKey = `${nodeId}-${isInput ? 'in' : 'out'}-${slotIndex}`
249-
250-
// Calculate bounds for the slot (20x20 area around center)
251-
const slotSize = 20
252-
const halfSize = slotSize / 2
253-
254-
const slotLayout: SlotLayout = {
255-
nodeId,
256-
index: slotIndex,
257-
type: isInput ? 'input' : 'output',
258-
position: { x: position[0], y: position[1] },
259-
bounds: {
260-
x: position[0] - halfSize,
261-
y: position[1] - halfSize,
262-
width: slotSize,
263-
height: slotSize
264-
}
265-
}
266-
267-
layoutStore.updateSlotLayout(slotKey, slotLayout)
268-
}
269-
270-
/**
271-
* Register all slots for a node
272-
* @param nodeId The node ID
273-
* @param context The slot position context
274-
*/
275-
export function registerNodeSlots(
276-
nodeId: string,
277-
context: SlotPositionContext
278-
): void {
279-
// Register input slots
280-
context.inputs.forEach((_, index) => {
281-
const position = calculateInputSlotPos(context, index)
282-
registerSlotLayout(nodeId, index, true, position)
283-
})
284-
285-
// Register output slots
286-
context.outputs.forEach((_, index) => {
287-
const position = calculateOutputSlotPos(context, index)
288-
registerSlotLayout(nodeId, index, false, position)
289-
})
290-
}

0 commit comments

Comments
 (0)