From 1c6add285fd49051a77b827d9f3660368b5c9ba3 Mon Sep 17 00:00:00 2001 From: Nils Christian Bonnevie Date: Thu, 28 Sep 2023 13:33:16 +0200 Subject: [PATCH] Added simple unit test + fixed crash caused by horizontal wells. --- example-data/well_176.json | 1213 +++++++++++++++++ .../src/layers/wells/utils/spline.test.ts | 32 + .../src/layers/wells/utils/spline.ts | 114 +- .../src/layers/wells/wellsLayer.stories.tsx | 34 + .../src/layers/wells/wellsLayer.ts | 11 +- 5 files changed, 1374 insertions(+), 30 deletions(-) create mode 100644 example-data/well_176.json create mode 100644 typescript/packages/subsurface-viewer/src/layers/wells/utils/spline.test.ts diff --git a/example-data/well_176.json b/example-data/well_176.json new file mode 100644 index 000000000..a89ef63ea --- /dev/null +++ b/example-data/well_176.json @@ -0,0 +1,1213 @@ +{ + "type": "FeatureCollection", + "features": [{ + "type": "Feature", + "geometry": { + "type": "GeometryCollection", + "geometries": [ + { + "type": "Point", + "coordinates": [ + 756785.127841631, + 166800.4158503118 + ] + }, + { + "type": "LineString", + "coordinates": [ + [ + 756785.127841631, + 166800.4158503118, + 298.82591542560647 + ], + [ + 756785.9696401906, + 166800.49202233925, + 270.49477352117805 + ], + [ + 756786.6415165352, + 166800.5486630776, + 261.0703467010097 + ], + [ + 756788.4286294868, + 166800.68342897235, + 242.25808371007423 + ], + [ + 756791.8700426242, + 166800.57991314016, + 214.12504706051394 + ], + [ + 756793.1962171532, + 166800.4568660189, + 204.7707345164081 + ], + [ + 756794.5985637096, + 166800.3201469953, + 195.4286137691628 + ], + [ + 756796.0438791023, + 166800.1678029404, + 186.08956004465708 + ], + [ + 756798.5067746562, + 166799.919755569, + 170.12717153161316 + ], + [ + 756802.5712359155, + 166799.59358304122, + 144.54225094353282 + ], + [ + 756804.7450683911, + 166799.4588171465, + 130.9999875131632 + ], + [ + 756808.5087477984, + 166799.23811357984, + 103.8301180744006 + ], + [ + 756811.7275042401, + 166799.2166291618, + 76.89494453990716 + ], + [ + 756815.0810265765, + 166799.2166291618, + 49.67020820056748 + ], + [ + 756818.581033581, + 166799.04866007564, + 22.460711607303395 + ], + [ + 756821.96580598, + 166798.7439719659, + -4.453128190036646 + ], + [ + 756825.329093961, + 166798.47639330535, + -31.67481658016121 + ], + [ + 756828.7607414539, + 166798.23615844958, + -58.89040716450308 + ], + [ + 756832.1865295599, + 166797.86897021474, + -86.1059920267876 + ], + [ + 756835.35450465, + 166797.40021927663, + -113.04422495461087 + ], + [ + 756838.3174012046, + 166797.02326539723, + -140.31163639766714 + ], + [ + 756841.1240474466, + 166796.7342023187, + -167.29252535568247 + ], + [ + 756843.8428028877, + 166796.49006120508, + -194.58736452696994 + ], + [ + 756846.5010113326, + 166796.40802979094, + -221.89135899001747 + ], + [ + 756848.7295314176, + 166796.24592009152, + -244.6416181433475 + ], + [ + 756851.2256301631, + 166796.13849800153, + -272.26259932476756 + ], + [ + 756852.2705541292, + 166796.28107641186, + -285.93898777942206 + ], + [ + 756853.9229011862, + 166796.8865463736, + -313.0082863382004 + ], + [ + 756855.124075465, + 166797.72053241768, + -340.40061410791293 + ], + [ + 756855.981499056, + 166798.64436239153, + -367.8052404862231 + ], + [ + 756856.5908752754, + 166799.6756144554, + -395.2097753116157 + ], + [ + 756857.0205636354, + 166800.78108541778, + -422.30953047431586 + ], + [ + 756857.2490797178, + 166801.9158533138, + -449.7171475812677 + ], + [ + 756857.2607984912, + 166802.08186927103, + -453.67650609110234 + ], + [ + 756857.3545486788, + 166802.55647959586, + -467.38338166731785 + ], + [ + 756857.6807212067, + 166802.8064800962, + -481.0932784898142 + ], + [ + 756858.2568942348, + 166802.84358954546, + -494.7970717844705 + ], + [ + 756859.0361926694, + 166802.73616745547, + -508.491740305006 + ], + [ + 756859.9248663229, + 166802.54671395133, + -522.1772535337814 + ], + [ + 756860.8057274608, + 166802.2498383572, + -535.5549658535834 + ], + [ + 756861.7178386612, + 166801.82210312618, + -549.2343755545188 + ], + [ + 756862.6162779591, + 166801.4080397975, + -562.9137852554542 + ], + [ + 756863.4365921009, + 166801.15413303938, + -576.6023502481495 + ], + [ + 756864.1514372815, + 166801.06624223848, + -590.300070532605 + ], + [ + 756864.6924539893, + 166800.95100763283, + -604.0038943449006 + ], + [ + 756864.9776108098, + 166800.66585081216, + -617.7137606497577 + ], + [ + 756865.1983143765, + 166800.05256833477, + -644.8349086775372 + ], + [ + 756865.2998770799, + 166799.67952071322, + -672.2638576142899 + ], + [ + 756865.3780022362, + 166799.51155162705, + -699.6958583149627 + ], + [ + 756865.446361748, + 166799.50569224032, + -726.8230488353038 + ], + [ + 756865.5147212598, + 166799.64827065065, + -754.252058807335 + ], + [ + 756865.5694088694, + 166799.88459924865, + -781.3791882923978 + ], + [ + 756865.5908932872, + 166800.1638966826, + -808.8111889930705 + ], + [ + 756865.6026120608, + 166800.50960049944, + -836.2401379298233 + ], + [ + 756865.6944091195, + 166800.91389818356, + -863.3642766862444 + ], + [ + 756865.7998780805, + 166801.35139905915, + -890.7932256229972 + ], + [ + 756865.7725342759, + 166801.91780644268, + -917.9143736507765 + ], + [ + 756865.3780022362, + 166802.318197869, + -945.3372190596893 + ], + [ + 756864.7451884698, + 166802.25960400174, + -972.763116232522 + ], + [ + 756864.1670623128, + 166802.14632252502, + -999.8842032250232 + ], + [ + 756863.5869830268, + 166802.1873382321, + -1027.3101614331342 + ], + [ + 756863.0205756434, + 166802.3435885448, + -1054.7359975706886 + ], + [ + 756862.4424494863, + 166802.5877296584, + -1081.854093834548 + ], + [ + 756862.0303392865, + 166802.6697610726, + -1109.2829817360225 + ], + [ + 756861.8506514268, + 166802.52522953335, + -1136.7150434719736 + ], + [ + 756861.700260501, + 166802.44319811914, + -1163.8391211931164 + ], + [ + 756861.5127601258, + 166802.4998388575, + -1191.2711829290674 + ], + [ + 756861.5244788992, + 166802.4080417988, + -1218.7031225944618 + ], + [ + 756861.7705731418, + 166802.21663516574, + -1245.8273223861613 + ], + [ + 756861.9736985482, + 166802.23226019702, + -1273.2595061926693 + ], + [ + 756862.1026050561, + 166802.43929186134, + -1300.691323787507 + ], + [ + 756862.534246545, + 166802.51351075986, + -1328.117281995618 + ], + [ + 756863.0674507371, + 166802.10335368905, + -1355.235134118364 + ], + [ + 756863.3194043663, + 166801.50960250074, + -1382.6610923264752 + ], + [ + 756863.2725292726, + 166801.3455396724, + -1410.0901022985063 + ], + [ + 756863.0674507371, + 166801.5584307235, + -1437.5221640344575 + ], + [ + 756862.8916691353, + 166801.8279625129, + -1464.6462417556002 + ], + [ + 756862.7686220141, + 166802.0056972436, + -1480.8006930309505 + ], + [ + 756862.7295594359, + 166802.07210362647, + -1486.2871542063635 + ], + [ + 756862.7276063069, + 166802.20296326338, + -1499.999950204584 + ], + [ + 756863.2041697608, + 166802.1619475563, + -1513.7070088866346 + ], + [ + 756864.6846414736, + 166801.81038435272, + -1527.0266156213995 + ], + [ + 756867.5576940986, + 166801.1170235901, + -1540.4134832329619 + ], + [ + 756871.7198118032, + 166800.0154588855, + -1553.4284018579517 + ], + [ + 756876.8760721225, + 166798.44904950063, + -1566.038046234363 + ], + [ + 756882.7725682982, + 166796.42951420892, + -1578.2543792767624 + ], + [ + 756889.1573467011, + 166794.02130626436, + -1590.1538171537063 + ], + [ + 756895.8761101473, + 166791.30841021004, + -1601.7939771680058 + ], + [ + 756903.0401869848, + 166788.23613843645, + -1613.0778132270032 + ], + [ + 756910.5792645729, + 166784.8728504555, + -1623.6452171881367 + ], + [ + 756918.8566248884, + 166781.1501867553, + -1633.9291733163789 + ], + [ + 756927.669142525, + 166777.23806955095, + -1643.6796811114014 + ], + [ + 756937.0851769943, + 166773.17751454952, + -1652.7810176853568 + ], + [ + 756947.0656657185, + 166768.99586555574, + -1661.2057171629658 + ], + [ + 756957.3957645172, + 166764.73804453455, + -1669.1639850430388 + ], + [ + 756968.1672704493, + 166760.6325675682, + -1676.5889266604486 + ], + [ + 756979.503230636, + 166756.80443490692, + -1683.2884029587915 + ], + [ + 756991.0520818738, + 166753.13255255838, + -1689.0218128706124 + ], + [ + 757003.1380435616, + 166749.31418554165, + -1694.2674288374571 + ], + [ + 757015.3333804682, + 166745.48995913818, + -1699.2448557910107 + ], + [ + 757027.6185613046, + 166741.69112341054, + -1704.011711034083 + ], + [ + 757039.9799141685, + 166737.8532251047, + -1708.5534681704144 + ], + [ + 757052.1381416259, + 166734.14228017797, + -1712.8145850966605 + ], + [ + 757064.6284009976, + 166730.68133575155, + -1717.307269869158 + ], + [ + 757078.1655374648, + 166727.4938293724, + -1722.7418510579307 + ], + [ + 757090.5327497153, + 166725.13835590833, + -1728.1794840106234 + ], + [ + 757102.8628525166, + 166723.54264958983, + -1733.9674594613343 + ], + [ + 757115.0952988726, + 166722.9137420812, + -1740.127628039731 + ], + [ + 757127.1910262048, + 166723.25749276913, + -1746.5771038377457 + ], + [ + 757138.8180025991, + 166724.5289796888, + -1753.133391372961 + ], + [ + 757150.3805257392, + 166726.86296873481, + -1760.1254707959554 + ], + [ + 757161.4469541365, + 166730.3219600323, + -1767.4406709828013 + ], + [ + 757171.9040063142, + 166734.84345345624, + -1775.0728884056591 + ], + [ + 757181.7301978546, + 166740.29072998292, + -1782.9306922174849 + ], + [ + 757190.888419308, + 166746.67941464364, + -1790.8859083336376 + ], + [ + 757199.1911702993, + 166753.90794473517, + -1799.0606073109182 + ], + [ + 757206.4958724183, + 166761.95288271055, + -1807.4184121234002 + ], + [ + 757212.5935408716, + 166770.70485335097, + -1815.5381793501206 + ], + [ + 757217.9040983745, + 166780.44315409032, + -1823.5999630623603 + ], + [ + 757222.4314511853, + 166790.80059669373, + -1831.3634063337793 + ], + [ + 757226.120911694, + 166801.71663416512, + -1838.797503242949 + ], + [ + 757229.1013864089, + 166813.15415705508, + -1845.7438062071433 + ], + [ + 757231.3845941033, + 166825.00183701597, + -1852.2634725753182 + ], + [ + 757232.8377220115, + 166837.14639257095, + -1858.4662437780385 + ], + [ + 757233.3865512348, + 166849.2304011298, + -1864.2482377714662 + ], + [ + 757232.9627222616, + 166861.70308234147, + -1869.9328194605669 + ], + [ + 757231.4822505488, + 166874.16013852187, + -1875.4678647175867 + ], + [ + 757228.906073518, + 166886.50391322558, + -1880.8537397541959 + ], + [ + 757225.2908319078, + 166898.6094062024, + -1886.1848051108013 + ], + [ + 757220.6248069446, + 166910.33989842873, + -1891.527833381973 + ], + [ + 757214.9314361754, + 166921.68562426005, + -1896.7155879048946 + ], + [ + 757208.4411888114, + 166932.43759890305, + -1901.4155484828398 + ], + [ + 757200.9997676689, + 166943.1993391906, + -1905.5182178263585 + ], + [ + 757193.0231892053, + 166953.94154818906, + -1908.4990587528778 + ], + [ + 757184.6677037334, + 166964.69352283212, + -1910.0931781541399 + ], + [ + 757176.107139726, + 166975.4005755102, + -1910.4040918623116 + ], + [ + 757167.4801693358, + 166986.04903432107, + -1909.980384959656 + ], + [ + 757158.696948633, + 166996.57835226847, + -1909.5506965997172 + ], + [ + 757149.9723217973, + 167006.7561070123, + -1909.218542614662 + ], + [ + 757131.8043166875, + 167027.29130435956, + -1909.605384209164 + ], + [ + 757113.5620926791, + 167047.75032967937, + -1910.6450591414364 + ], + [ + 757095.6929162925, + 167068.15466738975, + -1910.946695487291 + ], + [ + 757077.7026459133, + 167088.861740081, + -1911.3885909029102 + ], + [ + 757059.8139382375, + 167109.64498479967, + -1911.9554865686932 + ], + [ + 757041.9291368196, + 167130.4438545496, + -1912.190350319978 + ], + [ + 757024.3001952885, + 167151.05717705324, + -1911.9860042078933 + ], + [ + 757006.4427376753, + 167171.87753122117, + -1912.1018491662974 + ], + [ + 756988.4895767454, + 167192.60413520152, + -1912.741865095604 + ], + [ + 756970.4524312726, + 167213.27214531455, + -1913.0405717480958 + ], + [ + 756952.5930205304, + 167233.68429554056, + -1912.842451234408 + ], + [ + 756934.6007970225, + 167254.38160258727, + -1912.168865901981 + ], + [ + 756916.6300579325, + 167275.10234718086, + -1911.7787284024457 + ], + [ + 756898.5362717211, + 167295.7176228134, + -1911.9038507231664 + ], + [ + 756880.5538138577, + 167316.02625720724, + -1911.7543142910854 + ], + [ + 756862.4268244549, + 167336.60442339047, + -1911.147867764899 + ], + [ + 756844.2510068296, + 167357.1259488354, + -1910.1450581407803 + ], + [ + 756826.0126890792, + 167377.6064585732, + -1909.544593071877 + ], + [ + 756808.1610908525, + 167398.02446818593, + -1909.3310916680325 + ], + [ + 756790.2469925008, + 167418.79794726006, + -1909.2550417111456 + ], + [ + 756772.3758629853, + 167439.60658265455, + -1909.3982304742729 + ], + [ + 756754.6141086885, + 167460.50896823668, + -1909.1605591001817 + ], + [ + 756737.0730579585, + 167481.1945565099, + -1908.5295763920783 + ], + [ + 756719.4616945877, + 167502.21803608438, + -1908.2157329905433 + ], + [ + 756702.0573628813, + 167523.42120351846, + -1908.395420850154 + ], + [ + 756684.7624063937, + 167544.71421488235, + -1908.4534043646345 + ], + [ + 756667.4654967772, + 167565.99941373058, + -1908.2522320870264 + ], + [ + 756650.4068688877, + 167587.0853934301, + -1907.6915620196405 + ], + [ + 756633.2603501973, + 167608.47215498163, + -1906.6826488676818 + ], + [ + 756615.6978150492, + 167629.53274400538, + -1906.350250741513 + ], + [ + 756597.8969981743, + 167649.9937224541, + -1906.8592849633726 + ], + [ + 756579.9203996975, + 167670.7125139188, + -1907.1213704488239 + ], + [ + 756561.9301293185, + 167691.42153973895, + -1907.02078431002 + ], + [ + 756543.8324368495, + 167712.0270497269, + -1906.5300606716805 + ], + [ + 756525.740603767, + 167732.22240264402, + -1905.7071830482862 + ], + [ + 756507.1897853912, + 167752.39822427207, + -1904.5366484791232 + ], + [ + 756488.6702170778, + 167772.15998257144, + -1903.0371337593817 + ], + [ + 756469.9377577134, + 167792.14439756642, + -1901.558859316524 + ], + [ + 756451.2306890248, + 167812.13857820595, + -1899.955584623502 + ], + [ + 756432.8927616999, + 167832.0741649782, + -1898.5412751524077 + ], + [ + 756415.0001477663, + 167852.85740969688, + -1898.0505515140683 + ], + [ + 756397.6641755716, + 167874.1133116115, + -1897.9682759587847 + ], + [ + 756380.6114070689, + 167895.2090569556, + -1897.5842419870892 + ], + [ + 756363.4004351244, + 167916.5528496711, + -1896.8193478781752 + ], + [ + 756346.080087961, + 167937.80093907006, + -1895.7491553067023 + ], + [ + 756328.7382563796, + 167958.6115275935, + -1894.356330253605 + ], + [ + 756311.103455462, + 167979.56469452722, + -1892.8354531864236 + ], + [ + 756293.4217794505, + 168000.4846582695, + -1891.3144540486855 + ], + [ + 756274.9783831646, + 168022.32649885677, + -1889.4370088850887 + ], + [ + 756257.3416291181, + 168043.23474382565, + -1887.385613178051 + ], + [ + 756239.8494066107, + 168063.85392571596, + -1885.187854873409 + ], + [ + 756222.1149961186, + 168084.64107669247, + -1882.7862387389096 + ], + [ + 756204.3493355641, + 168105.39709967698, + -1880.3143099636927 + ], + [ + 756186.6012531696, + 168126.16264416493, + -1877.821018841036 + ], + [ + 756174.7731044979, + 168140.00446874168, + -1876.10495095353 + ], + [ + 756162.5367518843, + 168154.28965358072, + -1874.2973301484237 + ], + [ + 756162.5367518843, + 168154.28965358072, + -1874.2973301484237 + ] + ] + } + ] + }, + "properties": { + "name": "Well_176", + "color": [ + 25, + 125, + 255, + 255 + ], + "md": [ + [ + 63.70332749000001, + 92.04978422, + 101.49860313, + 120.39624095, + 148.74269768000002, + 158.19151659000002, + 167.64033550000002, + 177.08915441000002, + 193.24358674, + 219.15163859000003, + 232.86766604000002, + 260.29972094000004, + 287.42697523000004, + 314.85903013, + 342.29108503000003, + 369.41833932000003, + 396.85039422000006, + 424.28244912, + 451.71450402000005, + 478.84175831000005, + 506.27381321000007, + 533.4010675000001, + 560.8331224000001, + 588.2651773, + 611.12522305, + 638.8620785600001, + 652.57810601, + 679.7053603, + 707.1374152000001, + 734.5694701000001, + 762.001525, + 789.1287792900001, + 816.56083419, + 820.5232421200001, + 834.23926957, + 847.9552970200001, + 861.6713244700001, + 875.3873519200001, + 889.1033793700001, + 902.5146062100001, + 916.2306336600001, + 929.94666111, + 943.6626885600001, + 957.3787160100001, + 971.0947434600001, + 984.8107709100001, + 1011.9380252000001, + 1039.3700801, + 1066.8021350000001, + 1093.92938929, + 1121.3614441900002, + 1148.48869848, + 1175.9207533800002, + 1203.35280828, + 1230.4800625700002, + 1257.91211747, + 1285.0393717600002, + 1312.4714266600001, + 1339.90348156, + 1367.0307358500002, + 1394.46279075, + 1421.8948456500002, + 1449.02209994, + 1476.4541548400002, + 1503.8862097400001, + 1531.0134640300003, + 1558.4455189300002, + 1585.87757383, + 1613.0048281200002, + 1640.43688302, + 1667.8689379200002, + 1695.3009928200001, + 1722.4282471100003, + 1749.8603020100002, + 1777.29235691, + 1804.7244118100002, + 1831.8516661, + 1848.00609843, + 1853.4925094100001, + 1867.20853686, + 1880.9245643100003, + 1894.3357911500002, + 1908.0518186000002, + 1921.7678460500001, + 1935.4838735, + 1949.1999009500003, + 1962.9159284000002, + 1976.6319558500002, + 1990.3479833000001, + 2003.7592101400003, + 2017.4752375900002, + 2031.1912650400002, + 2044.9072924900001, + 2058.6233199400003, + 2072.33934739, + 2086.0553748400002, + 2099.77140229, + 2113.1826291300004, + 2126.89865658, + 2140.6146840300003, + 2154.33071148, + 2168.04673893, + 2181.45796577, + 2195.1739932200003, + 2210.10922311, + 2223.8252505600003, + 2237.54127801, + 2251.25730546, + 2264.9733329100004, + 2278.3845597500003, + 2292.1005872, + 2305.8166146500002, + 2319.5326421000004, + 2333.24866955, + 2346.9646970000003, + 2360.68072445, + 2374.3967519000003, + 2387.80797874, + 2401.5240061900004, + 2415.24003364, + 2428.9560610900003, + 2442.67208854, + 2456.38811599, + 2470.1041434400004, + 2483.5153702800003, + 2497.23139773, + 2510.94742518, + 2524.6634526300004, + 2538.37948008, + 2552.0955075300003, + 2565.81153498, + 2579.2227618200004, + 2592.93878927, + 2606.6548167200003, + 2620.37084417, + 2634.0868716200002, + 2647.8028990700004, + 2661.51892652, + 2674.93015336, + 2702.3622082600004, + 2729.7942631600004, + 2756.9215174500005, + 2784.3535723500004, + 2811.7856272500003, + 2839.21768215, + 2866.3449364400003, + 2893.77699134, + 2921.20904624, + 2948.64110114, + 2975.76835543, + 3003.20041033, + 3030.6324652300004, + 3058.0645201300003, + 3085.1917744200005, + 3112.6238293200004, + 3140.0558842200003, + 3167.48793912, + 3194.6151934100003, + 3222.04724831, + 3249.47930321, + 3276.9113581100005, + 3304.0386124, + 3331.4706673000005, + 3358.9027222000004, + 3386.3347771000003, + 3413.7668320000002, + 3440.8940862900004, + 3468.3261411900003, + 3495.75819609, + 3522.8854503800003, + 3550.31750528, + 3577.74956018, + 3605.1816150800005, + 3632.30886937, + 3659.7409242700005, + 3686.86817856, + 3714.3002334600005, + 3741.7322883600004, + 3768.8595426500005, + 3796.2915975500005, + 3823.7236524500004, + 3850.8509067400005, + 3878.2829616400004, + 3905.7150165400003, + 3932.8422708300004, + 3960.2743257300003, + 3987.7063806300002, + 4016.3576379700003, + 4043.78969287, + 4070.9169471600003, + 4098.34900206, + 4125.781056960001, + 4153.21311186, + 4171.50114846, + 4190.39878628, + 4190.399083936846 + ] + ] + } +} +] +} \ No newline at end of file diff --git a/typescript/packages/subsurface-viewer/src/layers/wells/utils/spline.test.ts b/typescript/packages/subsurface-viewer/src/layers/wells/utils/spline.test.ts new file mode 100644 index 000000000..24b4cbdf5 --- /dev/null +++ b/typescript/packages/subsurface-viewer/src/layers/wells/utils/spline.test.ts @@ -0,0 +1,32 @@ +import { removeConsecutiveDuplicates } from "./spline"; +import type { Position3D } from "../../utils/layerTools"; + +describe("remove duplicates", () => { + const coords: Position3D[] = [ + [1, 2, 3], + [1, 2, 3], + [4, 5, 6], + ]; + + const coordsRes: Position3D[] = [ + [1, 2, 3], + [4, 5, 6], + ]; + + const mds = [0, 1, 2]; + const mdsRes = [1, 2]; + + it("should remove duplicate", () => { + expect(removeConsecutiveDuplicates(coords, mds).length).toBe(2); + expect(removeConsecutiveDuplicates(coords, mds)[0]).not.toBe(coords); + expect(removeConsecutiveDuplicates(coords, mds)[0]).toStrictEqual( + coordsRes + ); + }); + + it("should remove corresponding md's", () => { + expect(removeConsecutiveDuplicates(coords, mds)[1]).toStrictEqual( + mdsRes + ); + }); +}); diff --git a/typescript/packages/subsurface-viewer/src/layers/wells/utils/spline.ts b/typescript/packages/subsurface-viewer/src/layers/wells/utils/spline.ts index 3aa9915a6..0d85e6dae 100644 --- a/typescript/packages/subsurface-viewer/src/layers/wells/utils/spline.ts +++ b/typescript/packages/subsurface-viewer/src/layers/wells/utils/spline.ts @@ -7,6 +7,68 @@ import { cloneDeep, range } from "lodash"; import type { Position3D } from "../../utils/layerTools"; import simplify from "@turf/simplify"; +export function removeConsecutiveDuplicates( + coords: Position3D[], + mds: number[] +): [Position3D[], number[]] { + // Filter out consecutive duplicate vertex's. + const keep = coords.map((e, index, arr) => { + if (index < arr.length - 1) { + return ( + e[0] !== arr[index + 1][0] || + e[1] !== arr[index + 1][1] || + e[2] !== arr[index + 1][2] + ); + } + return true; + }); + coords = coords.filter((_e, index) => { + return keep[index]; + }); + mds = mds.filter((_e: number, index: number) => { + return keep[index]; + }); + + return [coords, mds]; +} + +export function removeDuplicates(data: FeatureCollection): FeatureCollection { + const no_wells = data.features.length; + for (let well_no = 0; well_no < no_wells; well_no++) { + const mds = data.features[well_no].properties?.["md"]; + if (mds === undefined) { + continue; + } + const geometryCollection = data.features[well_no] + .geometry as GeometryCollection; + const lineString = geometryCollection?.geometries[1] as LineString; + + if (lineString.coordinates?.length === undefined) { + continue; + } + + let coords = lineString.coordinates as Position3D[]; + + [coords, mds[0]] = removeConsecutiveDuplicates(coords, mds[0]); + + const n = coords.length; + if (n <= 1) { + continue; + } + + ( + (data.features[well_no].geometry as GeometryCollection) + .geometries[1] as LineString + ).coordinates = coords; + + if (data.features[well_no].properties) { + data.features[well_no].properties!["md"] = mds; // eslint-disable-line + } + } + + return data; +} + /** * Given four points P0, P1, P2, P4 and a argument t in the interval [0,1]. * returns function value at t. t == 0 corresponds to P1 and t == 1 corrsponds to P2 @@ -136,25 +198,7 @@ export function splineRefine(data_in: FeatureCollection): FeatureCollection { continue; } - let coords = lineString.coordinates as Position3D[]; - - // Filter out consecutive duplicate vertex's. - const keep = coords.map((e, index, arr) => { - if (index < arr.length - 1) { - return ( - e[1] !== arr[index + 1][1] && - e[1] !== arr[index + 1][1] && - e[2] !== arr[index + 1][2] - ); - } - return true; - }); - coords = coords.filter((_e, index) => { - return keep[index]; - }); - mds[0] = mds[0].filter((_e: number, index: number) => { - return keep[index]; - }); + const coords = lineString.coordinates as Position3D[]; const n = coords.length; if (n <= 1) { @@ -258,7 +302,6 @@ export function coarsenWells(data_in: FeatureCollection): FeatureCollection { const data = cloneDeep(data_in); const no_wells = data.features.length; - for (let well_no = 0; well_no < no_wells; well_no++) { const geometryCollection = data.features[well_no] .geometry as GeometryCollection; @@ -268,14 +311,29 @@ export function coarsenWells(data_in: FeatureCollection): FeatureCollection { continue; } - const options = { - tolerance: 0.01, - highQuality: false, - mutate: false, - }; - - const coordsSimplified = simplify(lineString, options); - lineString.coordinates = coordsSimplified.coordinates as Position3D[]; + const n = lineString.coordinates.length; + const isHorizontalWell = + lineString.coordinates[0][0] == lineString.coordinates[n - 1][0] && + lineString.coordinates[0][1] == lineString.coordinates[n - 1][1]; + + if (isHorizontalWell) { + // The simplify algorithm below did not work on horizontal wells hence in this case we only use first and last point. + const coordsSimplified = [ + lineString.coordinates[0], + lineString.coordinates[n - 1], + ]; + lineString.coordinates = coordsSimplified; + } else { + const options = { + tolerance: 0.01, + highQuality: false, + mutate: false, + }; + + const coordsSimplified = simplify(lineString, options); + lineString.coordinates = + coordsSimplified.coordinates as Position3D[]; + } } return data; diff --git a/typescript/packages/subsurface-viewer/src/layers/wells/wellsLayer.stories.tsx b/typescript/packages/subsurface-viewer/src/layers/wells/wellsLayer.stories.tsx index 62c2811fa..308cb0fa7 100644 --- a/typescript/packages/subsurface-viewer/src/layers/wells/wellsLayer.stories.tsx +++ b/typescript/packages/subsurface-viewer/src/layers/wells/wellsLayer.stories.tsx @@ -437,6 +437,40 @@ Wells3d.parameters = { }, }; +export const OneWell = Template.bind({}); +OneWell.args = { + id: "well_176", + bounds: [756125, 166200, 757327, 167938], + layers: [ + { + "@@type": "WellsLayer", + data: "./well_176.json", + refine: true, + simplifiedRendering: true, + }, + ], + + views: { + layout: [1, 1], + viewports: [ + { + id: "a", + show3D: true, + }, + ], + }, +}; + +OneWell.parameters = { + docs: { + description: { + story: "One single well with duplicate vertexs example", + }, + inlineStories: false, + iframeHeight: 500, + }, +}; + // Gullfaks wells. export const SimplifiedRendering: ComponentStory = ( args diff --git a/typescript/packages/subsurface-viewer/src/layers/wells/wellsLayer.ts b/typescript/packages/subsurface-viewer/src/layers/wells/wellsLayer.ts index 1fccf7784..4511c3403 100644 --- a/typescript/packages/subsurface-viewer/src/layers/wells/wellsLayer.ts +++ b/typescript/packages/subsurface-viewer/src/layers/wells/wellsLayer.ts @@ -30,6 +30,7 @@ import { coarsenWells, invertPath, GetBoundingBox, + removeDuplicates as removeDuplicates, } from "./utils/spline"; import { interpolateNumberArray } from "d3"; import type { DeckGLLayerContext } from "../../components/Map"; @@ -248,6 +249,8 @@ export default class WellsLayer extends CompositeLayer { data = invertPath(data); } + removeDuplicates(data); + const refine = this.props.refine; data = refine ? splineRefine(data) // smooth well paths. @@ -409,6 +412,7 @@ export default class WellsLayer extends CompositeLayer { visible: fastDrawing, }) ); + const outlineLayer = new UnfoldedGeoJsonLayer( this.getSubLayerProps({ id: "outline", @@ -650,8 +654,7 @@ export default class WellsLayer extends CompositeLayer { }) ); - return [ - fastLayer, + const layers = [ outlineLayer, logLayer, colorsLayer, @@ -660,6 +663,10 @@ export default class WellsLayer extends CompositeLayer { selectionLayer, namesLayer, ]; + if (fastDrawing) { + layers.push(fastLayer as UnfoldedGeoJsonLayer); + } + return layers; } getPickingInfo({ info }: { info: PickingInfo }): WellsPickInfo {