@code3d/core 0.0.1-alpha.7 → 0.0.1-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -119,7 +119,7 @@ function openShell(
119
119
  return {
120
120
  shape: result,
121
121
  topology: transferShapeTopology(
122
- [{shape, topology, index: 1}],
122
+ [{shape, topology, namespace: 'preserve'}],
123
123
  result,
124
124
  builder,
125
125
  ),
@@ -202,12 +202,12 @@ function closedShell(
202
202
  } finally {
203
203
  shells.delete();
204
204
  }
205
- // Original boundaries retain their input paths for either direction. Offset
205
+ // Original boundaries retain their IDs for either direction. Offset
206
206
  // boundaries are new topology, even when OCCT has generation history.
207
207
  return {
208
208
  shape: result,
209
209
  topology: transferShapeTopology(
210
- [{shape, topology, index: 1}],
210
+ [{shape, topology, namespace: 'preserve'}],
211
211
  result,
212
212
  cut,
213
213
  ),
@@ -107,6 +107,8 @@ function topologyShapes(shape: AnyShape, kind: TopologyKind): AnyShape[] {
107
107
  type StableTopology = Readonly<{
108
108
  /** IDs aligned with the corresponding shape traversal order. */
109
109
  ids: readonly TopologyId[];
110
+ /** Next local ID; retained across edits so retired IDs cannot be reused. */
111
+ nextId: number;
110
112
  }>;
111
113
 
112
114
  export type VertexTopology = StableTopology;
@@ -519,7 +521,7 @@ function modifyEdges(
519
521
  return {
520
522
  shape: result,
521
523
  topology: transferShapeTopology(
522
- [{shape, topology: source, index: 1}],
524
+ [{shape, topology: source, namespace: 'preserve'}],
523
525
  result,
524
526
  builder,
525
527
  ),
@@ -616,8 +618,8 @@ export function assertTopologyId(kind: TopologyKind, id: TopologyId): void {
616
618
  export type TopologyInput = Readonly<{
617
619
  shape: AnyShape;
618
620
  topology: ShapeTopology;
619
- /** Omitted only for intermediate results inside a single operation. */
620
- index?: number;
621
+ /** Input prefix, unchanged namespace for edits, or an internal operation step. */
622
+ namespace: number | 'preserve' | 'intermediate';
621
623
  }>;
622
624
 
623
625
  /** Returns owned handles, released by the transfer after matching. */
@@ -636,23 +638,26 @@ export function transferShapeTopology(
636
638
  const transfer = (kind: TopologyKind): StableTopology => {
637
639
  const originals: AnyShape[][] = [];
638
640
  const results = topologyShapes(output, kind);
641
+ let nextId = 1;
639
642
  try {
640
643
  const candidates = inputs.flatMap((input, inputIndex) => {
641
644
  const shapes = topologyShapes(input.shape, kind);
642
645
  originals.push(shapes);
643
646
  const source = input.topology[topologyMetadata[kind].plural];
644
647
  assertTopologyLength(kind, shapes, source);
648
+ if (input.namespace === 'preserve')
649
+ nextId = Math.max(nextId, source.nextId);
645
650
  return shapes.map((shape, index) => {
646
651
  const id = source.ids[index];
647
652
  // Numeric elements in an internal prefix are still new to this
648
653
  // operation. Reallocate them with the final traversal, without exposing
649
654
  // internal creation steps or reserving numbers for discarded geometry.
650
655
  const inherited =
651
- input.index !== undefined
652
- ? inheritedTopologyId(input.index, id)
653
- : typeof id === 'number'
654
- ? undefined
655
- : id;
656
+ typeof input.namespace === 'number'
657
+ ? inheritedTopologyId(input.namespace, id)
658
+ : input.namespace === 'preserve' || typeof id !== 'number'
659
+ ? id
660
+ : undefined;
656
661
  const unchanged = matchingOutputShapes(shape.wrapped, results);
657
662
  if (unchanged.length) return {id: inherited, matches: unchanged};
658
663
  if (typeof history !== 'function') {
@@ -693,10 +698,8 @@ export function transferShapeTopology(
693
698
  inherited.set(index, candidate.id);
694
699
  }
695
700
  }
696
- let nextId = 1;
697
- return stableTopology(
698
- results.map((_, index) => inherited.get(index) ?? nextId++),
699
- );
701
+ const ids = results.map((_, index) => inherited.get(index) ?? nextId++);
702
+ return stableTopology(ids, nextId);
700
703
  } finally {
701
704
  originals.forEach(deleteShapes);
702
705
  deleteShapes(results);
@@ -769,11 +772,17 @@ function stableGroupIds(
769
772
  function initialTopology(
770
773
  shapes: readonly (ReplicadVertex | ReplicadEdge | ReplicadFace)[],
771
774
  ): StableTopology {
772
- return stableTopology(shapes.map((_, index) => index + 1));
775
+ return stableTopology(
776
+ shapes.map((_, index) => index + 1),
777
+ shapes.length + 1,
778
+ );
773
779
  }
774
780
 
775
- function stableTopology(ids: readonly TopologyId[]): StableTopology {
776
- return {ids};
781
+ function stableTopology(
782
+ ids: readonly TopologyId[],
783
+ nextId: number,
784
+ ): StableTopology {
785
+ return {ids, nextId};
777
786
  }
778
787
 
779
788
  function shapeTopology(
@@ -101,6 +101,7 @@ export type {
101
101
  RelationTraceReference,
102
102
  ElementKind,
103
103
  ElementSnapshot,
104
+ DistanceSnapshot,
104
105
  ModelElementReference,
105
106
  ModelGeometryKind,
106
107
  ModelGeometrySnapshot,