@itwin/core-geometry 4.4.0-dev.2 → 4.4.0-dev.21
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/CHANGELOG.md +21 -1
- package/lib/cjs/geometry3d/YawPitchRollAngles.d.ts +7 -5
- package/lib/cjs/geometry3d/YawPitchRollAngles.d.ts.map +1 -1
- package/lib/cjs/geometry3d/YawPitchRollAngles.js +8 -6
- package/lib/cjs/geometry3d/YawPitchRollAngles.js.map +1 -1
- package/lib/cjs/serialization/GeometrySamples.d.ts +11 -0
- package/lib/cjs/serialization/GeometrySamples.d.ts.map +1 -1
- package/lib/cjs/serialization/GeometrySamples.js +16 -0
- package/lib/cjs/serialization/GeometrySamples.js.map +1 -1
- package/lib/cjs/topology/Graph.d.ts +18 -10
- package/lib/cjs/topology/Graph.d.ts.map +1 -1
- package/lib/cjs/topology/Graph.js +20 -10
- package/lib/cjs/topology/Graph.js.map +1 -1
- package/lib/cjs/topology/HalfEdgeGraphSearch.d.ts +81 -76
- package/lib/cjs/topology/HalfEdgeGraphSearch.d.ts.map +1 -1
- package/lib/cjs/topology/HalfEdgeGraphSearch.js +126 -111
- package/lib/cjs/topology/HalfEdgeGraphSearch.js.map +1 -1
- package/lib/cjs/topology/HalfEdgeGraphValidation.d.ts +23 -18
- package/lib/cjs/topology/HalfEdgeGraphValidation.d.ts.map +1 -1
- package/lib/cjs/topology/HalfEdgeGraphValidation.js +23 -18
- package/lib/cjs/topology/HalfEdgeGraphValidation.js.map +1 -1
- package/lib/cjs/topology/HalfEdgeNodeXYZUV.d.ts +17 -10
- package/lib/cjs/topology/HalfEdgeNodeXYZUV.d.ts.map +1 -1
- package/lib/cjs/topology/HalfEdgeNodeXYZUV.js +38 -17
- package/lib/cjs/topology/HalfEdgeNodeXYZUV.js.map +1 -1
- package/lib/cjs/topology/SignedDataSummary.d.ts +13 -13
- package/lib/cjs/topology/SignedDataSummary.d.ts.map +1 -1
- package/lib/cjs/topology/SignedDataSummary.js +3 -3
- package/lib/cjs/topology/SignedDataSummary.js.map +1 -1
- package/lib/cjs/topology/XYParitySearchContext.d.ts +27 -21
- package/lib/cjs/topology/XYParitySearchContext.d.ts.map +1 -1
- package/lib/cjs/topology/XYParitySearchContext.js +73 -71
- package/lib/cjs/topology/XYParitySearchContext.js.map +1 -1
- package/lib/esm/geometry3d/YawPitchRollAngles.d.ts +7 -5
- package/lib/esm/geometry3d/YawPitchRollAngles.d.ts.map +1 -1
- package/lib/esm/geometry3d/YawPitchRollAngles.js +8 -6
- package/lib/esm/geometry3d/YawPitchRollAngles.js.map +1 -1
- package/lib/esm/serialization/GeometrySamples.d.ts +11 -0
- package/lib/esm/serialization/GeometrySamples.d.ts.map +1 -1
- package/lib/esm/serialization/GeometrySamples.js +16 -0
- package/lib/esm/serialization/GeometrySamples.js.map +1 -1
- package/lib/esm/topology/Graph.d.ts +18 -10
- package/lib/esm/topology/Graph.d.ts.map +1 -1
- package/lib/esm/topology/Graph.js +20 -10
- package/lib/esm/topology/Graph.js.map +1 -1
- package/lib/esm/topology/HalfEdgeGraphSearch.d.ts +81 -76
- package/lib/esm/topology/HalfEdgeGraphSearch.d.ts.map +1 -1
- package/lib/esm/topology/HalfEdgeGraphSearch.js +126 -111
- package/lib/esm/topology/HalfEdgeGraphSearch.js.map +1 -1
- package/lib/esm/topology/HalfEdgeGraphValidation.d.ts +23 -18
- package/lib/esm/topology/HalfEdgeGraphValidation.d.ts.map +1 -1
- package/lib/esm/topology/HalfEdgeGraphValidation.js +23 -18
- package/lib/esm/topology/HalfEdgeGraphValidation.js.map +1 -1
- package/lib/esm/topology/HalfEdgeNodeXYZUV.d.ts +17 -10
- package/lib/esm/topology/HalfEdgeNodeXYZUV.d.ts.map +1 -1
- package/lib/esm/topology/HalfEdgeNodeXYZUV.js +38 -17
- package/lib/esm/topology/HalfEdgeNodeXYZUV.js.map +1 -1
- package/lib/esm/topology/SignedDataSummary.d.ts +13 -13
- package/lib/esm/topology/SignedDataSummary.d.ts.map +1 -1
- package/lib/esm/topology/SignedDataSummary.js +3 -3
- package/lib/esm/topology/SignedDataSummary.js.map +1 -1
- package/lib/esm/topology/XYParitySearchContext.d.ts +27 -21
- package/lib/esm/topology/XYParitySearchContext.d.ts.map +1 -1
- package/lib/esm/topology/XYParitySearchContext.js +73 -71
- package/lib/esm/topology/XYParitySearchContext.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignedDataSummary.js","sourceRoot":"","sources":["../../../src/topology/SignedDataSummary.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AACH;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAuB5B
|
|
1
|
+
{"version":3,"file":"SignedDataSummary.js","sourceRoot":"","sources":["../../../src/topology/SignedDataSummary.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AACH;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAuB5B,gDAAgD;IAChD,YAAmB,YAAqB;QACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;QACzD,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,GAAG,GAAG,CAAC;QAC5D,IAAI,YAAY,EAAE;YAChB,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;YAC5B,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;YAC5B,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;SACzB;IACH,CAAC;IACD,8CAA8C;IACvC,YAAY,CAAC,IAAO,EAAE,IAAY;QACvC,IAAI,IAAI,GAAG,CAAC,EAAE;YACZ,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC;YACzB,IAAI,IAAI,CAAC,iBAAiB;gBACxB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACpC,IAAI,IAAI,GAAG,IAAI,CAAC,oBAAoB,EAAE;gBACpC,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;gBACjC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;aACjC;SACF;aAAM,IAAI,IAAI,GAAG,CAAC,EAAE;YACnB,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC;YACzB,IAAI,IAAI,CAAC,iBAAiB;gBACxB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACpC,IAAI,IAAI,GAAG,IAAI,CAAC,oBAAoB,EAAE;gBACpC,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;gBACjC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;aACjC;SACF;aAAM;YACL,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,IAAI,IAAI,CAAC,aAAa;gBACpB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACjC;IACH,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module Topology\r\n */\r\n/**\r\n * Class to accumulate statistics about a stream of signed numbers with tag items.\r\n * * All sums, counts, extrema, and item values are initialized to zero in the constructor.\r\n * * Each call to `announceItem(item, value)` updates the various sums, counts, and extrema.\r\n */\r\nexport class SignedDataSummary<T> {\r\n /** Sum of all positive area items. */\r\n public positiveSum: number;\r\n /** Number of positive area items. */\r\n public numPositive: number;\r\n /** Sum of negative area items. */\r\n public negativeSum: number;\r\n /** Number of negative area items. */\r\n public numNegative: number;\r\n /** Number of zero area items. */\r\n public numZero: number;\r\n /** The tag item item with the largest positive data. */\r\n public largestPositiveItem?: T;\r\n /** The tag item item with the most negative data. */\r\n public largestNegativeItem?: T;\r\n public largestPositiveValue: number;\r\n public largestNegativeValue: number;\r\n /** Array of all negative area items. */\r\n public negativeItemArray?: T[];\r\n /** Array of zero area items. */\r\n public zeroItemArray?: T[];\r\n /** Array of positive area items. */\r\n public positiveItemArray?: T[];\r\n /** Setup with zero sums and optional arrays. */\r\n public constructor(createArrays: boolean) {\r\n this.positiveSum = this.negativeSum = 0.0;\r\n this.numPositive = this.numNegative = this.numZero = 0.0;\r\n this.largestPositiveValue = this.largestNegativeValue = 0.0;\r\n if (createArrays) {\r\n this.negativeItemArray = [];\r\n this.positiveItemArray = [];\r\n this.zeroItemArray = [];\r\n }\r\n }\r\n /** Update with an item and its data value. */\r\n public announceItem(item: T, data: number) {\r\n if (data < 0) {\r\n this.numNegative++;\r\n this.negativeSum += data;\r\n if (this.negativeItemArray)\r\n this.negativeItemArray.push(item);\r\n if (data < this.largestNegativeValue) {\r\n this.largestNegativeValue = data;\r\n this.largestNegativeItem = item;\r\n }\r\n } else if (data > 0) {\r\n this.numPositive++;\r\n this.positiveSum += data;\r\n if (this.positiveItemArray)\r\n this.positiveItemArray.push(item);\r\n if (data > this.largestPositiveValue) {\r\n this.largestPositiveValue = data;\r\n this.largestPositiveItem = item;\r\n }\r\n } else {\r\n this.numZero++;\r\n if (this.zeroItemArray)\r\n this.zeroItemArray.push(item);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -2,52 +2,58 @@
|
|
|
2
2
|
* @module Topology
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* `XYParitySearchContext` is an internal class for callers that can feed points (without extracting to array structures)
|
|
6
6
|
* * Most will be via static methods which handle a specific data source.
|
|
7
|
-
* * PolygonOps.classifyPointInPolygon
|
|
8
|
-
* * HalfEdgeGraphSearch.pointInOrOnFaceXY
|
|
7
|
+
* * PolygonOps.classifyPointInPolygon(x,y,points: XAndY[])
|
|
8
|
+
* * HalfEdgeGraphSearch.pointInOrOnFaceXY(halfEdgeOnFace, x, y)
|
|
9
9
|
* Use pattern:
|
|
10
|
-
* * Caller must be able walk around polygon producing x,y coordinates (possibly transformed from actual polygon)
|
|
10
|
+
* * Caller must be able to walk around polygon producing x,y coordinates (possibly transformed from actual polygon).
|
|
11
11
|
* * Caller announce edges to tryStartEdge until finding one acceptable to the search.
|
|
12
12
|
* * Caller then passes additional points up to and including both x0,y0 and x1, y1 of the accepted start edge.
|
|
13
13
|
* Call sequence is:
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* * `context = new XYParitySearchContext`
|
|
15
|
+
* * `repeat { acquire edge (x0,y0) (x1,y1) } until context.tryStartEdge(x0,y0,x1,y1);`
|
|
16
|
+
* * `for each (x,y) beginning AFTER x1,y1 and ending with (x1,y1) context.advance (x,y)`
|
|
17
|
+
* * `return context.classifyCounts();`
|
|
18
18
|
*/
|
|
19
19
|
export declare class XYParitySearchContext {
|
|
20
20
|
xTest: number;
|
|
21
21
|
yTest: number;
|
|
22
|
+
/** local x-coordinate of the start of the previous (or earlier) edge */
|
|
22
23
|
u0: number;
|
|
24
|
+
/** local y-coordinate of the start of the previous (or earlier) edge */
|
|
23
25
|
v0: number;
|
|
26
|
+
/** local x-coordinate of the end of the previous edge (and start of current edge) */
|
|
24
27
|
u1: number;
|
|
28
|
+
/** local y-coordinate of the end of the previous edge (and start of current edge) */
|
|
25
29
|
v1: number;
|
|
26
30
|
numLeftCrossing: number;
|
|
27
31
|
numRightCrossing: number;
|
|
28
32
|
numHit: number;
|
|
29
33
|
/**
|
|
30
34
|
* Create a new searcher for specified test point.
|
|
31
|
-
* @param xTest x coordinate of test point
|
|
32
|
-
* @param yTest y coordinate of test point
|
|
35
|
+
* @param xTest x coordinate of test point.
|
|
36
|
+
* @param yTest y coordinate of test point.
|
|
33
37
|
*/
|
|
34
38
|
constructor(xTest: number, yTest: number);
|
|
35
|
-
/**
|
|
36
|
-
* test if x,y is a safe first coordinate to start the search.
|
|
37
|
-
* * safe start must have non-zero y so that final point test (return to x0,y0) does not need look back for exact crossing logic.
|
|
38
|
-
* @param x
|
|
39
|
-
* @param y
|
|
40
|
-
*/
|
|
39
|
+
/** Test if parity processing can begin with this edge. */
|
|
41
40
|
tryStartEdge(x0: number, y0: number, x1: number, y1: number): boolean;
|
|
42
|
-
/**
|
|
43
|
-
|
|
41
|
+
/** Update local coordinates: the current edge becomes the previous edge. */
|
|
42
|
+
private updateUV01;
|
|
43
|
+
/**
|
|
44
|
+
* Process the current edge ending at (x2,y2).
|
|
45
|
+
* * Accumulate left/right parity of the test point wrt to the polygon. These counts track the number of polygon crossings
|
|
46
|
+
* of the left and right horizontal rays emanating from the test point. After all edges are processed, if either count is
|
|
47
|
+
* odd/even, the test point is inside/outside the polygon (see [[classifyCounts]]).
|
|
48
|
+
* * Check whether the test point lies on the edge.
|
|
49
|
+
* @returns whether caller should continue processing with the next edge. In particular, `false` if we have an exact hit.
|
|
44
50
|
*/
|
|
45
|
-
advance(
|
|
51
|
+
advance(x2: number, y2: number): boolean;
|
|
46
52
|
/**
|
|
47
53
|
* Return classification as ON, IN, or OUT according to hit and crossing counts.
|
|
48
|
-
* * Any nonzero hit count is ON
|
|
54
|
+
* * Any nonzero hit count is ON.
|
|
49
55
|
* * Otherwise IN if left crossing count is odd.
|
|
50
|
-
* @return 0 if ON, 1 if IN, -1 if OUT
|
|
56
|
+
* @return 0 if ON, 1 if IN, -1 if OUT.
|
|
51
57
|
*/
|
|
52
58
|
classifyCounts(): number | undefined;
|
|
53
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XYParitySearchContext.d.ts","sourceRoot":"","sources":["../../../src/topology/XYParitySearchContext.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;;;;;;;;;;;;;GAcG;AACH,qBAAa,qBAAqB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"XYParitySearchContext.d.ts","sourceRoot":"","sources":["../../../src/topology/XYParitySearchContext.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;;;;;;;;;;;;;GAcG;AACH,qBAAa,qBAAqB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACjE,EAAE,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACjE,EAAE,EAAE,MAAM,CAAC;IAClB,qFAAqF;IAC9E,EAAE,EAAE,MAAM,CAAC;IAClB,qFAAqF;IAC9E,EAAE,EAAE,MAAM,CAAC;IACX,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACtB;;;;OAIG;gBACgB,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAO/C,0DAA0D;IACnD,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO;IAU5E,4EAA4E;IAC5E,OAAO,CAAC,UAAU;IAOlB;;;;;;;OAOG;IACI,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO;IAgE/C;;;;;OAKG;IACI,cAAc,IAAI,MAAM,GAAG,SAAS;CAM5C"}
|
|
@@ -6,127 +6,129 @@
|
|
|
6
6
|
* @module Topology
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* `XYParitySearchContext` is an internal class for callers that can feed points (without extracting to array structures)
|
|
10
10
|
* * Most will be via static methods which handle a specific data source.
|
|
11
|
-
* * PolygonOps.classifyPointInPolygon
|
|
12
|
-
* * HalfEdgeGraphSearch.pointInOrOnFaceXY
|
|
11
|
+
* * PolygonOps.classifyPointInPolygon(x,y,points: XAndY[])
|
|
12
|
+
* * HalfEdgeGraphSearch.pointInOrOnFaceXY(halfEdgeOnFace, x, y)
|
|
13
13
|
* Use pattern:
|
|
14
|
-
* * Caller must be able walk around polygon producing x,y coordinates (possibly transformed from actual polygon)
|
|
14
|
+
* * Caller must be able to walk around polygon producing x,y coordinates (possibly transformed from actual polygon).
|
|
15
15
|
* * Caller announce edges to tryStartEdge until finding one acceptable to the search.
|
|
16
16
|
* * Caller then passes additional points up to and including both x0,y0 and x1, y1 of the accepted start edge.
|
|
17
17
|
* Call sequence is:
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* * `context = new XYParitySearchContext`
|
|
19
|
+
* * `repeat { acquire edge (x0,y0) (x1,y1) } until context.tryStartEdge(x0,y0,x1,y1);`
|
|
20
|
+
* * `for each (x,y) beginning AFTER x1,y1 and ending with (x1,y1) context.advance (x,y)`
|
|
21
|
+
* * `return context.classifyCounts();`
|
|
22
22
|
*/
|
|
23
23
|
export class XYParitySearchContext {
|
|
24
24
|
/**
|
|
25
25
|
* Create a new searcher for specified test point.
|
|
26
|
-
* @param xTest x coordinate of test point
|
|
27
|
-
* @param yTest y coordinate of test point
|
|
26
|
+
* @param xTest x coordinate of test point.
|
|
27
|
+
* @param yTest y coordinate of test point.
|
|
28
28
|
*/
|
|
29
29
|
constructor(xTest, yTest) {
|
|
30
30
|
this.xTest = xTest;
|
|
31
31
|
this.yTest = yTest;
|
|
32
|
-
this.u0 = this.v0 = this.u1 = this.v1 = 0; //
|
|
32
|
+
this.u0 = this.v0 = this.u1 = this.v1 = 0; // not valid for search; caller must satisfy tryStartEdge
|
|
33
33
|
this.numLeftCrossing = this.numRightCrossing = 0;
|
|
34
34
|
this.numHit = 0;
|
|
35
35
|
}
|
|
36
|
-
/**
|
|
37
|
-
* test if x,y is a safe first coordinate to start the search.
|
|
38
|
-
* * safe start must have non-zero y so that final point test (return to x0,y0) does not need look back for exact crossing logic.
|
|
39
|
-
* @param x
|
|
40
|
-
* @param y
|
|
41
|
-
*/
|
|
36
|
+
/** Test if parity processing can begin with this edge. */
|
|
42
37
|
tryStartEdge(x0, y0, x1, y1) {
|
|
43
38
|
if (y0 !== this.yTest) {
|
|
44
39
|
this.u0 = x0 - this.xTest;
|
|
45
40
|
this.v0 = y0 - this.yTest;
|
|
46
41
|
this.u1 = x1 - this.xTest;
|
|
47
42
|
this.v1 = y1 - this.yTest;
|
|
48
|
-
return true;
|
|
43
|
+
return true; // we won't need wraparound logic to process the final edge ending at (x0,y0)
|
|
49
44
|
}
|
|
50
45
|
return false;
|
|
51
46
|
}
|
|
52
|
-
/**
|
|
53
|
-
|
|
47
|
+
/** Update local coordinates: the current edge becomes the previous edge. */
|
|
48
|
+
updateUV01(u2, v2) {
|
|
49
|
+
this.u0 = this.u1;
|
|
50
|
+
this.v0 = this.v1;
|
|
51
|
+
this.u1 = u2;
|
|
52
|
+
this.v1 = v2;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Process the current edge ending at (x2,y2).
|
|
57
|
+
* * Accumulate left/right parity of the test point wrt to the polygon. These counts track the number of polygon crossings
|
|
58
|
+
* of the left and right horizontal rays emanating from the test point. After all edges are processed, if either count is
|
|
59
|
+
* odd/even, the test point is inside/outside the polygon (see [[classifyCounts]]).
|
|
60
|
+
* * Check whether the test point lies on the edge.
|
|
61
|
+
* @returns whether caller should continue processing with the next edge. In particular, `false` if we have an exact hit.
|
|
54
62
|
*/
|
|
55
|
-
advance(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
advance(x2, y2) {
|
|
64
|
+
// In this method we use local u,v coordinates obtained by translating the test point to the origin.
|
|
65
|
+
// This simplifies our computations:
|
|
66
|
+
// * left (right) parity is incremented if the current edge crosses the u-axis at u<0 (u>0)
|
|
67
|
+
// * we have an exact hit if the current edge crosses the u-axis at u=0
|
|
68
|
+
const u2 = x2 - this.xTest;
|
|
69
|
+
const v2 = y2 - this.yTest;
|
|
70
|
+
const p = v2 * this.v1;
|
|
59
71
|
if (p > 0) {
|
|
60
|
-
//
|
|
61
|
-
this.
|
|
62
|
-
this.v0 = this.v1;
|
|
63
|
-
this.u1 = u;
|
|
64
|
-
this.v1 = v;
|
|
65
|
-
return true;
|
|
72
|
+
// Current edge does not cross u-axis.
|
|
73
|
+
return this.updateUV01(u2, v2);
|
|
66
74
|
}
|
|
67
75
|
if (p < 0) {
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
const
|
|
71
|
-
const uCross = this.u1 +
|
|
76
|
+
// Current edge crosses the u-axis at edge parameter 0 < lambda < 1 by the Intermediate Value Theorem.
|
|
77
|
+
// Solve for lambda in 0 = v1 + lambda (v2 - v1), then use it to compute the u-value of the crossing.
|
|
78
|
+
const lambda = -this.v1 / (v2 - this.v1);
|
|
79
|
+
const uCross = this.u1 + lambda * (u2 - this.u1);
|
|
72
80
|
if (uCross === 0.0) {
|
|
73
|
-
this.numHit++;
|
|
81
|
+
this.numHit++; // Current edge crosses at the origin.
|
|
74
82
|
return false;
|
|
75
83
|
}
|
|
76
84
|
if (uCross > 0)
|
|
77
85
|
this.numRightCrossing++;
|
|
78
86
|
else
|
|
79
87
|
this.numLeftCrossing++;
|
|
80
|
-
this.
|
|
81
|
-
this.v0 = this.v1;
|
|
82
|
-
this.u1 = u;
|
|
83
|
-
this.v1 = v;
|
|
84
|
-
return true;
|
|
88
|
+
return this.updateUV01(u2, v2);
|
|
85
89
|
}
|
|
86
|
-
//
|
|
87
|
-
if (
|
|
90
|
+
// At this point, at least one endpoint of the current edge lies on the u-axis.
|
|
91
|
+
if (v2 === 0.0) {
|
|
88
92
|
if (this.v1 === 0.0) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.numHit++;
|
|
93
|
+
if (u2 * this.u1 <= 0.0) {
|
|
94
|
+
this.numHit++; // Current edge lies on u-axis and contains the origin.
|
|
92
95
|
return false;
|
|
93
96
|
}
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
this.u1 =
|
|
97
|
-
this.v1 =
|
|
97
|
+
// Current edge lies on the u-axis to one side of the origin.
|
|
98
|
+
// This edge doesn't contribute to parity computations, so advance past it.
|
|
99
|
+
this.u1 = u2;
|
|
100
|
+
this.v1 = v2;
|
|
98
101
|
return true;
|
|
99
102
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return
|
|
103
|
+
if (u2 === 0.0) {
|
|
104
|
+
this.numHit++; // Current edge ends at the origin.
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
// Current edge ends on the u-axis away from the origin.
|
|
108
|
+
return this.updateUV01(u2, v2);
|
|
106
109
|
}
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (this.u1 > 0) {
|
|
112
|
-
if (q < 0)
|
|
113
|
-
this.numRightCrossing++;
|
|
110
|
+
// At this point, the current edge starts at the u-axis.
|
|
111
|
+
if (this.u1 === 0.0) {
|
|
112
|
+
this.numHit++; // Current edge starts at the origin.
|
|
113
|
+
return false;
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
// At this point, the current edge starts on the u-axis away from the origin.
|
|
116
|
+
const q = this.v0 * v2;
|
|
117
|
+
if (q < 0) {
|
|
118
|
+
// The current edge and the previous edge lie on opposite sides of the u-axis, so we have a parity change.
|
|
119
|
+
if (this.u1 > 0)
|
|
120
|
+
this.numRightCrossing++;
|
|
121
|
+
else
|
|
117
122
|
this.numLeftCrossing++;
|
|
118
123
|
}
|
|
119
|
-
|
|
120
|
-
this.
|
|
121
|
-
this.u1 = u;
|
|
122
|
-
this.v1 = v;
|
|
123
|
-
return true;
|
|
124
|
+
// The current edge and the previous edge lie on the same sides of the u-axis, so no parity change.
|
|
125
|
+
return this.updateUV01(u2, v2);
|
|
124
126
|
}
|
|
125
127
|
/**
|
|
126
128
|
* Return classification as ON, IN, or OUT according to hit and crossing counts.
|
|
127
|
-
* * Any nonzero hit count is ON
|
|
129
|
+
* * Any nonzero hit count is ON.
|
|
128
130
|
* * Otherwise IN if left crossing count is odd.
|
|
129
|
-
* @return 0 if ON, 1 if IN, -1 if OUT
|
|
131
|
+
* @return 0 if ON, 1 if IN, -1 if OUT.
|
|
130
132
|
*/
|
|
131
133
|
classifyCounts() {
|
|
132
134
|
if (this.numHit > 0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XYParitySearchContext.js","sourceRoot":"","sources":["../../../src/topology/XYParitySearchContext.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,qBAAqB;IAUhC;;;;OAIG;IACH,YAAmB,KAAa,EAAE,KAAa;QAC7C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,+DAA+D;QAC1G,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;IACD;;;;;OAKG;IACI,YAAY,CAAC,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU;QAChE,IAAI,EAAE,KAAK,IAAI,CAAC,KAAK,EAAE;YACrB,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAC1B,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAC1B,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAC1B,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,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IACI,cAAc;QACnB,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;YACjB,OAAO,CAAC,CAAC;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC3C,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module Topology\r\n */\r\n\r\n/**\r\n * * XYParitySearchContext is an internal class for callers that can feed points (without extracting to array structures)\r\n * * Most will be via static methods which handle a specific data source.\r\n * * PolygonOps.classifyPointInPolygon (x,y,points: XAndY[])\r\n * * HalfEdgeGraphSearch.pointInOrOnFaceXY (halfEdgeOnFace, x, y)\r\n * Use pattern:\r\n * * Caller must be able walk around polygon producing x,y coordinates (possibly transformed from actual polygon)\r\n * * Caller announce edges to tryStartEdge until finding one acceptable to the search.\r\n * * Caller then passes additional points up to and including both x0,y0 and x1, y1 of the accepted start edge.\r\n * Call sequence is:\r\n * `context = new XYParitySearchContext`\r\n * `repeat { acquire edge (x0,y0) (x1,y1)} until context.tryStartEdge (x0,y0,x1,y1);`\r\n * `for each (x,y) beginning AFTER x1,y1 and ending with (x1,y1) context.advance (x,y)`\r\n * `return context.classifyCounts ();`\r\n */\r\nexport class XYParitySearchContext {\r\n public xTest: number;\r\n public yTest: number;\r\n public u0: number; // local coordinates of recent point with nonzero v. Usually \"second last point\" but points can be skipped if y1 is zero\r\n public v0: number;\r\n public u1: number; // local coordinates of most recent point\r\n public v1: number;\r\n public numLeftCrossing: number;\r\n public numRightCrossing: number;\r\n public numHit: number;\r\n /**\r\n * Create a new searcher for specified test point.\r\n * @param xTest x coordinate of test point\r\n * @param yTest y coordinate of test point\r\n */\r\n public constructor(xTest: number, yTest: number) {\r\n this.xTest = xTest;\r\n this.yTest = yTest;\r\n this.u0 = this.v0 = this.u1 = this.v1 = 0; // Not valid for search -- caller must satisfy tryStartEdge !!!\r\n this.numLeftCrossing = this.numRightCrossing = 0;\r\n this.numHit = 0;\r\n }\r\n /**\r\n * test if x,y is a safe first coordinate to start the search.\r\n * * safe start must have non-zero y so that final point test (return to x0,y0) does not need look back for exact crossing logic.\r\n * @param x\r\n * @param y\r\n */\r\n public tryStartEdge(x0: number, y0: number, x1: number, y1: number): boolean {\r\n if (y0 !== this.yTest) {\r\n this.u0 = x0 - this.xTest;\r\n this.v0 = y0 - this.yTest;\r\n this.u1 = x1 - this.xTest;\r\n this.v1 = y1 - this.yTest;\r\n return true;\r\n }\r\n return false;\r\n }\r\n /** Return true if parity accumulation proceeded normally.\r\n * Return false if interrupted for exact hit.\r\n */\r\n public advance(x: number, y: number): boolean {\r\n const u = x - this.xTest;\r\n const v = y - this.yTest;\r\n const p = v * this.v1;\r\n if (p > 0) {\r\n // The common case -- skittering along above or below the x axis . . .\r\n this.u0 = this.u1;\r\n this.v0 = this.v1;\r\n this.u1 = u;\r\n this.v1 = v;\r\n return true;\r\n }\r\n if (p < 0) {\r\n // crossing within (u1,v1) to (u,v)\r\n // both v values are nonzero and of opposite sign, so this division is safe . . .\r\n const fraction = -this.v1 / (v - this.v1);\r\n const uCross = this.u1 + fraction * (u - this.u1);\r\n if (uCross === 0.0) {\r\n this.numHit++;\r\n return false;\r\n }\r\n if (uCross > 0)\r\n this.numRightCrossing++;\r\n else\r\n this.numLeftCrossing++;\r\n this.u0 = this.u1;\r\n this.v0 = this.v1;\r\n this.u1 = u;\r\n this.v1 = v;\r\n return true;\r\n }\r\n // hard stuff -- one or more exact hits . . .\r\n if (v === 0.0) {\r\n if (this.v1 === 0.0) {\r\n // uh oh -- moving along x axis. Does it pass through xTest:\r\n if (u * this.u1 <= 0.0) {\r\n this.numHit++;\r\n return false;\r\n }\r\n // quietly moving along the scan line, both xy and x1y1 to same side of test point ...\r\n // u0 and u1 remain unchanged !!!\r\n this.u1 = u;\r\n this.v1 = v;\r\n return true;\r\n }\r\n // just moved onto the scan line ...\r\n this.u0 = this.u1;\r\n this.v0 = this.v1;\r\n this.u1 = u;\r\n this.v1 = v;\r\n return true;\r\n }\r\n // fall out with v1 = 0\r\n // both v0 and v are nonzero.\r\n // any along-0 v values that have passed through are on the same side of xTest, so u1 determines crossing\r\n const q = this.v0 * v;\r\n if (this.u1 > 0) {\r\n if (q < 0)\r\n this.numRightCrossing++;\r\n } else {\r\n if (q < 0)\r\n this.numLeftCrossing++;\r\n }\r\n this.u0 = this.u1;\r\n this.v0 = this.v1;\r\n this.u1 = u;\r\n this.v1 = v;\r\n return true;\r\n }\r\n /**\r\n * Return classification as ON, IN, or OUT according to hit and crossing counts.\r\n * * Any nonzero hit count is ON\r\n * * Otherwise IN if left crossing count is odd.\r\n * @return 0 if ON, 1 if IN, -1 if OUT\r\n */\r\n public classifyCounts(): number | undefined {\r\n if (this.numHit > 0)\r\n return 0;\r\n const parity = this.numLeftCrossing & 0x01;\r\n return (parity === 1) ? 1 : -1;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"XYParitySearchContext.js","sourceRoot":"","sources":["../../../src/topology/XYParitySearchContext.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,qBAAqB;IAchC;;;;OAIG;IACH,YAAmB,KAAa,EAAE,KAAa;QAC7C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,yDAAyD;QACpG,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,gBAAgB,G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,CAAC,MAAM,EAAE,CAAC,CAAE,qCAAqC;YACrD,OAAO,KAAK,CAAC;SACd;QACD,6EAA6E;QAC7E,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,GAAG,CAAC,EAAE;YACT,0GAA0G;YAC1G,IAAI,IAAI,CAAC,EAAE,GAAG,CAAC;gBACb,IAAI,CAAC,gBAAgB,EAAE,CAAC;;gBAExB,IAAI,CAAC,eAAe,EAAE,CAAC;SAC1B;QACD,mGAAmG;QACnG,OAAO,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACjC,CAAC;IACD;;;;;OAKG;IACI,cAAc;QACnB,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;YACjB,OAAO,CAAC,CAAC;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC3C,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module Topology\r\n */\r\n\r\n/**\r\n * `XYParitySearchContext` is an internal class for callers that can feed points (without extracting to array structures)\r\n * * Most will be via static methods which handle a specific data source.\r\n * * PolygonOps.classifyPointInPolygon(x,y,points: XAndY[])\r\n * * HalfEdgeGraphSearch.pointInOrOnFaceXY(halfEdgeOnFace, x, y)\r\n * Use pattern:\r\n * * Caller must be able to walk around polygon producing x,y coordinates (possibly transformed from actual polygon).\r\n * * Caller announce edges to tryStartEdge until finding one acceptable to the search.\r\n * * Caller then passes additional points up to and including both x0,y0 and x1, y1 of the accepted start edge.\r\n * Call sequence is:\r\n * * `context = new XYParitySearchContext`\r\n * * `repeat { acquire edge (x0,y0) (x1,y1) } until context.tryStartEdge(x0,y0,x1,y1);`\r\n * * `for each (x,y) beginning AFTER x1,y1 and ending with (x1,y1) context.advance (x,y)`\r\n * * `return context.classifyCounts();`\r\n */\r\nexport class XYParitySearchContext {\r\n public xTest: number;\r\n public yTest: number;\r\n /** local x-coordinate of the start of the previous (or earlier) edge */\r\n public u0: number;\r\n /** local y-coordinate of the start of the previous (or earlier) edge */\r\n public v0: number;\r\n /** local x-coordinate of the end of the previous edge (and start of current edge) */\r\n public u1: number;\r\n /** local y-coordinate of the end of the previous edge (and start of current edge) */\r\n public v1: number;\r\n public numLeftCrossing: number;\r\n public numRightCrossing: number;\r\n public numHit: number;\r\n /**\r\n * Create a new searcher for specified test point.\r\n * @param xTest x coordinate of test point.\r\n * @param yTest y coordinate of test point.\r\n */\r\n public constructor(xTest: number, yTest: number) {\r\n this.xTest = xTest;\r\n this.yTest = yTest;\r\n this.u0 = this.v0 = this.u1 = this.v1 = 0; // not valid for search; caller must satisfy tryStartEdge\r\n this.numLeftCrossing = this.numRightCrossing = 0;\r\n this.numHit = 0;\r\n }\r\n /** Test if parity processing can begin with this edge. */\r\n public tryStartEdge(x0: number, y0: number, x1: number, y1: number): boolean {\r\n if (y0 !== this.yTest) {\r\n this.u0 = x0 - this.xTest;\r\n this.v0 = y0 - this.yTest;\r\n this.u1 = x1 - this.xTest;\r\n this.v1 = y1 - this.yTest;\r\n return true; // we won't need wraparound logic to process the final edge ending at (x0,y0)\r\n }\r\n return false;\r\n }\r\n /** Update local coordinates: the current edge becomes the previous edge. */\r\n private updateUV01(u2: number, v2: number) {\r\n this.u0 = this.u1;\r\n this.v0 = this.v1;\r\n this.u1 = u2;\r\n this.v1 = v2;\r\n return true;\r\n }\r\n /**\r\n * Process the current edge ending at (x2,y2).\r\n * * Accumulate left/right parity of the test point wrt to the polygon. These counts track the number of polygon crossings\r\n * of the left and right horizontal rays emanating from the test point. After all edges are processed, if either count is\r\n * odd/even, the test point is inside/outside the polygon (see [[classifyCounts]]).\r\n * * Check whether the test point lies on the edge.\r\n * @returns whether caller should continue processing with the next edge. In particular, `false` if we have an exact hit.\r\n */\r\n public advance(x2: number, y2: number): boolean {\r\n // In this method we use local u,v coordinates obtained by translating the test point to the origin.\r\n // This simplifies our computations:\r\n // * left (right) parity is incremented if the current edge crosses the u-axis at u<0 (u>0)\r\n // * we have an exact hit if the current edge crosses the u-axis at u=0\r\n const u2 = x2 - this.xTest;\r\n const v2 = y2 - this.yTest;\r\n const p = v2 * this.v1;\r\n if (p > 0) {\r\n // Current edge does not cross u-axis.\r\n return this.updateUV01(u2, v2);\r\n }\r\n if (p < 0) {\r\n // Current edge crosses the u-axis at edge parameter 0 < lambda < 1 by the Intermediate Value Theorem.\r\n // Solve for lambda in 0 = v1 + lambda (v2 - v1), then use it to compute the u-value of the crossing.\r\n const lambda = -this.v1 / (v2 - this.v1);\r\n const uCross = this.u1 + lambda * (u2 - this.u1);\r\n if (uCross === 0.0) {\r\n this.numHit++; // Current edge crosses at the origin.\r\n return false;\r\n }\r\n if (uCross > 0)\r\n this.numRightCrossing++;\r\n else\r\n this.numLeftCrossing++;\r\n return this.updateUV01(u2, v2);\r\n }\r\n // At this point, at least one endpoint of the current edge lies on the u-axis.\r\n if (v2 === 0.0) {\r\n if (this.v1 === 0.0) {\r\n if (u2 * this.u1 <= 0.0) {\r\n this.numHit++; // Current edge lies on u-axis and contains the origin.\r\n return false;\r\n }\r\n // Current edge lies on the u-axis to one side of the origin.\r\n // This edge doesn't contribute to parity computations, so advance past it.\r\n this.u1 = u2;\r\n this.v1 = v2;\r\n return true;\r\n }\r\n if (u2 === 0.0) {\r\n this.numHit++; // Current edge ends at the origin.\r\n return false;\r\n }\r\n // Current edge ends on the u-axis away from the origin.\r\n return this.updateUV01(u2, v2);\r\n }\r\n // At this point, the current edge starts at the u-axis.\r\n if (this.u1 === 0.0) {\r\n this.numHit++; // Current edge starts at the origin.\r\n return false;\r\n }\r\n // At this point, the current edge starts on the u-axis away from the origin.\r\n const q = this.v0 * v2;\r\n if (q < 0) {\r\n // The current edge and the previous edge lie on opposite sides of the u-axis, so we have a parity change.\r\n if (this.u1 > 0)\r\n this.numRightCrossing++;\r\n else\r\n this.numLeftCrossing++;\r\n }\r\n // The current edge and the previous edge lie on the same sides of the u-axis, so no parity change.\r\n return this.updateUV01(u2, v2);\r\n }\r\n /**\r\n * Return classification as ON, IN, or OUT according to hit and crossing counts.\r\n * * Any nonzero hit count is ON.\r\n * * Otherwise IN if left crossing count is odd.\r\n * @return 0 if ON, 1 if IN, -1 if OUT.\r\n */\r\n public classifyCounts(): number | undefined {\r\n if (this.numHit > 0)\r\n return 0;\r\n const parity = this.numLeftCrossing & 0x01;\r\n return (parity === 1) ? 1 : -1;\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-geometry",
|
|
3
|
-
"version": "4.4.0-dev.
|
|
3
|
+
"version": "4.4.0-dev.21",
|
|
4
4
|
"description": "iTwin.js Core Geometry library",
|
|
5
5
|
"main": "lib/cjs/core-geometry.js",
|
|
6
6
|
"module": "lib/esm/core-geometry.js",
|
|
@@ -26,19 +26,19 @@
|
|
|
26
26
|
"@itwin/eslint-plugin": "4.0.0-dev.44",
|
|
27
27
|
"@types/chai": "4.3.1",
|
|
28
28
|
"@types/flatbuffers": "~1.10.0",
|
|
29
|
-
"@types/mocha": "^
|
|
29
|
+
"@types/mocha": "^10.0.6",
|
|
30
30
|
"chai": "^4.3.10",
|
|
31
31
|
"debug": "^2.6.9",
|
|
32
32
|
"eslint": "^8.44.0",
|
|
33
|
-
"mocha": "^10.
|
|
33
|
+
"mocha": "^10.2.0",
|
|
34
34
|
"nyc": "^15.1.0",
|
|
35
35
|
"rimraf": "^3.0.2",
|
|
36
36
|
"typescript": "~5.0.2",
|
|
37
|
-
"@itwin/build-tools": "4.4.0-dev.
|
|
37
|
+
"@itwin/build-tools": "4.4.0-dev.21"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"flatbuffers": "~1.12.0",
|
|
41
|
-
"@itwin/core-bentley": "4.4.0-dev.
|
|
41
|
+
"@itwin/core-bentley": "4.4.0-dev.21"
|
|
42
42
|
},
|
|
43
43
|
"nyc": {
|
|
44
44
|
"extends": "./node_modules/@itwin/build-tools/.nycrc",
|