MCPcopy Create free account
hub / github.com/openclaw/gogcli / buildCopySegments

Function buildCopySegments

internal/sheetsvalidation/copy.go:334–457  ·  view source on GitHub ↗
(
	source, destination *sheets.GridRange,
	transpose bool,
	spans []Span,
)

Source from the content-addressed store, hash-verified

332}
333
334func buildCopySegments(
335 source, destination *sheets.GridRange,
336 transpose bool,
337 spans []Span,
338) ([]copySegment, error) {
339 sourceHeight := source.EndRowIndex - source.StartRowIndex
340 sourceWidth := source.EndColumnIndex - source.StartColumnIndex
341
342 patternHeight, patternWidth := sourceHeight, sourceWidth
343 if transpose {
344 patternHeight, patternWidth = sourceWidth, sourceHeight
345 }
346 rowTiles := (destination.EndRowIndex - destination.StartRowIndex) / patternHeight
347 colTiles := (destination.EndColumnIndex - destination.StartColumnIndex) / patternWidth
348
349 patternSegments := make([]copySegment, 0, len(spans))
350 for _, span := range spans {
351 ruleKey, err := ruleKeyForValidation(span.Rule)
352 if err != nil {
353 return nil, err
354 }
355
356 patternSegments = append(patternSegments, copySegment{
357 StartRow: span.StartRow,
358 EndRow: span.EndRow,
359 StartCol: span.StartCol,
360 EndCol: span.EndCol,
361 RuleKey: ruleKey,
362 Rule: span.Rule,
363 })
364 }
365 patternSegments = mergeCopySegments(patternSegments)
366
367 segments := make([]copySegment, 0, len(patternSegments))
368 var err error
369
370 for _, patternSegment := range patternSegments {
371 relRowStart := patternSegment.StartRow - source.StartRowIndex
372 relRowEnd := patternSegment.EndRow - source.StartRowIndex
373 relColStart := patternSegment.StartCol - source.StartColumnIndex
374 relColEnd := patternSegment.EndCol - source.StartColumnIndex
375 mappedRowStart, mappedRowEnd := relRowStart, relRowEnd
376
377 mappedColStart, mappedColEnd := relColStart, relColEnd
378 if transpose {
379 mappedRowStart, mappedRowEnd = relColStart, relColEnd
380 mappedColStart, mappedColEnd = relRowStart, relRowEnd
381 }
382 fullRows := mappedRowStart == 0 && mappedRowEnd == patternHeight
383
384 fullCols := mappedColStart == 0 && mappedColEnd == patternWidth
385 if fullRows && fullCols {
386 segments, err = appendCopySegment(segments, copySegment{
387 StartRow: destination.StartRowIndex,
388 EndRow: destination.EndRowIndex,
389 StartCol: destination.StartColumnIndex,
390 EndCol: destination.EndColumnIndex,
391 RuleKey: patternSegment.RuleKey,

Callers 1

BuildCopyRequestsFunction · 0.85

Calls 3

ruleKeyForValidationFunction · 0.85
mergeCopySegmentsFunction · 0.85
appendCopySegmentFunction · 0.85

Tested by

no test coverage detected