@maplat/tin 0.11.3 → 0.12.0

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.
package/src/tin.ts CHANGED
@@ -6,8 +6,7 @@
6
6
  import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
7
7
  import turfCentroid from "@turf/centroid";
8
8
  import convex from "@turf/convex";
9
- import { featureCollection, lineString, point, polygon } from "@turf/helpers";
10
- import lineIntersect from "@turf/line-intersect";
9
+ import { featureCollection, point, polygon } from "@turf/helpers";
11
10
  import type { Feature, Point, Position } from "geojson";
12
11
  import {
13
12
  counterTri,
@@ -35,13 +34,18 @@ import type {
35
34
  TinsBD,
36
35
  Tri,
37
36
  VertexMode,
38
- WeightBufferBD,
39
37
  YaxisMode,
40
38
  } from "@maplat/transform";
41
39
  import constrainedTin from "./constrained-tin.ts";
40
+ import {
41
+ calculateBirdeyeVertices,
42
+ calculatePlainVertices,
43
+ } from "./boundary-vertices.ts";
42
44
  import findIntersections from "./kinks.ts";
43
45
  import { insertSearchIndex } from "./searchutils.ts";
44
46
  import { counterPoint, createPoint, vertexCalc } from "./vertexutils.ts";
47
+ import { buildPointsWeightBuffer } from "./weight-buffer.ts";
48
+ import { resolveOverlaps } from "./strict-overlap.ts";
45
49
  import type { SearchIndex } from "./searchutils.ts";
46
50
  import type { PointsSetBD } from "./types/tin.d.ts";
47
51
 
@@ -106,7 +110,8 @@ export class Tin extends Transform {
106
110
  }
107
111
 
108
112
  /**
109
- * 制御点(GCP: Ground Control Points)を設定します
113
+ * 制御点(GCP: Ground Control Points)を設定します。
114
+ * 指定した点群に合わせて内部のTINキャッシュをリセットします。
110
115
  */
111
116
  setPoints(points: PointSet[]): void {
112
117
  if (this.yaxisMode === Tin.YAXIS_FOLLOW) {
@@ -121,7 +126,8 @@ export class Tin extends Transform {
121
126
  }
122
127
 
123
128
  /**
124
- * エッジ(制約線)を設定します
129
+ * エッジ(制約線)を設定します。
130
+ * 制約線を正規化した上で、依存するキャッシュをリセットします。
125
131
  */
126
132
  setEdges(edges: EdgeSet[] | EdgeSetLegacy[] = []): void {
127
133
  this.edges = normalizeEdges(edges);
@@ -278,6 +284,12 @@ export class Tin extends Transform {
278
284
  insertSearchIndex(searchIndex, { forw: forTri, bakw: bakTri });
279
285
  });
280
286
 
287
+ resolveOverlaps(
288
+ this.tins!,
289
+ searchIndex,
290
+ this.pointsSet?.edges || [],
291
+ );
292
+
281
293
  const kinks = ["forw", "bakw"].map((direction) => {
282
294
  const tins = this.tins![direction as keyof TinsBD]!.features.map(
283
295
  (tin: Tri) => tin.geometry!.coordinates[0],
@@ -290,18 +302,16 @@ export class Tin extends Transform {
290
302
  delete this.kinks;
291
303
  } else {
292
304
  this.strict_status = Tin.STATUS_ERROR;
293
- this.kinks = {};
294
- if (kinks[0].length > 0) {
295
- this.kinks.forw = featureCollection(kinks[0]);
296
- }
297
- if (kinks[1].length > 0) {
298
- this.kinks.bakw = featureCollection(kinks[1]);
299
- }
305
+ this.kinks = {
306
+ forw: featureCollection(kinks[0]),
307
+ bakw: featureCollection(kinks[1]),
308
+ };
300
309
  }
301
310
  }
302
311
 
303
312
  /**
304
- * 点群セットを生成します
313
+ * 点群セットを生成します。
314
+ * GCP と中間エッジノードを GeoJSON Point に変換し、後続の三角分割に備えます。
305
315
  */
306
316
  generatePointsSet(): {
307
317
  forw: Feature<Point>[];
@@ -502,7 +512,9 @@ export class Tin extends Transform {
502
512
  }
503
513
 
504
514
  /**
505
- * TINネットワークを更新し、座標変換の準備を行います
515
+ * TINネットワークを同期的に更新し、座標変換の準備を行います。
516
+ * 重めの計算を伴うため、呼び出し側が非同期制御を行いたい場合は
517
+ * {@link updateTinAsync} を利用してください。
506
518
  */
507
519
  updateTin(): void {
508
520
  let strict = this.strictMode;
@@ -585,25 +597,18 @@ export class Tin extends Transform {
585
597
  };
586
598
 
587
599
  // Calculate vertices
600
+ const boundaryParams = {
601
+ convexBuf,
602
+ centroid: centCalc,
603
+ bbox,
604
+ minx,
605
+ maxx,
606
+ miny,
607
+ maxy,
608
+ };
588
609
  const verticesSet = this.vertexMode === Tin.VERTEX_BIRDEYE
589
- ? this.calculateBirdeyeVertices(
590
- convexBuf,
591
- centCalc,
592
- bbox,
593
- minx,
594
- maxx,
595
- miny,
596
- maxy,
597
- )
598
- : this.calculatePlainVertices(
599
- convexBuf,
600
- centCalc,
601
- bbox,
602
- minx,
603
- maxx,
604
- miny,
605
- maxy,
606
- );
610
+ ? calculateBirdeyeVertices(boundaryParams)
611
+ : calculatePlainVertices(boundaryParams);
607
612
 
608
613
  // Add vertices to points set
609
614
  const verticesList = {
@@ -624,7 +629,7 @@ export class Tin extends Transform {
624
629
  this.pointsSet = {
625
630
  forw: featureCollection(rawPointsSet.forw),
626
631
  bakw: featureCollection(rawPointsSet.bakw),
627
- edges: [],
632
+ edges: rawPointsSet.edges,
628
633
  };
629
634
 
630
635
  // Generate forward TIN
@@ -666,362 +671,25 @@ export class Tin extends Transform {
666
671
  };
667
672
 
668
673
  this.addIndexedTin();
669
- this.calculatePointsWeight();
670
- }
671
-
672
- /**
673
- * 通常の頂点を計算
674
- */
675
- private calculatePlainVertices(
676
- convexBuf: Record<string, { forw: Position; bakw: Position }>,
677
- centCalc: { forw: Position; bakw: Position },
678
- bbox: Position[],
679
- minx: number,
680
- maxx: number,
681
- miny: number,
682
- maxy: number,
683
- ): Array<{ forw: Position; bakw: Position }> {
684
- // Calculate edge vertices
685
- const edgeNodes = Object.keys(convexBuf).reduce((prev, key) => {
686
- const item = convexBuf[key];
687
- const forw = item.forw;
688
- const bakw = item.bakw;
689
-
690
- const vec = {
691
- forw: [forw[0] - centCalc.forw[0], forw[1] - centCalc.forw[1]],
692
- bakw: [bakw[0] - centCalc.bakw[0], bakw[1] - centCalc.bakw[1]],
693
- };
694
674
 
695
- const xRate = vec.forw[0] === 0
696
- ? Infinity
697
- : ((vec.forw[0] < 0 ? minx : maxx) - centCalc.forw[0]) / vec.forw[0];
698
- const yRate = vec.forw[1] === 0
699
- ? Infinity
700
- : ((vec.forw[1] < 0 ? miny : maxy) - centCalc.forw[1]) / vec.forw[1];
701
-
702
- if (Math.abs(xRate) / Math.abs(yRate) < 1.1) {
703
- const node = {
704
- forw: [
705
- vec.forw[0] * xRate + centCalc.forw[0],
706
- vec.forw[1] * xRate + centCalc.forw[1],
707
- ] as Position,
708
- bakw: [
709
- vec.bakw[0] * xRate + centCalc.bakw[0],
710
- vec.bakw[1] * xRate + centCalc.bakw[1],
711
- ] as Position,
712
- };
713
- if (vec.forw[0] < 0) {
714
- prev[3].push(node);
715
- } else {
716
- prev[1].push(node);
717
- }
718
- }
719
-
720
- if (Math.abs(yRate) / Math.abs(xRate) < 1.1) {
721
- const node = {
722
- forw: [
723
- vec.forw[0] * yRate + centCalc.forw[0],
724
- vec.forw[1] * yRate + centCalc.forw[1],
725
- ] as Position,
726
- bakw: [
727
- vec.bakw[0] * yRate + centCalc.bakw[0],
728
- vec.bakw[1] * yRate + centCalc.bakw[1],
729
- ] as Position,
730
- };
731
- if (vec.forw[1] < 0) {
732
- prev[0].push(node);
733
- } else {
734
- prev[2].push(node);
735
- }
736
- }
737
-
738
- return prev;
739
- }, [[], [], [], []] as Array<Array<{ forw: Position; bakw: Position }>>);
740
-
741
- // Calculate vertex angles
742
- const vertexCalc = Object.keys(convexBuf).reduce(
743
- (prev, key, index, arr) => {
744
- const item = convexBuf[key];
745
- const forw = item.forw;
746
- const bakw = item.bakw;
747
-
748
- const vec = {
749
- forw: [forw[0] - centCalc.forw[0], forw[1] - centCalc.forw[1]],
750
- bakw: [bakw[0] - centCalc.bakw[0], centCalc.bakw[1] - bakw[1]],
751
- };
752
-
753
- if (vec.forw[0] === 0 || vec.forw[1] === 0) return prev;
754
-
755
- let quad = 0;
756
- if (vec.forw[0] > 0) quad += 1;
757
- if (vec.forw[1] > 0) quad += 2;
758
-
759
- prev[quad].push([vec.forw, vec.bakw]);
760
-
761
- if (index === arr.length - 1) {
762
- return prev.map((quadArr) => {
763
- return quadArr.reduce(
764
- (
765
- qprev: number[] | undefined,
766
- curr: number[][],
767
- qindex: number,
768
- qarr: number[][][],
769
- ) => {
770
- if (!qprev) qprev = [Infinity, 0, 0];
771
-
772
- let ratio =
773
- Math.sqrt(Math.pow(curr[0][0], 2) + Math.pow(curr[0][1], 2)) /
774
- Math.sqrt(Math.pow(curr[1][0], 2) + Math.pow(curr[1][1], 2));
775
- ratio = ratio < qprev[0] ? ratio : qprev[0];
776
-
777
- const theta = Math.atan2(curr[0][0], curr[0][1]) -
778
- Math.atan2(curr[1][0], curr[1][1]);
779
- const sumcos = qprev[1] + Math.cos(theta);
780
- const sumsin = qprev[2] + Math.sin(theta);
781
-
782
- if (qindex === qarr.length - 1) {
783
- return [ratio, Math.atan2(sumsin, sumcos)];
784
- }
785
- return [ratio, sumcos, sumsin];
786
- },
787
- null as any,
788
- );
789
- });
790
- }
791
-
792
- return prev;
793
- },
794
- [[], [], [], []] as any[],
795
- );
796
-
797
- let vertexRatio: any[] = vertexCalc;
798
- if (vertexRatio.length === 1) {
799
- vertexRatio = [
800
- vertexRatio[0],
801
- vertexRatio[0],
802
- vertexRatio[0],
803
- vertexRatio[0],
804
- ];
805
- }
806
-
807
- // Calculate vertices
808
- const vertices = vertexRatio.map((ratio: any, index: number) => {
809
- const forVertex = bbox[index];
810
- const forDelta = [
811
- forVertex[0] - centCalc.forw[0],
812
- forVertex[1] - centCalc.forw[1],
813
- ];
814
- const forDistance = Math.sqrt(
815
- Math.pow(forDelta[0], 2) + Math.pow(forDelta[1], 2),
816
- );
817
- const bakDistance = forDistance / ratio[0];
818
- const bakTheta = Math.atan2(forDelta[0], forDelta[1]) - ratio[1];
819
- const bakw: Position = [
820
- centCalc.bakw[0] + bakDistance * Math.sin(bakTheta),
821
- centCalc.bakw[1] - bakDistance * Math.cos(bakTheta),
822
- ];
823
-
824
- return { forw: forVertex, bakw };
825
- });
826
-
827
- // Swap vertices 2 and 3 for correct ordering
828
- const swap = vertices[2];
829
- vertices[2] = vertices[3];
830
- vertices[3] = swap;
831
-
832
- // Check edge intersections
833
- this.checkAndAdjustVertices(vertices, edgeNodes, centCalc);
834
-
835
- return vertices;
836
- }
837
-
838
- /**
839
- * 鳥瞰図モードの頂点を計算
840
- */
841
- private calculateBirdeyeVertices(
842
- convexBuf: Record<string, { forw: Position; bakw: Position }>,
843
- centCalc: { forw: Position; bakw: Position },
844
- bbox: Position[],
845
- minx: number,
846
- maxx: number,
847
- miny: number,
848
- maxy: number,
849
- ): Array<{ forw: Position; bakw: Position }> {
850
- // For birdeye mode, implement special vertex calculation
851
- // This is a simplified version, actual implementation might be more complex
852
- return this.calculatePlainVertices(
853
- convexBuf,
854
- centCalc,
855
- bbox,
856
- minx,
857
- maxx,
858
- miny,
859
- maxy,
860
- );
861
- }
862
-
863
- /**
864
- * 頂点の位置を調整
865
- */
866
- private checkAndAdjustVertices(
867
- vertices: Array<{ forw: Position; bakw: Position }>,
868
- edgeNodes: Array<Array<{ forw: Position; bakw: Position }>>,
869
- centCalc: { forw: Position; bakw: Position },
870
- ): void {
871
- const expandRatio = [1, 1, 1, 1];
872
-
873
- for (let i = 0; i < 4; i++) {
874
- const j = (i + 1) % 4;
875
- const side = lineString([vertices[i].bakw, vertices[j].bakw]);
876
-
877
- edgeNodes[i].map((node) => {
878
- const line = lineString([centCalc.bakw, node.bakw]);
879
- const intersect = lineIntersect(side, line);
880
-
881
- if (intersect.features.length > 0 && intersect.features[0].geometry) {
882
- const intersectPt = intersect.features[0];
883
- const distance = Math.sqrt(
884
- Math.pow(node.bakw[0] - centCalc.bakw[0], 2) +
885
- Math.pow(node.bakw[1] - centCalc.bakw[1], 2),
886
- );
887
- const intDistance = Math.sqrt(
888
- Math.pow(
889
- intersectPt.geometry.coordinates[0] - centCalc.bakw[0],
890
- 2,
891
- ) +
892
- Math.pow(
893
- intersectPt.geometry.coordinates[1] - centCalc.bakw[1],
894
- 2,
895
- ),
896
- );
897
- const ratio = distance / intDistance;
898
-
899
- if (ratio > expandRatio[i]) expandRatio[i] = ratio;
900
- if (ratio > expandRatio[j]) expandRatio[j] = ratio;
901
- }
902
- });
675
+ const targets: Array<keyof TinsBD> = ["forw"];
676
+ if (this.strict_status === Tin.STATUS_LOOSE) {
677
+ targets.push("bakw");
903
678
  }
904
679
 
905
- vertices.forEach((vertex, i) => {
906
- const ratio = expandRatio[i];
907
- const bakw: Position = [
908
- (vertex.bakw[0] - centCalc.bakw[0]) * ratio + centCalc.bakw[0],
909
- (vertex.bakw[1] - centCalc.bakw[1]) * ratio + centCalc.bakw[1],
910
- ];
911
- vertex.bakw = bakw;
680
+ const includeReciprocals = this.strict_status === Tin.STATUS_STRICT;
681
+ this.pointsWeightBuffer = buildPointsWeightBuffer({
682
+ tins: this.tins!,
683
+ targets,
684
+ includeReciprocals,
912
685
  });
913
686
  }
914
687
 
915
688
  /**
916
- * 点の重み付けを計算します
689
+ * 非同期ラッパーを提供します。
690
+ * 互換性のために Promise ベースの API を維持しますが、内部処理は同期的です。
917
691
  */
918
- calculatePointsWeight(): void {
919
- const calcTargets = ["forw"];
920
- if (this.strict_status === Tin.STATUS_LOOSE) {
921
- calcTargets.push("bakw");
922
- }
923
-
924
- const weightBuffer: WeightBufferBD = {};
925
-
926
- calcTargets.forEach((target) => {
927
- weightBuffer[target as keyof WeightBufferBD] = {};
928
- const tin_points: Record<string, number> = {};
929
-
930
- this.tins![target as keyof TinsBD]!.features.map((tri: Tri) => {
931
- const props = ["a", "b", "c"] as PropertyTriKey[];
932
- for (let i = 0; i < 3; i++) {
933
- const j = (i + 1) % 3;
934
- const prop_i = props[i];
935
- const prop_j = props[j];
936
- const index_i = tri.properties![prop_i].index;
937
- const index_j = tri.properties![prop_j].index;
938
- const key = [index_i, index_j].sort().join("-");
939
-
940
- if (!tin_points[key]) {
941
- const i_xy = tri.geometry!.coordinates[0][i];
942
- const j_xy = tri.geometry!.coordinates[0][j];
943
- const i_merc = tri.properties![prop_i].geom;
944
- const j_merc = tri.properties![prop_j].geom;
945
-
946
- tin_points[key] = 1;
947
- const ratio = Math.sqrt(
948
- Math.pow(i_merc[0] - j_merc[0], 2) +
949
- Math.pow(i_merc[1] - j_merc[1], 2),
950
- ) / Math.sqrt(
951
- Math.pow(i_xy[0] - j_xy[0], 2) + Math.pow(i_xy[1] - j_xy[1], 2),
952
- );
953
-
954
- if (!weightBuffer[target as keyof WeightBufferBD]) {
955
- weightBuffer[target as keyof WeightBufferBD] = {};
956
- }
957
-
958
- const targetBuffer = weightBuffer[target as keyof WeightBufferBD]!;
959
- targetBuffer[`${index_i}:${key}`] = ratio;
960
- targetBuffer[`${index_j}:${key}`] = ratio;
961
- }
962
- }
963
- });
964
- });
965
-
966
- // Calculate average weights
967
- const pointsWeightBuffer: WeightBufferBD = {};
968
-
969
- calcTargets.map((target) => {
970
- pointsWeightBuffer[target as keyof WeightBufferBD] = {};
971
-
972
- if (this.strict_status === Tin.STATUS_STRICT) {
973
- pointsWeightBuffer.bakw = {};
974
- }
975
-
976
- const targetBuffer = weightBuffer[target as keyof WeightBufferBD]!;
977
- const pointWeights: { [pointId: string]: number[] } = {};
978
-
979
- // Group weights by point ID
980
- Object.keys(targetBuffer).forEach((key) => {
981
- const [pointId] = key.split(":");
982
- if (!pointWeights[pointId]) {
983
- pointWeights[pointId] = [];
984
- }
985
- pointWeights[pointId].push(targetBuffer[key]);
986
- });
987
-
988
- // Calculate average weight for each point
989
- Object.keys(pointWeights).forEach((pointId) => {
990
- const weights = pointWeights[pointId];
991
- const avgWeight = weights.reduce((sum, w) => sum + w, 0) /
992
- weights.length;
993
-
994
- if (!pointsWeightBuffer[target as keyof WeightBufferBD]) {
995
- pointsWeightBuffer[target as keyof WeightBufferBD] = {};
996
- }
997
- pointsWeightBuffer[target as keyof WeightBufferBD]![pointId] =
998
- avgWeight;
999
-
1000
- if (this.strict_status === Tin.STATUS_STRICT) {
1001
- if (!pointsWeightBuffer.bakw) {
1002
- pointsWeightBuffer.bakw = {};
1003
- }
1004
- pointsWeightBuffer.bakw[pointId] = 1 / avgWeight;
1005
- }
1006
- });
1007
-
1008
- // Calculate centroid weight
1009
- let centroidSum = 0;
1010
- for (let i = 0; i < 4; i++) {
1011
- const key = `b${i}`;
1012
- const weight =
1013
- pointsWeightBuffer[target as keyof WeightBufferBD]![key] || 0;
1014
- centroidSum += weight;
1015
- }
1016
- pointsWeightBuffer[target as keyof WeightBufferBD]!["c"] = centroidSum /
1017
- 4;
1018
-
1019
- if (this.strict_status === Tin.STATUS_STRICT && pointsWeightBuffer.bakw) {
1020
- pointsWeightBuffer.bakw["c"] = 1 /
1021
- pointsWeightBuffer[target as keyof WeightBufferBD]!["c"];
1022
- }
1023
- });
1024
-
1025
- this.pointsWeightBuffer = pointsWeightBuffer;
692
+ async updateTinAsync(): Promise<void> {
693
+ this.updateTin();
1026
694
  }
1027
695
  }
@@ -0,0 +1,111 @@
1
+ import type {
2
+ PropertyTriKey,
3
+ TinsBD,
4
+ Tri,
5
+ WeightBufferBD,
6
+ } from "@maplat/transform";
7
+
8
+ interface WeightBufferOptions {
9
+ tins: TinsBD;
10
+ targets: Array<keyof TinsBD>;
11
+ includeReciprocals: boolean;
12
+ }
13
+
14
+ /**
15
+ * Calculate per-point stretch ratios used for non-linear interpolation.
16
+ */
17
+ export function buildPointsWeightBuffer(
18
+ options: WeightBufferOptions,
19
+ ): WeightBufferBD {
20
+ const { tins, targets, includeReciprocals } = options;
21
+ const edgeRatios: WeightBufferBD = {};
22
+
23
+ targets.forEach((target) => {
24
+ const triCollection = tins[target];
25
+ if (!triCollection || !triCollection.features) return;
26
+
27
+ edgeRatios[target as keyof WeightBufferBD] = {};
28
+ const seenEdges: Record<string, boolean> = {};
29
+
30
+ triCollection.features.forEach((tri: Tri) => {
31
+ const props = ["a", "b", "c"] as PropertyTriKey[];
32
+ for (let i = 0; i < 3; i++) {
33
+ const j = (i + 1) % 3;
34
+ const prop_i = props[i];
35
+ const prop_j = props[j];
36
+ const index_i = tri.properties![prop_i].index;
37
+ const index_j = tri.properties![prop_j].index;
38
+ const key = [index_i, index_j].sort().join("-");
39
+
40
+ if (seenEdges[key]) continue;
41
+ seenEdges[key] = true;
42
+
43
+ const i_xy = tri.geometry!.coordinates[0][i];
44
+ const j_xy = tri.geometry!.coordinates[0][j];
45
+ const i_merc = tri.properties![prop_i].geom;
46
+ const j_merc = tri.properties![prop_j].geom;
47
+
48
+ const ratio = Math.sqrt(
49
+ Math.pow(i_merc[0] - j_merc[0], 2) +
50
+ Math.pow(i_merc[1] - j_merc[1], 2),
51
+ ) / Math.sqrt(
52
+ Math.pow(i_xy[0] - j_xy[0], 2) + Math.pow(i_xy[1] - j_xy[1], 2),
53
+ );
54
+
55
+ const targetBuffer = edgeRatios[target as keyof WeightBufferBD]!;
56
+ targetBuffer[`${index_i}:${key}`] = ratio;
57
+ targetBuffer[`${index_j}:${key}`] = ratio;
58
+ }
59
+ });
60
+ });
61
+
62
+ const pointsWeightBuffer: WeightBufferBD = {};
63
+ if (includeReciprocals) {
64
+ pointsWeightBuffer.bakw = {};
65
+ }
66
+
67
+ targets.forEach((target) => {
68
+ const targetBuffer = edgeRatios[target as keyof WeightBufferBD];
69
+ pointsWeightBuffer[target as keyof WeightBufferBD] = {};
70
+
71
+ if (!targetBuffer) {
72
+ return;
73
+ }
74
+
75
+ const pointWeights: Record<string, number[]> = {};
76
+ Object.keys(targetBuffer).forEach((key) => {
77
+ const [pointId] = key.split(":");
78
+ if (!pointWeights[pointId]) {
79
+ pointWeights[pointId] = [];
80
+ }
81
+ pointWeights[pointId].push(targetBuffer[key]);
82
+ });
83
+
84
+ Object.keys(pointWeights).forEach((pointId) => {
85
+ const weights = pointWeights[pointId];
86
+ const avgWeight = weights.reduce((sum, w) => sum + w, 0) / weights.length;
87
+
88
+ pointsWeightBuffer[target as keyof WeightBufferBD]![pointId] = avgWeight;
89
+
90
+ if (includeReciprocals && pointsWeightBuffer.bakw) {
91
+ pointsWeightBuffer.bakw[pointId] = 1 / avgWeight;
92
+ }
93
+ });
94
+
95
+ let centroidSum = 0;
96
+ for (let i = 0; i < 4; i++) {
97
+ const key = `b${i}`;
98
+ const weight =
99
+ pointsWeightBuffer[target as keyof WeightBufferBD]![key] || 0;
100
+ centroidSum += weight;
101
+ }
102
+ pointsWeightBuffer[target as keyof WeightBufferBD]!["c"] = centroidSum / 4;
103
+
104
+ if (includeReciprocals && pointsWeightBuffer.bakw) {
105
+ pointsWeightBuffer.bakw["c"] = 1 /
106
+ pointsWeightBuffer[target as keyof WeightBufferBD]!["c"];
107
+ }
108
+ });
109
+
110
+ return pointsWeightBuffer;
111
+ }