jsts.mjs 626 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742
  1. /* Polyfill service v3.13.0
  2. * For detailed credits and licence information see http://github.com/financial-times/polyfill-service
  3. *
  4. * - Array.prototype.fill, License: CC0 */
  5. if (!('fill' in Array.prototype)) {
  6. Object.defineProperty(Array.prototype, 'fill', {
  7. configurable: true,
  8. value: function fill (value) {
  9. if (this === undefined || this === null) {
  10. throw new TypeError(this + ' is not an object')
  11. }
  12. var arrayLike = Object(this);
  13. var length = Math.max(Math.min(arrayLike.length, 9007199254740991), 0) || 0;
  14. var relativeStart = 1 in arguments ? parseInt(Number(arguments[1]), 10) || 0 : 0;
  15. relativeStart = relativeStart < 0 ? Math.max(length + relativeStart, 0) : Math.min(relativeStart, length);
  16. var relativeEnd = 2 in arguments && arguments[2] !== undefined ? parseInt(Number(arguments[2]), 10) || 0 : length;
  17. relativeEnd = relativeEnd < 0 ? Math.max(length + arguments[2], 0) : Math.min(relativeEnd, length);
  18. while (relativeStart < relativeEnd) {
  19. arrayLike[relativeStart] = value;
  20. ++relativeStart;
  21. }
  22. return arrayLike
  23. },
  24. writable: true
  25. });
  26. }
  27. /**
  28. * Polyfill for IE support
  29. */
  30. Number.isFinite = Number.isFinite || function (value) {
  31. return typeof value === 'number' && isFinite(value)
  32. };
  33. Number.isInteger = Number.isInteger || function (val) {
  34. return typeof val === 'number' &&
  35. isFinite(val) &&
  36. Math.floor(val) === val
  37. };
  38. Number.parseFloat = Number.parseFloat || parseFloat;
  39. Number.isNaN = Number.isNaN || function (value) {
  40. return value !== value // eslint-disable-line
  41. };
  42. /**
  43. * Polyfill for IE support
  44. */
  45. Math.trunc = Math.trunc || function (x) {
  46. return x < 0 ? Math.ceil(x) : Math.floor(x)
  47. };
  48. var NumberUtil = function NumberUtil () {};
  49. NumberUtil.prototype.interfaces_ = function interfaces_ () {
  50. return []
  51. };
  52. NumberUtil.prototype.getClass = function getClass () {
  53. return NumberUtil
  54. };
  55. NumberUtil.prototype.equalsWithTolerance = function equalsWithTolerance (x1, x2, tolerance) {
  56. return Math.abs(x1 - x2) <= tolerance
  57. };
  58. var IllegalArgumentException = (function (Error) {
  59. function IllegalArgumentException (message) {
  60. Error.call(this, message);
  61. this.name = 'IllegalArgumentException';
  62. this.message = message;
  63. this.stack = (new Error()).stack;
  64. }
  65. if ( Error ) IllegalArgumentException.__proto__ = Error;
  66. IllegalArgumentException.prototype = Object.create( Error && Error.prototype );
  67. IllegalArgumentException.prototype.constructor = IllegalArgumentException;
  68. return IllegalArgumentException;
  69. }(Error));
  70. var Double = function Double () {};
  71. var staticAccessors$1 = { MAX_VALUE: { configurable: true } };
  72. Double.isNaN = function isNaN (n) { return Number.isNaN(n) };
  73. Double.doubleToLongBits = function doubleToLongBits (n) { return n };
  74. Double.longBitsToDouble = function longBitsToDouble (n) { return n };
  75. Double.isInfinite = function isInfinite (n) { return !Number.isFinite(n) };
  76. staticAccessors$1.MAX_VALUE.get = function () { return Number.MAX_VALUE };
  77. Object.defineProperties( Double, staticAccessors$1 );
  78. var Comparable = function Comparable () {};
  79. var Clonable = function Clonable () {};
  80. var Comparator = function Comparator () {};
  81. function Serializable () {}
  82. // import Assert from '../util/Assert'
  83. var Coordinate = function Coordinate () {
  84. this.x = null;
  85. this.y = null;
  86. this.z = null;
  87. if (arguments.length === 0) {
  88. this.x = 0.0;
  89. this.y = 0.0;
  90. this.z = Coordinate.NULL_ORDINATE;
  91. } else if (arguments.length === 1) {
  92. var c = arguments[0];
  93. this.x = c.x;
  94. this.y = c.y;
  95. this.z = c.z;
  96. } else if (arguments.length === 2) {
  97. this.x = arguments[0];
  98. this.y = arguments[1];
  99. this.z = Coordinate.NULL_ORDINATE;
  100. } else if (arguments.length === 3) {
  101. this.x = arguments[0];
  102. this.y = arguments[1];
  103. this.z = arguments[2];
  104. }
  105. };
  106. var staticAccessors = { DimensionalComparator: { configurable: true },serialVersionUID: { configurable: true },NULL_ORDINATE: { configurable: true },X: { configurable: true },Y: { configurable: true },Z: { configurable: true } };
  107. Coordinate.prototype.setOrdinate = function setOrdinate (ordinateIndex, value) {
  108. switch (ordinateIndex) {
  109. case Coordinate.X:
  110. this.x = value;
  111. break
  112. case Coordinate.Y:
  113. this.y = value;
  114. break
  115. case Coordinate.Z:
  116. this.z = value;
  117. break
  118. default:
  119. throw new IllegalArgumentException('Invalid ordinate index: ' + ordinateIndex)
  120. }
  121. };
  122. Coordinate.prototype.equals2D = function equals2D () {
  123. if (arguments.length === 1) {
  124. var other = arguments[0];
  125. if (this.x !== other.x) {
  126. return false
  127. }
  128. if (this.y !== other.y) {
  129. return false
  130. }
  131. return true
  132. } else if (arguments.length === 2) {
  133. var c = arguments[0];
  134. var tolerance = arguments[1];
  135. if (!NumberUtil.equalsWithTolerance(this.x, c.x, tolerance)) {
  136. return false
  137. }
  138. if (!NumberUtil.equalsWithTolerance(this.y, c.y, tolerance)) {
  139. return false
  140. }
  141. return true
  142. }
  143. };
  144. Coordinate.prototype.getOrdinate = function getOrdinate (ordinateIndex) {
  145. switch (ordinateIndex) {
  146. case Coordinate.X:
  147. return this.x
  148. case Coordinate.Y:
  149. return this.y
  150. case Coordinate.Z:
  151. return this.z
  152. default:
  153. }
  154. throw new IllegalArgumentException('Invalid ordinate index: ' + ordinateIndex)
  155. };
  156. Coordinate.prototype.equals3D = function equals3D (other) {
  157. return this.x === other.x &&
  158. this.y === other.y &&
  159. ((this.z === other.z || Double.isNaN(this.z)) &&
  160. Double.isNaN(other.z))
  161. };
  162. Coordinate.prototype.equals = function equals (other) {
  163. if (!(other instanceof Coordinate)) {
  164. return false
  165. }
  166. return this.equals2D(other)
  167. };
  168. Coordinate.prototype.equalInZ = function equalInZ (c, tolerance) {
  169. return NumberUtil.equalsWithTolerance(this.z, c.z, tolerance)
  170. };
  171. Coordinate.prototype.compareTo = function compareTo (o) {
  172. var other = o;
  173. if (this.x < other.x) { return -1 }
  174. if (this.x > other.x) { return 1 }
  175. if (this.y < other.y) { return -1 }
  176. if (this.y > other.y) { return 1 }
  177. return 0
  178. };
  179. Coordinate.prototype.clone = function clone () {
  180. // try {
  181. // var coord = null
  182. // return coord
  183. // } catch (e) {
  184. // if (e instanceof CloneNotSupportedException) {
  185. // Assert.shouldNeverReachHere("this shouldn't happen because this class is Cloneable")
  186. // return null
  187. // } else throw e
  188. // } finally {}
  189. };
  190. Coordinate.prototype.copy = function copy () {
  191. return new Coordinate(this)
  192. };
  193. Coordinate.prototype.toString = function toString () {
  194. return '(' + this.x + ', ' + this.y + ', ' + this.z + ')'
  195. };
  196. Coordinate.prototype.distance3D = function distance3D (c) {
  197. var dx = this.x - c.x;
  198. var dy = this.y - c.y;
  199. var dz = this.z - c.z;
  200. return Math.sqrt(dx * dx + dy * dy + dz * dz)
  201. };
  202. Coordinate.prototype.distance = function distance (c) {
  203. var dx = this.x - c.x;
  204. var dy = this.y - c.y;
  205. return Math.sqrt(dx * dx + dy * dy)
  206. };
  207. Coordinate.prototype.hashCode = function hashCode () {
  208. var result = 17;
  209. result = 37 * result + Coordinate.hashCode(this.x);
  210. result = 37 * result + Coordinate.hashCode(this.y);
  211. return result
  212. };
  213. Coordinate.prototype.setCoordinate = function setCoordinate (other) {
  214. this.x = other.x;
  215. this.y = other.y;
  216. this.z = other.z;
  217. };
  218. Coordinate.prototype.interfaces_ = function interfaces_ () {
  219. return [Comparable, Clonable, Serializable]
  220. };
  221. Coordinate.prototype.getClass = function getClass () {
  222. return Coordinate
  223. };
  224. Coordinate.hashCode = function hashCode () {
  225. if (arguments.length === 1) {
  226. var x = arguments[0];
  227. var f = Double.doubleToLongBits(x);
  228. return Math.trunc((f ^ f) >>> 32)
  229. }
  230. };
  231. staticAccessors.DimensionalComparator.get = function () { return DimensionalComparator };
  232. staticAccessors.serialVersionUID.get = function () { return 6683108902428366910 };
  233. staticAccessors.NULL_ORDINATE.get = function () { return Double.NaN };
  234. staticAccessors.X.get = function () { return 0 };
  235. staticAccessors.Y.get = function () { return 1 };
  236. staticAccessors.Z.get = function () { return 2 };
  237. Object.defineProperties( Coordinate, staticAccessors );
  238. var DimensionalComparator = function DimensionalComparator (dimensionsToTest) {
  239. this._dimensionsToTest = 2;
  240. if (arguments.length === 0) {} else if (arguments.length === 1) {
  241. var dimensionsToTest$1 = arguments[0];
  242. if (dimensionsToTest$1 !== 2 && dimensionsToTest$1 !== 3) { throw new IllegalArgumentException('only 2 or 3 dimensions may be specified') }
  243. this._dimensionsToTest = dimensionsToTest$1;
  244. }
  245. };
  246. DimensionalComparator.prototype.compare = function compare (o1, o2) {
  247. var c1 = o1;
  248. var c2 = o2;
  249. var compX = DimensionalComparator.compare(c1.x, c2.x);
  250. if (compX !== 0) { return compX }
  251. var compY = DimensionalComparator.compare(c1.y, c2.y);
  252. if (compY !== 0) { return compY }
  253. if (this._dimensionsToTest <= 2) { return 0 }
  254. var compZ = DimensionalComparator.compare(c1.z, c2.z);
  255. return compZ
  256. };
  257. DimensionalComparator.prototype.interfaces_ = function interfaces_ () {
  258. return [Comparator]
  259. };
  260. DimensionalComparator.prototype.getClass = function getClass () {
  261. return DimensionalComparator
  262. };
  263. DimensionalComparator.compare = function compare (a, b) {
  264. if (a < b) { return -1 }
  265. if (a > b) { return 1 }
  266. if (Double.isNaN(a)) {
  267. if (Double.isNaN(b)) { return 0 }
  268. return -1
  269. }
  270. if (Double.isNaN(b)) { return 1 }
  271. return 0
  272. };
  273. // import hasInterface from '../../../../hasInterface'
  274. // import CoordinateSequence from './CoordinateSequence'
  275. var CoordinateSequenceFactory = function CoordinateSequenceFactory () {};
  276. CoordinateSequenceFactory.prototype.create = function create () {
  277. // if (arguments.length === 1) {
  278. // if (arguments[0] instanceof Array) {
  279. // let coordinates = arguments[0]
  280. // } else if (hasInterface(arguments[0], CoordinateSequence)) {
  281. // let coordSeq = arguments[0]
  282. // }
  283. // } else if (arguments.length === 2) {
  284. // let size = arguments[0]
  285. // let dimension = arguments[1]
  286. // }
  287. };
  288. CoordinateSequenceFactory.prototype.interfaces_ = function interfaces_ () {
  289. return []
  290. };
  291. CoordinateSequenceFactory.prototype.getClass = function getClass () {
  292. return CoordinateSequenceFactory
  293. };
  294. var Location = function Location () {};
  295. var staticAccessors$4 = { INTERIOR: { configurable: true },BOUNDARY: { configurable: true },EXTERIOR: { configurable: true },NONE: { configurable: true } };
  296. Location.prototype.interfaces_ = function interfaces_ () {
  297. return []
  298. };
  299. Location.prototype.getClass = function getClass () {
  300. return Location
  301. };
  302. Location.toLocationSymbol = function toLocationSymbol (locationValue) {
  303. switch (locationValue) {
  304. case Location.EXTERIOR:
  305. return 'e'
  306. case Location.BOUNDARY:
  307. return 'b'
  308. case Location.INTERIOR:
  309. return 'i'
  310. case Location.NONE:
  311. return '-'
  312. default:
  313. }
  314. throw new IllegalArgumentException('Unknown location value: ' + locationValue)
  315. };
  316. staticAccessors$4.INTERIOR.get = function () { return 0 };
  317. staticAccessors$4.BOUNDARY.get = function () { return 1 };
  318. staticAccessors$4.EXTERIOR.get = function () { return 2 };
  319. staticAccessors$4.NONE.get = function () { return -1 };
  320. Object.defineProperties( Location, staticAccessors$4 );
  321. var hasInterface = function (o, i) {
  322. return o.interfaces_ && o.interfaces_().indexOf(i) > -1
  323. };
  324. var MathUtil = function MathUtil () {};
  325. var staticAccessors$5 = { LOG_10: { configurable: true } };
  326. MathUtil.prototype.interfaces_ = function interfaces_ () {
  327. return []
  328. };
  329. MathUtil.prototype.getClass = function getClass () {
  330. return MathUtil
  331. };
  332. MathUtil.log10 = function log10 (x) {
  333. var ln = Math.log(x);
  334. if (Double.isInfinite(ln)) { return ln }
  335. if (Double.isNaN(ln)) { return ln }
  336. return ln / MathUtil.LOG_10
  337. };
  338. MathUtil.min = function min (v1, v2, v3, v4) {
  339. var min = v1;
  340. if (v2 < min) { min = v2; }
  341. if (v3 < min) { min = v3; }
  342. if (v4 < min) { min = v4; }
  343. return min
  344. };
  345. MathUtil.clamp = function clamp () {
  346. if (typeof arguments[2] === 'number' && (typeof arguments[0] === 'number' && typeof arguments[1] === 'number')) {
  347. var x = arguments[0];
  348. var min = arguments[1];
  349. var max = arguments[2];
  350. if (x < min) { return min }
  351. if (x > max) { return max }
  352. return x
  353. } else if (Number.isInteger(arguments[2]) && (Number.isInteger(arguments[0]) && Number.isInteger(arguments[1]))) {
  354. var x$1 = arguments[0];
  355. var min$1 = arguments[1];
  356. var max$1 = arguments[2];
  357. if (x$1 < min$1) { return min$1 }
  358. if (x$1 > max$1) { return max$1 }
  359. return x$1
  360. }
  361. };
  362. MathUtil.wrap = function wrap (index, max) {
  363. if (index < 0) {
  364. return max - -index % max
  365. }
  366. return index % max
  367. };
  368. MathUtil.max = function max () {
  369. if (arguments.length === 3) {
  370. var v1 = arguments[0];
  371. var v2 = arguments[1];
  372. var v3 = arguments[2];
  373. var max = v1;
  374. if (v2 > max) { max = v2; }
  375. if (v3 > max) { max = v3; }
  376. return max
  377. } else if (arguments.length === 4) {
  378. var v1$1 = arguments[0];
  379. var v2$1 = arguments[1];
  380. var v3$1 = arguments[2];
  381. var v4 = arguments[3];
  382. var max$1 = v1$1;
  383. if (v2$1 > max$1) { max$1 = v2$1; }
  384. if (v3$1 > max$1) { max$1 = v3$1; }
  385. if (v4 > max$1) { max$1 = v4; }
  386. return max$1
  387. }
  388. };
  389. MathUtil.average = function average (x1, x2) {
  390. return (x1 + x2) / 2.0
  391. };
  392. staticAccessors$5.LOG_10.get = function () { return Math.log(10) };
  393. Object.defineProperties( MathUtil, staticAccessors$5 );
  394. var StringBuffer = function StringBuffer (str) {
  395. this.str = str;
  396. };
  397. StringBuffer.prototype.append = function append (e) {
  398. this.str += e;
  399. };
  400. StringBuffer.prototype.setCharAt = function setCharAt (i, c) {
  401. this.str = this.str.substr(0, i) + c + this.str.substr(i + 1);
  402. };
  403. StringBuffer.prototype.toString = function toString (e) {
  404. return this.str
  405. };
  406. var Integer = function Integer (value) {
  407. this.value = value;
  408. };
  409. Integer.prototype.intValue = function intValue () {
  410. return this.value
  411. };
  412. Integer.prototype.compareTo = function compareTo (o) {
  413. if (this.value < o) { return -1 }
  414. if (this.value > o) { return 1 }
  415. return 0
  416. };
  417. Integer.isNaN = function isNaN (n) { return Number.isNaN(n) };
  418. var Character = function Character () {};
  419. Character.isWhitespace = function isWhitespace (c) { return ((c <= 32 && c >= 0) || c === 127) };
  420. Character.toUpperCase = function toUpperCase (c) { return c.toUpperCase() };
  421. var DD = function DD () {
  422. this._hi = 0.0;
  423. this._lo = 0.0;
  424. if (arguments.length === 0) {
  425. this.init(0.0);
  426. } else if (arguments.length === 1) {
  427. if (typeof arguments[0] === 'number') {
  428. var x = arguments[0];
  429. this.init(x);
  430. } else if (arguments[0] instanceof DD) {
  431. var dd = arguments[0];
  432. this.init(dd);
  433. } else if (typeof arguments[0] === 'string') {
  434. var str = arguments[0];
  435. DD.call(this, DD.parse(str));
  436. }
  437. } else if (arguments.length === 2) {
  438. var hi = arguments[0];
  439. var lo = arguments[1];
  440. this.init(hi, lo);
  441. }
  442. };
  443. var staticAccessors$7 = { PI: { configurable: true },TWO_PI: { configurable: true },PI_2: { configurable: true },E: { configurable: true },NaN: { configurable: true },EPS: { configurable: true },SPLIT: { configurable: true },MAX_PRINT_DIGITS: { configurable: true },TEN: { configurable: true },ONE: { configurable: true },SCI_NOT_EXPONENT_CHAR: { configurable: true },SCI_NOT_ZERO: { configurable: true } };
  444. DD.prototype.le = function le (y) {
  445. return (this._hi < y._hi || this._hi === y._hi) && this._lo <= y._lo
  446. };
  447. DD.prototype.extractSignificantDigits = function extractSignificantDigits (insertDecimalPoint, magnitude) {
  448. var y = this.abs();
  449. var mag = DD.magnitude(y._hi);
  450. var scale = DD.TEN.pow(mag);
  451. y = y.divide(scale);
  452. if (y.gt(DD.TEN)) {
  453. y = y.divide(DD.TEN);
  454. mag += 1;
  455. } else if (y.lt(DD.ONE)) {
  456. y = y.multiply(DD.TEN);
  457. mag -= 1;
  458. }
  459. var decimalPointPos = mag + 1;
  460. var buf = new StringBuffer();
  461. var numDigits = DD.MAX_PRINT_DIGITS - 1;
  462. for (var i = 0; i <= numDigits; i++) {
  463. if (insertDecimalPoint && i === decimalPointPos) {
  464. buf.append('.');
  465. }
  466. var digit = Math.trunc(y._hi);
  467. if (digit < 0) {
  468. break
  469. }
  470. var rebiasBy10 = false;
  471. var digitChar = 0;
  472. if (digit > 9) {
  473. rebiasBy10 = true;
  474. digitChar = '9';
  475. } else {
  476. digitChar = '0' + digit;
  477. }
  478. buf.append(digitChar);
  479. y = y.subtract(DD.valueOf(digit)).multiply(DD.TEN);
  480. if (rebiasBy10) { y.selfAdd(DD.TEN); }
  481. var continueExtractingDigits = true;
  482. var remMag = DD.magnitude(y._hi);
  483. if (remMag < 0 && Math.abs(remMag) >= numDigits - i) { continueExtractingDigits = false; }
  484. if (!continueExtractingDigits) { break }
  485. }
  486. magnitude[0] = mag;
  487. return buf.toString()
  488. };
  489. DD.prototype.sqr = function sqr () {
  490. return this.multiply(this)
  491. };
  492. DD.prototype.doubleValue = function doubleValue () {
  493. return this._hi + this._lo
  494. };
  495. DD.prototype.subtract = function subtract () {
  496. if (arguments[0] instanceof DD) {
  497. var y = arguments[0];
  498. return this.add(y.negate())
  499. } else if (typeof arguments[0] === 'number') {
  500. var y$1 = arguments[0];
  501. return this.add(-y$1)
  502. }
  503. };
  504. DD.prototype.equals = function equals () {
  505. if (arguments.length === 1) {
  506. var y = arguments[0];
  507. return this._hi === y._hi && this._lo === y._lo
  508. }
  509. };
  510. DD.prototype.isZero = function isZero () {
  511. return this._hi === 0.0 && this._lo === 0.0
  512. };
  513. DD.prototype.selfSubtract = function selfSubtract () {
  514. if (arguments[0] instanceof DD) {
  515. var y = arguments[0];
  516. if (this.isNaN()) { return this }
  517. return this.selfAdd(-y._hi, -y._lo)
  518. } else if (typeof arguments[0] === 'number') {
  519. var y$1 = arguments[0];
  520. if (this.isNaN()) { return this }
  521. return this.selfAdd(-y$1, 0.0)
  522. }
  523. };
  524. DD.prototype.getSpecialNumberString = function getSpecialNumberString () {
  525. if (this.isZero()) { return '0.0' }
  526. if (this.isNaN()) { return 'NaN ' }
  527. return null
  528. };
  529. DD.prototype.min = function min (x) {
  530. if (this.le(x)) {
  531. return this
  532. } else {
  533. return x
  534. }
  535. };
  536. DD.prototype.selfDivide = function selfDivide () {
  537. if (arguments.length === 1) {
  538. if (arguments[0] instanceof DD) {
  539. var y = arguments[0];
  540. return this.selfDivide(y._hi, y._lo)
  541. } else if (typeof arguments[0] === 'number') {
  542. var y$1 = arguments[0];
  543. return this.selfDivide(y$1, 0.0)
  544. }
  545. } else if (arguments.length === 2) {
  546. var yhi = arguments[0];
  547. var ylo = arguments[1];
  548. var hc = null;
  549. var tc = null;
  550. var hy = null;
  551. var ty = null;
  552. var C = null;
  553. var c = null;
  554. var U = null;
  555. var u = null;
  556. C = this._hi / yhi;
  557. c = DD.SPLIT * C;
  558. hc = c - C;
  559. u = DD.SPLIT * yhi;
  560. hc = c - hc;
  561. tc = C - hc;
  562. hy = u - yhi;
  563. U = C * yhi;
  564. hy = u - hy;
  565. ty = yhi - hy;
  566. u = hc * hy - U + hc * ty + tc * hy + tc * ty;
  567. c = (this._hi - U - u + this._lo - C * ylo) / yhi;
  568. u = C + c;
  569. this._hi = u;
  570. this._lo = C - u + c;
  571. return this
  572. }
  573. };
  574. DD.prototype.dump = function dump () {
  575. return 'DD<' + this._hi + ', ' + this._lo + '>'
  576. };
  577. DD.prototype.divide = function divide () {
  578. if (arguments[0] instanceof DD) {
  579. var y = arguments[0];
  580. var hc = null;
  581. var tc = null;
  582. var hy = null;
  583. var ty = null;
  584. var C = null;
  585. var c = null;
  586. var U = null;
  587. var u = null;
  588. C = this._hi / y._hi;
  589. c = DD.SPLIT * C;
  590. hc = c - C;
  591. u = DD.SPLIT * y._hi;
  592. hc = c - hc;
  593. tc = C - hc;
  594. hy = u - y._hi;
  595. U = C * y._hi;
  596. hy = u - hy;
  597. ty = y._hi - hy;
  598. u = hc * hy - U + hc * ty + tc * hy + tc * ty;
  599. c = (this._hi - U - u + this._lo - C * y._lo) / y._hi;
  600. u = C + c;
  601. var zhi = u;
  602. var zlo = C - u + c;
  603. return new DD(zhi, zlo)
  604. } else if (typeof arguments[0] === 'number') {
  605. var y$1 = arguments[0];
  606. if (Double.isNaN(y$1)) { return DD.createNaN() }
  607. return DD.copy(this).selfDivide(y$1, 0.0)
  608. }
  609. };
  610. DD.prototype.ge = function ge (y) {
  611. return (this._hi > y._hi || this._hi === y._hi) && this._lo >= y._lo
  612. };
  613. DD.prototype.pow = function pow (exp) {
  614. if (exp === 0.0) { return DD.valueOf(1.0) }
  615. var r = new DD(this);
  616. var s = DD.valueOf(1.0);
  617. var n = Math.abs(exp);
  618. if (n > 1) {
  619. while (n > 0) {
  620. if (n % 2 === 1) {
  621. s.selfMultiply(r);
  622. }
  623. n /= 2;
  624. if (n > 0) { r = r.sqr(); }
  625. }
  626. } else {
  627. s = r;
  628. }
  629. if (exp < 0) { return s.reciprocal() }
  630. return s
  631. };
  632. DD.prototype.ceil = function ceil () {
  633. if (this.isNaN()) { return DD.NaN }
  634. var fhi = Math.ceil(this._hi);
  635. var flo = 0.0;
  636. if (fhi === this._hi) {
  637. flo = Math.ceil(this._lo);
  638. }
  639. return new DD(fhi, flo)
  640. };
  641. DD.prototype.compareTo = function compareTo (o) {
  642. var other = o;
  643. if (this._hi < other._hi) { return -1 }
  644. if (this._hi > other._hi) { return 1 }
  645. if (this._lo < other._lo) { return -1 }
  646. if (this._lo > other._lo) { return 1 }
  647. return 0
  648. };
  649. DD.prototype.rint = function rint () {
  650. if (this.isNaN()) { return this }
  651. var plus5 = this.add(0.5);
  652. return plus5.floor()
  653. };
  654. DD.prototype.setValue = function setValue () {
  655. if (arguments[0] instanceof DD) {
  656. var value = arguments[0];
  657. this.init(value);
  658. return this
  659. } else if (typeof arguments[0] === 'number') {
  660. var value$1 = arguments[0];
  661. this.init(value$1);
  662. return this
  663. }
  664. };
  665. DD.prototype.max = function max (x) {
  666. if (this.ge(x)) {
  667. return this
  668. } else {
  669. return x
  670. }
  671. };
  672. DD.prototype.sqrt = function sqrt () {
  673. if (this.isZero()) { return DD.valueOf(0.0) }
  674. if (this.isNegative()) {
  675. return DD.NaN
  676. }
  677. var x = 1.0 / Math.sqrt(this._hi);
  678. var ax = this._hi * x;
  679. var axdd = DD.valueOf(ax);
  680. var diffSq = this.subtract(axdd.sqr());
  681. var d2 = diffSq._hi * (x * 0.5);
  682. return axdd.add(d2)
  683. };
  684. DD.prototype.selfAdd = function selfAdd () {
  685. if (arguments.length === 1) {
  686. if (arguments[0] instanceof DD) {
  687. var y = arguments[0];
  688. return this.selfAdd(y._hi, y._lo)
  689. } else if (typeof arguments[0] === 'number') {
  690. var y$1 = arguments[0];
  691. var H = null;
  692. var h = null;
  693. var S = null;
  694. var s = null;
  695. var e = null;
  696. var f = null;
  697. S = this._hi + y$1;
  698. e = S - this._hi;
  699. s = S - e;
  700. s = y$1 - e + (this._hi - s);
  701. f = s + this._lo;
  702. H = S + f;
  703. h = f + (S - H);
  704. this._hi = H + h;
  705. this._lo = h + (H - this._hi);
  706. return this
  707. }
  708. } else if (arguments.length === 2) {
  709. var yhi = arguments[0];
  710. var ylo = arguments[1];
  711. var H$1 = null;
  712. var h$1 = null;
  713. var T = null;
  714. var t = null;
  715. var S$1 = null;
  716. var s$1 = null;
  717. var e$1 = null;
  718. var f$1 = null;
  719. S$1 = this._hi + yhi;
  720. T = this._lo + ylo;
  721. e$1 = S$1 - this._hi;
  722. f$1 = T - this._lo;
  723. s$1 = S$1 - e$1;
  724. t = T - f$1;
  725. s$1 = yhi - e$1 + (this._hi - s$1);
  726. t = ylo - f$1 + (this._lo - t);
  727. e$1 = s$1 + T;
  728. H$1 = S$1 + e$1;
  729. h$1 = e$1 + (S$1 - H$1);
  730. e$1 = t + h$1;
  731. var zhi = H$1 + e$1;
  732. var zlo = e$1 + (H$1 - zhi);
  733. this._hi = zhi;
  734. this._lo = zlo;
  735. return this
  736. }
  737. };
  738. DD.prototype.selfMultiply = function selfMultiply () {
  739. if (arguments.length === 1) {
  740. if (arguments[0] instanceof DD) {
  741. var y = arguments[0];
  742. return this.selfMultiply(y._hi, y._lo)
  743. } else if (typeof arguments[0] === 'number') {
  744. var y$1 = arguments[0];
  745. return this.selfMultiply(y$1, 0.0)
  746. }
  747. } else if (arguments.length === 2) {
  748. var yhi = arguments[0];
  749. var ylo = arguments[1];
  750. var hx = null;
  751. var tx = null;
  752. var hy = null;
  753. var ty = null;
  754. var C = null;
  755. var c = null;
  756. C = DD.SPLIT * this._hi;
  757. hx = C - this._hi;
  758. c = DD.SPLIT * yhi;
  759. hx = C - hx;
  760. tx = this._hi - hx;
  761. hy = c - yhi;
  762. C = this._hi * yhi;
  763. hy = c - hy;
  764. ty = yhi - hy;
  765. c = hx * hy - C + hx * ty + tx * hy + tx * ty + (this._hi * ylo + this._lo * yhi);
  766. var zhi = C + c;
  767. hx = C - zhi;
  768. var zlo = c + hx;
  769. this._hi = zhi;
  770. this._lo = zlo;
  771. return this
  772. }
  773. };
  774. DD.prototype.selfSqr = function selfSqr () {
  775. return this.selfMultiply(this)
  776. };
  777. DD.prototype.floor = function floor () {
  778. if (this.isNaN()) { return DD.NaN }
  779. var fhi = Math.floor(this._hi);
  780. var flo = 0.0;
  781. if (fhi === this._hi) {
  782. flo = Math.floor(this._lo);
  783. }
  784. return new DD(fhi, flo)
  785. };
  786. DD.prototype.negate = function negate () {
  787. if (this.isNaN()) { return this }
  788. return new DD(-this._hi, -this._lo)
  789. };
  790. DD.prototype.clone = function clone () {
  791. // try {
  792. // return null
  793. // } catch (ex) {
  794. // if (ex instanceof CloneNotSupportedException) {
  795. // return null
  796. // } else throw ex
  797. // } finally {}
  798. };
  799. DD.prototype.multiply = function multiply () {
  800. if (arguments[0] instanceof DD) {
  801. var y = arguments[0];
  802. if (y.isNaN()) { return DD.createNaN() }
  803. return DD.copy(this).selfMultiply(y)
  804. } else if (typeof arguments[0] === 'number') {
  805. var y$1 = arguments[0];
  806. if (Double.isNaN(y$1)) { return DD.createNaN() }
  807. return DD.copy(this).selfMultiply(y$1, 0.0)
  808. }
  809. };
  810. DD.prototype.isNaN = function isNaN () {
  811. return Double.isNaN(this._hi)
  812. };
  813. DD.prototype.intValue = function intValue () {
  814. return Math.trunc(this._hi)
  815. };
  816. DD.prototype.toString = function toString () {
  817. var mag = DD.magnitude(this._hi);
  818. if (mag >= -3 && mag <= 20) { return this.toStandardNotation() }
  819. return this.toSciNotation()
  820. };
  821. DD.prototype.toStandardNotation = function toStandardNotation () {
  822. var specialStr = this.getSpecialNumberString();
  823. if (specialStr !== null) { return specialStr }
  824. var magnitude = new Array(1).fill(null);
  825. var sigDigits = this.extractSignificantDigits(true, magnitude);
  826. var decimalPointPos = magnitude[0] + 1;
  827. var num = sigDigits;
  828. if (sigDigits.charAt(0) === '.') {
  829. num = '0' + sigDigits;
  830. } else if (decimalPointPos < 0) {
  831. num = '0.' + DD.stringOfChar('0', -decimalPointPos) + sigDigits;
  832. } else if (sigDigits.indexOf('.') === -1) {
  833. var numZeroes = decimalPointPos - sigDigits.length;
  834. var zeroes = DD.stringOfChar('0', numZeroes);
  835. num = sigDigits + zeroes + '.0';
  836. }
  837. if (this.isNegative()) { return '-' + num }
  838. return num
  839. };
  840. DD.prototype.reciprocal = function reciprocal () {
  841. var hc = null;
  842. var tc = null;
  843. var hy = null;
  844. var ty = null;
  845. var C = null;
  846. var c = null;
  847. var U = null;
  848. var u = null;
  849. C = 1.0 / this._hi;
  850. c = DD.SPLIT * C;
  851. hc = c - C;
  852. u = DD.SPLIT * this._hi;
  853. hc = c - hc;
  854. tc = C - hc;
  855. hy = u - this._hi;
  856. U = C * this._hi;
  857. hy = u - hy;
  858. ty = this._hi - hy;
  859. u = hc * hy - U + hc * ty + tc * hy + tc * ty;
  860. c = (1.0 - U - u - C * this._lo) / this._hi;
  861. var zhi = C + c;
  862. var zlo = C - zhi + c;
  863. return new DD(zhi, zlo)
  864. };
  865. DD.prototype.toSciNotation = function toSciNotation () {
  866. if (this.isZero()) { return DD.SCI_NOT_ZERO }
  867. var specialStr = this.getSpecialNumberString();
  868. if (specialStr !== null) { return specialStr }
  869. var magnitude = new Array(1).fill(null);
  870. var digits = this.extractSignificantDigits(false, magnitude);
  871. var expStr = DD.SCI_NOT_EXPONENT_CHAR + magnitude[0];
  872. if (digits.charAt(0) === '0') {
  873. throw new Error('Found leading zero: ' + digits)
  874. }
  875. var trailingDigits = '';
  876. if (digits.length > 1) { trailingDigits = digits.substring(1); }
  877. var digitsWithDecimal = digits.charAt(0) + '.' + trailingDigits;
  878. if (this.isNegative()) { return '-' + digitsWithDecimal + expStr }
  879. return digitsWithDecimal + expStr
  880. };
  881. DD.prototype.abs = function abs () {
  882. if (this.isNaN()) { return DD.NaN }
  883. if (this.isNegative()) { return this.negate() }
  884. return new DD(this)
  885. };
  886. DD.prototype.isPositive = function isPositive () {
  887. return (this._hi > 0.0 || this._hi === 0.0) && this._lo > 0.0
  888. };
  889. DD.prototype.lt = function lt (y) {
  890. return (this._hi < y._hi || this._hi === y._hi) && this._lo < y._lo
  891. };
  892. DD.prototype.add = function add () {
  893. if (arguments[0] instanceof DD) {
  894. var y = arguments[0];
  895. return DD.copy(this).selfAdd(y)
  896. } else if (typeof arguments[0] === 'number') {
  897. var y$1 = arguments[0];
  898. return DD.copy(this).selfAdd(y$1)
  899. }
  900. };
  901. DD.prototype.init = function init () {
  902. if (arguments.length === 1) {
  903. if (typeof arguments[0] === 'number') {
  904. var x = arguments[0];
  905. this._hi = x;
  906. this._lo = 0.0;
  907. } else if (arguments[0] instanceof DD) {
  908. var dd = arguments[0];
  909. this._hi = dd._hi;
  910. this._lo = dd._lo;
  911. }
  912. } else if (arguments.length === 2) {
  913. var hi = arguments[0];
  914. var lo = arguments[1];
  915. this._hi = hi;
  916. this._lo = lo;
  917. }
  918. };
  919. DD.prototype.gt = function gt (y) {
  920. return (this._hi > y._hi || this._hi === y._hi) && this._lo > y._lo
  921. };
  922. DD.prototype.isNegative = function isNegative () {
  923. return (this._hi < 0.0 || this._hi === 0.0) && this._lo < 0.0
  924. };
  925. DD.prototype.trunc = function trunc () {
  926. if (this.isNaN()) { return DD.NaN }
  927. if (this.isPositive()) { return this.floor(); } else { return this.ceil() }
  928. };
  929. DD.prototype.signum = function signum () {
  930. if (this._hi > 0) { return 1 }
  931. if (this._hi < 0) { return -1 }
  932. if (this._lo > 0) { return 1 }
  933. if (this._lo < 0) { return -1 }
  934. return 0
  935. };
  936. DD.prototype.interfaces_ = function interfaces_ () {
  937. return [Serializable, Comparable, Clonable]
  938. };
  939. DD.prototype.getClass = function getClass () {
  940. return DD
  941. };
  942. DD.sqr = function sqr (x) {
  943. return DD.valueOf(x).selfMultiply(x)
  944. };
  945. DD.valueOf = function valueOf () {
  946. if (typeof arguments[0] === 'string') {
  947. var str = arguments[0];
  948. return DD.parse(str)
  949. } else if (typeof arguments[0] === 'number') {
  950. var x = arguments[0];
  951. return new DD(x)
  952. }
  953. };
  954. DD.sqrt = function sqrt (x) {
  955. return DD.valueOf(x).sqrt()
  956. };
  957. DD.parse = function parse (str) {
  958. var i = 0;
  959. var strlen = str.length;
  960. while (Character.isWhitespace(str.charAt(i))) { i++; }
  961. var isNegative = false;
  962. if (i < strlen) {
  963. var signCh = str.charAt(i);
  964. if (signCh === '-' || signCh === '+') {
  965. i++;
  966. if (signCh === '-') { isNegative = true; }
  967. }
  968. }
  969. var val = new DD();
  970. var numDigits = 0;
  971. var numBeforeDec = 0;
  972. var exp = 0;
  973. while (true) {
  974. if (i >= strlen) { break }
  975. var ch = str.charAt(i);
  976. i++;
  977. if (Character.isDigit(ch)) {
  978. var d = ch - '0';
  979. val.selfMultiply(DD.TEN);
  980. val.selfAdd(d);
  981. numDigits++;
  982. continue
  983. }
  984. if (ch === '.') {
  985. numBeforeDec = numDigits;
  986. continue
  987. }
  988. if (ch === 'e' || ch === 'E') {
  989. var expStr = str.substring(i);
  990. try {
  991. exp = Integer.parseInt(expStr);
  992. } catch (ex) {
  993. if (ex instanceof Error) {
  994. throw new Error('Invalid exponent ' + expStr + ' in string ' + str)
  995. } else { throw ex }
  996. } finally {}
  997. break
  998. }
  999. throw new Error("Unexpected character '" + ch + "' at position " + i + ' in string ' + str)
  1000. }
  1001. var val2 = val;
  1002. var numDecPlaces = numDigits - numBeforeDec - exp;
  1003. if (numDecPlaces === 0) {
  1004. val2 = val;
  1005. } else if (numDecPlaces > 0) {
  1006. var scale = DD.TEN.pow(numDecPlaces);
  1007. val2 = val.divide(scale);
  1008. } else if (numDecPlaces < 0) {
  1009. var scale$1 = DD.TEN.pow(-numDecPlaces);
  1010. val2 = val.multiply(scale$1);
  1011. }
  1012. if (isNegative) {
  1013. return val2.negate()
  1014. }
  1015. return val2
  1016. };
  1017. DD.createNaN = function createNaN () {
  1018. return new DD(Double.NaN, Double.NaN)
  1019. };
  1020. DD.copy = function copy (dd) {
  1021. return new DD(dd)
  1022. };
  1023. DD.magnitude = function magnitude (x) {
  1024. var xAbs = Math.abs(x);
  1025. var xLog10 = Math.log(xAbs) / Math.log(10);
  1026. var xMag = Math.trunc(Math.floor(xLog10));
  1027. var xApprox = Math.pow(10, xMag);
  1028. if (xApprox * 10 <= xAbs) { xMag += 1; }
  1029. return xMag
  1030. };
  1031. DD.stringOfChar = function stringOfChar (ch, len) {
  1032. var buf = new StringBuffer();
  1033. for (var i = 0; i < len; i++) {
  1034. buf.append(ch);
  1035. }
  1036. return buf.toString()
  1037. };
  1038. staticAccessors$7.PI.get = function () { return new DD(3.141592653589793116e+00, 1.224646799147353207e-16) };
  1039. staticAccessors$7.TWO_PI.get = function () { return new DD(6.283185307179586232e+00, 2.449293598294706414e-16) };
  1040. staticAccessors$7.PI_2.get = function () { return new DD(1.570796326794896558e+00, 6.123233995736766036e-17) };
  1041. staticAccessors$7.E.get = function () { return new DD(2.718281828459045091e+00, 1.445646891729250158e-16) };
  1042. staticAccessors$7.NaN.get = function () { return new DD(Double.NaN, Double.NaN) };
  1043. staticAccessors$7.EPS.get = function () { return 1.23259516440783e-32 };
  1044. staticAccessors$7.SPLIT.get = function () { return 134217729.0 };
  1045. staticAccessors$7.MAX_PRINT_DIGITS.get = function () { return 32 };
  1046. staticAccessors$7.TEN.get = function () { return DD.valueOf(10.0) };
  1047. staticAccessors$7.ONE.get = function () { return DD.valueOf(1.0) };
  1048. staticAccessors$7.SCI_NOT_EXPONENT_CHAR.get = function () { return 'E' };
  1049. staticAccessors$7.SCI_NOT_ZERO.get = function () { return '0.0E0' };
  1050. Object.defineProperties( DD, staticAccessors$7 );
  1051. var CGAlgorithmsDD = function CGAlgorithmsDD () {};
  1052. var staticAccessors$6 = { DP_SAFE_EPSILON: { configurable: true } };
  1053. CGAlgorithmsDD.prototype.interfaces_ = function interfaces_ () {
  1054. return []
  1055. };
  1056. CGAlgorithmsDD.prototype.getClass = function getClass () {
  1057. return CGAlgorithmsDD
  1058. };
  1059. CGAlgorithmsDD.orientationIndex = function orientationIndex (p1, p2, q) {
  1060. var index = CGAlgorithmsDD.orientationIndexFilter(p1, p2, q);
  1061. if (index <= 1) { return index }
  1062. var dx1 = DD.valueOf(p2.x).selfAdd(-p1.x);
  1063. var dy1 = DD.valueOf(p2.y).selfAdd(-p1.y);
  1064. var dx2 = DD.valueOf(q.x).selfAdd(-p2.x);
  1065. var dy2 = DD.valueOf(q.y).selfAdd(-p2.y);
  1066. return dx1.selfMultiply(dy2).selfSubtract(dy1.selfMultiply(dx2)).signum()
  1067. };
  1068. CGAlgorithmsDD.signOfDet2x2 = function signOfDet2x2 (x1, y1, x2, y2) {
  1069. var det = x1.multiply(y2).selfSubtract(y1.multiply(x2));
  1070. return det.signum()
  1071. };
  1072. CGAlgorithmsDD.intersection = function intersection (p1, p2, q1, q2) {
  1073. var denom1 = DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(DD.valueOf(p2.x).selfSubtract(p1.x));
  1074. var denom2 = DD.valueOf(q2.x).selfSubtract(q1.x).selfMultiply(DD.valueOf(p2.y).selfSubtract(p1.y));
  1075. var denom = denom1.subtract(denom2);
  1076. var numx1 = DD.valueOf(q2.x).selfSubtract(q1.x).selfMultiply(DD.valueOf(p1.y).selfSubtract(q1.y));
  1077. var numx2 = DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(DD.valueOf(p1.x).selfSubtract(q1.x));
  1078. var numx = numx1.subtract(numx2);
  1079. var fracP = numx.selfDivide(denom).doubleValue();
  1080. var x = DD.valueOf(p1.x).selfAdd(DD.valueOf(p2.x).selfSubtract(p1.x).selfMultiply(fracP)).doubleValue();
  1081. var numy1 = DD.valueOf(p2.x).selfSubtract(p1.x).selfMultiply(DD.valueOf(p1.y).selfSubtract(q1.y));
  1082. var numy2 = DD.valueOf(p2.y).selfSubtract(p1.y).selfMultiply(DD.valueOf(p1.x).selfSubtract(q1.x));
  1083. var numy = numy1.subtract(numy2);
  1084. var fracQ = numy.selfDivide(denom).doubleValue();
  1085. var y = DD.valueOf(q1.y).selfAdd(DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(fracQ)).doubleValue();
  1086. return new Coordinate(x, y)
  1087. };
  1088. CGAlgorithmsDD.orientationIndexFilter = function orientationIndexFilter (pa, pb, pc) {
  1089. var detsum = null;
  1090. var detleft = (pa.x - pc.x) * (pb.y - pc.y);
  1091. var detright = (pa.y - pc.y) * (pb.x - pc.x);
  1092. var det = detleft - detright;
  1093. if (detleft > 0.0) {
  1094. if (detright <= 0.0) {
  1095. return CGAlgorithmsDD.signum(det)
  1096. } else {
  1097. detsum = detleft + detright;
  1098. }
  1099. } else if (detleft < 0.0) {
  1100. if (detright >= 0.0) {
  1101. return CGAlgorithmsDD.signum(det)
  1102. } else {
  1103. detsum = -detleft - detright;
  1104. }
  1105. } else {
  1106. return CGAlgorithmsDD.signum(det)
  1107. }
  1108. var errbound = CGAlgorithmsDD.DP_SAFE_EPSILON * detsum;
  1109. if (det >= errbound || -det >= errbound) {
  1110. return CGAlgorithmsDD.signum(det)
  1111. }
  1112. return 2
  1113. };
  1114. CGAlgorithmsDD.signum = function signum (x) {
  1115. if (x > 0) { return 1 }
  1116. if (x < 0) { return -1 }
  1117. return 0
  1118. };
  1119. staticAccessors$6.DP_SAFE_EPSILON.get = function () { return 1e-15 };
  1120. Object.defineProperties( CGAlgorithmsDD, staticAccessors$6 );
  1121. var CoordinateSequence = function CoordinateSequence () {};
  1122. var staticAccessors$8 = { X: { configurable: true },Y: { configurable: true },Z: { configurable: true },M: { configurable: true } };
  1123. staticAccessors$8.X.get = function () { return 0 };
  1124. staticAccessors$8.Y.get = function () { return 1 };
  1125. staticAccessors$8.Z.get = function () { return 2 };
  1126. staticAccessors$8.M.get = function () { return 3 };
  1127. CoordinateSequence.prototype.setOrdinate = function setOrdinate (index, ordinateIndex, value) {};
  1128. CoordinateSequence.prototype.size = function size () {};
  1129. CoordinateSequence.prototype.getOrdinate = function getOrdinate (index, ordinateIndex) {};
  1130. CoordinateSequence.prototype.getCoordinate = function getCoordinate () {};
  1131. CoordinateSequence.prototype.getCoordinateCopy = function getCoordinateCopy (i) {};
  1132. CoordinateSequence.prototype.getDimension = function getDimension () {};
  1133. CoordinateSequence.prototype.getX = function getX (index) {};
  1134. CoordinateSequence.prototype.clone = function clone () {};
  1135. CoordinateSequence.prototype.expandEnvelope = function expandEnvelope (env) {};
  1136. CoordinateSequence.prototype.copy = function copy () {};
  1137. CoordinateSequence.prototype.getY = function getY (index) {};
  1138. CoordinateSequence.prototype.toCoordinateArray = function toCoordinateArray () {};
  1139. CoordinateSequence.prototype.interfaces_ = function interfaces_ () {
  1140. return [Clonable]
  1141. };
  1142. CoordinateSequence.prototype.getClass = function getClass () {
  1143. return CoordinateSequence
  1144. };
  1145. Object.defineProperties( CoordinateSequence, staticAccessors$8 );
  1146. var Exception = function Exception () {};
  1147. var NotRepresentableException = (function (Exception$$1) {
  1148. function NotRepresentableException () {
  1149. Exception$$1.call(this, 'Projective point not representable on the Cartesian plane.');
  1150. }
  1151. if ( Exception$$1 ) NotRepresentableException.__proto__ = Exception$$1;
  1152. NotRepresentableException.prototype = Object.create( Exception$$1 && Exception$$1.prototype );
  1153. NotRepresentableException.prototype.constructor = NotRepresentableException;
  1154. NotRepresentableException.prototype.interfaces_ = function interfaces_ () {
  1155. return []
  1156. };
  1157. NotRepresentableException.prototype.getClass = function getClass () {
  1158. return NotRepresentableException
  1159. };
  1160. return NotRepresentableException;
  1161. }(Exception));
  1162. var System = function System () {};
  1163. System.arraycopy = function arraycopy (src, srcPos, dest, destPos, len) {
  1164. var c = 0;
  1165. for (var i = srcPos; i < srcPos + len; i++) {
  1166. dest[destPos + c] = src[i];
  1167. c++;
  1168. }
  1169. };
  1170. System.getProperty = function getProperty (name) {
  1171. return {
  1172. 'line.separator': '\n'
  1173. }[name]
  1174. };
  1175. var HCoordinate = function HCoordinate () {
  1176. this.x = null;
  1177. this.y = null;
  1178. this.w = null;
  1179. if (arguments.length === 0) {
  1180. this.x = 0.0;
  1181. this.y = 0.0;
  1182. this.w = 1.0;
  1183. } else if (arguments.length === 1) {
  1184. var p = arguments[0];
  1185. this.x = p.x;
  1186. this.y = p.y;
  1187. this.w = 1.0;
  1188. } else if (arguments.length === 2) {
  1189. if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
  1190. var _x = arguments[0];
  1191. var _y = arguments[1];
  1192. this.x = _x;
  1193. this.y = _y;
  1194. this.w = 1.0;
  1195. } else if (arguments[0] instanceof HCoordinate && arguments[1] instanceof HCoordinate) {
  1196. var p1 = arguments[0];
  1197. var p2 = arguments[1];
  1198. this.x = p1.y * p2.w - p2.y * p1.w;
  1199. this.y = p2.x * p1.w - p1.x * p2.w;
  1200. this.w = p1.x * p2.y - p2.x * p1.y;
  1201. } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {
  1202. var p1$1 = arguments[0];
  1203. var p2$1 = arguments[1];
  1204. this.x = p1$1.y - p2$1.y;
  1205. this.y = p2$1.x - p1$1.x;
  1206. this.w = p1$1.x * p2$1.y - p2$1.x * p1$1.y;
  1207. }
  1208. } else if (arguments.length === 3) {
  1209. var _x$1 = arguments[0];
  1210. var _y$1 = arguments[1];
  1211. var _w = arguments[2];
  1212. this.x = _x$1;
  1213. this.y = _y$1;
  1214. this.w = _w;
  1215. } else if (arguments.length === 4) {
  1216. var p1$2 = arguments[0];
  1217. var p2$2 = arguments[1];
  1218. var q1 = arguments[2];
  1219. var q2 = arguments[3];
  1220. var px = p1$2.y - p2$2.y;
  1221. var py = p2$2.x - p1$2.x;
  1222. var pw = p1$2.x * p2$2.y - p2$2.x * p1$2.y;
  1223. var qx = q1.y - q2.y;
  1224. var qy = q2.x - q1.x;
  1225. var qw = q1.x * q2.y - q2.x * q1.y;
  1226. this.x = py * qw - qy * pw;
  1227. this.y = qx * pw - px * qw;
  1228. this.w = px * qy - qx * py;
  1229. }
  1230. };
  1231. HCoordinate.prototype.getY = function getY () {
  1232. var a = this.y / this.w;
  1233. if (Double.isNaN(a) || Double.isInfinite(a)) {
  1234. throw new NotRepresentableException()
  1235. }
  1236. return a
  1237. };
  1238. HCoordinate.prototype.getX = function getX () {
  1239. var a = this.x / this.w;
  1240. if (Double.isNaN(a) || Double.isInfinite(a)) {
  1241. throw new NotRepresentableException()
  1242. }
  1243. return a
  1244. };
  1245. HCoordinate.prototype.getCoordinate = function getCoordinate () {
  1246. var p = new Coordinate();
  1247. p.x = this.getX();
  1248. p.y = this.getY();
  1249. return p
  1250. };
  1251. HCoordinate.prototype.interfaces_ = function interfaces_ () {
  1252. return []
  1253. };
  1254. HCoordinate.prototype.getClass = function getClass () {
  1255. return HCoordinate
  1256. };
  1257. HCoordinate.intersection = function intersection (p1, p2, q1, q2) {
  1258. var px = p1.y - p2.y;
  1259. var py = p2.x - p1.x;
  1260. var pw = p1.x * p2.y - p2.x * p1.y;
  1261. var qx = q1.y - q2.y;
  1262. var qy = q2.x - q1.x;
  1263. var qw = q1.x * q2.y - q2.x * q1.y;
  1264. var x = py * qw - qy * pw;
  1265. var y = qx * pw - px * qw;
  1266. var w = px * qy - qx * py;
  1267. var xInt = x / w;
  1268. var yInt = y / w;
  1269. if (Double.isNaN(xInt) || (Double.isInfinite(xInt) || Double.isNaN(yInt)) || Double.isInfinite(yInt)) {
  1270. throw new NotRepresentableException()
  1271. }
  1272. return new Coordinate(xInt, yInt)
  1273. };
  1274. var Envelope = function Envelope () {
  1275. this._minx = null;
  1276. this._maxx = null;
  1277. this._miny = null;
  1278. this._maxy = null;
  1279. if (arguments.length === 0) {
  1280. this.init();
  1281. } else if (arguments.length === 1) {
  1282. if (arguments[0] instanceof Coordinate) {
  1283. var p = arguments[0];
  1284. this.init(p.x, p.x, p.y, p.y);
  1285. } else if (arguments[0] instanceof Envelope) {
  1286. var env = arguments[0];
  1287. this.init(env);
  1288. }
  1289. } else if (arguments.length === 2) {
  1290. var p1 = arguments[0];
  1291. var p2 = arguments[1];
  1292. this.init(p1.x, p2.x, p1.y, p2.y);
  1293. } else if (arguments.length === 4) {
  1294. var x1 = arguments[0];
  1295. var x2 = arguments[1];
  1296. var y1 = arguments[2];
  1297. var y2 = arguments[3];
  1298. this.init(x1, x2, y1, y2);
  1299. }
  1300. };
  1301. var staticAccessors$9 = { serialVersionUID: { configurable: true } };
  1302. Envelope.prototype.getArea = function getArea () {
  1303. return this.getWidth() * this.getHeight()
  1304. };
  1305. Envelope.prototype.equals = function equals (other) {
  1306. if (!(other instanceof Envelope)) {
  1307. return false
  1308. }
  1309. var otherEnvelope = other;
  1310. if (this.isNull()) {
  1311. return otherEnvelope.isNull()
  1312. }
  1313. return this._maxx === otherEnvelope.getMaxX() && this._maxy === otherEnvelope.getMaxY() && this._minx === otherEnvelope.getMinX() && this._miny === otherEnvelope.getMinY()
  1314. };
  1315. Envelope.prototype.intersection = function intersection (env) {
  1316. if (this.isNull() || env.isNull() || !this.intersects(env)) { return new Envelope() }
  1317. var intMinX = this._minx > env._minx ? this._minx : env._minx;
  1318. var intMinY = this._miny > env._miny ? this._miny : env._miny;
  1319. var intMaxX = this._maxx < env._maxx ? this._maxx : env._maxx;
  1320. var intMaxY = this._maxy < env._maxy ? this._maxy : env._maxy;
  1321. return new Envelope(intMinX, intMaxX, intMinY, intMaxY)
  1322. };
  1323. Envelope.prototype.isNull = function isNull () {
  1324. return this._maxx < this._minx
  1325. };
  1326. Envelope.prototype.getMaxX = function getMaxX () {
  1327. return this._maxx
  1328. };
  1329. Envelope.prototype.covers = function covers () {
  1330. if (arguments.length === 1) {
  1331. if (arguments[0] instanceof Coordinate) {
  1332. var p = arguments[0];
  1333. return this.covers(p.x, p.y)
  1334. } else if (arguments[0] instanceof Envelope) {
  1335. var other = arguments[0];
  1336. if (this.isNull() || other.isNull()) {
  1337. return false
  1338. }
  1339. return other.getMinX() >= this._minx && other.getMaxX() <= this._maxx && other.getMinY() >= this._miny && other.getMaxY() <= this._maxy
  1340. }
  1341. } else if (arguments.length === 2) {
  1342. var x = arguments[0];
  1343. var y = arguments[1];
  1344. if (this.isNull()) { return false }
  1345. return x >= this._minx && x <= this._maxx && y >= this._miny && y <= this._maxy
  1346. }
  1347. };
  1348. Envelope.prototype.intersects = function intersects () {
  1349. if (arguments.length === 1) {
  1350. if (arguments[0] instanceof Envelope) {
  1351. var other = arguments[0];
  1352. if (this.isNull() || other.isNull()) {
  1353. return false
  1354. }
  1355. return !(other._minx > this._maxx || other._maxx < this._minx || other._miny > this._maxy || other._maxy < this._miny)
  1356. } else if (arguments[0] instanceof Coordinate) {
  1357. var p = arguments[0];
  1358. return this.intersects(p.x, p.y)
  1359. }
  1360. } else if (arguments.length === 2) {
  1361. var x = arguments[0];
  1362. var y = arguments[1];
  1363. if (this.isNull()) { return false }
  1364. return !(x > this._maxx || x < this._minx || y > this._maxy || y < this._miny)
  1365. }
  1366. };
  1367. Envelope.prototype.getMinY = function getMinY () {
  1368. return this._miny
  1369. };
  1370. Envelope.prototype.getMinX = function getMinX () {
  1371. return this._minx
  1372. };
  1373. Envelope.prototype.expandToInclude = function expandToInclude () {
  1374. if (arguments.length === 1) {
  1375. if (arguments[0] instanceof Coordinate) {
  1376. var p = arguments[0];
  1377. this.expandToInclude(p.x, p.y);
  1378. } else if (arguments[0] instanceof Envelope) {
  1379. var other = arguments[0];
  1380. if (other.isNull()) {
  1381. return null
  1382. }
  1383. if (this.isNull()) {
  1384. this._minx = other.getMinX();
  1385. this._maxx = other.getMaxX();
  1386. this._miny = other.getMinY();
  1387. this._maxy = other.getMaxY();
  1388. } else {
  1389. if (other._minx < this._minx) {
  1390. this._minx = other._minx;
  1391. }
  1392. if (other._maxx > this._maxx) {
  1393. this._maxx = other._maxx;
  1394. }
  1395. if (other._miny < this._miny) {
  1396. this._miny = other._miny;
  1397. }
  1398. if (other._maxy > this._maxy) {
  1399. this._maxy = other._maxy;
  1400. }
  1401. }
  1402. }
  1403. } else if (arguments.length === 2) {
  1404. var x = arguments[0];
  1405. var y = arguments[1];
  1406. if (this.isNull()) {
  1407. this._minx = x;
  1408. this._maxx = x;
  1409. this._miny = y;
  1410. this._maxy = y;
  1411. } else {
  1412. if (x < this._minx) {
  1413. this._minx = x;
  1414. }
  1415. if (x > this._maxx) {
  1416. this._maxx = x;
  1417. }
  1418. if (y < this._miny) {
  1419. this._miny = y;
  1420. }
  1421. if (y > this._maxy) {
  1422. this._maxy = y;
  1423. }
  1424. }
  1425. }
  1426. };
  1427. Envelope.prototype.minExtent = function minExtent () {
  1428. if (this.isNull()) { return 0.0 }
  1429. var w = this.getWidth();
  1430. var h = this.getHeight();
  1431. if (w < h) { return w }
  1432. return h
  1433. };
  1434. Envelope.prototype.getWidth = function getWidth () {
  1435. if (this.isNull()) {
  1436. return 0
  1437. }
  1438. return this._maxx - this._minx
  1439. };
  1440. Envelope.prototype.compareTo = function compareTo (o) {
  1441. var env = o;
  1442. if (this.isNull()) {
  1443. if (env.isNull()) { return 0 }
  1444. return -1
  1445. } else {
  1446. if (env.isNull()) { return 1 }
  1447. }
  1448. if (this._minx < env._minx) { return -1 }
  1449. if (this._minx > env._minx) { return 1 }
  1450. if (this._miny < env._miny) { return -1 }
  1451. if (this._miny > env._miny) { return 1 }
  1452. if (this._maxx < env._maxx) { return -1 }
  1453. if (this._maxx > env._maxx) { return 1 }
  1454. if (this._maxy < env._maxy) { return -1 }
  1455. if (this._maxy > env._maxy) { return 1 }
  1456. return 0
  1457. };
  1458. Envelope.prototype.translate = function translate (transX, transY) {
  1459. if (this.isNull()) {
  1460. return null
  1461. }
  1462. this.init(this.getMinX() + transX, this.getMaxX() + transX, this.getMinY() + transY, this.getMaxY() + transY);
  1463. };
  1464. Envelope.prototype.toString = function toString () {
  1465. return 'Env[' + this._minx + ' : ' + this._maxx + ', ' + this._miny + ' : ' + this._maxy + ']'
  1466. };
  1467. Envelope.prototype.setToNull = function setToNull () {
  1468. this._minx = 0;
  1469. this._maxx = -1;
  1470. this._miny = 0;
  1471. this._maxy = -1;
  1472. };
  1473. Envelope.prototype.getHeight = function getHeight () {
  1474. if (this.isNull()) {
  1475. return 0
  1476. }
  1477. return this._maxy - this._miny
  1478. };
  1479. Envelope.prototype.maxExtent = function maxExtent () {
  1480. if (this.isNull()) { return 0.0 }
  1481. var w = this.getWidth();
  1482. var h = this.getHeight();
  1483. if (w > h) { return w }
  1484. return h
  1485. };
  1486. Envelope.prototype.expandBy = function expandBy () {
  1487. if (arguments.length === 1) {
  1488. var distance = arguments[0];
  1489. this.expandBy(distance, distance);
  1490. } else if (arguments.length === 2) {
  1491. var deltaX = arguments[0];
  1492. var deltaY = arguments[1];
  1493. if (this.isNull()) { return null }
  1494. this._minx -= deltaX;
  1495. this._maxx += deltaX;
  1496. this._miny -= deltaY;
  1497. this._maxy += deltaY;
  1498. if (this._minx > this._maxx || this._miny > this._maxy) { this.setToNull(); }
  1499. }
  1500. };
  1501. Envelope.prototype.contains = function contains () {
  1502. if (arguments.length === 1) {
  1503. if (arguments[0] instanceof Envelope) {
  1504. var other = arguments[0];
  1505. return this.covers(other)
  1506. } else if (arguments[0] instanceof Coordinate) {
  1507. var p = arguments[0];
  1508. return this.covers(p)
  1509. }
  1510. } else if (arguments.length === 2) {
  1511. var x = arguments[0];
  1512. var y = arguments[1];
  1513. return this.covers(x, y)
  1514. }
  1515. };
  1516. Envelope.prototype.centre = function centre () {
  1517. if (this.isNull()) { return null }
  1518. return new Coordinate((this.getMinX() + this.getMaxX()) / 2.0, (this.getMinY() + this.getMaxY()) / 2.0)
  1519. };
  1520. Envelope.prototype.init = function init () {
  1521. if (arguments.length === 0) {
  1522. this.setToNull();
  1523. } else if (arguments.length === 1) {
  1524. if (arguments[0] instanceof Coordinate) {
  1525. var p = arguments[0];
  1526. this.init(p.x, p.x, p.y, p.y);
  1527. } else if (arguments[0] instanceof Envelope) {
  1528. var env = arguments[0];
  1529. this._minx = env._minx;
  1530. this._maxx = env._maxx;
  1531. this._miny = env._miny;
  1532. this._maxy = env._maxy;
  1533. }
  1534. } else if (arguments.length === 2) {
  1535. var p1 = arguments[0];
  1536. var p2 = arguments[1];
  1537. this.init(p1.x, p2.x, p1.y, p2.y);
  1538. } else if (arguments.length === 4) {
  1539. var x1 = arguments[0];
  1540. var x2 = arguments[1];
  1541. var y1 = arguments[2];
  1542. var y2 = arguments[3];
  1543. if (x1 < x2) {
  1544. this._minx = x1;
  1545. this._maxx = x2;
  1546. } else {
  1547. this._minx = x2;
  1548. this._maxx = x1;
  1549. }
  1550. if (y1 < y2) {
  1551. this._miny = y1;
  1552. this._maxy = y2;
  1553. } else {
  1554. this._miny = y2;
  1555. this._maxy = y1;
  1556. }
  1557. }
  1558. };
  1559. Envelope.prototype.getMaxY = function getMaxY () {
  1560. return this._maxy
  1561. };
  1562. Envelope.prototype.distance = function distance (env) {
  1563. if (this.intersects(env)) { return 0 }
  1564. var dx = 0.0;
  1565. if (this._maxx < env._minx) { dx = env._minx - this._maxx; } else if (this._minx > env._maxx) { dx = this._minx - env._maxx; }
  1566. var dy = 0.0;
  1567. if (this._maxy < env._miny) { dy = env._miny - this._maxy; } else if (this._miny > env._maxy) { dy = this._miny - env._maxy; }
  1568. if (dx === 0.0) { return dy }
  1569. if (dy === 0.0) { return dx }
  1570. return Math.sqrt(dx * dx + dy * dy)
  1571. };
  1572. Envelope.prototype.hashCode = function hashCode () {
  1573. var result = 17;
  1574. result = 37 * result + Coordinate.hashCode(this._minx);
  1575. result = 37 * result + Coordinate.hashCode(this._maxx);
  1576. result = 37 * result + Coordinate.hashCode(this._miny);
  1577. result = 37 * result + Coordinate.hashCode(this._maxy);
  1578. return result
  1579. };
  1580. Envelope.prototype.interfaces_ = function interfaces_ () {
  1581. return [Comparable, Serializable]
  1582. };
  1583. Envelope.prototype.getClass = function getClass () {
  1584. return Envelope
  1585. };
  1586. Envelope.intersects = function intersects () {
  1587. if (arguments.length === 3) {
  1588. var p1 = arguments[0];
  1589. var p2 = arguments[1];
  1590. var q = arguments[2];
  1591. if (q.x >= (p1.x < p2.x ? p1.x : p2.x) && q.x <= (p1.x > p2.x ? p1.x : p2.x) && (q.y >= (p1.y < p2.y ? p1.y : p2.y) && q.y <= (p1.y > p2.y ? p1.y : p2.y))) {
  1592. return true
  1593. }
  1594. return false
  1595. } else if (arguments.length === 4) {
  1596. var p1$1 = arguments[0];
  1597. var p2$1 = arguments[1];
  1598. var q1 = arguments[2];
  1599. var q2 = arguments[3];
  1600. var minq = Math.min(q1.x, q2.x);
  1601. var maxq = Math.max(q1.x, q2.x);
  1602. var minp = Math.min(p1$1.x, p2$1.x);
  1603. var maxp = Math.max(p1$1.x, p2$1.x);
  1604. if (minp > maxq) { return false }
  1605. if (maxp < minq) { return false }
  1606. minq = Math.min(q1.y, q2.y);
  1607. maxq = Math.max(q1.y, q2.y);
  1608. minp = Math.min(p1$1.y, p2$1.y);
  1609. maxp = Math.max(p1$1.y, p2$1.y);
  1610. if (minp > maxq) { return false }
  1611. if (maxp < minq) { return false }
  1612. return true
  1613. }
  1614. };
  1615. staticAccessors$9.serialVersionUID.get = function () { return 5873921885273102420 };
  1616. Object.defineProperties( Envelope, staticAccessors$9 );
  1617. var regExes = {
  1618. 'typeStr': /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/,
  1619. 'emptyTypeStr': /^\s*(\w+)\s*EMPTY\s*$/,
  1620. 'spaces': /\s+/,
  1621. 'parenComma': /\)\s*,\s*\(/,
  1622. 'doubleParenComma': /\)\s*\)\s*,\s*\(\s*\(/, // can't use {2} here
  1623. 'trimParens': /^\s*\(?(.*?)\)?\s*$/
  1624. };
  1625. /**
  1626. * Class for reading and writing Well-Known Text.
  1627. *
  1628. * NOTE: Adapted from OpenLayers 2.11 implementation.
  1629. */
  1630. /** Create a new parser for WKT
  1631. *
  1632. * @param {GeometryFactory} geometryFactory
  1633. * @return An instance of WKTParser.
  1634. * @constructor
  1635. * @private
  1636. */
  1637. var WKTParser = function WKTParser (geometryFactory) {
  1638. this.geometryFactory = geometryFactory || new GeometryFactory();
  1639. };
  1640. /**
  1641. * Deserialize a WKT string and return a geometry. Supports WKT for POINT,
  1642. * MULTIPOINT, LINESTRING, LINEARRING, MULTILINESTRING, POLYGON, MULTIPOLYGON,
  1643. * and GEOMETRYCOLLECTION.
  1644. *
  1645. * @param {String} wkt A WKT string.
  1646. * @return {Geometry} A geometry instance.
  1647. * @private
  1648. */
  1649. WKTParser.prototype.read = function read (wkt) {
  1650. var geometry, type, str;
  1651. wkt = wkt.replace(/[\n\r]/g, ' ');
  1652. var matches = regExes.typeStr.exec(wkt);
  1653. if (wkt.search('EMPTY') !== -1) {
  1654. matches = regExes.emptyTypeStr.exec(wkt);
  1655. matches[2] = undefined;
  1656. }
  1657. if (matches) {
  1658. type = matches[1].toLowerCase();
  1659. str = matches[2];
  1660. if (parse$1[type]) {
  1661. geometry = parse$1[type].apply(this, [str]);
  1662. }
  1663. }
  1664. if (geometry === undefined) { throw new Error('Could not parse WKT ' + wkt) }
  1665. return geometry
  1666. };
  1667. /**
  1668. * Serialize a geometry into a WKT string.
  1669. *
  1670. * @param {Geometry} geometry A feature or array of features.
  1671. * @return {String} The WKT string representation of the input geometries.
  1672. * @private
  1673. */
  1674. WKTParser.prototype.write = function write (geometry) {
  1675. return this.extractGeometry(geometry)
  1676. };
  1677. /**
  1678. * Entry point to construct the WKT for a single Geometry object.
  1679. *
  1680. * @param {Geometry} geometry
  1681. * @return {String} A WKT string of representing the geometry.
  1682. * @private
  1683. */
  1684. WKTParser.prototype.extractGeometry = function extractGeometry (geometry) {
  1685. var type = geometry.getGeometryType().toLowerCase();
  1686. if (!extract$1[type]) {
  1687. return null
  1688. }
  1689. var wktType = type.toUpperCase();
  1690. var data;
  1691. if (geometry.isEmpty()) {
  1692. data = wktType + ' EMPTY';
  1693. } else {
  1694. data = wktType + '(' + extract$1[type].apply(this, [geometry]) + ')';
  1695. }
  1696. return data
  1697. };
  1698. /**
  1699. * Object with properties corresponding to the geometry types. Property values
  1700. * are functions that do the actual data extraction.
  1701. * @private
  1702. */
  1703. var extract$1 = {
  1704. coordinate: function coordinate (coordinate$1) {
  1705. return coordinate$1.x + ' ' + coordinate$1.y
  1706. },
  1707. /**
  1708. * Return a space delimited string of point coordinates.
  1709. *
  1710. * @param {Point}
  1711. * point
  1712. * @return {String} A string of coordinates representing the point.
  1713. */
  1714. point: function point (point$1) {
  1715. return extract$1.coordinate.call(this, point$1._coordinates._coordinates[0])
  1716. },
  1717. /**
  1718. * Return a comma delimited string of point coordinates from a multipoint.
  1719. *
  1720. * @param {MultiPoint}
  1721. * multipoint
  1722. * @return {String} A string of point coordinate strings representing the
  1723. * multipoint.
  1724. */
  1725. multipoint: function multipoint (multipoint$1) {
  1726. var this$1 = this;
  1727. var array = [];
  1728. for (var i = 0, len = multipoint$1._geometries.length; i < len; ++i) {
  1729. array.push('(' + extract$1.point.apply(this$1, [multipoint$1._geometries[i]]) + ')');
  1730. }
  1731. return array.join(',')
  1732. },
  1733. /**
  1734. * Return a comma delimited string of point coordinates from a line.
  1735. *
  1736. * @param {LineString} linestring
  1737. * @return {String} A string of point coordinate strings representing the linestring.
  1738. */
  1739. linestring: function linestring (linestring$1) {
  1740. var this$1 = this;
  1741. var array = [];
  1742. for (var i = 0, len = linestring$1._points._coordinates.length; i < len; ++i) {
  1743. array.push(extract$1.coordinate.apply(this$1, [linestring$1._points._coordinates[i]]));
  1744. }
  1745. return array.join(',')
  1746. },
  1747. linearring: function linearring (linearring$1) {
  1748. var this$1 = this;
  1749. var array = [];
  1750. for (var i = 0, len = linearring$1._points._coordinates.length; i < len; ++i) {
  1751. array.push(extract$1.coordinate.apply(this$1, [linearring$1._points._coordinates[i]]));
  1752. }
  1753. return array.join(',')
  1754. },
  1755. /**
  1756. * Return a comma delimited string of linestring strings from a
  1757. * multilinestring.
  1758. *
  1759. * @param {MultiLineString} multilinestring
  1760. * @return {String} A string of of linestring strings representing the multilinestring.
  1761. */
  1762. multilinestring: function multilinestring (multilinestring$1) {
  1763. var this$1 = this;
  1764. var array = [];
  1765. for (var i = 0, len = multilinestring$1._geometries.length; i < len; ++i) {
  1766. array.push('(' +
  1767. extract$1.linestring.apply(this$1, [multilinestring$1._geometries[i]]) +
  1768. ')');
  1769. }
  1770. return array.join(',')
  1771. },
  1772. /**
  1773. * Return a comma delimited string of linear ring arrays from a polygon.
  1774. *
  1775. * @param {Polygon} polygon
  1776. * @return {String} An array of linear ring arrays representing the polygon.
  1777. */
  1778. polygon: function polygon (polygon$1) {
  1779. var this$1 = this;
  1780. var array = [];
  1781. array.push('(' + extract$1.linestring.apply(this, [polygon$1._shell]) + ')');
  1782. for (var i = 0, len = polygon$1._holes.length; i < len; ++i) {
  1783. array.push('(' + extract$1.linestring.apply(this$1, [polygon$1._holes[i]]) + ')');
  1784. }
  1785. return array.join(',')
  1786. },
  1787. /**
  1788. * Return an array of polygon arrays from a multipolygon.
  1789. *
  1790. * @param {MultiPolygon} multipolygon
  1791. * @return {String} An array of polygon arrays representing the multipolygon.
  1792. */
  1793. multipolygon: function multipolygon (multipolygon$1) {
  1794. var this$1 = this;
  1795. var array = [];
  1796. for (var i = 0, len = multipolygon$1._geometries.length; i < len; ++i) {
  1797. array.push('(' + extract$1.polygon.apply(this$1, [multipolygon$1._geometries[i]]) + ')');
  1798. }
  1799. return array.join(',')
  1800. },
  1801. /**
  1802. * Return the WKT portion between 'GEOMETRYCOLLECTION(' and ')' for an
  1803. * geometrycollection.
  1804. *
  1805. * @param {GeometryCollection} collection
  1806. * @return {String} internal WKT representation of the collection.
  1807. */
  1808. geometrycollection: function geometrycollection (collection) {
  1809. var this$1 = this;
  1810. var array = [];
  1811. for (var i = 0, len = collection._geometries.length; i < len; ++i) {
  1812. array.push(this$1.extractGeometry(collection._geometries[i]));
  1813. }
  1814. return array.join(',')
  1815. }
  1816. };
  1817. /**
  1818. * Object with properties corresponding to the geometry types. Property values
  1819. * are functions that do the actual parsing.
  1820. * @private
  1821. */
  1822. var parse$1 = {
  1823. /**
  1824. * Return point geometry given a point WKT fragment.
  1825. *
  1826. * @param {String} str A WKT fragment representing the point.
  1827. * @return {Point} A point geometry.
  1828. * @private
  1829. */
  1830. point: function point (str) {
  1831. if (str === undefined) {
  1832. return this.geometryFactory.createPoint()
  1833. }
  1834. var coords = str.trim().split(regExes.spaces);
  1835. return this.geometryFactory.createPoint(new Coordinate(Number.parseFloat(coords[0]),
  1836. Number.parseFloat(coords[1])))
  1837. },
  1838. /**
  1839. * Return a multipoint geometry given a multipoint WKT fragment.
  1840. *
  1841. * @param {String} str A WKT fragment representing the multipoint.
  1842. * @return {Point} A multipoint feature.
  1843. * @private
  1844. */
  1845. multipoint: function multipoint (str) {
  1846. var this$1 = this;
  1847. if (str === undefined) {
  1848. return this.geometryFactory.createMultiPoint()
  1849. }
  1850. var point;
  1851. var points = str.trim().split(',');
  1852. var components = [];
  1853. for (var i = 0, len = points.length; i < len; ++i) {
  1854. point = points[i].replace(regExes.trimParens, '$1');
  1855. components.push(parse$1.point.apply(this$1, [point]));
  1856. }
  1857. return this.geometryFactory.createMultiPoint(components)
  1858. },
  1859. /**
  1860. * Return a linestring geometry given a linestring WKT fragment.
  1861. *
  1862. * @param {String} str A WKT fragment representing the linestring.
  1863. * @return {LineString} A linestring geometry.
  1864. * @private
  1865. */
  1866. linestring: function linestring (str) {
  1867. if (str === undefined) {
  1868. return this.geometryFactory.createLineString()
  1869. }
  1870. var points = str.trim().split(',');
  1871. var components = [];
  1872. var coords;
  1873. for (var i = 0, len = points.length; i < len; ++i) {
  1874. coords = points[i].trim().split(regExes.spaces);
  1875. components.push(new Coordinate(Number.parseFloat(coords[0]), Number.parseFloat(coords[1])));
  1876. }
  1877. return this.geometryFactory.createLineString(components)
  1878. },
  1879. /**
  1880. * Return a linearring geometry given a linearring WKT fragment.
  1881. *
  1882. * @param {String} str A WKT fragment representing the linearring.
  1883. * @return {LinearRing} A linearring geometry.
  1884. * @private
  1885. */
  1886. linearring: function linearring (str) {
  1887. if (str === undefined) {
  1888. return this.geometryFactory.createLinearRing()
  1889. }
  1890. var points = str.trim().split(',');
  1891. var components = [];
  1892. var coords;
  1893. for (var i = 0, len = points.length; i < len; ++i) {
  1894. coords = points[i].trim().split(regExes.spaces);
  1895. components.push(new Coordinate(Number.parseFloat(coords[0]), Number.parseFloat(coords[1])));
  1896. }
  1897. return this.geometryFactory.createLinearRing(components)
  1898. },
  1899. /**
  1900. * Return a multilinestring geometry given a multilinestring WKT fragment.
  1901. *
  1902. * @param {String} str A WKT fragment representing the multilinestring.
  1903. * @return {MultiLineString} A multilinestring geometry.
  1904. * @private
  1905. */
  1906. multilinestring: function multilinestring (str) {
  1907. var this$1 = this;
  1908. if (str === undefined) {
  1909. return this.geometryFactory.createMultiLineString()
  1910. }
  1911. var line;
  1912. var lines = str.trim().split(regExes.parenComma);
  1913. var components = [];
  1914. for (var i = 0, len = lines.length; i < len; ++i) {
  1915. line = lines[i].replace(regExes.trimParens, '$1');
  1916. components.push(parse$1.linestring.apply(this$1, [line]));
  1917. }
  1918. return this.geometryFactory.createMultiLineString(components)
  1919. },
  1920. /**
  1921. * Return a polygon geometry given a polygon WKT fragment.
  1922. *
  1923. * @param {String} str A WKT fragment representing the polygon.
  1924. * @return {Polygon} A polygon geometry.
  1925. * @private
  1926. */
  1927. polygon: function polygon (str) {
  1928. var this$1 = this;
  1929. if (str === undefined) {
  1930. return this.geometryFactory.createPolygon()
  1931. }
  1932. var ring, linestring, linearring;
  1933. var rings = str.trim().split(regExes.parenComma);
  1934. var shell;
  1935. var holes = [];
  1936. for (var i = 0, len = rings.length; i < len; ++i) {
  1937. ring = rings[i].replace(regExes.trimParens, '$1');
  1938. linestring = parse$1.linestring.apply(this$1, [ring]);
  1939. linearring = this$1.geometryFactory.createLinearRing(linestring._points);
  1940. if (i === 0) {
  1941. shell = linearring;
  1942. } else {
  1943. holes.push(linearring);
  1944. }
  1945. }
  1946. return this.geometryFactory.createPolygon(shell, holes)
  1947. },
  1948. /**
  1949. * Return a multipolygon geometry given a multipolygon WKT fragment.
  1950. *
  1951. * @param {String} str A WKT fragment representing the multipolygon.
  1952. * @return {MultiPolygon} A multipolygon geometry.
  1953. * @private
  1954. */
  1955. multipolygon: function multipolygon (str) {
  1956. var this$1 = this;
  1957. if (str === undefined) {
  1958. return this.geometryFactory.createMultiPolygon()
  1959. }
  1960. var polygon;
  1961. var polygons = str.trim().split(regExes.doubleParenComma);
  1962. var components = [];
  1963. for (var i = 0, len = polygons.length; i < len; ++i) {
  1964. polygon = polygons[i].replace(regExes.trimParens, '$1');
  1965. components.push(parse$1.polygon.apply(this$1, [polygon]));
  1966. }
  1967. return this.geometryFactory.createMultiPolygon(components)
  1968. },
  1969. /**
  1970. * Return a geometrycollection given a geometrycollection WKT fragment.
  1971. *
  1972. * @param {String} str A WKT fragment representing the geometrycollection.
  1973. * @return {GeometryCollection}
  1974. * @private
  1975. */
  1976. geometrycollection: function geometrycollection (str) {
  1977. var this$1 = this;
  1978. if (str === undefined) {
  1979. return this.geometryFactory.createGeometryCollection()
  1980. }
  1981. // separate components of the collection with |
  1982. str = str.replace(/,\s*([A-Za-z])/g, '|$1');
  1983. var wktArray = str.trim().split('|');
  1984. var components = [];
  1985. for (var i = 0, len = wktArray.length; i < len; ++i) {
  1986. components.push(this$1.read(wktArray[i]));
  1987. }
  1988. return this.geometryFactory.createGeometryCollection(components)
  1989. }
  1990. };
  1991. /**
  1992. * Writes the Well-Known Text representation of a {@link Geometry}. The
  1993. * Well-Known Text format is defined in the <A
  1994. * HREF="http://www.opengis.org/techno/specs.htm"> OGC Simple Features
  1995. * Specification for SQL</A>.
  1996. * <p>
  1997. * The <code>WKTWriter</code> outputs coordinates rounded to the precision
  1998. * model. Only the maximum number of decimal places necessary to represent the
  1999. * ordinates to the required precision will be output.
  2000. * <p>
  2001. * The SFS WKT spec does not define a special tag for {@link LinearRing}s.
  2002. * Under the spec, rings are output as <code>LINESTRING</code>s.
  2003. */
  2004. /**
  2005. * @param {GeometryFactory} geometryFactory
  2006. * @constructor
  2007. */
  2008. var WKTWriter = function WKTWriter (geometryFactory) {
  2009. this.parser = new WKTParser(geometryFactory);
  2010. };
  2011. /**
  2012. * Converts a <code>Geometry</code> to its Well-known Text representation.
  2013. *
  2014. * @param {Geometry} geometry a <code>Geometry</code> to process.
  2015. * @return {string} a <Geometry Tagged Text> string (see the OpenGIS Simple
  2016. * Features Specification).
  2017. * @memberof WKTWriter
  2018. */
  2019. WKTWriter.prototype.write = function write (geometry) {
  2020. return this.parser.write(geometry)
  2021. };
  2022. /**
  2023. * Generates the WKT for a <tt>LINESTRING</tt> specified by two
  2024. * {@link Coordinate}s.
  2025. *
  2026. * @param p0 the first coordinate.
  2027. * @param p1 the second coordinate.
  2028. *
  2029. * @return the WKT.
  2030. * @private
  2031. */
  2032. WKTWriter.toLineString = function toLineString (p0, p1) {
  2033. if (arguments.length !== 2) {
  2034. throw new Error('Not implemented')
  2035. }
  2036. return 'LINESTRING ( ' + p0.x + ' ' + p0.y + ', ' + p1.x + ' ' + p1.y + ' )'
  2037. };
  2038. var RuntimeException = (function (Error) {
  2039. function RuntimeException (message) {
  2040. Error.call(this, message);
  2041. this.name = 'RuntimeException';
  2042. this.message = message;
  2043. this.stack = (new Error()).stack;
  2044. }
  2045. if ( Error ) RuntimeException.__proto__ = Error;
  2046. RuntimeException.prototype = Object.create( Error && Error.prototype );
  2047. RuntimeException.prototype.constructor = RuntimeException;
  2048. return RuntimeException;
  2049. }(Error));
  2050. var AssertionFailedException = (function (RuntimeException$$1) {
  2051. function AssertionFailedException () {
  2052. RuntimeException$$1.call(this);
  2053. if (arguments.length === 0) {
  2054. RuntimeException$$1.call(this);
  2055. } else if (arguments.length === 1) {
  2056. var message = arguments[0];
  2057. RuntimeException$$1.call(this, message);
  2058. }
  2059. }
  2060. if ( RuntimeException$$1 ) AssertionFailedException.__proto__ = RuntimeException$$1;
  2061. AssertionFailedException.prototype = Object.create( RuntimeException$$1 && RuntimeException$$1.prototype );
  2062. AssertionFailedException.prototype.constructor = AssertionFailedException;
  2063. AssertionFailedException.prototype.interfaces_ = function interfaces_ () {
  2064. return []
  2065. };
  2066. AssertionFailedException.prototype.getClass = function getClass () {
  2067. return AssertionFailedException
  2068. };
  2069. return AssertionFailedException;
  2070. }(RuntimeException));
  2071. var Assert = function Assert () {};
  2072. Assert.prototype.interfaces_ = function interfaces_ () {
  2073. return []
  2074. };
  2075. Assert.prototype.getClass = function getClass () {
  2076. return Assert
  2077. };
  2078. Assert.shouldNeverReachHere = function shouldNeverReachHere () {
  2079. if (arguments.length === 0) {
  2080. Assert.shouldNeverReachHere(null);
  2081. } else if (arguments.length === 1) {
  2082. var message = arguments[0];
  2083. throw new AssertionFailedException('Should never reach here' + (message !== null ? ': ' + message : ''))
  2084. }
  2085. };
  2086. Assert.isTrue = function isTrue () {
  2087. var assertion;
  2088. var message;
  2089. if (arguments.length === 1) {
  2090. assertion = arguments[0];
  2091. Assert.isTrue(assertion, null);
  2092. } else if (arguments.length === 2) {
  2093. assertion = arguments[0];
  2094. message = arguments[1];
  2095. if (!assertion) {
  2096. if (message === null) {
  2097. throw new AssertionFailedException()
  2098. } else {
  2099. throw new AssertionFailedException(message)
  2100. }
  2101. }
  2102. }
  2103. };
  2104. Assert.equals = function equals () {
  2105. var expectedValue;
  2106. var actualValue;
  2107. var message;
  2108. if (arguments.length === 2) {
  2109. expectedValue = arguments[0];
  2110. actualValue = arguments[1];
  2111. Assert.equals(expectedValue, actualValue, null);
  2112. } else if (arguments.length === 3) {
  2113. expectedValue = arguments[0];
  2114. actualValue = arguments[1];
  2115. message = arguments[2];
  2116. if (!actualValue.equals(expectedValue)) {
  2117. throw new AssertionFailedException('Expected ' + expectedValue + ' but encountered ' + actualValue + (message !== null ? ': ' + message : ''))
  2118. }
  2119. }
  2120. };
  2121. var LineIntersector = function LineIntersector () {
  2122. this._result = null;
  2123. this._inputLines = Array(2).fill().map(function () { return Array(2); });
  2124. this._intPt = new Array(2).fill(null);
  2125. this._intLineIndex = null;
  2126. this._isProper = null;
  2127. this._pa = null;
  2128. this._pb = null;
  2129. this._precisionModel = null;
  2130. this._intPt[0] = new Coordinate();
  2131. this._intPt[1] = new Coordinate();
  2132. this._pa = this._intPt[0];
  2133. this._pb = this._intPt[1];
  2134. this._result = 0;
  2135. };
  2136. var staticAccessors$10 = { DONT_INTERSECT: { configurable: true },DO_INTERSECT: { configurable: true },COLLINEAR: { configurable: true },NO_INTERSECTION: { configurable: true },POINT_INTERSECTION: { configurable: true },COLLINEAR_INTERSECTION: { configurable: true } };
  2137. LineIntersector.prototype.getIndexAlongSegment = function getIndexAlongSegment (segmentIndex, intIndex) {
  2138. this.computeIntLineIndex();
  2139. return this._intLineIndex[segmentIndex][intIndex]
  2140. };
  2141. LineIntersector.prototype.getTopologySummary = function getTopologySummary () {
  2142. var catBuf = new StringBuffer();
  2143. if (this.isEndPoint()) { catBuf.append(' endpoint'); }
  2144. if (this._isProper) { catBuf.append(' proper'); }
  2145. if (this.isCollinear()) { catBuf.append(' collinear'); }
  2146. return catBuf.toString()
  2147. };
  2148. LineIntersector.prototype.computeIntersection = function computeIntersection (p1, p2, p3, p4) {
  2149. this._inputLines[0][0] = p1;
  2150. this._inputLines[0][1] = p2;
  2151. this._inputLines[1][0] = p3;
  2152. this._inputLines[1][1] = p4;
  2153. this._result = this.computeIntersect(p1, p2, p3, p4);
  2154. };
  2155. LineIntersector.prototype.getIntersectionNum = function getIntersectionNum () {
  2156. return this._result
  2157. };
  2158. LineIntersector.prototype.computeIntLineIndex = function computeIntLineIndex () {
  2159. if (arguments.length === 0) {
  2160. if (this._intLineIndex === null) {
  2161. this._intLineIndex = Array(2).fill().map(function () { return Array(2); });
  2162. this.computeIntLineIndex(0);
  2163. this.computeIntLineIndex(1);
  2164. }
  2165. } else if (arguments.length === 1) {
  2166. var segmentIndex = arguments[0];
  2167. var dist0 = this.getEdgeDistance(segmentIndex, 0);
  2168. var dist1 = this.getEdgeDistance(segmentIndex, 1);
  2169. if (dist0 > dist1) {
  2170. this._intLineIndex[segmentIndex][0] = 0;
  2171. this._intLineIndex[segmentIndex][1] = 1;
  2172. } else {
  2173. this._intLineIndex[segmentIndex][0] = 1;
  2174. this._intLineIndex[segmentIndex][1] = 0;
  2175. }
  2176. }
  2177. };
  2178. LineIntersector.prototype.isProper = function isProper () {
  2179. return this.hasIntersection() && this._isProper
  2180. };
  2181. LineIntersector.prototype.setPrecisionModel = function setPrecisionModel (precisionModel) {
  2182. this._precisionModel = precisionModel;
  2183. };
  2184. LineIntersector.prototype.isInteriorIntersection = function isInteriorIntersection () {
  2185. var this$1 = this;
  2186. if (arguments.length === 0) {
  2187. if (this.isInteriorIntersection(0)) { return true }
  2188. if (this.isInteriorIntersection(1)) { return true }
  2189. return false
  2190. } else if (arguments.length === 1) {
  2191. var inputLineIndex = arguments[0];
  2192. for (var i = 0; i < this._result; i++) {
  2193. if (!(this$1._intPt[i].equals2D(this$1._inputLines[inputLineIndex][0]) || this$1._intPt[i].equals2D(this$1._inputLines[inputLineIndex][1]))) {
  2194. return true
  2195. }
  2196. }
  2197. return false
  2198. }
  2199. };
  2200. LineIntersector.prototype.getIntersection = function getIntersection (intIndex) {
  2201. return this._intPt[intIndex]
  2202. };
  2203. LineIntersector.prototype.isEndPoint = function isEndPoint () {
  2204. return this.hasIntersection() && !this._isProper
  2205. };
  2206. LineIntersector.prototype.hasIntersection = function hasIntersection () {
  2207. return this._result !== LineIntersector.NO_INTERSECTION
  2208. };
  2209. LineIntersector.prototype.getEdgeDistance = function getEdgeDistance (segmentIndex, intIndex) {
  2210. var dist = LineIntersector.computeEdgeDistance(this._intPt[intIndex], this._inputLines[segmentIndex][0], this._inputLines[segmentIndex][1]);
  2211. return dist
  2212. };
  2213. LineIntersector.prototype.isCollinear = function isCollinear () {
  2214. return this._result === LineIntersector.COLLINEAR_INTERSECTION
  2215. };
  2216. LineIntersector.prototype.toString = function toString () {
  2217. return WKTWriter.toLineString(this._inputLines[0][0], this._inputLines[0][1]) + ' - ' + WKTWriter.toLineString(this._inputLines[1][0], this._inputLines[1][1]) + this.getTopologySummary()
  2218. };
  2219. LineIntersector.prototype.getEndpoint = function getEndpoint (segmentIndex, ptIndex) {
  2220. return this._inputLines[segmentIndex][ptIndex]
  2221. };
  2222. LineIntersector.prototype.isIntersection = function isIntersection (pt) {
  2223. var this$1 = this;
  2224. for (var i = 0; i < this._result; i++) {
  2225. if (this$1._intPt[i].equals2D(pt)) {
  2226. return true
  2227. }
  2228. }
  2229. return false
  2230. };
  2231. LineIntersector.prototype.getIntersectionAlongSegment = function getIntersectionAlongSegment (segmentIndex, intIndex) {
  2232. this.computeIntLineIndex();
  2233. return this._intPt[this._intLineIndex[segmentIndex][intIndex]]
  2234. };
  2235. LineIntersector.prototype.interfaces_ = function interfaces_ () {
  2236. return []
  2237. };
  2238. LineIntersector.prototype.getClass = function getClass () {
  2239. return LineIntersector
  2240. };
  2241. LineIntersector.computeEdgeDistance = function computeEdgeDistance (p, p0, p1) {
  2242. var dx = Math.abs(p1.x - p0.x);
  2243. var dy = Math.abs(p1.y - p0.y);
  2244. var dist = -1.0;
  2245. if (p.equals(p0)) {
  2246. dist = 0.0;
  2247. } else if (p.equals(p1)) {
  2248. if (dx > dy) { dist = dx; } else { dist = dy; }
  2249. } else {
  2250. var pdx = Math.abs(p.x - p0.x);
  2251. var pdy = Math.abs(p.y - p0.y);
  2252. if (dx > dy) { dist = pdx; } else { dist = pdy; }
  2253. if (dist === 0.0 && !p.equals(p0)) {
  2254. dist = Math.max(pdx, pdy);
  2255. }
  2256. }
  2257. Assert.isTrue(!(dist === 0.0 && !p.equals(p0)), 'Bad distance calculation');
  2258. return dist
  2259. };
  2260. LineIntersector.nonRobustComputeEdgeDistance = function nonRobustComputeEdgeDistance (p, p1, p2) {
  2261. var dx = p.x - p1.x;
  2262. var dy = p.y - p1.y;
  2263. var dist = Math.sqrt(dx * dx + dy * dy);
  2264. Assert.isTrue(!(dist === 0.0 && !p.equals(p1)), 'Invalid distance calculation');
  2265. return dist
  2266. };
  2267. staticAccessors$10.DONT_INTERSECT.get = function () { return 0 };
  2268. staticAccessors$10.DO_INTERSECT.get = function () { return 1 };
  2269. staticAccessors$10.COLLINEAR.get = function () { return 2 };
  2270. staticAccessors$10.NO_INTERSECTION.get = function () { return 0 };
  2271. staticAccessors$10.POINT_INTERSECTION.get = function () { return 1 };
  2272. staticAccessors$10.COLLINEAR_INTERSECTION.get = function () { return 2 };
  2273. Object.defineProperties( LineIntersector, staticAccessors$10 );
  2274. var RobustLineIntersector = (function (LineIntersector$$1) {
  2275. function RobustLineIntersector () {
  2276. LineIntersector$$1.apply(this, arguments);
  2277. }
  2278. if ( LineIntersector$$1 ) RobustLineIntersector.__proto__ = LineIntersector$$1;
  2279. RobustLineIntersector.prototype = Object.create( LineIntersector$$1 && LineIntersector$$1.prototype );
  2280. RobustLineIntersector.prototype.constructor = RobustLineIntersector;
  2281. RobustLineIntersector.prototype.isInSegmentEnvelopes = function isInSegmentEnvelopes (intPt) {
  2282. var env0 = new Envelope(this._inputLines[0][0], this._inputLines[0][1]);
  2283. var env1 = new Envelope(this._inputLines[1][0], this._inputLines[1][1]);
  2284. return env0.contains(intPt) && env1.contains(intPt)
  2285. };
  2286. RobustLineIntersector.prototype.computeIntersection = function computeIntersection () {
  2287. if (arguments.length === 3) {
  2288. var p = arguments[0];
  2289. var p1 = arguments[1];
  2290. var p2 = arguments[2];
  2291. this._isProper = false;
  2292. if (Envelope.intersects(p1, p2, p)) {
  2293. if (CGAlgorithms.orientationIndex(p1, p2, p) === 0 && CGAlgorithms.orientationIndex(p2, p1, p) === 0) {
  2294. this._isProper = true;
  2295. if (p.equals(p1) || p.equals(p2)) {
  2296. this._isProper = false;
  2297. }
  2298. this._result = LineIntersector$$1.POINT_INTERSECTION;
  2299. return null
  2300. }
  2301. }
  2302. this._result = LineIntersector$$1.NO_INTERSECTION;
  2303. } else { return LineIntersector$$1.prototype.computeIntersection.apply(this, arguments) }
  2304. };
  2305. RobustLineIntersector.prototype.normalizeToMinimum = function normalizeToMinimum (n1, n2, n3, n4, normPt) {
  2306. normPt.x = this.smallestInAbsValue(n1.x, n2.x, n3.x, n4.x);
  2307. normPt.y = this.smallestInAbsValue(n1.y, n2.y, n3.y, n4.y);
  2308. n1.x -= normPt.x;
  2309. n1.y -= normPt.y;
  2310. n2.x -= normPt.x;
  2311. n2.y -= normPt.y;
  2312. n3.x -= normPt.x;
  2313. n3.y -= normPt.y;
  2314. n4.x -= normPt.x;
  2315. n4.y -= normPt.y;
  2316. };
  2317. RobustLineIntersector.prototype.safeHCoordinateIntersection = function safeHCoordinateIntersection (p1, p2, q1, q2) {
  2318. var intPt = null;
  2319. try {
  2320. intPt = HCoordinate.intersection(p1, p2, q1, q2);
  2321. } catch (e) {
  2322. if (e instanceof NotRepresentableException) {
  2323. intPt = RobustLineIntersector.nearestEndpoint(p1, p2, q1, q2);
  2324. } else { throw e }
  2325. } finally {}
  2326. return intPt
  2327. };
  2328. RobustLineIntersector.prototype.intersection = function intersection (p1, p2, q1, q2) {
  2329. var intPt = this.intersectionWithNormalization(p1, p2, q1, q2);
  2330. if (!this.isInSegmentEnvelopes(intPt)) {
  2331. intPt = new Coordinate(RobustLineIntersector.nearestEndpoint(p1, p2, q1, q2));
  2332. }
  2333. if (this._precisionModel !== null) {
  2334. this._precisionModel.makePrecise(intPt);
  2335. }
  2336. return intPt
  2337. };
  2338. RobustLineIntersector.prototype.smallestInAbsValue = function smallestInAbsValue (x1, x2, x3, x4) {
  2339. var x = x1;
  2340. var xabs = Math.abs(x);
  2341. if (Math.abs(x2) < xabs) {
  2342. x = x2;
  2343. xabs = Math.abs(x2);
  2344. }
  2345. if (Math.abs(x3) < xabs) {
  2346. x = x3;
  2347. xabs = Math.abs(x3);
  2348. }
  2349. if (Math.abs(x4) < xabs) {
  2350. x = x4;
  2351. }
  2352. return x
  2353. };
  2354. RobustLineIntersector.prototype.checkDD = function checkDD (p1, p2, q1, q2, intPt) {
  2355. var intPtDD = CGAlgorithmsDD.intersection(p1, p2, q1, q2);
  2356. var isIn = this.isInSegmentEnvelopes(intPtDD);
  2357. System.out.println('DD in env = ' + isIn + ' --------------------- ' + intPtDD);
  2358. if (intPt.distance(intPtDD) > 0.0001) {
  2359. System.out.println('Distance = ' + intPt.distance(intPtDD));
  2360. }
  2361. };
  2362. RobustLineIntersector.prototype.intersectionWithNormalization = function intersectionWithNormalization (p1, p2, q1, q2) {
  2363. var n1 = new Coordinate(p1);
  2364. var n2 = new Coordinate(p2);
  2365. var n3 = new Coordinate(q1);
  2366. var n4 = new Coordinate(q2);
  2367. var normPt = new Coordinate();
  2368. this.normalizeToEnvCentre(n1, n2, n3, n4, normPt);
  2369. var intPt = this.safeHCoordinateIntersection(n1, n2, n3, n4);
  2370. intPt.x += normPt.x;
  2371. intPt.y += normPt.y;
  2372. return intPt
  2373. };
  2374. RobustLineIntersector.prototype.computeCollinearIntersection = function computeCollinearIntersection (p1, p2, q1, q2) {
  2375. var p1q1p2 = Envelope.intersects(p1, p2, q1);
  2376. var p1q2p2 = Envelope.intersects(p1, p2, q2);
  2377. var q1p1q2 = Envelope.intersects(q1, q2, p1);
  2378. var q1p2q2 = Envelope.intersects(q1, q2, p2);
  2379. if (p1q1p2 && p1q2p2) {
  2380. this._intPt[0] = q1;
  2381. this._intPt[1] = q2;
  2382. return LineIntersector$$1.COLLINEAR_INTERSECTION
  2383. }
  2384. if (q1p1q2 && q1p2q2) {
  2385. this._intPt[0] = p1;
  2386. this._intPt[1] = p2;
  2387. return LineIntersector$$1.COLLINEAR_INTERSECTION
  2388. }
  2389. if (p1q1p2 && q1p1q2) {
  2390. this._intPt[0] = q1;
  2391. this._intPt[1] = p1;
  2392. return q1.equals(p1) && !p1q2p2 && !q1p2q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
  2393. }
  2394. if (p1q1p2 && q1p2q2) {
  2395. this._intPt[0] = q1;
  2396. this._intPt[1] = p2;
  2397. return q1.equals(p2) && !p1q2p2 && !q1p1q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
  2398. }
  2399. if (p1q2p2 && q1p1q2) {
  2400. this._intPt[0] = q2;
  2401. this._intPt[1] = p1;
  2402. return q2.equals(p1) && !p1q1p2 && !q1p2q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
  2403. }
  2404. if (p1q2p2 && q1p2q2) {
  2405. this._intPt[0] = q2;
  2406. this._intPt[1] = p2;
  2407. return q2.equals(p2) && !p1q1p2 && !q1p1q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
  2408. }
  2409. return LineIntersector$$1.NO_INTERSECTION
  2410. };
  2411. RobustLineIntersector.prototype.normalizeToEnvCentre = function normalizeToEnvCentre (n00, n01, n10, n11, normPt) {
  2412. var minX0 = n00.x < n01.x ? n00.x : n01.x;
  2413. var minY0 = n00.y < n01.y ? n00.y : n01.y;
  2414. var maxX0 = n00.x > n01.x ? n00.x : n01.x;
  2415. var maxY0 = n00.y > n01.y ? n00.y : n01.y;
  2416. var minX1 = n10.x < n11.x ? n10.x : n11.x;
  2417. var minY1 = n10.y < n11.y ? n10.y : n11.y;
  2418. var maxX1 = n10.x > n11.x ? n10.x : n11.x;
  2419. var maxY1 = n10.y > n11.y ? n10.y : n11.y;
  2420. var intMinX = minX0 > minX1 ? minX0 : minX1;
  2421. var intMaxX = maxX0 < maxX1 ? maxX0 : maxX1;
  2422. var intMinY = minY0 > minY1 ? minY0 : minY1;
  2423. var intMaxY = maxY0 < maxY1 ? maxY0 : maxY1;
  2424. var intMidX = (intMinX + intMaxX) / 2.0;
  2425. var intMidY = (intMinY + intMaxY) / 2.0;
  2426. normPt.x = intMidX;
  2427. normPt.y = intMidY;
  2428. n00.x -= normPt.x;
  2429. n00.y -= normPt.y;
  2430. n01.x -= normPt.x;
  2431. n01.y -= normPt.y;
  2432. n10.x -= normPt.x;
  2433. n10.y -= normPt.y;
  2434. n11.x -= normPt.x;
  2435. n11.y -= normPt.y;
  2436. };
  2437. RobustLineIntersector.prototype.computeIntersect = function computeIntersect (p1, p2, q1, q2) {
  2438. this._isProper = false;
  2439. if (!Envelope.intersects(p1, p2, q1, q2)) { return LineIntersector$$1.NO_INTERSECTION }
  2440. var Pq1 = CGAlgorithms.orientationIndex(p1, p2, q1);
  2441. var Pq2 = CGAlgorithms.orientationIndex(p1, p2, q2);
  2442. if ((Pq1 > 0 && Pq2 > 0) || (Pq1 < 0 && Pq2 < 0)) {
  2443. return LineIntersector$$1.NO_INTERSECTION
  2444. }
  2445. var Qp1 = CGAlgorithms.orientationIndex(q1, q2, p1);
  2446. var Qp2 = CGAlgorithms.orientationIndex(q1, q2, p2);
  2447. if ((Qp1 > 0 && Qp2 > 0) || (Qp1 < 0 && Qp2 < 0)) {
  2448. return LineIntersector$$1.NO_INTERSECTION
  2449. }
  2450. var collinear = Pq1 === 0 && Pq2 === 0 && Qp1 === 0 && Qp2 === 0;
  2451. if (collinear) {
  2452. return this.computeCollinearIntersection(p1, p2, q1, q2)
  2453. }
  2454. if (Pq1 === 0 || Pq2 === 0 || Qp1 === 0 || Qp2 === 0) {
  2455. this._isProper = false;
  2456. if (p1.equals2D(q1) || p1.equals2D(q2)) {
  2457. this._intPt[0] = p1;
  2458. } else if (p2.equals2D(q1) || p2.equals2D(q2)) {
  2459. this._intPt[0] = p2;
  2460. } else if (Pq1 === 0) {
  2461. this._intPt[0] = new Coordinate(q1);
  2462. } else if (Pq2 === 0) {
  2463. this._intPt[0] = new Coordinate(q2);
  2464. } else if (Qp1 === 0) {
  2465. this._intPt[0] = new Coordinate(p1);
  2466. } else if (Qp2 === 0) {
  2467. this._intPt[0] = new Coordinate(p2);
  2468. }
  2469. } else {
  2470. this._isProper = true;
  2471. this._intPt[0] = this.intersection(p1, p2, q1, q2);
  2472. }
  2473. return LineIntersector$$1.POINT_INTERSECTION
  2474. };
  2475. RobustLineIntersector.prototype.interfaces_ = function interfaces_ () {
  2476. return []
  2477. };
  2478. RobustLineIntersector.prototype.getClass = function getClass () {
  2479. return RobustLineIntersector
  2480. };
  2481. RobustLineIntersector.nearestEndpoint = function nearestEndpoint (p1, p2, q1, q2) {
  2482. var nearestPt = p1;
  2483. var minDist = CGAlgorithms.distancePointLine(p1, q1, q2);
  2484. var dist = CGAlgorithms.distancePointLine(p2, q1, q2);
  2485. if (dist < minDist) {
  2486. minDist = dist;
  2487. nearestPt = p2;
  2488. }
  2489. dist = CGAlgorithms.distancePointLine(q1, p1, p2);
  2490. if (dist < minDist) {
  2491. minDist = dist;
  2492. nearestPt = q1;
  2493. }
  2494. dist = CGAlgorithms.distancePointLine(q2, p1, p2);
  2495. if (dist < minDist) {
  2496. minDist = dist;
  2497. nearestPt = q2;
  2498. }
  2499. return nearestPt
  2500. };
  2501. return RobustLineIntersector;
  2502. }(LineIntersector));
  2503. var RobustDeterminant = function RobustDeterminant () {};
  2504. RobustDeterminant.prototype.interfaces_ = function interfaces_ () {
  2505. return []
  2506. };
  2507. RobustDeterminant.prototype.getClass = function getClass () {
  2508. return RobustDeterminant
  2509. };
  2510. RobustDeterminant.orientationIndex = function orientationIndex (p1, p2, q) {
  2511. var dx1 = p2.x - p1.x;
  2512. var dy1 = p2.y - p1.y;
  2513. var dx2 = q.x - p2.x;
  2514. var dy2 = q.y - p2.y;
  2515. return RobustDeterminant.signOfDet2x2(dx1, dy1, dx2, dy2)
  2516. };
  2517. RobustDeterminant.signOfDet2x2 = function signOfDet2x2 (x1, y1, x2, y2) {
  2518. var sign = null;
  2519. var swap = null;
  2520. var k = null;
  2521. sign = 1;
  2522. if (x1 === 0.0 || y2 === 0.0) {
  2523. if (y1 === 0.0 || x2 === 0.0) {
  2524. return 0
  2525. } else if (y1 > 0) {
  2526. if (x2 > 0) {
  2527. return -sign
  2528. } else {
  2529. return sign
  2530. }
  2531. } else {
  2532. if (x2 > 0) {
  2533. return sign
  2534. } else {
  2535. return -sign
  2536. }
  2537. }
  2538. }
  2539. if (y1 === 0.0 || x2 === 0.0) {
  2540. if (y2 > 0) {
  2541. if (x1 > 0) {
  2542. return sign
  2543. } else {
  2544. return -sign
  2545. }
  2546. } else {
  2547. if (x1 > 0) {
  2548. return -sign
  2549. } else {
  2550. return sign
  2551. }
  2552. }
  2553. }
  2554. if (y1 > 0.0) {
  2555. if (y2 > 0.0) {
  2556. if (y1 <= y2) {
  2557. } else {
  2558. sign = -sign;
  2559. swap = x1;
  2560. x1 = x2;
  2561. x2 = swap;
  2562. swap = y1;
  2563. y1 = y2;
  2564. y2 = swap;
  2565. }
  2566. } else {
  2567. if (y1 <= -y2) {
  2568. sign = -sign;
  2569. x2 = -x2;
  2570. y2 = -y2;
  2571. } else {
  2572. swap = x1;
  2573. x1 = -x2;
  2574. x2 = swap;
  2575. swap = y1;
  2576. y1 = -y2;
  2577. y2 = swap;
  2578. }
  2579. }
  2580. } else {
  2581. if (y2 > 0.0) {
  2582. if (-y1 <= y2) {
  2583. sign = -sign;
  2584. x1 = -x1;
  2585. y1 = -y1;
  2586. } else {
  2587. swap = -x1;
  2588. x1 = x2;
  2589. x2 = swap;
  2590. swap = -y1;
  2591. y1 = y2;
  2592. y2 = swap;
  2593. }
  2594. } else {
  2595. if (y1 >= y2) {
  2596. x1 = -x1;
  2597. y1 = -y1;
  2598. x2 = -x2;
  2599. y2 = -y2;
  2600. } else {
  2601. sign = -sign;
  2602. swap = -x1;
  2603. x1 = -x2;
  2604. x2 = swap;
  2605. swap = -y1;
  2606. y1 = -y2;
  2607. y2 = swap;
  2608. }
  2609. }
  2610. }
  2611. if (x1 > 0.0) {
  2612. if (x2 > 0.0) {
  2613. if (x1 <= x2) {
  2614. } else {
  2615. return sign
  2616. }
  2617. } else {
  2618. return sign
  2619. }
  2620. } else {
  2621. if (x2 > 0.0) {
  2622. return -sign
  2623. } else {
  2624. if (x1 >= x2) {
  2625. sign = -sign;
  2626. x1 = -x1;
  2627. x2 = -x2;
  2628. } else {
  2629. return -sign
  2630. }
  2631. }
  2632. }
  2633. while (true) {
  2634. k = Math.floor(x2 / x1);
  2635. x2 = x2 - k * x1;
  2636. y2 = y2 - k * y1;
  2637. if (y2 < 0.0) {
  2638. return -sign
  2639. }
  2640. if (y2 > y1) {
  2641. return sign
  2642. }
  2643. if (x1 > x2 + x2) {
  2644. if (y1 < y2 + y2) {
  2645. return sign
  2646. }
  2647. } else {
  2648. if (y1 > y2 + y2) {
  2649. return -sign
  2650. } else {
  2651. x2 = x1 - x2;
  2652. y2 = y1 - y2;
  2653. sign = -sign;
  2654. }
  2655. }
  2656. if (y2 === 0.0) {
  2657. if (x2 === 0.0) {
  2658. return 0
  2659. } else {
  2660. return -sign
  2661. }
  2662. }
  2663. if (x2 === 0.0) {
  2664. return sign
  2665. }
  2666. k = Math.floor(x1 / x2);
  2667. x1 = x1 - k * x2;
  2668. y1 = y1 - k * y2;
  2669. if (y1 < 0.0) {
  2670. return sign
  2671. }
  2672. if (y1 > y2) {
  2673. return -sign
  2674. }
  2675. if (x2 > x1 + x1) {
  2676. if (y2 < y1 + y1) {
  2677. return -sign
  2678. }
  2679. } else {
  2680. if (y2 > y1 + y1) {
  2681. return sign
  2682. } else {
  2683. x1 = x2 - x1;
  2684. y1 = y2 - y1;
  2685. sign = -sign;
  2686. }
  2687. }
  2688. if (y1 === 0.0) {
  2689. if (x1 === 0.0) {
  2690. return 0
  2691. } else {
  2692. return sign
  2693. }
  2694. }
  2695. if (x1 === 0.0) {
  2696. return -sign
  2697. }
  2698. }
  2699. };
  2700. var RayCrossingCounter = function RayCrossingCounter () {
  2701. this._p = null;
  2702. this._crossingCount = 0;
  2703. this._isPointOnSegment = false;
  2704. var p = arguments[0];
  2705. this._p = p;
  2706. };
  2707. RayCrossingCounter.prototype.countSegment = function countSegment (p1, p2) {
  2708. if (p1.x < this._p.x && p2.x < this._p.x) { return null }
  2709. if (this._p.x === p2.x && this._p.y === p2.y) {
  2710. this._isPointOnSegment = true;
  2711. return null
  2712. }
  2713. if (p1.y === this._p.y && p2.y === this._p.y) {
  2714. var minx = p1.x;
  2715. var maxx = p2.x;
  2716. if (minx > maxx) {
  2717. minx = p2.x;
  2718. maxx = p1.x;
  2719. }
  2720. if (this._p.x >= minx && this._p.x <= maxx) {
  2721. this._isPointOnSegment = true;
  2722. }
  2723. return null
  2724. }
  2725. if ((p1.y > this._p.y && p2.y <= this._p.y) || (p2.y > this._p.y && p1.y <= this._p.y)) {
  2726. var x1 = p1.x - this._p.x;
  2727. var y1 = p1.y - this._p.y;
  2728. var x2 = p2.x - this._p.x;
  2729. var y2 = p2.y - this._p.y;
  2730. var xIntSign = RobustDeterminant.signOfDet2x2(x1, y1, x2, y2);
  2731. if (xIntSign === 0.0) {
  2732. this._isPointOnSegment = true;
  2733. return null
  2734. }
  2735. if (y2 < y1) { xIntSign = -xIntSign; }
  2736. if (xIntSign > 0.0) {
  2737. this._crossingCount++;
  2738. }
  2739. }
  2740. };
  2741. RayCrossingCounter.prototype.isPointInPolygon = function isPointInPolygon () {
  2742. return this.getLocation() !== Location.EXTERIOR
  2743. };
  2744. RayCrossingCounter.prototype.getLocation = function getLocation () {
  2745. if (this._isPointOnSegment) { return Location.BOUNDARY }
  2746. if (this._crossingCount % 2 === 1) {
  2747. return Location.INTERIOR
  2748. }
  2749. return Location.EXTERIOR
  2750. };
  2751. RayCrossingCounter.prototype.isOnSegment = function isOnSegment () {
  2752. return this._isPointOnSegment
  2753. };
  2754. RayCrossingCounter.prototype.interfaces_ = function interfaces_ () {
  2755. return []
  2756. };
  2757. RayCrossingCounter.prototype.getClass = function getClass () {
  2758. return RayCrossingCounter
  2759. };
  2760. RayCrossingCounter.locatePointInRing = function locatePointInRing () {
  2761. if (arguments[0] instanceof Coordinate && hasInterface(arguments[1], CoordinateSequence)) {
  2762. var p = arguments[0];
  2763. var ring = arguments[1];
  2764. var counter = new RayCrossingCounter(p);
  2765. var p1 = new Coordinate();
  2766. var p2 = new Coordinate();
  2767. for (var i = 1; i < ring.size(); i++) {
  2768. ring.getCoordinate(i, p1);
  2769. ring.getCoordinate(i - 1, p2);
  2770. counter.countSegment(p1, p2);
  2771. if (counter.isOnSegment()) { return counter.getLocation() }
  2772. }
  2773. return counter.getLocation()
  2774. } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Array) {
  2775. var p$1 = arguments[0];
  2776. var ring$1 = arguments[1];
  2777. var counter$1 = new RayCrossingCounter(p$1);
  2778. for (var i$1 = 1; i$1 < ring$1.length; i$1++) {
  2779. var p1$1 = ring$1[i$1];
  2780. var p2$1 = ring$1[i$1 - 1];
  2781. counter$1.countSegment(p1$1, p2$1);
  2782. if (counter$1.isOnSegment()) { return counter$1.getLocation() }
  2783. }
  2784. return counter$1.getLocation()
  2785. }
  2786. };
  2787. var CGAlgorithms = function CGAlgorithms () {};
  2788. var staticAccessors$3 = { CLOCKWISE: { configurable: true },RIGHT: { configurable: true },COUNTERCLOCKWISE: { configurable: true },LEFT: { configurable: true },COLLINEAR: { configurable: true },STRAIGHT: { configurable: true } };
  2789. CGAlgorithms.prototype.interfaces_ = function interfaces_ () {
  2790. return []
  2791. };
  2792. CGAlgorithms.prototype.getClass = function getClass () {
  2793. return CGAlgorithms
  2794. };
  2795. CGAlgorithms.orientationIndex = function orientationIndex (p1, p2, q) {
  2796. return CGAlgorithmsDD.orientationIndex(p1, p2, q)
  2797. };
  2798. CGAlgorithms.signedArea = function signedArea () {
  2799. if (arguments[0] instanceof Array) {
  2800. var ring = arguments[0];
  2801. if (ring.length < 3) { return 0.0 }
  2802. var sum = 0.0;
  2803. var x0 = ring[0].x;
  2804. for (var i = 1; i < ring.length - 1; i++) {
  2805. var x = ring[i].x - x0;
  2806. var y1 = ring[i + 1].y;
  2807. var y2 = ring[i - 1].y;
  2808. sum += x * (y2 - y1);
  2809. }
  2810. return sum / 2.0
  2811. } else if (hasInterface(arguments[0], CoordinateSequence)) {
  2812. var ring$1 = arguments[0];
  2813. var n = ring$1.size();
  2814. if (n < 3) { return 0.0 }
  2815. var p0 = new Coordinate();
  2816. var p1 = new Coordinate();
  2817. var p2 = new Coordinate();
  2818. ring$1.getCoordinate(0, p1);
  2819. ring$1.getCoordinate(1, p2);
  2820. var x0$1 = p1.x;
  2821. p2.x -= x0$1;
  2822. var sum$1 = 0.0;
  2823. for (var i$1 = 1; i$1 < n - 1; i$1++) {
  2824. p0.y = p1.y;
  2825. p1.x = p2.x;
  2826. p1.y = p2.y;
  2827. ring$1.getCoordinate(i$1 + 1, p2);
  2828. p2.x -= x0$1;
  2829. sum$1 += p1.x * (p0.y - p2.y);
  2830. }
  2831. return sum$1 / 2.0
  2832. }
  2833. };
  2834. CGAlgorithms.distanceLineLine = function distanceLineLine (A, B, C, D) {
  2835. if (A.equals(B)) { return CGAlgorithms.distancePointLine(A, C, D) }
  2836. if (C.equals(D)) { return CGAlgorithms.distancePointLine(D, A, B) }
  2837. var noIntersection = false;
  2838. if (!Envelope.intersects(A, B, C, D)) {
  2839. noIntersection = true;
  2840. } else {
  2841. var denom = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);
  2842. if (denom === 0) {
  2843. noIntersection = true;
  2844. } else {
  2845. var rNumb = (A.y - C.y) * (D.x - C.x) - (A.x - C.x) * (D.y - C.y);
  2846. var sNum = (A.y - C.y) * (B.x - A.x) - (A.x - C.x) * (B.y - A.y);
  2847. var s = sNum / denom;
  2848. var r = rNumb / denom;
  2849. if (r < 0 || r > 1 || s < 0 || s > 1) {
  2850. noIntersection = true;
  2851. }
  2852. }
  2853. }
  2854. if (noIntersection) {
  2855. return MathUtil.min(CGAlgorithms.distancePointLine(A, C, D), CGAlgorithms.distancePointLine(B, C, D), CGAlgorithms.distancePointLine(C, A, B), CGAlgorithms.distancePointLine(D, A, B))
  2856. }
  2857. return 0.0
  2858. };
  2859. CGAlgorithms.isPointInRing = function isPointInRing (p, ring) {
  2860. return CGAlgorithms.locatePointInRing(p, ring) !== Location.EXTERIOR
  2861. };
  2862. CGAlgorithms.computeLength = function computeLength (pts) {
  2863. var n = pts.size();
  2864. if (n <= 1) { return 0.0 }
  2865. var len = 0.0;
  2866. var p = new Coordinate();
  2867. pts.getCoordinate(0, p);
  2868. var x0 = p.x;
  2869. var y0 = p.y;
  2870. for (var i = 1; i < n; i++) {
  2871. pts.getCoordinate(i, p);
  2872. var x1 = p.x;
  2873. var y1 = p.y;
  2874. var dx = x1 - x0;
  2875. var dy = y1 - y0;
  2876. len += Math.sqrt(dx * dx + dy * dy);
  2877. x0 = x1;
  2878. y0 = y1;
  2879. }
  2880. return len
  2881. };
  2882. CGAlgorithms.isCCW = function isCCW (ring) {
  2883. var nPts = ring.length - 1;
  2884. if (nPts < 3) { throw new IllegalArgumentException('Ring has fewer than 4 points, so orientation cannot be determined') }
  2885. var hiPt = ring[0];
  2886. var hiIndex = 0;
  2887. for (var i = 1; i <= nPts; i++) {
  2888. var p = ring[i];
  2889. if (p.y > hiPt.y) {
  2890. hiPt = p;
  2891. hiIndex = i;
  2892. }
  2893. }
  2894. var iPrev = hiIndex;
  2895. do {
  2896. iPrev = iPrev - 1;
  2897. if (iPrev < 0) { iPrev = nPts; }
  2898. } while (ring[iPrev].equals2D(hiPt) && iPrev !== hiIndex)
  2899. var iNext = hiIndex;
  2900. do {
  2901. iNext = (iNext + 1) % nPts;
  2902. } while (ring[iNext].equals2D(hiPt) && iNext !== hiIndex)
  2903. var prev = ring[iPrev];
  2904. var next = ring[iNext];
  2905. if (prev.equals2D(hiPt) || next.equals2D(hiPt) || prev.equals2D(next)) { return false }
  2906. var disc = CGAlgorithms.computeOrientation(prev, hiPt, next);
  2907. var isCCW = false;
  2908. if (disc === 0) {
  2909. isCCW = prev.x > next.x;
  2910. } else {
  2911. isCCW = disc > 0;
  2912. }
  2913. return isCCW
  2914. };
  2915. CGAlgorithms.locatePointInRing = function locatePointInRing (p, ring) {
  2916. return RayCrossingCounter.locatePointInRing(p, ring)
  2917. };
  2918. CGAlgorithms.distancePointLinePerpendicular = function distancePointLinePerpendicular (p, A, B) {
  2919. var len2 = (B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y);
  2920. var s = ((A.y - p.y) * (B.x - A.x) - (A.x - p.x) * (B.y - A.y)) / len2;
  2921. return Math.abs(s) * Math.sqrt(len2)
  2922. };
  2923. CGAlgorithms.computeOrientation = function computeOrientation (p1, p2, q) {
  2924. return CGAlgorithms.orientationIndex(p1, p2, q)
  2925. };
  2926. CGAlgorithms.distancePointLine = function distancePointLine () {
  2927. if (arguments.length === 2) {
  2928. var p = arguments[0];
  2929. var line = arguments[1];
  2930. if (line.length === 0) { throw new IllegalArgumentException('Line array must contain at least one vertex') }
  2931. var minDistance = p.distance(line[0]);
  2932. for (var i = 0; i < line.length - 1; i++) {
  2933. var dist = CGAlgorithms.distancePointLine(p, line[i], line[i + 1]);
  2934. if (dist < minDistance) {
  2935. minDistance = dist;
  2936. }
  2937. }
  2938. return minDistance
  2939. } else if (arguments.length === 3) {
  2940. var p$1 = arguments[0];
  2941. var A = arguments[1];
  2942. var B = arguments[2];
  2943. if (A.x === B.x && A.y === B.y) { return p$1.distance(A) }
  2944. var len2 = (B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y);
  2945. var r = ((p$1.x - A.x) * (B.x - A.x) + (p$1.y - A.y) * (B.y - A.y)) / len2;
  2946. if (r <= 0.0) { return p$1.distance(A) }
  2947. if (r >= 1.0) { return p$1.distance(B) }
  2948. var s = ((A.y - p$1.y) * (B.x - A.x) - (A.x - p$1.x) * (B.y - A.y)) / len2;
  2949. return Math.abs(s) * Math.sqrt(len2)
  2950. }
  2951. };
  2952. CGAlgorithms.isOnLine = function isOnLine (p, pt) {
  2953. var lineIntersector = new RobustLineIntersector();
  2954. for (var i = 1; i < pt.length; i++) {
  2955. var p0 = pt[i - 1];
  2956. var p1 = pt[i];
  2957. lineIntersector.computeIntersection(p, p0, p1);
  2958. if (lineIntersector.hasIntersection()) {
  2959. return true
  2960. }
  2961. }
  2962. return false
  2963. };
  2964. staticAccessors$3.CLOCKWISE.get = function () { return -1 };
  2965. staticAccessors$3.RIGHT.get = function () { return CGAlgorithms.CLOCKWISE };
  2966. staticAccessors$3.COUNTERCLOCKWISE.get = function () { return 1 };
  2967. staticAccessors$3.LEFT.get = function () { return CGAlgorithms.COUNTERCLOCKWISE };
  2968. staticAccessors$3.COLLINEAR.get = function () { return 0 };
  2969. staticAccessors$3.STRAIGHT.get = function () { return CGAlgorithms.COLLINEAR };
  2970. Object.defineProperties( CGAlgorithms, staticAccessors$3 );
  2971. var GeometryComponentFilter = function GeometryComponentFilter () {};
  2972. GeometryComponentFilter.prototype.filter = function filter (geom) {};
  2973. GeometryComponentFilter.prototype.interfaces_ = function interfaces_ () {
  2974. return []
  2975. };
  2976. GeometryComponentFilter.prototype.getClass = function getClass () {
  2977. return GeometryComponentFilter
  2978. };
  2979. var Geometry = function Geometry () {
  2980. var factory = arguments[0];
  2981. this._envelope = null;
  2982. this._factory = null;
  2983. this._SRID = null;
  2984. this._userData = null;
  2985. this._factory = factory;
  2986. this._SRID = factory.getSRID();
  2987. };
  2988. var staticAccessors$11 = { serialVersionUID: { configurable: true },SORTINDEX_POINT: { configurable: true },SORTINDEX_MULTIPOINT: { configurable: true },SORTINDEX_LINESTRING: { configurable: true },SORTINDEX_LINEARRING: { configurable: true },SORTINDEX_MULTILINESTRING: { configurable: true },SORTINDEX_POLYGON: { configurable: true },SORTINDEX_MULTIPOLYGON: { configurable: true },SORTINDEX_GEOMETRYCOLLECTION: { configurable: true },geometryChangedFilter: { configurable: true } };
  2989. Geometry.prototype.isGeometryCollection = function isGeometryCollection () {
  2990. return this.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION
  2991. };
  2992. Geometry.prototype.getFactory = function getFactory () {
  2993. return this._factory
  2994. };
  2995. Geometry.prototype.getGeometryN = function getGeometryN (n) {
  2996. return this
  2997. };
  2998. Geometry.prototype.getArea = function getArea () {
  2999. return 0.0
  3000. };
  3001. Geometry.prototype.isRectangle = function isRectangle () {
  3002. return false
  3003. };
  3004. Geometry.prototype.equals = function equals () {
  3005. if (arguments[0] instanceof Geometry) {
  3006. var g$1 = arguments[0];
  3007. if (g$1 === null) { return false }
  3008. return this.equalsTopo(g$1)
  3009. } else if (arguments[0] instanceof Object) {
  3010. var o = arguments[0];
  3011. if (!(o instanceof Geometry)) { return false }
  3012. var g = o;
  3013. return this.equalsExact(g)
  3014. }
  3015. };
  3016. Geometry.prototype.equalsExact = function equalsExact (other) {
  3017. return this === other || this.equalsExact(other, 0)
  3018. };
  3019. Geometry.prototype.geometryChanged = function geometryChanged () {
  3020. this.apply(Geometry.geometryChangedFilter);
  3021. };
  3022. Geometry.prototype.geometryChangedAction = function geometryChangedAction () {
  3023. this._envelope = null;
  3024. };
  3025. Geometry.prototype.equalsNorm = function equalsNorm (g) {
  3026. if (g === null) { return false }
  3027. return this.norm().equalsExact(g.norm())
  3028. };
  3029. Geometry.prototype.getLength = function getLength () {
  3030. return 0.0
  3031. };
  3032. Geometry.prototype.getNumGeometries = function getNumGeometries () {
  3033. return 1
  3034. };
  3035. Geometry.prototype.compareTo = function compareTo () {
  3036. if (arguments.length === 1) {
  3037. var o = arguments[0];
  3038. var other = o;
  3039. if (this.getSortIndex() !== other.getSortIndex()) {
  3040. return this.getSortIndex() - other.getSortIndex()
  3041. }
  3042. if (this.isEmpty() && other.isEmpty()) {
  3043. return 0
  3044. }
  3045. if (this.isEmpty()) {
  3046. return -1
  3047. }
  3048. if (other.isEmpty()) {
  3049. return 1
  3050. }
  3051. return this.compareToSameClass(o)
  3052. } else if (arguments.length === 2) {
  3053. var other$1 = arguments[0];
  3054. var comp = arguments[1];
  3055. if (this.getSortIndex() !== other$1.getSortIndex()) {
  3056. return this.getSortIndex() - other$1.getSortIndex()
  3057. }
  3058. if (this.isEmpty() && other$1.isEmpty()) {
  3059. return 0
  3060. }
  3061. if (this.isEmpty()) {
  3062. return -1
  3063. }
  3064. if (other$1.isEmpty()) {
  3065. return 1
  3066. }
  3067. return this.compareToSameClass(other$1, comp)
  3068. }
  3069. };
  3070. Geometry.prototype.getUserData = function getUserData () {
  3071. return this._userData
  3072. };
  3073. Geometry.prototype.getSRID = function getSRID () {
  3074. return this._SRID
  3075. };
  3076. Geometry.prototype.getEnvelope = function getEnvelope () {
  3077. return this.getFactory().toGeometry(this.getEnvelopeInternal())
  3078. };
  3079. Geometry.prototype.checkNotGeometryCollection = function checkNotGeometryCollection (g) {
  3080. if (g.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION) {
  3081. throw new IllegalArgumentException('This method does not support GeometryCollection arguments')
  3082. }
  3083. };
  3084. Geometry.prototype.equal = function equal (a, b, tolerance) {
  3085. if (tolerance === 0) {
  3086. return a.equals(b)
  3087. }
  3088. return a.distance(b) <= tolerance
  3089. };
  3090. Geometry.prototype.norm = function norm () {
  3091. var copy = this.copy();
  3092. copy.normalize();
  3093. return copy
  3094. };
  3095. Geometry.prototype.getPrecisionModel = function getPrecisionModel () {
  3096. return this._factory.getPrecisionModel()
  3097. };
  3098. Geometry.prototype.getEnvelopeInternal = function getEnvelopeInternal () {
  3099. if (this._envelope === null) {
  3100. this._envelope = this.computeEnvelopeInternal();
  3101. }
  3102. return new Envelope(this._envelope)
  3103. };
  3104. Geometry.prototype.setSRID = function setSRID (SRID) {
  3105. this._SRID = SRID;
  3106. };
  3107. Geometry.prototype.setUserData = function setUserData (userData) {
  3108. this._userData = userData;
  3109. };
  3110. Geometry.prototype.compare = function compare (a, b) {
  3111. var i = a.iterator();
  3112. var j = b.iterator();
  3113. while (i.hasNext() && j.hasNext()) {
  3114. var aElement = i.next();
  3115. var bElement = j.next();
  3116. var comparison = aElement.compareTo(bElement);
  3117. if (comparison !== 0) {
  3118. return comparison
  3119. }
  3120. }
  3121. if (i.hasNext()) {
  3122. return 1
  3123. }
  3124. if (j.hasNext()) {
  3125. return -1
  3126. }
  3127. return 0
  3128. };
  3129. Geometry.prototype.hashCode = function hashCode () {
  3130. return this.getEnvelopeInternal().hashCode()
  3131. };
  3132. Geometry.prototype.isGeometryCollectionOrDerived = function isGeometryCollectionOrDerived () {
  3133. if (this.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION || this.getSortIndex() === Geometry.SORTINDEX_MULTIPOINT || this.getSortIndex() === Geometry.SORTINDEX_MULTILINESTRING || this.getSortIndex() === Geometry.SORTINDEX_MULTIPOLYGON) {
  3134. return true
  3135. }
  3136. return false
  3137. };
  3138. Geometry.prototype.interfaces_ = function interfaces_ () {
  3139. return [Clonable, Comparable, Serializable]
  3140. };
  3141. Geometry.prototype.getClass = function getClass () {
  3142. return Geometry
  3143. };
  3144. Geometry.hasNonEmptyElements = function hasNonEmptyElements (geometries) {
  3145. for (var i = 0; i < geometries.length; i++) {
  3146. if (!geometries[i].isEmpty()) {
  3147. return true
  3148. }
  3149. }
  3150. return false
  3151. };
  3152. Geometry.hasNullElements = function hasNullElements (array) {
  3153. for (var i = 0; i < array.length; i++) {
  3154. if (array[i] === null) {
  3155. return true
  3156. }
  3157. }
  3158. return false
  3159. };
  3160. staticAccessors$11.serialVersionUID.get = function () { return 8763622679187376702 };
  3161. staticAccessors$11.SORTINDEX_POINT.get = function () { return 0 };
  3162. staticAccessors$11.SORTINDEX_MULTIPOINT.get = function () { return 1 };
  3163. staticAccessors$11.SORTINDEX_LINESTRING.get = function () { return 2 };
  3164. staticAccessors$11.SORTINDEX_LINEARRING.get = function () { return 3 };
  3165. staticAccessors$11.SORTINDEX_MULTILINESTRING.get = function () { return 4 };
  3166. staticAccessors$11.SORTINDEX_POLYGON.get = function () { return 5 };
  3167. staticAccessors$11.SORTINDEX_MULTIPOLYGON.get = function () { return 6 };
  3168. staticAccessors$11.SORTINDEX_GEOMETRYCOLLECTION.get = function () { return 7 };
  3169. staticAccessors$11.geometryChangedFilter.get = function () { return geometryChangedFilter };
  3170. Object.defineProperties( Geometry, staticAccessors$11 );
  3171. var geometryChangedFilter = function geometryChangedFilter () {};
  3172. geometryChangedFilter.interfaces_ = function interfaces_ () {
  3173. return [GeometryComponentFilter]
  3174. };
  3175. geometryChangedFilter.filter = function filter (geom) {
  3176. geom.geometryChangedAction();
  3177. };
  3178. var CoordinateFilter = function CoordinateFilter () {};
  3179. CoordinateFilter.prototype.filter = function filter (coord) {};
  3180. CoordinateFilter.prototype.interfaces_ = function interfaces_ () {
  3181. return []
  3182. };
  3183. CoordinateFilter.prototype.getClass = function getClass () {
  3184. return CoordinateFilter
  3185. };
  3186. var BoundaryNodeRule = function BoundaryNodeRule () {};
  3187. var staticAccessors$12 = { Mod2BoundaryNodeRule: { configurable: true },EndPointBoundaryNodeRule: { configurable: true },MultiValentEndPointBoundaryNodeRule: { configurable: true },MonoValentEndPointBoundaryNodeRule: { configurable: true },MOD2_BOUNDARY_RULE: { configurable: true },ENDPOINT_BOUNDARY_RULE: { configurable: true },MULTIVALENT_ENDPOINT_BOUNDARY_RULE: { configurable: true },MONOVALENT_ENDPOINT_BOUNDARY_RULE: { configurable: true },OGC_SFS_BOUNDARY_RULE: { configurable: true } };
  3188. BoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {};
  3189. BoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
  3190. return []
  3191. };
  3192. BoundaryNodeRule.prototype.getClass = function getClass () {
  3193. return BoundaryNodeRule
  3194. };
  3195. staticAccessors$12.Mod2BoundaryNodeRule.get = function () { return Mod2BoundaryNodeRule };
  3196. staticAccessors$12.EndPointBoundaryNodeRule.get = function () { return EndPointBoundaryNodeRule };
  3197. staticAccessors$12.MultiValentEndPointBoundaryNodeRule.get = function () { return MultiValentEndPointBoundaryNodeRule };
  3198. staticAccessors$12.MonoValentEndPointBoundaryNodeRule.get = function () { return MonoValentEndPointBoundaryNodeRule };
  3199. staticAccessors$12.MOD2_BOUNDARY_RULE.get = function () { return new Mod2BoundaryNodeRule() };
  3200. staticAccessors$12.ENDPOINT_BOUNDARY_RULE.get = function () { return new EndPointBoundaryNodeRule() };
  3201. staticAccessors$12.MULTIVALENT_ENDPOINT_BOUNDARY_RULE.get = function () { return new MultiValentEndPointBoundaryNodeRule() };
  3202. staticAccessors$12.MONOVALENT_ENDPOINT_BOUNDARY_RULE.get = function () { return new MonoValentEndPointBoundaryNodeRule() };
  3203. staticAccessors$12.OGC_SFS_BOUNDARY_RULE.get = function () { return BoundaryNodeRule.MOD2_BOUNDARY_RULE };
  3204. Object.defineProperties( BoundaryNodeRule, staticAccessors$12 );
  3205. var Mod2BoundaryNodeRule = function Mod2BoundaryNodeRule () {};
  3206. Mod2BoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
  3207. return boundaryCount % 2 === 1
  3208. };
  3209. Mod2BoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
  3210. return [BoundaryNodeRule]
  3211. };
  3212. Mod2BoundaryNodeRule.prototype.getClass = function getClass () {
  3213. return Mod2BoundaryNodeRule
  3214. };
  3215. var EndPointBoundaryNodeRule = function EndPointBoundaryNodeRule () {};
  3216. EndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
  3217. return boundaryCount > 0
  3218. };
  3219. EndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
  3220. return [BoundaryNodeRule]
  3221. };
  3222. EndPointBoundaryNodeRule.prototype.getClass = function getClass () {
  3223. return EndPointBoundaryNodeRule
  3224. };
  3225. var MultiValentEndPointBoundaryNodeRule = function MultiValentEndPointBoundaryNodeRule () {};
  3226. MultiValentEndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
  3227. return boundaryCount > 1
  3228. };
  3229. MultiValentEndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
  3230. return [BoundaryNodeRule]
  3231. };
  3232. MultiValentEndPointBoundaryNodeRule.prototype.getClass = function getClass () {
  3233. return MultiValentEndPointBoundaryNodeRule
  3234. };
  3235. var MonoValentEndPointBoundaryNodeRule = function MonoValentEndPointBoundaryNodeRule () {};
  3236. MonoValentEndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
  3237. return boundaryCount === 1
  3238. };
  3239. MonoValentEndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
  3240. return [BoundaryNodeRule]
  3241. };
  3242. MonoValentEndPointBoundaryNodeRule.prototype.getClass = function getClass () {
  3243. return MonoValentEndPointBoundaryNodeRule
  3244. };
  3245. // import Iterator from './Iterator'
  3246. /**
  3247. * @see http://download.oracle.com/javase/6/docs/api/java/util/Collection.html
  3248. *
  3249. * @constructor
  3250. * @private
  3251. */
  3252. var Collection = function Collection () {};
  3253. Collection.prototype.add = function add () {};
  3254. /**
  3255. * Appends all of the elements in the specified collection to the end of this
  3256. * list, in the order that they are returned by the specified collection's
  3257. * iterator (optional operation).
  3258. * @param {javascript.util.Collection} c
  3259. * @return {boolean}
  3260. */
  3261. Collection.prototype.addAll = function addAll () {};
  3262. /**
  3263. * Returns true if this collection contains no elements.
  3264. * @return {boolean}
  3265. */
  3266. Collection.prototype.isEmpty = function isEmpty () {};
  3267. /**
  3268. * Returns an iterator over the elements in this collection.
  3269. * @return {javascript.util.Iterator}
  3270. */
  3271. Collection.prototype.iterator = function iterator () {};
  3272. /**
  3273. * Returns an iterator over the elements in this collection.
  3274. * @return {number}
  3275. */
  3276. Collection.prototype.size = function size () {};
  3277. /**
  3278. * Returns an array containing all of the elements in this collection.
  3279. * @return {Array}
  3280. */
  3281. Collection.prototype.toArray = function toArray () {};
  3282. /**
  3283. * Removes a single instance of the specified element from this collection if it
  3284. * is present. (optional)
  3285. * @param {Object} e
  3286. * @return {boolean}
  3287. */
  3288. Collection.prototype.remove = function remove () {};
  3289. /**
  3290. * @param {string=} message Optional message
  3291. * @extends {Error}
  3292. * @constructor
  3293. * @private
  3294. */
  3295. function IndexOutOfBoundsException (message) {
  3296. this.message = message || '';
  3297. }
  3298. IndexOutOfBoundsException.prototype = new Error();
  3299. /**
  3300. * @type {string}
  3301. */
  3302. IndexOutOfBoundsException.prototype.name = 'IndexOutOfBoundsException';
  3303. /**
  3304. * @see http://download.oracle.com/javase/6/docs/api/java/util/Iterator.html
  3305. * @constructor
  3306. * @private
  3307. */
  3308. var Iterator = function Iterator () {};
  3309. Iterator.prototype.hasNext = function hasNext () {};
  3310. /**
  3311. * Returns the next element in the iteration.
  3312. * @return {Object}
  3313. */
  3314. Iterator.prototype.next = function next () {};
  3315. /**
  3316. * Removes from the underlying collection the last element returned by the
  3317. * iterator (optional operation).
  3318. */
  3319. Iterator.prototype.remove = function remove () {};
  3320. /**
  3321. * @see http://download.oracle.com/javase/6/docs/api/java/util/List.html
  3322. *
  3323. * @extends {javascript.util.Collection}
  3324. * @constructor
  3325. * @private
  3326. */
  3327. var List = (function (Collection$$1) {
  3328. function List () {
  3329. Collection$$1.apply(this, arguments);
  3330. }
  3331. if ( Collection$$1 ) List.__proto__ = Collection$$1;
  3332. List.prototype = Object.create( Collection$$1 && Collection$$1.prototype );
  3333. List.prototype.constructor = List;
  3334. List.prototype.get = function get () { };
  3335. /**
  3336. * Replaces the element at the specified position in this list with the
  3337. * specified element (optional operation).
  3338. * @param {number} index
  3339. * @param {Object} e
  3340. * @return {Object}
  3341. */
  3342. List.prototype.set = function set () { };
  3343. /**
  3344. * Returns true if this collection contains no elements.
  3345. * @return {boolean}
  3346. */
  3347. List.prototype.isEmpty = function isEmpty () { };
  3348. return List;
  3349. }(Collection));
  3350. /**
  3351. * @param {string=} message Optional message
  3352. * @extends {Error}
  3353. * @constructor
  3354. * @private
  3355. */
  3356. function NoSuchElementException (message) {
  3357. this.message = message || '';
  3358. }
  3359. NoSuchElementException.prototype = new Error();
  3360. /**
  3361. * @type {string}
  3362. */
  3363. NoSuchElementException.prototype.name = 'NoSuchElementException';
  3364. // import OperationNotSupported from './OperationNotSupported'
  3365. /**
  3366. * @see http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html
  3367. *
  3368. * @extends List
  3369. * @private
  3370. */
  3371. var ArrayList = (function (List$$1) {
  3372. function ArrayList () {
  3373. List$$1.call(this);
  3374. this.array_ = [];
  3375. if (arguments[0] instanceof Collection) {
  3376. this.addAll(arguments[0]);
  3377. }
  3378. }
  3379. if ( List$$1 ) ArrayList.__proto__ = List$$1;
  3380. ArrayList.prototype = Object.create( List$$1 && List$$1.prototype );
  3381. ArrayList.prototype.constructor = ArrayList;
  3382. ArrayList.prototype.ensureCapacity = function ensureCapacity () {};
  3383. ArrayList.prototype.interfaces_ = function interfaces_ () { return [List$$1, Collection] };
  3384. /**
  3385. * @override
  3386. */
  3387. ArrayList.prototype.add = function add (e) {
  3388. if (arguments.length === 1) {
  3389. this.array_.push(e);
  3390. } else {
  3391. this.array_.splice(arguments[0], arguments[1]);
  3392. }
  3393. return true
  3394. };
  3395. ArrayList.prototype.clear = function clear () {
  3396. this.array_ = [];
  3397. };
  3398. /**
  3399. * @override
  3400. */
  3401. ArrayList.prototype.addAll = function addAll (c) {
  3402. var this$1 = this;
  3403. for (var i = c.iterator(); i.hasNext();) {
  3404. this$1.add(i.next());
  3405. }
  3406. return true
  3407. };
  3408. /**
  3409. * @override
  3410. */
  3411. ArrayList.prototype.set = function set (index, element) {
  3412. var oldElement = this.array_[index];
  3413. this.array_[index] = element;
  3414. return oldElement
  3415. };
  3416. /**
  3417. * @override
  3418. */
  3419. ArrayList.prototype.iterator = function iterator () {
  3420. return new Iterator_(this)
  3421. };
  3422. /**
  3423. * @override
  3424. */
  3425. ArrayList.prototype.get = function get (index) {
  3426. if (index < 0 || index >= this.size()) {
  3427. throw new IndexOutOfBoundsException()
  3428. }
  3429. return this.array_[index]
  3430. };
  3431. /**
  3432. * @override
  3433. */
  3434. ArrayList.prototype.isEmpty = function isEmpty () {
  3435. return this.array_.length === 0
  3436. };
  3437. /**
  3438. * @override
  3439. */
  3440. ArrayList.prototype.size = function size () {
  3441. return this.array_.length
  3442. };
  3443. /**
  3444. * @override
  3445. */
  3446. ArrayList.prototype.toArray = function toArray () {
  3447. var this$1 = this;
  3448. var array = [];
  3449. for (var i = 0, len = this.array_.length; i < len; i++) {
  3450. array.push(this$1.array_[i]);
  3451. }
  3452. return array
  3453. };
  3454. /**
  3455. * @override
  3456. */
  3457. ArrayList.prototype.remove = function remove (o) {
  3458. var this$1 = this;
  3459. var found = false;
  3460. for (var i = 0, len = this.array_.length; i < len; i++) {
  3461. if (this$1.array_[i] === o) {
  3462. this$1.array_.splice(i, 1);
  3463. found = true;
  3464. break
  3465. }
  3466. }
  3467. return found
  3468. };
  3469. return ArrayList;
  3470. }(List));
  3471. /**
  3472. * @extends {Iterator}
  3473. * @param {ArrayList} arrayList
  3474. * @constructor
  3475. * @private
  3476. */
  3477. var Iterator_ = (function (Iterator$$1) {
  3478. function Iterator_ (arrayList) {
  3479. Iterator$$1.call(this);
  3480. /**
  3481. * @type {ArrayList}
  3482. * @private
  3483. */
  3484. this.arrayList_ = arrayList;
  3485. /**
  3486. * @type {number}
  3487. * @private
  3488. */
  3489. this.position_ = 0;
  3490. }
  3491. if ( Iterator$$1 ) Iterator_.__proto__ = Iterator$$1;
  3492. Iterator_.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
  3493. Iterator_.prototype.constructor = Iterator_;
  3494. /**
  3495. * @override
  3496. */
  3497. Iterator_.prototype.next = function next () {
  3498. if (this.position_ === this.arrayList_.size()) {
  3499. throw new NoSuchElementException()
  3500. }
  3501. return this.arrayList_.get(this.position_++)
  3502. };
  3503. /**
  3504. * @override
  3505. */
  3506. Iterator_.prototype.hasNext = function hasNext () {
  3507. if (this.position_ < this.arrayList_.size()) {
  3508. return true
  3509. } else {
  3510. return false
  3511. }
  3512. };
  3513. /**
  3514. * TODO: should be in ListIterator
  3515. * @override
  3516. */
  3517. Iterator_.prototype.set = function set (element) {
  3518. return this.arrayList_.set(this.position_ - 1, element)
  3519. };
  3520. /**
  3521. * @override
  3522. */
  3523. Iterator_.prototype.remove = function remove () {
  3524. this.arrayList_.remove(this.arrayList_.get(this.position_));
  3525. };
  3526. return Iterator_;
  3527. }(Iterator));
  3528. var CoordinateList = (function (ArrayList$$1) {
  3529. function CoordinateList () {
  3530. ArrayList$$1.call(this);
  3531. if (arguments.length === 0) {
  3532. } else if (arguments.length === 1) {
  3533. var coord = arguments[0];
  3534. this.ensureCapacity(coord.length);
  3535. this.add(coord, true);
  3536. } else if (arguments.length === 2) {
  3537. var coord$1 = arguments[0];
  3538. var allowRepeated = arguments[1];
  3539. this.ensureCapacity(coord$1.length);
  3540. this.add(coord$1, allowRepeated);
  3541. }
  3542. }
  3543. if ( ArrayList$$1 ) CoordinateList.__proto__ = ArrayList$$1;
  3544. CoordinateList.prototype = Object.create( ArrayList$$1 && ArrayList$$1.prototype );
  3545. CoordinateList.prototype.constructor = CoordinateList;
  3546. var staticAccessors = { coordArrayType: { configurable: true } };
  3547. staticAccessors.coordArrayType.get = function () { return new Array(0).fill(null) };
  3548. CoordinateList.prototype.getCoordinate = function getCoordinate (i) {
  3549. return this.get(i)
  3550. };
  3551. CoordinateList.prototype.addAll = function addAll () {
  3552. var this$1 = this;
  3553. if (arguments.length === 2) {
  3554. var coll = arguments[0];
  3555. var allowRepeated = arguments[1];
  3556. var isChanged = false;
  3557. for (var i = coll.iterator(); i.hasNext();) {
  3558. this$1.add(i.next(), allowRepeated);
  3559. isChanged = true;
  3560. }
  3561. return isChanged
  3562. } else { return ArrayList$$1.prototype.addAll.apply(this, arguments) }
  3563. };
  3564. CoordinateList.prototype.clone = function clone () {
  3565. var this$1 = this;
  3566. var clone = ArrayList$$1.prototype.clone.call(this);
  3567. for (var i = 0; i < this.size(); i++) {
  3568. clone.add(i, this$1.get(i).copy());
  3569. }
  3570. return clone
  3571. };
  3572. CoordinateList.prototype.toCoordinateArray = function toCoordinateArray () {
  3573. return this.toArray(CoordinateList.coordArrayType)
  3574. };
  3575. CoordinateList.prototype.add = function add () {
  3576. var this$1 = this;
  3577. if (arguments.length === 1) {
  3578. var coord = arguments[0];
  3579. ArrayList$$1.prototype.add.call(this, coord);
  3580. } else if (arguments.length === 2) {
  3581. if (arguments[0] instanceof Array && typeof arguments[1] === 'boolean') {
  3582. var coord$1 = arguments[0];
  3583. var allowRepeated = arguments[1];
  3584. this.add(coord$1, allowRepeated, true);
  3585. return true
  3586. } else if (arguments[0] instanceof Coordinate && typeof arguments[1] === 'boolean') {
  3587. var coord$2 = arguments[0];
  3588. var allowRepeated$1 = arguments[1];
  3589. if (!allowRepeated$1) {
  3590. if (this.size() >= 1) {
  3591. var last = this.get(this.size() - 1);
  3592. if (last.equals2D(coord$2)) { return null }
  3593. }
  3594. }
  3595. ArrayList$$1.prototype.add.call(this, coord$2);
  3596. } else if (arguments[0] instanceof Object && typeof arguments[1] === 'boolean') {
  3597. var obj = arguments[0];
  3598. var allowRepeated$2 = arguments[1];
  3599. this.add(obj, allowRepeated$2);
  3600. return true
  3601. }
  3602. } else if (arguments.length === 3) {
  3603. if (typeof arguments[2] === 'boolean' && (arguments[0] instanceof Array && typeof arguments[1] === 'boolean')) {
  3604. var coord$3 = arguments[0];
  3605. var allowRepeated$3 = arguments[1];
  3606. var direction = arguments[2];
  3607. if (direction) {
  3608. for (var i$1 = 0; i$1 < coord$3.length; i$1++) {
  3609. this$1.add(coord$3[i$1], allowRepeated$3);
  3610. }
  3611. } else {
  3612. for (var i$2 = coord$3.length - 1; i$2 >= 0; i$2--) {
  3613. this$1.add(coord$3[i$2], allowRepeated$3);
  3614. }
  3615. }
  3616. return true
  3617. } else if (typeof arguments[2] === 'boolean' && (Number.isInteger(arguments[0]) && arguments[1] instanceof Coordinate)) {
  3618. var i$3 = arguments[0];
  3619. var coord$4 = arguments[1];
  3620. var allowRepeated$4 = arguments[2];
  3621. if (!allowRepeated$4) {
  3622. var size = this.size();
  3623. if (size > 0) {
  3624. if (i$3 > 0) {
  3625. var prev = this.get(i$3 - 1);
  3626. if (prev.equals2D(coord$4)) { return null }
  3627. }
  3628. if (i$3 < size) {
  3629. var next = this.get(i$3);
  3630. if (next.equals2D(coord$4)) { return null }
  3631. }
  3632. }
  3633. }
  3634. ArrayList$$1.prototype.add.call(this, i$3, coord$4);
  3635. }
  3636. } else if (arguments.length === 4) {
  3637. var coord$5 = arguments[0];
  3638. var allowRepeated$5 = arguments[1];
  3639. var start = arguments[2];
  3640. var end = arguments[3];
  3641. var inc = 1;
  3642. if (start > end) { inc = -1; }
  3643. for (var i = start; i !== end; i += inc) {
  3644. this$1.add(coord$5[i], allowRepeated$5);
  3645. }
  3646. return true
  3647. }
  3648. };
  3649. CoordinateList.prototype.closeRing = function closeRing () {
  3650. if (this.size() > 0) { this.add(new Coordinate(this.get(0)), false); }
  3651. };
  3652. CoordinateList.prototype.interfaces_ = function interfaces_ () {
  3653. return []
  3654. };
  3655. CoordinateList.prototype.getClass = function getClass () {
  3656. return CoordinateList
  3657. };
  3658. Object.defineProperties( CoordinateList, staticAccessors );
  3659. return CoordinateList;
  3660. }(ArrayList));
  3661. var CoordinateArrays = function CoordinateArrays () {};
  3662. var staticAccessors$13 = { ForwardComparator: { configurable: true },BidirectionalComparator: { configurable: true },coordArrayType: { configurable: true } };
  3663. staticAccessors$13.ForwardComparator.get = function () { return ForwardComparator };
  3664. staticAccessors$13.BidirectionalComparator.get = function () { return BidirectionalComparator };
  3665. staticAccessors$13.coordArrayType.get = function () { return new Array(0).fill(null) };
  3666. CoordinateArrays.prototype.interfaces_ = function interfaces_ () {
  3667. return []
  3668. };
  3669. CoordinateArrays.prototype.getClass = function getClass () {
  3670. return CoordinateArrays
  3671. };
  3672. CoordinateArrays.isRing = function isRing (pts) {
  3673. if (pts.length < 4) { return false }
  3674. if (!pts[0].equals2D(pts[pts.length - 1])) { return false }
  3675. return true
  3676. };
  3677. CoordinateArrays.ptNotInList = function ptNotInList (testPts, pts) {
  3678. for (var i = 0; i < testPts.length; i++) {
  3679. var testPt = testPts[i];
  3680. if (CoordinateArrays.indexOf(testPt, pts) < 0) { return testPt }
  3681. }
  3682. return null
  3683. };
  3684. CoordinateArrays.scroll = function scroll (coordinates, firstCoordinate) {
  3685. var i = CoordinateArrays.indexOf(firstCoordinate, coordinates);
  3686. if (i < 0) { return null }
  3687. var newCoordinates = new Array(coordinates.length).fill(null);
  3688. System.arraycopy(coordinates, i, newCoordinates, 0, coordinates.length - i);
  3689. System.arraycopy(coordinates, 0, newCoordinates, coordinates.length - i, i);
  3690. System.arraycopy(newCoordinates, 0, coordinates, 0, coordinates.length);
  3691. };
  3692. CoordinateArrays.equals = function equals () {
  3693. if (arguments.length === 2) {
  3694. var coord1 = arguments[0];
  3695. var coord2 = arguments[1];
  3696. if (coord1 === coord2) { return true }
  3697. if (coord1 === null || coord2 === null) { return false }
  3698. if (coord1.length !== coord2.length) { return false }
  3699. for (var i = 0; i < coord1.length; i++) {
  3700. if (!coord1[i].equals(coord2[i])) { return false }
  3701. }
  3702. return true
  3703. } else if (arguments.length === 3) {
  3704. var coord1$1 = arguments[0];
  3705. var coord2$1 = arguments[1];
  3706. var coordinateComparator = arguments[2];
  3707. if (coord1$1 === coord2$1) { return true }
  3708. if (coord1$1 === null || coord2$1 === null) { return false }
  3709. if (coord1$1.length !== coord2$1.length) { return false }
  3710. for (var i$1 = 0; i$1 < coord1$1.length; i$1++) {
  3711. if (coordinateComparator.compare(coord1$1[i$1], coord2$1[i$1]) !== 0) { return false }
  3712. }
  3713. return true
  3714. }
  3715. };
  3716. CoordinateArrays.intersection = function intersection (coordinates, env) {
  3717. var coordList = new CoordinateList();
  3718. for (var i = 0; i < coordinates.length; i++) {
  3719. if (env.intersects(coordinates[i])) { coordList.add(coordinates[i], true); }
  3720. }
  3721. return coordList.toCoordinateArray()
  3722. };
  3723. CoordinateArrays.hasRepeatedPoints = function hasRepeatedPoints (coord) {
  3724. for (var i = 1; i < coord.length; i++) {
  3725. if (coord[i - 1].equals(coord[i])) {
  3726. return true
  3727. }
  3728. }
  3729. return false
  3730. };
  3731. CoordinateArrays.removeRepeatedPoints = function removeRepeatedPoints (coord) {
  3732. if (!CoordinateArrays.hasRepeatedPoints(coord)) { return coord }
  3733. var coordList = new CoordinateList(coord, false);
  3734. return coordList.toCoordinateArray()
  3735. };
  3736. CoordinateArrays.reverse = function reverse (coord) {
  3737. var last = coord.length - 1;
  3738. var mid = Math.trunc(last / 2);
  3739. for (var i = 0; i <= mid; i++) {
  3740. var tmp = coord[i];
  3741. coord[i] = coord[last - i];
  3742. coord[last - i] = tmp;
  3743. }
  3744. };
  3745. CoordinateArrays.removeNull = function removeNull (coord) {
  3746. var nonNull = 0;
  3747. for (var i = 0; i < coord.length; i++) {
  3748. if (coord[i] !== null) { nonNull++; }
  3749. }
  3750. var newCoord = new Array(nonNull).fill(null);
  3751. if (nonNull === 0) { return newCoord }
  3752. var j = 0;
  3753. for (var i$1 = 0; i$1 < coord.length; i$1++) {
  3754. if (coord[i$1] !== null) { newCoord[j++] = coord[i$1]; }
  3755. }
  3756. return newCoord
  3757. };
  3758. CoordinateArrays.copyDeep = function copyDeep () {
  3759. if (arguments.length === 1) {
  3760. var coordinates = arguments[0];
  3761. var copy = new Array(coordinates.length).fill(null);
  3762. for (var i = 0; i < coordinates.length; i++) {
  3763. copy[i] = new Coordinate(coordinates[i]);
  3764. }
  3765. return copy
  3766. } else if (arguments.length === 5) {
  3767. var src = arguments[0];
  3768. var srcStart = arguments[1];
  3769. var dest = arguments[2];
  3770. var destStart = arguments[3];
  3771. var length = arguments[4];
  3772. for (var i$1 = 0; i$1 < length; i$1++) {
  3773. dest[destStart + i$1] = new Coordinate(src[srcStart + i$1]);
  3774. }
  3775. }
  3776. };
  3777. CoordinateArrays.isEqualReversed = function isEqualReversed (pts1, pts2) {
  3778. for (var i = 0; i < pts1.length; i++) {
  3779. var p1 = pts1[i];
  3780. var p2 = pts2[pts1.length - i - 1];
  3781. if (p1.compareTo(p2) !== 0) { return false }
  3782. }
  3783. return true
  3784. };
  3785. CoordinateArrays.envelope = function envelope (coordinates) {
  3786. var env = new Envelope();
  3787. for (var i = 0; i < coordinates.length; i++) {
  3788. env.expandToInclude(coordinates[i]);
  3789. }
  3790. return env
  3791. };
  3792. CoordinateArrays.toCoordinateArray = function toCoordinateArray (coordList) {
  3793. return coordList.toArray(CoordinateArrays.coordArrayType)
  3794. };
  3795. CoordinateArrays.atLeastNCoordinatesOrNothing = function atLeastNCoordinatesOrNothing (n, c) {
  3796. return c.length >= n ? c : []
  3797. };
  3798. CoordinateArrays.indexOf = function indexOf (coordinate, coordinates) {
  3799. for (var i = 0; i < coordinates.length; i++) {
  3800. if (coordinate.equals(coordinates[i])) {
  3801. return i
  3802. }
  3803. }
  3804. return -1
  3805. };
  3806. CoordinateArrays.increasingDirection = function increasingDirection (pts) {
  3807. for (var i = 0; i < Math.trunc(pts.length / 2); i++) {
  3808. var j = pts.length - 1 - i;
  3809. var comp = pts[i].compareTo(pts[j]);
  3810. if (comp !== 0) { return comp }
  3811. }
  3812. return 1
  3813. };
  3814. CoordinateArrays.compare = function compare (pts1, pts2) {
  3815. var i = 0;
  3816. while (i < pts1.length && i < pts2.length) {
  3817. var compare = pts1[i].compareTo(pts2[i]);
  3818. if (compare !== 0) { return compare }
  3819. i++;
  3820. }
  3821. if (i < pts2.length) { return -1 }
  3822. if (i < pts1.length) { return 1 }
  3823. return 0
  3824. };
  3825. CoordinateArrays.minCoordinate = function minCoordinate (coordinates) {
  3826. var minCoord = null;
  3827. for (var i = 0; i < coordinates.length; i++) {
  3828. if (minCoord === null || minCoord.compareTo(coordinates[i]) > 0) {
  3829. minCoord = coordinates[i];
  3830. }
  3831. }
  3832. return minCoord
  3833. };
  3834. CoordinateArrays.extract = function extract (pts, start, end) {
  3835. start = MathUtil.clamp(start, 0, pts.length);
  3836. end = MathUtil.clamp(end, -1, pts.length);
  3837. var npts = end - start + 1;
  3838. if (end < 0) { npts = 0; }
  3839. if (start >= pts.length) { npts = 0; }
  3840. if (end < start) { npts = 0; }
  3841. var extractPts = new Array(npts).fill(null);
  3842. if (npts === 0) { return extractPts }
  3843. var iPts = 0;
  3844. for (var i = start; i <= end; i++) {
  3845. extractPts[iPts++] = pts[i];
  3846. }
  3847. return extractPts
  3848. };
  3849. Object.defineProperties( CoordinateArrays, staticAccessors$13 );
  3850. var ForwardComparator = function ForwardComparator () {};
  3851. ForwardComparator.prototype.compare = function compare (o1, o2) {
  3852. var pts1 = o1;
  3853. var pts2 = o2;
  3854. return CoordinateArrays.compare(pts1, pts2)
  3855. };
  3856. ForwardComparator.prototype.interfaces_ = function interfaces_ () {
  3857. return [Comparator]
  3858. };
  3859. ForwardComparator.prototype.getClass = function getClass () {
  3860. return ForwardComparator
  3861. };
  3862. var BidirectionalComparator = function BidirectionalComparator () {};
  3863. BidirectionalComparator.prototype.compare = function compare (o1, o2) {
  3864. var pts1 = o1;
  3865. var pts2 = o2;
  3866. if (pts1.length < pts2.length) { return -1 }
  3867. if (pts1.length > pts2.length) { return 1 }
  3868. if (pts1.length === 0) { return 0 }
  3869. var forwardComp = CoordinateArrays.compare(pts1, pts2);
  3870. var isEqualRev = CoordinateArrays.isEqualReversed(pts1, pts2);
  3871. if (isEqualRev) { return 0 }
  3872. return forwardComp
  3873. };
  3874. BidirectionalComparator.prototype.OLDcompare = function OLDcompare (o1, o2) {
  3875. var pts1 = o1;
  3876. var pts2 = o2;
  3877. if (pts1.length < pts2.length) { return -1 }
  3878. if (pts1.length > pts2.length) { return 1 }
  3879. if (pts1.length === 0) { return 0 }
  3880. var dir1 = CoordinateArrays.increasingDirection(pts1);
  3881. var dir2 = CoordinateArrays.increasingDirection(pts2);
  3882. var i1 = dir1 > 0 ? 0 : pts1.length - 1;
  3883. var i2 = dir2 > 0 ? 0 : pts1.length - 1;
  3884. for (var i = 0; i < pts1.length; i++) {
  3885. var comparePt = pts1[i1].compareTo(pts2[i2]);
  3886. if (comparePt !== 0) { return comparePt }
  3887. i1 += dir1;
  3888. i2 += dir2;
  3889. }
  3890. return 0
  3891. };
  3892. BidirectionalComparator.prototype.interfaces_ = function interfaces_ () {
  3893. return [Comparator]
  3894. };
  3895. BidirectionalComparator.prototype.getClass = function getClass () {
  3896. return BidirectionalComparator
  3897. };
  3898. /**
  3899. * @see http://download.oracle.com/javase/6/docs/api/java/util/Map.html
  3900. *
  3901. * @constructor
  3902. * @private
  3903. */
  3904. var Map$1 = function Map () {};
  3905. Map$1.prototype.get = function get () {};
  3906. /**
  3907. * Associates the specified value with the specified key in this map (optional
  3908. * operation).
  3909. * @param {Object} key
  3910. * @param {Object} value
  3911. * @return {Object}
  3912. */
  3913. Map$1.prototype.put = function put () {};
  3914. /**
  3915. * Returns the number of key-value mappings in this map.
  3916. * @return {number}
  3917. */
  3918. Map$1.prototype.size = function size () {};
  3919. /**
  3920. * Returns a Collection view of the values contained in this map.
  3921. * @return {javascript.util.Collection}
  3922. */
  3923. Map$1.prototype.values = function values () {};
  3924. /**
  3925. * Returns a {@link Set} view of the mappings contained in this map.
  3926. * The set is backed by the map, so changes to the map are
  3927. * reflected in the set, and vice-versa.If the map is modified
  3928. * while an iteration over the set is in progress (except through
  3929. * the iterator's own <tt>remove</tt> operation, or through the
  3930. * <tt>setValue</tt> operation on a map entry returned by the
  3931. * iterator) the results of the iteration are undefined.The set
  3932. * supports element removal, which removes the corresponding
  3933. * mapping from the map, via the <tt>Iterator.remove</tt>,
  3934. * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
  3935. * <tt>clear</tt> operations.It does not support the
  3936. * <tt>add</tt> or <tt>addAll</tt> operations.
  3937. *
  3938. * @return {Set} a set view of the mappings contained in this map
  3939. */
  3940. Map$1.prototype.entrySet = function entrySet () {};
  3941. /**
  3942. * @see http://download.oracle.com/javase/6/docs/api/java/util/SortedMap.html
  3943. *
  3944. * @extends {Map}
  3945. * @constructor
  3946. * @private
  3947. */
  3948. var SortedMap = (function (Map) {
  3949. function SortedMap () {
  3950. Map.apply(this, arguments);
  3951. }if ( Map ) SortedMap.__proto__ = Map;
  3952. SortedMap.prototype = Object.create( Map && Map.prototype );
  3953. SortedMap.prototype.constructor = SortedMap;
  3954. return SortedMap;
  3955. }(Map$1));
  3956. /**
  3957. * @param {string=} message Optional message
  3958. * @extends {Error}
  3959. * @constructor
  3960. * @private
  3961. */
  3962. function OperationNotSupported (message) {
  3963. this.message = message || '';
  3964. }
  3965. OperationNotSupported.prototype = new Error();
  3966. /**
  3967. * @type {string}
  3968. */
  3969. OperationNotSupported.prototype.name = 'OperationNotSupported';
  3970. /**
  3971. * @see http://download.oracle.com/javase/6/docs/api/java/util/Set.html
  3972. *
  3973. * @extends {Collection}
  3974. * @constructor
  3975. * @private
  3976. */
  3977. function Set() {}
  3978. Set.prototype = new Collection();
  3979. /**
  3980. * Returns true if this set contains the specified element. More formally,
  3981. * returns true if and only if this set contains an element e such that (o==null ?
  3982. * e==null : o.equals(e)).
  3983. * @param {Object} e
  3984. * @return {boolean}
  3985. */
  3986. Set.prototype.contains = function() {};
  3987. /**
  3988. * @see http://docs.oracle.com/javase/6/docs/api/java/util/HashSet.html
  3989. *
  3990. * @extends {javascript.util.Set}
  3991. * @constructor
  3992. * @private
  3993. */
  3994. var HashSet = (function (Set$$1) {
  3995. function HashSet () {
  3996. Set$$1.call(this);
  3997. this.array_ = [];
  3998. if (arguments[0] instanceof Collection) {
  3999. this.addAll(arguments[0]);
  4000. }
  4001. }
  4002. if ( Set$$1 ) HashSet.__proto__ = Set$$1;
  4003. HashSet.prototype = Object.create( Set$$1 && Set$$1.prototype );
  4004. HashSet.prototype.constructor = HashSet;
  4005. /**
  4006. * @override
  4007. */
  4008. HashSet.prototype.contains = function contains (o) {
  4009. var this$1 = this;
  4010. for (var i = 0, len = this.array_.length; i < len; i++) {
  4011. var e = this$1.array_[i];
  4012. if (e === o) {
  4013. return true
  4014. }
  4015. }
  4016. return false
  4017. };
  4018. /**
  4019. * @override
  4020. */
  4021. HashSet.prototype.add = function add (o) {
  4022. if (this.contains(o)) {
  4023. return false
  4024. }
  4025. this.array_.push(o);
  4026. return true
  4027. };
  4028. /**
  4029. * @override
  4030. */
  4031. HashSet.prototype.addAll = function addAll (c) {
  4032. var this$1 = this;
  4033. for (var i = c.iterator(); i.hasNext();) {
  4034. this$1.add(i.next());
  4035. }
  4036. return true
  4037. };
  4038. /**
  4039. * @override
  4040. */
  4041. HashSet.prototype.remove = function remove (o) {
  4042. // throw new javascript.util.OperationNotSupported()
  4043. throw new Error()
  4044. };
  4045. /**
  4046. * @override
  4047. */
  4048. HashSet.prototype.size = function size () {
  4049. return this.array_.length
  4050. };
  4051. /**
  4052. * @override
  4053. */
  4054. HashSet.prototype.isEmpty = function isEmpty () {
  4055. return this.array_.length === 0
  4056. };
  4057. /**
  4058. * @override
  4059. */
  4060. HashSet.prototype.toArray = function toArray () {
  4061. var this$1 = this;
  4062. var array = [];
  4063. for (var i = 0, len = this.array_.length; i < len; i++) {
  4064. array.push(this$1.array_[i]);
  4065. }
  4066. return array
  4067. };
  4068. /**
  4069. * @override
  4070. */
  4071. HashSet.prototype.iterator = function iterator () {
  4072. return new Iterator_$1(this)
  4073. };
  4074. return HashSet;
  4075. }(Set));
  4076. /**
  4077. * @extends {Iterator}
  4078. * @param {HashSet} hashSet
  4079. * @constructor
  4080. * @private
  4081. */
  4082. var Iterator_$1 = (function (Iterator$$1) {
  4083. function Iterator_ (hashSet) {
  4084. Iterator$$1.call(this);
  4085. /**
  4086. * @type {HashSet}
  4087. * @private
  4088. */
  4089. this.hashSet_ = hashSet;
  4090. /**
  4091. * @type {number}
  4092. * @private
  4093. */
  4094. this.position_ = 0;
  4095. }
  4096. if ( Iterator$$1 ) Iterator_.__proto__ = Iterator$$1;
  4097. Iterator_.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
  4098. Iterator_.prototype.constructor = Iterator_;
  4099. /**
  4100. * @override
  4101. */
  4102. Iterator_.prototype.next = function next () {
  4103. if (this.position_ === this.hashSet_.size()) {
  4104. throw new NoSuchElementException()
  4105. }
  4106. return this.hashSet_.array_[this.position_++]
  4107. };
  4108. /**
  4109. * @override
  4110. */
  4111. Iterator_.prototype.hasNext = function hasNext () {
  4112. if (this.position_ < this.hashSet_.size()) {
  4113. return true
  4114. } else {
  4115. return false
  4116. }
  4117. };
  4118. /**
  4119. * @override
  4120. */
  4121. Iterator_.prototype.remove = function remove () {
  4122. throw new OperationNotSupported()
  4123. };
  4124. return Iterator_;
  4125. }(Iterator));
  4126. var BLACK = 0;
  4127. var RED = 1;
  4128. function colorOf (p) { return (p === null ? BLACK : p.color) }
  4129. function parentOf (p) { return (p === null ? null : p.parent) }
  4130. function setColor (p, c) { if (p !== null) { p.color = c; } }
  4131. function leftOf (p) { return (p === null ? null : p.left) }
  4132. function rightOf (p) { return (p === null ? null : p.right) }
  4133. /**
  4134. * @see http://download.oracle.com/javase/6/docs/api/java/util/TreeMap.html
  4135. *
  4136. * @extends {SortedMap}
  4137. * @constructor
  4138. * @private
  4139. */
  4140. function TreeMap () {
  4141. /**
  4142. * @type {Object}
  4143. * @private
  4144. */
  4145. this.root_ = null;
  4146. /**
  4147. * @type {number}
  4148. * @private
  4149. */
  4150. this.size_ = 0;
  4151. }
  4152. TreeMap.prototype = new SortedMap();
  4153. /**
  4154. * @override
  4155. */
  4156. TreeMap.prototype.get = function (key) {
  4157. var p = this.root_;
  4158. while (p !== null) {
  4159. var cmp = key['compareTo'](p.key);
  4160. if (cmp < 0) { p = p.left; }
  4161. else if (cmp > 0) { p = p.right; }
  4162. else { return p.value }
  4163. }
  4164. return null
  4165. };
  4166. /**
  4167. * @override
  4168. */
  4169. TreeMap.prototype.put = function (key, value) {
  4170. if (this.root_ === null) {
  4171. this.root_ = {
  4172. key: key,
  4173. value: value,
  4174. left: null,
  4175. right: null,
  4176. parent: null,
  4177. color: BLACK,
  4178. getValue: function getValue () { return this.value },
  4179. getKey: function getKey () { return this.key }
  4180. };
  4181. this.size_ = 1;
  4182. return null
  4183. }
  4184. var t = this.root_;
  4185. var parent;
  4186. var cmp;
  4187. do {
  4188. parent = t;
  4189. cmp = key['compareTo'](t.key);
  4190. if (cmp < 0) {
  4191. t = t.left;
  4192. } else if (cmp > 0) {
  4193. t = t.right;
  4194. } else {
  4195. var oldValue = t.value;
  4196. t.value = value;
  4197. return oldValue
  4198. }
  4199. } while (t !== null)
  4200. var e = {
  4201. key: key,
  4202. left: null,
  4203. right: null,
  4204. value: value,
  4205. parent: parent,
  4206. color: BLACK,
  4207. getValue: function getValue () { return this.value },
  4208. getKey: function getKey () { return this.key }
  4209. };
  4210. if (cmp < 0) {
  4211. parent.left = e;
  4212. } else {
  4213. parent.right = e;
  4214. }
  4215. this.fixAfterInsertion(e);
  4216. this.size_++;
  4217. return null
  4218. };
  4219. /**
  4220. * @param {Object} x
  4221. */
  4222. TreeMap.prototype.fixAfterInsertion = function (x) {
  4223. var this$1 = this;
  4224. x.color = RED;
  4225. while (x != null && x !== this.root_ && x.parent.color === RED) {
  4226. if (parentOf(x) === leftOf(parentOf(parentOf(x)))) {
  4227. var y = rightOf(parentOf(parentOf(x)));
  4228. if (colorOf(y) === RED) {
  4229. setColor(parentOf(x), BLACK);
  4230. setColor(y, BLACK);
  4231. setColor(parentOf(parentOf(x)), RED);
  4232. x = parentOf(parentOf(x));
  4233. } else {
  4234. if (x === rightOf(parentOf(x))) {
  4235. x = parentOf(x);
  4236. this$1.rotateLeft(x);
  4237. }
  4238. setColor(parentOf(x), BLACK);
  4239. setColor(parentOf(parentOf(x)), RED);
  4240. this$1.rotateRight(parentOf(parentOf(x)));
  4241. }
  4242. } else {
  4243. var y$1 = leftOf(parentOf(parentOf(x)));
  4244. if (colorOf(y$1) === RED) {
  4245. setColor(parentOf(x), BLACK);
  4246. setColor(y$1, BLACK);
  4247. setColor(parentOf(parentOf(x)), RED);
  4248. x = parentOf(parentOf(x));
  4249. } else {
  4250. if (x === leftOf(parentOf(x))) {
  4251. x = parentOf(x);
  4252. this$1.rotateRight(x);
  4253. }
  4254. setColor(parentOf(x), BLACK);
  4255. setColor(parentOf(parentOf(x)), RED);
  4256. this$1.rotateLeft(parentOf(parentOf(x)));
  4257. }
  4258. }
  4259. }
  4260. this.root_.color = BLACK;
  4261. };
  4262. /**
  4263. * @override
  4264. */
  4265. TreeMap.prototype.values = function () {
  4266. var arrayList = new ArrayList();
  4267. var p = this.getFirstEntry();
  4268. if (p !== null) {
  4269. arrayList.add(p.value);
  4270. while ((p = TreeMap.successor(p)) !== null) {
  4271. arrayList.add(p.value);
  4272. }
  4273. }
  4274. return arrayList
  4275. };
  4276. /**
  4277. * @override
  4278. */
  4279. TreeMap.prototype.entrySet = function () {
  4280. var hashSet = new HashSet();
  4281. var p = this.getFirstEntry();
  4282. if (p !== null) {
  4283. hashSet.add(p);
  4284. while ((p = TreeMap.successor(p)) !== null) {
  4285. hashSet.add(p);
  4286. }
  4287. }
  4288. return hashSet
  4289. };
  4290. /**
  4291. * @param {Object} p
  4292. */
  4293. TreeMap.prototype.rotateLeft = function (p) {
  4294. if (p != null) {
  4295. var r = p.right;
  4296. p.right = r.left;
  4297. if (r.left != null) { r.left.parent = p; }
  4298. r.parent = p.parent;
  4299. if (p.parent === null) { this.root_ = r; } else if (p.parent.left === p) { p.parent.left = r; } else { p.parent.right = r; }
  4300. r.left = p;
  4301. p.parent = r;
  4302. }
  4303. };
  4304. /**
  4305. * @param {Object} p
  4306. */
  4307. TreeMap.prototype.rotateRight = function (p) {
  4308. if (p != null) {
  4309. var l = p.left;
  4310. p.left = l.right;
  4311. if (l.right != null) { l.right.parent = p; }
  4312. l.parent = p.parent;
  4313. if (p.parent === null) { this.root_ = l; } else if (p.parent.right === p) { p.parent.right = l; } else { p.parent.left = l; }
  4314. l.right = p;
  4315. p.parent = l;
  4316. }
  4317. };
  4318. /**
  4319. * @return {Object}
  4320. */
  4321. TreeMap.prototype.getFirstEntry = function () {
  4322. var p = this.root_;
  4323. if (p != null) {
  4324. while (p.left != null) {
  4325. p = p.left;
  4326. }
  4327. }
  4328. return p
  4329. };
  4330. /**
  4331. * @param {Object} t
  4332. * @return {Object}
  4333. * @private
  4334. */
  4335. TreeMap.successor = function (t) {
  4336. if (t === null) { return null } else if (t.right !== null) {
  4337. var p = t.right;
  4338. while (p.left !== null) {
  4339. p = p.left;
  4340. }
  4341. return p
  4342. } else {
  4343. var p$1 = t.parent;
  4344. var ch = t;
  4345. while (p$1 !== null && ch === p$1.right) {
  4346. ch = p$1;
  4347. p$1 = p$1.parent;
  4348. }
  4349. return p$1
  4350. }
  4351. };
  4352. /**
  4353. * @override
  4354. */
  4355. TreeMap.prototype.size = function () {
  4356. return this.size_
  4357. };
  4358. var Lineal = function Lineal () {};
  4359. Lineal.prototype.interfaces_ = function interfaces_ () {
  4360. return []
  4361. };
  4362. Lineal.prototype.getClass = function getClass () {
  4363. return Lineal
  4364. };
  4365. /**
  4366. * @see http://download.oracle.com/javase/6/docs/api/java/util/SortedSet.html
  4367. *
  4368. * @extends {Set}
  4369. * @constructor
  4370. * @private
  4371. */
  4372. function SortedSet () {}
  4373. SortedSet.prototype = new Set();
  4374. // import Iterator from './Iterator'
  4375. /**
  4376. * @see http://download.oracle.com/javase/6/docs/api/java/util/TreeSet.html
  4377. *
  4378. * @extends {SortedSet}
  4379. * @constructor
  4380. * @private
  4381. */
  4382. function TreeSet () {
  4383. /**
  4384. * @type {Array}
  4385. * @private
  4386. */
  4387. this.array_ = [];
  4388. if (arguments[0] instanceof Collection) {
  4389. this.addAll(arguments[0]);
  4390. }
  4391. }
  4392. TreeSet.prototype = new SortedSet();
  4393. /**
  4394. * @override
  4395. */
  4396. TreeSet.prototype.contains = function (o) {
  4397. var this$1 = this;
  4398. for (var i = 0, len = this.array_.length; i < len; i++) {
  4399. var e = this$1.array_[i];
  4400. if (e['compareTo'](o) === 0) {
  4401. return true
  4402. }
  4403. }
  4404. return false
  4405. };
  4406. /**
  4407. * @override
  4408. */
  4409. TreeSet.prototype.add = function (o) {
  4410. var this$1 = this;
  4411. if (this.contains(o)) {
  4412. return false
  4413. }
  4414. for (var i = 0, len = this.array_.length; i < len; i++) {
  4415. var e = this$1.array_[i];
  4416. if (e['compareTo'](o) === 1) {
  4417. this$1.array_.splice(i, 0, o);
  4418. return true
  4419. }
  4420. }
  4421. this.array_.push(o);
  4422. return true
  4423. };
  4424. /**
  4425. * @override
  4426. */
  4427. TreeSet.prototype.addAll = function (c) {
  4428. var this$1 = this;
  4429. for (var i = c.iterator(); i.hasNext();) {
  4430. this$1.add(i.next());
  4431. }
  4432. return true
  4433. };
  4434. /**
  4435. * @override
  4436. */
  4437. TreeSet.prototype.remove = function (e) {
  4438. throw new OperationNotSupported()
  4439. };
  4440. /**
  4441. * @override
  4442. */
  4443. TreeSet.prototype.size = function () {
  4444. return this.array_.length
  4445. };
  4446. /**
  4447. * @override
  4448. */
  4449. TreeSet.prototype.isEmpty = function () {
  4450. return this.array_.length === 0
  4451. };
  4452. /**
  4453. * @override
  4454. */
  4455. TreeSet.prototype.toArray = function () {
  4456. var this$1 = this;
  4457. var array = [];
  4458. for (var i = 0, len = this.array_.length; i < len; i++) {
  4459. array.push(this$1.array_[i]);
  4460. }
  4461. return array
  4462. };
  4463. /**
  4464. * @override
  4465. */
  4466. TreeSet.prototype.iterator = function () {
  4467. return new Iterator_$2(this)
  4468. };
  4469. /**
  4470. * @extends {javascript.util.Iterator}
  4471. * @param {javascript.util.TreeSet} treeSet
  4472. * @constructor
  4473. * @private
  4474. */
  4475. var Iterator_$2 = function (treeSet) {
  4476. /**
  4477. * @type {javascript.util.TreeSet}
  4478. * @private
  4479. */
  4480. this.treeSet_ = treeSet;
  4481. /**
  4482. * @type {number}
  4483. * @private
  4484. */
  4485. this.position_ = 0;
  4486. };
  4487. /**
  4488. * @override
  4489. */
  4490. Iterator_$2.prototype.next = function () {
  4491. if (this.position_ === this.treeSet_.size()) {
  4492. throw new NoSuchElementException()
  4493. }
  4494. return this.treeSet_.array_[this.position_++]
  4495. };
  4496. /**
  4497. * @override
  4498. */
  4499. Iterator_$2.prototype.hasNext = function () {
  4500. if (this.position_ < this.treeSet_.size()) {
  4501. return true
  4502. } else {
  4503. return false
  4504. }
  4505. };
  4506. /**
  4507. * @override
  4508. */
  4509. Iterator_$2.prototype.remove = function () {
  4510. throw new OperationNotSupported()
  4511. };
  4512. /**
  4513. * @see http://download.oracle.com/javase/6/docs/api/java/util/Arrays.html
  4514. *
  4515. * @constructor
  4516. * @private
  4517. */
  4518. var Arrays = function Arrays () {};
  4519. Arrays.sort = function sort () {
  4520. var a = arguments[0];
  4521. var i;
  4522. var t;
  4523. var comparator;
  4524. var compare;
  4525. if (arguments.length === 1) {
  4526. compare = function (a, b) {
  4527. return a.compareTo(b)
  4528. };
  4529. a.sort(compare);
  4530. } else if (arguments.length === 2) {
  4531. comparator = arguments[1];
  4532. compare = function (a, b) {
  4533. return comparator['compare'](a, b)
  4534. };
  4535. a.sort(compare);
  4536. } else if (arguments.length === 3) {
  4537. t = a.slice(arguments[1], arguments[2]);
  4538. t.sort();
  4539. var r = a.slice(0, arguments[1]).concat(t, a.slice(arguments[2], a.length));
  4540. a.splice(0, a.length);
  4541. for (i = 0; i < r.length; i++) {
  4542. a.push(r[i]);
  4543. }
  4544. } else if (arguments.length === 4) {
  4545. t = a.slice(arguments[1], arguments[2]);
  4546. comparator = arguments[3];
  4547. compare = function (a, b) {
  4548. return comparator['compare'](a, b)
  4549. };
  4550. t.sort(compare);
  4551. r = a.slice(0, arguments[1]).concat(t, a.slice(arguments[2], a.length));
  4552. a.splice(0, a.length);
  4553. for (i = 0; i < r.length; i++) {
  4554. a.push(r[i]);
  4555. }
  4556. }
  4557. };
  4558. /**
  4559. * @param {Array} array
  4560. * @return {ArrayList}
  4561. */
  4562. Arrays.asList = function asList (array) {
  4563. var arrayList = new ArrayList();
  4564. for (var i = 0, len = array.length; i < len; i++) {
  4565. arrayList.add(array[i]);
  4566. }
  4567. return arrayList
  4568. };
  4569. var Dimension = function Dimension () {};
  4570. var staticAccessors$14 = { P: { configurable: true },L: { configurable: true },A: { configurable: true },FALSE: { configurable: true },TRUE: { configurable: true },DONTCARE: { configurable: true },SYM_FALSE: { configurable: true },SYM_TRUE: { configurable: true },SYM_DONTCARE: { configurable: true },SYM_P: { configurable: true },SYM_L: { configurable: true },SYM_A: { configurable: true } };
  4571. staticAccessors$14.P.get = function () { return 0 };
  4572. staticAccessors$14.L.get = function () { return 1 };
  4573. staticAccessors$14.A.get = function () { return 2 };
  4574. staticAccessors$14.FALSE.get = function () { return -1 };
  4575. staticAccessors$14.TRUE.get = function () { return -2 };
  4576. staticAccessors$14.DONTCARE.get = function () { return -3 };
  4577. staticAccessors$14.SYM_FALSE.get = function () { return 'F' };
  4578. staticAccessors$14.SYM_TRUE.get = function () { return 'T' };
  4579. staticAccessors$14.SYM_DONTCARE.get = function () { return '*' };
  4580. staticAccessors$14.SYM_P.get = function () { return '0' };
  4581. staticAccessors$14.SYM_L.get = function () { return '1' };
  4582. staticAccessors$14.SYM_A.get = function () { return '2' };
  4583. Dimension.prototype.interfaces_ = function interfaces_ () {
  4584. return []
  4585. };
  4586. Dimension.prototype.getClass = function getClass () {
  4587. return Dimension
  4588. };
  4589. Dimension.toDimensionSymbol = function toDimensionSymbol (dimensionValue) {
  4590. switch (dimensionValue) {
  4591. case Dimension.FALSE:
  4592. return Dimension.SYM_FALSE
  4593. case Dimension.TRUE:
  4594. return Dimension.SYM_TRUE
  4595. case Dimension.DONTCARE:
  4596. return Dimension.SYM_DONTCARE
  4597. case Dimension.P:
  4598. return Dimension.SYM_P
  4599. case Dimension.L:
  4600. return Dimension.SYM_L
  4601. case Dimension.A:
  4602. return Dimension.SYM_A
  4603. default:
  4604. }
  4605. throw new IllegalArgumentException('Unknown dimension value: ' + dimensionValue)
  4606. };
  4607. Dimension.toDimensionValue = function toDimensionValue (dimensionSymbol) {
  4608. switch (Character.toUpperCase(dimensionSymbol)) {
  4609. case Dimension.SYM_FALSE:
  4610. return Dimension.FALSE
  4611. case Dimension.SYM_TRUE:
  4612. return Dimension.TRUE
  4613. case Dimension.SYM_DONTCARE:
  4614. return Dimension.DONTCARE
  4615. case Dimension.SYM_P:
  4616. return Dimension.P
  4617. case Dimension.SYM_L:
  4618. return Dimension.L
  4619. case Dimension.SYM_A:
  4620. return Dimension.A
  4621. default:
  4622. }
  4623. throw new IllegalArgumentException('Unknown dimension symbol: ' + dimensionSymbol)
  4624. };
  4625. Object.defineProperties( Dimension, staticAccessors$14 );
  4626. var GeometryFilter = function GeometryFilter () {};
  4627. GeometryFilter.prototype.filter = function filter (geom) {};
  4628. GeometryFilter.prototype.interfaces_ = function interfaces_ () {
  4629. return []
  4630. };
  4631. GeometryFilter.prototype.getClass = function getClass () {
  4632. return GeometryFilter
  4633. };
  4634. var CoordinateSequenceFilter = function CoordinateSequenceFilter () {};
  4635. CoordinateSequenceFilter.prototype.filter = function filter (seq, i) {};
  4636. CoordinateSequenceFilter.prototype.isDone = function isDone () {};
  4637. CoordinateSequenceFilter.prototype.isGeometryChanged = function isGeometryChanged () {};
  4638. CoordinateSequenceFilter.prototype.interfaces_ = function interfaces_ () {
  4639. return []
  4640. };
  4641. CoordinateSequenceFilter.prototype.getClass = function getClass () {
  4642. return CoordinateSequenceFilter
  4643. };
  4644. var GeometryCollection = (function (Geometry$$1) {
  4645. function GeometryCollection (geometries, factory) {
  4646. Geometry$$1.call(this, factory);
  4647. this._geometries = geometries || [];
  4648. if (Geometry$$1.hasNullElements(this._geometries)) {
  4649. throw new IllegalArgumentException('geometries must not contain null elements')
  4650. }
  4651. }
  4652. if ( Geometry$$1 ) GeometryCollection.__proto__ = Geometry$$1;
  4653. GeometryCollection.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
  4654. GeometryCollection.prototype.constructor = GeometryCollection;
  4655. var staticAccessors = { serialVersionUID: { configurable: true } };
  4656. GeometryCollection.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
  4657. var this$1 = this;
  4658. var envelope = new Envelope();
  4659. for (var i = 0; i < this._geometries.length; i++) {
  4660. envelope.expandToInclude(this$1._geometries[i].getEnvelopeInternal());
  4661. }
  4662. return envelope
  4663. };
  4664. GeometryCollection.prototype.getGeometryN = function getGeometryN (n) {
  4665. return this._geometries[n]
  4666. };
  4667. GeometryCollection.prototype.getSortIndex = function getSortIndex () {
  4668. return Geometry$$1.SORTINDEX_GEOMETRYCOLLECTION
  4669. };
  4670. GeometryCollection.prototype.getCoordinates = function getCoordinates () {
  4671. var this$1 = this;
  4672. var coordinates = new Array(this.getNumPoints()).fill(null);
  4673. var k = -1;
  4674. for (var i = 0; i < this._geometries.length; i++) {
  4675. var childCoordinates = this$1._geometries[i].getCoordinates();
  4676. for (var j = 0; j < childCoordinates.length; j++) {
  4677. k++;
  4678. coordinates[k] = childCoordinates[j];
  4679. }
  4680. }
  4681. return coordinates
  4682. };
  4683. GeometryCollection.prototype.getArea = function getArea () {
  4684. var this$1 = this;
  4685. var area = 0.0;
  4686. for (var i = 0; i < this._geometries.length; i++) {
  4687. area += this$1._geometries[i].getArea();
  4688. }
  4689. return area
  4690. };
  4691. GeometryCollection.prototype.equalsExact = function equalsExact () {
  4692. var this$1 = this;
  4693. if (arguments.length === 2) {
  4694. var other = arguments[0];
  4695. var tolerance = arguments[1];
  4696. if (!this.isEquivalentClass(other)) {
  4697. return false
  4698. }
  4699. var otherCollection = other;
  4700. if (this._geometries.length !== otherCollection._geometries.length) {
  4701. return false
  4702. }
  4703. for (var i = 0; i < this._geometries.length; i++) {
  4704. if (!this$1._geometries[i].equalsExact(otherCollection._geometries[i], tolerance)) {
  4705. return false
  4706. }
  4707. }
  4708. return true
  4709. } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
  4710. };
  4711. GeometryCollection.prototype.normalize = function normalize () {
  4712. var this$1 = this;
  4713. for (var i = 0; i < this._geometries.length; i++) {
  4714. this$1._geometries[i].normalize();
  4715. }
  4716. Arrays.sort(this._geometries);
  4717. };
  4718. GeometryCollection.prototype.getCoordinate = function getCoordinate () {
  4719. if (this.isEmpty()) { return null }
  4720. return this._geometries[0].getCoordinate()
  4721. };
  4722. GeometryCollection.prototype.getBoundaryDimension = function getBoundaryDimension () {
  4723. var this$1 = this;
  4724. var dimension = Dimension.FALSE;
  4725. for (var i = 0; i < this._geometries.length; i++) {
  4726. dimension = Math.max(dimension, this$1._geometries[i].getBoundaryDimension());
  4727. }
  4728. return dimension
  4729. };
  4730. GeometryCollection.prototype.getDimension = function getDimension () {
  4731. var this$1 = this;
  4732. var dimension = Dimension.FALSE;
  4733. for (var i = 0; i < this._geometries.length; i++) {
  4734. dimension = Math.max(dimension, this$1._geometries[i].getDimension());
  4735. }
  4736. return dimension
  4737. };
  4738. GeometryCollection.prototype.getLength = function getLength () {
  4739. var this$1 = this;
  4740. var sum = 0.0;
  4741. for (var i = 0; i < this._geometries.length; i++) {
  4742. sum += this$1._geometries[i].getLength();
  4743. }
  4744. return sum
  4745. };
  4746. GeometryCollection.prototype.getNumPoints = function getNumPoints () {
  4747. var this$1 = this;
  4748. var numPoints = 0;
  4749. for (var i = 0; i < this._geometries.length; i++) {
  4750. numPoints += this$1._geometries[i].getNumPoints();
  4751. }
  4752. return numPoints
  4753. };
  4754. GeometryCollection.prototype.getNumGeometries = function getNumGeometries () {
  4755. return this._geometries.length
  4756. };
  4757. GeometryCollection.prototype.reverse = function reverse () {
  4758. var this$1 = this;
  4759. var n = this._geometries.length;
  4760. var revGeoms = new Array(n).fill(null);
  4761. for (var i = 0; i < this._geometries.length; i++) {
  4762. revGeoms[i] = this$1._geometries[i].reverse();
  4763. }
  4764. return this.getFactory().createGeometryCollection(revGeoms)
  4765. };
  4766. GeometryCollection.prototype.compareToSameClass = function compareToSameClass () {
  4767. var this$1 = this;
  4768. if (arguments.length === 1) {
  4769. var o = arguments[0];
  4770. var theseElements = new TreeSet(Arrays.asList(this._geometries));
  4771. var otherElements = new TreeSet(Arrays.asList(o._geometries));
  4772. return this.compare(theseElements, otherElements)
  4773. } else if (arguments.length === 2) {
  4774. var o$1 = arguments[0];
  4775. var comp = arguments[1];
  4776. var gc = o$1;
  4777. var n1 = this.getNumGeometries();
  4778. var n2 = gc.getNumGeometries();
  4779. var i = 0;
  4780. while (i < n1 && i < n2) {
  4781. var thisGeom = this$1.getGeometryN(i);
  4782. var otherGeom = gc.getGeometryN(i);
  4783. var holeComp = thisGeom.compareToSameClass(otherGeom, comp);
  4784. if (holeComp !== 0) { return holeComp }
  4785. i++;
  4786. }
  4787. if (i < n1) { return 1 }
  4788. if (i < n2) { return -1 }
  4789. return 0
  4790. }
  4791. };
  4792. GeometryCollection.prototype.apply = function apply () {
  4793. var this$1 = this;
  4794. if (hasInterface(arguments[0], CoordinateFilter)) {
  4795. var filter = arguments[0];
  4796. for (var i = 0; i < this._geometries.length; i++) {
  4797. this$1._geometries[i].apply(filter);
  4798. }
  4799. } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {
  4800. var filter$1 = arguments[0];
  4801. if (this._geometries.length === 0) { return null }
  4802. for (var i$1 = 0; i$1 < this._geometries.length; i$1++) {
  4803. this$1._geometries[i$1].apply(filter$1);
  4804. if (filter$1.isDone()) {
  4805. break
  4806. }
  4807. }
  4808. if (filter$1.isGeometryChanged()) { this.geometryChanged(); }
  4809. } else if (hasInterface(arguments[0], GeometryFilter)) {
  4810. var filter$2 = arguments[0];
  4811. filter$2.filter(this);
  4812. for (var i$2 = 0; i$2 < this._geometries.length; i$2++) {
  4813. this$1._geometries[i$2].apply(filter$2);
  4814. }
  4815. } else if (hasInterface(arguments[0], GeometryComponentFilter)) {
  4816. var filter$3 = arguments[0];
  4817. filter$3.filter(this);
  4818. for (var i$3 = 0; i$3 < this._geometries.length; i$3++) {
  4819. this$1._geometries[i$3].apply(filter$3);
  4820. }
  4821. }
  4822. };
  4823. GeometryCollection.prototype.getBoundary = function getBoundary () {
  4824. this.checkNotGeometryCollection(this);
  4825. Assert.shouldNeverReachHere();
  4826. return null
  4827. };
  4828. GeometryCollection.prototype.clone = function clone () {
  4829. var this$1 = this;
  4830. var gc = Geometry$$1.prototype.clone.call(this);
  4831. gc._geometries = new Array(this._geometries.length).fill(null);
  4832. for (var i = 0; i < this._geometries.length; i++) {
  4833. gc._geometries[i] = this$1._geometries[i].clone();
  4834. }
  4835. return gc
  4836. };
  4837. GeometryCollection.prototype.getGeometryType = function getGeometryType () {
  4838. return 'GeometryCollection'
  4839. };
  4840. GeometryCollection.prototype.copy = function copy () {
  4841. var this$1 = this;
  4842. var geometries = new Array(this._geometries.length).fill(null);
  4843. for (var i = 0; i < geometries.length; i++) {
  4844. geometries[i] = this$1._geometries[i].copy();
  4845. }
  4846. return new GeometryCollection(geometries, this._factory)
  4847. };
  4848. GeometryCollection.prototype.isEmpty = function isEmpty () {
  4849. var this$1 = this;
  4850. for (var i = 0; i < this._geometries.length; i++) {
  4851. if (!this$1._geometries[i].isEmpty()) {
  4852. return false
  4853. }
  4854. }
  4855. return true
  4856. };
  4857. GeometryCollection.prototype.interfaces_ = function interfaces_ () {
  4858. return []
  4859. };
  4860. GeometryCollection.prototype.getClass = function getClass () {
  4861. return GeometryCollection
  4862. };
  4863. staticAccessors.serialVersionUID.get = function () { return -5694727726395021467 };
  4864. Object.defineProperties( GeometryCollection, staticAccessors );
  4865. return GeometryCollection;
  4866. }(Geometry));
  4867. var MultiLineString = (function (GeometryCollection$$1) {
  4868. function MultiLineString () {
  4869. GeometryCollection$$1.apply(this, arguments);
  4870. }
  4871. if ( GeometryCollection$$1 ) MultiLineString.__proto__ = GeometryCollection$$1;
  4872. MultiLineString.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );
  4873. MultiLineString.prototype.constructor = MultiLineString;
  4874. var staticAccessors = { serialVersionUID: { configurable: true } };
  4875. MultiLineString.prototype.getSortIndex = function getSortIndex () {
  4876. return Geometry.SORTINDEX_MULTILINESTRING
  4877. };
  4878. MultiLineString.prototype.equalsExact = function equalsExact () {
  4879. if (arguments.length === 2) {
  4880. var other = arguments[0];
  4881. var tolerance = arguments[1];
  4882. if (!this.isEquivalentClass(other)) {
  4883. return false
  4884. }
  4885. return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)
  4886. } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }
  4887. };
  4888. MultiLineString.prototype.getBoundaryDimension = function getBoundaryDimension () {
  4889. if (this.isClosed()) {
  4890. return Dimension.FALSE
  4891. }
  4892. return 0
  4893. };
  4894. MultiLineString.prototype.isClosed = function isClosed () {
  4895. var this$1 = this;
  4896. if (this.isEmpty()) {
  4897. return false
  4898. }
  4899. for (var i = 0; i < this._geometries.length; i++) {
  4900. if (!this$1._geometries[i].isClosed()) {
  4901. return false
  4902. }
  4903. }
  4904. return true
  4905. };
  4906. MultiLineString.prototype.getDimension = function getDimension () {
  4907. return 1
  4908. };
  4909. MultiLineString.prototype.reverse = function reverse () {
  4910. var this$1 = this;
  4911. var nLines = this._geometries.length;
  4912. var revLines = new Array(nLines).fill(null);
  4913. for (var i = 0; i < this._geometries.length; i++) {
  4914. revLines[nLines - 1 - i] = this$1._geometries[i].reverse();
  4915. }
  4916. return this.getFactory().createMultiLineString(revLines)
  4917. };
  4918. MultiLineString.prototype.getBoundary = function getBoundary () {
  4919. return new BoundaryOp(this).getBoundary()
  4920. };
  4921. MultiLineString.prototype.getGeometryType = function getGeometryType () {
  4922. return 'MultiLineString'
  4923. };
  4924. MultiLineString.prototype.copy = function copy () {
  4925. var this$1 = this;
  4926. var lineStrings = new Array(this._geometries.length).fill(null);
  4927. for (var i = 0; i < lineStrings.length; i++) {
  4928. lineStrings[i] = this$1._geometries[i].copy();
  4929. }
  4930. return new MultiLineString(lineStrings, this._factory)
  4931. };
  4932. MultiLineString.prototype.interfaces_ = function interfaces_ () {
  4933. return [Lineal]
  4934. };
  4935. MultiLineString.prototype.getClass = function getClass () {
  4936. return MultiLineString
  4937. };
  4938. staticAccessors.serialVersionUID.get = function () { return 8166665132445433741 };
  4939. Object.defineProperties( MultiLineString, staticAccessors );
  4940. return MultiLineString;
  4941. }(GeometryCollection));
  4942. var BoundaryOp = function BoundaryOp () {
  4943. this._geom = null;
  4944. this._geomFact = null;
  4945. this._bnRule = null;
  4946. this._endpointMap = null;
  4947. if (arguments.length === 1) {
  4948. var geom = arguments[0];
  4949. var bnRule = BoundaryNodeRule.MOD2_BOUNDARY_RULE;
  4950. this._geom = geom;
  4951. this._geomFact = geom.getFactory();
  4952. this._bnRule = bnRule;
  4953. } else if (arguments.length === 2) {
  4954. var geom$1 = arguments[0];
  4955. var bnRule$1 = arguments[1];
  4956. this._geom = geom$1;
  4957. this._geomFact = geom$1.getFactory();
  4958. this._bnRule = bnRule$1;
  4959. }
  4960. };
  4961. BoundaryOp.prototype.boundaryMultiLineString = function boundaryMultiLineString (mLine) {
  4962. if (this._geom.isEmpty()) {
  4963. return this.getEmptyMultiPoint()
  4964. }
  4965. var bdyPts = this.computeBoundaryCoordinates(mLine);
  4966. if (bdyPts.length === 1) {
  4967. return this._geomFact.createPoint(bdyPts[0])
  4968. }
  4969. return this._geomFact.createMultiPointFromCoords(bdyPts)
  4970. };
  4971. BoundaryOp.prototype.getBoundary = function getBoundary () {
  4972. if (this._geom instanceof LineString) { return this.boundaryLineString(this._geom) }
  4973. if (this._geom instanceof MultiLineString) { return this.boundaryMultiLineString(this._geom) }
  4974. return this._geom.getBoundary()
  4975. };
  4976. BoundaryOp.prototype.boundaryLineString = function boundaryLineString (line) {
  4977. if (this._geom.isEmpty()) {
  4978. return this.getEmptyMultiPoint()
  4979. }
  4980. if (line.isClosed()) {
  4981. var closedEndpointOnBoundary = this._bnRule.isInBoundary(2);
  4982. if (closedEndpointOnBoundary) {
  4983. return line.getStartPoint()
  4984. } else {
  4985. return this._geomFact.createMultiPoint()
  4986. }
  4987. }
  4988. return this._geomFact.createMultiPoint([line.getStartPoint(), line.getEndPoint()])
  4989. };
  4990. BoundaryOp.prototype.getEmptyMultiPoint = function getEmptyMultiPoint () {
  4991. return this._geomFact.createMultiPoint()
  4992. };
  4993. BoundaryOp.prototype.computeBoundaryCoordinates = function computeBoundaryCoordinates (mLine) {
  4994. var this$1 = this;
  4995. var bdyPts = new ArrayList();
  4996. this._endpointMap = new TreeMap();
  4997. for (var i = 0; i < mLine.getNumGeometries(); i++) {
  4998. var line = mLine.getGeometryN(i);
  4999. if (line.getNumPoints() === 0) { continue }
  5000. this$1.addEndpoint(line.getCoordinateN(0));
  5001. this$1.addEndpoint(line.getCoordinateN(line.getNumPoints() - 1));
  5002. }
  5003. for (var it = this._endpointMap.entrySet().iterator(); it.hasNext();) {
  5004. var entry = it.next();
  5005. var counter = entry.getValue();
  5006. var valence = counter.count;
  5007. if (this$1._bnRule.isInBoundary(valence)) {
  5008. bdyPts.add(entry.getKey());
  5009. }
  5010. }
  5011. return CoordinateArrays.toCoordinateArray(bdyPts)
  5012. };
  5013. BoundaryOp.prototype.addEndpoint = function addEndpoint (pt) {
  5014. var counter = this._endpointMap.get(pt);
  5015. if (counter === null) {
  5016. counter = new Counter();
  5017. this._endpointMap.put(pt, counter);
  5018. }
  5019. counter.count++;
  5020. };
  5021. BoundaryOp.prototype.interfaces_ = function interfaces_ () {
  5022. return []
  5023. };
  5024. BoundaryOp.prototype.getClass = function getClass () {
  5025. return BoundaryOp
  5026. };
  5027. BoundaryOp.getBoundary = function getBoundary () {
  5028. if (arguments.length === 1) {
  5029. var g = arguments[0];
  5030. var bop = new BoundaryOp(g);
  5031. return bop.getBoundary()
  5032. } else if (arguments.length === 2) {
  5033. var g$1 = arguments[0];
  5034. var bnRule = arguments[1];
  5035. var bop$1 = new BoundaryOp(g$1, bnRule);
  5036. return bop$1.getBoundary()
  5037. }
  5038. };
  5039. var Counter = function Counter () {
  5040. this.count = null;
  5041. };
  5042. Counter.prototype.interfaces_ = function interfaces_ () {
  5043. return []
  5044. };
  5045. Counter.prototype.getClass = function getClass () {
  5046. return Counter
  5047. };
  5048. // boundary
  5049. function PrintStream () {}
  5050. function StringReader () {}
  5051. var DecimalFormat = function DecimalFormat () {};
  5052. function ByteArrayOutputStream () {}
  5053. function IOException () {}
  5054. function LineNumberReader () {}
  5055. var StringUtil = function StringUtil () {};
  5056. var staticAccessors$15 = { NEWLINE: { configurable: true },SIMPLE_ORDINATE_FORMAT: { configurable: true } };
  5057. StringUtil.prototype.interfaces_ = function interfaces_ () {
  5058. return []
  5059. };
  5060. StringUtil.prototype.getClass = function getClass () {
  5061. return StringUtil
  5062. };
  5063. StringUtil.chars = function chars (c, n) {
  5064. var ch = new Array(n).fill(null);
  5065. for (var i = 0; i < n; i++) {
  5066. ch[i] = c;
  5067. }
  5068. return String(ch)
  5069. };
  5070. StringUtil.getStackTrace = function getStackTrace () {
  5071. if (arguments.length === 1) {
  5072. var t = arguments[0];
  5073. var os = new ByteArrayOutputStream();
  5074. var ps = new PrintStream(os);
  5075. t.printStackTrace(ps);
  5076. return os.toString()
  5077. } else if (arguments.length === 2) {
  5078. var t$1 = arguments[0];
  5079. var depth = arguments[1];
  5080. var stackTrace = '';
  5081. var stringReader = new StringReader(StringUtil.getStackTrace(t$1));
  5082. var lineNumberReader = new LineNumberReader(stringReader);
  5083. for (var i = 0; i < depth; i++) {
  5084. try {
  5085. stackTrace += lineNumberReader.readLine() + StringUtil.NEWLINE;
  5086. } catch (e) {
  5087. if (e instanceof IOException) {
  5088. Assert.shouldNeverReachHere();
  5089. } else { throw e }
  5090. } finally {}
  5091. }
  5092. return stackTrace
  5093. }
  5094. };
  5095. StringUtil.split = function split (s, separator) {
  5096. var separatorlen = separator.length;
  5097. var tokenList = new ArrayList();
  5098. var tmpString = '' + s;
  5099. var pos = tmpString.indexOf(separator);
  5100. while (pos >= 0) {
  5101. var token = tmpString.substring(0, pos);
  5102. tokenList.add(token);
  5103. tmpString = tmpString.substring(pos + separatorlen);
  5104. pos = tmpString.indexOf(separator);
  5105. }
  5106. if (tmpString.length > 0) { tokenList.add(tmpString); }
  5107. var res = new Array(tokenList.size()).fill(null);
  5108. for (var i = 0; i < res.length; i++) {
  5109. res[i] = tokenList.get(i);
  5110. }
  5111. return res
  5112. };
  5113. StringUtil.toString = function toString () {
  5114. if (arguments.length === 1) {
  5115. var d = arguments[0];
  5116. return StringUtil.SIMPLE_ORDINATE_FORMAT.format(d)
  5117. }
  5118. };
  5119. StringUtil.spaces = function spaces (n) {
  5120. return StringUtil.chars(' ', n)
  5121. };
  5122. staticAccessors$15.NEWLINE.get = function () { return System.getProperty('line.separator') };
  5123. staticAccessors$15.SIMPLE_ORDINATE_FORMAT.get = function () { return new DecimalFormat('0.#') };
  5124. Object.defineProperties( StringUtil, staticAccessors$15 );
  5125. var CoordinateSequences = function CoordinateSequences () {};
  5126. CoordinateSequences.prototype.interfaces_ = function interfaces_ () {
  5127. return []
  5128. };
  5129. CoordinateSequences.prototype.getClass = function getClass () {
  5130. return CoordinateSequences
  5131. };
  5132. CoordinateSequences.copyCoord = function copyCoord (src, srcPos, dest, destPos) {
  5133. var minDim = Math.min(src.getDimension(), dest.getDimension());
  5134. for (var dim = 0; dim < minDim; dim++) {
  5135. dest.setOrdinate(destPos, dim, src.getOrdinate(srcPos, dim));
  5136. }
  5137. };
  5138. CoordinateSequences.isRing = function isRing (seq) {
  5139. var n = seq.size();
  5140. if (n === 0) { return true }
  5141. if (n <= 3) { return false }
  5142. return seq.getOrdinate(0, CoordinateSequence.X) === seq.getOrdinate(n - 1, CoordinateSequence.X) && seq.getOrdinate(0, CoordinateSequence.Y) === seq.getOrdinate(n - 1, CoordinateSequence.Y)
  5143. };
  5144. CoordinateSequences.isEqual = function isEqual (cs1, cs2) {
  5145. var cs1Size = cs1.size();
  5146. var cs2Size = cs2.size();
  5147. if (cs1Size !== cs2Size) { return false }
  5148. var dim = Math.min(cs1.getDimension(), cs2.getDimension());
  5149. for (var i = 0; i < cs1Size; i++) {
  5150. for (var d = 0; d < dim; d++) {
  5151. var v1 = cs1.getOrdinate(i, d);
  5152. var v2 = cs2.getOrdinate(i, d);
  5153. if (cs1.getOrdinate(i, d) === cs2.getOrdinate(i, d)) { continue }
  5154. if (Double.isNaN(v1) && Double.isNaN(v2)) { continue }
  5155. return false
  5156. }
  5157. }
  5158. return true
  5159. };
  5160. CoordinateSequences.extend = function extend (fact, seq, size) {
  5161. var newseq = fact.create(size, seq.getDimension());
  5162. var n = seq.size();
  5163. CoordinateSequences.copy(seq, 0, newseq, 0, n);
  5164. if (n > 0) {
  5165. for (var i = n; i < size; i++) { CoordinateSequences.copy(seq, n - 1, newseq, i, 1); }
  5166. }
  5167. return newseq
  5168. };
  5169. CoordinateSequences.reverse = function reverse (seq) {
  5170. var last = seq.size() - 1;
  5171. var mid = Math.trunc(last / 2);
  5172. for (var i = 0; i <= mid; i++) {
  5173. CoordinateSequences.swap(seq, i, last - i);
  5174. }
  5175. };
  5176. CoordinateSequences.swap = function swap (seq, i, j) {
  5177. if (i === j) { return null }
  5178. for (var dim = 0; dim < seq.getDimension(); dim++) {
  5179. var tmp = seq.getOrdinate(i, dim);
  5180. seq.setOrdinate(i, dim, seq.getOrdinate(j, dim));
  5181. seq.setOrdinate(j, dim, tmp);
  5182. }
  5183. };
  5184. CoordinateSequences.copy = function copy (src, srcPos, dest, destPos, length) {
  5185. for (var i = 0; i < length; i++) {
  5186. CoordinateSequences.copyCoord(src, srcPos + i, dest, destPos + i);
  5187. }
  5188. };
  5189. CoordinateSequences.toString = function toString () {
  5190. if (arguments.length === 1) {
  5191. var cs = arguments[0];
  5192. var size = cs.size();
  5193. if (size === 0) { return '()' }
  5194. var dim = cs.getDimension();
  5195. var buf = new StringBuffer();
  5196. buf.append('(');
  5197. for (var i = 0; i < size; i++) {
  5198. if (i > 0) { buf.append(' '); }
  5199. for (var d = 0; d < dim; d++) {
  5200. if (d > 0) { buf.append(','); }
  5201. buf.append(StringUtil.toString(cs.getOrdinate(i, d)));
  5202. }
  5203. }
  5204. buf.append(')');
  5205. return buf.toString()
  5206. }
  5207. };
  5208. CoordinateSequences.ensureValidRing = function ensureValidRing (fact, seq) {
  5209. var n = seq.size();
  5210. if (n === 0) { return seq }
  5211. if (n <= 3) { return CoordinateSequences.createClosedRing(fact, seq, 4) }
  5212. var isClosed = seq.getOrdinate(0, CoordinateSequence.X) === seq.getOrdinate(n - 1, CoordinateSequence.X) && seq.getOrdinate(0, CoordinateSequence.Y) === seq.getOrdinate(n - 1, CoordinateSequence.Y);
  5213. if (isClosed) { return seq }
  5214. return CoordinateSequences.createClosedRing(fact, seq, n + 1)
  5215. };
  5216. CoordinateSequences.createClosedRing = function createClosedRing (fact, seq, size) {
  5217. var newseq = fact.create(size, seq.getDimension());
  5218. var n = seq.size();
  5219. CoordinateSequences.copy(seq, 0, newseq, 0, n);
  5220. for (var i = n; i < size; i++) { CoordinateSequences.copy(seq, 0, newseq, i, 1); }
  5221. return newseq
  5222. };
  5223. var LineString = (function (Geometry$$1) {
  5224. function LineString (points, factory) {
  5225. Geometry$$1.call(this, factory);
  5226. this._points = null;
  5227. this.init(points);
  5228. }
  5229. if ( Geometry$$1 ) LineString.__proto__ = Geometry$$1;
  5230. LineString.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
  5231. LineString.prototype.constructor = LineString;
  5232. var staticAccessors = { serialVersionUID: { configurable: true } };
  5233. LineString.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
  5234. if (this.isEmpty()) {
  5235. return new Envelope()
  5236. }
  5237. return this._points.expandEnvelope(new Envelope())
  5238. };
  5239. LineString.prototype.isRing = function isRing () {
  5240. return this.isClosed() && this.isSimple()
  5241. };
  5242. LineString.prototype.getSortIndex = function getSortIndex () {
  5243. return Geometry$$1.SORTINDEX_LINESTRING
  5244. };
  5245. LineString.prototype.getCoordinates = function getCoordinates () {
  5246. return this._points.toCoordinateArray()
  5247. };
  5248. LineString.prototype.equalsExact = function equalsExact () {
  5249. var this$1 = this;
  5250. if (arguments.length === 2) {
  5251. var other = arguments[0];
  5252. var tolerance = arguments[1];
  5253. if (!this.isEquivalentClass(other)) {
  5254. return false
  5255. }
  5256. var otherLineString = other;
  5257. if (this._points.size() !== otherLineString._points.size()) {
  5258. return false
  5259. }
  5260. for (var i = 0; i < this._points.size(); i++) {
  5261. if (!this$1.equal(this$1._points.getCoordinate(i), otherLineString._points.getCoordinate(i), tolerance)) {
  5262. return false
  5263. }
  5264. }
  5265. return true
  5266. } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
  5267. };
  5268. LineString.prototype.normalize = function normalize () {
  5269. var this$1 = this;
  5270. for (var i = 0; i < Math.trunc(this._points.size() / 2); i++) {
  5271. var j = this$1._points.size() - 1 - i;
  5272. if (!this$1._points.getCoordinate(i).equals(this$1._points.getCoordinate(j))) {
  5273. if (this$1._points.getCoordinate(i).compareTo(this$1._points.getCoordinate(j)) > 0) {
  5274. CoordinateSequences.reverse(this$1._points);
  5275. }
  5276. return null
  5277. }
  5278. }
  5279. };
  5280. LineString.prototype.getCoordinate = function getCoordinate () {
  5281. if (this.isEmpty()) { return null }
  5282. return this._points.getCoordinate(0)
  5283. };
  5284. LineString.prototype.getBoundaryDimension = function getBoundaryDimension () {
  5285. if (this.isClosed()) {
  5286. return Dimension.FALSE
  5287. }
  5288. return 0
  5289. };
  5290. LineString.prototype.isClosed = function isClosed () {
  5291. if (this.isEmpty()) {
  5292. return false
  5293. }
  5294. return this.getCoordinateN(0).equals2D(this.getCoordinateN(this.getNumPoints() - 1))
  5295. };
  5296. LineString.prototype.getEndPoint = function getEndPoint () {
  5297. if (this.isEmpty()) {
  5298. return null
  5299. }
  5300. return this.getPointN(this.getNumPoints() - 1)
  5301. };
  5302. LineString.prototype.getDimension = function getDimension () {
  5303. return 1
  5304. };
  5305. LineString.prototype.getLength = function getLength () {
  5306. return CGAlgorithms.computeLength(this._points)
  5307. };
  5308. LineString.prototype.getNumPoints = function getNumPoints () {
  5309. return this._points.size()
  5310. };
  5311. LineString.prototype.reverse = function reverse () {
  5312. var seq = this._points.copy();
  5313. CoordinateSequences.reverse(seq);
  5314. var revLine = this.getFactory().createLineString(seq);
  5315. return revLine
  5316. };
  5317. LineString.prototype.compareToSameClass = function compareToSameClass () {
  5318. var this$1 = this;
  5319. if (arguments.length === 1) {
  5320. var o = arguments[0];
  5321. var line = o;
  5322. var i = 0;
  5323. var j = 0;
  5324. while (i < this._points.size() && j < line._points.size()) {
  5325. var comparison = this$1._points.getCoordinate(i).compareTo(line._points.getCoordinate(j));
  5326. if (comparison !== 0) {
  5327. return comparison
  5328. }
  5329. i++;
  5330. j++;
  5331. }
  5332. if (i < this._points.size()) {
  5333. return 1
  5334. }
  5335. if (j < line._points.size()) {
  5336. return -1
  5337. }
  5338. return 0
  5339. } else if (arguments.length === 2) {
  5340. var o$1 = arguments[0];
  5341. var comp = arguments[1];
  5342. var line$1 = o$1;
  5343. return comp.compare(this._points, line$1._points)
  5344. }
  5345. };
  5346. LineString.prototype.apply = function apply () {
  5347. var this$1 = this;
  5348. if (hasInterface(arguments[0], CoordinateFilter)) {
  5349. var filter = arguments[0];
  5350. for (var i = 0; i < this._points.size(); i++) {
  5351. filter.filter(this$1._points.getCoordinate(i));
  5352. }
  5353. } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {
  5354. var filter$1 = arguments[0];
  5355. if (this._points.size() === 0) { return null }
  5356. for (var i$1 = 0; i$1 < this._points.size(); i$1++) {
  5357. filter$1.filter(this$1._points, i$1);
  5358. if (filter$1.isDone()) { break }
  5359. }
  5360. if (filter$1.isGeometryChanged()) { this.geometryChanged(); }
  5361. } else if (hasInterface(arguments[0], GeometryFilter)) {
  5362. var filter$2 = arguments[0];
  5363. filter$2.filter(this);
  5364. } else if (hasInterface(arguments[0], GeometryComponentFilter)) {
  5365. var filter$3 = arguments[0];
  5366. filter$3.filter(this);
  5367. }
  5368. };
  5369. LineString.prototype.getBoundary = function getBoundary () {
  5370. return new BoundaryOp(this).getBoundary()
  5371. };
  5372. LineString.prototype.isEquivalentClass = function isEquivalentClass (other) {
  5373. return other instanceof LineString
  5374. };
  5375. LineString.prototype.clone = function clone () {
  5376. var ls = Geometry$$1.prototype.clone.call(this);
  5377. ls._points = this._points.clone();
  5378. return ls
  5379. };
  5380. LineString.prototype.getCoordinateN = function getCoordinateN (n) {
  5381. return this._points.getCoordinate(n)
  5382. };
  5383. LineString.prototype.getGeometryType = function getGeometryType () {
  5384. return 'LineString'
  5385. };
  5386. LineString.prototype.copy = function copy () {
  5387. return new LineString(this._points.copy(), this._factory)
  5388. };
  5389. LineString.prototype.getCoordinateSequence = function getCoordinateSequence () {
  5390. return this._points
  5391. };
  5392. LineString.prototype.isEmpty = function isEmpty () {
  5393. return this._points.size() === 0
  5394. };
  5395. LineString.prototype.init = function init (points) {
  5396. if (points === null) {
  5397. points = this.getFactory().getCoordinateSequenceFactory().create([]);
  5398. }
  5399. if (points.size() === 1) {
  5400. throw new IllegalArgumentException('Invalid number of points in LineString (found ' + points.size() + ' - must be 0 or >= 2)')
  5401. }
  5402. this._points = points;
  5403. };
  5404. LineString.prototype.isCoordinate = function isCoordinate (pt) {
  5405. var this$1 = this;
  5406. for (var i = 0; i < this._points.size(); i++) {
  5407. if (this$1._points.getCoordinate(i).equals(pt)) {
  5408. return true
  5409. }
  5410. }
  5411. return false
  5412. };
  5413. LineString.prototype.getStartPoint = function getStartPoint () {
  5414. if (this.isEmpty()) {
  5415. return null
  5416. }
  5417. return this.getPointN(0)
  5418. };
  5419. LineString.prototype.getPointN = function getPointN (n) {
  5420. return this.getFactory().createPoint(this._points.getCoordinate(n))
  5421. };
  5422. LineString.prototype.interfaces_ = function interfaces_ () {
  5423. return [Lineal]
  5424. };
  5425. LineString.prototype.getClass = function getClass () {
  5426. return LineString
  5427. };
  5428. staticAccessors.serialVersionUID.get = function () { return 3110669828065365560 };
  5429. Object.defineProperties( LineString, staticAccessors );
  5430. return LineString;
  5431. }(Geometry));
  5432. var Puntal = function Puntal () {};
  5433. Puntal.prototype.interfaces_ = function interfaces_ () {
  5434. return []
  5435. };
  5436. Puntal.prototype.getClass = function getClass () {
  5437. return Puntal
  5438. };
  5439. var Point = (function (Geometry$$1) {
  5440. function Point (coordinates, factory) {
  5441. Geometry$$1.call(this, factory);
  5442. this._coordinates = coordinates || null;
  5443. this.init(this._coordinates);
  5444. }
  5445. if ( Geometry$$1 ) Point.__proto__ = Geometry$$1;
  5446. Point.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
  5447. Point.prototype.constructor = Point;
  5448. var staticAccessors = { serialVersionUID: { configurable: true } };
  5449. Point.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
  5450. if (this.isEmpty()) {
  5451. return new Envelope()
  5452. }
  5453. var env = new Envelope();
  5454. env.expandToInclude(this._coordinates.getX(0), this._coordinates.getY(0));
  5455. return env
  5456. };
  5457. Point.prototype.getSortIndex = function getSortIndex () {
  5458. return Geometry$$1.SORTINDEX_POINT
  5459. };
  5460. Point.prototype.getCoordinates = function getCoordinates () {
  5461. return this.isEmpty() ? [] : [this.getCoordinate()]
  5462. };
  5463. Point.prototype.equalsExact = function equalsExact () {
  5464. if (arguments.length === 2) {
  5465. var other = arguments[0];
  5466. var tolerance = arguments[1];
  5467. if (!this.isEquivalentClass(other)) {
  5468. return false
  5469. }
  5470. if (this.isEmpty() && other.isEmpty()) {
  5471. return true
  5472. }
  5473. if (this.isEmpty() !== other.isEmpty()) {
  5474. return false
  5475. }
  5476. return this.equal(other.getCoordinate(), this.getCoordinate(), tolerance)
  5477. } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
  5478. };
  5479. Point.prototype.normalize = function normalize () {};
  5480. Point.prototype.getCoordinate = function getCoordinate () {
  5481. return this._coordinates.size() !== 0 ? this._coordinates.getCoordinate(0) : null
  5482. };
  5483. Point.prototype.getBoundaryDimension = function getBoundaryDimension () {
  5484. return Dimension.FALSE
  5485. };
  5486. Point.prototype.getDimension = function getDimension () {
  5487. return 0
  5488. };
  5489. Point.prototype.getNumPoints = function getNumPoints () {
  5490. return this.isEmpty() ? 0 : 1
  5491. };
  5492. Point.prototype.reverse = function reverse () {
  5493. return this.copy()
  5494. };
  5495. Point.prototype.getX = function getX () {
  5496. if (this.getCoordinate() === null) {
  5497. throw new Error('getX called on empty Point')
  5498. }
  5499. return this.getCoordinate().x
  5500. };
  5501. Point.prototype.compareToSameClass = function compareToSameClass () {
  5502. if (arguments.length === 1) {
  5503. var other = arguments[0];
  5504. var point$1 = other;
  5505. return this.getCoordinate().compareTo(point$1.getCoordinate())
  5506. } else if (arguments.length === 2) {
  5507. var other$1 = arguments[0];
  5508. var comp = arguments[1];
  5509. var point = other$1;
  5510. return comp.compare(this._coordinates, point._coordinates)
  5511. }
  5512. };
  5513. Point.prototype.apply = function apply () {
  5514. if (hasInterface(arguments[0], CoordinateFilter)) {
  5515. var filter = arguments[0];
  5516. if (this.isEmpty()) {
  5517. return null
  5518. }
  5519. filter.filter(this.getCoordinate());
  5520. } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {
  5521. var filter$1 = arguments[0];
  5522. if (this.isEmpty()) { return null }
  5523. filter$1.filter(this._coordinates, 0);
  5524. if (filter$1.isGeometryChanged()) { this.geometryChanged(); }
  5525. } else if (hasInterface(arguments[0], GeometryFilter)) {
  5526. var filter$2 = arguments[0];
  5527. filter$2.filter(this);
  5528. } else if (hasInterface(arguments[0], GeometryComponentFilter)) {
  5529. var filter$3 = arguments[0];
  5530. filter$3.filter(this);
  5531. }
  5532. };
  5533. Point.prototype.getBoundary = function getBoundary () {
  5534. return this.getFactory().createGeometryCollection(null)
  5535. };
  5536. Point.prototype.clone = function clone () {
  5537. var p = Geometry$$1.prototype.clone.call(this);
  5538. p._coordinates = this._coordinates.clone();
  5539. return p
  5540. };
  5541. Point.prototype.getGeometryType = function getGeometryType () {
  5542. return 'Point'
  5543. };
  5544. Point.prototype.copy = function copy () {
  5545. return new Point(this._coordinates.copy(), this._factory)
  5546. };
  5547. Point.prototype.getCoordinateSequence = function getCoordinateSequence () {
  5548. return this._coordinates
  5549. };
  5550. Point.prototype.getY = function getY () {
  5551. if (this.getCoordinate() === null) {
  5552. throw new Error('getY called on empty Point')
  5553. }
  5554. return this.getCoordinate().y
  5555. };
  5556. Point.prototype.isEmpty = function isEmpty () {
  5557. return this._coordinates.size() === 0
  5558. };
  5559. Point.prototype.init = function init (coordinates) {
  5560. if (coordinates === null) {
  5561. coordinates = this.getFactory().getCoordinateSequenceFactory().create([]);
  5562. }
  5563. Assert.isTrue(coordinates.size() <= 1);
  5564. this._coordinates = coordinates;
  5565. };
  5566. Point.prototype.isSimple = function isSimple () {
  5567. return true
  5568. };
  5569. Point.prototype.interfaces_ = function interfaces_ () {
  5570. return [Puntal]
  5571. };
  5572. Point.prototype.getClass = function getClass () {
  5573. return Point
  5574. };
  5575. staticAccessors.serialVersionUID.get = function () { return 4902022702746614570 };
  5576. Object.defineProperties( Point, staticAccessors );
  5577. return Point;
  5578. }(Geometry));
  5579. var Polygonal = function Polygonal () {};
  5580. Polygonal.prototype.interfaces_ = function interfaces_ () {
  5581. return []
  5582. };
  5583. Polygonal.prototype.getClass = function getClass () {
  5584. return Polygonal
  5585. };
  5586. var Polygon = (function (Geometry$$1) {
  5587. function Polygon (shell, holes, factory) {
  5588. Geometry$$1.call(this, factory);
  5589. this._shell = null;
  5590. this._holes = null;
  5591. if (shell === null) {
  5592. shell = this.getFactory().createLinearRing();
  5593. }
  5594. if (holes === null) {
  5595. holes = [];
  5596. }
  5597. if (Geometry$$1.hasNullElements(holes)) {
  5598. throw new IllegalArgumentException('holes must not contain null elements')
  5599. }
  5600. if (shell.isEmpty() && Geometry$$1.hasNonEmptyElements(holes)) {
  5601. throw new IllegalArgumentException('shell is empty but holes are not')
  5602. }
  5603. this._shell = shell;
  5604. this._holes = holes;
  5605. }
  5606. if ( Geometry$$1 ) Polygon.__proto__ = Geometry$$1;
  5607. Polygon.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
  5608. Polygon.prototype.constructor = Polygon;
  5609. var staticAccessors = { serialVersionUID: { configurable: true } };
  5610. Polygon.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
  5611. return this._shell.getEnvelopeInternal()
  5612. };
  5613. Polygon.prototype.getSortIndex = function getSortIndex () {
  5614. return Geometry$$1.SORTINDEX_POLYGON
  5615. };
  5616. Polygon.prototype.getCoordinates = function getCoordinates () {
  5617. var this$1 = this;
  5618. if (this.isEmpty()) {
  5619. return []
  5620. }
  5621. var coordinates = new Array(this.getNumPoints()).fill(null);
  5622. var k = -1;
  5623. var shellCoordinates = this._shell.getCoordinates();
  5624. for (var x = 0; x < shellCoordinates.length; x++) {
  5625. k++;
  5626. coordinates[k] = shellCoordinates[x];
  5627. }
  5628. for (var i = 0; i < this._holes.length; i++) {
  5629. var childCoordinates = this$1._holes[i].getCoordinates();
  5630. for (var j = 0; j < childCoordinates.length; j++) {
  5631. k++;
  5632. coordinates[k] = childCoordinates[j];
  5633. }
  5634. }
  5635. return coordinates
  5636. };
  5637. Polygon.prototype.getArea = function getArea () {
  5638. var this$1 = this;
  5639. var area = 0.0;
  5640. area += Math.abs(CGAlgorithms.signedArea(this._shell.getCoordinateSequence()));
  5641. for (var i = 0; i < this._holes.length; i++) {
  5642. area -= Math.abs(CGAlgorithms.signedArea(this$1._holes[i].getCoordinateSequence()));
  5643. }
  5644. return area
  5645. };
  5646. Polygon.prototype.isRectangle = function isRectangle () {
  5647. if (this.getNumInteriorRing() !== 0) { return false }
  5648. if (this._shell === null) { return false }
  5649. if (this._shell.getNumPoints() !== 5) { return false }
  5650. var seq = this._shell.getCoordinateSequence();
  5651. var env = this.getEnvelopeInternal();
  5652. for (var i = 0; i < 5; i++) {
  5653. var x = seq.getX(i);
  5654. if (!(x === env.getMinX() || x === env.getMaxX())) { return false }
  5655. var y = seq.getY(i);
  5656. if (!(y === env.getMinY() || y === env.getMaxY())) { return false }
  5657. }
  5658. var prevX = seq.getX(0);
  5659. var prevY = seq.getY(0);
  5660. for (var i$1 = 1; i$1 <= 4; i$1++) {
  5661. var x$1 = seq.getX(i$1);
  5662. var y$1 = seq.getY(i$1);
  5663. var xChanged = x$1 !== prevX;
  5664. var yChanged = y$1 !== prevY;
  5665. if (xChanged === yChanged) { return false }
  5666. prevX = x$1;
  5667. prevY = y$1;
  5668. }
  5669. return true
  5670. };
  5671. Polygon.prototype.equalsExact = function equalsExact () {
  5672. var this$1 = this;
  5673. if (arguments.length === 2) {
  5674. var other = arguments[0];
  5675. var tolerance = arguments[1];
  5676. if (!this.isEquivalentClass(other)) {
  5677. return false
  5678. }
  5679. var otherPolygon = other;
  5680. var thisShell = this._shell;
  5681. var otherPolygonShell = otherPolygon._shell;
  5682. if (!thisShell.equalsExact(otherPolygonShell, tolerance)) {
  5683. return false
  5684. }
  5685. if (this._holes.length !== otherPolygon._holes.length) {
  5686. return false
  5687. }
  5688. for (var i = 0; i < this._holes.length; i++) {
  5689. if (!this$1._holes[i].equalsExact(otherPolygon._holes[i], tolerance)) {
  5690. return false
  5691. }
  5692. }
  5693. return true
  5694. } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
  5695. };
  5696. Polygon.prototype.normalize = function normalize () {
  5697. var this$1 = this;
  5698. if (arguments.length === 0) {
  5699. this.normalize(this._shell, true);
  5700. for (var i = 0; i < this._holes.length; i++) {
  5701. this$1.normalize(this$1._holes[i], false);
  5702. }
  5703. Arrays.sort(this._holes);
  5704. } else if (arguments.length === 2) {
  5705. var ring = arguments[0];
  5706. var clockwise = arguments[1];
  5707. if (ring.isEmpty()) {
  5708. return null
  5709. }
  5710. var uniqueCoordinates = new Array(ring.getCoordinates().length - 1).fill(null);
  5711. System.arraycopy(ring.getCoordinates(), 0, uniqueCoordinates, 0, uniqueCoordinates.length);
  5712. var minCoordinate = CoordinateArrays.minCoordinate(ring.getCoordinates());
  5713. CoordinateArrays.scroll(uniqueCoordinates, minCoordinate);
  5714. System.arraycopy(uniqueCoordinates, 0, ring.getCoordinates(), 0, uniqueCoordinates.length);
  5715. ring.getCoordinates()[uniqueCoordinates.length] = uniqueCoordinates[0];
  5716. if (CGAlgorithms.isCCW(ring.getCoordinates()) === clockwise) {
  5717. CoordinateArrays.reverse(ring.getCoordinates());
  5718. }
  5719. }
  5720. };
  5721. Polygon.prototype.getCoordinate = function getCoordinate () {
  5722. return this._shell.getCoordinate()
  5723. };
  5724. Polygon.prototype.getNumInteriorRing = function getNumInteriorRing () {
  5725. return this._holes.length
  5726. };
  5727. Polygon.prototype.getBoundaryDimension = function getBoundaryDimension () {
  5728. return 1
  5729. };
  5730. Polygon.prototype.getDimension = function getDimension () {
  5731. return 2
  5732. };
  5733. Polygon.prototype.getLength = function getLength () {
  5734. var this$1 = this;
  5735. var len = 0.0;
  5736. len += this._shell.getLength();
  5737. for (var i = 0; i < this._holes.length; i++) {
  5738. len += this$1._holes[i].getLength();
  5739. }
  5740. return len
  5741. };
  5742. Polygon.prototype.getNumPoints = function getNumPoints () {
  5743. var this$1 = this;
  5744. var numPoints = this._shell.getNumPoints();
  5745. for (var i = 0; i < this._holes.length; i++) {
  5746. numPoints += this$1._holes[i].getNumPoints();
  5747. }
  5748. return numPoints
  5749. };
  5750. Polygon.prototype.reverse = function reverse () {
  5751. var this$1 = this;
  5752. var poly = this.copy();
  5753. poly._shell = this._shell.copy().reverse();
  5754. poly._holes = new Array(this._holes.length).fill(null);
  5755. for (var i = 0; i < this._holes.length; i++) {
  5756. poly._holes[i] = this$1._holes[i].copy().reverse();
  5757. }
  5758. return poly
  5759. };
  5760. Polygon.prototype.convexHull = function convexHull () {
  5761. return this.getExteriorRing().convexHull()
  5762. };
  5763. Polygon.prototype.compareToSameClass = function compareToSameClass () {
  5764. var this$1 = this;
  5765. if (arguments.length === 1) {
  5766. var o = arguments[0];
  5767. var thisShell = this._shell;
  5768. var otherShell = o._shell;
  5769. return thisShell.compareToSameClass(otherShell)
  5770. } else if (arguments.length === 2) {
  5771. var o$1 = arguments[0];
  5772. var comp = arguments[1];
  5773. var poly = o$1;
  5774. var thisShell$1 = this._shell;
  5775. var otherShell$1 = poly._shell;
  5776. var shellComp = thisShell$1.compareToSameClass(otherShell$1, comp);
  5777. if (shellComp !== 0) { return shellComp }
  5778. var nHole1 = this.getNumInteriorRing();
  5779. var nHole2 = poly.getNumInteriorRing();
  5780. var i = 0;
  5781. while (i < nHole1 && i < nHole2) {
  5782. var thisHole = this$1.getInteriorRingN(i);
  5783. var otherHole = poly.getInteriorRingN(i);
  5784. var holeComp = thisHole.compareToSameClass(otherHole, comp);
  5785. if (holeComp !== 0) { return holeComp }
  5786. i++;
  5787. }
  5788. if (i < nHole1) { return 1 }
  5789. if (i < nHole2) { return -1 }
  5790. return 0
  5791. }
  5792. };
  5793. Polygon.prototype.apply = function apply (filter) {
  5794. var this$1 = this;
  5795. if (hasInterface(filter, CoordinateFilter)) {
  5796. this._shell.apply(filter);
  5797. for (var i$1 = 0; i$1 < this._holes.length; i$1++) {
  5798. this$1._holes[i$1].apply(filter);
  5799. }
  5800. } else if (hasInterface(filter, CoordinateSequenceFilter)) {
  5801. this._shell.apply(filter);
  5802. if (!filter.isDone()) {
  5803. for (var i$2 = 0; i$2 < this._holes.length; i$2++) {
  5804. this$1._holes[i$2].apply(filter);
  5805. if (filter.isDone()) { break }
  5806. }
  5807. }
  5808. if (filter.isGeometryChanged()) { this.geometryChanged(); }
  5809. } else if (hasInterface(filter, GeometryFilter)) {
  5810. filter.filter(this);
  5811. } else if (hasInterface(filter, GeometryComponentFilter)) {
  5812. filter.filter(this);
  5813. this._shell.apply(filter);
  5814. for (var i = 0; i < this._holes.length; i++) {
  5815. this$1._holes[i].apply(filter);
  5816. }
  5817. }
  5818. };
  5819. Polygon.prototype.getBoundary = function getBoundary () {
  5820. var this$1 = this;
  5821. if (this.isEmpty()) {
  5822. return this.getFactory().createMultiLineString()
  5823. }
  5824. var rings = new Array(this._holes.length + 1).fill(null);
  5825. rings[0] = this._shell;
  5826. for (var i = 0; i < this._holes.length; i++) {
  5827. rings[i + 1] = this$1._holes[i];
  5828. }
  5829. if (rings.length <= 1) { return this.getFactory().createLinearRing(rings[0].getCoordinateSequence()) }
  5830. return this.getFactory().createMultiLineString(rings)
  5831. };
  5832. Polygon.prototype.clone = function clone () {
  5833. var this$1 = this;
  5834. var poly = Geometry$$1.prototype.clone.call(this);
  5835. poly._shell = this._shell.clone();
  5836. poly._holes = new Array(this._holes.length).fill(null);
  5837. for (var i = 0; i < this._holes.length; i++) {
  5838. poly._holes[i] = this$1._holes[i].clone();
  5839. }
  5840. return poly
  5841. };
  5842. Polygon.prototype.getGeometryType = function getGeometryType () {
  5843. return 'Polygon'
  5844. };
  5845. Polygon.prototype.copy = function copy () {
  5846. var this$1 = this;
  5847. var shell = this._shell.copy();
  5848. var holes = new Array(this._holes.length).fill(null);
  5849. for (var i = 0; i < holes.length; i++) {
  5850. holes[i] = this$1._holes[i].copy();
  5851. }
  5852. return new Polygon(shell, holes, this._factory)
  5853. };
  5854. Polygon.prototype.getExteriorRing = function getExteriorRing () {
  5855. return this._shell
  5856. };
  5857. Polygon.prototype.isEmpty = function isEmpty () {
  5858. return this._shell.isEmpty()
  5859. };
  5860. Polygon.prototype.getInteriorRingN = function getInteriorRingN (n) {
  5861. return this._holes[n]
  5862. };
  5863. Polygon.prototype.interfaces_ = function interfaces_ () {
  5864. return [Polygonal]
  5865. };
  5866. Polygon.prototype.getClass = function getClass () {
  5867. return Polygon
  5868. };
  5869. staticAccessors.serialVersionUID.get = function () { return -3494792200821764533 };
  5870. Object.defineProperties( Polygon, staticAccessors );
  5871. return Polygon;
  5872. }(Geometry));
  5873. var MultiPoint = (function (GeometryCollection$$1) {
  5874. function MultiPoint () {
  5875. GeometryCollection$$1.apply(this, arguments);
  5876. }
  5877. if ( GeometryCollection$$1 ) MultiPoint.__proto__ = GeometryCollection$$1;
  5878. MultiPoint.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );
  5879. MultiPoint.prototype.constructor = MultiPoint;
  5880. var staticAccessors = { serialVersionUID: { configurable: true } };
  5881. MultiPoint.prototype.getSortIndex = function getSortIndex () {
  5882. return Geometry.SORTINDEX_MULTIPOINT
  5883. };
  5884. MultiPoint.prototype.isValid = function isValid () {
  5885. return true
  5886. };
  5887. MultiPoint.prototype.equalsExact = function equalsExact () {
  5888. if (arguments.length === 2) {
  5889. var other = arguments[0];
  5890. var tolerance = arguments[1];
  5891. if (!this.isEquivalentClass(other)) {
  5892. return false
  5893. }
  5894. return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)
  5895. } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }
  5896. };
  5897. MultiPoint.prototype.getCoordinate = function getCoordinate () {
  5898. if (arguments.length === 1) {
  5899. var n = arguments[0];
  5900. return this._geometries[n].getCoordinate()
  5901. } else { return GeometryCollection$$1.prototype.getCoordinate.apply(this, arguments) }
  5902. };
  5903. MultiPoint.prototype.getBoundaryDimension = function getBoundaryDimension () {
  5904. return Dimension.FALSE
  5905. };
  5906. MultiPoint.prototype.getDimension = function getDimension () {
  5907. return 0
  5908. };
  5909. MultiPoint.prototype.getBoundary = function getBoundary () {
  5910. return this.getFactory().createGeometryCollection(null)
  5911. };
  5912. MultiPoint.prototype.getGeometryType = function getGeometryType () {
  5913. return 'MultiPoint'
  5914. };
  5915. MultiPoint.prototype.copy = function copy () {
  5916. var this$1 = this;
  5917. var points = new Array(this._geometries.length).fill(null);
  5918. for (var i = 0; i < points.length; i++) {
  5919. points[i] = this$1._geometries[i].copy();
  5920. }
  5921. return new MultiPoint(points, this._factory)
  5922. };
  5923. MultiPoint.prototype.interfaces_ = function interfaces_ () {
  5924. return [Puntal]
  5925. };
  5926. MultiPoint.prototype.getClass = function getClass () {
  5927. return MultiPoint
  5928. };
  5929. staticAccessors.serialVersionUID.get = function () { return -8048474874175355449 };
  5930. Object.defineProperties( MultiPoint, staticAccessors );
  5931. return MultiPoint;
  5932. }(GeometryCollection));
  5933. var LinearRing = (function (LineString$$1) {
  5934. function LinearRing (points, factory) {
  5935. if (points instanceof Coordinate && factory instanceof GeometryFactory) {
  5936. points = factory.getCoordinateSequenceFactory().create(points);
  5937. }
  5938. LineString$$1.call(this, points, factory);
  5939. this.validateConstruction();
  5940. }
  5941. if ( LineString$$1 ) LinearRing.__proto__ = LineString$$1;
  5942. LinearRing.prototype = Object.create( LineString$$1 && LineString$$1.prototype );
  5943. LinearRing.prototype.constructor = LinearRing;
  5944. var staticAccessors = { MINIMUM_VALID_SIZE: { configurable: true },serialVersionUID: { configurable: true } };
  5945. LinearRing.prototype.getSortIndex = function getSortIndex () {
  5946. return Geometry.SORTINDEX_LINEARRING
  5947. };
  5948. LinearRing.prototype.getBoundaryDimension = function getBoundaryDimension () {
  5949. return Dimension.FALSE
  5950. };
  5951. LinearRing.prototype.isClosed = function isClosed () {
  5952. if (this.isEmpty()) {
  5953. return true
  5954. }
  5955. return LineString$$1.prototype.isClosed.call(this)
  5956. };
  5957. LinearRing.prototype.reverse = function reverse () {
  5958. var seq = this._points.copy();
  5959. CoordinateSequences.reverse(seq);
  5960. var rev = this.getFactory().createLinearRing(seq);
  5961. return rev
  5962. };
  5963. LinearRing.prototype.validateConstruction = function validateConstruction () {
  5964. if (!this.isEmpty() && !LineString$$1.prototype.isClosed.call(this)) {
  5965. throw new IllegalArgumentException('Points of LinearRing do not form a closed linestring')
  5966. }
  5967. if (this.getCoordinateSequence().size() >= 1 && this.getCoordinateSequence().size() < LinearRing.MINIMUM_VALID_SIZE) {
  5968. throw new IllegalArgumentException('Invalid number of points in LinearRing (found ' + this.getCoordinateSequence().size() + ' - must be 0 or >= 4)')
  5969. }
  5970. };
  5971. LinearRing.prototype.getGeometryType = function getGeometryType () {
  5972. return 'LinearRing'
  5973. };
  5974. LinearRing.prototype.copy = function copy () {
  5975. return new LinearRing(this._points.copy(), this._factory)
  5976. };
  5977. LinearRing.prototype.interfaces_ = function interfaces_ () {
  5978. return []
  5979. };
  5980. LinearRing.prototype.getClass = function getClass () {
  5981. return LinearRing
  5982. };
  5983. staticAccessors.MINIMUM_VALID_SIZE.get = function () { return 4 };
  5984. staticAccessors.serialVersionUID.get = function () { return -4261142084085851829 };
  5985. Object.defineProperties( LinearRing, staticAccessors );
  5986. return LinearRing;
  5987. }(LineString));
  5988. var MultiPolygon = (function (GeometryCollection$$1) {
  5989. function MultiPolygon () {
  5990. GeometryCollection$$1.apply(this, arguments);
  5991. }
  5992. if ( GeometryCollection$$1 ) MultiPolygon.__proto__ = GeometryCollection$$1;
  5993. MultiPolygon.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );
  5994. MultiPolygon.prototype.constructor = MultiPolygon;
  5995. var staticAccessors = { serialVersionUID: { configurable: true } };
  5996. MultiPolygon.prototype.getSortIndex = function getSortIndex () {
  5997. return Geometry.SORTINDEX_MULTIPOLYGON
  5998. };
  5999. MultiPolygon.prototype.equalsExact = function equalsExact () {
  6000. if (arguments.length === 2) {
  6001. var other = arguments[0];
  6002. var tolerance = arguments[1];
  6003. if (!this.isEquivalentClass(other)) {
  6004. return false
  6005. }
  6006. return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)
  6007. } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }
  6008. };
  6009. MultiPolygon.prototype.getBoundaryDimension = function getBoundaryDimension () {
  6010. return 1
  6011. };
  6012. MultiPolygon.prototype.getDimension = function getDimension () {
  6013. return 2
  6014. };
  6015. MultiPolygon.prototype.reverse = function reverse () {
  6016. var this$1 = this;
  6017. var n = this._geometries.length;
  6018. var revGeoms = new Array(n).fill(null);
  6019. for (var i = 0; i < this._geometries.length; i++) {
  6020. revGeoms[i] = this$1._geometries[i].reverse();
  6021. }
  6022. return this.getFactory().createMultiPolygon(revGeoms)
  6023. };
  6024. MultiPolygon.prototype.getBoundary = function getBoundary () {
  6025. var this$1 = this;
  6026. if (this.isEmpty()) {
  6027. return this.getFactory().createMultiLineString()
  6028. }
  6029. var allRings = new ArrayList();
  6030. for (var i = 0; i < this._geometries.length; i++) {
  6031. var polygon = this$1._geometries[i];
  6032. var rings = polygon.getBoundary();
  6033. for (var j = 0; j < rings.getNumGeometries(); j++) {
  6034. allRings.add(rings.getGeometryN(j));
  6035. }
  6036. }
  6037. var allRingsArray = new Array(allRings.size()).fill(null);
  6038. return this.getFactory().createMultiLineString(allRings.toArray(allRingsArray))
  6039. };
  6040. MultiPolygon.prototype.getGeometryType = function getGeometryType () {
  6041. return 'MultiPolygon'
  6042. };
  6043. MultiPolygon.prototype.copy = function copy () {
  6044. var this$1 = this;
  6045. var polygons = new Array(this._geometries.length).fill(null);
  6046. for (var i = 0; i < polygons.length; i++) {
  6047. polygons[i] = this$1._geometries[i].copy();
  6048. }
  6049. return new MultiPolygon(polygons, this._factory)
  6050. };
  6051. MultiPolygon.prototype.interfaces_ = function interfaces_ () {
  6052. return [Polygonal]
  6053. };
  6054. MultiPolygon.prototype.getClass = function getClass () {
  6055. return MultiPolygon
  6056. };
  6057. staticAccessors.serialVersionUID.get = function () { return -551033529766975875 };
  6058. Object.defineProperties( MultiPolygon, staticAccessors );
  6059. return MultiPolygon;
  6060. }(GeometryCollection));
  6061. var GeometryEditor = function GeometryEditor (factory) {
  6062. this._factory = factory || null;
  6063. this._isUserDataCopied = false;
  6064. };
  6065. var staticAccessors$16 = { NoOpGeometryOperation: { configurable: true },CoordinateOperation: { configurable: true },CoordinateSequenceOperation: { configurable: true } };
  6066. GeometryEditor.prototype.setCopyUserData = function setCopyUserData (isUserDataCopied) {
  6067. this._isUserDataCopied = isUserDataCopied;
  6068. };
  6069. GeometryEditor.prototype.edit = function edit (geometry, operation) {
  6070. if (geometry === null) { return null }
  6071. var result = this.editInternal(geometry, operation);
  6072. if (this._isUserDataCopied) {
  6073. result.setUserData(geometry.getUserData());
  6074. }
  6075. return result
  6076. };
  6077. GeometryEditor.prototype.editInternal = function editInternal (geometry, operation) {
  6078. if (this._factory === null) { this._factory = geometry.getFactory(); }
  6079. if (geometry instanceof GeometryCollection) {
  6080. return this.editGeometryCollection(geometry, operation)
  6081. }
  6082. if (geometry instanceof Polygon) {
  6083. return this.editPolygon(geometry, operation)
  6084. }
  6085. if (geometry instanceof Point) {
  6086. return operation.edit(geometry, this._factory)
  6087. }
  6088. if (geometry instanceof LineString) {
  6089. return operation.edit(geometry, this._factory)
  6090. }
  6091. Assert.shouldNeverReachHere('Unsupported Geometry class: ' + geometry.getClass().getName());
  6092. return null
  6093. };
  6094. GeometryEditor.prototype.editGeometryCollection = function editGeometryCollection (collection, operation) {
  6095. var this$1 = this;
  6096. var collectionForType = operation.edit(collection, this._factory);
  6097. var geometries = new ArrayList();
  6098. for (var i = 0; i < collectionForType.getNumGeometries(); i++) {
  6099. var geometry = this$1.edit(collectionForType.getGeometryN(i), operation);
  6100. if (geometry === null || geometry.isEmpty()) {
  6101. continue
  6102. }
  6103. geometries.add(geometry);
  6104. }
  6105. if (collectionForType.getClass() === MultiPoint) {
  6106. return this._factory.createMultiPoint(geometries.toArray([]))
  6107. }
  6108. if (collectionForType.getClass() === MultiLineString) {
  6109. return this._factory.createMultiLineString(geometries.toArray([]))
  6110. }
  6111. if (collectionForType.getClass() === MultiPolygon) {
  6112. return this._factory.createMultiPolygon(geometries.toArray([]))
  6113. }
  6114. return this._factory.createGeometryCollection(geometries.toArray([]))
  6115. };
  6116. GeometryEditor.prototype.editPolygon = function editPolygon (polygon, operation) {
  6117. var this$1 = this;
  6118. var newPolygon = operation.edit(polygon, this._factory);
  6119. if (newPolygon === null) { newPolygon = this._factory.createPolygon(null); }
  6120. if (newPolygon.isEmpty()) {
  6121. return newPolygon
  6122. }
  6123. var shell = this.edit(newPolygon.getExteriorRing(), operation);
  6124. if (shell === null || shell.isEmpty()) {
  6125. return this._factory.createPolygon()
  6126. }
  6127. var holes = new ArrayList();
  6128. for (var i = 0; i < newPolygon.getNumInteriorRing(); i++) {
  6129. var hole = this$1.edit(newPolygon.getInteriorRingN(i), operation);
  6130. if (hole === null || hole.isEmpty()) {
  6131. continue
  6132. }
  6133. holes.add(hole);
  6134. }
  6135. return this._factory.createPolygon(shell, holes.toArray([]))
  6136. };
  6137. GeometryEditor.prototype.interfaces_ = function interfaces_ () {
  6138. return []
  6139. };
  6140. GeometryEditor.prototype.getClass = function getClass () {
  6141. return GeometryEditor
  6142. };
  6143. GeometryEditor.GeometryEditorOperation = function GeometryEditorOperation () {};
  6144. staticAccessors$16.NoOpGeometryOperation.get = function () { return NoOpGeometryOperation };
  6145. staticAccessors$16.CoordinateOperation.get = function () { return CoordinateOperation };
  6146. staticAccessors$16.CoordinateSequenceOperation.get = function () { return CoordinateSequenceOperation };
  6147. Object.defineProperties( GeometryEditor, staticAccessors$16 );
  6148. var NoOpGeometryOperation = function NoOpGeometryOperation () {};
  6149. NoOpGeometryOperation.prototype.edit = function edit (geometry, factory) {
  6150. return geometry
  6151. };
  6152. NoOpGeometryOperation.prototype.interfaces_ = function interfaces_ () {
  6153. return [GeometryEditor.GeometryEditorOperation]
  6154. };
  6155. NoOpGeometryOperation.prototype.getClass = function getClass () {
  6156. return NoOpGeometryOperation
  6157. };
  6158. var CoordinateOperation = function CoordinateOperation () {};
  6159. CoordinateOperation.prototype.edit = function edit (geometry, factory) {
  6160. var coords = this.editCoordinates(geometry.getCoordinates(), geometry);
  6161. if (coords === null) { return geometry }
  6162. if (geometry instanceof LinearRing) {
  6163. return factory.createLinearRing(coords)
  6164. }
  6165. if (geometry instanceof LineString) {
  6166. return factory.createLineString(coords)
  6167. }
  6168. if (geometry instanceof Point) {
  6169. if (coords.length > 0) {
  6170. return factory.createPoint(coords[0])
  6171. } else {
  6172. return factory.createPoint()
  6173. }
  6174. }
  6175. return geometry
  6176. };
  6177. CoordinateOperation.prototype.interfaces_ = function interfaces_ () {
  6178. return [GeometryEditor.GeometryEditorOperation]
  6179. };
  6180. CoordinateOperation.prototype.getClass = function getClass () {
  6181. return CoordinateOperation
  6182. };
  6183. var CoordinateSequenceOperation = function CoordinateSequenceOperation () {};
  6184. CoordinateSequenceOperation.prototype.edit = function edit (geometry, factory) {
  6185. if (geometry instanceof LinearRing) {
  6186. return factory.createLinearRing(this.edit(geometry.getCoordinateSequence(), geometry))
  6187. }
  6188. if (geometry instanceof LineString) {
  6189. return factory.createLineString(this.edit(geometry.getCoordinateSequence(), geometry))
  6190. }
  6191. if (geometry instanceof Point) {
  6192. return factory.createPoint(this.edit(geometry.getCoordinateSequence(), geometry))
  6193. }
  6194. return geometry
  6195. };
  6196. CoordinateSequenceOperation.prototype.interfaces_ = function interfaces_ () {
  6197. return [GeometryEditor.GeometryEditorOperation]
  6198. };
  6199. CoordinateSequenceOperation.prototype.getClass = function getClass () {
  6200. return CoordinateSequenceOperation
  6201. };
  6202. var CoordinateArraySequence = function CoordinateArraySequence () {
  6203. var this$1 = this;
  6204. this._dimension = 3;
  6205. this._coordinates = null;
  6206. if (arguments.length === 1) {
  6207. if (arguments[0] instanceof Array) {
  6208. this._coordinates = arguments[0];
  6209. this._dimension = 3;
  6210. } else if (Number.isInteger(arguments[0])) {
  6211. var size = arguments[0];
  6212. this._coordinates = new Array(size).fill(null);
  6213. for (var i = 0; i < size; i++) {
  6214. this$1._coordinates[i] = new Coordinate();
  6215. }
  6216. } else if (hasInterface(arguments[0], CoordinateSequence)) {
  6217. var coordSeq = arguments[0];
  6218. if (coordSeq === null) {
  6219. this._coordinates = new Array(0).fill(null);
  6220. return null
  6221. }
  6222. this._dimension = coordSeq.getDimension();
  6223. this._coordinates = new Array(coordSeq.size()).fill(null);
  6224. for (var i$1 = 0; i$1 < this._coordinates.length; i$1++) {
  6225. this$1._coordinates[i$1] = coordSeq.getCoordinateCopy(i$1);
  6226. }
  6227. }
  6228. } else if (arguments.length === 2) {
  6229. if (arguments[0] instanceof Array && Number.isInteger(arguments[1])) {
  6230. var coordinates = arguments[0];
  6231. var dimension = arguments[1];
  6232. this._coordinates = coordinates;
  6233. this._dimension = dimension;
  6234. if (coordinates === null) { this._coordinates = new Array(0).fill(null); }
  6235. } else if (Number.isInteger(arguments[0]) && Number.isInteger(arguments[1])) {
  6236. var size$1 = arguments[0];
  6237. var dimension$1 = arguments[1];
  6238. this._coordinates = new Array(size$1).fill(null);
  6239. this._dimension = dimension$1;
  6240. for (var i$2 = 0; i$2 < size$1; i$2++) {
  6241. this$1._coordinates[i$2] = new Coordinate();
  6242. }
  6243. }
  6244. }
  6245. };
  6246. var staticAccessors$18 = { serialVersionUID: { configurable: true } };
  6247. CoordinateArraySequence.prototype.setOrdinate = function setOrdinate (index, ordinateIndex, value) {
  6248. switch (ordinateIndex) {
  6249. case CoordinateSequence.X:
  6250. this._coordinates[index].x = value;
  6251. break
  6252. case CoordinateSequence.Y:
  6253. this._coordinates[index].y = value;
  6254. break
  6255. case CoordinateSequence.Z:
  6256. this._coordinates[index].z = value;
  6257. break
  6258. default:
  6259. throw new IllegalArgumentException('invalid ordinateIndex')
  6260. }
  6261. };
  6262. CoordinateArraySequence.prototype.size = function size () {
  6263. return this._coordinates.length
  6264. };
  6265. CoordinateArraySequence.prototype.getOrdinate = function getOrdinate (index, ordinateIndex) {
  6266. switch (ordinateIndex) {
  6267. case CoordinateSequence.X:
  6268. return this._coordinates[index].x
  6269. case CoordinateSequence.Y:
  6270. return this._coordinates[index].y
  6271. case CoordinateSequence.Z:
  6272. return this._coordinates[index].z
  6273. default:
  6274. }
  6275. return Double.NaN
  6276. };
  6277. CoordinateArraySequence.prototype.getCoordinate = function getCoordinate () {
  6278. if (arguments.length === 1) {
  6279. var i = arguments[0];
  6280. return this._coordinates[i]
  6281. } else if (arguments.length === 2) {
  6282. var index = arguments[0];
  6283. var coord = arguments[1];
  6284. coord.x = this._coordinates[index].x;
  6285. coord.y = this._coordinates[index].y;
  6286. coord.z = this._coordinates[index].z;
  6287. }
  6288. };
  6289. CoordinateArraySequence.prototype.getCoordinateCopy = function getCoordinateCopy (i) {
  6290. return new Coordinate(this._coordinates[i])
  6291. };
  6292. CoordinateArraySequence.prototype.getDimension = function getDimension () {
  6293. return this._dimension
  6294. };
  6295. CoordinateArraySequence.prototype.getX = function getX (index) {
  6296. return this._coordinates[index].x
  6297. };
  6298. CoordinateArraySequence.prototype.clone = function clone () {
  6299. var this$1 = this;
  6300. var cloneCoordinates = new Array(this.size()).fill(null);
  6301. for (var i = 0; i < this._coordinates.length; i++) {
  6302. cloneCoordinates[i] = this$1._coordinates[i].clone();
  6303. }
  6304. return new CoordinateArraySequence(cloneCoordinates, this._dimension)
  6305. };
  6306. CoordinateArraySequence.prototype.expandEnvelope = function expandEnvelope (env) {
  6307. var this$1 = this;
  6308. for (var i = 0; i < this._coordinates.length; i++) {
  6309. env.expandToInclude(this$1._coordinates[i]);
  6310. }
  6311. return env
  6312. };
  6313. CoordinateArraySequence.prototype.copy = function copy () {
  6314. var this$1 = this;
  6315. var cloneCoordinates = new Array(this.size()).fill(null);
  6316. for (var i = 0; i < this._coordinates.length; i++) {
  6317. cloneCoordinates[i] = this$1._coordinates[i].copy();
  6318. }
  6319. return new CoordinateArraySequence(cloneCoordinates, this._dimension)
  6320. };
  6321. CoordinateArraySequence.prototype.toString = function toString () {
  6322. var this$1 = this;
  6323. if (this._coordinates.length > 0) {
  6324. var strBuf = new StringBuffer(17 * this._coordinates.length);
  6325. strBuf.append('(');
  6326. strBuf.append(this._coordinates[0]);
  6327. for (var i = 1; i < this._coordinates.length; i++) {
  6328. strBuf.append(', ');
  6329. strBuf.append(this$1._coordinates[i]);
  6330. }
  6331. strBuf.append(')');
  6332. return strBuf.toString()
  6333. } else {
  6334. return '()'
  6335. }
  6336. };
  6337. CoordinateArraySequence.prototype.getY = function getY (index) {
  6338. return this._coordinates[index].y
  6339. };
  6340. CoordinateArraySequence.prototype.toCoordinateArray = function toCoordinateArray () {
  6341. return this._coordinates
  6342. };
  6343. CoordinateArraySequence.prototype.interfaces_ = function interfaces_ () {
  6344. return [CoordinateSequence, Serializable]
  6345. };
  6346. CoordinateArraySequence.prototype.getClass = function getClass () {
  6347. return CoordinateArraySequence
  6348. };
  6349. staticAccessors$18.serialVersionUID.get = function () { return -915438501601840650 };
  6350. Object.defineProperties( CoordinateArraySequence, staticAccessors$18 );
  6351. var CoordinateArraySequenceFactory = function CoordinateArraySequenceFactory () {};
  6352. var staticAccessors$17 = { serialVersionUID: { configurable: true },instanceObject: { configurable: true } };
  6353. CoordinateArraySequenceFactory.prototype.readResolve = function readResolve () {
  6354. return CoordinateArraySequenceFactory.instance()
  6355. };
  6356. CoordinateArraySequenceFactory.prototype.create = function create () {
  6357. if (arguments.length === 1) {
  6358. if (arguments[0] instanceof Array) {
  6359. var coordinates = arguments[0];
  6360. return new CoordinateArraySequence(coordinates)
  6361. } else if (hasInterface(arguments[0], CoordinateSequence)) {
  6362. var coordSeq = arguments[0];
  6363. return new CoordinateArraySequence(coordSeq)
  6364. }
  6365. } else if (arguments.length === 2) {
  6366. var size = arguments[0];
  6367. var dimension = arguments[1];
  6368. if (dimension > 3) { dimension = 3; }
  6369. if (dimension < 2) { return new CoordinateArraySequence(size) }
  6370. return new CoordinateArraySequence(size, dimension)
  6371. }
  6372. };
  6373. CoordinateArraySequenceFactory.prototype.interfaces_ = function interfaces_ () {
  6374. return [CoordinateSequenceFactory, Serializable]
  6375. };
  6376. CoordinateArraySequenceFactory.prototype.getClass = function getClass () {
  6377. return CoordinateArraySequenceFactory
  6378. };
  6379. CoordinateArraySequenceFactory.instance = function instance () {
  6380. return CoordinateArraySequenceFactory.instanceObject
  6381. };
  6382. staticAccessors$17.serialVersionUID.get = function () { return -4099577099607551657 };
  6383. staticAccessors$17.instanceObject.get = function () { return new CoordinateArraySequenceFactory() };
  6384. Object.defineProperties( CoordinateArraySequenceFactory, staticAccessors$17 );
  6385. /**
  6386. * @see http://download.oracle.com/javase/6/docs/api/java/util/HashMap.html
  6387. *
  6388. * @extends {javascript.util.Map}
  6389. * @constructor
  6390. * @private
  6391. */
  6392. var HashMap = (function (MapInterface) {
  6393. function HashMap () {
  6394. MapInterface.call(this);
  6395. this.map_ = new Map();
  6396. }
  6397. if ( MapInterface ) HashMap.__proto__ = MapInterface;
  6398. HashMap.prototype = Object.create( MapInterface && MapInterface.prototype );
  6399. HashMap.prototype.constructor = HashMap;
  6400. /**
  6401. * @override
  6402. */
  6403. HashMap.prototype.get = function get (key) {
  6404. return this.map_.get(key) || null
  6405. };
  6406. /**
  6407. * @override
  6408. */
  6409. HashMap.prototype.put = function put (key, value) {
  6410. this.map_.set(key, value);
  6411. return value
  6412. };
  6413. /**
  6414. * @override
  6415. */
  6416. HashMap.prototype.values = function values () {
  6417. var arrayList = new ArrayList();
  6418. var it = this.map_.values();
  6419. var o = it.next();
  6420. while (!o.done) {
  6421. arrayList.add(o.value);
  6422. o = it.next();
  6423. }
  6424. return arrayList
  6425. };
  6426. /**
  6427. * @override
  6428. */
  6429. HashMap.prototype.entrySet = function entrySet () {
  6430. var hashSet = new HashSet();
  6431. this.map_.entries().forEach(function (entry) { return hashSet.add(entry); });
  6432. return hashSet
  6433. };
  6434. /**
  6435. * @override
  6436. */
  6437. HashMap.prototype.size = function size () {
  6438. return this.map_.size()
  6439. };
  6440. return HashMap;
  6441. }(Map$1));
  6442. var PrecisionModel = function PrecisionModel () {
  6443. this._modelType = null;
  6444. this._scale = null;
  6445. if (arguments.length === 0) {
  6446. this._modelType = PrecisionModel.FLOATING;
  6447. } else if (arguments.length === 1) {
  6448. if (arguments[0] instanceof Type) {
  6449. var modelType = arguments[0];
  6450. this._modelType = modelType;
  6451. if (modelType === PrecisionModel.FIXED) {
  6452. this.setScale(1.0);
  6453. }
  6454. } else if (typeof arguments[0] === 'number') {
  6455. var scale = arguments[0];
  6456. this._modelType = PrecisionModel.FIXED;
  6457. this.setScale(scale);
  6458. } else if (arguments[0] instanceof PrecisionModel) {
  6459. var pm = arguments[0];
  6460. this._modelType = pm._modelType;
  6461. this._scale = pm._scale;
  6462. }
  6463. }
  6464. };
  6465. var staticAccessors$19 = { serialVersionUID: { configurable: true },maximumPreciseValue: { configurable: true } };
  6466. PrecisionModel.prototype.equals = function equals (other) {
  6467. if (!(other instanceof PrecisionModel)) {
  6468. return false
  6469. }
  6470. var otherPrecisionModel = other;
  6471. return this._modelType === otherPrecisionModel._modelType && this._scale === otherPrecisionModel._scale
  6472. };
  6473. PrecisionModel.prototype.compareTo = function compareTo (o) {
  6474. var other = o;
  6475. var sigDigits = this.getMaximumSignificantDigits();
  6476. var otherSigDigits = other.getMaximumSignificantDigits();
  6477. return new Integer(sigDigits).compareTo(new Integer(otherSigDigits))
  6478. };
  6479. PrecisionModel.prototype.getScale = function getScale () {
  6480. return this._scale
  6481. };
  6482. PrecisionModel.prototype.isFloating = function isFloating () {
  6483. return this._modelType === PrecisionModel.FLOATING || this._modelType === PrecisionModel.FLOATING_SINGLE
  6484. };
  6485. PrecisionModel.prototype.getType = function getType () {
  6486. return this._modelType
  6487. };
  6488. PrecisionModel.prototype.toString = function toString () {
  6489. var description = 'UNKNOWN';
  6490. if (this._modelType === PrecisionModel.FLOATING) {
  6491. description = 'Floating';
  6492. } else if (this._modelType === PrecisionModel.FLOATING_SINGLE) {
  6493. description = 'Floating-Single';
  6494. } else if (this._modelType === PrecisionModel.FIXED) {
  6495. description = 'Fixed (Scale=' + this.getScale() + ')';
  6496. }
  6497. return description
  6498. };
  6499. PrecisionModel.prototype.makePrecise = function makePrecise () {
  6500. if (typeof arguments[0] === 'number') {
  6501. var val = arguments[0];
  6502. if (Double.isNaN(val)) { return val }
  6503. if (this._modelType === PrecisionModel.FLOATING_SINGLE) {
  6504. var floatSingleVal = val;
  6505. return floatSingleVal
  6506. }
  6507. if (this._modelType === PrecisionModel.FIXED) {
  6508. return Math.round(val * this._scale) / this._scale
  6509. }
  6510. return val
  6511. } else if (arguments[0] instanceof Coordinate) {
  6512. var coord = arguments[0];
  6513. if (this._modelType === PrecisionModel.FLOATING) { return null }
  6514. coord.x = this.makePrecise(coord.x);
  6515. coord.y = this.makePrecise(coord.y);
  6516. }
  6517. };
  6518. PrecisionModel.prototype.getMaximumSignificantDigits = function getMaximumSignificantDigits () {
  6519. var maxSigDigits = 16;
  6520. if (this._modelType === PrecisionModel.FLOATING) {
  6521. maxSigDigits = 16;
  6522. } else if (this._modelType === PrecisionModel.FLOATING_SINGLE) {
  6523. maxSigDigits = 6;
  6524. } else if (this._modelType === PrecisionModel.FIXED) {
  6525. maxSigDigits = 1 + Math.trunc(Math.ceil(Math.log(this.getScale()) / Math.log(10)));
  6526. }
  6527. return maxSigDigits
  6528. };
  6529. PrecisionModel.prototype.setScale = function setScale (scale) {
  6530. this._scale = Math.abs(scale);
  6531. };
  6532. PrecisionModel.prototype.interfaces_ = function interfaces_ () {
  6533. return [Serializable, Comparable]
  6534. };
  6535. PrecisionModel.prototype.getClass = function getClass () {
  6536. return PrecisionModel
  6537. };
  6538. PrecisionModel.mostPrecise = function mostPrecise (pm1, pm2) {
  6539. if (pm1.compareTo(pm2) >= 0) { return pm1 }
  6540. return pm2
  6541. };
  6542. staticAccessors$19.serialVersionUID.get = function () { return 7777263578777803835 };
  6543. staticAccessors$19.maximumPreciseValue.get = function () { return 9007199254740992.0 };
  6544. Object.defineProperties( PrecisionModel, staticAccessors$19 );
  6545. var Type = function Type (name) {
  6546. this._name = name || null;
  6547. Type.nameToTypeMap.put(name, this);
  6548. };
  6549. var staticAccessors$1$1 = { serialVersionUID: { configurable: true },nameToTypeMap: { configurable: true } };
  6550. Type.prototype.readResolve = function readResolve () {
  6551. return Type.nameToTypeMap.get(this._name)
  6552. };
  6553. Type.prototype.toString = function toString () {
  6554. return this._name
  6555. };
  6556. Type.prototype.interfaces_ = function interfaces_ () {
  6557. return [Serializable]
  6558. };
  6559. Type.prototype.getClass = function getClass () {
  6560. return Type
  6561. };
  6562. staticAccessors$1$1.serialVersionUID.get = function () { return -5528602631731589822 };
  6563. staticAccessors$1$1.nameToTypeMap.get = function () { return new HashMap() };
  6564. Object.defineProperties( Type, staticAccessors$1$1 );
  6565. PrecisionModel.Type = Type;
  6566. PrecisionModel.FIXED = new Type('FIXED');
  6567. PrecisionModel.FLOATING = new Type('FLOATING');
  6568. PrecisionModel.FLOATING_SINGLE = new Type('FLOATING SINGLE');
  6569. var GeometryFactory = function GeometryFactory () {
  6570. this._precisionModel = new PrecisionModel();
  6571. this._SRID = 0;
  6572. this._coordinateSequenceFactory = GeometryFactory.getDefaultCoordinateSequenceFactory();
  6573. if (arguments.length === 0) {
  6574. } else if (arguments.length === 1) {
  6575. if (hasInterface(arguments[0], CoordinateSequenceFactory)) {
  6576. this._coordinateSequenceFactory = arguments[0];
  6577. } else if (arguments[0] instanceof PrecisionModel) {
  6578. this._precisionModel = arguments[0];
  6579. }
  6580. } else if (arguments.length === 2) {
  6581. this._precisionModel = arguments[0];
  6582. this._SRID = arguments[1];
  6583. } else if (arguments.length === 3) {
  6584. this._precisionModel = arguments[0];
  6585. this._SRID = arguments[1];
  6586. this._coordinateSequenceFactory = arguments[2];
  6587. }
  6588. };
  6589. var staticAccessors$2 = { serialVersionUID: { configurable: true } };
  6590. GeometryFactory.prototype.toGeometry = function toGeometry (envelope) {
  6591. if (envelope.isNull()) {
  6592. return this.createPoint(null)
  6593. }
  6594. if (envelope.getMinX() === envelope.getMaxX() && envelope.getMinY() === envelope.getMaxY()) {
  6595. return this.createPoint(new Coordinate(envelope.getMinX(), envelope.getMinY()))
  6596. }
  6597. if (envelope.getMinX() === envelope.getMaxX() || envelope.getMinY() === envelope.getMaxY()) {
  6598. return this.createLineString([new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY())])
  6599. }
  6600. return this.createPolygon(this.createLinearRing([new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMinX(), envelope.getMaxY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY()), new Coordinate(envelope.getMaxX(), envelope.getMinY()), new Coordinate(envelope.getMinX(), envelope.getMinY())]), null)
  6601. };
  6602. GeometryFactory.prototype.createLineString = function createLineString (coordinates) {
  6603. if (!coordinates) { return new LineString(this.getCoordinateSequenceFactory().create([]), this) }
  6604. else if (coordinates instanceof Array) { return new LineString(this.getCoordinateSequenceFactory().create(coordinates), this) }
  6605. else if (hasInterface(coordinates, CoordinateSequence)) { return new LineString(coordinates, this) }
  6606. };
  6607. GeometryFactory.prototype.createMultiLineString = function createMultiLineString () {
  6608. if (arguments.length === 0) {
  6609. return new MultiLineString(null, this)
  6610. } else if (arguments.length === 1) {
  6611. var lineStrings = arguments[0];
  6612. return new MultiLineString(lineStrings, this)
  6613. }
  6614. };
  6615. GeometryFactory.prototype.buildGeometry = function buildGeometry (geomList) {
  6616. var geomClass = null;
  6617. var isHeterogeneous = false;
  6618. var hasGeometryCollection = false;
  6619. for (var i = geomList.iterator(); i.hasNext();) {
  6620. var geom = i.next();
  6621. var partClass = geom.getClass();
  6622. if (geomClass === null) {
  6623. geomClass = partClass;
  6624. }
  6625. if (partClass !== geomClass) {
  6626. isHeterogeneous = true;
  6627. }
  6628. if (geom.isGeometryCollectionOrDerived()) { hasGeometryCollection = true; }
  6629. }
  6630. if (geomClass === null) {
  6631. return this.createGeometryCollection()
  6632. }
  6633. if (isHeterogeneous || hasGeometryCollection) {
  6634. return this.createGeometryCollection(GeometryFactory.toGeometryArray(geomList))
  6635. }
  6636. var geom0 = geomList.iterator().next();
  6637. var isCollection = geomList.size() > 1;
  6638. if (isCollection) {
  6639. if (geom0 instanceof Polygon) {
  6640. return this.createMultiPolygon(GeometryFactory.toPolygonArray(geomList))
  6641. } else if (geom0 instanceof LineString) {
  6642. return this.createMultiLineString(GeometryFactory.toLineStringArray(geomList))
  6643. } else if (geom0 instanceof Point) {
  6644. return this.createMultiPoint(GeometryFactory.toPointArray(geomList))
  6645. }
  6646. Assert.shouldNeverReachHere('Unhandled class: ' + geom0.getClass().getName());
  6647. }
  6648. return geom0
  6649. };
  6650. GeometryFactory.prototype.createMultiPointFromCoords = function createMultiPointFromCoords (coordinates) {
  6651. return this.createMultiPoint(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)
  6652. };
  6653. GeometryFactory.prototype.createPoint = function createPoint () {
  6654. if (arguments.length === 0) {
  6655. return this.createPoint(this.getCoordinateSequenceFactory().create([]))
  6656. } else if (arguments.length === 1) {
  6657. if (arguments[0] instanceof Coordinate) {
  6658. var coordinate = arguments[0];
  6659. return this.createPoint(coordinate !== null ? this.getCoordinateSequenceFactory().create([coordinate]) : null)
  6660. } else if (hasInterface(arguments[0], CoordinateSequence)) {
  6661. var coordinates = arguments[0];
  6662. return new Point(coordinates, this)
  6663. }
  6664. }
  6665. };
  6666. GeometryFactory.prototype.getCoordinateSequenceFactory = function getCoordinateSequenceFactory () {
  6667. return this._coordinateSequenceFactory
  6668. };
  6669. GeometryFactory.prototype.createPolygon = function createPolygon () {
  6670. if (arguments.length === 0) {
  6671. return new Polygon(null, null, this)
  6672. } else if (arguments.length === 1) {
  6673. if (hasInterface(arguments[0], CoordinateSequence)) {
  6674. var coordinates = arguments[0];
  6675. return this.createPolygon(this.createLinearRing(coordinates))
  6676. } else if (arguments[0] instanceof Array) {
  6677. var coordinates$1 = arguments[0];
  6678. return this.createPolygon(this.createLinearRing(coordinates$1))
  6679. } else if (arguments[0] instanceof LinearRing) {
  6680. var shell = arguments[0];
  6681. return this.createPolygon(shell, null)
  6682. }
  6683. } else if (arguments.length === 2) {
  6684. var shell$1 = arguments[0];
  6685. var holes = arguments[1];
  6686. return new Polygon(shell$1, holes, this)
  6687. }
  6688. };
  6689. GeometryFactory.prototype.getSRID = function getSRID () {
  6690. return this._SRID
  6691. };
  6692. GeometryFactory.prototype.createGeometryCollection = function createGeometryCollection () {
  6693. if (arguments.length === 0) {
  6694. return new GeometryCollection(null, this)
  6695. } else if (arguments.length === 1) {
  6696. var geometries = arguments[0];
  6697. return new GeometryCollection(geometries, this)
  6698. }
  6699. };
  6700. GeometryFactory.prototype.createGeometry = function createGeometry (g) {
  6701. var editor = new GeometryEditor(this);
  6702. return editor.edit(g, {
  6703. edit: function () {
  6704. if (arguments.length === 2) {
  6705. var coordSeq = arguments[0];
  6706. // const geometry = arguments[1]
  6707. return this._coordinateSequenceFactory.create(coordSeq)
  6708. }
  6709. }
  6710. })
  6711. };
  6712. GeometryFactory.prototype.getPrecisionModel = function getPrecisionModel () {
  6713. return this._precisionModel
  6714. };
  6715. GeometryFactory.prototype.createLinearRing = function createLinearRing () {
  6716. if (arguments.length === 0) {
  6717. return this.createLinearRing(this.getCoordinateSequenceFactory().create([]))
  6718. } else if (arguments.length === 1) {
  6719. if (arguments[0] instanceof Array) {
  6720. var coordinates = arguments[0];
  6721. return this.createLinearRing(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)
  6722. } else if (hasInterface(arguments[0], CoordinateSequence)) {
  6723. var coordinates$1 = arguments[0];
  6724. return new LinearRing(coordinates$1, this)
  6725. }
  6726. }
  6727. };
  6728. GeometryFactory.prototype.createMultiPolygon = function createMultiPolygon () {
  6729. if (arguments.length === 0) {
  6730. return new MultiPolygon(null, this)
  6731. } else if (arguments.length === 1) {
  6732. var polygons = arguments[0];
  6733. return new MultiPolygon(polygons, this)
  6734. }
  6735. };
  6736. GeometryFactory.prototype.createMultiPoint = function createMultiPoint () {
  6737. var this$1 = this;
  6738. if (arguments.length === 0) {
  6739. return new MultiPoint(null, this)
  6740. } else if (arguments.length === 1) {
  6741. if (arguments[0] instanceof Array) {
  6742. var point = arguments[0];
  6743. return new MultiPoint(point, this)
  6744. } else if (arguments[0] instanceof Array) {
  6745. var coordinates = arguments[0];
  6746. return this.createMultiPoint(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)
  6747. } else if (hasInterface(arguments[0], CoordinateSequence)) {
  6748. var coordinates$1 = arguments[0];
  6749. if (coordinates$1 === null) {
  6750. return this.createMultiPoint(new Array(0).fill(null))
  6751. }
  6752. var points = new Array(coordinates$1.size()).fill(null);
  6753. for (var i = 0; i < coordinates$1.size(); i++) {
  6754. var ptSeq = this$1.getCoordinateSequenceFactory().create(1, coordinates$1.getDimension());
  6755. CoordinateSequences.copy(coordinates$1, i, ptSeq, 0, 1);
  6756. points[i] = this$1.createPoint(ptSeq);
  6757. }
  6758. return this.createMultiPoint(points)
  6759. }
  6760. }
  6761. };
  6762. GeometryFactory.prototype.interfaces_ = function interfaces_ () {
  6763. return [Serializable]
  6764. };
  6765. GeometryFactory.prototype.getClass = function getClass () {
  6766. return GeometryFactory
  6767. };
  6768. GeometryFactory.toMultiPolygonArray = function toMultiPolygonArray (multiPolygons) {
  6769. var multiPolygonArray = new Array(multiPolygons.size()).fill(null);
  6770. return multiPolygons.toArray(multiPolygonArray)
  6771. };
  6772. GeometryFactory.toGeometryArray = function toGeometryArray (geometries) {
  6773. if (geometries === null) { return null }
  6774. var geometryArray = new Array(geometries.size()).fill(null);
  6775. return geometries.toArray(geometryArray)
  6776. };
  6777. GeometryFactory.getDefaultCoordinateSequenceFactory = function getDefaultCoordinateSequenceFactory () {
  6778. return CoordinateArraySequenceFactory.instance()
  6779. };
  6780. GeometryFactory.toMultiLineStringArray = function toMultiLineStringArray (multiLineStrings) {
  6781. var multiLineStringArray = new Array(multiLineStrings.size()).fill(null);
  6782. return multiLineStrings.toArray(multiLineStringArray)
  6783. };
  6784. GeometryFactory.toLineStringArray = function toLineStringArray (lineStrings) {
  6785. var lineStringArray = new Array(lineStrings.size()).fill(null);
  6786. return lineStrings.toArray(lineStringArray)
  6787. };
  6788. GeometryFactory.toMultiPointArray = function toMultiPointArray (multiPoints) {
  6789. var multiPointArray = new Array(multiPoints.size()).fill(null);
  6790. return multiPoints.toArray(multiPointArray)
  6791. };
  6792. GeometryFactory.toLinearRingArray = function toLinearRingArray (linearRings) {
  6793. var linearRingArray = new Array(linearRings.size()).fill(null);
  6794. return linearRings.toArray(linearRingArray)
  6795. };
  6796. GeometryFactory.toPointArray = function toPointArray (points) {
  6797. var pointArray = new Array(points.size()).fill(null);
  6798. return points.toArray(pointArray)
  6799. };
  6800. GeometryFactory.toPolygonArray = function toPolygonArray (polygons) {
  6801. var polygonArray = new Array(polygons.size()).fill(null);
  6802. return polygons.toArray(polygonArray)
  6803. };
  6804. GeometryFactory.createPointFromInternalCoord = function createPointFromInternalCoord (coord, exemplar) {
  6805. exemplar.getPrecisionModel().makePrecise(coord);
  6806. return exemplar.getFactory().createPoint(coord)
  6807. };
  6808. staticAccessors$2.serialVersionUID.get = function () { return -6820524753094095635 };
  6809. Object.defineProperties( GeometryFactory, staticAccessors$2 );
  6810. var geometryTypes = ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon'];
  6811. /**
  6812. * Class for reading and writing Well-Known Text.Create a new parser for GeoJSON
  6813. * NOTE: Adapted from OpenLayers 2.11 implementation.
  6814. */
  6815. /**
  6816. * Create a new parser for GeoJSON
  6817. *
  6818. * @param {GeometryFactory} geometryFactory
  6819. * @return An instance of GeoJsonParser.
  6820. * @constructor
  6821. * @private
  6822. */
  6823. var GeoJSONParser = function GeoJSONParser (geometryFactory) {
  6824. this.geometryFactory = geometryFactory || new GeometryFactory();
  6825. };
  6826. /**
  6827. * Deserialize a GeoJSON object and return the Geometry or Feature(Collection) with JSTS Geometries
  6828. *
  6829. * @param {}
  6830. * A GeoJSON object.
  6831. * @return {} A Geometry instance or object representing a Feature(Collection) with Geometry instances.
  6832. * @private
  6833. */
  6834. GeoJSONParser.prototype.read = function read (json) {
  6835. var obj;
  6836. if (typeof json === 'string') {
  6837. obj = JSON.parse(json);
  6838. } else {
  6839. obj = json;
  6840. }
  6841. var type = obj.type;
  6842. if (!parse[type]) {
  6843. throw new Error('Unknown GeoJSON type: ' + obj.type)
  6844. }
  6845. if (geometryTypes.indexOf(type) !== -1) {
  6846. return parse[type].apply(this, [obj.coordinates])
  6847. } else if (type === 'GeometryCollection') {
  6848. return parse[type].apply(this, [obj.geometries])
  6849. }
  6850. // feature or feature collection
  6851. return parse[type].apply(this, [obj])
  6852. };
  6853. /**
  6854. * Serialize a Geometry object into GeoJSON
  6855. *
  6856. * @param {Geometry}
  6857. * geometry A Geometry or array of Geometries.
  6858. * @return {Object} A GeoJSON object represting the input Geometry/Geometries.
  6859. * @private
  6860. */
  6861. GeoJSONParser.prototype.write = function write (geometry) {
  6862. var type = geometry.getGeometryType();
  6863. if (!extract[type]) {
  6864. throw new Error('Geometry is not supported')
  6865. }
  6866. return extract[type].apply(this, [geometry])
  6867. };
  6868. var parse = {
  6869. /**
  6870. * Parse a GeoJSON Feature object
  6871. *
  6872. * @param {Object}
  6873. * obj Object to parse.
  6874. *
  6875. * @return {Object} Feature with geometry/bbox converted to JSTS Geometries.
  6876. */
  6877. Feature: function (obj) {
  6878. var feature = {};
  6879. // copy features
  6880. for (var key in obj) {
  6881. feature[key] = obj[key];
  6882. }
  6883. // parse geometry
  6884. if (obj.geometry) {
  6885. var type = obj.geometry.type;
  6886. if (!parse[type]) {
  6887. throw new Error('Unknown GeoJSON type: ' + obj.type)
  6888. }
  6889. feature.geometry = this.read(obj.geometry);
  6890. }
  6891. // bbox
  6892. if (obj.bbox) {
  6893. feature.bbox = parse.bbox.apply(this, [obj.bbox]);
  6894. }
  6895. return feature
  6896. },
  6897. /**
  6898. * Parse a GeoJSON FeatureCollection object
  6899. *
  6900. * @param {Object}
  6901. * obj Object to parse.
  6902. *
  6903. * @return {Object} FeatureCollection with geometry/bbox converted to JSTS Geometries.
  6904. */
  6905. FeatureCollection: function (obj) {
  6906. var this$1 = this;
  6907. var featureCollection = {};
  6908. if (obj.features) {
  6909. featureCollection.features = [];
  6910. for (var i = 0; i < obj.features.length; ++i) {
  6911. featureCollection.features.push(this$1.read(obj.features[i]));
  6912. }
  6913. }
  6914. if (obj.bbox) {
  6915. featureCollection.bbox = this.parse.bbox.apply(this, [obj.bbox]);
  6916. }
  6917. return featureCollection
  6918. },
  6919. /**
  6920. * Convert the ordinates in an array to an array of Coordinates
  6921. *
  6922. * @param {Array}
  6923. * array Array with {Number}s.
  6924. *
  6925. * @return {Array} Array with Coordinates.
  6926. */
  6927. coordinates: function (array) {
  6928. var coordinates = [];
  6929. for (var i = 0; i < array.length; ++i) {
  6930. var sub = array[i];
  6931. coordinates.push(new Coordinate(sub[0], sub[1]));
  6932. }
  6933. return coordinates
  6934. },
  6935. /**
  6936. * Convert the bbox to a LinearRing
  6937. *
  6938. * @param {Array}
  6939. * array Array with [xMin, yMin, xMax, yMax].
  6940. *
  6941. * @return {Array} Array with Coordinates.
  6942. */
  6943. bbox: function (array) {
  6944. return this.geometryFactory.createLinearRing([
  6945. new Coordinate(array[0], array[1]),
  6946. new Coordinate(array[2], array[1]),
  6947. new Coordinate(array[2], array[3]),
  6948. new Coordinate(array[0], array[3]),
  6949. new Coordinate(array[0], array[1])
  6950. ])
  6951. },
  6952. /**
  6953. * Convert an Array with ordinates to a Point
  6954. *
  6955. * @param {Array}
  6956. * array Array with ordinates.
  6957. *
  6958. * @return {Point} Point.
  6959. */
  6960. Point: function (array) {
  6961. var coordinate = new Coordinate(array[0], array[1]);
  6962. return this.geometryFactory.createPoint(coordinate)
  6963. },
  6964. /**
  6965. * Convert an Array with coordinates to a MultiPoint
  6966. *
  6967. * @param {Array}
  6968. * array Array with coordinates.
  6969. *
  6970. * @return {MultiPoint} MultiPoint.
  6971. */
  6972. MultiPoint: function (array) {
  6973. var this$1 = this;
  6974. var points = [];
  6975. for (var i = 0; i < array.length; ++i) {
  6976. points.push(parse.Point.apply(this$1, [array[i]]));
  6977. }
  6978. return this.geometryFactory.createMultiPoint(points)
  6979. },
  6980. /**
  6981. * Convert an Array with coordinates to a LineString
  6982. *
  6983. * @param {Array}
  6984. * array Array with coordinates.
  6985. *
  6986. * @return {LineString} LineString.
  6987. */
  6988. LineString: function (array) {
  6989. var coordinates = parse.coordinates.apply(this, [array]);
  6990. return this.geometryFactory.createLineString(coordinates)
  6991. },
  6992. /**
  6993. * Convert an Array with coordinates to a MultiLineString
  6994. *
  6995. * @param {Array}
  6996. * array Array with coordinates.
  6997. *
  6998. * @return {MultiLineString} MultiLineString.
  6999. */
  7000. MultiLineString: function (array) {
  7001. var this$1 = this;
  7002. var lineStrings = [];
  7003. for (var i = 0; i < array.length; ++i) {
  7004. lineStrings.push(parse.LineString.apply(this$1, [array[i]]));
  7005. }
  7006. return this.geometryFactory.createMultiLineString(lineStrings)
  7007. },
  7008. /**
  7009. * Convert an Array to a Polygon
  7010. *
  7011. * @param {Array}
  7012. * array Array with shell and holes.
  7013. *
  7014. * @return {Polygon} Polygon.
  7015. */
  7016. Polygon: function (array) {
  7017. var this$1 = this;
  7018. var shellCoordinates = parse.coordinates.apply(this, [array[0]]);
  7019. var shell = this.geometryFactory.createLinearRing(shellCoordinates);
  7020. var holes = [];
  7021. for (var i = 1; i < array.length; ++i) {
  7022. var hole = array[i];
  7023. var coordinates = parse.coordinates.apply(this$1, [hole]);
  7024. var linearRing = this$1.geometryFactory.createLinearRing(coordinates);
  7025. holes.push(linearRing);
  7026. }
  7027. return this.geometryFactory.createPolygon(shell, holes)
  7028. },
  7029. /**
  7030. * Convert an Array to a MultiPolygon
  7031. *
  7032. * @param {Array}
  7033. * array Array of arrays with shell and rings.
  7034. *
  7035. * @return {MultiPolygon} MultiPolygon.
  7036. */
  7037. MultiPolygon: function (array) {
  7038. var this$1 = this;
  7039. var polygons = [];
  7040. for (var i = 0; i < array.length; ++i) {
  7041. var polygon = array[i];
  7042. polygons.push(parse.Polygon.apply(this$1, [polygon]));
  7043. }
  7044. return this.geometryFactory.createMultiPolygon(polygons)
  7045. },
  7046. /**
  7047. * Convert an Array to a GeometryCollection
  7048. *
  7049. * @param {Array}
  7050. * array Array of GeoJSON geometries.
  7051. *
  7052. * @return {GeometryCollection} GeometryCollection.
  7053. */
  7054. GeometryCollection: function (array) {
  7055. var this$1 = this;
  7056. var geometries = [];
  7057. for (var i = 0; i < array.length; ++i) {
  7058. var geometry = array[i];
  7059. geometries.push(this$1.read(geometry));
  7060. }
  7061. return this.geometryFactory.createGeometryCollection(geometries)
  7062. }
  7063. };
  7064. var extract = {
  7065. /**
  7066. * Convert a Coordinate to an Array
  7067. *
  7068. * @param {Coordinate}
  7069. * coordinate Coordinate to convert.
  7070. *
  7071. * @return {Array} Array of ordinates.
  7072. */
  7073. coordinate: function (coordinate) {
  7074. return [coordinate.x, coordinate.y]
  7075. },
  7076. /**
  7077. * Convert a Point to a GeoJSON object
  7078. *
  7079. * @param {Point}
  7080. * point Point to convert.
  7081. *
  7082. * @return {Array} Array of 2 ordinates (paired to a coordinate).
  7083. */
  7084. Point: function (point) {
  7085. var array = extract.coordinate.apply(this, [point.getCoordinate()]);
  7086. return {
  7087. type: 'Point',
  7088. coordinates: array
  7089. }
  7090. },
  7091. /**
  7092. * Convert a MultiPoint to a GeoJSON object
  7093. *
  7094. * @param {MultiPoint}
  7095. * multipoint MultiPoint to convert.
  7096. *
  7097. * @return {Array} Array of coordinates.
  7098. */
  7099. MultiPoint: function (multipoint) {
  7100. var this$1 = this;
  7101. var array = [];
  7102. for (var i = 0; i < multipoint._geometries.length; ++i) {
  7103. var point = multipoint._geometries[i];
  7104. var geoJson = extract.Point.apply(this$1, [point]);
  7105. array.push(geoJson.coordinates);
  7106. }
  7107. return {
  7108. type: 'MultiPoint',
  7109. coordinates: array
  7110. }
  7111. },
  7112. /**
  7113. * Convert a LineString to a GeoJSON object
  7114. *
  7115. * @param {LineString}
  7116. * linestring LineString to convert.
  7117. *
  7118. * @return {Array} Array of coordinates.
  7119. */
  7120. LineString: function (linestring) {
  7121. var this$1 = this;
  7122. var array = [];
  7123. var coordinates = linestring.getCoordinates();
  7124. for (var i = 0; i < coordinates.length; ++i) {
  7125. var coordinate = coordinates[i];
  7126. array.push(extract.coordinate.apply(this$1, [coordinate]));
  7127. }
  7128. return {
  7129. type: 'LineString',
  7130. coordinates: array
  7131. }
  7132. },
  7133. /**
  7134. * Convert a MultiLineString to a GeoJSON object
  7135. *
  7136. * @param {MultiLineString}
  7137. * multilinestring MultiLineString to convert.
  7138. *
  7139. * @return {Array} Array of Array of coordinates.
  7140. */
  7141. MultiLineString: function (multilinestring) {
  7142. var this$1 = this;
  7143. var array = [];
  7144. for (var i = 0; i < multilinestring._geometries.length; ++i) {
  7145. var linestring = multilinestring._geometries[i];
  7146. var geoJson = extract.LineString.apply(this$1, [linestring]);
  7147. array.push(geoJson.coordinates);
  7148. }
  7149. return {
  7150. type: 'MultiLineString',
  7151. coordinates: array
  7152. }
  7153. },
  7154. /**
  7155. * Convert a Polygon to a GeoJSON object
  7156. *
  7157. * @param {Polygon}
  7158. * polygon Polygon to convert.
  7159. *
  7160. * @return {Array} Array with shell, holes.
  7161. */
  7162. Polygon: function (polygon) {
  7163. var this$1 = this;
  7164. var array = [];
  7165. var shellGeoJson = extract.LineString.apply(this, [polygon._shell]);
  7166. array.push(shellGeoJson.coordinates);
  7167. for (var i = 0; i < polygon._holes.length; ++i) {
  7168. var hole = polygon._holes[i];
  7169. var holeGeoJson = extract.LineString.apply(this$1, [hole]);
  7170. array.push(holeGeoJson.coordinates);
  7171. }
  7172. return {
  7173. type: 'Polygon',
  7174. coordinates: array
  7175. }
  7176. },
  7177. /**
  7178. * Convert a MultiPolygon to a GeoJSON object
  7179. *
  7180. * @param {MultiPolygon}
  7181. * multipolygon MultiPolygon to convert.
  7182. *
  7183. * @return {Array} Array of polygons.
  7184. */
  7185. MultiPolygon: function (multipolygon) {
  7186. var this$1 = this;
  7187. var array = [];
  7188. for (var i = 0; i < multipolygon._geometries.length; ++i) {
  7189. var polygon = multipolygon._geometries[i];
  7190. var geoJson = extract.Polygon.apply(this$1, [polygon]);
  7191. array.push(geoJson.coordinates);
  7192. }
  7193. return {
  7194. type: 'MultiPolygon',
  7195. coordinates: array
  7196. }
  7197. },
  7198. /**
  7199. * Convert a GeometryCollection to a GeoJSON object
  7200. *
  7201. * @param {GeometryCollection}
  7202. * collection GeometryCollection to convert.
  7203. *
  7204. * @return {Array} Array of geometries.
  7205. */
  7206. GeometryCollection: function (collection) {
  7207. var this$1 = this;
  7208. var array = [];
  7209. for (var i = 0; i < collection._geometries.length; ++i) {
  7210. var geometry = collection._geometries[i];
  7211. var type = geometry.getGeometryType();
  7212. array.push(extract[type].apply(this$1, [geometry]));
  7213. }
  7214. return {
  7215. type: 'GeometryCollection',
  7216. geometries: array
  7217. }
  7218. }
  7219. };
  7220. /**
  7221. * Converts a geometry in GeoJSON to a {@link Geometry}.
  7222. */
  7223. /**
  7224. * A <code>GeoJSONReader</code> is parameterized by a <code>GeometryFactory</code>,
  7225. * to allow it to create <code>Geometry</code> objects of the appropriate
  7226. * implementation. In particular, the <code>GeometryFactory</code> determines
  7227. * the <code>PrecisionModel</code> and <code>SRID</code> that is used.
  7228. *
  7229. * @param {GeometryFactory} geometryFactory
  7230. * @constructor
  7231. */
  7232. var GeoJSONReader = function GeoJSONReader (geometryFactory) {
  7233. this.geometryFactory = geometryFactory || new GeometryFactory();
  7234. this.precisionModel = this.geometryFactory.getPrecisionModel();
  7235. this.parser = new GeoJSONParser(this.geometryFactory);
  7236. };
  7237. /**
  7238. * Reads a GeoJSON representation of a {@link Geometry}
  7239. *
  7240. * Will also parse GeoJSON Features/FeatureCollections as custom objects.
  7241. *
  7242. * @param {Object|String} geoJson a GeoJSON Object or String.
  7243. * @return {Geometry|Object} a <code>Geometry or Feature/FeatureCollection representation.</code>
  7244. * @memberof GeoJSONReader
  7245. */
  7246. GeoJSONReader.prototype.read = function read (geoJson) {
  7247. var geometry = this.parser.read(geoJson);
  7248. if (this.precisionModel.getType() === PrecisionModel.FIXED) {
  7249. this.reducePrecision(geometry);
  7250. }
  7251. return geometry
  7252. };
  7253. // NOTE: this is a hack
  7254. GeoJSONReader.prototype.reducePrecision = function reducePrecision (geometry) {
  7255. var this$1 = this;
  7256. var i, len;
  7257. if (geometry.coordinate) {
  7258. this.precisionModel.makePrecise(geometry.coordinate);
  7259. } else if (geometry.points) {
  7260. for (i = 0, len = geometry.points.length; i < len; i++) {
  7261. this$1.precisionModel.makePrecise(geometry.points[i]);
  7262. }
  7263. } else if (geometry.geometries) {
  7264. for (i = 0, len = geometry.geometries.length; i < len; i++) {
  7265. this$1.reducePrecision(geometry.geometries[i]);
  7266. }
  7267. }
  7268. };
  7269. /**
  7270. * @module GeoJSONWriter
  7271. */
  7272. /**
  7273. * Writes the GeoJSON representation of a {@link Geometry}. The
  7274. * The GeoJSON format is defined <A
  7275. * HREF="http://geojson.org/geojson-spec.html">here</A>.
  7276. */
  7277. /**
  7278. * The <code>GeoJSONWriter</code> outputs coordinates rounded to the precision
  7279. * model. Only the maximum number of decimal places necessary to represent the
  7280. * ordinates to the required precision will be output.
  7281. *
  7282. * @param {GeometryFactory} geometryFactory
  7283. * @constructor
  7284. */
  7285. var GeoJSONWriter = function GeoJSONWriter () {
  7286. this.parser = new GeoJSONParser(this.geometryFactory);
  7287. };
  7288. /**
  7289. * Converts a <code>Geometry</code> to its GeoJSON representation.
  7290. *
  7291. * @param {Geometry}
  7292. * geometry a <code>Geometry</code> to process.
  7293. * @return {Object} The GeoJSON representation of the Geometry.
  7294. * @memberof GeoJSONWriter
  7295. */
  7296. GeoJSONWriter.prototype.write = function write (geometry) {
  7297. return this.parser.write(geometry)
  7298. };
  7299. /* eslint-disable no-undef */
  7300. // io
  7301. var Position = function Position () {};
  7302. var staticAccessors$20 = { ON: { configurable: true },LEFT: { configurable: true },RIGHT: { configurable: true } };
  7303. Position.prototype.interfaces_ = function interfaces_ () {
  7304. return []
  7305. };
  7306. Position.prototype.getClass = function getClass () {
  7307. return Position
  7308. };
  7309. Position.opposite = function opposite (position) {
  7310. if (position === Position.LEFT) { return Position.RIGHT }
  7311. if (position === Position.RIGHT) { return Position.LEFT }
  7312. return position
  7313. };
  7314. staticAccessors$20.ON.get = function () { return 0 };
  7315. staticAccessors$20.LEFT.get = function () { return 1 };
  7316. staticAccessors$20.RIGHT.get = function () { return 2 };
  7317. Object.defineProperties( Position, staticAccessors$20 );
  7318. /**
  7319. * @param {string=} message Optional message
  7320. * @extends {Error}
  7321. * @constructor
  7322. * @private
  7323. */
  7324. function EmptyStackException (message) {
  7325. this.message = message || '';
  7326. }
  7327. EmptyStackException.prototype = new Error();
  7328. /**
  7329. * @type {string}
  7330. */
  7331. EmptyStackException.prototype.name = 'EmptyStackException';
  7332. /**
  7333. * @see http://download.oracle.com/javase/6/docs/api/java/util/Stack.html
  7334. *
  7335. * @extends {List}
  7336. * @constructor
  7337. * @private
  7338. */
  7339. function Stack () {
  7340. /**
  7341. * @type {Array}
  7342. * @private
  7343. */
  7344. this.array_ = [];
  7345. }
  7346. Stack.prototype = new List();
  7347. /**
  7348. * @override
  7349. */
  7350. Stack.prototype.add = function (e) {
  7351. this.array_.push(e);
  7352. return true
  7353. };
  7354. /**
  7355. * @override
  7356. */
  7357. Stack.prototype.get = function (index) {
  7358. if (index < 0 || index >= this.size()) {
  7359. throw new Error()
  7360. }
  7361. return this.array_[index]
  7362. };
  7363. /**
  7364. * Pushes an item onto the top of this stack.
  7365. * @param {Object} e
  7366. * @return {Object}
  7367. */
  7368. Stack.prototype.push = function (e) {
  7369. this.array_.push(e);
  7370. return e
  7371. };
  7372. /**
  7373. * Pushes an item onto the top of this stack.
  7374. * @param {Object} e
  7375. * @return {Object}
  7376. */
  7377. Stack.prototype.pop = function (e) {
  7378. if (this.array_.length === 0) {
  7379. throw new EmptyStackException()
  7380. }
  7381. return this.array_.pop()
  7382. };
  7383. /**
  7384. * Looks at the object at the top of this stack without removing it from the
  7385. * stack.
  7386. * @return {Object}
  7387. */
  7388. Stack.prototype.peek = function () {
  7389. if (this.array_.length === 0) {
  7390. throw new EmptyStackException()
  7391. }
  7392. return this.array_[this.array_.length - 1]
  7393. };
  7394. /**
  7395. * Tests if this stack is empty.
  7396. * @return {boolean} true if and only if this stack contains no items; false
  7397. * otherwise.
  7398. */
  7399. Stack.prototype.empty = function () {
  7400. if (this.array_.length === 0) {
  7401. return true
  7402. } else {
  7403. return false
  7404. }
  7405. };
  7406. /**
  7407. * @return {boolean}
  7408. */
  7409. Stack.prototype.isEmpty = function () {
  7410. return this.empty()
  7411. };
  7412. /**
  7413. * Returns the 1-based position where an object is on this stack. If the object
  7414. * o occurs as an item in this stack, this method returns the distance from the
  7415. * top of the stack of the occurrence nearest the top of the stack; the topmost
  7416. * item on the stack is considered to be at distance 1. The equals method is
  7417. * used to compare o to the items in this stack.
  7418. *
  7419. * NOTE: does not currently actually use equals. (=== is used)
  7420. *
  7421. * @param {Object} o
  7422. * @return {number} the 1-based position from the top of the stack where the
  7423. * object is located; the return value -1 indicates that the object is
  7424. * not on the stack.
  7425. */
  7426. Stack.prototype.search = function (o) {
  7427. return this.array_.indexOf(o)
  7428. };
  7429. /**
  7430. * @return {number}
  7431. * @export
  7432. */
  7433. Stack.prototype.size = function () {
  7434. return this.array_.length
  7435. };
  7436. /**
  7437. * @return {Array}
  7438. */
  7439. Stack.prototype.toArray = function () {
  7440. var this$1 = this;
  7441. var array = [];
  7442. for (var i = 0, len = this.array_.length; i < len; i++) {
  7443. array.push(this$1.array_[i]);
  7444. }
  7445. return array
  7446. };
  7447. var RightmostEdgeFinder = function RightmostEdgeFinder () {
  7448. this._minIndex = -1;
  7449. this._minCoord = null;
  7450. this._minDe = null;
  7451. this._orientedDe = null;
  7452. };
  7453. RightmostEdgeFinder.prototype.getCoordinate = function getCoordinate () {
  7454. return this._minCoord
  7455. };
  7456. RightmostEdgeFinder.prototype.getRightmostSide = function getRightmostSide (de, index) {
  7457. var side = this.getRightmostSideOfSegment(de, index);
  7458. if (side < 0) { side = this.getRightmostSideOfSegment(de, index - 1); }
  7459. if (side < 0) {
  7460. this._minCoord = null;
  7461. this.checkForRightmostCoordinate(de);
  7462. }
  7463. return side
  7464. };
  7465. RightmostEdgeFinder.prototype.findRightmostEdgeAtVertex = function findRightmostEdgeAtVertex () {
  7466. var pts = this._minDe.getEdge().getCoordinates();
  7467. Assert.isTrue(this._minIndex > 0 && this._minIndex < pts.length, 'rightmost point expected to be interior vertex of edge');
  7468. var pPrev = pts[this._minIndex - 1];
  7469. var pNext = pts[this._minIndex + 1];
  7470. var orientation = CGAlgorithms.computeOrientation(this._minCoord, pNext, pPrev);
  7471. var usePrev = false;
  7472. if (pPrev.y < this._minCoord.y && pNext.y < this._minCoord.y && orientation === CGAlgorithms.COUNTERCLOCKWISE) {
  7473. usePrev = true;
  7474. } else if (pPrev.y > this._minCoord.y && pNext.y > this._minCoord.y && orientation === CGAlgorithms.CLOCKWISE) {
  7475. usePrev = true;
  7476. }
  7477. if (usePrev) {
  7478. this._minIndex = this._minIndex - 1;
  7479. }
  7480. };
  7481. RightmostEdgeFinder.prototype.getRightmostSideOfSegment = function getRightmostSideOfSegment (de, i) {
  7482. var e = de.getEdge();
  7483. var coord = e.getCoordinates();
  7484. if (i < 0 || i + 1 >= coord.length) { return -1 }
  7485. if (coord[i].y === coord[i + 1].y) { return -1 }
  7486. var pos = Position.LEFT;
  7487. if (coord[i].y < coord[i + 1].y) { pos = Position.RIGHT; }
  7488. return pos
  7489. };
  7490. RightmostEdgeFinder.prototype.getEdge = function getEdge () {
  7491. return this._orientedDe
  7492. };
  7493. RightmostEdgeFinder.prototype.checkForRightmostCoordinate = function checkForRightmostCoordinate (de) {
  7494. var this$1 = this;
  7495. var coord = de.getEdge().getCoordinates();
  7496. for (var i = 0; i < coord.length - 1; i++) {
  7497. if (this$1._minCoord === null || coord[i].x > this$1._minCoord.x) {
  7498. this$1._minDe = de;
  7499. this$1._minIndex = i;
  7500. this$1._minCoord = coord[i];
  7501. }
  7502. }
  7503. };
  7504. RightmostEdgeFinder.prototype.findRightmostEdgeAtNode = function findRightmostEdgeAtNode () {
  7505. var node = this._minDe.getNode();
  7506. var star = node.getEdges();
  7507. this._minDe = star.getRightmostEdge();
  7508. if (!this._minDe.isForward()) {
  7509. this._minDe = this._minDe.getSym();
  7510. this._minIndex = this._minDe.getEdge().getCoordinates().length - 1;
  7511. }
  7512. };
  7513. RightmostEdgeFinder.prototype.findEdge = function findEdge (dirEdgeList) {
  7514. var this$1 = this;
  7515. for (var i = dirEdgeList.iterator(); i.hasNext();) {
  7516. var de = i.next();
  7517. if (!de.isForward()) { continue }
  7518. this$1.checkForRightmostCoordinate(de);
  7519. }
  7520. Assert.isTrue(this._minIndex !== 0 || this._minCoord.equals(this._minDe.getCoordinate()), 'inconsistency in rightmost processing');
  7521. if (this._minIndex === 0) {
  7522. this.findRightmostEdgeAtNode();
  7523. } else {
  7524. this.findRightmostEdgeAtVertex();
  7525. }
  7526. this._orientedDe = this._minDe;
  7527. var rightmostSide = this.getRightmostSide(this._minDe, this._minIndex);
  7528. if (rightmostSide === Position.LEFT) {
  7529. this._orientedDe = this._minDe.getSym();
  7530. }
  7531. };
  7532. RightmostEdgeFinder.prototype.interfaces_ = function interfaces_ () {
  7533. return []
  7534. };
  7535. RightmostEdgeFinder.prototype.getClass = function getClass () {
  7536. return RightmostEdgeFinder
  7537. };
  7538. var TopologyException = (function (RuntimeException$$1) {
  7539. function TopologyException (msg, pt) {
  7540. RuntimeException$$1.call(this, TopologyException.msgWithCoord(msg, pt));
  7541. this.pt = pt ? new Coordinate(pt) : null;
  7542. this.name = 'TopologyException';
  7543. }
  7544. if ( RuntimeException$$1 ) TopologyException.__proto__ = RuntimeException$$1;
  7545. TopologyException.prototype = Object.create( RuntimeException$$1 && RuntimeException$$1.prototype );
  7546. TopologyException.prototype.constructor = TopologyException;
  7547. TopologyException.prototype.getCoordinate = function getCoordinate () {
  7548. return this.pt
  7549. };
  7550. TopologyException.prototype.interfaces_ = function interfaces_ () {
  7551. return []
  7552. };
  7553. TopologyException.prototype.getClass = function getClass () {
  7554. return TopologyException
  7555. };
  7556. TopologyException.msgWithCoord = function msgWithCoord (msg, pt) {
  7557. if (!pt) { return msg + ' [ ' + pt + ' ]' }
  7558. return msg
  7559. };
  7560. return TopologyException;
  7561. }(RuntimeException));
  7562. var LinkedList = function LinkedList () {
  7563. this.array_ = [];
  7564. };
  7565. LinkedList.prototype.addLast = function addLast (e) {
  7566. this.array_.push(e);
  7567. };
  7568. LinkedList.prototype.removeFirst = function removeFirst () {
  7569. return this.array_.shift()
  7570. };
  7571. LinkedList.prototype.isEmpty = function isEmpty () {
  7572. return this.array_.length === 0
  7573. };
  7574. var BufferSubgraph = function BufferSubgraph () {
  7575. this._finder = null;
  7576. this._dirEdgeList = new ArrayList();
  7577. this._nodes = new ArrayList();
  7578. this._rightMostCoord = null;
  7579. this._env = null;
  7580. this._finder = new RightmostEdgeFinder();
  7581. };
  7582. BufferSubgraph.prototype.clearVisitedEdges = function clearVisitedEdges () {
  7583. for (var it = this._dirEdgeList.iterator(); it.hasNext();) {
  7584. var de = it.next();
  7585. de.setVisited(false);
  7586. }
  7587. };
  7588. BufferSubgraph.prototype.getRightmostCoordinate = function getRightmostCoordinate () {
  7589. return this._rightMostCoord
  7590. };
  7591. BufferSubgraph.prototype.computeNodeDepth = function computeNodeDepth (n) {
  7592. var this$1 = this;
  7593. var startEdge = null;
  7594. for (var i = n.getEdges().iterator(); i.hasNext();) {
  7595. var de = i.next();
  7596. if (de.isVisited() || de.getSym().isVisited()) {
  7597. startEdge = de;
  7598. break
  7599. }
  7600. }
  7601. if (startEdge === null) { throw new TopologyException('unable to find edge to compute depths at ' + n.getCoordinate()) }
  7602. n.getEdges().computeDepths(startEdge);
  7603. for (var i$1 = n.getEdges().iterator(); i$1.hasNext();) {
  7604. var de$1 = i$1.next();
  7605. de$1.setVisited(true);
  7606. this$1.copySymDepths(de$1);
  7607. }
  7608. };
  7609. BufferSubgraph.prototype.computeDepth = function computeDepth (outsideDepth) {
  7610. this.clearVisitedEdges();
  7611. var de = this._finder.getEdge();
  7612. // const n = de.getNode()
  7613. // const label = de.getLabel()
  7614. de.setEdgeDepths(Position.RIGHT, outsideDepth);
  7615. this.copySymDepths(de);
  7616. this.computeDepths(de);
  7617. };
  7618. BufferSubgraph.prototype.create = function create (node) {
  7619. this.addReachable(node);
  7620. this._finder.findEdge(this._dirEdgeList);
  7621. this._rightMostCoord = this._finder.getCoordinate();
  7622. };
  7623. BufferSubgraph.prototype.findResultEdges = function findResultEdges () {
  7624. for (var it = this._dirEdgeList.iterator(); it.hasNext();) {
  7625. var de = it.next();
  7626. if (de.getDepth(Position.RIGHT) >= 1 && de.getDepth(Position.LEFT) <= 0 && !de.isInteriorAreaEdge()) {
  7627. de.setInResult(true);
  7628. }
  7629. }
  7630. };
  7631. BufferSubgraph.prototype.computeDepths = function computeDepths (startEdge) {
  7632. var this$1 = this;
  7633. var nodesVisited = new HashSet();
  7634. var nodeQueue = new LinkedList();
  7635. var startNode = startEdge.getNode();
  7636. nodeQueue.addLast(startNode);
  7637. nodesVisited.add(startNode);
  7638. startEdge.setVisited(true);
  7639. while (!nodeQueue.isEmpty()) {
  7640. var n = nodeQueue.removeFirst();
  7641. nodesVisited.add(n);
  7642. this$1.computeNodeDepth(n);
  7643. for (var i = n.getEdges().iterator(); i.hasNext();) {
  7644. var de = i.next();
  7645. var sym = de.getSym();
  7646. if (sym.isVisited()) { continue }
  7647. var adjNode = sym.getNode();
  7648. if (!nodesVisited.contains(adjNode)) {
  7649. nodeQueue.addLast(adjNode);
  7650. nodesVisited.add(adjNode);
  7651. }
  7652. }
  7653. }
  7654. };
  7655. BufferSubgraph.prototype.compareTo = function compareTo (o) {
  7656. var graph = o;
  7657. if (this._rightMostCoord.x < graph._rightMostCoord.x) {
  7658. return -1
  7659. }
  7660. if (this._rightMostCoord.x > graph._rightMostCoord.x) {
  7661. return 1
  7662. }
  7663. return 0
  7664. };
  7665. BufferSubgraph.prototype.getEnvelope = function getEnvelope () {
  7666. if (this._env === null) {
  7667. var edgeEnv = new Envelope();
  7668. for (var it = this._dirEdgeList.iterator(); it.hasNext();) {
  7669. var dirEdge = it.next();
  7670. var pts = dirEdge.getEdge().getCoordinates();
  7671. for (var i = 0; i < pts.length - 1; i++) {
  7672. edgeEnv.expandToInclude(pts[i]);
  7673. }
  7674. }
  7675. this._env = edgeEnv;
  7676. }
  7677. return this._env
  7678. };
  7679. BufferSubgraph.prototype.addReachable = function addReachable (startNode) {
  7680. var this$1 = this;
  7681. var nodeStack = new Stack();
  7682. nodeStack.add(startNode);
  7683. while (!nodeStack.empty()) {
  7684. var node = nodeStack.pop();
  7685. this$1.add(node, nodeStack);
  7686. }
  7687. };
  7688. BufferSubgraph.prototype.copySymDepths = function copySymDepths (de) {
  7689. var sym = de.getSym();
  7690. sym.setDepth(Position.LEFT, de.getDepth(Position.RIGHT));
  7691. sym.setDepth(Position.RIGHT, de.getDepth(Position.LEFT));
  7692. };
  7693. BufferSubgraph.prototype.add = function add (node, nodeStack) {
  7694. var this$1 = this;
  7695. node.setVisited(true);
  7696. this._nodes.add(node);
  7697. for (var i = node.getEdges().iterator(); i.hasNext();) {
  7698. var de = i.next();
  7699. this$1._dirEdgeList.add(de);
  7700. var sym = de.getSym();
  7701. var symNode = sym.getNode();
  7702. if (!symNode.isVisited()) { nodeStack.push(symNode); }
  7703. }
  7704. };
  7705. BufferSubgraph.prototype.getNodes = function getNodes () {
  7706. return this._nodes
  7707. };
  7708. BufferSubgraph.prototype.getDirectedEdges = function getDirectedEdges () {
  7709. return this._dirEdgeList
  7710. };
  7711. BufferSubgraph.prototype.interfaces_ = function interfaces_ () {
  7712. return [Comparable]
  7713. };
  7714. BufferSubgraph.prototype.getClass = function getClass () {
  7715. return BufferSubgraph
  7716. };
  7717. var TopologyLocation = function TopologyLocation () {
  7718. var this$1 = this;
  7719. this.location = null;
  7720. if (arguments.length === 1) {
  7721. if (arguments[0] instanceof Array) {
  7722. var location = arguments[0];
  7723. this.init(location.length);
  7724. } else if (Number.isInteger(arguments[0])) {
  7725. var on = arguments[0];
  7726. this.init(1);
  7727. this.location[Position.ON] = on;
  7728. } else if (arguments[0] instanceof TopologyLocation) {
  7729. var gl = arguments[0];
  7730. this.init(gl.location.length);
  7731. if (gl !== null) {
  7732. for (var i = 0; i < this.location.length; i++) {
  7733. this$1.location[i] = gl.location[i];
  7734. }
  7735. }
  7736. }
  7737. } else if (arguments.length === 3) {
  7738. var on$1 = arguments[0];
  7739. var left = arguments[1];
  7740. var right = arguments[2];
  7741. this.init(3);
  7742. this.location[Position.ON] = on$1;
  7743. this.location[Position.LEFT] = left;
  7744. this.location[Position.RIGHT] = right;
  7745. }
  7746. };
  7747. TopologyLocation.prototype.setAllLocations = function setAllLocations (locValue) {
  7748. var this$1 = this;
  7749. for (var i = 0; i < this.location.length; i++) {
  7750. this$1.location[i] = locValue;
  7751. }
  7752. };
  7753. TopologyLocation.prototype.isNull = function isNull () {
  7754. var this$1 = this;
  7755. for (var i = 0; i < this.location.length; i++) {
  7756. if (this$1.location[i] !== Location.NONE) { return false }
  7757. }
  7758. return true
  7759. };
  7760. TopologyLocation.prototype.setAllLocationsIfNull = function setAllLocationsIfNull (locValue) {
  7761. var this$1 = this;
  7762. for (var i = 0; i < this.location.length; i++) {
  7763. if (this$1.location[i] === Location.NONE) { this$1.location[i] = locValue; }
  7764. }
  7765. };
  7766. TopologyLocation.prototype.isLine = function isLine () {
  7767. return this.location.length === 1
  7768. };
  7769. TopologyLocation.prototype.merge = function merge (gl) {
  7770. var this$1 = this;
  7771. if (gl.location.length > this.location.length) {
  7772. var newLoc = new Array(3).fill(null);
  7773. newLoc[Position.ON] = this.location[Position.ON];
  7774. newLoc[Position.LEFT] = Location.NONE;
  7775. newLoc[Position.RIGHT] = Location.NONE;
  7776. this.location = newLoc;
  7777. }
  7778. for (var i = 0; i < this.location.length; i++) {
  7779. if (this$1.location[i] === Location.NONE && i < gl.location.length) { this$1.location[i] = gl.location[i]; }
  7780. }
  7781. };
  7782. TopologyLocation.prototype.getLocations = function getLocations () {
  7783. return this.location
  7784. };
  7785. TopologyLocation.prototype.flip = function flip () {
  7786. if (this.location.length <= 1) { return null }
  7787. var temp = this.location[Position.LEFT];
  7788. this.location[Position.LEFT] = this.location[Position.RIGHT];
  7789. this.location[Position.RIGHT] = temp;
  7790. };
  7791. TopologyLocation.prototype.toString = function toString () {
  7792. var buf = new StringBuffer();
  7793. if (this.location.length > 1) { buf.append(Location.toLocationSymbol(this.location[Position.LEFT])); }
  7794. buf.append(Location.toLocationSymbol(this.location[Position.ON]));
  7795. if (this.location.length > 1) { buf.append(Location.toLocationSymbol(this.location[Position.RIGHT])); }
  7796. return buf.toString()
  7797. };
  7798. TopologyLocation.prototype.setLocations = function setLocations (on, left, right) {
  7799. this.location[Position.ON] = on;
  7800. this.location[Position.LEFT] = left;
  7801. this.location[Position.RIGHT] = right;
  7802. };
  7803. TopologyLocation.prototype.get = function get (posIndex) {
  7804. if (posIndex < this.location.length) { return this.location[posIndex] }
  7805. return Location.NONE
  7806. };
  7807. TopologyLocation.prototype.isArea = function isArea () {
  7808. return this.location.length > 1
  7809. };
  7810. TopologyLocation.prototype.isAnyNull = function isAnyNull () {
  7811. var this$1 = this;
  7812. for (var i = 0; i < this.location.length; i++) {
  7813. if (this$1.location[i] === Location.NONE) { return true }
  7814. }
  7815. return false
  7816. };
  7817. TopologyLocation.prototype.setLocation = function setLocation () {
  7818. if (arguments.length === 1) {
  7819. var locValue = arguments[0];
  7820. this.setLocation(Position.ON, locValue);
  7821. } else if (arguments.length === 2) {
  7822. var locIndex = arguments[0];
  7823. var locValue$1 = arguments[1];
  7824. this.location[locIndex] = locValue$1;
  7825. }
  7826. };
  7827. TopologyLocation.prototype.init = function init (size) {
  7828. this.location = new Array(size).fill(null);
  7829. this.setAllLocations(Location.NONE);
  7830. };
  7831. TopologyLocation.prototype.isEqualOnSide = function isEqualOnSide (le, locIndex) {
  7832. return this.location[locIndex] === le.location[locIndex]
  7833. };
  7834. TopologyLocation.prototype.allPositionsEqual = function allPositionsEqual (loc) {
  7835. var this$1 = this;
  7836. for (var i = 0; i < this.location.length; i++) {
  7837. if (this$1.location[i] !== loc) { return false }
  7838. }
  7839. return true
  7840. };
  7841. TopologyLocation.prototype.interfaces_ = function interfaces_ () {
  7842. return []
  7843. };
  7844. TopologyLocation.prototype.getClass = function getClass () {
  7845. return TopologyLocation
  7846. };
  7847. var Label = function Label () {
  7848. this.elt = new Array(2).fill(null);
  7849. if (arguments.length === 1) {
  7850. if (Number.isInteger(arguments[0])) {
  7851. var onLoc = arguments[0];
  7852. this.elt[0] = new TopologyLocation(onLoc);
  7853. this.elt[1] = new TopologyLocation(onLoc);
  7854. } else if (arguments[0] instanceof Label) {
  7855. var lbl = arguments[0];
  7856. this.elt[0] = new TopologyLocation(lbl.elt[0]);
  7857. this.elt[1] = new TopologyLocation(lbl.elt[1]);
  7858. }
  7859. } else if (arguments.length === 2) {
  7860. var geomIndex = arguments[0];
  7861. var onLoc$1 = arguments[1];
  7862. this.elt[0] = new TopologyLocation(Location.NONE);
  7863. this.elt[1] = new TopologyLocation(Location.NONE);
  7864. this.elt[geomIndex].setLocation(onLoc$1);
  7865. } else if (arguments.length === 3) {
  7866. var onLoc$2 = arguments[0];
  7867. var leftLoc = arguments[1];
  7868. var rightLoc = arguments[2];
  7869. this.elt[0] = new TopologyLocation(onLoc$2, leftLoc, rightLoc);
  7870. this.elt[1] = new TopologyLocation(onLoc$2, leftLoc, rightLoc);
  7871. } else if (arguments.length === 4) {
  7872. var geomIndex$1 = arguments[0];
  7873. var onLoc$3 = arguments[1];
  7874. var leftLoc$1 = arguments[2];
  7875. var rightLoc$1 = arguments[3];
  7876. this.elt[0] = new TopologyLocation(Location.NONE, Location.NONE, Location.NONE);
  7877. this.elt[1] = new TopologyLocation(Location.NONE, Location.NONE, Location.NONE);
  7878. this.elt[geomIndex$1].setLocations(onLoc$3, leftLoc$1, rightLoc$1);
  7879. }
  7880. };
  7881. Label.prototype.getGeometryCount = function getGeometryCount () {
  7882. var count = 0;
  7883. if (!this.elt[0].isNull()) { count++; }
  7884. if (!this.elt[1].isNull()) { count++; }
  7885. return count
  7886. };
  7887. Label.prototype.setAllLocations = function setAllLocations (geomIndex, location) {
  7888. this.elt[geomIndex].setAllLocations(location);
  7889. };
  7890. Label.prototype.isNull = function isNull (geomIndex) {
  7891. return this.elt[geomIndex].isNull()
  7892. };
  7893. Label.prototype.setAllLocationsIfNull = function setAllLocationsIfNull () {
  7894. if (arguments.length === 1) {
  7895. var location = arguments[0];
  7896. this.setAllLocationsIfNull(0, location);
  7897. this.setAllLocationsIfNull(1, location);
  7898. } else if (arguments.length === 2) {
  7899. var geomIndex = arguments[0];
  7900. var location$1 = arguments[1];
  7901. this.elt[geomIndex].setAllLocationsIfNull(location$1);
  7902. }
  7903. };
  7904. Label.prototype.isLine = function isLine (geomIndex) {
  7905. return this.elt[geomIndex].isLine()
  7906. };
  7907. Label.prototype.merge = function merge (lbl) {
  7908. var this$1 = this;
  7909. for (var i = 0; i < 2; i++) {
  7910. if (this$1.elt[i] === null && lbl.elt[i] !== null) {
  7911. this$1.elt[i] = new TopologyLocation(lbl.elt[i]);
  7912. } else {
  7913. this$1.elt[i].merge(lbl.elt[i]);
  7914. }
  7915. }
  7916. };
  7917. Label.prototype.flip = function flip () {
  7918. this.elt[0].flip();
  7919. this.elt[1].flip();
  7920. };
  7921. Label.prototype.getLocation = function getLocation () {
  7922. if (arguments.length === 1) {
  7923. var geomIndex = arguments[0];
  7924. return this.elt[geomIndex].get(Position.ON)
  7925. } else if (arguments.length === 2) {
  7926. var geomIndex$1 = arguments[0];
  7927. var posIndex = arguments[1];
  7928. return this.elt[geomIndex$1].get(posIndex)
  7929. }
  7930. };
  7931. Label.prototype.toString = function toString () {
  7932. var buf = new StringBuffer();
  7933. if (this.elt[0] !== null) {
  7934. buf.append('A:');
  7935. buf.append(this.elt[0].toString());
  7936. }
  7937. if (this.elt[1] !== null) {
  7938. buf.append(' B:');
  7939. buf.append(this.elt[1].toString());
  7940. }
  7941. return buf.toString()
  7942. };
  7943. Label.prototype.isArea = function isArea () {
  7944. if (arguments.length === 0) {
  7945. return this.elt[0].isArea() || this.elt[1].isArea()
  7946. } else if (arguments.length === 1) {
  7947. var geomIndex = arguments[0];
  7948. return this.elt[geomIndex].isArea()
  7949. }
  7950. };
  7951. Label.prototype.isAnyNull = function isAnyNull (geomIndex) {
  7952. return this.elt[geomIndex].isAnyNull()
  7953. };
  7954. Label.prototype.setLocation = function setLocation () {
  7955. if (arguments.length === 2) {
  7956. var geomIndex = arguments[0];
  7957. var location = arguments[1];
  7958. this.elt[geomIndex].setLocation(Position.ON, location);
  7959. } else if (arguments.length === 3) {
  7960. var geomIndex$1 = arguments[0];
  7961. var posIndex = arguments[1];
  7962. var location$1 = arguments[2];
  7963. this.elt[geomIndex$1].setLocation(posIndex, location$1);
  7964. }
  7965. };
  7966. Label.prototype.isEqualOnSide = function isEqualOnSide (lbl, side) {
  7967. return this.elt[0].isEqualOnSide(lbl.elt[0], side) && this.elt[1].isEqualOnSide(lbl.elt[1], side)
  7968. };
  7969. Label.prototype.allPositionsEqual = function allPositionsEqual (geomIndex, loc) {
  7970. return this.elt[geomIndex].allPositionsEqual(loc)
  7971. };
  7972. Label.prototype.toLine = function toLine (geomIndex) {
  7973. if (this.elt[geomIndex].isArea()) { this.elt[geomIndex] = new TopologyLocation(this.elt[geomIndex].location[0]); }
  7974. };
  7975. Label.prototype.interfaces_ = function interfaces_ () {
  7976. return []
  7977. };
  7978. Label.prototype.getClass = function getClass () {
  7979. return Label
  7980. };
  7981. Label.toLineLabel = function toLineLabel (label) {
  7982. var lineLabel = new Label(Location.NONE);
  7983. for (var i = 0; i < 2; i++) {
  7984. lineLabel.setLocation(i, label.getLocation(i));
  7985. }
  7986. return lineLabel
  7987. };
  7988. var EdgeRing = function EdgeRing () {
  7989. this._startDe = null;
  7990. this._maxNodeDegree = -1;
  7991. this._edges = new ArrayList();
  7992. this._pts = new ArrayList();
  7993. this._label = new Label(Location.NONE);
  7994. this._ring = null;
  7995. this._isHole = null;
  7996. this._shell = null;
  7997. this._holes = new ArrayList();
  7998. this._geometryFactory = null;
  7999. var start = arguments[0];
  8000. var geometryFactory = arguments[1];
  8001. this._geometryFactory = geometryFactory;
  8002. this.computePoints(start);
  8003. this.computeRing();
  8004. };
  8005. EdgeRing.prototype.computeRing = function computeRing () {
  8006. var this$1 = this;
  8007. if (this._ring !== null) { return null }
  8008. var coord = new Array(this._pts.size()).fill(null);
  8009. for (var i = 0; i < this._pts.size(); i++) {
  8010. coord[i] = this$1._pts.get(i);
  8011. }
  8012. this._ring = this._geometryFactory.createLinearRing(coord);
  8013. this._isHole = CGAlgorithms.isCCW(this._ring.getCoordinates());
  8014. };
  8015. EdgeRing.prototype.isIsolated = function isIsolated () {
  8016. return this._label.getGeometryCount() === 1
  8017. };
  8018. EdgeRing.prototype.computePoints = function computePoints (start) {
  8019. var this$1 = this;
  8020. this._startDe = start;
  8021. var de = start;
  8022. var isFirstEdge = true;
  8023. do {
  8024. if (de === null) { throw new TopologyException('Found null DirectedEdge') }
  8025. if (de.getEdgeRing() === this$1) { throw new TopologyException('Directed Edge visited twice during ring-building at ' + de.getCoordinate()) }
  8026. this$1._edges.add(de);
  8027. var label = de.getLabel();
  8028. Assert.isTrue(label.isArea());
  8029. this$1.mergeLabel(label);
  8030. this$1.addPoints(de.getEdge(), de.isForward(), isFirstEdge);
  8031. isFirstEdge = false;
  8032. this$1.setEdgeRing(de, this$1);
  8033. de = this$1.getNext(de);
  8034. } while (de !== this._startDe)
  8035. };
  8036. EdgeRing.prototype.getLinearRing = function getLinearRing () {
  8037. return this._ring
  8038. };
  8039. EdgeRing.prototype.getCoordinate = function getCoordinate (i) {
  8040. return this._pts.get(i)
  8041. };
  8042. EdgeRing.prototype.computeMaxNodeDegree = function computeMaxNodeDegree () {
  8043. var this$1 = this;
  8044. this._maxNodeDegree = 0;
  8045. var de = this._startDe;
  8046. do {
  8047. var node = de.getNode();
  8048. var degree = node.getEdges().getOutgoingDegree(this$1);
  8049. if (degree > this$1._maxNodeDegree) { this$1._maxNodeDegree = degree; }
  8050. de = this$1.getNext(de);
  8051. } while (de !== this._startDe)
  8052. this._maxNodeDegree *= 2;
  8053. };
  8054. EdgeRing.prototype.addPoints = function addPoints (edge, isForward, isFirstEdge) {
  8055. var this$1 = this;
  8056. var edgePts = edge.getCoordinates();
  8057. if (isForward) {
  8058. var startIndex = 1;
  8059. if (isFirstEdge) { startIndex = 0; }
  8060. for (var i = startIndex; i < edgePts.length; i++) {
  8061. this$1._pts.add(edgePts[i]);
  8062. }
  8063. } else {
  8064. var startIndex$1 = edgePts.length - 2;
  8065. if (isFirstEdge) { startIndex$1 = edgePts.length - 1; }
  8066. for (var i$1 = startIndex$1; i$1 >= 0; i$1--) {
  8067. this$1._pts.add(edgePts[i$1]);
  8068. }
  8069. }
  8070. };
  8071. EdgeRing.prototype.isHole = function isHole () {
  8072. return this._isHole
  8073. };
  8074. EdgeRing.prototype.setInResult = function setInResult () {
  8075. var de = this._startDe;
  8076. do {
  8077. de.getEdge().setInResult(true);
  8078. de = de.getNext();
  8079. } while (de !== this._startDe)
  8080. };
  8081. EdgeRing.prototype.containsPoint = function containsPoint (p) {
  8082. var shell = this.getLinearRing();
  8083. var env = shell.getEnvelopeInternal();
  8084. if (!env.contains(p)) { return false }
  8085. if (!CGAlgorithms.isPointInRing(p, shell.getCoordinates())) { return false }
  8086. for (var i = this._holes.iterator(); i.hasNext();) {
  8087. var hole = i.next();
  8088. if (hole.containsPoint(p)) { return false }
  8089. }
  8090. return true
  8091. };
  8092. EdgeRing.prototype.addHole = function addHole (ring) {
  8093. this._holes.add(ring);
  8094. };
  8095. EdgeRing.prototype.isShell = function isShell () {
  8096. return this._shell === null
  8097. };
  8098. EdgeRing.prototype.getLabel = function getLabel () {
  8099. return this._label
  8100. };
  8101. EdgeRing.prototype.getEdges = function getEdges () {
  8102. return this._edges
  8103. };
  8104. EdgeRing.prototype.getMaxNodeDegree = function getMaxNodeDegree () {
  8105. if (this._maxNodeDegree < 0) { this.computeMaxNodeDegree(); }
  8106. return this._maxNodeDegree
  8107. };
  8108. EdgeRing.prototype.getShell = function getShell () {
  8109. return this._shell
  8110. };
  8111. EdgeRing.prototype.mergeLabel = function mergeLabel () {
  8112. if (arguments.length === 1) {
  8113. var deLabel = arguments[0];
  8114. this.mergeLabel(deLabel, 0);
  8115. this.mergeLabel(deLabel, 1);
  8116. } else if (arguments.length === 2) {
  8117. var deLabel$1 = arguments[0];
  8118. var geomIndex = arguments[1];
  8119. var loc = deLabel$1.getLocation(geomIndex, Position.RIGHT);
  8120. if (loc === Location.NONE) { return null }
  8121. if (this._label.getLocation(geomIndex) === Location.NONE) {
  8122. this._label.setLocation(geomIndex, loc);
  8123. return null
  8124. }
  8125. }
  8126. };
  8127. EdgeRing.prototype.setShell = function setShell (shell) {
  8128. this._shell = shell;
  8129. if (shell !== null) { shell.addHole(this); }
  8130. };
  8131. EdgeRing.prototype.toPolygon = function toPolygon (geometryFactory) {
  8132. var this$1 = this;
  8133. var holeLR = new Array(this._holes.size()).fill(null);
  8134. for (var i = 0; i < this._holes.size(); i++) {
  8135. holeLR[i] = this$1._holes.get(i).getLinearRing();
  8136. }
  8137. var poly = geometryFactory.createPolygon(this.getLinearRing(), holeLR);
  8138. return poly
  8139. };
  8140. EdgeRing.prototype.interfaces_ = function interfaces_ () {
  8141. return []
  8142. };
  8143. EdgeRing.prototype.getClass = function getClass () {
  8144. return EdgeRing
  8145. };
  8146. var MinimalEdgeRing = (function (EdgeRing$$1) {
  8147. function MinimalEdgeRing () {
  8148. var start = arguments[0];
  8149. var geometryFactory = arguments[1];
  8150. EdgeRing$$1.call(this, start, geometryFactory);
  8151. }
  8152. if ( EdgeRing$$1 ) MinimalEdgeRing.__proto__ = EdgeRing$$1;
  8153. MinimalEdgeRing.prototype = Object.create( EdgeRing$$1 && EdgeRing$$1.prototype );
  8154. MinimalEdgeRing.prototype.constructor = MinimalEdgeRing;
  8155. MinimalEdgeRing.prototype.setEdgeRing = function setEdgeRing (de, er) {
  8156. de.setMinEdgeRing(er);
  8157. };
  8158. MinimalEdgeRing.prototype.getNext = function getNext (de) {
  8159. return de.getNextMin()
  8160. };
  8161. MinimalEdgeRing.prototype.interfaces_ = function interfaces_ () {
  8162. return []
  8163. };
  8164. MinimalEdgeRing.prototype.getClass = function getClass () {
  8165. return MinimalEdgeRing
  8166. };
  8167. return MinimalEdgeRing;
  8168. }(EdgeRing));
  8169. var MaximalEdgeRing = (function (EdgeRing$$1) {
  8170. function MaximalEdgeRing () {
  8171. var start = arguments[0];
  8172. var geometryFactory = arguments[1];
  8173. EdgeRing$$1.call(this, start, geometryFactory);
  8174. }
  8175. if ( EdgeRing$$1 ) MaximalEdgeRing.__proto__ = EdgeRing$$1;
  8176. MaximalEdgeRing.prototype = Object.create( EdgeRing$$1 && EdgeRing$$1.prototype );
  8177. MaximalEdgeRing.prototype.constructor = MaximalEdgeRing;
  8178. MaximalEdgeRing.prototype.buildMinimalRings = function buildMinimalRings () {
  8179. var this$1 = this;
  8180. var minEdgeRings = new ArrayList();
  8181. var de = this._startDe;
  8182. do {
  8183. if (de.getMinEdgeRing() === null) {
  8184. var minEr = new MinimalEdgeRing(de, this$1._geometryFactory);
  8185. minEdgeRings.add(minEr);
  8186. }
  8187. de = de.getNext();
  8188. } while (de !== this._startDe)
  8189. return minEdgeRings
  8190. };
  8191. MaximalEdgeRing.prototype.setEdgeRing = function setEdgeRing (de, er) {
  8192. de.setEdgeRing(er);
  8193. };
  8194. MaximalEdgeRing.prototype.linkDirectedEdgesForMinimalEdgeRings = function linkDirectedEdgesForMinimalEdgeRings () {
  8195. var this$1 = this;
  8196. var de = this._startDe;
  8197. do {
  8198. var node = de.getNode();
  8199. node.getEdges().linkMinimalDirectedEdges(this$1);
  8200. de = de.getNext();
  8201. } while (de !== this._startDe)
  8202. };
  8203. MaximalEdgeRing.prototype.getNext = function getNext (de) {
  8204. return de.getNext()
  8205. };
  8206. MaximalEdgeRing.prototype.interfaces_ = function interfaces_ () {
  8207. return []
  8208. };
  8209. MaximalEdgeRing.prototype.getClass = function getClass () {
  8210. return MaximalEdgeRing
  8211. };
  8212. return MaximalEdgeRing;
  8213. }(EdgeRing));
  8214. var GraphComponent = function GraphComponent () {
  8215. this._label = null;
  8216. this._isInResult = false;
  8217. this._isCovered = false;
  8218. this._isCoveredSet = false;
  8219. this._isVisited = false;
  8220. if (arguments.length === 0) {} else if (arguments.length === 1) {
  8221. var label = arguments[0];
  8222. this._label = label;
  8223. }
  8224. };
  8225. GraphComponent.prototype.setVisited = function setVisited (isVisited) {
  8226. this._isVisited = isVisited;
  8227. };
  8228. GraphComponent.prototype.setInResult = function setInResult (isInResult) {
  8229. this._isInResult = isInResult;
  8230. };
  8231. GraphComponent.prototype.isCovered = function isCovered () {
  8232. return this._isCovered
  8233. };
  8234. GraphComponent.prototype.isCoveredSet = function isCoveredSet () {
  8235. return this._isCoveredSet
  8236. };
  8237. GraphComponent.prototype.setLabel = function setLabel (label) {
  8238. this._label = label;
  8239. };
  8240. GraphComponent.prototype.getLabel = function getLabel () {
  8241. return this._label
  8242. };
  8243. GraphComponent.prototype.setCovered = function setCovered (isCovered) {
  8244. this._isCovered = isCovered;
  8245. this._isCoveredSet = true;
  8246. };
  8247. GraphComponent.prototype.updateIM = function updateIM (im) {
  8248. Assert.isTrue(this._label.getGeometryCount() >= 2, 'found partial label');
  8249. this.computeIM(im);
  8250. };
  8251. GraphComponent.prototype.isInResult = function isInResult () {
  8252. return this._isInResult
  8253. };
  8254. GraphComponent.prototype.isVisited = function isVisited () {
  8255. return this._isVisited
  8256. };
  8257. GraphComponent.prototype.interfaces_ = function interfaces_ () {
  8258. return []
  8259. };
  8260. GraphComponent.prototype.getClass = function getClass () {
  8261. return GraphComponent
  8262. };
  8263. var Node = (function (GraphComponent$$1) {
  8264. function Node () {
  8265. GraphComponent$$1.call(this);
  8266. this._coord = null;
  8267. this._edges = null;
  8268. var coord = arguments[0];
  8269. var edges = arguments[1];
  8270. this._coord = coord;
  8271. this._edges = edges;
  8272. this._label = new Label(0, Location.NONE);
  8273. }
  8274. if ( GraphComponent$$1 ) Node.__proto__ = GraphComponent$$1;
  8275. Node.prototype = Object.create( GraphComponent$$1 && GraphComponent$$1.prototype );
  8276. Node.prototype.constructor = Node;
  8277. Node.prototype.isIncidentEdgeInResult = function isIncidentEdgeInResult () {
  8278. for (var it = this.getEdges().getEdges().iterator(); it.hasNext();) {
  8279. var de = it.next();
  8280. if (de.getEdge().isInResult()) { return true }
  8281. }
  8282. return false
  8283. };
  8284. Node.prototype.isIsolated = function isIsolated () {
  8285. return this._label.getGeometryCount() === 1
  8286. };
  8287. Node.prototype.getCoordinate = function getCoordinate () {
  8288. return this._coord
  8289. };
  8290. Node.prototype.print = function print (out) {
  8291. out.println('node ' + this._coord + ' lbl: ' + this._label);
  8292. };
  8293. Node.prototype.computeIM = function computeIM (im) {};
  8294. Node.prototype.computeMergedLocation = function computeMergedLocation (label2, eltIndex) {
  8295. var loc = Location.NONE;
  8296. loc = this._label.getLocation(eltIndex);
  8297. if (!label2.isNull(eltIndex)) {
  8298. var nLoc = label2.getLocation(eltIndex);
  8299. if (loc !== Location.BOUNDARY) { loc = nLoc; }
  8300. }
  8301. return loc
  8302. };
  8303. Node.prototype.setLabel = function setLabel () {
  8304. if (arguments.length === 2) {
  8305. var argIndex = arguments[0];
  8306. var onLocation = arguments[1];
  8307. if (this._label === null) {
  8308. this._label = new Label(argIndex, onLocation);
  8309. } else { this._label.setLocation(argIndex, onLocation); }
  8310. } else { return GraphComponent$$1.prototype.setLabel.apply(this, arguments) }
  8311. };
  8312. Node.prototype.getEdges = function getEdges () {
  8313. return this._edges
  8314. };
  8315. Node.prototype.mergeLabel = function mergeLabel () {
  8316. var this$1 = this;
  8317. if (arguments[0] instanceof Node) {
  8318. var n = arguments[0];
  8319. this.mergeLabel(n._label);
  8320. } else if (arguments[0] instanceof Label) {
  8321. var label2 = arguments[0];
  8322. for (var i = 0; i < 2; i++) {
  8323. var loc = this$1.computeMergedLocation(label2, i);
  8324. var thisLoc = this$1._label.getLocation(i);
  8325. if (thisLoc === Location.NONE) { this$1._label.setLocation(i, loc); }
  8326. }
  8327. }
  8328. };
  8329. Node.prototype.add = function add (e) {
  8330. this._edges.insert(e);
  8331. e.setNode(this);
  8332. };
  8333. Node.prototype.setLabelBoundary = function setLabelBoundary (argIndex) {
  8334. if (this._label === null) { return null }
  8335. var loc = Location.NONE;
  8336. if (this._label !== null) { loc = this._label.getLocation(argIndex); }
  8337. var newLoc = null;
  8338. switch (loc) {
  8339. case Location.BOUNDARY:
  8340. newLoc = Location.INTERIOR;
  8341. break
  8342. case Location.INTERIOR:
  8343. newLoc = Location.BOUNDARY;
  8344. break
  8345. default:
  8346. newLoc = Location.BOUNDARY;
  8347. break
  8348. }
  8349. this._label.setLocation(argIndex, newLoc);
  8350. };
  8351. Node.prototype.interfaces_ = function interfaces_ () {
  8352. return []
  8353. };
  8354. Node.prototype.getClass = function getClass () {
  8355. return Node
  8356. };
  8357. return Node;
  8358. }(GraphComponent));
  8359. var NodeMap = function NodeMap () {
  8360. this.nodeMap = new TreeMap();
  8361. this.nodeFact = null;
  8362. var nodeFact = arguments[0];
  8363. this.nodeFact = nodeFact;
  8364. };
  8365. NodeMap.prototype.find = function find (coord) {
  8366. return this.nodeMap.get(coord)
  8367. };
  8368. NodeMap.prototype.addNode = function addNode () {
  8369. if (arguments[0] instanceof Coordinate) {
  8370. var coord = arguments[0];
  8371. var node = this.nodeMap.get(coord);
  8372. if (node === null) {
  8373. node = this.nodeFact.createNode(coord);
  8374. this.nodeMap.put(coord, node);
  8375. }
  8376. return node
  8377. } else if (arguments[0] instanceof Node) {
  8378. var n = arguments[0];
  8379. var node$1 = this.nodeMap.get(n.getCoordinate());
  8380. if (node$1 === null) {
  8381. this.nodeMap.put(n.getCoordinate(), n);
  8382. return n
  8383. }
  8384. node$1.mergeLabel(n);
  8385. return node$1
  8386. }
  8387. };
  8388. NodeMap.prototype.print = function print (out) {
  8389. for (var it = this.iterator(); it.hasNext();) {
  8390. var n = it.next();
  8391. n.print(out);
  8392. }
  8393. };
  8394. NodeMap.prototype.iterator = function iterator () {
  8395. return this.nodeMap.values().iterator()
  8396. };
  8397. NodeMap.prototype.values = function values () {
  8398. return this.nodeMap.values()
  8399. };
  8400. NodeMap.prototype.getBoundaryNodes = function getBoundaryNodes (geomIndex) {
  8401. var bdyNodes = new ArrayList();
  8402. for (var i = this.iterator(); i.hasNext();) {
  8403. var node = i.next();
  8404. if (node.getLabel().getLocation(geomIndex) === Location.BOUNDARY) { bdyNodes.add(node); }
  8405. }
  8406. return bdyNodes
  8407. };
  8408. NodeMap.prototype.add = function add (e) {
  8409. var p = e.getCoordinate();
  8410. var n = this.addNode(p);
  8411. n.add(e);
  8412. };
  8413. NodeMap.prototype.interfaces_ = function interfaces_ () {
  8414. return []
  8415. };
  8416. NodeMap.prototype.getClass = function getClass () {
  8417. return NodeMap
  8418. };
  8419. var Quadrant = function Quadrant () {};
  8420. var staticAccessors$21 = { NE: { configurable: true },NW: { configurable: true },SW: { configurable: true },SE: { configurable: true } };
  8421. Quadrant.prototype.interfaces_ = function interfaces_ () {
  8422. return []
  8423. };
  8424. Quadrant.prototype.getClass = function getClass () {
  8425. return Quadrant
  8426. };
  8427. Quadrant.isNorthern = function isNorthern (quad) {
  8428. return quad === Quadrant.NE || quad === Quadrant.NW
  8429. };
  8430. Quadrant.isOpposite = function isOpposite (quad1, quad2) {
  8431. if (quad1 === quad2) { return false }
  8432. var diff = (quad1 - quad2 + 4) % 4;
  8433. if (diff === 2) { return true }
  8434. return false
  8435. };
  8436. Quadrant.commonHalfPlane = function commonHalfPlane (quad1, quad2) {
  8437. if (quad1 === quad2) { return quad1 }
  8438. var diff = (quad1 - quad2 + 4) % 4;
  8439. if (diff === 2) { return -1 }
  8440. var min = quad1 < quad2 ? quad1 : quad2;
  8441. var max = quad1 > quad2 ? quad1 : quad2;
  8442. if (min === 0 && max === 3) { return 3 }
  8443. return min
  8444. };
  8445. Quadrant.isInHalfPlane = function isInHalfPlane (quad, halfPlane) {
  8446. if (halfPlane === Quadrant.SE) {
  8447. return quad === Quadrant.SE || quad === Quadrant.SW
  8448. }
  8449. return quad === halfPlane || quad === halfPlane + 1
  8450. };
  8451. Quadrant.quadrant = function quadrant () {
  8452. if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
  8453. var dx = arguments[0];
  8454. var dy = arguments[1];
  8455. if (dx === 0.0 && dy === 0.0) { throw new IllegalArgumentException('Cannot compute the quadrant for point ( ' + dx + ', ' + dy + ' )') }
  8456. if (dx >= 0.0) {
  8457. if (dy >= 0.0) { return Quadrant.NE; } else { return Quadrant.SE }
  8458. } else {
  8459. if (dy >= 0.0) { return Quadrant.NW; } else { return Quadrant.SW }
  8460. }
  8461. } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {
  8462. var p0 = arguments[0];
  8463. var p1 = arguments[1];
  8464. if (p1.x === p0.x && p1.y === p0.y) { throw new IllegalArgumentException('Cannot compute the quadrant for two identical points ' + p0) }
  8465. if (p1.x >= p0.x) {
  8466. if (p1.y >= p0.y) { return Quadrant.NE; } else { return Quadrant.SE }
  8467. } else {
  8468. if (p1.y >= p0.y) { return Quadrant.NW; } else { return Quadrant.SW }
  8469. }
  8470. }
  8471. };
  8472. staticAccessors$21.NE.get = function () { return 0 };
  8473. staticAccessors$21.NW.get = function () { return 1 };
  8474. staticAccessors$21.SW.get = function () { return 2 };
  8475. staticAccessors$21.SE.get = function () { return 3 };
  8476. Object.defineProperties( Quadrant, staticAccessors$21 );
  8477. var EdgeEnd = function EdgeEnd () {
  8478. this._edge = null;
  8479. this._label = null;
  8480. this._node = null;
  8481. this._p0 = null;
  8482. this._p1 = null;
  8483. this._dx = null;
  8484. this._dy = null;
  8485. this._quadrant = null;
  8486. if (arguments.length === 1) {
  8487. var edge = arguments[0];
  8488. this._edge = edge;
  8489. } else if (arguments.length === 3) {
  8490. var edge$1 = arguments[0];
  8491. var p0 = arguments[1];
  8492. var p1 = arguments[2];
  8493. var label = null;
  8494. this._edge = edge$1;
  8495. this.init(p0, p1);
  8496. this._label = label;
  8497. } else if (arguments.length === 4) {
  8498. var edge$2 = arguments[0];
  8499. var p0$1 = arguments[1];
  8500. var p1$1 = arguments[2];
  8501. var label$1 = arguments[3];
  8502. this._edge = edge$2;
  8503. this.init(p0$1, p1$1);
  8504. this._label = label$1;
  8505. }
  8506. };
  8507. EdgeEnd.prototype.compareDirection = function compareDirection (e) {
  8508. if (this._dx === e._dx && this._dy === e._dy) { return 0 }
  8509. if (this._quadrant > e._quadrant) { return 1 }
  8510. if (this._quadrant < e._quadrant) { return -1 }
  8511. return CGAlgorithms.computeOrientation(e._p0, e._p1, this._p1)
  8512. };
  8513. EdgeEnd.prototype.getDy = function getDy () {
  8514. return this._dy
  8515. };
  8516. EdgeEnd.prototype.getCoordinate = function getCoordinate () {
  8517. return this._p0
  8518. };
  8519. EdgeEnd.prototype.setNode = function setNode (node) {
  8520. this._node = node;
  8521. };
  8522. EdgeEnd.prototype.print = function print (out) {
  8523. var angle = Math.atan2(this._dy, this._dx);
  8524. var className = this.getClass().getName();
  8525. var lastDotPos = className.lastIndexOf('.');
  8526. var name = className.substring(lastDotPos + 1);
  8527. out.print(' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + angle + ' ' + this._label);
  8528. };
  8529. EdgeEnd.prototype.compareTo = function compareTo (obj) {
  8530. var e = obj;
  8531. return this.compareDirection(e)
  8532. };
  8533. EdgeEnd.prototype.getDirectedCoordinate = function getDirectedCoordinate () {
  8534. return this._p1
  8535. };
  8536. EdgeEnd.prototype.getDx = function getDx () {
  8537. return this._dx
  8538. };
  8539. EdgeEnd.prototype.getLabel = function getLabel () {
  8540. return this._label
  8541. };
  8542. EdgeEnd.prototype.getEdge = function getEdge () {
  8543. return this._edge
  8544. };
  8545. EdgeEnd.prototype.getQuadrant = function getQuadrant () {
  8546. return this._quadrant
  8547. };
  8548. EdgeEnd.prototype.getNode = function getNode () {
  8549. return this._node
  8550. };
  8551. EdgeEnd.prototype.toString = function toString () {
  8552. var angle = Math.atan2(this._dy, this._dx);
  8553. var className = this.getClass().getName();
  8554. var lastDotPos = className.lastIndexOf('.');
  8555. var name = className.substring(lastDotPos + 1);
  8556. return ' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + angle + ' ' + this._label
  8557. };
  8558. EdgeEnd.prototype.computeLabel = function computeLabel (boundaryNodeRule) {};
  8559. EdgeEnd.prototype.init = function init (p0, p1) {
  8560. this._p0 = p0;
  8561. this._p1 = p1;
  8562. this._dx = p1.x - p0.x;
  8563. this._dy = p1.y - p0.y;
  8564. this._quadrant = Quadrant.quadrant(this._dx, this._dy);
  8565. Assert.isTrue(!(this._dx === 0 && this._dy === 0), 'EdgeEnd with identical endpoints found');
  8566. };
  8567. EdgeEnd.prototype.interfaces_ = function interfaces_ () {
  8568. return [Comparable]
  8569. };
  8570. EdgeEnd.prototype.getClass = function getClass () {
  8571. return EdgeEnd
  8572. };
  8573. var DirectedEdge = (function (EdgeEnd$$1) {
  8574. function DirectedEdge () {
  8575. var edge = arguments[0];
  8576. var isForward = arguments[1];
  8577. EdgeEnd$$1.call(this, edge);
  8578. this._isForward = null;
  8579. this._isInResult = false;
  8580. this._isVisited = false;
  8581. this._sym = null;
  8582. this._next = null;
  8583. this._nextMin = null;
  8584. this._edgeRing = null;
  8585. this._minEdgeRing = null;
  8586. this._depth = [0, -999, -999];
  8587. this._isForward = isForward;
  8588. if (isForward) {
  8589. this.init(edge.getCoordinate(0), edge.getCoordinate(1));
  8590. } else {
  8591. var n = edge.getNumPoints() - 1;
  8592. this.init(edge.getCoordinate(n), edge.getCoordinate(n - 1));
  8593. }
  8594. this.computeDirectedLabel();
  8595. }
  8596. if ( EdgeEnd$$1 ) DirectedEdge.__proto__ = EdgeEnd$$1;
  8597. DirectedEdge.prototype = Object.create( EdgeEnd$$1 && EdgeEnd$$1.prototype );
  8598. DirectedEdge.prototype.constructor = DirectedEdge;
  8599. DirectedEdge.prototype.getNextMin = function getNextMin () {
  8600. return this._nextMin
  8601. };
  8602. DirectedEdge.prototype.getDepth = function getDepth (position) {
  8603. return this._depth[position]
  8604. };
  8605. DirectedEdge.prototype.setVisited = function setVisited (isVisited) {
  8606. this._isVisited = isVisited;
  8607. };
  8608. DirectedEdge.prototype.computeDirectedLabel = function computeDirectedLabel () {
  8609. this._label = new Label(this._edge.getLabel());
  8610. if (!this._isForward) { this._label.flip(); }
  8611. };
  8612. DirectedEdge.prototype.getNext = function getNext () {
  8613. return this._next
  8614. };
  8615. DirectedEdge.prototype.setDepth = function setDepth (position, depthVal) {
  8616. if (this._depth[position] !== -999) {
  8617. if (this._depth[position] !== depthVal) { throw new TopologyException('assigned depths do not match', this.getCoordinate()) }
  8618. }
  8619. this._depth[position] = depthVal;
  8620. };
  8621. DirectedEdge.prototype.isInteriorAreaEdge = function isInteriorAreaEdge () {
  8622. var this$1 = this;
  8623. var isInteriorAreaEdge = true;
  8624. for (var i = 0; i < 2; i++) {
  8625. if (!(this$1._label.isArea(i) && this$1._label.getLocation(i, Position.LEFT) === Location.INTERIOR && this$1._label.getLocation(i, Position.RIGHT) === Location.INTERIOR)) {
  8626. isInteriorAreaEdge = false;
  8627. }
  8628. }
  8629. return isInteriorAreaEdge
  8630. };
  8631. DirectedEdge.prototype.setNextMin = function setNextMin (nextMin) {
  8632. this._nextMin = nextMin;
  8633. };
  8634. DirectedEdge.prototype.print = function print (out) {
  8635. EdgeEnd$$1.prototype.print.call(this, out);
  8636. out.print(' ' + this._depth[Position.LEFT] + '/' + this._depth[Position.RIGHT]);
  8637. out.print(' (' + this.getDepthDelta() + ')');
  8638. if (this._isInResult) { out.print(' inResult'); }
  8639. };
  8640. DirectedEdge.prototype.setMinEdgeRing = function setMinEdgeRing (minEdgeRing) {
  8641. this._minEdgeRing = minEdgeRing;
  8642. };
  8643. DirectedEdge.prototype.isLineEdge = function isLineEdge () {
  8644. var isLine = this._label.isLine(0) || this._label.isLine(1);
  8645. var isExteriorIfArea0 = !this._label.isArea(0) || this._label.allPositionsEqual(0, Location.EXTERIOR);
  8646. var isExteriorIfArea1 = !this._label.isArea(1) || this._label.allPositionsEqual(1, Location.EXTERIOR);
  8647. return isLine && isExteriorIfArea0 && isExteriorIfArea1
  8648. };
  8649. DirectedEdge.prototype.setEdgeRing = function setEdgeRing (edgeRing) {
  8650. this._edgeRing = edgeRing;
  8651. };
  8652. DirectedEdge.prototype.getMinEdgeRing = function getMinEdgeRing () {
  8653. return this._minEdgeRing
  8654. };
  8655. DirectedEdge.prototype.getDepthDelta = function getDepthDelta () {
  8656. var depthDelta = this._edge.getDepthDelta();
  8657. if (!this._isForward) { depthDelta = -depthDelta; }
  8658. return depthDelta
  8659. };
  8660. DirectedEdge.prototype.setInResult = function setInResult (isInResult) {
  8661. this._isInResult = isInResult;
  8662. };
  8663. DirectedEdge.prototype.getSym = function getSym () {
  8664. return this._sym
  8665. };
  8666. DirectedEdge.prototype.isForward = function isForward () {
  8667. return this._isForward
  8668. };
  8669. DirectedEdge.prototype.getEdge = function getEdge () {
  8670. return this._edge
  8671. };
  8672. DirectedEdge.prototype.printEdge = function printEdge (out) {
  8673. this.print(out);
  8674. out.print(' ');
  8675. if (this._isForward) { this._edge.print(out); } else { this._edge.printReverse(out); }
  8676. };
  8677. DirectedEdge.prototype.setSym = function setSym (de) {
  8678. this._sym = de;
  8679. };
  8680. DirectedEdge.prototype.setVisitedEdge = function setVisitedEdge (isVisited) {
  8681. this.setVisited(isVisited);
  8682. this._sym.setVisited(isVisited);
  8683. };
  8684. DirectedEdge.prototype.setEdgeDepths = function setEdgeDepths (position, depth) {
  8685. var depthDelta = this.getEdge().getDepthDelta();
  8686. if (!this._isForward) { depthDelta = -depthDelta; }
  8687. var directionFactor = 1;
  8688. if (position === Position.LEFT) { directionFactor = -1; }
  8689. var oppositePos = Position.opposite(position);
  8690. var delta = depthDelta * directionFactor;
  8691. var oppositeDepth = depth + delta;
  8692. this.setDepth(position, depth);
  8693. this.setDepth(oppositePos, oppositeDepth);
  8694. };
  8695. DirectedEdge.prototype.getEdgeRing = function getEdgeRing () {
  8696. return this._edgeRing
  8697. };
  8698. DirectedEdge.prototype.isInResult = function isInResult () {
  8699. return this._isInResult
  8700. };
  8701. DirectedEdge.prototype.setNext = function setNext (next) {
  8702. this._next = next;
  8703. };
  8704. DirectedEdge.prototype.isVisited = function isVisited () {
  8705. return this._isVisited
  8706. };
  8707. DirectedEdge.prototype.interfaces_ = function interfaces_ () {
  8708. return []
  8709. };
  8710. DirectedEdge.prototype.getClass = function getClass () {
  8711. return DirectedEdge
  8712. };
  8713. DirectedEdge.depthFactor = function depthFactor (currLocation, nextLocation) {
  8714. if (currLocation === Location.EXTERIOR && nextLocation === Location.INTERIOR) { return 1; } else if (currLocation === Location.INTERIOR && nextLocation === Location.EXTERIOR) { return -1 }
  8715. return 0
  8716. };
  8717. return DirectedEdge;
  8718. }(EdgeEnd));
  8719. var NodeFactory = function NodeFactory () {};
  8720. NodeFactory.prototype.createNode = function createNode (coord) {
  8721. return new Node(coord, null)
  8722. };
  8723. NodeFactory.prototype.interfaces_ = function interfaces_ () {
  8724. return []
  8725. };
  8726. NodeFactory.prototype.getClass = function getClass () {
  8727. return NodeFactory
  8728. };
  8729. var PlanarGraph = function PlanarGraph () {
  8730. this._edges = new ArrayList();
  8731. this._nodes = null;
  8732. this._edgeEndList = new ArrayList();
  8733. if (arguments.length === 0) {
  8734. this._nodes = new NodeMap(new NodeFactory());
  8735. } else if (arguments.length === 1) {
  8736. var nodeFact = arguments[0];
  8737. this._nodes = new NodeMap(nodeFact);
  8738. }
  8739. };
  8740. PlanarGraph.prototype.printEdges = function printEdges (out) {
  8741. var this$1 = this;
  8742. out.println('Edges:');
  8743. for (var i = 0; i < this._edges.size(); i++) {
  8744. out.println('edge ' + i + ':');
  8745. var e = this$1._edges.get(i);
  8746. e.print(out);
  8747. e.eiList.print(out);
  8748. }
  8749. };
  8750. PlanarGraph.prototype.find = function find (coord) {
  8751. return this._nodes.find(coord)
  8752. };
  8753. PlanarGraph.prototype.addNode = function addNode () {
  8754. if (arguments[0] instanceof Node) {
  8755. var node = arguments[0];
  8756. return this._nodes.addNode(node)
  8757. } else if (arguments[0] instanceof Coordinate) {
  8758. var coord = arguments[0];
  8759. return this._nodes.addNode(coord)
  8760. }
  8761. };
  8762. PlanarGraph.prototype.getNodeIterator = function getNodeIterator () {
  8763. return this._nodes.iterator()
  8764. };
  8765. PlanarGraph.prototype.linkResultDirectedEdges = function linkResultDirectedEdges () {
  8766. for (var nodeit = this._nodes.iterator(); nodeit.hasNext();) {
  8767. var node = nodeit.next();
  8768. node.getEdges().linkResultDirectedEdges();
  8769. }
  8770. };
  8771. PlanarGraph.prototype.debugPrintln = function debugPrintln (o) {
  8772. System.out.println(o);
  8773. };
  8774. PlanarGraph.prototype.isBoundaryNode = function isBoundaryNode (geomIndex, coord) {
  8775. var node = this._nodes.find(coord);
  8776. if (node === null) { return false }
  8777. var label = node.getLabel();
  8778. if (label !== null && label.getLocation(geomIndex) === Location.BOUNDARY) { return true }
  8779. return false
  8780. };
  8781. PlanarGraph.prototype.linkAllDirectedEdges = function linkAllDirectedEdges () {
  8782. for (var nodeit = this._nodes.iterator(); nodeit.hasNext();) {
  8783. var node = nodeit.next();
  8784. node.getEdges().linkAllDirectedEdges();
  8785. }
  8786. };
  8787. PlanarGraph.prototype.matchInSameDirection = function matchInSameDirection (p0, p1, ep0, ep1) {
  8788. if (!p0.equals(ep0)) { return false }
  8789. if (CGAlgorithms.computeOrientation(p0, p1, ep1) === CGAlgorithms.COLLINEAR && Quadrant.quadrant(p0, p1) === Quadrant.quadrant(ep0, ep1)) { return true }
  8790. return false
  8791. };
  8792. PlanarGraph.prototype.getEdgeEnds = function getEdgeEnds () {
  8793. return this._edgeEndList
  8794. };
  8795. PlanarGraph.prototype.debugPrint = function debugPrint (o) {
  8796. System.out.print(o);
  8797. };
  8798. PlanarGraph.prototype.getEdgeIterator = function getEdgeIterator () {
  8799. return this._edges.iterator()
  8800. };
  8801. PlanarGraph.prototype.findEdgeInSameDirection = function findEdgeInSameDirection (p0, p1) {
  8802. var this$1 = this;
  8803. for (var i = 0; i < this._edges.size(); i++) {
  8804. var e = this$1._edges.get(i);
  8805. var eCoord = e.getCoordinates();
  8806. if (this$1.matchInSameDirection(p0, p1, eCoord[0], eCoord[1])) { return e }
  8807. if (this$1.matchInSameDirection(p0, p1, eCoord[eCoord.length - 1], eCoord[eCoord.length - 2])) { return e }
  8808. }
  8809. return null
  8810. };
  8811. PlanarGraph.prototype.insertEdge = function insertEdge (e) {
  8812. this._edges.add(e);
  8813. };
  8814. PlanarGraph.prototype.findEdgeEnd = function findEdgeEnd (e) {
  8815. for (var i = this.getEdgeEnds().iterator(); i.hasNext();) {
  8816. var ee = i.next();
  8817. if (ee.getEdge() === e) { return ee }
  8818. }
  8819. return null
  8820. };
  8821. PlanarGraph.prototype.addEdges = function addEdges (edgesToAdd) {
  8822. var this$1 = this;
  8823. for (var it = edgesToAdd.iterator(); it.hasNext();) {
  8824. var e = it.next();
  8825. this$1._edges.add(e);
  8826. var de1 = new DirectedEdge(e, true);
  8827. var de2 = new DirectedEdge(e, false);
  8828. de1.setSym(de2);
  8829. de2.setSym(de1);
  8830. this$1.add(de1);
  8831. this$1.add(de2);
  8832. }
  8833. };
  8834. PlanarGraph.prototype.add = function add (e) {
  8835. this._nodes.add(e);
  8836. this._edgeEndList.add(e);
  8837. };
  8838. PlanarGraph.prototype.getNodes = function getNodes () {
  8839. return this._nodes.values()
  8840. };
  8841. PlanarGraph.prototype.findEdge = function findEdge (p0, p1) {
  8842. var this$1 = this;
  8843. for (var i = 0; i < this._edges.size(); i++) {
  8844. var e = this$1._edges.get(i);
  8845. var eCoord = e.getCoordinates();
  8846. if (p0.equals(eCoord[0]) && p1.equals(eCoord[1])) { return e }
  8847. }
  8848. return null
  8849. };
  8850. PlanarGraph.prototype.interfaces_ = function interfaces_ () {
  8851. return []
  8852. };
  8853. PlanarGraph.prototype.getClass = function getClass () {
  8854. return PlanarGraph
  8855. };
  8856. PlanarGraph.linkResultDirectedEdges = function linkResultDirectedEdges (nodes) {
  8857. for (var nodeit = nodes.iterator(); nodeit.hasNext();) {
  8858. var node = nodeit.next();
  8859. node.getEdges().linkResultDirectedEdges();
  8860. }
  8861. };
  8862. var PolygonBuilder = function PolygonBuilder () {
  8863. this._geometryFactory = null;
  8864. this._shellList = new ArrayList();
  8865. var geometryFactory = arguments[0];
  8866. this._geometryFactory = geometryFactory;
  8867. };
  8868. PolygonBuilder.prototype.sortShellsAndHoles = function sortShellsAndHoles (edgeRings, shellList, freeHoleList) {
  8869. for (var it = edgeRings.iterator(); it.hasNext();) {
  8870. var er = it.next();
  8871. if (er.isHole()) {
  8872. freeHoleList.add(er);
  8873. } else {
  8874. shellList.add(er);
  8875. }
  8876. }
  8877. };
  8878. PolygonBuilder.prototype.computePolygons = function computePolygons (shellList) {
  8879. var this$1 = this;
  8880. var resultPolyList = new ArrayList();
  8881. for (var it = shellList.iterator(); it.hasNext();) {
  8882. var er = it.next();
  8883. var poly = er.toPolygon(this$1._geometryFactory);
  8884. resultPolyList.add(poly);
  8885. }
  8886. return resultPolyList
  8887. };
  8888. PolygonBuilder.prototype.placeFreeHoles = function placeFreeHoles (shellList, freeHoleList) {
  8889. var this$1 = this;
  8890. for (var it = freeHoleList.iterator(); it.hasNext();) {
  8891. var hole = it.next();
  8892. if (hole.getShell() === null) {
  8893. var shell = this$1.findEdgeRingContaining(hole, shellList);
  8894. if (shell === null) { throw new TopologyException('unable to assign hole to a shell', hole.getCoordinate(0)) }
  8895. hole.setShell(shell);
  8896. }
  8897. }
  8898. };
  8899. PolygonBuilder.prototype.buildMinimalEdgeRings = function buildMinimalEdgeRings (maxEdgeRings, shellList, freeHoleList) {
  8900. var this$1 = this;
  8901. var edgeRings = new ArrayList();
  8902. for (var it = maxEdgeRings.iterator(); it.hasNext();) {
  8903. var er = it.next();
  8904. if (er.getMaxNodeDegree() > 2) {
  8905. er.linkDirectedEdgesForMinimalEdgeRings();
  8906. var minEdgeRings = er.buildMinimalRings();
  8907. var shell = this$1.findShell(minEdgeRings);
  8908. if (shell !== null) {
  8909. this$1.placePolygonHoles(shell, minEdgeRings);
  8910. shellList.add(shell);
  8911. } else {
  8912. freeHoleList.addAll(minEdgeRings);
  8913. }
  8914. } else {
  8915. edgeRings.add(er);
  8916. }
  8917. }
  8918. return edgeRings
  8919. };
  8920. PolygonBuilder.prototype.containsPoint = function containsPoint (p) {
  8921. for (var it = this._shellList.iterator(); it.hasNext();) {
  8922. var er = it.next();
  8923. if (er.containsPoint(p)) { return true }
  8924. }
  8925. return false
  8926. };
  8927. PolygonBuilder.prototype.buildMaximalEdgeRings = function buildMaximalEdgeRings (dirEdges) {
  8928. var this$1 = this;
  8929. var maxEdgeRings = new ArrayList();
  8930. for (var it = dirEdges.iterator(); it.hasNext();) {
  8931. var de = it.next();
  8932. if (de.isInResult() && de.getLabel().isArea()) {
  8933. if (de.getEdgeRing() === null) {
  8934. var er = new MaximalEdgeRing(de, this$1._geometryFactory);
  8935. maxEdgeRings.add(er);
  8936. er.setInResult();
  8937. }
  8938. }
  8939. }
  8940. return maxEdgeRings
  8941. };
  8942. PolygonBuilder.prototype.placePolygonHoles = function placePolygonHoles (shell, minEdgeRings) {
  8943. for (var it = minEdgeRings.iterator(); it.hasNext();) {
  8944. var er = it.next();
  8945. if (er.isHole()) {
  8946. er.setShell(shell);
  8947. }
  8948. }
  8949. };
  8950. PolygonBuilder.prototype.getPolygons = function getPolygons () {
  8951. var resultPolyList = this.computePolygons(this._shellList);
  8952. return resultPolyList
  8953. };
  8954. PolygonBuilder.prototype.findEdgeRingContaining = function findEdgeRingContaining (testEr, shellList) {
  8955. var testRing = testEr.getLinearRing();
  8956. var testEnv = testRing.getEnvelopeInternal();
  8957. var testPt = testRing.getCoordinateN(0);
  8958. var minShell = null;
  8959. var minEnv = null;
  8960. for (var it = shellList.iterator(); it.hasNext();) {
  8961. var tryShell = it.next();
  8962. var tryRing = tryShell.getLinearRing();
  8963. var tryEnv = tryRing.getEnvelopeInternal();
  8964. if (minShell !== null) { minEnv = minShell.getLinearRing().getEnvelopeInternal(); }
  8965. var isContained = false;
  8966. if (tryEnv.contains(testEnv) && CGAlgorithms.isPointInRing(testPt, tryRing.getCoordinates())) { isContained = true; }
  8967. if (isContained) {
  8968. if (minShell === null || minEnv.contains(tryEnv)) {
  8969. minShell = tryShell;
  8970. }
  8971. }
  8972. }
  8973. return minShell
  8974. };
  8975. PolygonBuilder.prototype.findShell = function findShell (minEdgeRings) {
  8976. var shellCount = 0;
  8977. var shell = null;
  8978. for (var it = minEdgeRings.iterator(); it.hasNext();) {
  8979. var er = it.next();
  8980. if (!er.isHole()) {
  8981. shell = er;
  8982. shellCount++;
  8983. }
  8984. }
  8985. Assert.isTrue(shellCount <= 1, 'found two shells in MinimalEdgeRing list');
  8986. return shell
  8987. };
  8988. PolygonBuilder.prototype.add = function add () {
  8989. if (arguments.length === 1) {
  8990. var graph = arguments[0];
  8991. this.add(graph.getEdgeEnds(), graph.getNodes());
  8992. } else if (arguments.length === 2) {
  8993. var dirEdges = arguments[0];
  8994. var nodes = arguments[1];
  8995. PlanarGraph.linkResultDirectedEdges(nodes);
  8996. var maxEdgeRings = this.buildMaximalEdgeRings(dirEdges);
  8997. var freeHoleList = new ArrayList();
  8998. var edgeRings = this.buildMinimalEdgeRings(maxEdgeRings, this._shellList, freeHoleList);
  8999. this.sortShellsAndHoles(edgeRings, this._shellList, freeHoleList);
  9000. this.placeFreeHoles(this._shellList, freeHoleList);
  9001. }
  9002. };
  9003. PolygonBuilder.prototype.interfaces_ = function interfaces_ () {
  9004. return []
  9005. };
  9006. PolygonBuilder.prototype.getClass = function getClass () {
  9007. return PolygonBuilder
  9008. };
  9009. var Boundable = function Boundable () {};
  9010. Boundable.prototype.getBounds = function getBounds () {};
  9011. Boundable.prototype.interfaces_ = function interfaces_ () {
  9012. return []
  9013. };
  9014. Boundable.prototype.getClass = function getClass () {
  9015. return Boundable
  9016. };
  9017. var ItemBoundable = function ItemBoundable () {
  9018. this._bounds = null;
  9019. this._item = null;
  9020. var bounds = arguments[0];
  9021. var item = arguments[1];
  9022. this._bounds = bounds;
  9023. this._item = item;
  9024. };
  9025. ItemBoundable.prototype.getItem = function getItem () {
  9026. return this._item
  9027. };
  9028. ItemBoundable.prototype.getBounds = function getBounds () {
  9029. return this._bounds
  9030. };
  9031. ItemBoundable.prototype.interfaces_ = function interfaces_ () {
  9032. return [Boundable, Serializable]
  9033. };
  9034. ItemBoundable.prototype.getClass = function getClass () {
  9035. return ItemBoundable
  9036. };
  9037. var PriorityQueue = function PriorityQueue () {
  9038. this._size = null;
  9039. this._items = null;
  9040. this._size = 0;
  9041. this._items = new ArrayList();
  9042. this._items.add(null);
  9043. };
  9044. PriorityQueue.prototype.poll = function poll () {
  9045. if (this.isEmpty()) { return null }
  9046. var minItem = this._items.get(1);
  9047. this._items.set(1, this._items.get(this._size));
  9048. this._size -= 1;
  9049. this.reorder(1);
  9050. return minItem
  9051. };
  9052. PriorityQueue.prototype.size = function size () {
  9053. return this._size
  9054. };
  9055. PriorityQueue.prototype.reorder = function reorder (hole) {
  9056. var this$1 = this;
  9057. var child = null;
  9058. var tmp = this._items.get(hole);
  9059. for (; hole * 2 <= this._size; hole = child) {
  9060. child = hole * 2;
  9061. if (child !== this$1._size && this$1._items.get(child + 1).compareTo(this$1._items.get(child)) < 0) { child++; }
  9062. if (this$1._items.get(child).compareTo(tmp) < 0) { this$1._items.set(hole, this$1._items.get(child)); } else { break }
  9063. }
  9064. this._items.set(hole, tmp);
  9065. };
  9066. PriorityQueue.prototype.clear = function clear () {
  9067. this._size = 0;
  9068. this._items.clear();
  9069. };
  9070. PriorityQueue.prototype.isEmpty = function isEmpty () {
  9071. return this._size === 0
  9072. };
  9073. PriorityQueue.prototype.add = function add (x) {
  9074. var this$1 = this;
  9075. this._items.add(null);
  9076. this._size += 1;
  9077. var hole = this._size;
  9078. this._items.set(0, x);
  9079. for (; x.compareTo(this._items.get(Math.trunc(hole / 2))) < 0; hole /= 2) {
  9080. this$1._items.set(hole, this$1._items.get(Math.trunc(hole / 2)));
  9081. }
  9082. this._items.set(hole, x);
  9083. };
  9084. PriorityQueue.prototype.interfaces_ = function interfaces_ () {
  9085. return []
  9086. };
  9087. PriorityQueue.prototype.getClass = function getClass () {
  9088. return PriorityQueue
  9089. };
  9090. var ItemVisitor = function ItemVisitor () {};
  9091. ItemVisitor.prototype.visitItem = function visitItem (item) {};
  9092. ItemVisitor.prototype.interfaces_ = function interfaces_ () {
  9093. return []
  9094. };
  9095. ItemVisitor.prototype.getClass = function getClass () {
  9096. return ItemVisitor
  9097. };
  9098. var SpatialIndex = function SpatialIndex () {};
  9099. SpatialIndex.prototype.insert = function insert (itemEnv, item) {};
  9100. SpatialIndex.prototype.remove = function remove (itemEnv, item) {};
  9101. SpatialIndex.prototype.query = function query () {
  9102. // if (arguments.length === 1) {
  9103. // const searchEnv = arguments[0]
  9104. // } else if (arguments.length === 2) {
  9105. // const searchEnv = arguments[0]
  9106. // const visitor = arguments[1]
  9107. // }
  9108. };
  9109. SpatialIndex.prototype.interfaces_ = function interfaces_ () {
  9110. return []
  9111. };
  9112. SpatialIndex.prototype.getClass = function getClass () {
  9113. return SpatialIndex
  9114. };
  9115. var AbstractNode = function AbstractNode () {
  9116. this._childBoundables = new ArrayList();
  9117. this._bounds = null;
  9118. this._level = null;
  9119. if (arguments.length === 0) {} else if (arguments.length === 1) {
  9120. var level = arguments[0];
  9121. this._level = level;
  9122. }
  9123. };
  9124. var staticAccessors$22 = { serialVersionUID: { configurable: true } };
  9125. AbstractNode.prototype.getLevel = function getLevel () {
  9126. return this._level
  9127. };
  9128. AbstractNode.prototype.size = function size () {
  9129. return this._childBoundables.size()
  9130. };
  9131. AbstractNode.prototype.getChildBoundables = function getChildBoundables () {
  9132. return this._childBoundables
  9133. };
  9134. AbstractNode.prototype.addChildBoundable = function addChildBoundable (childBoundable) {
  9135. Assert.isTrue(this._bounds === null);
  9136. this._childBoundables.add(childBoundable);
  9137. };
  9138. AbstractNode.prototype.isEmpty = function isEmpty () {
  9139. return this._childBoundables.isEmpty()
  9140. };
  9141. AbstractNode.prototype.getBounds = function getBounds () {
  9142. if (this._bounds === null) {
  9143. this._bounds = this.computeBounds();
  9144. }
  9145. return this._bounds
  9146. };
  9147. AbstractNode.prototype.interfaces_ = function interfaces_ () {
  9148. return [Boundable, Serializable]
  9149. };
  9150. AbstractNode.prototype.getClass = function getClass () {
  9151. return AbstractNode
  9152. };
  9153. staticAccessors$22.serialVersionUID.get = function () { return 6493722185909573708 };
  9154. Object.defineProperties( AbstractNode, staticAccessors$22 );
  9155. var Collections = function Collections () {};
  9156. Collections.reverseOrder = function reverseOrder () {
  9157. return {
  9158. compare: function compare (a, b) {
  9159. return b.compareTo(a)
  9160. }
  9161. }
  9162. };
  9163. Collections.min = function min (l) {
  9164. Collections.sort(l);
  9165. return l.get(0)
  9166. };
  9167. Collections.sort = function sort (l, c) {
  9168. var a = l.toArray();
  9169. if (c) {
  9170. Arrays.sort(a, c);
  9171. } else {
  9172. Arrays.sort(a);
  9173. }
  9174. var i = l.iterator();
  9175. for (var pos = 0, alen = a.length; pos < alen; pos++) {
  9176. i.next();
  9177. i.set(a[pos]);
  9178. }
  9179. };
  9180. Collections.singletonList = function singletonList (o) {
  9181. var arrayList = new ArrayList();
  9182. arrayList.add(o);
  9183. return arrayList
  9184. };
  9185. var BoundablePair = function BoundablePair () {
  9186. this._boundable1 = null;
  9187. this._boundable2 = null;
  9188. this._distance = null;
  9189. this._itemDistance = null;
  9190. var boundable1 = arguments[0];
  9191. var boundable2 = arguments[1];
  9192. var itemDistance = arguments[2];
  9193. this._boundable1 = boundable1;
  9194. this._boundable2 = boundable2;
  9195. this._itemDistance = itemDistance;
  9196. this._distance = this.distance();
  9197. };
  9198. BoundablePair.prototype.expandToQueue = function expandToQueue (priQ, minDistance) {
  9199. var isComp1 = BoundablePair.isComposite(this._boundable1);
  9200. var isComp2 = BoundablePair.isComposite(this._boundable2);
  9201. if (isComp1 && isComp2) {
  9202. if (BoundablePair.area(this._boundable1) > BoundablePair.area(this._boundable2)) {
  9203. this.expand(this._boundable1, this._boundable2, priQ, minDistance);
  9204. return null
  9205. } else {
  9206. this.expand(this._boundable2, this._boundable1, priQ, minDistance);
  9207. return null
  9208. }
  9209. } else if (isComp1) {
  9210. this.expand(this._boundable1, this._boundable2, priQ, minDistance);
  9211. return null
  9212. } else if (isComp2) {
  9213. this.expand(this._boundable2, this._boundable1, priQ, minDistance);
  9214. return null
  9215. }
  9216. throw new IllegalArgumentException('neither boundable is composite')
  9217. };
  9218. BoundablePair.prototype.isLeaves = function isLeaves () {
  9219. return !(BoundablePair.isComposite(this._boundable1) || BoundablePair.isComposite(this._boundable2))
  9220. };
  9221. BoundablePair.prototype.compareTo = function compareTo (o) {
  9222. var nd = o;
  9223. if (this._distance < nd._distance) { return -1 }
  9224. if (this._distance > nd._distance) { return 1 }
  9225. return 0
  9226. };
  9227. BoundablePair.prototype.expand = function expand (bndComposite, bndOther, priQ, minDistance) {
  9228. var this$1 = this;
  9229. var children = bndComposite.getChildBoundables();
  9230. for (var i = children.iterator(); i.hasNext();) {
  9231. var child = i.next();
  9232. var bp = new BoundablePair(child, bndOther, this$1._itemDistance);
  9233. if (bp.getDistance() < minDistance) {
  9234. priQ.add(bp);
  9235. }
  9236. }
  9237. };
  9238. BoundablePair.prototype.getBoundable = function getBoundable (i) {
  9239. if (i === 0) { return this._boundable1 }
  9240. return this._boundable2
  9241. };
  9242. BoundablePair.prototype.getDistance = function getDistance () {
  9243. return this._distance
  9244. };
  9245. BoundablePair.prototype.distance = function distance () {
  9246. if (this.isLeaves()) {
  9247. return this._itemDistance.distance(this._boundable1, this._boundable2)
  9248. }
  9249. return this._boundable1.getBounds().distance(this._boundable2.getBounds())
  9250. };
  9251. BoundablePair.prototype.interfaces_ = function interfaces_ () {
  9252. return [Comparable]
  9253. };
  9254. BoundablePair.prototype.getClass = function getClass () {
  9255. return BoundablePair
  9256. };
  9257. BoundablePair.area = function area (b) {
  9258. return b.getBounds().getArea()
  9259. };
  9260. BoundablePair.isComposite = function isComposite (item) {
  9261. return item instanceof AbstractNode
  9262. };
  9263. var AbstractSTRtree = function AbstractSTRtree () {
  9264. this._root = null;
  9265. this._built = false;
  9266. this._itemBoundables = new ArrayList();
  9267. this._nodeCapacity = null;
  9268. if (arguments.length === 0) {
  9269. var nodeCapacity = AbstractSTRtree.DEFAULT_NODE_CAPACITY;
  9270. this._nodeCapacity = nodeCapacity;
  9271. } else if (arguments.length === 1) {
  9272. var nodeCapacity$1 = arguments[0];
  9273. Assert.isTrue(nodeCapacity$1 > 1, 'Node capacity must be greater than 1');
  9274. this._nodeCapacity = nodeCapacity$1;
  9275. }
  9276. };
  9277. var staticAccessors$23 = { IntersectsOp: { configurable: true },serialVersionUID: { configurable: true },DEFAULT_NODE_CAPACITY: { configurable: true } };
  9278. AbstractSTRtree.prototype.getNodeCapacity = function getNodeCapacity () {
  9279. return this._nodeCapacity
  9280. };
  9281. AbstractSTRtree.prototype.lastNode = function lastNode (nodes) {
  9282. return nodes.get(nodes.size() - 1)
  9283. };
  9284. AbstractSTRtree.prototype.size = function size () {
  9285. var this$1 = this;
  9286. if (arguments.length === 0) {
  9287. if (this.isEmpty()) {
  9288. return 0
  9289. }
  9290. this.build();
  9291. return this.size(this._root)
  9292. } else if (arguments.length === 1) {
  9293. var node = arguments[0];
  9294. var size = 0;
  9295. for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
  9296. var childBoundable = i.next();
  9297. if (childBoundable instanceof AbstractNode) {
  9298. size += this$1.size(childBoundable);
  9299. } else if (childBoundable instanceof ItemBoundable) {
  9300. size += 1;
  9301. }
  9302. }
  9303. return size
  9304. }
  9305. };
  9306. AbstractSTRtree.prototype.removeItem = function removeItem (node, item) {
  9307. var childToRemove = null;
  9308. for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
  9309. var childBoundable = i.next();
  9310. if (childBoundable instanceof ItemBoundable) {
  9311. if (childBoundable.getItem() === item) { childToRemove = childBoundable; }
  9312. }
  9313. }
  9314. if (childToRemove !== null) {
  9315. node.getChildBoundables().remove(childToRemove);
  9316. return true
  9317. }
  9318. return false
  9319. };
  9320. AbstractSTRtree.prototype.itemsTree = function itemsTree () {
  9321. var this$1 = this;
  9322. if (arguments.length === 0) {
  9323. this.build();
  9324. var valuesTree = this.itemsTree(this._root);
  9325. if (valuesTree === null) { return new ArrayList() }
  9326. return valuesTree
  9327. } else if (arguments.length === 1) {
  9328. var node = arguments[0];
  9329. var valuesTreeForNode = new ArrayList();
  9330. for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
  9331. var childBoundable = i.next();
  9332. if (childBoundable instanceof AbstractNode) {
  9333. var valuesTreeForChild = this$1.itemsTree(childBoundable);
  9334. if (valuesTreeForChild !== null) { valuesTreeForNode.add(valuesTreeForChild); }
  9335. } else if (childBoundable instanceof ItemBoundable) {
  9336. valuesTreeForNode.add(childBoundable.getItem());
  9337. } else {
  9338. Assert.shouldNeverReachHere();
  9339. }
  9340. }
  9341. if (valuesTreeForNode.size() <= 0) { return null }
  9342. return valuesTreeForNode
  9343. }
  9344. };
  9345. AbstractSTRtree.prototype.insert = function insert (bounds, item) {
  9346. Assert.isTrue(!this._built, 'Cannot insert items into an STR packed R-tree after it has been built.');
  9347. this._itemBoundables.add(new ItemBoundable(bounds, item));
  9348. };
  9349. AbstractSTRtree.prototype.boundablesAtLevel = function boundablesAtLevel () {
  9350. var this$1 = this;
  9351. if (arguments.length === 1) {
  9352. var level = arguments[0];
  9353. var boundables = new ArrayList();
  9354. this.boundablesAtLevel(level, this._root, boundables);
  9355. return boundables
  9356. } else if (arguments.length === 3) {
  9357. var level$1 = arguments[0];
  9358. var top = arguments[1];
  9359. var boundables$1 = arguments[2];
  9360. Assert.isTrue(level$1 > -2);
  9361. if (top.getLevel() === level$1) {
  9362. boundables$1.add(top);
  9363. return null
  9364. }
  9365. for (var i = top.getChildBoundables().iterator(); i.hasNext();) {
  9366. var boundable = i.next();
  9367. if (boundable instanceof AbstractNode) {
  9368. this$1.boundablesAtLevel(level$1, boundable, boundables$1);
  9369. } else {
  9370. Assert.isTrue(boundable instanceof ItemBoundable);
  9371. if (level$1 === -1) {
  9372. boundables$1.add(boundable);
  9373. }
  9374. }
  9375. }
  9376. return null
  9377. }
  9378. };
  9379. AbstractSTRtree.prototype.query = function query () {
  9380. var this$1 = this;
  9381. if (arguments.length === 1) {
  9382. var searchBounds = arguments[0];
  9383. this.build();
  9384. var matches = new ArrayList();
  9385. if (this.isEmpty()) {
  9386. return matches
  9387. }
  9388. if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds)) {
  9389. this.query(searchBounds, this._root, matches);
  9390. }
  9391. return matches
  9392. } else if (arguments.length === 2) {
  9393. var searchBounds$1 = arguments[0];
  9394. var visitor = arguments[1];
  9395. this.build();
  9396. if (this.isEmpty()) {
  9397. return null
  9398. }
  9399. if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds$1)) {
  9400. this.query(searchBounds$1, this._root, visitor);
  9401. }
  9402. } else if (arguments.length === 3) {
  9403. if (hasInterface(arguments[2], ItemVisitor) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
  9404. var searchBounds$2 = arguments[0];
  9405. var node = arguments[1];
  9406. var visitor$1 = arguments[2];
  9407. var childBoundables = node.getChildBoundables();
  9408. for (var i = 0; i < childBoundables.size(); i++) {
  9409. var childBoundable = childBoundables.get(i);
  9410. if (!this$1.getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds$2)) {
  9411. continue
  9412. }
  9413. if (childBoundable instanceof AbstractNode) {
  9414. this$1.query(searchBounds$2, childBoundable, visitor$1);
  9415. } else if (childBoundable instanceof ItemBoundable) {
  9416. visitor$1.visitItem(childBoundable.getItem());
  9417. } else {
  9418. Assert.shouldNeverReachHere();
  9419. }
  9420. }
  9421. } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
  9422. var searchBounds$3 = arguments[0];
  9423. var node$1 = arguments[1];
  9424. var matches$1 = arguments[2];
  9425. var childBoundables$1 = node$1.getChildBoundables();
  9426. for (var i$1 = 0; i$1 < childBoundables$1.size(); i$1++) {
  9427. var childBoundable$1 = childBoundables$1.get(i$1);
  9428. if (!this$1.getIntersectsOp().intersects(childBoundable$1.getBounds(), searchBounds$3)) {
  9429. continue
  9430. }
  9431. if (childBoundable$1 instanceof AbstractNode) {
  9432. this$1.query(searchBounds$3, childBoundable$1, matches$1);
  9433. } else if (childBoundable$1 instanceof ItemBoundable) {
  9434. matches$1.add(childBoundable$1.getItem());
  9435. } else {
  9436. Assert.shouldNeverReachHere();
  9437. }
  9438. }
  9439. }
  9440. }
  9441. };
  9442. AbstractSTRtree.prototype.build = function build () {
  9443. if (this._built) { return null }
  9444. this._root = this._itemBoundables.isEmpty() ? this.createNode(0) : this.createHigherLevels(this._itemBoundables, -1);
  9445. this._itemBoundables = null;
  9446. this._built = true;
  9447. };
  9448. AbstractSTRtree.prototype.getRoot = function getRoot () {
  9449. this.build();
  9450. return this._root
  9451. };
  9452. AbstractSTRtree.prototype.remove = function remove () {
  9453. var this$1 = this;
  9454. if (arguments.length === 2) {
  9455. var searchBounds = arguments[0];
  9456. var item = arguments[1];
  9457. this.build();
  9458. if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds)) {
  9459. return this.remove(searchBounds, this._root, item)
  9460. }
  9461. return false
  9462. } else if (arguments.length === 3) {
  9463. var searchBounds$1 = arguments[0];
  9464. var node = arguments[1];
  9465. var item$1 = arguments[2];
  9466. var found = this.removeItem(node, item$1);
  9467. if (found) { return true }
  9468. var childToPrune = null;
  9469. for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
  9470. var childBoundable = i.next();
  9471. if (!this$1.getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds$1)) {
  9472. continue
  9473. }
  9474. if (childBoundable instanceof AbstractNode) {
  9475. found = this$1.remove(searchBounds$1, childBoundable, item$1);
  9476. if (found) {
  9477. childToPrune = childBoundable;
  9478. break
  9479. }
  9480. }
  9481. }
  9482. if (childToPrune !== null) {
  9483. if (childToPrune.getChildBoundables().isEmpty()) {
  9484. node.getChildBoundables().remove(childToPrune);
  9485. }
  9486. }
  9487. return found
  9488. }
  9489. };
  9490. AbstractSTRtree.prototype.createHigherLevels = function createHigherLevels (boundablesOfALevel, level) {
  9491. Assert.isTrue(!boundablesOfALevel.isEmpty());
  9492. var parentBoundables = this.createParentBoundables(boundablesOfALevel, level + 1);
  9493. if (parentBoundables.size() === 1) {
  9494. return parentBoundables.get(0)
  9495. }
  9496. return this.createHigherLevels(parentBoundables, level + 1)
  9497. };
  9498. AbstractSTRtree.prototype.depth = function depth () {
  9499. var this$1 = this;
  9500. if (arguments.length === 0) {
  9501. if (this.isEmpty()) {
  9502. return 0
  9503. }
  9504. this.build();
  9505. return this.depth(this._root)
  9506. } else if (arguments.length === 1) {
  9507. var node = arguments[0];
  9508. var maxChildDepth = 0;
  9509. for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
  9510. var childBoundable = i.next();
  9511. if (childBoundable instanceof AbstractNode) {
  9512. var childDepth = this$1.depth(childBoundable);
  9513. if (childDepth > maxChildDepth) { maxChildDepth = childDepth; }
  9514. }
  9515. }
  9516. return maxChildDepth + 1
  9517. }
  9518. };
  9519. AbstractSTRtree.prototype.createParentBoundables = function createParentBoundables (childBoundables, newLevel) {
  9520. var this$1 = this;
  9521. Assert.isTrue(!childBoundables.isEmpty());
  9522. var parentBoundables = new ArrayList();
  9523. parentBoundables.add(this.createNode(newLevel));
  9524. var sortedChildBoundables = new ArrayList(childBoundables);
  9525. Collections.sort(sortedChildBoundables, this.getComparator());
  9526. for (var i = sortedChildBoundables.iterator(); i.hasNext();) {
  9527. var childBoundable = i.next();
  9528. if (this$1.lastNode(parentBoundables).getChildBoundables().size() === this$1.getNodeCapacity()) {
  9529. parentBoundables.add(this$1.createNode(newLevel));
  9530. }
  9531. this$1.lastNode(parentBoundables).addChildBoundable(childBoundable);
  9532. }
  9533. return parentBoundables
  9534. };
  9535. AbstractSTRtree.prototype.isEmpty = function isEmpty () {
  9536. if (!this._built) { return this._itemBoundables.isEmpty() }
  9537. return this._root.isEmpty()
  9538. };
  9539. AbstractSTRtree.prototype.interfaces_ = function interfaces_ () {
  9540. return [Serializable]
  9541. };
  9542. AbstractSTRtree.prototype.getClass = function getClass () {
  9543. return AbstractSTRtree
  9544. };
  9545. AbstractSTRtree.compareDoubles = function compareDoubles (a, b) {
  9546. return a > b ? 1 : a < b ? -1 : 0
  9547. };
  9548. staticAccessors$23.IntersectsOp.get = function () { return IntersectsOp };
  9549. staticAccessors$23.serialVersionUID.get = function () { return -3886435814360241337 };
  9550. staticAccessors$23.DEFAULT_NODE_CAPACITY.get = function () { return 10 };
  9551. Object.defineProperties( AbstractSTRtree, staticAccessors$23 );
  9552. var IntersectsOp = function IntersectsOp () {};
  9553. var ItemDistance = function ItemDistance () {};
  9554. ItemDistance.prototype.distance = function distance (item1, item2) {};
  9555. ItemDistance.prototype.interfaces_ = function interfaces_ () {
  9556. return []
  9557. };
  9558. ItemDistance.prototype.getClass = function getClass () {
  9559. return ItemDistance
  9560. };
  9561. var STRtree = (function (AbstractSTRtree$$1) {
  9562. function STRtree (nodeCapacity) {
  9563. nodeCapacity = nodeCapacity || STRtree.DEFAULT_NODE_CAPACITY;
  9564. AbstractSTRtree$$1.call(this, nodeCapacity);
  9565. }
  9566. if ( AbstractSTRtree$$1 ) STRtree.__proto__ = AbstractSTRtree$$1;
  9567. STRtree.prototype = Object.create( AbstractSTRtree$$1 && AbstractSTRtree$$1.prototype );
  9568. STRtree.prototype.constructor = STRtree;
  9569. var staticAccessors = { STRtreeNode: { configurable: true },serialVersionUID: { configurable: true },xComparator: { configurable: true },yComparator: { configurable: true },intersectsOp: { configurable: true },DEFAULT_NODE_CAPACITY: { configurable: true } };
  9570. STRtree.prototype.createParentBoundablesFromVerticalSlices = function createParentBoundablesFromVerticalSlices (verticalSlices, newLevel) {
  9571. var this$1 = this;
  9572. Assert.isTrue(verticalSlices.length > 0);
  9573. var parentBoundables = new ArrayList();
  9574. for (var i = 0; i < verticalSlices.length; i++) {
  9575. parentBoundables.addAll(this$1.createParentBoundablesFromVerticalSlice(verticalSlices[i], newLevel));
  9576. }
  9577. return parentBoundables
  9578. };
  9579. STRtree.prototype.createNode = function createNode (level) {
  9580. return new STRtreeNode(level)
  9581. };
  9582. STRtree.prototype.size = function size () {
  9583. if (arguments.length === 0) {
  9584. return AbstractSTRtree$$1.prototype.size.call(this)
  9585. } else { return AbstractSTRtree$$1.prototype.size.apply(this, arguments) }
  9586. };
  9587. STRtree.prototype.insert = function insert () {
  9588. if (arguments.length === 2) {
  9589. var itemEnv = arguments[0];
  9590. var item = arguments[1];
  9591. if (itemEnv.isNull()) {
  9592. return null
  9593. }
  9594. AbstractSTRtree$$1.prototype.insert.call(this, itemEnv, item);
  9595. } else { return AbstractSTRtree$$1.prototype.insert.apply(this, arguments) }
  9596. };
  9597. STRtree.prototype.getIntersectsOp = function getIntersectsOp () {
  9598. return STRtree.intersectsOp
  9599. };
  9600. STRtree.prototype.verticalSlices = function verticalSlices (childBoundables, sliceCount) {
  9601. var sliceCapacity = Math.trunc(Math.ceil(childBoundables.size() / sliceCount));
  9602. var slices = new Array(sliceCount).fill(null);
  9603. var i = childBoundables.iterator();
  9604. for (var j = 0; j < sliceCount; j++) {
  9605. slices[j] = new ArrayList();
  9606. var boundablesAddedToSlice = 0;
  9607. while (i.hasNext() && boundablesAddedToSlice < sliceCapacity) {
  9608. var childBoundable = i.next();
  9609. slices[j].add(childBoundable);
  9610. boundablesAddedToSlice++;
  9611. }
  9612. }
  9613. return slices
  9614. };
  9615. STRtree.prototype.query = function query () {
  9616. if (arguments.length === 1) {
  9617. var searchEnv = arguments[0];
  9618. return AbstractSTRtree$$1.prototype.query.call(this, searchEnv)
  9619. } else if (arguments.length === 2) {
  9620. var searchEnv$1 = arguments[0];
  9621. var visitor = arguments[1];
  9622. AbstractSTRtree$$1.prototype.query.call(this, searchEnv$1, visitor);
  9623. } else if (arguments.length === 3) {
  9624. if (hasInterface(arguments[2], ItemVisitor) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
  9625. var searchBounds = arguments[0];
  9626. var node = arguments[1];
  9627. var visitor$1 = arguments[2];
  9628. AbstractSTRtree$$1.prototype.query.call(this, searchBounds, node, visitor$1);
  9629. } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
  9630. var searchBounds$1 = arguments[0];
  9631. var node$1 = arguments[1];
  9632. var matches = arguments[2];
  9633. AbstractSTRtree$$1.prototype.query.call(this, searchBounds$1, node$1, matches);
  9634. }
  9635. }
  9636. };
  9637. STRtree.prototype.getComparator = function getComparator () {
  9638. return STRtree.yComparator
  9639. };
  9640. STRtree.prototype.createParentBoundablesFromVerticalSlice = function createParentBoundablesFromVerticalSlice (childBoundables, newLevel) {
  9641. return AbstractSTRtree$$1.prototype.createParentBoundables.call(this, childBoundables, newLevel)
  9642. };
  9643. STRtree.prototype.remove = function remove () {
  9644. if (arguments.length === 2) {
  9645. var itemEnv = arguments[0];
  9646. var item = arguments[1];
  9647. return AbstractSTRtree$$1.prototype.remove.call(this, itemEnv, item)
  9648. } else { return AbstractSTRtree$$1.prototype.remove.apply(this, arguments) }
  9649. };
  9650. STRtree.prototype.depth = function depth () {
  9651. if (arguments.length === 0) {
  9652. return AbstractSTRtree$$1.prototype.depth.call(this)
  9653. } else { return AbstractSTRtree$$1.prototype.depth.apply(this, arguments) }
  9654. };
  9655. STRtree.prototype.createParentBoundables = function createParentBoundables (childBoundables, newLevel) {
  9656. Assert.isTrue(!childBoundables.isEmpty());
  9657. var minLeafCount = Math.trunc(Math.ceil(childBoundables.size() / this.getNodeCapacity()));
  9658. var sortedChildBoundables = new ArrayList(childBoundables);
  9659. Collections.sort(sortedChildBoundables, STRtree.xComparator);
  9660. var verticalSlices = this.verticalSlices(sortedChildBoundables, Math.trunc(Math.ceil(Math.sqrt(minLeafCount))));
  9661. return this.createParentBoundablesFromVerticalSlices(verticalSlices, newLevel)
  9662. };
  9663. STRtree.prototype.nearestNeighbour = function nearestNeighbour () {
  9664. if (arguments.length === 1) {
  9665. if (hasInterface(arguments[0], ItemDistance)) {
  9666. var itemDist = arguments[0];
  9667. var bp = new BoundablePair(this.getRoot(), this.getRoot(), itemDist);
  9668. return this.nearestNeighbour(bp)
  9669. } else if (arguments[0] instanceof BoundablePair) {
  9670. var initBndPair = arguments[0];
  9671. return this.nearestNeighbour(initBndPair, Double.POSITIVE_INFINITY)
  9672. }
  9673. } else if (arguments.length === 2) {
  9674. if (arguments[0] instanceof STRtree && hasInterface(arguments[1], ItemDistance)) {
  9675. var tree = arguments[0];
  9676. var itemDist$1 = arguments[1];
  9677. var bp$1 = new BoundablePair(this.getRoot(), tree.getRoot(), itemDist$1);
  9678. return this.nearestNeighbour(bp$1)
  9679. } else if (arguments[0] instanceof BoundablePair && typeof arguments[1] === 'number') {
  9680. var initBndPair$1 = arguments[0];
  9681. var maxDistance = arguments[1];
  9682. var distanceLowerBound = maxDistance;
  9683. var minPair = null;
  9684. var priQ = new PriorityQueue();
  9685. priQ.add(initBndPair$1);
  9686. while (!priQ.isEmpty() && distanceLowerBound > 0.0) {
  9687. var bndPair = priQ.poll();
  9688. var currentDistance = bndPair.getDistance();
  9689. if (currentDistance >= distanceLowerBound) { break }
  9690. if (bndPair.isLeaves()) {
  9691. distanceLowerBound = currentDistance;
  9692. minPair = bndPair;
  9693. } else {
  9694. bndPair.expandToQueue(priQ, distanceLowerBound);
  9695. }
  9696. }
  9697. return [minPair.getBoundable(0).getItem(), minPair.getBoundable(1).getItem()]
  9698. }
  9699. } else if (arguments.length === 3) {
  9700. var env = arguments[0];
  9701. var item = arguments[1];
  9702. var itemDist$2 = arguments[2];
  9703. var bnd = new ItemBoundable(env, item);
  9704. var bp$2 = new BoundablePair(this.getRoot(), bnd, itemDist$2);
  9705. return this.nearestNeighbour(bp$2)[0]
  9706. }
  9707. };
  9708. STRtree.prototype.interfaces_ = function interfaces_ () {
  9709. return [SpatialIndex, Serializable]
  9710. };
  9711. STRtree.prototype.getClass = function getClass () {
  9712. return STRtree
  9713. };
  9714. STRtree.centreX = function centreX (e) {
  9715. return STRtree.avg(e.getMinX(), e.getMaxX())
  9716. };
  9717. STRtree.avg = function avg (a, b) {
  9718. return (a + b) / 2
  9719. };
  9720. STRtree.centreY = function centreY (e) {
  9721. return STRtree.avg(e.getMinY(), e.getMaxY())
  9722. };
  9723. staticAccessors.STRtreeNode.get = function () { return STRtreeNode };
  9724. staticAccessors.serialVersionUID.get = function () { return 259274702368956900 };
  9725. staticAccessors.xComparator.get = function () {
  9726. return {
  9727. interfaces_: function () {
  9728. return [Comparator]
  9729. },
  9730. compare: function (o1, o2) {
  9731. return AbstractSTRtree$$1.compareDoubles(STRtree.centreX(o1.getBounds()), STRtree.centreX(o2.getBounds()))
  9732. }
  9733. }
  9734. };
  9735. staticAccessors.yComparator.get = function () {
  9736. return {
  9737. interfaces_: function () {
  9738. return [Comparator]
  9739. },
  9740. compare: function (o1, o2) {
  9741. return AbstractSTRtree$$1.compareDoubles(STRtree.centreY(o1.getBounds()), STRtree.centreY(o2.getBounds()))
  9742. }
  9743. }
  9744. };
  9745. staticAccessors.intersectsOp.get = function () {
  9746. return {
  9747. interfaces_: function () {
  9748. return [AbstractSTRtree$$1.IntersectsOp]
  9749. },
  9750. intersects: function (aBounds, bBounds) {
  9751. return aBounds.intersects(bBounds)
  9752. }
  9753. }
  9754. };
  9755. staticAccessors.DEFAULT_NODE_CAPACITY.get = function () { return 10 };
  9756. Object.defineProperties( STRtree, staticAccessors );
  9757. return STRtree;
  9758. }(AbstractSTRtree));
  9759. var STRtreeNode = (function (AbstractNode$$1) {
  9760. function STRtreeNode () {
  9761. var level = arguments[0];
  9762. AbstractNode$$1.call(this, level);
  9763. }
  9764. if ( AbstractNode$$1 ) STRtreeNode.__proto__ = AbstractNode$$1;
  9765. STRtreeNode.prototype = Object.create( AbstractNode$$1 && AbstractNode$$1.prototype );
  9766. STRtreeNode.prototype.constructor = STRtreeNode;
  9767. STRtreeNode.prototype.computeBounds = function computeBounds () {
  9768. var bounds = null;
  9769. for (var i = this.getChildBoundables().iterator(); i.hasNext();) {
  9770. var childBoundable = i.next();
  9771. if (bounds === null) {
  9772. bounds = new Envelope(childBoundable.getBounds());
  9773. } else {
  9774. bounds.expandToInclude(childBoundable.getBounds());
  9775. }
  9776. }
  9777. return bounds
  9778. };
  9779. STRtreeNode.prototype.interfaces_ = function interfaces_ () {
  9780. return []
  9781. };
  9782. STRtreeNode.prototype.getClass = function getClass () {
  9783. return STRtreeNode
  9784. };
  9785. return STRtreeNode;
  9786. }(AbstractNode));
  9787. var SegmentPointComparator = function SegmentPointComparator () {};
  9788. SegmentPointComparator.prototype.interfaces_ = function interfaces_ () {
  9789. return []
  9790. };
  9791. SegmentPointComparator.prototype.getClass = function getClass () {
  9792. return SegmentPointComparator
  9793. };
  9794. SegmentPointComparator.relativeSign = function relativeSign (x0, x1) {
  9795. if (x0 < x1) { return -1 }
  9796. if (x0 > x1) { return 1 }
  9797. return 0
  9798. };
  9799. SegmentPointComparator.compare = function compare (octant, p0, p1) {
  9800. if (p0.equals2D(p1)) { return 0 }
  9801. var xSign = SegmentPointComparator.relativeSign(p0.x, p1.x);
  9802. var ySign = SegmentPointComparator.relativeSign(p0.y, p1.y);
  9803. switch (octant) {
  9804. case 0:
  9805. return SegmentPointComparator.compareValue(xSign, ySign)
  9806. case 1:
  9807. return SegmentPointComparator.compareValue(ySign, xSign)
  9808. case 2:
  9809. return SegmentPointComparator.compareValue(ySign, -xSign)
  9810. case 3:
  9811. return SegmentPointComparator.compareValue(-xSign, ySign)
  9812. case 4:
  9813. return SegmentPointComparator.compareValue(-xSign, -ySign)
  9814. case 5:
  9815. return SegmentPointComparator.compareValue(-ySign, -xSign)
  9816. case 6:
  9817. return SegmentPointComparator.compareValue(-ySign, xSign)
  9818. case 7:
  9819. return SegmentPointComparator.compareValue(xSign, -ySign)
  9820. default:
  9821. }
  9822. Assert.shouldNeverReachHere('invalid octant value');
  9823. return 0
  9824. };
  9825. SegmentPointComparator.compareValue = function compareValue (compareSign0, compareSign1) {
  9826. if (compareSign0 < 0) { return -1 }
  9827. if (compareSign0 > 0) { return 1 }
  9828. if (compareSign1 < 0) { return -1 }
  9829. if (compareSign1 > 0) { return 1 }
  9830. return 0
  9831. };
  9832. var SegmentNode = function SegmentNode () {
  9833. this._segString = null;
  9834. this.coord = null;
  9835. this.segmentIndex = null;
  9836. this._segmentOctant = null;
  9837. this._isInterior = null;
  9838. var segString = arguments[0];
  9839. var coord = arguments[1];
  9840. var segmentIndex = arguments[2];
  9841. var segmentOctant = arguments[3];
  9842. this._segString = segString;
  9843. this.coord = new Coordinate(coord);
  9844. this.segmentIndex = segmentIndex;
  9845. this._segmentOctant = segmentOctant;
  9846. this._isInterior = !coord.equals2D(segString.getCoordinate(segmentIndex));
  9847. };
  9848. SegmentNode.prototype.getCoordinate = function getCoordinate () {
  9849. return this.coord
  9850. };
  9851. SegmentNode.prototype.print = function print (out) {
  9852. out.print(this.coord);
  9853. out.print(' seg # = ' + this.segmentIndex);
  9854. };
  9855. SegmentNode.prototype.compareTo = function compareTo (obj) {
  9856. var other = obj;
  9857. if (this.segmentIndex < other.segmentIndex) { return -1 }
  9858. if (this.segmentIndex > other.segmentIndex) { return 1 }
  9859. if (this.coord.equals2D(other.coord)) { return 0 }
  9860. return SegmentPointComparator.compare(this._segmentOctant, this.coord, other.coord)
  9861. };
  9862. SegmentNode.prototype.isEndPoint = function isEndPoint (maxSegmentIndex) {
  9863. if (this.segmentIndex === 0 && !this._isInterior) { return true }
  9864. if (this.segmentIndex === maxSegmentIndex) { return true }
  9865. return false
  9866. };
  9867. SegmentNode.prototype.isInterior = function isInterior () {
  9868. return this._isInterior
  9869. };
  9870. SegmentNode.prototype.interfaces_ = function interfaces_ () {
  9871. return [Comparable]
  9872. };
  9873. SegmentNode.prototype.getClass = function getClass () {
  9874. return SegmentNode
  9875. };
  9876. // import Iterator from '../../../../java/util/Iterator'
  9877. var SegmentNodeList = function SegmentNodeList () {
  9878. this._nodeMap = new TreeMap();
  9879. this._edge = null;
  9880. var edge = arguments[0];
  9881. this._edge = edge;
  9882. };
  9883. SegmentNodeList.prototype.getSplitCoordinates = function getSplitCoordinates () {
  9884. var this$1 = this;
  9885. var coordList = new CoordinateList();
  9886. this.addEndpoints();
  9887. var it = this.iterator();
  9888. var eiPrev = it.next();
  9889. while (it.hasNext()) {
  9890. var ei = it.next();
  9891. this$1.addEdgeCoordinates(eiPrev, ei, coordList);
  9892. eiPrev = ei;
  9893. }
  9894. return coordList.toCoordinateArray()
  9895. };
  9896. SegmentNodeList.prototype.addCollapsedNodes = function addCollapsedNodes () {
  9897. var this$1 = this;
  9898. var collapsedVertexIndexes = new ArrayList();
  9899. this.findCollapsesFromInsertedNodes(collapsedVertexIndexes);
  9900. this.findCollapsesFromExistingVertices(collapsedVertexIndexes);
  9901. for (var it = collapsedVertexIndexes.iterator(); it.hasNext();) {
  9902. var vertexIndex = it.next().intValue();
  9903. this$1.add(this$1._edge.getCoordinate(vertexIndex), vertexIndex);
  9904. }
  9905. };
  9906. SegmentNodeList.prototype.print = function print (out) {
  9907. out.println('Intersections:');
  9908. for (var it = this.iterator(); it.hasNext();) {
  9909. var ei = it.next();
  9910. ei.print(out);
  9911. }
  9912. };
  9913. SegmentNodeList.prototype.findCollapsesFromExistingVertices = function findCollapsesFromExistingVertices (collapsedVertexIndexes) {
  9914. var this$1 = this;
  9915. for (var i = 0; i < this._edge.size() - 2; i++) {
  9916. var p0 = this$1._edge.getCoordinate(i);
  9917. // const p1 = this._edge.getCoordinate(i + 1)
  9918. var p2 = this$1._edge.getCoordinate(i + 2);
  9919. if (p0.equals2D(p2)) {
  9920. collapsedVertexIndexes.add(new Integer(i + 1));
  9921. }
  9922. }
  9923. };
  9924. SegmentNodeList.prototype.addEdgeCoordinates = function addEdgeCoordinates (ei0, ei1, coordList) {
  9925. var this$1 = this;
  9926. // let npts = ei1.segmentIndex - ei0.segmentIndex + 2
  9927. var lastSegStartPt = this._edge.getCoordinate(ei1.segmentIndex);
  9928. var useIntPt1 = ei1.isInterior() || !ei1.coord.equals2D(lastSegStartPt);
  9929. // if (!useIntPt1) {
  9930. // npts--
  9931. // }
  9932. // const ipt = 0
  9933. coordList.add(new Coordinate(ei0.coord), false);
  9934. for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
  9935. coordList.add(this$1._edge.getCoordinate(i));
  9936. }
  9937. if (useIntPt1) {
  9938. coordList.add(new Coordinate(ei1.coord));
  9939. }
  9940. };
  9941. SegmentNodeList.prototype.iterator = function iterator () {
  9942. return this._nodeMap.values().iterator()
  9943. };
  9944. SegmentNodeList.prototype.addSplitEdges = function addSplitEdges (edgeList) {
  9945. var this$1 = this;
  9946. this.addEndpoints();
  9947. this.addCollapsedNodes();
  9948. var it = this.iterator();
  9949. var eiPrev = it.next();
  9950. while (it.hasNext()) {
  9951. var ei = it.next();
  9952. var newEdge = this$1.createSplitEdge(eiPrev, ei);
  9953. edgeList.add(newEdge);
  9954. eiPrev = ei;
  9955. }
  9956. };
  9957. SegmentNodeList.prototype.findCollapseIndex = function findCollapseIndex (ei0, ei1, collapsedVertexIndex) {
  9958. if (!ei0.coord.equals2D(ei1.coord)) { return false }
  9959. var numVerticesBetween = ei1.segmentIndex - ei0.segmentIndex;
  9960. if (!ei1.isInterior()) {
  9961. numVerticesBetween--;
  9962. }
  9963. if (numVerticesBetween === 1) {
  9964. collapsedVertexIndex[0] = ei0.segmentIndex + 1;
  9965. return true
  9966. }
  9967. return false
  9968. };
  9969. SegmentNodeList.prototype.findCollapsesFromInsertedNodes = function findCollapsesFromInsertedNodes (collapsedVertexIndexes) {
  9970. var this$1 = this;
  9971. var collapsedVertexIndex = new Array(1).fill(null);
  9972. var it = this.iterator();
  9973. var eiPrev = it.next();
  9974. while (it.hasNext()) {
  9975. var ei = it.next();
  9976. var isCollapsed = this$1.findCollapseIndex(eiPrev, ei, collapsedVertexIndex);
  9977. if (isCollapsed) { collapsedVertexIndexes.add(new Integer(collapsedVertexIndex[0])); }
  9978. eiPrev = ei;
  9979. }
  9980. };
  9981. SegmentNodeList.prototype.getEdge = function getEdge () {
  9982. return this._edge
  9983. };
  9984. SegmentNodeList.prototype.addEndpoints = function addEndpoints () {
  9985. var maxSegIndex = this._edge.size() - 1;
  9986. this.add(this._edge.getCoordinate(0), 0);
  9987. this.add(this._edge.getCoordinate(maxSegIndex), maxSegIndex);
  9988. };
  9989. SegmentNodeList.prototype.createSplitEdge = function createSplitEdge (ei0, ei1) {
  9990. var this$1 = this;
  9991. var npts = ei1.segmentIndex - ei0.segmentIndex + 2;
  9992. var lastSegStartPt = this._edge.getCoordinate(ei1.segmentIndex);
  9993. var useIntPt1 = ei1.isInterior() || !ei1.coord.equals2D(lastSegStartPt);
  9994. if (!useIntPt1) {
  9995. npts--;
  9996. }
  9997. var pts = new Array(npts).fill(null);
  9998. var ipt = 0;
  9999. pts[ipt++] = new Coordinate(ei0.coord);
  10000. for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
  10001. pts[ipt++] = this$1._edge.getCoordinate(i);
  10002. }
  10003. if (useIntPt1) { pts[ipt] = new Coordinate(ei1.coord); }
  10004. return new NodedSegmentString(pts, this._edge.getData())
  10005. };
  10006. SegmentNodeList.prototype.add = function add (intPt, segmentIndex) {
  10007. var eiNew = new SegmentNode(this._edge, intPt, segmentIndex, this._edge.getSegmentOctant(segmentIndex));
  10008. var ei = this._nodeMap.get(eiNew);
  10009. if (ei !== null) {
  10010. Assert.isTrue(ei.coord.equals2D(intPt), 'Found equal nodes with different coordinates');
  10011. return ei
  10012. }
  10013. this._nodeMap.put(eiNew, eiNew);
  10014. return eiNew
  10015. };
  10016. SegmentNodeList.prototype.checkSplitEdgesCorrectness = function checkSplitEdgesCorrectness (splitEdges) {
  10017. var edgePts = this._edge.getCoordinates();
  10018. var split0 = splitEdges.get(0);
  10019. var pt0 = split0.getCoordinate(0);
  10020. if (!pt0.equals2D(edgePts[0])) { throw new RuntimeException('bad split edge start point at ' + pt0) }
  10021. var splitn = splitEdges.get(splitEdges.size() - 1);
  10022. var splitnPts = splitn.getCoordinates();
  10023. var ptn = splitnPts[splitnPts.length - 1];
  10024. if (!ptn.equals2D(edgePts[edgePts.length - 1])) { throw new RuntimeException('bad split edge end point at ' + ptn) }
  10025. };
  10026. SegmentNodeList.prototype.interfaces_ = function interfaces_ () {
  10027. return []
  10028. };
  10029. SegmentNodeList.prototype.getClass = function getClass () {
  10030. return SegmentNodeList
  10031. };
  10032. // class NodeVertexIterator {
  10033. // constructor () {
  10034. // this._nodeList = null
  10035. // this._edge = null
  10036. // this._nodeIt = null
  10037. // this._currNode = null
  10038. // this._nextNode = null
  10039. // this._currSegIndex = 0
  10040. // let nodeList = arguments[0]
  10041. // this._nodeList = nodeList
  10042. // this._edge = nodeList.getEdge()
  10043. // this._nodeIt = nodeList.iterator()
  10044. // this.readNextNode()
  10045. // }
  10046. // next () {
  10047. // if (this._currNode === null) {
  10048. // this._currNode = this._nextNode
  10049. // this._currSegIndex = this._currNode.segmentIndex
  10050. // this.readNextNode()
  10051. // return this._currNode
  10052. // }
  10053. // if (this._nextNode === null) return null
  10054. // if (this._nextNode.segmentIndex === this._currNode.segmentIndex) {
  10055. // this._currNode = this._nextNode
  10056. // this._currSegIndex = this._currNode.segmentIndex
  10057. // this.readNextNode()
  10058. // return this._currNode
  10059. // }
  10060. // if (this._nextNode.segmentIndex > this._currNode.segmentIndex) {}
  10061. // return null
  10062. // }
  10063. // remove () {
  10064. // // throw new UnsupportedOperationException(this.getClass().getName())
  10065. // }
  10066. // hasNext () {
  10067. // if (this._nextNode === null) return false
  10068. // return true
  10069. // }
  10070. // readNextNode () {
  10071. // if (this._nodeIt.hasNext()) this._nextNode = this._nodeIt.next(); else this._nextNode = null
  10072. // }
  10073. // interfaces_ () {
  10074. // return [Iterator]
  10075. // }
  10076. // getClass () {
  10077. // return NodeVertexIterator
  10078. // }
  10079. // }
  10080. var Octant = function Octant () {};
  10081. Octant.prototype.interfaces_ = function interfaces_ () {
  10082. return []
  10083. };
  10084. Octant.prototype.getClass = function getClass () {
  10085. return Octant
  10086. };
  10087. Octant.octant = function octant () {
  10088. if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
  10089. var dx = arguments[0];
  10090. var dy = arguments[1];
  10091. if (dx === 0.0 && dy === 0.0) { throw new IllegalArgumentException('Cannot compute the octant for point ( ' + dx + ', ' + dy + ' )') }
  10092. var adx = Math.abs(dx);
  10093. var ady = Math.abs(dy);
  10094. if (dx >= 0) {
  10095. if (dy >= 0) {
  10096. if (adx >= ady) { return 0; } else { return 1 }
  10097. } else {
  10098. if (adx >= ady) { return 7; } else { return 6 }
  10099. }
  10100. } else {
  10101. if (dy >= 0) {
  10102. if (adx >= ady) { return 3; } else { return 2 }
  10103. } else {
  10104. if (adx >= ady) { return 4; } else { return 5 }
  10105. }
  10106. }
  10107. } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {
  10108. var p0 = arguments[0];
  10109. var p1 = arguments[1];
  10110. var dx$1 = p1.x - p0.x;
  10111. var dy$1 = p1.y - p0.y;
  10112. if (dx$1 === 0.0 && dy$1 === 0.0) { throw new IllegalArgumentException('Cannot compute the octant for two identical points ' + p0) }
  10113. return Octant.octant(dx$1, dy$1)
  10114. }
  10115. };
  10116. var SegmentString = function SegmentString () {};
  10117. SegmentString.prototype.getCoordinates = function getCoordinates () {};
  10118. SegmentString.prototype.size = function size () {};
  10119. SegmentString.prototype.getCoordinate = function getCoordinate (i) {};
  10120. SegmentString.prototype.isClosed = function isClosed () {};
  10121. SegmentString.prototype.setData = function setData (data) {};
  10122. SegmentString.prototype.getData = function getData () {};
  10123. SegmentString.prototype.interfaces_ = function interfaces_ () {
  10124. return []
  10125. };
  10126. SegmentString.prototype.getClass = function getClass () {
  10127. return SegmentString
  10128. };
  10129. var NodableSegmentString = function NodableSegmentString () {};
  10130. NodableSegmentString.prototype.addIntersection = function addIntersection (intPt, segmentIndex) {};
  10131. NodableSegmentString.prototype.interfaces_ = function interfaces_ () {
  10132. return [SegmentString]
  10133. };
  10134. NodableSegmentString.prototype.getClass = function getClass () {
  10135. return NodableSegmentString
  10136. };
  10137. var NodedSegmentString = function NodedSegmentString () {
  10138. this._nodeList = new SegmentNodeList(this);
  10139. this._pts = null;
  10140. this._data = null;
  10141. var pts = arguments[0];
  10142. var data = arguments[1];
  10143. this._pts = pts;
  10144. this._data = data;
  10145. };
  10146. NodedSegmentString.prototype.getCoordinates = function getCoordinates () {
  10147. return this._pts
  10148. };
  10149. NodedSegmentString.prototype.size = function size () {
  10150. return this._pts.length
  10151. };
  10152. NodedSegmentString.prototype.getCoordinate = function getCoordinate (i) {
  10153. return this._pts[i]
  10154. };
  10155. NodedSegmentString.prototype.isClosed = function isClosed () {
  10156. return this._pts[0].equals(this._pts[this._pts.length - 1])
  10157. };
  10158. NodedSegmentString.prototype.getSegmentOctant = function getSegmentOctant (index) {
  10159. if (index === this._pts.length - 1) { return -1 }
  10160. return this.safeOctant(this.getCoordinate(index), this.getCoordinate(index + 1))
  10161. };
  10162. NodedSegmentString.prototype.setData = function setData (data) {
  10163. this._data = data;
  10164. };
  10165. NodedSegmentString.prototype.safeOctant = function safeOctant (p0, p1) {
  10166. if (p0.equals2D(p1)) { return 0 }
  10167. return Octant.octant(p0, p1)
  10168. };
  10169. NodedSegmentString.prototype.getData = function getData () {
  10170. return this._data
  10171. };
  10172. NodedSegmentString.prototype.addIntersection = function addIntersection () {
  10173. if (arguments.length === 2) {
  10174. var intPt$1 = arguments[0];
  10175. var segmentIndex = arguments[1];
  10176. this.addIntersectionNode(intPt$1, segmentIndex);
  10177. } else if (arguments.length === 4) {
  10178. var li = arguments[0];
  10179. var segmentIndex$1 = arguments[1];
  10180. // const geomIndex = arguments[2]
  10181. var intIndex = arguments[3];
  10182. var intPt = new Coordinate(li.getIntersection(intIndex));
  10183. this.addIntersection(intPt, segmentIndex$1);
  10184. }
  10185. };
  10186. NodedSegmentString.prototype.toString = function toString () {
  10187. return WKTWriter.toLineString(new CoordinateArraySequence(this._pts))
  10188. };
  10189. NodedSegmentString.prototype.getNodeList = function getNodeList () {
  10190. return this._nodeList
  10191. };
  10192. NodedSegmentString.prototype.addIntersectionNode = function addIntersectionNode (intPt, segmentIndex) {
  10193. var normalizedSegmentIndex = segmentIndex;
  10194. var nextSegIndex = normalizedSegmentIndex + 1;
  10195. if (nextSegIndex < this._pts.length) {
  10196. var nextPt = this._pts[nextSegIndex];
  10197. if (intPt.equals2D(nextPt)) {
  10198. normalizedSegmentIndex = nextSegIndex;
  10199. }
  10200. }
  10201. var ei = this._nodeList.add(intPt, normalizedSegmentIndex);
  10202. return ei
  10203. };
  10204. NodedSegmentString.prototype.addIntersections = function addIntersections (li, segmentIndex, geomIndex) {
  10205. var this$1 = this;
  10206. for (var i = 0; i < li.getIntersectionNum(); i++) {
  10207. this$1.addIntersection(li, segmentIndex, geomIndex, i);
  10208. }
  10209. };
  10210. NodedSegmentString.prototype.interfaces_ = function interfaces_ () {
  10211. return [NodableSegmentString]
  10212. };
  10213. NodedSegmentString.prototype.getClass = function getClass () {
  10214. return NodedSegmentString
  10215. };
  10216. NodedSegmentString.getNodedSubstrings = function getNodedSubstrings () {
  10217. if (arguments.length === 1) {
  10218. var segStrings = arguments[0];
  10219. var resultEdgelist = new ArrayList();
  10220. NodedSegmentString.getNodedSubstrings(segStrings, resultEdgelist);
  10221. return resultEdgelist
  10222. } else if (arguments.length === 2) {
  10223. var segStrings$1 = arguments[0];
  10224. var resultEdgelist$1 = arguments[1];
  10225. for (var i = segStrings$1.iterator(); i.hasNext();) {
  10226. var ss = i.next();
  10227. ss.getNodeList().addSplitEdges(resultEdgelist$1);
  10228. }
  10229. }
  10230. };
  10231. var LineSegment = function LineSegment () {
  10232. this.p0 = null;
  10233. this.p1 = null;
  10234. if (arguments.length === 0) {
  10235. this.p0 = new Coordinate();
  10236. this.p1 = new Coordinate();
  10237. } else if (arguments.length === 1) {
  10238. var ls = arguments[0];
  10239. this.p0 = new Coordinate(ls.p0);
  10240. this.p1 = new Coordinate(ls.p1);
  10241. } else if (arguments.length === 2) {
  10242. this.p0 = arguments[0];
  10243. this.p1 = arguments[1];
  10244. } else if (arguments.length === 4) {
  10245. var x0 = arguments[0];
  10246. var y0 = arguments[1];
  10247. var x1 = arguments[2];
  10248. var y1 = arguments[3];
  10249. this.p0 = new Coordinate(x0, y0);
  10250. this.p1 = new Coordinate(x1, y1);
  10251. }
  10252. };
  10253. var staticAccessors$24 = { serialVersionUID: { configurable: true } };
  10254. LineSegment.prototype.minX = function minX () {
  10255. return Math.min(this.p0.x, this.p1.x)
  10256. };
  10257. LineSegment.prototype.orientationIndex = function orientationIndex () {
  10258. if (arguments[0] instanceof LineSegment) {
  10259. var seg = arguments[0];
  10260. var orient0 = CGAlgorithms.orientationIndex(this.p0, this.p1, seg.p0);
  10261. var orient1 = CGAlgorithms.orientationIndex(this.p0, this.p1, seg.p1);
  10262. if (orient0 >= 0 && orient1 >= 0) { return Math.max(orient0, orient1) }
  10263. if (orient0 <= 0 && orient1 <= 0) { return Math.max(orient0, orient1) }
  10264. return 0
  10265. } else if (arguments[0] instanceof Coordinate) {
  10266. var p = arguments[0];
  10267. return CGAlgorithms.orientationIndex(this.p0, this.p1, p)
  10268. }
  10269. };
  10270. LineSegment.prototype.toGeometry = function toGeometry (geomFactory) {
  10271. return geomFactory.createLineString([this.p0, this.p1])
  10272. };
  10273. LineSegment.prototype.isVertical = function isVertical () {
  10274. return this.p0.x === this.p1.x
  10275. };
  10276. LineSegment.prototype.equals = function equals (o) {
  10277. if (!(o instanceof LineSegment)) {
  10278. return false
  10279. }
  10280. var other = o;
  10281. return this.p0.equals(other.p0) && this.p1.equals(other.p1)
  10282. };
  10283. LineSegment.prototype.intersection = function intersection (line) {
  10284. var li = new RobustLineIntersector();
  10285. li.computeIntersection(this.p0, this.p1, line.p0, line.p1);
  10286. if (li.hasIntersection()) { return li.getIntersection(0) }
  10287. return null
  10288. };
  10289. LineSegment.prototype.project = function project () {
  10290. if (arguments[0] instanceof Coordinate) {
  10291. var p = arguments[0];
  10292. if (p.equals(this.p0) || p.equals(this.p1)) { return new Coordinate(p) }
  10293. var r = this.projectionFactor(p);
  10294. var coord = new Coordinate();
  10295. coord.x = this.p0.x + r * (this.p1.x - this.p0.x);
  10296. coord.y = this.p0.y + r * (this.p1.y - this.p0.y);
  10297. return coord
  10298. } else if (arguments[0] instanceof LineSegment) {
  10299. var seg = arguments[0];
  10300. var pf0 = this.projectionFactor(seg.p0);
  10301. var pf1 = this.projectionFactor(seg.p1);
  10302. if (pf0 >= 1.0 && pf1 >= 1.0) { return null }
  10303. if (pf0 <= 0.0 && pf1 <= 0.0) { return null }
  10304. var newp0 = this.project(seg.p0);
  10305. if (pf0 < 0.0) { newp0 = this.p0; }
  10306. if (pf0 > 1.0) { newp0 = this.p1; }
  10307. var newp1 = this.project(seg.p1);
  10308. if (pf1 < 0.0) { newp1 = this.p0; }
  10309. if (pf1 > 1.0) { newp1 = this.p1; }
  10310. return new LineSegment(newp0, newp1)
  10311. }
  10312. };
  10313. LineSegment.prototype.normalize = function normalize () {
  10314. if (this.p1.compareTo(this.p0) < 0) { this.reverse(); }
  10315. };
  10316. LineSegment.prototype.angle = function angle () {
  10317. return Math.atan2(this.p1.y - this.p0.y, this.p1.x - this.p0.x)
  10318. };
  10319. LineSegment.prototype.getCoordinate = function getCoordinate (i) {
  10320. if (i === 0) { return this.p0 }
  10321. return this.p1
  10322. };
  10323. LineSegment.prototype.distancePerpendicular = function distancePerpendicular (p) {
  10324. return CGAlgorithms.distancePointLinePerpendicular(p, this.p0, this.p1)
  10325. };
  10326. LineSegment.prototype.minY = function minY () {
  10327. return Math.min(this.p0.y, this.p1.y)
  10328. };
  10329. LineSegment.prototype.midPoint = function midPoint () {
  10330. return LineSegment.midPoint(this.p0, this.p1)
  10331. };
  10332. LineSegment.prototype.projectionFactor = function projectionFactor (p) {
  10333. if (p.equals(this.p0)) { return 0.0 }
  10334. if (p.equals(this.p1)) { return 1.0 }
  10335. var dx = this.p1.x - this.p0.x;
  10336. var dy = this.p1.y - this.p0.y;
  10337. var len = dx * dx + dy * dy;
  10338. if (len <= 0.0) { return Double.NaN }
  10339. var r = ((p.x - this.p0.x) * dx + (p.y - this.p0.y) * dy) / len;
  10340. return r
  10341. };
  10342. LineSegment.prototype.closestPoints = function closestPoints (line) {
  10343. var intPt = this.intersection(line);
  10344. if (intPt !== null) {
  10345. return [intPt, intPt]
  10346. }
  10347. var closestPt = new Array(2).fill(null);
  10348. var minDistance = Double.MAX_VALUE;
  10349. var dist = null;
  10350. var close00 = this.closestPoint(line.p0);
  10351. minDistance = close00.distance(line.p0);
  10352. closestPt[0] = close00;
  10353. closestPt[1] = line.p0;
  10354. var close01 = this.closestPoint(line.p1);
  10355. dist = close01.distance(line.p1);
  10356. if (dist < minDistance) {
  10357. minDistance = dist;
  10358. closestPt[0] = close01;
  10359. closestPt[1] = line.p1;
  10360. }
  10361. var close10 = line.closestPoint(this.p0);
  10362. dist = close10.distance(this.p0);
  10363. if (dist < minDistance) {
  10364. minDistance = dist;
  10365. closestPt[0] = this.p0;
  10366. closestPt[1] = close10;
  10367. }
  10368. var close11 = line.closestPoint(this.p1);
  10369. dist = close11.distance(this.p1);
  10370. if (dist < minDistance) {
  10371. minDistance = dist;
  10372. closestPt[0] = this.p1;
  10373. closestPt[1] = close11;
  10374. }
  10375. return closestPt
  10376. };
  10377. LineSegment.prototype.closestPoint = function closestPoint (p) {
  10378. var factor = this.projectionFactor(p);
  10379. if (factor > 0 && factor < 1) {
  10380. return this.project(p)
  10381. }
  10382. var dist0 = this.p0.distance(p);
  10383. var dist1 = this.p1.distance(p);
  10384. if (dist0 < dist1) { return this.p0 }
  10385. return this.p1
  10386. };
  10387. LineSegment.prototype.maxX = function maxX () {
  10388. return Math.max(this.p0.x, this.p1.x)
  10389. };
  10390. LineSegment.prototype.getLength = function getLength () {
  10391. return this.p0.distance(this.p1)
  10392. };
  10393. LineSegment.prototype.compareTo = function compareTo (o) {
  10394. var other = o;
  10395. var comp0 = this.p0.compareTo(other.p0);
  10396. if (comp0 !== 0) { return comp0 }
  10397. return this.p1.compareTo(other.p1)
  10398. };
  10399. LineSegment.prototype.reverse = function reverse () {
  10400. var temp = this.p0;
  10401. this.p0 = this.p1;
  10402. this.p1 = temp;
  10403. };
  10404. LineSegment.prototype.equalsTopo = function equalsTopo (other) {
  10405. return this.p0.equals(other.p0) &&
  10406. (this.p1.equals(other.p1) || this.p0.equals(other.p1)) &&
  10407. this.p1.equals(other.p0)
  10408. };
  10409. LineSegment.prototype.lineIntersection = function lineIntersection (line) {
  10410. try {
  10411. var intPt = HCoordinate.intersection(this.p0, this.p1, line.p0, line.p1);
  10412. return intPt
  10413. } catch (ex) {
  10414. if (ex instanceof NotRepresentableException) {} else { throw ex }
  10415. } finally {}
  10416. return null
  10417. };
  10418. LineSegment.prototype.maxY = function maxY () {
  10419. return Math.max(this.p0.y, this.p1.y)
  10420. };
  10421. LineSegment.prototype.pointAlongOffset = function pointAlongOffset (segmentLengthFraction, offsetDistance) {
  10422. var segx = this.p0.x + segmentLengthFraction * (this.p1.x - this.p0.x);
  10423. var segy = this.p0.y + segmentLengthFraction * (this.p1.y - this.p0.y);
  10424. var dx = this.p1.x - this.p0.x;
  10425. var dy = this.p1.y - this.p0.y;
  10426. var len = Math.sqrt(dx * dx + dy * dy);
  10427. var ux = 0.0;
  10428. var uy = 0.0;
  10429. if (offsetDistance !== 0.0) {
  10430. if (len <= 0.0) { throw new Error('Cannot compute offset from zero-length line segment') }
  10431. ux = offsetDistance * dx / len;
  10432. uy = offsetDistance * dy / len;
  10433. }
  10434. var offsetx = segx - uy;
  10435. var offsety = segy + ux;
  10436. var coord = new Coordinate(offsetx, offsety);
  10437. return coord
  10438. };
  10439. LineSegment.prototype.setCoordinates = function setCoordinates () {
  10440. if (arguments.length === 1) {
  10441. var ls = arguments[0];
  10442. this.setCoordinates(ls.p0, ls.p1);
  10443. } else if (arguments.length === 2) {
  10444. var p0 = arguments[0];
  10445. var p1 = arguments[1];
  10446. this.p0.x = p0.x;
  10447. this.p0.y = p0.y;
  10448. this.p1.x = p1.x;
  10449. this.p1.y = p1.y;
  10450. }
  10451. };
  10452. LineSegment.prototype.segmentFraction = function segmentFraction (inputPt) {
  10453. var segFrac = this.projectionFactor(inputPt);
  10454. if (segFrac < 0.0) { segFrac = 0.0; } else if (segFrac > 1.0 || Double.isNaN(segFrac)) { segFrac = 1.0; }
  10455. return segFrac
  10456. };
  10457. LineSegment.prototype.toString = function toString () {
  10458. return 'LINESTRING( ' + this.p0.x + ' ' + this.p0.y + ', ' + this.p1.x + ' ' + this.p1.y + ')'
  10459. };
  10460. LineSegment.prototype.isHorizontal = function isHorizontal () {
  10461. return this.p0.y === this.p1.y
  10462. };
  10463. LineSegment.prototype.distance = function distance () {
  10464. if (arguments[0] instanceof LineSegment) {
  10465. var ls = arguments[0];
  10466. return CGAlgorithms.distanceLineLine(this.p0, this.p1, ls.p0, ls.p1)
  10467. } else if (arguments[0] instanceof Coordinate) {
  10468. var p = arguments[0];
  10469. return CGAlgorithms.distancePointLine(p, this.p0, this.p1)
  10470. }
  10471. };
  10472. LineSegment.prototype.pointAlong = function pointAlong (segmentLengthFraction) {
  10473. var coord = new Coordinate();
  10474. coord.x = this.p0.x + segmentLengthFraction * (this.p1.x - this.p0.x);
  10475. coord.y = this.p0.y + segmentLengthFraction * (this.p1.y - this.p0.y);
  10476. return coord
  10477. };
  10478. LineSegment.prototype.hashCode = function hashCode () {
  10479. var bits0 = Double.doubleToLongBits(this.p0.x);
  10480. bits0 ^= Double.doubleToLongBits(this.p0.y) * 31;
  10481. var hash0 = Math.trunc(bits0) ^ Math.trunc(bits0 >> 32);
  10482. var bits1 = Double.doubleToLongBits(this.p1.x);
  10483. bits1 ^= Double.doubleToLongBits(this.p1.y) * 31;
  10484. var hash1 = Math.trunc(bits1) ^ Math.trunc(bits1 >> 32);
  10485. return hash0 ^ hash1
  10486. };
  10487. LineSegment.prototype.interfaces_ = function interfaces_ () {
  10488. return [Comparable, Serializable]
  10489. };
  10490. LineSegment.prototype.getClass = function getClass () {
  10491. return LineSegment
  10492. };
  10493. LineSegment.midPoint = function midPoint (p0, p1) {
  10494. return new Coordinate((p0.x + p1.x) / 2, (p0.y + p1.y) / 2)
  10495. };
  10496. staticAccessors$24.serialVersionUID.get = function () { return 3252005833466256227 };
  10497. Object.defineProperties( LineSegment, staticAccessors$24 );
  10498. var MonotoneChainOverlapAction = function MonotoneChainOverlapAction () {
  10499. this.tempEnv1 = new Envelope();
  10500. this.tempEnv2 = new Envelope();
  10501. this._overlapSeg1 = new LineSegment();
  10502. this._overlapSeg2 = new LineSegment();
  10503. };
  10504. MonotoneChainOverlapAction.prototype.overlap = function overlap () {
  10505. if (arguments.length === 2) {
  10506. // const seg1 = arguments[0]
  10507. // const seg2 = arguments[1]
  10508. } else if (arguments.length === 4) {
  10509. var mc1 = arguments[0];
  10510. var start1 = arguments[1];
  10511. var mc2 = arguments[2];
  10512. var start2 = arguments[3];
  10513. mc1.getLineSegment(start1, this._overlapSeg1);
  10514. mc2.getLineSegment(start2, this._overlapSeg2);
  10515. this.overlap(this._overlapSeg1, this._overlapSeg2);
  10516. }
  10517. };
  10518. MonotoneChainOverlapAction.prototype.interfaces_ = function interfaces_ () {
  10519. return []
  10520. };
  10521. MonotoneChainOverlapAction.prototype.getClass = function getClass () {
  10522. return MonotoneChainOverlapAction
  10523. };
  10524. var MonotoneChain = function MonotoneChain () {
  10525. this._pts = null;
  10526. this._start = null;
  10527. this._end = null;
  10528. this._env = null;
  10529. this._context = null;
  10530. this._id = null;
  10531. var pts = arguments[0];
  10532. var start = arguments[1];
  10533. var end = arguments[2];
  10534. var context = arguments[3];
  10535. this._pts = pts;
  10536. this._start = start;
  10537. this._end = end;
  10538. this._context = context;
  10539. };
  10540. MonotoneChain.prototype.getLineSegment = function getLineSegment (index, ls) {
  10541. ls.p0 = this._pts[index];
  10542. ls.p1 = this._pts[index + 1];
  10543. };
  10544. MonotoneChain.prototype.computeSelect = function computeSelect (searchEnv, start0, end0, mcs) {
  10545. var p0 = this._pts[start0];
  10546. var p1 = this._pts[end0];
  10547. mcs.tempEnv1.init(p0, p1);
  10548. if (end0 - start0 === 1) {
  10549. mcs.select(this, start0);
  10550. return null
  10551. }
  10552. if (!searchEnv.intersects(mcs.tempEnv1)) { return null }
  10553. var mid = Math.trunc((start0 + end0) / 2);
  10554. if (start0 < mid) {
  10555. this.computeSelect(searchEnv, start0, mid, mcs);
  10556. }
  10557. if (mid < end0) {
  10558. this.computeSelect(searchEnv, mid, end0, mcs);
  10559. }
  10560. };
  10561. MonotoneChain.prototype.getCoordinates = function getCoordinates () {
  10562. var this$1 = this;
  10563. var coord = new Array(this._end - this._start + 1).fill(null);
  10564. var index = 0;
  10565. for (var i = this._start; i <= this._end; i++) {
  10566. coord[index++] = this$1._pts[i];
  10567. }
  10568. return coord
  10569. };
  10570. MonotoneChain.prototype.computeOverlaps = function computeOverlaps (mc, mco) {
  10571. this.computeOverlapsInternal(this._start, this._end, mc, mc._start, mc._end, mco);
  10572. };
  10573. MonotoneChain.prototype.setId = function setId (id) {
  10574. this._id = id;
  10575. };
  10576. MonotoneChain.prototype.select = function select (searchEnv, mcs) {
  10577. this.computeSelect(searchEnv, this._start, this._end, mcs);
  10578. };
  10579. MonotoneChain.prototype.getEnvelope = function getEnvelope () {
  10580. if (this._env === null) {
  10581. var p0 = this._pts[this._start];
  10582. var p1 = this._pts[this._end];
  10583. this._env = new Envelope(p0, p1);
  10584. }
  10585. return this._env
  10586. };
  10587. MonotoneChain.prototype.getEndIndex = function getEndIndex () {
  10588. return this._end
  10589. };
  10590. MonotoneChain.prototype.getStartIndex = function getStartIndex () {
  10591. return this._start
  10592. };
  10593. MonotoneChain.prototype.getContext = function getContext () {
  10594. return this._context
  10595. };
  10596. MonotoneChain.prototype.getId = function getId () {
  10597. return this._id
  10598. };
  10599. MonotoneChain.prototype.computeOverlapsInternal = function computeOverlapsInternal (start0, end0, mc, start1, end1, mco) {
  10600. var p00 = this._pts[start0];
  10601. var p01 = this._pts[end0];
  10602. var p10 = mc._pts[start1];
  10603. var p11 = mc._pts[end1];
  10604. if (end0 - start0 === 1 && end1 - start1 === 1) {
  10605. mco.overlap(this, start0, mc, start1);
  10606. return null
  10607. }
  10608. mco.tempEnv1.init(p00, p01);
  10609. mco.tempEnv2.init(p10, p11);
  10610. if (!mco.tempEnv1.intersects(mco.tempEnv2)) { return null }
  10611. var mid0 = Math.trunc((start0 + end0) / 2);
  10612. var mid1 = Math.trunc((start1 + end1) / 2);
  10613. if (start0 < mid0) {
  10614. if (start1 < mid1) { this.computeOverlapsInternal(start0, mid0, mc, start1, mid1, mco); }
  10615. if (mid1 < end1) { this.computeOverlapsInternal(start0, mid0, mc, mid1, end1, mco); }
  10616. }
  10617. if (mid0 < end0) {
  10618. if (start1 < mid1) { this.computeOverlapsInternal(mid0, end0, mc, start1, mid1, mco); }
  10619. if (mid1 < end1) { this.computeOverlapsInternal(mid0, end0, mc, mid1, end1, mco); }
  10620. }
  10621. };
  10622. MonotoneChain.prototype.interfaces_ = function interfaces_ () {
  10623. return []
  10624. };
  10625. MonotoneChain.prototype.getClass = function getClass () {
  10626. return MonotoneChain
  10627. };
  10628. var MonotoneChainBuilder = function MonotoneChainBuilder () {};
  10629. MonotoneChainBuilder.prototype.interfaces_ = function interfaces_ () {
  10630. return []
  10631. };
  10632. MonotoneChainBuilder.prototype.getClass = function getClass () {
  10633. return MonotoneChainBuilder
  10634. };
  10635. MonotoneChainBuilder.getChainStartIndices = function getChainStartIndices (pts) {
  10636. var start = 0;
  10637. var startIndexList = new ArrayList();
  10638. startIndexList.add(new Integer(start));
  10639. do {
  10640. var last = MonotoneChainBuilder.findChainEnd(pts, start);
  10641. startIndexList.add(new Integer(last));
  10642. start = last;
  10643. } while (start < pts.length - 1)
  10644. var startIndex = MonotoneChainBuilder.toIntArray(startIndexList);
  10645. return startIndex
  10646. };
  10647. MonotoneChainBuilder.findChainEnd = function findChainEnd (pts, start) {
  10648. var safeStart = start;
  10649. while (safeStart < pts.length - 1 && pts[safeStart].equals2D(pts[safeStart + 1])) {
  10650. safeStart++;
  10651. }
  10652. if (safeStart >= pts.length - 1) {
  10653. return pts.length - 1
  10654. }
  10655. var chainQuad = Quadrant.quadrant(pts[safeStart], pts[safeStart + 1]);
  10656. var last = start + 1;
  10657. while (last < pts.length) {
  10658. if (!pts[last - 1].equals2D(pts[last])) {
  10659. var quad = Quadrant.quadrant(pts[last - 1], pts[last]);
  10660. if (quad !== chainQuad) { break }
  10661. }
  10662. last++;
  10663. }
  10664. return last - 1
  10665. };
  10666. MonotoneChainBuilder.getChains = function getChains () {
  10667. if (arguments.length === 1) {
  10668. var pts = arguments[0];
  10669. return MonotoneChainBuilder.getChains(pts, null)
  10670. } else if (arguments.length === 2) {
  10671. var pts$1 = arguments[0];
  10672. var context = arguments[1];
  10673. var mcList = new ArrayList();
  10674. var startIndex = MonotoneChainBuilder.getChainStartIndices(pts$1);
  10675. for (var i = 0; i < startIndex.length - 1; i++) {
  10676. var mc = new MonotoneChain(pts$1, startIndex[i], startIndex[i + 1], context);
  10677. mcList.add(mc);
  10678. }
  10679. return mcList
  10680. }
  10681. };
  10682. MonotoneChainBuilder.toIntArray = function toIntArray (list) {
  10683. var array = new Array(list.size()).fill(null);
  10684. for (var i = 0; i < array.length; i++) {
  10685. array[i] = list.get(i).intValue();
  10686. }
  10687. return array
  10688. };
  10689. var Noder = function Noder () {};
  10690. Noder.prototype.computeNodes = function computeNodes (segStrings) {};
  10691. Noder.prototype.getNodedSubstrings = function getNodedSubstrings () {};
  10692. Noder.prototype.interfaces_ = function interfaces_ () {
  10693. return []
  10694. };
  10695. Noder.prototype.getClass = function getClass () {
  10696. return Noder
  10697. };
  10698. var SinglePassNoder = function SinglePassNoder () {
  10699. this._segInt = null;
  10700. if (arguments.length === 0) {} else if (arguments.length === 1) {
  10701. var segInt = arguments[0];
  10702. this.setSegmentIntersector(segInt);
  10703. }
  10704. };
  10705. SinglePassNoder.prototype.setSegmentIntersector = function setSegmentIntersector (segInt) {
  10706. this._segInt = segInt;
  10707. };
  10708. SinglePassNoder.prototype.interfaces_ = function interfaces_ () {
  10709. return [Noder]
  10710. };
  10711. SinglePassNoder.prototype.getClass = function getClass () {
  10712. return SinglePassNoder
  10713. };
  10714. var MCIndexNoder = (function (SinglePassNoder$$1) {
  10715. function MCIndexNoder (si) {
  10716. if (si) { SinglePassNoder$$1.call(this, si); }
  10717. else { SinglePassNoder$$1.call(this); }
  10718. this._monoChains = new ArrayList();
  10719. this._index = new STRtree();
  10720. this._idCounter = 0;
  10721. this._nodedSegStrings = null;
  10722. this._nOverlaps = 0;
  10723. }
  10724. if ( SinglePassNoder$$1 ) MCIndexNoder.__proto__ = SinglePassNoder$$1;
  10725. MCIndexNoder.prototype = Object.create( SinglePassNoder$$1 && SinglePassNoder$$1.prototype );
  10726. MCIndexNoder.prototype.constructor = MCIndexNoder;
  10727. var staticAccessors = { SegmentOverlapAction: { configurable: true } };
  10728. MCIndexNoder.prototype.getMonotoneChains = function getMonotoneChains () {
  10729. return this._monoChains
  10730. };
  10731. MCIndexNoder.prototype.getNodedSubstrings = function getNodedSubstrings () {
  10732. return NodedSegmentString.getNodedSubstrings(this._nodedSegStrings)
  10733. };
  10734. MCIndexNoder.prototype.getIndex = function getIndex () {
  10735. return this._index
  10736. };
  10737. MCIndexNoder.prototype.add = function add (segStr) {
  10738. var this$1 = this;
  10739. var segChains = MonotoneChainBuilder.getChains(segStr.getCoordinates(), segStr);
  10740. for (var i = segChains.iterator(); i.hasNext();) {
  10741. var mc = i.next();
  10742. mc.setId(this$1._idCounter++);
  10743. this$1._index.insert(mc.getEnvelope(), mc);
  10744. this$1._monoChains.add(mc);
  10745. }
  10746. };
  10747. MCIndexNoder.prototype.computeNodes = function computeNodes (inputSegStrings) {
  10748. var this$1 = this;
  10749. this._nodedSegStrings = inputSegStrings;
  10750. for (var i = inputSegStrings.iterator(); i.hasNext();) {
  10751. this$1.add(i.next());
  10752. }
  10753. this.intersectChains();
  10754. };
  10755. MCIndexNoder.prototype.intersectChains = function intersectChains () {
  10756. var this$1 = this;
  10757. var overlapAction = new SegmentOverlapAction(this._segInt);
  10758. for (var i = this._monoChains.iterator(); i.hasNext();) {
  10759. var queryChain = i.next();
  10760. var overlapChains = this$1._index.query(queryChain.getEnvelope());
  10761. for (var j = overlapChains.iterator(); j.hasNext();) {
  10762. var testChain = j.next();
  10763. if (testChain.getId() > queryChain.getId()) {
  10764. queryChain.computeOverlaps(testChain, overlapAction);
  10765. this$1._nOverlaps++;
  10766. }
  10767. if (this$1._segInt.isDone()) { return null }
  10768. }
  10769. }
  10770. };
  10771. MCIndexNoder.prototype.interfaces_ = function interfaces_ () {
  10772. return []
  10773. };
  10774. MCIndexNoder.prototype.getClass = function getClass () {
  10775. return MCIndexNoder
  10776. };
  10777. staticAccessors.SegmentOverlapAction.get = function () { return SegmentOverlapAction };
  10778. Object.defineProperties( MCIndexNoder, staticAccessors );
  10779. return MCIndexNoder;
  10780. }(SinglePassNoder));
  10781. var SegmentOverlapAction = (function (MonotoneChainOverlapAction$$1) {
  10782. function SegmentOverlapAction () {
  10783. MonotoneChainOverlapAction$$1.call(this);
  10784. this._si = null;
  10785. var si = arguments[0];
  10786. this._si = si;
  10787. }
  10788. if ( MonotoneChainOverlapAction$$1 ) SegmentOverlapAction.__proto__ = MonotoneChainOverlapAction$$1;
  10789. SegmentOverlapAction.prototype = Object.create( MonotoneChainOverlapAction$$1 && MonotoneChainOverlapAction$$1.prototype );
  10790. SegmentOverlapAction.prototype.constructor = SegmentOverlapAction;
  10791. SegmentOverlapAction.prototype.overlap = function overlap () {
  10792. if (arguments.length === 4) {
  10793. var mc1 = arguments[0];
  10794. var start1 = arguments[1];
  10795. var mc2 = arguments[2];
  10796. var start2 = arguments[3];
  10797. var ss1 = mc1.getContext();
  10798. var ss2 = mc2.getContext();
  10799. this._si.processIntersections(ss1, start1, ss2, start2);
  10800. } else { return MonotoneChainOverlapAction$$1.prototype.overlap.apply(this, arguments) }
  10801. };
  10802. SegmentOverlapAction.prototype.interfaces_ = function interfaces_ () {
  10803. return []
  10804. };
  10805. SegmentOverlapAction.prototype.getClass = function getClass () {
  10806. return SegmentOverlapAction
  10807. };
  10808. return SegmentOverlapAction;
  10809. }(MonotoneChainOverlapAction));
  10810. var BufferParameters = function BufferParameters () {
  10811. this._quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS;
  10812. this._endCapStyle = BufferParameters.CAP_ROUND;
  10813. this._joinStyle = BufferParameters.JOIN_ROUND;
  10814. this._mitreLimit = BufferParameters.DEFAULT_MITRE_LIMIT;
  10815. this._isSingleSided = false;
  10816. this._simplifyFactor = BufferParameters.DEFAULT_SIMPLIFY_FACTOR;
  10817. if (arguments.length === 0) {} else if (arguments.length === 1) {
  10818. var quadrantSegments = arguments[0];
  10819. this.setQuadrantSegments(quadrantSegments);
  10820. } else if (arguments.length === 2) {
  10821. var quadrantSegments$1 = arguments[0];
  10822. var endCapStyle = arguments[1];
  10823. this.setQuadrantSegments(quadrantSegments$1);
  10824. this.setEndCapStyle(endCapStyle);
  10825. } else if (arguments.length === 4) {
  10826. var quadrantSegments$2 = arguments[0];
  10827. var endCapStyle$1 = arguments[1];
  10828. var joinStyle = arguments[2];
  10829. var mitreLimit = arguments[3];
  10830. this.setQuadrantSegments(quadrantSegments$2);
  10831. this.setEndCapStyle(endCapStyle$1);
  10832. this.setJoinStyle(joinStyle);
  10833. this.setMitreLimit(mitreLimit);
  10834. }
  10835. };
  10836. var staticAccessors$25 = { CAP_ROUND: { configurable: true },CAP_FLAT: { configurable: true },CAP_SQUARE: { configurable: true },JOIN_ROUND: { configurable: true },JOIN_MITRE: { configurable: true },JOIN_BEVEL: { configurable: true },DEFAULT_QUADRANT_SEGMENTS: { configurable: true },DEFAULT_MITRE_LIMIT: { configurable: true },DEFAULT_SIMPLIFY_FACTOR: { configurable: true } };
  10837. BufferParameters.prototype.getEndCapStyle = function getEndCapStyle () {
  10838. return this._endCapStyle
  10839. };
  10840. BufferParameters.prototype.isSingleSided = function isSingleSided () {
  10841. return this._isSingleSided
  10842. };
  10843. BufferParameters.prototype.setQuadrantSegments = function setQuadrantSegments (quadSegs) {
  10844. this._quadrantSegments = quadSegs;
  10845. if (this._quadrantSegments === 0) { this._joinStyle = BufferParameters.JOIN_BEVEL; }
  10846. if (this._quadrantSegments < 0) {
  10847. this._joinStyle = BufferParameters.JOIN_MITRE;
  10848. this._mitreLimit = Math.abs(this._quadrantSegments);
  10849. }
  10850. if (quadSegs <= 0) {
  10851. this._quadrantSegments = 1;
  10852. }
  10853. if (this._joinStyle !== BufferParameters.JOIN_ROUND) {
  10854. this._quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS;
  10855. }
  10856. };
  10857. BufferParameters.prototype.getJoinStyle = function getJoinStyle () {
  10858. return this._joinStyle
  10859. };
  10860. BufferParameters.prototype.setJoinStyle = function setJoinStyle (joinStyle) {
  10861. this._joinStyle = joinStyle;
  10862. };
  10863. BufferParameters.prototype.setSimplifyFactor = function setSimplifyFactor (simplifyFactor) {
  10864. this._simplifyFactor = simplifyFactor < 0 ? 0 : simplifyFactor;
  10865. };
  10866. BufferParameters.prototype.getSimplifyFactor = function getSimplifyFactor () {
  10867. return this._simplifyFactor
  10868. };
  10869. BufferParameters.prototype.getQuadrantSegments = function getQuadrantSegments () {
  10870. return this._quadrantSegments
  10871. };
  10872. BufferParameters.prototype.setEndCapStyle = function setEndCapStyle (endCapStyle) {
  10873. this._endCapStyle = endCapStyle;
  10874. };
  10875. BufferParameters.prototype.getMitreLimit = function getMitreLimit () {
  10876. return this._mitreLimit
  10877. };
  10878. BufferParameters.prototype.setMitreLimit = function setMitreLimit (mitreLimit) {
  10879. this._mitreLimit = mitreLimit;
  10880. };
  10881. BufferParameters.prototype.setSingleSided = function setSingleSided (isSingleSided) {
  10882. this._isSingleSided = isSingleSided;
  10883. };
  10884. BufferParameters.prototype.interfaces_ = function interfaces_ () {
  10885. return []
  10886. };
  10887. BufferParameters.prototype.getClass = function getClass () {
  10888. return BufferParameters
  10889. };
  10890. BufferParameters.bufferDistanceError = function bufferDistanceError (quadSegs) {
  10891. var alpha = Math.PI / 2.0 / quadSegs;
  10892. return 1 - Math.cos(alpha / 2.0)
  10893. };
  10894. staticAccessors$25.CAP_ROUND.get = function () { return 1 };
  10895. staticAccessors$25.CAP_FLAT.get = function () { return 2 };
  10896. staticAccessors$25.CAP_SQUARE.get = function () { return 3 };
  10897. staticAccessors$25.JOIN_ROUND.get = function () { return 1 };
  10898. staticAccessors$25.JOIN_MITRE.get = function () { return 2 };
  10899. staticAccessors$25.JOIN_BEVEL.get = function () { return 3 };
  10900. staticAccessors$25.DEFAULT_QUADRANT_SEGMENTS.get = function () { return 8 };
  10901. staticAccessors$25.DEFAULT_MITRE_LIMIT.get = function () { return 5.0 };
  10902. staticAccessors$25.DEFAULT_SIMPLIFY_FACTOR.get = function () { return 0.01 };
  10903. Object.defineProperties( BufferParameters, staticAccessors$25 );
  10904. var BufferInputLineSimplifier = function BufferInputLineSimplifier (inputLine) {
  10905. this._distanceTol = null;
  10906. this._isDeleted = null;
  10907. this._angleOrientation = CGAlgorithms.COUNTERCLOCKWISE;
  10908. this._inputLine = inputLine || null;
  10909. };
  10910. var staticAccessors$26 = { INIT: { configurable: true },DELETE: { configurable: true },KEEP: { configurable: true },NUM_PTS_TO_CHECK: { configurable: true } };
  10911. BufferInputLineSimplifier.prototype.isDeletable = function isDeletable (i0, i1, i2, distanceTol) {
  10912. var p0 = this._inputLine[i0];
  10913. var p1 = this._inputLine[i1];
  10914. var p2 = this._inputLine[i2];
  10915. if (!this.isConcave(p0, p1, p2)) { return false }
  10916. if (!this.isShallow(p0, p1, p2, distanceTol)) { return false }
  10917. return this.isShallowSampled(p0, p1, i0, i2, distanceTol)
  10918. };
  10919. BufferInputLineSimplifier.prototype.deleteShallowConcavities = function deleteShallowConcavities () {
  10920. var this$1 = this;
  10921. var index = 1;
  10922. // const maxIndex = this._inputLine.length - 1
  10923. var midIndex = this.findNextNonDeletedIndex(index);
  10924. var lastIndex = this.findNextNonDeletedIndex(midIndex);
  10925. var isChanged = false;
  10926. while (lastIndex < this._inputLine.length) {
  10927. var isMiddleVertexDeleted = false;
  10928. if (this$1.isDeletable(index, midIndex, lastIndex, this$1._distanceTol)) {
  10929. this$1._isDeleted[midIndex] = BufferInputLineSimplifier.DELETE;
  10930. isMiddleVertexDeleted = true;
  10931. isChanged = true;
  10932. }
  10933. if (isMiddleVertexDeleted) { index = lastIndex; } else { index = midIndex; }
  10934. midIndex = this$1.findNextNonDeletedIndex(index);
  10935. lastIndex = this$1.findNextNonDeletedIndex(midIndex);
  10936. }
  10937. return isChanged
  10938. };
  10939. BufferInputLineSimplifier.prototype.isShallowConcavity = function isShallowConcavity (p0, p1, p2, distanceTol) {
  10940. var orientation = CGAlgorithms.computeOrientation(p0, p1, p2);
  10941. var isAngleToSimplify = orientation === this._angleOrientation;
  10942. if (!isAngleToSimplify) { return false }
  10943. var dist = CGAlgorithms.distancePointLine(p1, p0, p2);
  10944. return dist < distanceTol
  10945. };
  10946. BufferInputLineSimplifier.prototype.isShallowSampled = function isShallowSampled (p0, p2, i0, i2, distanceTol) {
  10947. var this$1 = this;
  10948. var inc = Math.trunc((i2 - i0) / BufferInputLineSimplifier.NUM_PTS_TO_CHECK);
  10949. if (inc <= 0) { inc = 1; }
  10950. for (var i = i0; i < i2; i += inc) {
  10951. if (!this$1.isShallow(p0, p2, this$1._inputLine[i], distanceTol)) { return false }
  10952. }
  10953. return true
  10954. };
  10955. BufferInputLineSimplifier.prototype.isConcave = function isConcave (p0, p1, p2) {
  10956. var orientation = CGAlgorithms.computeOrientation(p0, p1, p2);
  10957. var isConcave = orientation === this._angleOrientation;
  10958. return isConcave
  10959. };
  10960. BufferInputLineSimplifier.prototype.simplify = function simplify (distanceTol) {
  10961. var this$1 = this;
  10962. this._distanceTol = Math.abs(distanceTol);
  10963. if (distanceTol < 0) { this._angleOrientation = CGAlgorithms.CLOCKWISE; }
  10964. this._isDeleted = new Array(this._inputLine.length).fill(null);
  10965. var isChanged = false;
  10966. do {
  10967. isChanged = this$1.deleteShallowConcavities();
  10968. } while (isChanged)
  10969. return this.collapseLine()
  10970. };
  10971. BufferInputLineSimplifier.prototype.findNextNonDeletedIndex = function findNextNonDeletedIndex (index) {
  10972. var next = index + 1;
  10973. while (next < this._inputLine.length && this._isDeleted[next] === BufferInputLineSimplifier.DELETE) { next++; }
  10974. return next
  10975. };
  10976. BufferInputLineSimplifier.prototype.isShallow = function isShallow (p0, p1, p2, distanceTol) {
  10977. var dist = CGAlgorithms.distancePointLine(p1, p0, p2);
  10978. return dist < distanceTol
  10979. };
  10980. BufferInputLineSimplifier.prototype.collapseLine = function collapseLine () {
  10981. var this$1 = this;
  10982. var coordList = new CoordinateList();
  10983. for (var i = 0; i < this._inputLine.length; i++) {
  10984. if (this$1._isDeleted[i] !== BufferInputLineSimplifier.DELETE) { coordList.add(this$1._inputLine[i]); }
  10985. }
  10986. return coordList.toCoordinateArray()
  10987. };
  10988. BufferInputLineSimplifier.prototype.interfaces_ = function interfaces_ () {
  10989. return []
  10990. };
  10991. BufferInputLineSimplifier.prototype.getClass = function getClass () {
  10992. return BufferInputLineSimplifier
  10993. };
  10994. BufferInputLineSimplifier.simplify = function simplify (inputLine, distanceTol) {
  10995. var simp = new BufferInputLineSimplifier(inputLine);
  10996. return simp.simplify(distanceTol)
  10997. };
  10998. staticAccessors$26.INIT.get = function () { return 0 };
  10999. staticAccessors$26.DELETE.get = function () { return 1 };
  11000. staticAccessors$26.KEEP.get = function () { return 1 };
  11001. staticAccessors$26.NUM_PTS_TO_CHECK.get = function () { return 10 };
  11002. Object.defineProperties( BufferInputLineSimplifier, staticAccessors$26 );
  11003. var OffsetSegmentString = function OffsetSegmentString () {
  11004. this._ptList = null;
  11005. this._precisionModel = null;
  11006. this._minimimVertexDistance = 0.0;
  11007. this._ptList = new ArrayList();
  11008. };
  11009. var staticAccessors$28 = { COORDINATE_ARRAY_TYPE: { configurable: true } };
  11010. OffsetSegmentString.prototype.getCoordinates = function getCoordinates () {
  11011. var coord = this._ptList.toArray(OffsetSegmentString.COORDINATE_ARRAY_TYPE);
  11012. return coord
  11013. };
  11014. OffsetSegmentString.prototype.setPrecisionModel = function setPrecisionModel (precisionModel) {
  11015. this._precisionModel = precisionModel;
  11016. };
  11017. OffsetSegmentString.prototype.addPt = function addPt (pt) {
  11018. var bufPt = new Coordinate(pt);
  11019. this._precisionModel.makePrecise(bufPt);
  11020. if (this.isRedundant(bufPt)) { return null }
  11021. this._ptList.add(bufPt);
  11022. };
  11023. OffsetSegmentString.prototype.revere = function revere () {};
  11024. OffsetSegmentString.prototype.addPts = function addPts (pt, isForward) {
  11025. var this$1 = this;
  11026. if (isForward) {
  11027. for (var i = 0; i < pt.length; i++) {
  11028. this$1.addPt(pt[i]);
  11029. }
  11030. } else {
  11031. for (var i$1 = pt.length - 1; i$1 >= 0; i$1--) {
  11032. this$1.addPt(pt[i$1]);
  11033. }
  11034. }
  11035. };
  11036. OffsetSegmentString.prototype.isRedundant = function isRedundant (pt) {
  11037. if (this._ptList.size() < 1) { return false }
  11038. var lastPt = this._ptList.get(this._ptList.size() - 1);
  11039. var ptDist = pt.distance(lastPt);
  11040. if (ptDist < this._minimimVertexDistance) { return true }
  11041. return false
  11042. };
  11043. OffsetSegmentString.prototype.toString = function toString () {
  11044. var fact = new GeometryFactory();
  11045. var line = fact.createLineString(this.getCoordinates());
  11046. return line.toString()
  11047. };
  11048. OffsetSegmentString.prototype.closeRing = function closeRing () {
  11049. if (this._ptList.size() < 1) { return null }
  11050. var startPt = new Coordinate(this._ptList.get(0));
  11051. var lastPt = this._ptList.get(this._ptList.size() - 1);
  11052. // const last2Pt = null
  11053. // if (this._ptList.size() >= 2) last2Pt = this._ptList.get(this._ptList.size() - 2)
  11054. if (startPt.equals(lastPt)) { return null }
  11055. this._ptList.add(startPt);
  11056. };
  11057. OffsetSegmentString.prototype.setMinimumVertexDistance = function setMinimumVertexDistance (minimimVertexDistance) {
  11058. this._minimimVertexDistance = minimimVertexDistance;
  11059. };
  11060. OffsetSegmentString.prototype.interfaces_ = function interfaces_ () {
  11061. return []
  11062. };
  11063. OffsetSegmentString.prototype.getClass = function getClass () {
  11064. return OffsetSegmentString
  11065. };
  11066. staticAccessors$28.COORDINATE_ARRAY_TYPE.get = function () { return new Array(0).fill(null) };
  11067. Object.defineProperties( OffsetSegmentString, staticAccessors$28 );
  11068. var Angle = function Angle () {};
  11069. var staticAccessors$29 = { PI_TIMES_2: { configurable: true },PI_OVER_2: { configurable: true },PI_OVER_4: { configurable: true },COUNTERCLOCKWISE: { configurable: true },CLOCKWISE: { configurable: true },NONE: { configurable: true } };
  11070. Angle.prototype.interfaces_ = function interfaces_ () {
  11071. return []
  11072. };
  11073. Angle.prototype.getClass = function getClass () {
  11074. return Angle
  11075. };
  11076. Angle.toDegrees = function toDegrees (radians) {
  11077. return radians * 180 / Math.PI
  11078. };
  11079. Angle.normalize = function normalize (angle) {
  11080. while (angle > Math.PI) { angle -= Angle.PI_TIMES_2; }
  11081. while (angle <= -Math.PI) { angle += Angle.PI_TIMES_2; }
  11082. return angle
  11083. };
  11084. Angle.angle = function angle () {
  11085. if (arguments.length === 1) {
  11086. var p = arguments[0];
  11087. return Math.atan2(p.y, p.x)
  11088. } else if (arguments.length === 2) {
  11089. var p0 = arguments[0];
  11090. var p1 = arguments[1];
  11091. var dx = p1.x - p0.x;
  11092. var dy = p1.y - p0.y;
  11093. return Math.atan2(dy, dx)
  11094. }
  11095. };
  11096. Angle.isAcute = function isAcute (p0, p1, p2) {
  11097. var dx0 = p0.x - p1.x;
  11098. var dy0 = p0.y - p1.y;
  11099. var dx1 = p2.x - p1.x;
  11100. var dy1 = p2.y - p1.y;
  11101. var dotprod = dx0 * dx1 + dy0 * dy1;
  11102. return dotprod > 0
  11103. };
  11104. Angle.isObtuse = function isObtuse (p0, p1, p2) {
  11105. var dx0 = p0.x - p1.x;
  11106. var dy0 = p0.y - p1.y;
  11107. var dx1 = p2.x - p1.x;
  11108. var dy1 = p2.y - p1.y;
  11109. var dotprod = dx0 * dx1 + dy0 * dy1;
  11110. return dotprod < 0
  11111. };
  11112. Angle.interiorAngle = function interiorAngle (p0, p1, p2) {
  11113. var anglePrev = Angle.angle(p1, p0);
  11114. var angleNext = Angle.angle(p1, p2);
  11115. return Math.abs(angleNext - anglePrev)
  11116. };
  11117. Angle.normalizePositive = function normalizePositive (angle) {
  11118. if (angle < 0.0) {
  11119. while (angle < 0.0) { angle += Angle.PI_TIMES_2; }
  11120. if (angle >= Angle.PI_TIMES_2) { angle = 0.0; }
  11121. } else {
  11122. while (angle >= Angle.PI_TIMES_2) { angle -= Angle.PI_TIMES_2; }
  11123. if (angle < 0.0) { angle = 0.0; }
  11124. }
  11125. return angle
  11126. };
  11127. Angle.angleBetween = function angleBetween (tip1, tail, tip2) {
  11128. var a1 = Angle.angle(tail, tip1);
  11129. var a2 = Angle.angle(tail, tip2);
  11130. return Angle.diff(a1, a2)
  11131. };
  11132. Angle.diff = function diff (ang1, ang2) {
  11133. var delAngle = null;
  11134. if (ang1 < ang2) {
  11135. delAngle = ang2 - ang1;
  11136. } else {
  11137. delAngle = ang1 - ang2;
  11138. }
  11139. if (delAngle > Math.PI) {
  11140. delAngle = 2 * Math.PI - delAngle;
  11141. }
  11142. return delAngle
  11143. };
  11144. Angle.toRadians = function toRadians (angleDegrees) {
  11145. return angleDegrees * Math.PI / 180.0
  11146. };
  11147. Angle.getTurn = function getTurn (ang1, ang2) {
  11148. var crossproduct = Math.sin(ang2 - ang1);
  11149. if (crossproduct > 0) {
  11150. return Angle.COUNTERCLOCKWISE
  11151. }
  11152. if (crossproduct < 0) {
  11153. return Angle.CLOCKWISE
  11154. }
  11155. return Angle.NONE
  11156. };
  11157. Angle.angleBetweenOriented = function angleBetweenOriented (tip1, tail, tip2) {
  11158. var a1 = Angle.angle(tail, tip1);
  11159. var a2 = Angle.angle(tail, tip2);
  11160. var angDel = a2 - a1;
  11161. if (angDel <= -Math.PI) { return angDel + Angle.PI_TIMES_2 }
  11162. if (angDel > Math.PI) { return angDel - Angle.PI_TIMES_2 }
  11163. return angDel
  11164. };
  11165. staticAccessors$29.PI_TIMES_2.get = function () { return 2.0 * Math.PI };
  11166. staticAccessors$29.PI_OVER_2.get = function () { return Math.PI / 2.0 };
  11167. staticAccessors$29.PI_OVER_4.get = function () { return Math.PI / 4.0 };
  11168. staticAccessors$29.COUNTERCLOCKWISE.get = function () { return CGAlgorithms.COUNTERCLOCKWISE };
  11169. staticAccessors$29.CLOCKWISE.get = function () { return CGAlgorithms.CLOCKWISE };
  11170. staticAccessors$29.NONE.get = function () { return CGAlgorithms.COLLINEAR };
  11171. Object.defineProperties( Angle, staticAccessors$29 );
  11172. var OffsetSegmentGenerator = function OffsetSegmentGenerator () {
  11173. this._maxCurveSegmentError = 0.0;
  11174. this._filletAngleQuantum = null;
  11175. this._closingSegLengthFactor = 1;
  11176. this._segList = null;
  11177. this._distance = 0.0;
  11178. this._precisionModel = null;
  11179. this._bufParams = null;
  11180. this._li = null;
  11181. this._s0 = null;
  11182. this._s1 = null;
  11183. this._s2 = null;
  11184. this._seg0 = new LineSegment();
  11185. this._seg1 = new LineSegment();
  11186. this._offset0 = new LineSegment();
  11187. this._offset1 = new LineSegment();
  11188. this._side = 0;
  11189. this._hasNarrowConcaveAngle = false;
  11190. var precisionModel = arguments[0];
  11191. var bufParams = arguments[1];
  11192. var distance = arguments[2];
  11193. this._precisionModel = precisionModel;
  11194. this._bufParams = bufParams;
  11195. this._li = new RobustLineIntersector();
  11196. this._filletAngleQuantum = Math.PI / 2.0 / bufParams.getQuadrantSegments();
  11197. if (bufParams.getQuadrantSegments() >= 8 && bufParams.getJoinStyle() === BufferParameters.JOIN_ROUND) { this._closingSegLengthFactor = OffsetSegmentGenerator.MAX_CLOSING_SEG_LEN_FACTOR; }
  11198. this.init(distance);
  11199. };
  11200. var staticAccessors$27 = { OFFSET_SEGMENT_SEPARATION_FACTOR: { configurable: true },INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR: { configurable: true },CURVE_VERTEX_SNAP_DISTANCE_FACTOR: { configurable: true },MAX_CLOSING_SEG_LEN_FACTOR: { configurable: true } };
  11201. OffsetSegmentGenerator.prototype.addNextSegment = function addNextSegment (p, addStartPoint) {
  11202. this._s0 = this._s1;
  11203. this._s1 = this._s2;
  11204. this._s2 = p;
  11205. this._seg0.setCoordinates(this._s0, this._s1);
  11206. this.computeOffsetSegment(this._seg0, this._side, this._distance, this._offset0);
  11207. this._seg1.setCoordinates(this._s1, this._s2);
  11208. this.computeOffsetSegment(this._seg1, this._side, this._distance, this._offset1);
  11209. if (this._s1.equals(this._s2)) { return null }
  11210. var orientation = CGAlgorithms.computeOrientation(this._s0, this._s1, this._s2);
  11211. var outsideTurn = (orientation === CGAlgorithms.CLOCKWISE && this._side === Position.LEFT) || (orientation === CGAlgorithms.COUNTERCLOCKWISE && this._side === Position.RIGHT);
  11212. if (orientation === 0) {
  11213. this.addCollinear(addStartPoint);
  11214. } else if (outsideTurn) {
  11215. this.addOutsideTurn(orientation, addStartPoint);
  11216. } else {
  11217. this.addInsideTurn(orientation, addStartPoint);
  11218. }
  11219. };
  11220. OffsetSegmentGenerator.prototype.addLineEndCap = function addLineEndCap (p0, p1) {
  11221. var seg = new LineSegment(p0, p1);
  11222. var offsetL = new LineSegment();
  11223. this.computeOffsetSegment(seg, Position.LEFT, this._distance, offsetL);
  11224. var offsetR = new LineSegment();
  11225. this.computeOffsetSegment(seg, Position.RIGHT, this._distance, offsetR);
  11226. var dx = p1.x - p0.x;
  11227. var dy = p1.y - p0.y;
  11228. var angle = Math.atan2(dy, dx);
  11229. switch (this._bufParams.getEndCapStyle()) {
  11230. case BufferParameters.CAP_ROUND:
  11231. this._segList.addPt(offsetL.p1);
  11232. this.addFilletArc(p1, angle + Math.PI / 2, angle - Math.PI / 2, CGAlgorithms.CLOCKWISE, this._distance);
  11233. this._segList.addPt(offsetR.p1);
  11234. break
  11235. case BufferParameters.CAP_FLAT:
  11236. this._segList.addPt(offsetL.p1);
  11237. this._segList.addPt(offsetR.p1);
  11238. break
  11239. case BufferParameters.CAP_SQUARE:
  11240. var squareCapSideOffset = new Coordinate();
  11241. squareCapSideOffset.x = Math.abs(this._distance) * Math.cos(angle);
  11242. squareCapSideOffset.y = Math.abs(this._distance) * Math.sin(angle);
  11243. var squareCapLOffset = new Coordinate(offsetL.p1.x + squareCapSideOffset.x, offsetL.p1.y + squareCapSideOffset.y);
  11244. var squareCapROffset = new Coordinate(offsetR.p1.x + squareCapSideOffset.x, offsetR.p1.y + squareCapSideOffset.y);
  11245. this._segList.addPt(squareCapLOffset);
  11246. this._segList.addPt(squareCapROffset);
  11247. break
  11248. default:
  11249. }
  11250. };
  11251. OffsetSegmentGenerator.prototype.getCoordinates = function getCoordinates () {
  11252. var pts = this._segList.getCoordinates();
  11253. return pts
  11254. };
  11255. OffsetSegmentGenerator.prototype.addMitreJoin = function addMitreJoin (p, offset0, offset1, distance) {
  11256. var isMitreWithinLimit = true;
  11257. var intPt = null;
  11258. try {
  11259. intPt = HCoordinate.intersection(offset0.p0, offset0.p1, offset1.p0, offset1.p1);
  11260. var mitreRatio = distance <= 0.0 ? 1.0 : intPt.distance(p) / Math.abs(distance);
  11261. if (mitreRatio > this._bufParams.getMitreLimit()) { isMitreWithinLimit = false; }
  11262. } catch (ex) {
  11263. if (ex instanceof NotRepresentableException) {
  11264. intPt = new Coordinate(0, 0);
  11265. isMitreWithinLimit = false;
  11266. } else { throw ex }
  11267. } finally {}
  11268. if (isMitreWithinLimit) {
  11269. this._segList.addPt(intPt);
  11270. } else {
  11271. this.addLimitedMitreJoin(offset0, offset1, distance, this._bufParams.getMitreLimit());
  11272. }
  11273. };
  11274. OffsetSegmentGenerator.prototype.addFilletCorner = function addFilletCorner (p, p0, p1, direction, radius) {
  11275. var dx0 = p0.x - p.x;
  11276. var dy0 = p0.y - p.y;
  11277. var startAngle = Math.atan2(dy0, dx0);
  11278. var dx1 = p1.x - p.x;
  11279. var dy1 = p1.y - p.y;
  11280. var endAngle = Math.atan2(dy1, dx1);
  11281. if (direction === CGAlgorithms.CLOCKWISE) {
  11282. if (startAngle <= endAngle) { startAngle += 2.0 * Math.PI; }
  11283. } else {
  11284. if (startAngle >= endAngle) { startAngle -= 2.0 * Math.PI; }
  11285. }
  11286. this._segList.addPt(p0);
  11287. this.addFilletArc(p, startAngle, endAngle, direction, radius);
  11288. this._segList.addPt(p1);
  11289. };
  11290. OffsetSegmentGenerator.prototype.addOutsideTurn = function addOutsideTurn (orientation, addStartPoint) {
  11291. if (this._offset0.p1.distance(this._offset1.p0) < this._distance * OffsetSegmentGenerator.OFFSET_SEGMENT_SEPARATION_FACTOR) {
  11292. this._segList.addPt(this._offset0.p1);
  11293. return null
  11294. }
  11295. if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_MITRE) {
  11296. this.addMitreJoin(this._s1, this._offset0, this._offset1, this._distance);
  11297. } else if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_BEVEL) {
  11298. this.addBevelJoin(this._offset0, this._offset1);
  11299. } else {
  11300. if (addStartPoint) { this._segList.addPt(this._offset0.p1); }
  11301. this.addFilletCorner(this._s1, this._offset0.p1, this._offset1.p0, orientation, this._distance);
  11302. this._segList.addPt(this._offset1.p0);
  11303. }
  11304. };
  11305. OffsetSegmentGenerator.prototype.createSquare = function createSquare (p) {
  11306. this._segList.addPt(new Coordinate(p.x + this._distance, p.y + this._distance));
  11307. this._segList.addPt(new Coordinate(p.x + this._distance, p.y - this._distance));
  11308. this._segList.addPt(new Coordinate(p.x - this._distance, p.y - this._distance));
  11309. this._segList.addPt(new Coordinate(p.x - this._distance, p.y + this._distance));
  11310. this._segList.closeRing();
  11311. };
  11312. OffsetSegmentGenerator.prototype.addSegments = function addSegments (pt, isForward) {
  11313. this._segList.addPts(pt, isForward);
  11314. };
  11315. OffsetSegmentGenerator.prototype.addFirstSegment = function addFirstSegment () {
  11316. this._segList.addPt(this._offset1.p0);
  11317. };
  11318. OffsetSegmentGenerator.prototype.addLastSegment = function addLastSegment () {
  11319. this._segList.addPt(this._offset1.p1);
  11320. };
  11321. OffsetSegmentGenerator.prototype.initSideSegments = function initSideSegments (s1, s2, side) {
  11322. this._s1 = s1;
  11323. this._s2 = s2;
  11324. this._side = side;
  11325. this._seg1.setCoordinates(s1, s2);
  11326. this.computeOffsetSegment(this._seg1, side, this._distance, this._offset1);
  11327. };
  11328. OffsetSegmentGenerator.prototype.addLimitedMitreJoin = function addLimitedMitreJoin (offset0, offset1, distance, mitreLimit) {
  11329. var basePt = this._seg0.p1;
  11330. var ang0 = Angle.angle(basePt, this._seg0.p0);
  11331. // const ang1 = Angle.angle(basePt, this._seg1.p1)
  11332. var angDiff = Angle.angleBetweenOriented(this._seg0.p0, basePt, this._seg1.p1);
  11333. var angDiffHalf = angDiff / 2;
  11334. var midAng = Angle.normalize(ang0 + angDiffHalf);
  11335. var mitreMidAng = Angle.normalize(midAng + Math.PI);
  11336. var mitreDist = mitreLimit * distance;
  11337. var bevelDelta = mitreDist * Math.abs(Math.sin(angDiffHalf));
  11338. var bevelHalfLen = distance - bevelDelta;
  11339. var bevelMidX = basePt.x + mitreDist * Math.cos(mitreMidAng);
  11340. var bevelMidY = basePt.y + mitreDist * Math.sin(mitreMidAng);
  11341. var bevelMidPt = new Coordinate(bevelMidX, bevelMidY);
  11342. var mitreMidLine = new LineSegment(basePt, bevelMidPt);
  11343. var bevelEndLeft = mitreMidLine.pointAlongOffset(1.0, bevelHalfLen);
  11344. var bevelEndRight = mitreMidLine.pointAlongOffset(1.0, -bevelHalfLen);
  11345. if (this._side === Position.LEFT) {
  11346. this._segList.addPt(bevelEndLeft);
  11347. this._segList.addPt(bevelEndRight);
  11348. } else {
  11349. this._segList.addPt(bevelEndRight);
  11350. this._segList.addPt(bevelEndLeft);
  11351. }
  11352. };
  11353. OffsetSegmentGenerator.prototype.computeOffsetSegment = function computeOffsetSegment (seg, side, distance, offset) {
  11354. var sideSign = side === Position.LEFT ? 1 : -1;
  11355. var dx = seg.p1.x - seg.p0.x;
  11356. var dy = seg.p1.y - seg.p0.y;
  11357. var len = Math.sqrt(dx * dx + dy * dy);
  11358. var ux = sideSign * distance * dx / len;
  11359. var uy = sideSign * distance * dy / len;
  11360. offset.p0.x = seg.p0.x - uy;
  11361. offset.p0.y = seg.p0.y + ux;
  11362. offset.p1.x = seg.p1.x - uy;
  11363. offset.p1.y = seg.p1.y + ux;
  11364. };
  11365. OffsetSegmentGenerator.prototype.addFilletArc = function addFilletArc (p, startAngle, endAngle, direction, radius) {
  11366. var this$1 = this;
  11367. var directionFactor = direction === CGAlgorithms.CLOCKWISE ? -1 : 1;
  11368. var totalAngle = Math.abs(startAngle - endAngle);
  11369. var nSegs = Math.trunc(totalAngle / this._filletAngleQuantum + 0.5);
  11370. if (nSegs < 1) { return null }
  11371. var initAngle = 0.0;
  11372. var currAngleInc = totalAngle / nSegs;
  11373. var currAngle = initAngle;
  11374. var pt = new Coordinate();
  11375. while (currAngle < totalAngle) {
  11376. var angle = startAngle + directionFactor * currAngle;
  11377. pt.x = p.x + radius * Math.cos(angle);
  11378. pt.y = p.y + radius * Math.sin(angle);
  11379. this$1._segList.addPt(pt);
  11380. currAngle += currAngleInc;
  11381. }
  11382. };
  11383. OffsetSegmentGenerator.prototype.addInsideTurn = function addInsideTurn (orientation, addStartPoint) {
  11384. this._li.computeIntersection(this._offset0.p0, this._offset0.p1, this._offset1.p0, this._offset1.p1);
  11385. if (this._li.hasIntersection()) {
  11386. this._segList.addPt(this._li.getIntersection(0));
  11387. } else {
  11388. this._hasNarrowConcaveAngle = true;
  11389. if (this._offset0.p1.distance(this._offset1.p0) < this._distance * OffsetSegmentGenerator.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR) {
  11390. this._segList.addPt(this._offset0.p1);
  11391. } else {
  11392. this._segList.addPt(this._offset0.p1);
  11393. if (this._closingSegLengthFactor > 0) {
  11394. var mid0 = new Coordinate((this._closingSegLengthFactor * this._offset0.p1.x + this._s1.x) / (this._closingSegLengthFactor + 1), (this._closingSegLengthFactor * this._offset0.p1.y + this._s1.y) / (this._closingSegLengthFactor + 1));
  11395. this._segList.addPt(mid0);
  11396. var mid1 = new Coordinate((this._closingSegLengthFactor * this._offset1.p0.x + this._s1.x) / (this._closingSegLengthFactor + 1), (this._closingSegLengthFactor * this._offset1.p0.y + this._s1.y) / (this._closingSegLengthFactor + 1));
  11397. this._segList.addPt(mid1);
  11398. } else {
  11399. this._segList.addPt(this._s1);
  11400. }
  11401. this._segList.addPt(this._offset1.p0);
  11402. }
  11403. }
  11404. };
  11405. OffsetSegmentGenerator.prototype.createCircle = function createCircle (p) {
  11406. var pt = new Coordinate(p.x + this._distance, p.y);
  11407. this._segList.addPt(pt);
  11408. this.addFilletArc(p, 0.0, 2.0 * Math.PI, -1, this._distance);
  11409. this._segList.closeRing();
  11410. };
  11411. OffsetSegmentGenerator.prototype.addBevelJoin = function addBevelJoin (offset0, offset1) {
  11412. this._segList.addPt(offset0.p1);
  11413. this._segList.addPt(offset1.p0);
  11414. };
  11415. OffsetSegmentGenerator.prototype.init = function init (distance) {
  11416. this._distance = distance;
  11417. this._maxCurveSegmentError = distance * (1 - Math.cos(this._filletAngleQuantum / 2.0));
  11418. this._segList = new OffsetSegmentString();
  11419. this._segList.setPrecisionModel(this._precisionModel);
  11420. this._segList.setMinimumVertexDistance(distance * OffsetSegmentGenerator.CURVE_VERTEX_SNAP_DISTANCE_FACTOR);
  11421. };
  11422. OffsetSegmentGenerator.prototype.addCollinear = function addCollinear (addStartPoint) {
  11423. this._li.computeIntersection(this._s0, this._s1, this._s1, this._s2);
  11424. var numInt = this._li.getIntersectionNum();
  11425. if (numInt >= 2) {
  11426. if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_BEVEL || this._bufParams.getJoinStyle() === BufferParameters.JOIN_MITRE) {
  11427. if (addStartPoint) { this._segList.addPt(this._offset0.p1); }
  11428. this._segList.addPt(this._offset1.p0);
  11429. } else {
  11430. this.addFilletCorner(this._s1, this._offset0.p1, this._offset1.p0, CGAlgorithms.CLOCKWISE, this._distance);
  11431. }
  11432. }
  11433. };
  11434. OffsetSegmentGenerator.prototype.closeRing = function closeRing () {
  11435. this._segList.closeRing();
  11436. };
  11437. OffsetSegmentGenerator.prototype.hasNarrowConcaveAngle = function hasNarrowConcaveAngle () {
  11438. return this._hasNarrowConcaveAngle
  11439. };
  11440. OffsetSegmentGenerator.prototype.interfaces_ = function interfaces_ () {
  11441. return []
  11442. };
  11443. OffsetSegmentGenerator.prototype.getClass = function getClass () {
  11444. return OffsetSegmentGenerator
  11445. };
  11446. staticAccessors$27.OFFSET_SEGMENT_SEPARATION_FACTOR.get = function () { return 1.0E-3 };
  11447. staticAccessors$27.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR.get = function () { return 1.0E-3 };
  11448. staticAccessors$27.CURVE_VERTEX_SNAP_DISTANCE_FACTOR.get = function () { return 1.0E-6 };
  11449. staticAccessors$27.MAX_CLOSING_SEG_LEN_FACTOR.get = function () { return 80 };
  11450. Object.defineProperties( OffsetSegmentGenerator, staticAccessors$27 );
  11451. var OffsetCurveBuilder = function OffsetCurveBuilder () {
  11452. this._distance = 0.0;
  11453. this._precisionModel = null;
  11454. this._bufParams = null;
  11455. var precisionModel = arguments[0];
  11456. var bufParams = arguments[1];
  11457. this._precisionModel = precisionModel;
  11458. this._bufParams = bufParams;
  11459. };
  11460. OffsetCurveBuilder.prototype.getOffsetCurve = function getOffsetCurve (inputPts, distance) {
  11461. this._distance = distance;
  11462. if (distance === 0.0) { return null }
  11463. var isRightSide = distance < 0.0;
  11464. var posDistance = Math.abs(distance);
  11465. var segGen = this.getSegGen(posDistance);
  11466. if (inputPts.length <= 1) {
  11467. this.computePointCurve(inputPts[0], segGen);
  11468. } else {
  11469. this.computeOffsetCurve(inputPts, isRightSide, segGen);
  11470. }
  11471. var curvePts = segGen.getCoordinates();
  11472. if (isRightSide) { CoordinateArrays.reverse(curvePts); }
  11473. return curvePts
  11474. };
  11475. OffsetCurveBuilder.prototype.computeSingleSidedBufferCurve = function computeSingleSidedBufferCurve (inputPts, isRightSide, segGen) {
  11476. var distTol = this.simplifyTolerance(this._distance);
  11477. if (isRightSide) {
  11478. segGen.addSegments(inputPts, true);
  11479. var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);
  11480. var n2 = simp2.length - 1;
  11481. segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);
  11482. segGen.addFirstSegment();
  11483. for (var i = n2 - 2; i >= 0; i--) {
  11484. segGen.addNextSegment(simp2[i], true);
  11485. }
  11486. } else {
  11487. segGen.addSegments(inputPts, false);
  11488. var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);
  11489. var n1 = simp1.length - 1;
  11490. segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);
  11491. segGen.addFirstSegment();
  11492. for (var i$1 = 2; i$1 <= n1; i$1++) {
  11493. segGen.addNextSegment(simp1[i$1], true);
  11494. }
  11495. }
  11496. segGen.addLastSegment();
  11497. segGen.closeRing();
  11498. };
  11499. OffsetCurveBuilder.prototype.computeRingBufferCurve = function computeRingBufferCurve (inputPts, side, segGen) {
  11500. var distTol = this.simplifyTolerance(this._distance);
  11501. if (side === Position.RIGHT) { distTol = -distTol; }
  11502. var simp = BufferInputLineSimplifier.simplify(inputPts, distTol);
  11503. var n = simp.length - 1;
  11504. segGen.initSideSegments(simp[n - 1], simp[0], side);
  11505. for (var i = 1; i <= n; i++) {
  11506. var addStartPoint = i !== 1;
  11507. segGen.addNextSegment(simp[i], addStartPoint);
  11508. }
  11509. segGen.closeRing();
  11510. };
  11511. OffsetCurveBuilder.prototype.computeLineBufferCurve = function computeLineBufferCurve (inputPts, segGen) {
  11512. var distTol = this.simplifyTolerance(this._distance);
  11513. var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);
  11514. var n1 = simp1.length - 1;
  11515. segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);
  11516. for (var i = 2; i <= n1; i++) {
  11517. segGen.addNextSegment(simp1[i], true);
  11518. }
  11519. segGen.addLastSegment();
  11520. segGen.addLineEndCap(simp1[n1 - 1], simp1[n1]);
  11521. var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);
  11522. var n2 = simp2.length - 1;
  11523. segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);
  11524. for (var i$1 = n2 - 2; i$1 >= 0; i$1--) {
  11525. segGen.addNextSegment(simp2[i$1], true);
  11526. }
  11527. segGen.addLastSegment();
  11528. segGen.addLineEndCap(simp2[1], simp2[0]);
  11529. segGen.closeRing();
  11530. };
  11531. OffsetCurveBuilder.prototype.computePointCurve = function computePointCurve (pt, segGen) {
  11532. switch (this._bufParams.getEndCapStyle()) {
  11533. case BufferParameters.CAP_ROUND:
  11534. segGen.createCircle(pt);
  11535. break
  11536. case BufferParameters.CAP_SQUARE:
  11537. segGen.createSquare(pt);
  11538. break
  11539. default:
  11540. }
  11541. };
  11542. OffsetCurveBuilder.prototype.getLineCurve = function getLineCurve (inputPts, distance) {
  11543. this._distance = distance;
  11544. if (distance < 0.0 && !this._bufParams.isSingleSided()) { return null }
  11545. if (distance === 0.0) { return null }
  11546. var posDistance = Math.abs(distance);
  11547. var segGen = this.getSegGen(posDistance);
  11548. if (inputPts.length <= 1) {
  11549. this.computePointCurve(inputPts[0], segGen);
  11550. } else {
  11551. if (this._bufParams.isSingleSided()) {
  11552. var isRightSide = distance < 0.0;
  11553. this.computeSingleSidedBufferCurve(inputPts, isRightSide, segGen);
  11554. } else { this.computeLineBufferCurve(inputPts, segGen); }
  11555. }
  11556. var lineCoord = segGen.getCoordinates();
  11557. return lineCoord
  11558. };
  11559. OffsetCurveBuilder.prototype.getBufferParameters = function getBufferParameters () {
  11560. return this._bufParams
  11561. };
  11562. OffsetCurveBuilder.prototype.simplifyTolerance = function simplifyTolerance (bufDistance) {
  11563. return bufDistance * this._bufParams.getSimplifyFactor()
  11564. };
  11565. OffsetCurveBuilder.prototype.getRingCurve = function getRingCurve (inputPts, side, distance) {
  11566. this._distance = distance;
  11567. if (inputPts.length <= 2) { return this.getLineCurve(inputPts, distance) }
  11568. if (distance === 0.0) {
  11569. return OffsetCurveBuilder.copyCoordinates(inputPts)
  11570. }
  11571. var segGen = this.getSegGen(distance);
  11572. this.computeRingBufferCurve(inputPts, side, segGen);
  11573. return segGen.getCoordinates()
  11574. };
  11575. OffsetCurveBuilder.prototype.computeOffsetCurve = function computeOffsetCurve (inputPts, isRightSide, segGen) {
  11576. var distTol = this.simplifyTolerance(this._distance);
  11577. if (isRightSide) {
  11578. var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);
  11579. var n2 = simp2.length - 1;
  11580. segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);
  11581. segGen.addFirstSegment();
  11582. for (var i = n2 - 2; i >= 0; i--) {
  11583. segGen.addNextSegment(simp2[i], true);
  11584. }
  11585. } else {
  11586. var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);
  11587. var n1 = simp1.length - 1;
  11588. segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);
  11589. segGen.addFirstSegment();
  11590. for (var i$1 = 2; i$1 <= n1; i$1++) {
  11591. segGen.addNextSegment(simp1[i$1], true);
  11592. }
  11593. }
  11594. segGen.addLastSegment();
  11595. };
  11596. OffsetCurveBuilder.prototype.getSegGen = function getSegGen (distance) {
  11597. return new OffsetSegmentGenerator(this._precisionModel, this._bufParams, distance)
  11598. };
  11599. OffsetCurveBuilder.prototype.interfaces_ = function interfaces_ () {
  11600. return []
  11601. };
  11602. OffsetCurveBuilder.prototype.getClass = function getClass () {
  11603. return OffsetCurveBuilder
  11604. };
  11605. OffsetCurveBuilder.copyCoordinates = function copyCoordinates (pts) {
  11606. var copy = new Array(pts.length).fill(null);
  11607. for (var i = 0; i < copy.length; i++) {
  11608. copy[i] = new Coordinate(pts[i]);
  11609. }
  11610. return copy
  11611. };
  11612. var SubgraphDepthLocater = function SubgraphDepthLocater () {
  11613. this._subgraphs = null;
  11614. this._seg = new LineSegment();
  11615. this._cga = new CGAlgorithms();
  11616. var subgraphs = arguments[0];
  11617. this._subgraphs = subgraphs;
  11618. };
  11619. var staticAccessors$30 = { DepthSegment: { configurable: true } };
  11620. SubgraphDepthLocater.prototype.findStabbedSegments = function findStabbedSegments () {
  11621. var this$1 = this;
  11622. if (arguments.length === 1) {
  11623. var stabbingRayLeftPt = arguments[0];
  11624. var stabbedSegments = new ArrayList();
  11625. for (var i = this._subgraphs.iterator(); i.hasNext();) {
  11626. var bsg = i.next();
  11627. var env = bsg.getEnvelope();
  11628. if (stabbingRayLeftPt.y < env.getMinY() || stabbingRayLeftPt.y > env.getMaxY()) { continue }
  11629. this$1.findStabbedSegments(stabbingRayLeftPt, bsg.getDirectedEdges(), stabbedSegments);
  11630. }
  11631. return stabbedSegments
  11632. } else if (arguments.length === 3) {
  11633. if (hasInterface(arguments[2], List) && (arguments[0] instanceof Coordinate && arguments[1] instanceof DirectedEdge)) {
  11634. var stabbingRayLeftPt$1 = arguments[0];
  11635. var dirEdge = arguments[1];
  11636. var stabbedSegments$1 = arguments[2];
  11637. var pts = dirEdge.getEdge().getCoordinates();
  11638. for (var i$1 = 0; i$1 < pts.length - 1; i$1++) {
  11639. this$1._seg.p0 = pts[i$1];
  11640. this$1._seg.p1 = pts[i$1 + 1];
  11641. if (this$1._seg.p0.y > this$1._seg.p1.y) { this$1._seg.reverse(); }
  11642. var maxx = Math.max(this$1._seg.p0.x, this$1._seg.p1.x);
  11643. if (maxx < stabbingRayLeftPt$1.x) { continue }
  11644. if (this$1._seg.isHorizontal()) { continue }
  11645. if (stabbingRayLeftPt$1.y < this$1._seg.p0.y || stabbingRayLeftPt$1.y > this$1._seg.p1.y) { continue }
  11646. if (CGAlgorithms.computeOrientation(this$1._seg.p0, this$1._seg.p1, stabbingRayLeftPt$1) === CGAlgorithms.RIGHT) { continue }
  11647. var depth = dirEdge.getDepth(Position.LEFT);
  11648. if (!this$1._seg.p0.equals(pts[i$1])) { depth = dirEdge.getDepth(Position.RIGHT); }
  11649. var ds = new DepthSegment(this$1._seg, depth);
  11650. stabbedSegments$1.add(ds);
  11651. }
  11652. } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Coordinate && hasInterface(arguments[1], List))) {
  11653. var stabbingRayLeftPt$2 = arguments[0];
  11654. var dirEdges = arguments[1];
  11655. var stabbedSegments$2 = arguments[2];
  11656. for (var i$2 = dirEdges.iterator(); i$2.hasNext();) {
  11657. var de = i$2.next();
  11658. if (!de.isForward()) { continue }
  11659. this$1.findStabbedSegments(stabbingRayLeftPt$2, de, stabbedSegments$2);
  11660. }
  11661. }
  11662. }
  11663. };
  11664. SubgraphDepthLocater.prototype.getDepth = function getDepth (p) {
  11665. var stabbedSegments = this.findStabbedSegments(p);
  11666. if (stabbedSegments.size() === 0) { return 0 }
  11667. var ds = Collections.min(stabbedSegments);
  11668. return ds._leftDepth
  11669. };
  11670. SubgraphDepthLocater.prototype.interfaces_ = function interfaces_ () {
  11671. return []
  11672. };
  11673. SubgraphDepthLocater.prototype.getClass = function getClass () {
  11674. return SubgraphDepthLocater
  11675. };
  11676. staticAccessors$30.DepthSegment.get = function () { return DepthSegment };
  11677. Object.defineProperties( SubgraphDepthLocater, staticAccessors$30 );
  11678. var DepthSegment = function DepthSegment () {
  11679. this._upwardSeg = null;
  11680. this._leftDepth = null;
  11681. var seg = arguments[0];
  11682. var depth = arguments[1];
  11683. this._upwardSeg = new LineSegment(seg);
  11684. this._leftDepth = depth;
  11685. };
  11686. DepthSegment.prototype.compareTo = function compareTo (obj) {
  11687. var other = obj;
  11688. if (this._upwardSeg.minX() >= other._upwardSeg.maxX()) { return 1 }
  11689. if (this._upwardSeg.maxX() <= other._upwardSeg.minX()) { return -1 }
  11690. var orientIndex = this._upwardSeg.orientationIndex(other._upwardSeg);
  11691. if (orientIndex !== 0) { return orientIndex }
  11692. orientIndex = -1 * other._upwardSeg.orientationIndex(this._upwardSeg);
  11693. if (orientIndex !== 0) { return orientIndex }
  11694. return this._upwardSeg.compareTo(other._upwardSeg)
  11695. };
  11696. DepthSegment.prototype.compareX = function compareX (seg0, seg1) {
  11697. var compare0 = seg0.p0.compareTo(seg1.p0);
  11698. if (compare0 !== 0) { return compare0 }
  11699. return seg0.p1.compareTo(seg1.p1)
  11700. };
  11701. DepthSegment.prototype.toString = function toString () {
  11702. return this._upwardSeg.toString()
  11703. };
  11704. DepthSegment.prototype.interfaces_ = function interfaces_ () {
  11705. return [Comparable]
  11706. };
  11707. DepthSegment.prototype.getClass = function getClass () {
  11708. return DepthSegment
  11709. };
  11710. var Triangle = function Triangle (p0, p1, p2) {
  11711. this.p0 = p0 || null;
  11712. this.p1 = p1 || null;
  11713. this.p2 = p2 || null;
  11714. };
  11715. Triangle.prototype.area = function area () {
  11716. return Triangle.area(this.p0, this.p1, this.p2)
  11717. };
  11718. Triangle.prototype.signedArea = function signedArea () {
  11719. return Triangle.signedArea(this.p0, this.p1, this.p2)
  11720. };
  11721. Triangle.prototype.interpolateZ = function interpolateZ (p) {
  11722. if (p === null) { throw new IllegalArgumentException('Supplied point is null.') }
  11723. return Triangle.interpolateZ(p, this.p0, this.p1, this.p2)
  11724. };
  11725. Triangle.prototype.longestSideLength = function longestSideLength () {
  11726. return Triangle.longestSideLength(this.p0, this.p1, this.p2)
  11727. };
  11728. Triangle.prototype.isAcute = function isAcute () {
  11729. return Triangle.isAcute(this.p0, this.p1, this.p2)
  11730. };
  11731. Triangle.prototype.circumcentre = function circumcentre () {
  11732. return Triangle.circumcentre(this.p0, this.p1, this.p2)
  11733. };
  11734. Triangle.prototype.area3D = function area3D () {
  11735. return Triangle.area3D(this.p0, this.p1, this.p2)
  11736. };
  11737. Triangle.prototype.centroid = function centroid () {
  11738. return Triangle.centroid(this.p0, this.p1, this.p2)
  11739. };
  11740. Triangle.prototype.inCentre = function inCentre () {
  11741. return Triangle.inCentre(this.p0, this.p1, this.p2)
  11742. };
  11743. Triangle.prototype.interfaces_ = function interfaces_ () {
  11744. return []
  11745. };
  11746. Triangle.prototype.getClass = function getClass () {
  11747. return Triangle
  11748. };
  11749. Triangle.area = function area (a, b, c) {
  11750. return Math.abs(((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2)
  11751. };
  11752. Triangle.signedArea = function signedArea (a, b, c) {
  11753. return ((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2
  11754. };
  11755. Triangle.det = function det (m00, m01, m10, m11) {
  11756. return m00 * m11 - m01 * m10
  11757. };
  11758. Triangle.interpolateZ = function interpolateZ (p, v0, v1, v2) {
  11759. var x0 = v0.x;
  11760. var y0 = v0.y;
  11761. var a = v1.x - x0;
  11762. var b = v2.x - x0;
  11763. var c = v1.y - y0;
  11764. var d = v2.y - y0;
  11765. var det = a * d - b * c;
  11766. var dx = p.x - x0;
  11767. var dy = p.y - y0;
  11768. var t = (d * dx - b * dy) / det;
  11769. var u = (-c * dx + a * dy) / det;
  11770. var z = v0.z + t * (v1.z - v0.z) + u * (v2.z - v0.z);
  11771. return z
  11772. };
  11773. Triangle.longestSideLength = function longestSideLength (a, b, c) {
  11774. var lenAB = a.distance(b);
  11775. var lenBC = b.distance(c);
  11776. var lenCA = c.distance(a);
  11777. var maxLen = lenAB;
  11778. if (lenBC > maxLen) { maxLen = lenBC; }
  11779. if (lenCA > maxLen) { maxLen = lenCA; }
  11780. return maxLen
  11781. };
  11782. Triangle.isAcute = function isAcute (a, b, c) {
  11783. if (!Angle.isAcute(a, b, c)) { return false }
  11784. if (!Angle.isAcute(b, c, a)) { return false }
  11785. if (!Angle.isAcute(c, a, b)) { return false }
  11786. return true
  11787. };
  11788. Triangle.circumcentre = function circumcentre (a, b, c) {
  11789. var cx = c.x;
  11790. var cy = c.y;
  11791. var ax = a.x - cx;
  11792. var ay = a.y - cy;
  11793. var bx = b.x - cx;
  11794. var by = b.y - cy;
  11795. var denom = 2 * Triangle.det(ax, ay, bx, by);
  11796. var numx = Triangle.det(ay, ax * ax + ay * ay, by, bx * bx + by * by);
  11797. var numy = Triangle.det(ax, ax * ax + ay * ay, bx, bx * bx + by * by);
  11798. var ccx = cx - numx / denom;
  11799. var ccy = cy + numy / denom;
  11800. return new Coordinate(ccx, ccy)
  11801. };
  11802. Triangle.perpendicularBisector = function perpendicularBisector (a, b) {
  11803. var dx = b.x - a.x;
  11804. var dy = b.y - a.y;
  11805. var l1 = new HCoordinate(a.x + dx / 2.0, a.y + dy / 2.0, 1.0);
  11806. var l2 = new HCoordinate(a.x - dy + dx / 2.0, a.y + dx + dy / 2.0, 1.0);
  11807. return new HCoordinate(l1, l2)
  11808. };
  11809. Triangle.angleBisector = function angleBisector (a, b, c) {
  11810. var len0 = b.distance(a);
  11811. var len2 = b.distance(c);
  11812. var frac = len0 / (len0 + len2);
  11813. var dx = c.x - a.x;
  11814. var dy = c.y - a.y;
  11815. var splitPt = new Coordinate(a.x + frac * dx, a.y + frac * dy);
  11816. return splitPt
  11817. };
  11818. Triangle.area3D = function area3D (a, b, c) {
  11819. var ux = b.x - a.x;
  11820. var uy = b.y - a.y;
  11821. var uz = b.z - a.z;
  11822. var vx = c.x - a.x;
  11823. var vy = c.y - a.y;
  11824. var vz = c.z - a.z;
  11825. var crossx = uy * vz - uz * vy;
  11826. var crossy = uz * vx - ux * vz;
  11827. var crossz = ux * vy - uy * vx;
  11828. var absSq = crossx * crossx + crossy * crossy + crossz * crossz;
  11829. var area3D = Math.sqrt(absSq) / 2;
  11830. return area3D
  11831. };
  11832. Triangle.centroid = function centroid (a, b, c) {
  11833. var x = (a.x + b.x + c.x) / 3;
  11834. var y = (a.y + b.y + c.y) / 3;
  11835. return new Coordinate(x, y)
  11836. };
  11837. Triangle.inCentre = function inCentre (a, b, c) {
  11838. var len0 = b.distance(c);
  11839. var len1 = a.distance(c);
  11840. var len2 = a.distance(b);
  11841. var circum = len0 + len1 + len2;
  11842. var inCentreX = (len0 * a.x + len1 * b.x + len2 * c.x) / circum;
  11843. var inCentreY = (len0 * a.y + len1 * b.y + len2 * c.y) / circum;
  11844. return new Coordinate(inCentreX, inCentreY)
  11845. };
  11846. var OffsetCurveSetBuilder = function OffsetCurveSetBuilder () {
  11847. this._inputGeom = null;
  11848. this._distance = null;
  11849. this._curveBuilder = null;
  11850. this._curveList = new ArrayList();
  11851. var inputGeom = arguments[0];
  11852. var distance = arguments[1];
  11853. var curveBuilder = arguments[2];
  11854. this._inputGeom = inputGeom;
  11855. this._distance = distance;
  11856. this._curveBuilder = curveBuilder;
  11857. };
  11858. OffsetCurveSetBuilder.prototype.addPoint = function addPoint (p) {
  11859. if (this._distance <= 0.0) { return null }
  11860. var coord = p.getCoordinates();
  11861. var curve = this._curveBuilder.getLineCurve(coord, this._distance);
  11862. this.addCurve(curve, Location.EXTERIOR, Location.INTERIOR);
  11863. };
  11864. OffsetCurveSetBuilder.prototype.addPolygon = function addPolygon (p) {
  11865. var this$1 = this;
  11866. var offsetDistance = this._distance;
  11867. var offsetSide = Position.LEFT;
  11868. if (this._distance < 0.0) {
  11869. offsetDistance = -this._distance;
  11870. offsetSide = Position.RIGHT;
  11871. }
  11872. var shell = p.getExteriorRing();
  11873. var shellCoord = CoordinateArrays.removeRepeatedPoints(shell.getCoordinates());
  11874. if (this._distance < 0.0 && this.isErodedCompletely(shell, this._distance)) { return null }
  11875. if (this._distance <= 0.0 && shellCoord.length < 3) { return null }
  11876. this.addPolygonRing(shellCoord, offsetDistance, offsetSide, Location.EXTERIOR, Location.INTERIOR);
  11877. for (var i = 0; i < p.getNumInteriorRing(); i++) {
  11878. var hole = p.getInteriorRingN(i);
  11879. var holeCoord = CoordinateArrays.removeRepeatedPoints(hole.getCoordinates());
  11880. if (this$1._distance > 0.0 && this$1.isErodedCompletely(hole, -this$1._distance)) { continue }
  11881. this$1.addPolygonRing(holeCoord, offsetDistance, Position.opposite(offsetSide), Location.INTERIOR, Location.EXTERIOR);
  11882. }
  11883. };
  11884. OffsetCurveSetBuilder.prototype.isTriangleErodedCompletely = function isTriangleErodedCompletely (triangleCoord, bufferDistance) {
  11885. var tri = new Triangle(triangleCoord[0], triangleCoord[1], triangleCoord[2]);
  11886. var inCentre = tri.inCentre();
  11887. var distToCentre = CGAlgorithms.distancePointLine(inCentre, tri.p0, tri.p1);
  11888. return distToCentre < Math.abs(bufferDistance)
  11889. };
  11890. OffsetCurveSetBuilder.prototype.addLineString = function addLineString (line) {
  11891. if (this._distance <= 0.0 && !this._curveBuilder.getBufferParameters().isSingleSided()) { return null }
  11892. var coord = CoordinateArrays.removeRepeatedPoints(line.getCoordinates());
  11893. var curve = this._curveBuilder.getLineCurve(coord, this._distance);
  11894. this.addCurve(curve, Location.EXTERIOR, Location.INTERIOR);
  11895. };
  11896. OffsetCurveSetBuilder.prototype.addCurve = function addCurve (coord, leftLoc, rightLoc) {
  11897. if (coord === null || coord.length < 2) { return null }
  11898. var e = new NodedSegmentString(coord, new Label(0, Location.BOUNDARY, leftLoc, rightLoc));
  11899. this._curveList.add(e);
  11900. };
  11901. OffsetCurveSetBuilder.prototype.getCurves = function getCurves () {
  11902. this.add(this._inputGeom);
  11903. return this._curveList
  11904. };
  11905. OffsetCurveSetBuilder.prototype.addPolygonRing = function addPolygonRing (coord, offsetDistance, side, cwLeftLoc, cwRightLoc) {
  11906. if (offsetDistance === 0.0 && coord.length < LinearRing.MINIMUM_VALID_SIZE) { return null }
  11907. var leftLoc = cwLeftLoc;
  11908. var rightLoc = cwRightLoc;
  11909. if (coord.length >= LinearRing.MINIMUM_VALID_SIZE && CGAlgorithms.isCCW(coord)) {
  11910. leftLoc = cwRightLoc;
  11911. rightLoc = cwLeftLoc;
  11912. side = Position.opposite(side);
  11913. }
  11914. var curve = this._curveBuilder.getRingCurve(coord, side, offsetDistance);
  11915. this.addCurve(curve, leftLoc, rightLoc);
  11916. };
  11917. OffsetCurveSetBuilder.prototype.add = function add (g) {
  11918. if (g.isEmpty()) { return null }
  11919. if (g instanceof Polygon) { this.addPolygon(g); }
  11920. else if (g instanceof LineString) { this.addLineString(g); }
  11921. else if (g instanceof Point) { this.addPoint(g); }
  11922. else if (g instanceof MultiPoint) { this.addCollection(g); }
  11923. else if (g instanceof MultiLineString) { this.addCollection(g); }
  11924. else if (g instanceof MultiPolygon) { this.addCollection(g); }
  11925. else if (g instanceof GeometryCollection) { this.addCollection(g); }
  11926. // else throw new UnsupportedOperationException(g.getClass().getName())
  11927. };
  11928. OffsetCurveSetBuilder.prototype.isErodedCompletely = function isErodedCompletely (ring, bufferDistance) {
  11929. var ringCoord = ring.getCoordinates();
  11930. // const minDiam = 0.0
  11931. if (ringCoord.length < 4) { return bufferDistance < 0 }
  11932. if (ringCoord.length === 4) { return this.isTriangleErodedCompletely(ringCoord, bufferDistance) }
  11933. var env = ring.getEnvelopeInternal();
  11934. var envMinDimension = Math.min(env.getHeight(), env.getWidth());
  11935. if (bufferDistance < 0.0 && 2 * Math.abs(bufferDistance) > envMinDimension) { return true }
  11936. return false
  11937. };
  11938. OffsetCurveSetBuilder.prototype.addCollection = function addCollection (gc) {
  11939. var this$1 = this;
  11940. for (var i = 0; i < gc.getNumGeometries(); i++) {
  11941. var g = gc.getGeometryN(i);
  11942. this$1.add(g);
  11943. }
  11944. };
  11945. OffsetCurveSetBuilder.prototype.interfaces_ = function interfaces_ () {
  11946. return []
  11947. };
  11948. OffsetCurveSetBuilder.prototype.getClass = function getClass () {
  11949. return OffsetCurveSetBuilder
  11950. };
  11951. var PointOnGeometryLocator = function PointOnGeometryLocator () {};
  11952. PointOnGeometryLocator.prototype.locate = function locate (p) {};
  11953. PointOnGeometryLocator.prototype.interfaces_ = function interfaces_ () {
  11954. return []
  11955. };
  11956. PointOnGeometryLocator.prototype.getClass = function getClass () {
  11957. return PointOnGeometryLocator
  11958. };
  11959. var GeometryCollectionIterator = function GeometryCollectionIterator () {
  11960. this._parent = null;
  11961. this._atStart = null;
  11962. this._max = null;
  11963. this._index = null;
  11964. this._subcollectionIterator = null;
  11965. var parent = arguments[0];
  11966. this._parent = parent;
  11967. this._atStart = true;
  11968. this._index = 0;
  11969. this._max = parent.getNumGeometries();
  11970. };
  11971. GeometryCollectionIterator.prototype.next = function next () {
  11972. if (this._atStart) {
  11973. this._atStart = false;
  11974. if (GeometryCollectionIterator.isAtomic(this._parent)) { this._index++; }
  11975. return this._parent
  11976. }
  11977. if (this._subcollectionIterator !== null) {
  11978. if (this._subcollectionIterator.hasNext()) {
  11979. return this._subcollectionIterator.next()
  11980. } else {
  11981. this._subcollectionIterator = null;
  11982. }
  11983. }
  11984. if (this._index >= this._max) {
  11985. throw new NoSuchElementException()
  11986. }
  11987. var obj = this._parent.getGeometryN(this._index++);
  11988. if (obj instanceof GeometryCollection) {
  11989. this._subcollectionIterator = new GeometryCollectionIterator(obj);
  11990. return this._subcollectionIterator.next()
  11991. }
  11992. return obj
  11993. };
  11994. GeometryCollectionIterator.prototype.remove = function remove () {
  11995. throw new Error(this.getClass().getName())
  11996. };
  11997. GeometryCollectionIterator.prototype.hasNext = function hasNext () {
  11998. if (this._atStart) {
  11999. return true
  12000. }
  12001. if (this._subcollectionIterator !== null) {
  12002. if (this._subcollectionIterator.hasNext()) {
  12003. return true
  12004. }
  12005. this._subcollectionIterator = null;
  12006. }
  12007. if (this._index >= this._max) {
  12008. return false
  12009. }
  12010. return true
  12011. };
  12012. GeometryCollectionIterator.prototype.interfaces_ = function interfaces_ () {
  12013. return [Iterator]
  12014. };
  12015. GeometryCollectionIterator.prototype.getClass = function getClass () {
  12016. return GeometryCollectionIterator
  12017. };
  12018. GeometryCollectionIterator.isAtomic = function isAtomic (geom) {
  12019. return !(geom instanceof GeometryCollection)
  12020. };
  12021. var SimplePointInAreaLocator = function SimplePointInAreaLocator () {
  12022. this._geom = null;
  12023. var geom = arguments[0];
  12024. this._geom = geom;
  12025. };
  12026. SimplePointInAreaLocator.prototype.locate = function locate (p) {
  12027. return SimplePointInAreaLocator.locate(p, this._geom)
  12028. };
  12029. SimplePointInAreaLocator.prototype.interfaces_ = function interfaces_ () {
  12030. return [PointOnGeometryLocator]
  12031. };
  12032. SimplePointInAreaLocator.prototype.getClass = function getClass () {
  12033. return SimplePointInAreaLocator
  12034. };
  12035. SimplePointInAreaLocator.isPointInRing = function isPointInRing (p, ring) {
  12036. if (!ring.getEnvelopeInternal().intersects(p)) { return false }
  12037. return CGAlgorithms.isPointInRing(p, ring.getCoordinates())
  12038. };
  12039. SimplePointInAreaLocator.containsPointInPolygon = function containsPointInPolygon (p, poly) {
  12040. if (poly.isEmpty()) { return false }
  12041. var shell = poly.getExteriorRing();
  12042. if (!SimplePointInAreaLocator.isPointInRing(p, shell)) { return false }
  12043. for (var i = 0; i < poly.getNumInteriorRing(); i++) {
  12044. var hole = poly.getInteriorRingN(i);
  12045. if (SimplePointInAreaLocator.isPointInRing(p, hole)) { return false }
  12046. }
  12047. return true
  12048. };
  12049. SimplePointInAreaLocator.containsPoint = function containsPoint (p, geom) {
  12050. if (geom instanceof Polygon) {
  12051. return SimplePointInAreaLocator.containsPointInPolygon(p, geom)
  12052. } else if (geom instanceof GeometryCollection) {
  12053. var geomi = new GeometryCollectionIterator(geom);
  12054. while (geomi.hasNext()) {
  12055. var g2 = geomi.next();
  12056. if (g2 !== geom) { if (SimplePointInAreaLocator.containsPoint(p, g2)) { return true } }
  12057. }
  12058. }
  12059. return false
  12060. };
  12061. SimplePointInAreaLocator.locate = function locate (p, geom) {
  12062. if (geom.isEmpty()) { return Location.EXTERIOR }
  12063. if (SimplePointInAreaLocator.containsPoint(p, geom)) { return Location.INTERIOR }
  12064. return Location.EXTERIOR
  12065. };
  12066. var EdgeEndStar = function EdgeEndStar () {
  12067. this._edgeMap = new TreeMap();
  12068. this._edgeList = null;
  12069. this._ptInAreaLocation = [Location.NONE, Location.NONE];
  12070. };
  12071. EdgeEndStar.prototype.getNextCW = function getNextCW (ee) {
  12072. this.getEdges();
  12073. var i = this._edgeList.indexOf(ee);
  12074. var iNextCW = i - 1;
  12075. if (i === 0) { iNextCW = this._edgeList.size() - 1; }
  12076. return this._edgeList.get(iNextCW)
  12077. };
  12078. EdgeEndStar.prototype.propagateSideLabels = function propagateSideLabels (geomIndex) {
  12079. var startLoc = Location.NONE;
  12080. for (var it = this.iterator(); it.hasNext();) {
  12081. var e = it.next();
  12082. var label = e.getLabel();
  12083. if (label.isArea(geomIndex) && label.getLocation(geomIndex, Position.LEFT) !== Location.NONE) { startLoc = label.getLocation(geomIndex, Position.LEFT); }
  12084. }
  12085. if (startLoc === Location.NONE) { return null }
  12086. var currLoc = startLoc;
  12087. for (var it$1 = this.iterator(); it$1.hasNext();) {
  12088. var e$1 = it$1.next();
  12089. var label$1 = e$1.getLabel();
  12090. if (label$1.getLocation(geomIndex, Position.ON) === Location.NONE) { label$1.setLocation(geomIndex, Position.ON, currLoc); }
  12091. if (label$1.isArea(geomIndex)) {
  12092. var leftLoc = label$1.getLocation(geomIndex, Position.LEFT);
  12093. var rightLoc = label$1.getLocation(geomIndex, Position.RIGHT);
  12094. if (rightLoc !== Location.NONE) {
  12095. if (rightLoc !== currLoc) { throw new TopologyException('side location conflict', e$1.getCoordinate()) }
  12096. if (leftLoc === Location.NONE) {
  12097. Assert.shouldNeverReachHere('found single null side (at ' + e$1.getCoordinate() + ')');
  12098. }
  12099. currLoc = leftLoc;
  12100. } else {
  12101. Assert.isTrue(label$1.getLocation(geomIndex, Position.LEFT) === Location.NONE, 'found single null side');
  12102. label$1.setLocation(geomIndex, Position.RIGHT, currLoc);
  12103. label$1.setLocation(geomIndex, Position.LEFT, currLoc);
  12104. }
  12105. }
  12106. }
  12107. };
  12108. EdgeEndStar.prototype.getCoordinate = function getCoordinate () {
  12109. var it = this.iterator();
  12110. if (!it.hasNext()) { return null }
  12111. var e = it.next();
  12112. return e.getCoordinate()
  12113. };
  12114. EdgeEndStar.prototype.print = function print (out) {
  12115. System.out.println('EdgeEndStar: ' + this.getCoordinate());
  12116. for (var it = this.iterator(); it.hasNext();) {
  12117. var e = it.next();
  12118. e.print(out);
  12119. }
  12120. };
  12121. EdgeEndStar.prototype.isAreaLabelsConsistent = function isAreaLabelsConsistent (geomGraph) {
  12122. this.computeEdgeEndLabels(geomGraph.getBoundaryNodeRule());
  12123. return this.checkAreaLabelsConsistent(0)
  12124. };
  12125. EdgeEndStar.prototype.checkAreaLabelsConsistent = function checkAreaLabelsConsistent (geomIndex) {
  12126. var edges = this.getEdges();
  12127. if (edges.size() <= 0) { return true }
  12128. var lastEdgeIndex = edges.size() - 1;
  12129. var startLabel = edges.get(lastEdgeIndex).getLabel();
  12130. var startLoc = startLabel.getLocation(geomIndex, Position.LEFT);
  12131. Assert.isTrue(startLoc !== Location.NONE, 'Found unlabelled area edge');
  12132. var currLoc = startLoc;
  12133. for (var it = this.iterator(); it.hasNext();) {
  12134. var e = it.next();
  12135. var label = e.getLabel();
  12136. Assert.isTrue(label.isArea(geomIndex), 'Found non-area edge');
  12137. var leftLoc = label.getLocation(geomIndex, Position.LEFT);
  12138. var rightLoc = label.getLocation(geomIndex, Position.RIGHT);
  12139. if (leftLoc === rightLoc) {
  12140. return false
  12141. }
  12142. if (rightLoc !== currLoc) {
  12143. return false
  12144. }
  12145. currLoc = leftLoc;
  12146. }
  12147. return true
  12148. };
  12149. EdgeEndStar.prototype.findIndex = function findIndex (eSearch) {
  12150. var this$1 = this;
  12151. this.iterator();
  12152. for (var i = 0; i < this._edgeList.size(); i++) {
  12153. var e = this$1._edgeList.get(i);
  12154. if (e === eSearch) { return i }
  12155. }
  12156. return -1
  12157. };
  12158. EdgeEndStar.prototype.iterator = function iterator () {
  12159. return this.getEdges().iterator()
  12160. };
  12161. EdgeEndStar.prototype.getEdges = function getEdges () {
  12162. if (this._edgeList === null) {
  12163. this._edgeList = new ArrayList(this._edgeMap.values());
  12164. }
  12165. return this._edgeList
  12166. };
  12167. EdgeEndStar.prototype.getLocation = function getLocation (geomIndex, p, geom) {
  12168. if (this._ptInAreaLocation[geomIndex] === Location.NONE) {
  12169. this._ptInAreaLocation[geomIndex] = SimplePointInAreaLocator.locate(p, geom[geomIndex].getGeometry());
  12170. }
  12171. return this._ptInAreaLocation[geomIndex]
  12172. };
  12173. EdgeEndStar.prototype.toString = function toString () {
  12174. var buf = new StringBuffer();
  12175. buf.append('EdgeEndStar: ' + this.getCoordinate());
  12176. buf.append('\n');
  12177. for (var it = this.iterator(); it.hasNext();) {
  12178. var e = it.next();
  12179. buf.append(e);
  12180. buf.append('\n');
  12181. }
  12182. return buf.toString()
  12183. };
  12184. EdgeEndStar.prototype.computeEdgeEndLabels = function computeEdgeEndLabels (boundaryNodeRule) {
  12185. for (var it = this.iterator(); it.hasNext();) {
  12186. var ee = it.next();
  12187. ee.computeLabel(boundaryNodeRule);
  12188. }
  12189. };
  12190. EdgeEndStar.prototype.computeLabelling = function computeLabelling (geomGraph) {
  12191. var this$1 = this;
  12192. this.computeEdgeEndLabels(geomGraph[0].getBoundaryNodeRule());
  12193. this.propagateSideLabels(0);
  12194. this.propagateSideLabels(1);
  12195. var hasDimensionalCollapseEdge = [false, false];
  12196. for (var it = this.iterator(); it.hasNext();) {
  12197. var e = it.next();
  12198. var label = e.getLabel();
  12199. for (var geomi = 0; geomi < 2; geomi++) {
  12200. if (label.isLine(geomi) && label.getLocation(geomi) === Location.BOUNDARY) { hasDimensionalCollapseEdge[geomi] = true; }
  12201. }
  12202. }
  12203. for (var it$1 = this.iterator(); it$1.hasNext();) {
  12204. var e$1 = it$1.next();
  12205. var label$1 = e$1.getLabel();
  12206. for (var geomi$1 = 0; geomi$1 < 2; geomi$1++) {
  12207. if (label$1.isAnyNull(geomi$1)) {
  12208. var loc = Location.NONE;
  12209. if (hasDimensionalCollapseEdge[geomi$1]) {
  12210. loc = Location.EXTERIOR;
  12211. } else {
  12212. var p = e$1.getCoordinate();
  12213. loc = this$1.getLocation(geomi$1, p, geomGraph);
  12214. }
  12215. label$1.setAllLocationsIfNull(geomi$1, loc);
  12216. }
  12217. }
  12218. }
  12219. };
  12220. EdgeEndStar.prototype.getDegree = function getDegree () {
  12221. return this._edgeMap.size()
  12222. };
  12223. EdgeEndStar.prototype.insertEdgeEnd = function insertEdgeEnd (e, obj) {
  12224. this._edgeMap.put(e, obj);
  12225. this._edgeList = null;
  12226. };
  12227. EdgeEndStar.prototype.interfaces_ = function interfaces_ () {
  12228. return []
  12229. };
  12230. EdgeEndStar.prototype.getClass = function getClass () {
  12231. return EdgeEndStar
  12232. };
  12233. var DirectedEdgeStar = (function (EdgeEndStar$$1) {
  12234. function DirectedEdgeStar () {
  12235. EdgeEndStar$$1.call(this);
  12236. this._resultAreaEdgeList = null;
  12237. this._label = null;
  12238. this._SCANNING_FOR_INCOMING = 1;
  12239. this._LINKING_TO_OUTGOING = 2;
  12240. }
  12241. if ( EdgeEndStar$$1 ) DirectedEdgeStar.__proto__ = EdgeEndStar$$1;
  12242. DirectedEdgeStar.prototype = Object.create( EdgeEndStar$$1 && EdgeEndStar$$1.prototype );
  12243. DirectedEdgeStar.prototype.constructor = DirectedEdgeStar;
  12244. DirectedEdgeStar.prototype.linkResultDirectedEdges = function linkResultDirectedEdges () {
  12245. var this$1 = this;
  12246. this.getResultAreaEdges();
  12247. var firstOut = null;
  12248. var incoming = null;
  12249. var state = this._SCANNING_FOR_INCOMING;
  12250. for (var i = 0; i < this._resultAreaEdgeList.size(); i++) {
  12251. var nextOut = this$1._resultAreaEdgeList.get(i);
  12252. var nextIn = nextOut.getSym();
  12253. if (!nextOut.getLabel().isArea()) { continue }
  12254. if (firstOut === null && nextOut.isInResult()) { firstOut = nextOut; }
  12255. switch (state) {
  12256. case this$1._SCANNING_FOR_INCOMING:
  12257. if (!nextIn.isInResult()) { continue }
  12258. incoming = nextIn;
  12259. state = this$1._LINKING_TO_OUTGOING;
  12260. break
  12261. case this$1._LINKING_TO_OUTGOING:
  12262. if (!nextOut.isInResult()) { continue }
  12263. incoming.setNext(nextOut);
  12264. state = this$1._SCANNING_FOR_INCOMING;
  12265. break
  12266. default:
  12267. }
  12268. }
  12269. if (state === this._LINKING_TO_OUTGOING) {
  12270. if (firstOut === null) { throw new TopologyException('no outgoing dirEdge found', this.getCoordinate()) }
  12271. Assert.isTrue(firstOut.isInResult(), 'unable to link last incoming dirEdge');
  12272. incoming.setNext(firstOut);
  12273. }
  12274. };
  12275. DirectedEdgeStar.prototype.insert = function insert (ee) {
  12276. var de = ee;
  12277. this.insertEdgeEnd(de, de);
  12278. };
  12279. DirectedEdgeStar.prototype.getRightmostEdge = function getRightmostEdge () {
  12280. var edges = this.getEdges();
  12281. var size = edges.size();
  12282. if (size < 1) { return null }
  12283. var de0 = edges.get(0);
  12284. if (size === 1) { return de0 }
  12285. var deLast = edges.get(size - 1);
  12286. var quad0 = de0.getQuadrant();
  12287. var quad1 = deLast.getQuadrant();
  12288. if (Quadrant.isNorthern(quad0) && Quadrant.isNorthern(quad1)) { return de0; } else if (!Quadrant.isNorthern(quad0) && !Quadrant.isNorthern(quad1)) { return deLast; } else {
  12289. // const nonHorizontalEdge = null
  12290. if (de0.getDy() !== 0) { return de0; } else if (deLast.getDy() !== 0) { return deLast }
  12291. }
  12292. Assert.shouldNeverReachHere('found two horizontal edges incident on node');
  12293. return null
  12294. };
  12295. DirectedEdgeStar.prototype.print = function print (out) {
  12296. System.out.println('DirectedEdgeStar: ' + this.getCoordinate());
  12297. for (var it = this.iterator(); it.hasNext();) {
  12298. var de = it.next();
  12299. out.print('out ');
  12300. de.print(out);
  12301. out.println();
  12302. out.print('in ');
  12303. de.getSym().print(out);
  12304. out.println();
  12305. }
  12306. };
  12307. DirectedEdgeStar.prototype.getResultAreaEdges = function getResultAreaEdges () {
  12308. var this$1 = this;
  12309. if (this._resultAreaEdgeList !== null) { return this._resultAreaEdgeList }
  12310. this._resultAreaEdgeList = new ArrayList();
  12311. for (var it = this.iterator(); it.hasNext();) {
  12312. var de = it.next();
  12313. if (de.isInResult() || de.getSym().isInResult()) { this$1._resultAreaEdgeList.add(de); }
  12314. }
  12315. return this._resultAreaEdgeList
  12316. };
  12317. DirectedEdgeStar.prototype.updateLabelling = function updateLabelling (nodeLabel) {
  12318. for (var it = this.iterator(); it.hasNext();) {
  12319. var de = it.next();
  12320. var label = de.getLabel();
  12321. label.setAllLocationsIfNull(0, nodeLabel.getLocation(0));
  12322. label.setAllLocationsIfNull(1, nodeLabel.getLocation(1));
  12323. }
  12324. };
  12325. DirectedEdgeStar.prototype.linkAllDirectedEdges = function linkAllDirectedEdges () {
  12326. var this$1 = this;
  12327. this.getEdges();
  12328. var prevOut = null;
  12329. var firstIn = null;
  12330. for (var i = this._edgeList.size() - 1; i >= 0; i--) {
  12331. var nextOut = this$1._edgeList.get(i);
  12332. var nextIn = nextOut.getSym();
  12333. if (firstIn === null) { firstIn = nextIn; }
  12334. if (prevOut !== null) { nextIn.setNext(prevOut); }
  12335. prevOut = nextOut;
  12336. }
  12337. firstIn.setNext(prevOut);
  12338. };
  12339. DirectedEdgeStar.prototype.computeDepths = function computeDepths () {
  12340. var this$1 = this;
  12341. if (arguments.length === 1) {
  12342. var de = arguments[0];
  12343. var edgeIndex = this.findIndex(de);
  12344. // const label = de.getLabel()
  12345. var startDepth = de.getDepth(Position.LEFT);
  12346. var targetLastDepth = de.getDepth(Position.RIGHT);
  12347. var nextDepth = this.computeDepths(edgeIndex + 1, this._edgeList.size(), startDepth);
  12348. var lastDepth = this.computeDepths(0, edgeIndex, nextDepth);
  12349. if (lastDepth !== targetLastDepth) { throw new TopologyException('depth mismatch at ' + de.getCoordinate()) }
  12350. } else if (arguments.length === 3) {
  12351. var startIndex = arguments[0];
  12352. var endIndex = arguments[1];
  12353. var startDepth$1 = arguments[2];
  12354. var currDepth = startDepth$1;
  12355. for (var i = startIndex; i < endIndex; i++) {
  12356. var nextDe = this$1._edgeList.get(i);
  12357. // const label = nextDe.getLabel()
  12358. nextDe.setEdgeDepths(Position.RIGHT, currDepth);
  12359. currDepth = nextDe.getDepth(Position.LEFT);
  12360. }
  12361. return currDepth
  12362. }
  12363. };
  12364. DirectedEdgeStar.prototype.mergeSymLabels = function mergeSymLabels () {
  12365. for (var it = this.iterator(); it.hasNext();) {
  12366. var de = it.next();
  12367. var label = de.getLabel();
  12368. label.merge(de.getSym().getLabel());
  12369. }
  12370. };
  12371. DirectedEdgeStar.prototype.linkMinimalDirectedEdges = function linkMinimalDirectedEdges (er) {
  12372. var this$1 = this;
  12373. var firstOut = null;
  12374. var incoming = null;
  12375. var state = this._SCANNING_FOR_INCOMING;
  12376. for (var i = this._resultAreaEdgeList.size() - 1; i >= 0; i--) {
  12377. var nextOut = this$1._resultAreaEdgeList.get(i);
  12378. var nextIn = nextOut.getSym();
  12379. if (firstOut === null && nextOut.getEdgeRing() === er) { firstOut = nextOut; }
  12380. switch (state) {
  12381. case this$1._SCANNING_FOR_INCOMING:
  12382. if (nextIn.getEdgeRing() !== er) { continue }
  12383. incoming = nextIn;
  12384. state = this$1._LINKING_TO_OUTGOING;
  12385. break
  12386. case this$1._LINKING_TO_OUTGOING:
  12387. if (nextOut.getEdgeRing() !== er) { continue }
  12388. incoming.setNextMin(nextOut);
  12389. state = this$1._SCANNING_FOR_INCOMING;
  12390. break
  12391. default:
  12392. }
  12393. }
  12394. if (state === this._LINKING_TO_OUTGOING) {
  12395. Assert.isTrue(firstOut !== null, 'found null for first outgoing dirEdge');
  12396. Assert.isTrue(firstOut.getEdgeRing() === er, 'unable to link last incoming dirEdge');
  12397. incoming.setNextMin(firstOut);
  12398. }
  12399. };
  12400. DirectedEdgeStar.prototype.getOutgoingDegree = function getOutgoingDegree () {
  12401. if (arguments.length === 0) {
  12402. var degree = 0;
  12403. for (var it = this.iterator(); it.hasNext();) {
  12404. var de = it.next();
  12405. if (de.isInResult()) { degree++; }
  12406. }
  12407. return degree
  12408. } else if (arguments.length === 1) {
  12409. var er = arguments[0];
  12410. var degree$1 = 0;
  12411. for (var it$1 = this.iterator(); it$1.hasNext();) {
  12412. var de$1 = it$1.next();
  12413. if (de$1.getEdgeRing() === er) { degree$1++; }
  12414. }
  12415. return degree$1
  12416. }
  12417. };
  12418. DirectedEdgeStar.prototype.getLabel = function getLabel () {
  12419. return this._label
  12420. };
  12421. DirectedEdgeStar.prototype.findCoveredLineEdges = function findCoveredLineEdges () {
  12422. var startLoc = Location.NONE;
  12423. for (var it = this.iterator(); it.hasNext();) {
  12424. var nextOut = it.next();
  12425. var nextIn = nextOut.getSym();
  12426. if (!nextOut.isLineEdge()) {
  12427. if (nextOut.isInResult()) {
  12428. startLoc = Location.INTERIOR;
  12429. break
  12430. }
  12431. if (nextIn.isInResult()) {
  12432. startLoc = Location.EXTERIOR;
  12433. break
  12434. }
  12435. }
  12436. }
  12437. if (startLoc === Location.NONE) { return null }
  12438. var currLoc = startLoc;
  12439. for (var it$1 = this.iterator(); it$1.hasNext();) {
  12440. var nextOut$1 = it$1.next();
  12441. var nextIn$1 = nextOut$1.getSym();
  12442. if (nextOut$1.isLineEdge()) {
  12443. nextOut$1.getEdge().setCovered(currLoc === Location.INTERIOR);
  12444. } else {
  12445. if (nextOut$1.isInResult()) { currLoc = Location.EXTERIOR; }
  12446. if (nextIn$1.isInResult()) { currLoc = Location.INTERIOR; }
  12447. }
  12448. }
  12449. };
  12450. DirectedEdgeStar.prototype.computeLabelling = function computeLabelling (geom) {
  12451. var this$1 = this;
  12452. EdgeEndStar$$1.prototype.computeLabelling.call(this, geom);
  12453. this._label = new Label(Location.NONE);
  12454. for (var it = this.iterator(); it.hasNext();) {
  12455. var ee = it.next();
  12456. var e = ee.getEdge();
  12457. var eLabel = e.getLabel();
  12458. for (var i = 0; i < 2; i++) {
  12459. var eLoc = eLabel.getLocation(i);
  12460. if (eLoc === Location.INTERIOR || eLoc === Location.BOUNDARY) { this$1._label.setLocation(i, Location.INTERIOR); }
  12461. }
  12462. }
  12463. };
  12464. DirectedEdgeStar.prototype.interfaces_ = function interfaces_ () {
  12465. return []
  12466. };
  12467. DirectedEdgeStar.prototype.getClass = function getClass () {
  12468. return DirectedEdgeStar
  12469. };
  12470. return DirectedEdgeStar;
  12471. }(EdgeEndStar));
  12472. var OverlayNodeFactory = (function (NodeFactory$$1) {
  12473. function OverlayNodeFactory () {
  12474. NodeFactory$$1.apply(this, arguments);
  12475. }
  12476. if ( NodeFactory$$1 ) OverlayNodeFactory.__proto__ = NodeFactory$$1;
  12477. OverlayNodeFactory.prototype = Object.create( NodeFactory$$1 && NodeFactory$$1.prototype );
  12478. OverlayNodeFactory.prototype.constructor = OverlayNodeFactory;
  12479. OverlayNodeFactory.prototype.createNode = function createNode (coord) {
  12480. return new Node(coord, new DirectedEdgeStar())
  12481. };
  12482. OverlayNodeFactory.prototype.interfaces_ = function interfaces_ () {
  12483. return []
  12484. };
  12485. OverlayNodeFactory.prototype.getClass = function getClass () {
  12486. return OverlayNodeFactory
  12487. };
  12488. return OverlayNodeFactory;
  12489. }(NodeFactory));
  12490. var OrientedCoordinateArray = function OrientedCoordinateArray () {
  12491. this._pts = null;
  12492. this._orientation = null;
  12493. var pts = arguments[0];
  12494. this._pts = pts;
  12495. this._orientation = OrientedCoordinateArray.orientation(pts);
  12496. };
  12497. OrientedCoordinateArray.prototype.compareTo = function compareTo (o1) {
  12498. var oca = o1;
  12499. var comp = OrientedCoordinateArray.compareOriented(this._pts, this._orientation, oca._pts, oca._orientation);
  12500. return comp
  12501. };
  12502. OrientedCoordinateArray.prototype.interfaces_ = function interfaces_ () {
  12503. return [Comparable]
  12504. };
  12505. OrientedCoordinateArray.prototype.getClass = function getClass () {
  12506. return OrientedCoordinateArray
  12507. };
  12508. OrientedCoordinateArray.orientation = function orientation (pts) {
  12509. return CoordinateArrays.increasingDirection(pts) === 1
  12510. };
  12511. OrientedCoordinateArray.compareOriented = function compareOriented (pts1, orientation1, pts2, orientation2) {
  12512. var dir1 = orientation1 ? 1 : -1;
  12513. var dir2 = orientation2 ? 1 : -1;
  12514. var limit1 = orientation1 ? pts1.length : -1;
  12515. var limit2 = orientation2 ? pts2.length : -1;
  12516. var i1 = orientation1 ? 0 : pts1.length - 1;
  12517. var i2 = orientation2 ? 0 : pts2.length - 1;
  12518. // const comp = 0
  12519. while (true) {
  12520. var compPt = pts1[i1].compareTo(pts2[i2]);
  12521. if (compPt !== 0) { return compPt }
  12522. i1 += dir1;
  12523. i2 += dir2;
  12524. var done1 = i1 === limit1;
  12525. var done2 = i2 === limit2;
  12526. if (done1 && !done2) { return -1 }
  12527. if (!done1 && done2) { return 1 }
  12528. if (done1 && done2) { return 0 }
  12529. }
  12530. };
  12531. var EdgeList = function EdgeList () {
  12532. this._edges = new ArrayList();
  12533. this._ocaMap = new TreeMap();
  12534. };
  12535. EdgeList.prototype.print = function print (out) {
  12536. var this$1 = this;
  12537. out.print('MULTILINESTRING ( ');
  12538. for (var j = 0; j < this._edges.size(); j++) {
  12539. var e = this$1._edges.get(j);
  12540. if (j > 0) { out.print(','); }
  12541. out.print('(');
  12542. var pts = e.getCoordinates();
  12543. for (var i = 0; i < pts.length; i++) {
  12544. if (i > 0) { out.print(','); }
  12545. out.print(pts[i].x + ' ' + pts[i].y);
  12546. }
  12547. out.println(')');
  12548. }
  12549. out.print(') ');
  12550. };
  12551. EdgeList.prototype.addAll = function addAll (edgeColl) {
  12552. var this$1 = this;
  12553. for (var i = edgeColl.iterator(); i.hasNext();) {
  12554. this$1.add(i.next());
  12555. }
  12556. };
  12557. EdgeList.prototype.findEdgeIndex = function findEdgeIndex (e) {
  12558. var this$1 = this;
  12559. for (var i = 0; i < this._edges.size(); i++) {
  12560. if (this$1._edges.get(i).equals(e)) { return i }
  12561. }
  12562. return -1
  12563. };
  12564. EdgeList.prototype.iterator = function iterator () {
  12565. return this._edges.iterator()
  12566. };
  12567. EdgeList.prototype.getEdges = function getEdges () {
  12568. return this._edges
  12569. };
  12570. EdgeList.prototype.get = function get (i) {
  12571. return this._edges.get(i)
  12572. };
  12573. EdgeList.prototype.findEqualEdge = function findEqualEdge (e) {
  12574. var oca = new OrientedCoordinateArray(e.getCoordinates());
  12575. var matchEdge = this._ocaMap.get(oca);
  12576. return matchEdge
  12577. };
  12578. EdgeList.prototype.add = function add (e) {
  12579. this._edges.add(e);
  12580. var oca = new OrientedCoordinateArray(e.getCoordinates());
  12581. this._ocaMap.put(oca, e);
  12582. };
  12583. EdgeList.prototype.interfaces_ = function interfaces_ () {
  12584. return []
  12585. };
  12586. EdgeList.prototype.getClass = function getClass () {
  12587. return EdgeList
  12588. };
  12589. var SegmentIntersector = function SegmentIntersector () {};
  12590. SegmentIntersector.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {};
  12591. SegmentIntersector.prototype.isDone = function isDone () {};
  12592. SegmentIntersector.prototype.interfaces_ = function interfaces_ () {
  12593. return []
  12594. };
  12595. SegmentIntersector.prototype.getClass = function getClass () {
  12596. return SegmentIntersector
  12597. };
  12598. var IntersectionAdder = function IntersectionAdder () {
  12599. this._hasIntersection = false;
  12600. this._hasProper = false;
  12601. this._hasProperInterior = false;
  12602. this._hasInterior = false;
  12603. this._properIntersectionPoint = null;
  12604. this._li = null;
  12605. this._isSelfIntersection = null;
  12606. this.numIntersections = 0;
  12607. this.numInteriorIntersections = 0;
  12608. this.numProperIntersections = 0;
  12609. this.numTests = 0;
  12610. var li = arguments[0];
  12611. this._li = li;
  12612. };
  12613. IntersectionAdder.prototype.isTrivialIntersection = function isTrivialIntersection (e0, segIndex0, e1, segIndex1) {
  12614. if (e0 === e1) {
  12615. if (this._li.getIntersectionNum() === 1) {
  12616. if (IntersectionAdder.isAdjacentSegments(segIndex0, segIndex1)) { return true }
  12617. if (e0.isClosed()) {
  12618. var maxSegIndex = e0.size() - 1;
  12619. if ((segIndex0 === 0 && segIndex1 === maxSegIndex) ||
  12620. (segIndex1 === 0 && segIndex0 === maxSegIndex)) {
  12621. return true
  12622. }
  12623. }
  12624. }
  12625. }
  12626. return false
  12627. };
  12628. IntersectionAdder.prototype.getProperIntersectionPoint = function getProperIntersectionPoint () {
  12629. return this._properIntersectionPoint
  12630. };
  12631. IntersectionAdder.prototype.hasProperInteriorIntersection = function hasProperInteriorIntersection () {
  12632. return this._hasProperInterior
  12633. };
  12634. IntersectionAdder.prototype.getLineIntersector = function getLineIntersector () {
  12635. return this._li
  12636. };
  12637. IntersectionAdder.prototype.hasProperIntersection = function hasProperIntersection () {
  12638. return this._hasProper
  12639. };
  12640. IntersectionAdder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {
  12641. if (e0 === e1 && segIndex0 === segIndex1) { return null }
  12642. this.numTests++;
  12643. var p00 = e0.getCoordinates()[segIndex0];
  12644. var p01 = e0.getCoordinates()[segIndex0 + 1];
  12645. var p10 = e1.getCoordinates()[segIndex1];
  12646. var p11 = e1.getCoordinates()[segIndex1 + 1];
  12647. this._li.computeIntersection(p00, p01, p10, p11);
  12648. if (this._li.hasIntersection()) {
  12649. this.numIntersections++;
  12650. if (this._li.isInteriorIntersection()) {
  12651. this.numInteriorIntersections++;
  12652. this._hasInterior = true;
  12653. }
  12654. if (!this.isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {
  12655. this._hasIntersection = true;
  12656. e0.addIntersections(this._li, segIndex0, 0);
  12657. e1.addIntersections(this._li, segIndex1, 1);
  12658. if (this._li.isProper()) {
  12659. this.numProperIntersections++;
  12660. this._hasProper = true;
  12661. this._hasProperInterior = true;
  12662. }
  12663. }
  12664. }
  12665. };
  12666. IntersectionAdder.prototype.hasIntersection = function hasIntersection () {
  12667. return this._hasIntersection
  12668. };
  12669. IntersectionAdder.prototype.isDone = function isDone () {
  12670. return false
  12671. };
  12672. IntersectionAdder.prototype.hasInteriorIntersection = function hasInteriorIntersection () {
  12673. return this._hasInterior
  12674. };
  12675. IntersectionAdder.prototype.interfaces_ = function interfaces_ () {
  12676. return [SegmentIntersector]
  12677. };
  12678. IntersectionAdder.prototype.getClass = function getClass () {
  12679. return IntersectionAdder
  12680. };
  12681. IntersectionAdder.isAdjacentSegments = function isAdjacentSegments (i1, i2) {
  12682. return Math.abs(i1 - i2) === 1
  12683. };
  12684. var EdgeIntersection = function EdgeIntersection () {
  12685. this.coord = null;
  12686. this.segmentIndex = null;
  12687. this.dist = null;
  12688. var coord = arguments[0];
  12689. var segmentIndex = arguments[1];
  12690. var dist = arguments[2];
  12691. this.coord = new Coordinate(coord);
  12692. this.segmentIndex = segmentIndex;
  12693. this.dist = dist;
  12694. };
  12695. EdgeIntersection.prototype.getSegmentIndex = function getSegmentIndex () {
  12696. return this.segmentIndex
  12697. };
  12698. EdgeIntersection.prototype.getCoordinate = function getCoordinate () {
  12699. return this.coord
  12700. };
  12701. EdgeIntersection.prototype.print = function print (out) {
  12702. out.print(this.coord);
  12703. out.print(' seg # = ' + this.segmentIndex);
  12704. out.println(' dist = ' + this.dist);
  12705. };
  12706. EdgeIntersection.prototype.compareTo = function compareTo (obj) {
  12707. var other = obj;
  12708. return this.compare(other.segmentIndex, other.dist)
  12709. };
  12710. EdgeIntersection.prototype.isEndPoint = function isEndPoint (maxSegmentIndex) {
  12711. if (this.segmentIndex === 0 && this.dist === 0.0) { return true }
  12712. if (this.segmentIndex === maxSegmentIndex) { return true }
  12713. return false
  12714. };
  12715. EdgeIntersection.prototype.toString = function toString () {
  12716. return this.coord + ' seg # = ' + this.segmentIndex + ' dist = ' + this.dist
  12717. };
  12718. EdgeIntersection.prototype.getDistance = function getDistance () {
  12719. return this.dist
  12720. };
  12721. EdgeIntersection.prototype.compare = function compare (segmentIndex, dist) {
  12722. if (this.segmentIndex < segmentIndex) { return -1 }
  12723. if (this.segmentIndex > segmentIndex) { return 1 }
  12724. if (this.dist < dist) { return -1 }
  12725. if (this.dist > dist) { return 1 }
  12726. return 0
  12727. };
  12728. EdgeIntersection.prototype.interfaces_ = function interfaces_ () {
  12729. return [Comparable]
  12730. };
  12731. EdgeIntersection.prototype.getClass = function getClass () {
  12732. return EdgeIntersection
  12733. };
  12734. var EdgeIntersectionList = function EdgeIntersectionList () {
  12735. this._nodeMap = new TreeMap();
  12736. this.edge = null;
  12737. var edge = arguments[0];
  12738. this.edge = edge;
  12739. };
  12740. EdgeIntersectionList.prototype.print = function print (out) {
  12741. out.println('Intersections:');
  12742. for (var it = this.iterator(); it.hasNext();) {
  12743. var ei = it.next();
  12744. ei.print(out);
  12745. }
  12746. };
  12747. EdgeIntersectionList.prototype.iterator = function iterator () {
  12748. return this._nodeMap.values().iterator()
  12749. };
  12750. EdgeIntersectionList.prototype.addSplitEdges = function addSplitEdges (edgeList) {
  12751. var this$1 = this;
  12752. this.addEndpoints();
  12753. var it = this.iterator();
  12754. var eiPrev = it.next();
  12755. while (it.hasNext()) {
  12756. var ei = it.next();
  12757. var newEdge = this$1.createSplitEdge(eiPrev, ei);
  12758. edgeList.add(newEdge);
  12759. eiPrev = ei;
  12760. }
  12761. };
  12762. EdgeIntersectionList.prototype.addEndpoints = function addEndpoints () {
  12763. var maxSegIndex = this.edge.pts.length - 1;
  12764. this.add(this.edge.pts[0], 0, 0.0);
  12765. this.add(this.edge.pts[maxSegIndex], maxSegIndex, 0.0);
  12766. };
  12767. EdgeIntersectionList.prototype.createSplitEdge = function createSplitEdge (ei0, ei1) {
  12768. var this$1 = this;
  12769. var npts = ei1.segmentIndex - ei0.segmentIndex + 2;
  12770. var lastSegStartPt = this.edge.pts[ei1.segmentIndex];
  12771. var useIntPt1 = ei1.dist > 0.0 || !ei1.coord.equals2D(lastSegStartPt);
  12772. if (!useIntPt1) {
  12773. npts--;
  12774. }
  12775. var pts = new Array(npts).fill(null);
  12776. var ipt = 0;
  12777. pts[ipt++] = new Coordinate(ei0.coord);
  12778. for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
  12779. pts[ipt++] = this$1.edge.pts[i];
  12780. }
  12781. if (useIntPt1) { pts[ipt] = ei1.coord; }
  12782. return new Edge(pts, new Label(this.edge._label))
  12783. };
  12784. EdgeIntersectionList.prototype.add = function add (intPt, segmentIndex, dist) {
  12785. var eiNew = new EdgeIntersection(intPt, segmentIndex, dist);
  12786. var ei = this._nodeMap.get(eiNew);
  12787. if (ei !== null) {
  12788. return ei
  12789. }
  12790. this._nodeMap.put(eiNew, eiNew);
  12791. return eiNew
  12792. };
  12793. EdgeIntersectionList.prototype.isIntersection = function isIntersection (pt) {
  12794. for (var it = this.iterator(); it.hasNext();) {
  12795. var ei = it.next();
  12796. if (ei.coord.equals(pt)) { return true }
  12797. }
  12798. return false
  12799. };
  12800. EdgeIntersectionList.prototype.interfaces_ = function interfaces_ () {
  12801. return []
  12802. };
  12803. EdgeIntersectionList.prototype.getClass = function getClass () {
  12804. return EdgeIntersectionList
  12805. };
  12806. var MonotoneChainIndexer = function MonotoneChainIndexer () {};
  12807. MonotoneChainIndexer.prototype.getChainStartIndices = function getChainStartIndices (pts) {
  12808. var this$1 = this;
  12809. var start = 0;
  12810. var startIndexList = new ArrayList();
  12811. startIndexList.add(new Integer(start));
  12812. do {
  12813. var last = this$1.findChainEnd(pts, start);
  12814. startIndexList.add(new Integer(last));
  12815. start = last;
  12816. } while (start < pts.length - 1)
  12817. var startIndex = MonotoneChainIndexer.toIntArray(startIndexList);
  12818. return startIndex
  12819. };
  12820. MonotoneChainIndexer.prototype.findChainEnd = function findChainEnd (pts, start) {
  12821. var chainQuad = Quadrant.quadrant(pts[start], pts[start + 1]);
  12822. var last = start + 1;
  12823. while (last < pts.length) {
  12824. var quad = Quadrant.quadrant(pts[last - 1], pts[last]);
  12825. if (quad !== chainQuad) { break }
  12826. last++;
  12827. }
  12828. return last - 1
  12829. };
  12830. MonotoneChainIndexer.prototype.interfaces_ = function interfaces_ () {
  12831. return []
  12832. };
  12833. MonotoneChainIndexer.prototype.getClass = function getClass () {
  12834. return MonotoneChainIndexer
  12835. };
  12836. MonotoneChainIndexer.toIntArray = function toIntArray (list) {
  12837. var array = new Array(list.size()).fill(null);
  12838. for (var i = 0; i < array.length; i++) {
  12839. array[i] = list.get(i).intValue();
  12840. }
  12841. return array
  12842. };
  12843. var MonotoneChainEdge = function MonotoneChainEdge () {
  12844. this.e = null;
  12845. this.pts = null;
  12846. this.startIndex = null;
  12847. this.env1 = new Envelope();
  12848. this.env2 = new Envelope();
  12849. var e = arguments[0];
  12850. this.e = e;
  12851. this.pts = e.getCoordinates();
  12852. var mcb = new MonotoneChainIndexer();
  12853. this.startIndex = mcb.getChainStartIndices(this.pts);
  12854. };
  12855. MonotoneChainEdge.prototype.getCoordinates = function getCoordinates () {
  12856. return this.pts
  12857. };
  12858. MonotoneChainEdge.prototype.getMaxX = function getMaxX (chainIndex) {
  12859. var x1 = this.pts[this.startIndex[chainIndex]].x;
  12860. var x2 = this.pts[this.startIndex[chainIndex + 1]].x;
  12861. return x1 > x2 ? x1 : x2
  12862. };
  12863. MonotoneChainEdge.prototype.getMinX = function getMinX (chainIndex) {
  12864. var x1 = this.pts[this.startIndex[chainIndex]].x;
  12865. var x2 = this.pts[this.startIndex[chainIndex + 1]].x;
  12866. return x1 < x2 ? x1 : x2
  12867. };
  12868. MonotoneChainEdge.prototype.computeIntersectsForChain = function computeIntersectsForChain () {
  12869. if (arguments.length === 4) {
  12870. var chainIndex0 = arguments[0];
  12871. var mce = arguments[1];
  12872. var chainIndex1 = arguments[2];
  12873. var si = arguments[3];
  12874. this.computeIntersectsForChain(this.startIndex[chainIndex0], this.startIndex[chainIndex0 + 1], mce, mce.startIndex[chainIndex1], mce.startIndex[chainIndex1 + 1], si);
  12875. } else if (arguments.length === 6) {
  12876. var start0 = arguments[0];
  12877. var end0 = arguments[1];
  12878. var mce$1 = arguments[2];
  12879. var start1 = arguments[3];
  12880. var end1 = arguments[4];
  12881. var ei = arguments[5];
  12882. var p00 = this.pts[start0];
  12883. var p01 = this.pts[end0];
  12884. var p10 = mce$1.pts[start1];
  12885. var p11 = mce$1.pts[end1];
  12886. if (end0 - start0 === 1 && end1 - start1 === 1) {
  12887. ei.addIntersections(this.e, start0, mce$1.e, start1);
  12888. return null
  12889. }
  12890. this.env1.init(p00, p01);
  12891. this.env2.init(p10, p11);
  12892. if (!this.env1.intersects(this.env2)) { return null }
  12893. var mid0 = Math.trunc((start0 + end0) / 2);
  12894. var mid1 = Math.trunc((start1 + end1) / 2);
  12895. if (start0 < mid0) {
  12896. if (start1 < mid1) { this.computeIntersectsForChain(start0, mid0, mce$1, start1, mid1, ei); }
  12897. if (mid1 < end1) { this.computeIntersectsForChain(start0, mid0, mce$1, mid1, end1, ei); }
  12898. }
  12899. if (mid0 < end0) {
  12900. if (start1 < mid1) { this.computeIntersectsForChain(mid0, end0, mce$1, start1, mid1, ei); }
  12901. if (mid1 < end1) { this.computeIntersectsForChain(mid0, end0, mce$1, mid1, end1, ei); }
  12902. }
  12903. }
  12904. };
  12905. MonotoneChainEdge.prototype.getStartIndexes = function getStartIndexes () {
  12906. return this.startIndex
  12907. };
  12908. MonotoneChainEdge.prototype.computeIntersects = function computeIntersects (mce, si) {
  12909. var this$1 = this;
  12910. for (var i = 0; i < this.startIndex.length - 1; i++) {
  12911. for (var j = 0; j < mce.startIndex.length - 1; j++) {
  12912. this$1.computeIntersectsForChain(i, mce, j, si);
  12913. }
  12914. }
  12915. };
  12916. MonotoneChainEdge.prototype.interfaces_ = function interfaces_ () {
  12917. return []
  12918. };
  12919. MonotoneChainEdge.prototype.getClass = function getClass () {
  12920. return MonotoneChainEdge
  12921. };
  12922. var Depth = function Depth () {
  12923. var this$1 = this;
  12924. this._depth = Array(2).fill().map(function () { return Array(3); });
  12925. for (var i = 0; i < 2; i++) {
  12926. for (var j = 0; j < 3; j++) {
  12927. this$1._depth[i][j] = Depth.NULL_VALUE;
  12928. }
  12929. }
  12930. };
  12931. var staticAccessors$31 = { NULL_VALUE: { configurable: true } };
  12932. Depth.prototype.getDepth = function getDepth (geomIndex, posIndex) {
  12933. return this._depth[geomIndex][posIndex]
  12934. };
  12935. Depth.prototype.setDepth = function setDepth (geomIndex, posIndex, depthValue) {
  12936. this._depth[geomIndex][posIndex] = depthValue;
  12937. };
  12938. Depth.prototype.isNull = function isNull () {
  12939. var this$1 = this;
  12940. if (arguments.length === 0) {
  12941. for (var i = 0; i < 2; i++) {
  12942. for (var j = 0; j < 3; j++) {
  12943. if (this$1._depth[i][j] !== Depth.NULL_VALUE) { return false }
  12944. }
  12945. }
  12946. return true
  12947. } else if (arguments.length === 1) {
  12948. var geomIndex = arguments[0];
  12949. return this._depth[geomIndex][1] === Depth.NULL_VALUE
  12950. } else if (arguments.length === 2) {
  12951. var geomIndex$1 = arguments[0];
  12952. var posIndex = arguments[1];
  12953. return this._depth[geomIndex$1][posIndex] === Depth.NULL_VALUE
  12954. }
  12955. };
  12956. Depth.prototype.normalize = function normalize () {
  12957. var this$1 = this;
  12958. for (var i = 0; i < 2; i++) {
  12959. if (!this$1.isNull(i)) {
  12960. var minDepth = this$1._depth[i][1];
  12961. if (this$1._depth[i][2] < minDepth) { minDepth = this$1._depth[i][2]; }
  12962. if (minDepth < 0) { minDepth = 0; }
  12963. for (var j = 1; j < 3; j++) {
  12964. var newValue = 0;
  12965. if (this$1._depth[i][j] > minDepth) { newValue = 1; }
  12966. this$1._depth[i][j] = newValue;
  12967. }
  12968. }
  12969. }
  12970. };
  12971. Depth.prototype.getDelta = function getDelta (geomIndex) {
  12972. return this._depth[geomIndex][Position.RIGHT] - this._depth[geomIndex][Position.LEFT]
  12973. };
  12974. Depth.prototype.getLocation = function getLocation (geomIndex, posIndex) {
  12975. if (this._depth[geomIndex][posIndex] <= 0) { return Location.EXTERIOR }
  12976. return Location.INTERIOR
  12977. };
  12978. Depth.prototype.toString = function toString () {
  12979. return 'A: ' + this._depth[0][1] + ',' + this._depth[0][2] + ' B: ' + this._depth[1][1] + ',' + this._depth[1][2]
  12980. };
  12981. Depth.prototype.add = function add () {
  12982. var this$1 = this;
  12983. if (arguments.length === 1) {
  12984. var lbl = arguments[0];
  12985. for (var i = 0; i < 2; i++) {
  12986. for (var j = 1; j < 3; j++) {
  12987. var loc = lbl.getLocation(i, j);
  12988. if (loc === Location.EXTERIOR || loc === Location.INTERIOR) {
  12989. if (this$1.isNull(i, j)) {
  12990. this$1._depth[i][j] = Depth.depthAtLocation(loc);
  12991. } else { this$1._depth[i][j] += Depth.depthAtLocation(loc); }
  12992. }
  12993. }
  12994. }
  12995. } else if (arguments.length === 3) {
  12996. var geomIndex = arguments[0];
  12997. var posIndex = arguments[1];
  12998. var location = arguments[2];
  12999. if (location === Location.INTERIOR) { this._depth[geomIndex][posIndex]++; }
  13000. }
  13001. };
  13002. Depth.prototype.interfaces_ = function interfaces_ () {
  13003. return []
  13004. };
  13005. Depth.prototype.getClass = function getClass () {
  13006. return Depth
  13007. };
  13008. Depth.depthAtLocation = function depthAtLocation (location) {
  13009. if (location === Location.EXTERIOR) { return 0 }
  13010. if (location === Location.INTERIOR) { return 1 }
  13011. return Depth.NULL_VALUE
  13012. };
  13013. staticAccessors$31.NULL_VALUE.get = function () { return -1 };
  13014. Object.defineProperties( Depth, staticAccessors$31 );
  13015. var Edge = (function (GraphComponent$$1) {
  13016. function Edge () {
  13017. GraphComponent$$1.call(this);
  13018. this.pts = null;
  13019. this._env = null;
  13020. this.eiList = new EdgeIntersectionList(this);
  13021. this._name = null;
  13022. this._mce = null;
  13023. this._isIsolated = true;
  13024. this._depth = new Depth();
  13025. this._depthDelta = 0;
  13026. if (arguments.length === 1) {
  13027. var pts = arguments[0];
  13028. Edge.call(this, pts, null);
  13029. } else if (arguments.length === 2) {
  13030. var pts$1 = arguments[0];
  13031. var label = arguments[1];
  13032. this.pts = pts$1;
  13033. this._label = label;
  13034. }
  13035. }
  13036. if ( GraphComponent$$1 ) Edge.__proto__ = GraphComponent$$1;
  13037. Edge.prototype = Object.create( GraphComponent$$1 && GraphComponent$$1.prototype );
  13038. Edge.prototype.constructor = Edge;
  13039. Edge.prototype.getDepth = function getDepth () {
  13040. return this._depth
  13041. };
  13042. Edge.prototype.getCollapsedEdge = function getCollapsedEdge () {
  13043. var newPts = new Array(2).fill(null);
  13044. newPts[0] = this.pts[0];
  13045. newPts[1] = this.pts[1];
  13046. var newe = new Edge(newPts, Label.toLineLabel(this._label));
  13047. return newe
  13048. };
  13049. Edge.prototype.isIsolated = function isIsolated () {
  13050. return this._isIsolated
  13051. };
  13052. Edge.prototype.getCoordinates = function getCoordinates () {
  13053. return this.pts
  13054. };
  13055. Edge.prototype.setIsolated = function setIsolated (isIsolated) {
  13056. this._isIsolated = isIsolated;
  13057. };
  13058. Edge.prototype.setName = function setName (name) {
  13059. this._name = name;
  13060. };
  13061. Edge.prototype.equals = function equals (o) {
  13062. var this$1 = this;
  13063. if (!(o instanceof Edge)) { return false }
  13064. var e = o;
  13065. if (this.pts.length !== e.pts.length) { return false }
  13066. var isEqualForward = true;
  13067. var isEqualReverse = true;
  13068. var iRev = this.pts.length;
  13069. for (var i = 0; i < this.pts.length; i++) {
  13070. if (!this$1.pts[i].equals2D(e.pts[i])) {
  13071. isEqualForward = false;
  13072. }
  13073. if (!this$1.pts[i].equals2D(e.pts[--iRev])) {
  13074. isEqualReverse = false;
  13075. }
  13076. if (!isEqualForward && !isEqualReverse) { return false }
  13077. }
  13078. return true
  13079. };
  13080. Edge.prototype.getCoordinate = function getCoordinate () {
  13081. if (arguments.length === 0) {
  13082. if (this.pts.length > 0) { return this.pts[0] }
  13083. return null
  13084. } else if (arguments.length === 1) {
  13085. var i = arguments[0];
  13086. return this.pts[i]
  13087. }
  13088. };
  13089. Edge.prototype.print = function print (out) {
  13090. var this$1 = this;
  13091. out.print('edge ' + this._name + ': ');
  13092. out.print('LINESTRING (');
  13093. for (var i = 0; i < this.pts.length; i++) {
  13094. if (i > 0) { out.print(','); }
  13095. out.print(this$1.pts[i].x + ' ' + this$1.pts[i].y);
  13096. }
  13097. out.print(') ' + this._label + ' ' + this._depthDelta);
  13098. };
  13099. Edge.prototype.computeIM = function computeIM (im) {
  13100. Edge.updateIM(this._label, im);
  13101. };
  13102. Edge.prototype.isCollapsed = function isCollapsed () {
  13103. if (!this._label.isArea()) { return false }
  13104. if (this.pts.length !== 3) { return false }
  13105. if (this.pts[0].equals(this.pts[2])) { return true }
  13106. return false
  13107. };
  13108. Edge.prototype.isClosed = function isClosed () {
  13109. return this.pts[0].equals(this.pts[this.pts.length - 1])
  13110. };
  13111. Edge.prototype.getMaximumSegmentIndex = function getMaximumSegmentIndex () {
  13112. return this.pts.length - 1
  13113. };
  13114. Edge.prototype.getDepthDelta = function getDepthDelta () {
  13115. return this._depthDelta
  13116. };
  13117. Edge.prototype.getNumPoints = function getNumPoints () {
  13118. return this.pts.length
  13119. };
  13120. Edge.prototype.printReverse = function printReverse (out) {
  13121. var this$1 = this;
  13122. out.print('edge ' + this._name + ': ');
  13123. for (var i = this.pts.length - 1; i >= 0; i--) {
  13124. out.print(this$1.pts[i] + ' ');
  13125. }
  13126. out.println('');
  13127. };
  13128. Edge.prototype.getMonotoneChainEdge = function getMonotoneChainEdge () {
  13129. if (this._mce === null) { this._mce = new MonotoneChainEdge(this); }
  13130. return this._mce
  13131. };
  13132. Edge.prototype.getEnvelope = function getEnvelope () {
  13133. var this$1 = this;
  13134. if (this._env === null) {
  13135. this._env = new Envelope();
  13136. for (var i = 0; i < this.pts.length; i++) {
  13137. this$1._env.expandToInclude(this$1.pts[i]);
  13138. }
  13139. }
  13140. return this._env
  13141. };
  13142. Edge.prototype.addIntersection = function addIntersection (li, segmentIndex, geomIndex, intIndex) {
  13143. var intPt = new Coordinate(li.getIntersection(intIndex));
  13144. var normalizedSegmentIndex = segmentIndex;
  13145. var dist = li.getEdgeDistance(geomIndex, intIndex);
  13146. var nextSegIndex = normalizedSegmentIndex + 1;
  13147. if (nextSegIndex < this.pts.length) {
  13148. var nextPt = this.pts[nextSegIndex];
  13149. if (intPt.equals2D(nextPt)) {
  13150. normalizedSegmentIndex = nextSegIndex;
  13151. dist = 0.0;
  13152. }
  13153. }
  13154. this.eiList.add(intPt, normalizedSegmentIndex, dist);
  13155. };
  13156. Edge.prototype.toString = function toString () {
  13157. var this$1 = this;
  13158. var buf = new StringBuffer();
  13159. buf.append('edge ' + this._name + ': ');
  13160. buf.append('LINESTRING (');
  13161. for (var i = 0; i < this.pts.length; i++) {
  13162. if (i > 0) { buf.append(','); }
  13163. buf.append(this$1.pts[i].x + ' ' + this$1.pts[i].y);
  13164. }
  13165. buf.append(') ' + this._label + ' ' + this._depthDelta);
  13166. return buf.toString()
  13167. };
  13168. Edge.prototype.isPointwiseEqual = function isPointwiseEqual (e) {
  13169. var this$1 = this;
  13170. if (this.pts.length !== e.pts.length) { return false }
  13171. for (var i = 0; i < this.pts.length; i++) {
  13172. if (!this$1.pts[i].equals2D(e.pts[i])) {
  13173. return false
  13174. }
  13175. }
  13176. return true
  13177. };
  13178. Edge.prototype.setDepthDelta = function setDepthDelta (depthDelta) {
  13179. this._depthDelta = depthDelta;
  13180. };
  13181. Edge.prototype.getEdgeIntersectionList = function getEdgeIntersectionList () {
  13182. return this.eiList
  13183. };
  13184. Edge.prototype.addIntersections = function addIntersections (li, segmentIndex, geomIndex) {
  13185. var this$1 = this;
  13186. for (var i = 0; i < li.getIntersectionNum(); i++) {
  13187. this$1.addIntersection(li, segmentIndex, geomIndex, i);
  13188. }
  13189. };
  13190. Edge.prototype.interfaces_ = function interfaces_ () {
  13191. return []
  13192. };
  13193. Edge.prototype.getClass = function getClass () {
  13194. return Edge
  13195. };
  13196. Edge.updateIM = function updateIM () {
  13197. if (arguments.length === 2) {
  13198. var label = arguments[0];
  13199. var im = arguments[1];
  13200. im.setAtLeastIfValid(label.getLocation(0, Position.ON), label.getLocation(1, Position.ON), 1);
  13201. if (label.isArea()) {
  13202. im.setAtLeastIfValid(label.getLocation(0, Position.LEFT), label.getLocation(1, Position.LEFT), 2);
  13203. im.setAtLeastIfValid(label.getLocation(0, Position.RIGHT), label.getLocation(1, Position.RIGHT), 2);
  13204. }
  13205. } else { return GraphComponent$$1.prototype.updateIM.apply(this, arguments) }
  13206. };
  13207. return Edge;
  13208. }(GraphComponent));
  13209. var BufferBuilder = function BufferBuilder (bufParams) {
  13210. this._workingPrecisionModel = null;
  13211. this._workingNoder = null;
  13212. this._geomFact = null;
  13213. this._graph = null;
  13214. this._edgeList = new EdgeList();
  13215. this._bufParams = bufParams || null;
  13216. };
  13217. BufferBuilder.prototype.setWorkingPrecisionModel = function setWorkingPrecisionModel (pm) {
  13218. this._workingPrecisionModel = pm;
  13219. };
  13220. BufferBuilder.prototype.insertUniqueEdge = function insertUniqueEdge (e) {
  13221. var existingEdge = this._edgeList.findEqualEdge(e);
  13222. if (existingEdge !== null) {
  13223. var existingLabel = existingEdge.getLabel();
  13224. var labelToMerge = e.getLabel();
  13225. if (!existingEdge.isPointwiseEqual(e)) {
  13226. labelToMerge = new Label(e.getLabel());
  13227. labelToMerge.flip();
  13228. }
  13229. existingLabel.merge(labelToMerge);
  13230. var mergeDelta = BufferBuilder.depthDelta(labelToMerge);
  13231. var existingDelta = existingEdge.getDepthDelta();
  13232. var newDelta = existingDelta + mergeDelta;
  13233. existingEdge.setDepthDelta(newDelta);
  13234. } else {
  13235. this._edgeList.add(e);
  13236. e.setDepthDelta(BufferBuilder.depthDelta(e.getLabel()));
  13237. }
  13238. };
  13239. BufferBuilder.prototype.buildSubgraphs = function buildSubgraphs (subgraphList, polyBuilder) {
  13240. var processedGraphs = new ArrayList();
  13241. for (var i = subgraphList.iterator(); i.hasNext();) {
  13242. var subgraph = i.next();
  13243. var p = subgraph.getRightmostCoordinate();
  13244. var locater = new SubgraphDepthLocater(processedGraphs);
  13245. var outsideDepth = locater.getDepth(p);
  13246. subgraph.computeDepth(outsideDepth);
  13247. subgraph.findResultEdges();
  13248. processedGraphs.add(subgraph);
  13249. polyBuilder.add(subgraph.getDirectedEdges(), subgraph.getNodes());
  13250. }
  13251. };
  13252. BufferBuilder.prototype.createSubgraphs = function createSubgraphs (graph) {
  13253. var subgraphList = new ArrayList();
  13254. for (var i = graph.getNodes().iterator(); i.hasNext();) {
  13255. var node = i.next();
  13256. if (!node.isVisited()) {
  13257. var subgraph = new BufferSubgraph();
  13258. subgraph.create(node);
  13259. subgraphList.add(subgraph);
  13260. }
  13261. }
  13262. Collections.sort(subgraphList, Collections.reverseOrder());
  13263. return subgraphList
  13264. };
  13265. BufferBuilder.prototype.createEmptyResultGeometry = function createEmptyResultGeometry () {
  13266. var emptyGeom = this._geomFact.createPolygon();
  13267. return emptyGeom
  13268. };
  13269. BufferBuilder.prototype.getNoder = function getNoder (precisionModel) {
  13270. if (this._workingNoder !== null) { return this._workingNoder }
  13271. var noder = new MCIndexNoder();
  13272. var li = new RobustLineIntersector();
  13273. li.setPrecisionModel(precisionModel);
  13274. noder.setSegmentIntersector(new IntersectionAdder(li));
  13275. return noder
  13276. };
  13277. BufferBuilder.prototype.buffer = function buffer (g, distance) {
  13278. var precisionModel = this._workingPrecisionModel;
  13279. if (precisionModel === null) { precisionModel = g.getPrecisionModel(); }
  13280. this._geomFact = g.getFactory();
  13281. var curveBuilder = new OffsetCurveBuilder(precisionModel, this._bufParams);
  13282. var curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);
  13283. var bufferSegStrList = curveSetBuilder.getCurves();
  13284. if (bufferSegStrList.size() <= 0) {
  13285. return this.createEmptyResultGeometry()
  13286. }
  13287. this.computeNodedEdges(bufferSegStrList, precisionModel);
  13288. this._graph = new PlanarGraph(new OverlayNodeFactory());
  13289. this._graph.addEdges(this._edgeList.getEdges());
  13290. var subgraphList = this.createSubgraphs(this._graph);
  13291. var polyBuilder = new PolygonBuilder(this._geomFact);
  13292. this.buildSubgraphs(subgraphList, polyBuilder);
  13293. var resultPolyList = polyBuilder.getPolygons();
  13294. if (resultPolyList.size() <= 0) {
  13295. return this.createEmptyResultGeometry()
  13296. }
  13297. var resultGeom = this._geomFact.buildGeometry(resultPolyList);
  13298. return resultGeom
  13299. };
  13300. BufferBuilder.prototype.computeNodedEdges = function computeNodedEdges (bufferSegStrList, precisionModel) {
  13301. var this$1 = this;
  13302. var noder = this.getNoder(precisionModel);
  13303. noder.computeNodes(bufferSegStrList);
  13304. var nodedSegStrings = noder.getNodedSubstrings();
  13305. for (var i = nodedSegStrings.iterator(); i.hasNext();) {
  13306. var segStr = i.next();
  13307. var pts = segStr.getCoordinates();
  13308. if (pts.length === 2 && pts[0].equals2D(pts[1])) { continue }
  13309. var oldLabel = segStr.getData();
  13310. var edge = new Edge(segStr.getCoordinates(), new Label(oldLabel));
  13311. this$1.insertUniqueEdge(edge);
  13312. }
  13313. };
  13314. BufferBuilder.prototype.setNoder = function setNoder (noder) {
  13315. this._workingNoder = noder;
  13316. };
  13317. BufferBuilder.prototype.interfaces_ = function interfaces_ () {
  13318. return []
  13319. };
  13320. BufferBuilder.prototype.getClass = function getClass () {
  13321. return BufferBuilder
  13322. };
  13323. BufferBuilder.depthDelta = function depthDelta (label) {
  13324. var lLoc = label.getLocation(0, Position.LEFT);
  13325. var rLoc = label.getLocation(0, Position.RIGHT);
  13326. if (lLoc === Location.INTERIOR && rLoc === Location.EXTERIOR) { return 1; } else if (lLoc === Location.EXTERIOR && rLoc === Location.INTERIOR) { return -1 }
  13327. return 0
  13328. };
  13329. BufferBuilder.convertSegStrings = function convertSegStrings (it) {
  13330. var fact = new GeometryFactory();
  13331. var lines = new ArrayList();
  13332. while (it.hasNext()) {
  13333. var ss = it.next();
  13334. var line = fact.createLineString(ss.getCoordinates());
  13335. lines.add(line);
  13336. }
  13337. return fact.buildGeometry(lines)
  13338. };
  13339. var ScaledNoder = function ScaledNoder () {
  13340. this._noder = null;
  13341. this._scaleFactor = null;
  13342. this._offsetX = null;
  13343. this._offsetY = null;
  13344. this._isScaled = false;
  13345. if (arguments.length === 2) {
  13346. var noder = arguments[0];
  13347. var scaleFactor = arguments[1];
  13348. this._noder = noder;
  13349. this._scaleFactor = scaleFactor;
  13350. this._offsetX = 0.0;
  13351. this._offsetY = 0.0;
  13352. this._isScaled = !this.isIntegerPrecision();
  13353. } else if (arguments.length === 4) {
  13354. var noder$1 = arguments[0];
  13355. var scaleFactor$1 = arguments[1];
  13356. var offsetX = arguments[2];
  13357. var offsetY = arguments[3];
  13358. this._noder = noder$1;
  13359. this._scaleFactor = scaleFactor$1;
  13360. this._offsetX = offsetX;
  13361. this._offsetY = offsetY;
  13362. this._isScaled = !this.isIntegerPrecision();
  13363. }
  13364. };
  13365. ScaledNoder.prototype.rescale = function rescale () {
  13366. var this$1 = this;
  13367. if (hasInterface(arguments[0], Collection)) {
  13368. var segStrings = arguments[0];
  13369. for (var i = segStrings.iterator(); i.hasNext();) {
  13370. var ss = i.next();
  13371. this$1.rescale(ss.getCoordinates());
  13372. }
  13373. } else if (arguments[0] instanceof Array) {
  13374. var pts = arguments[0];
  13375. // let p0 = null
  13376. // let p1 = null
  13377. // if (pts.length === 2) {
  13378. // p0 = new Coordinate(pts[0])
  13379. // p1 = new Coordinate(pts[1])
  13380. // }
  13381. for (var i$1 = 0; i$1 < pts.length; i$1++) {
  13382. pts[i$1].x = pts[i$1].x / this$1._scaleFactor + this$1._offsetX;
  13383. pts[i$1].y = pts[i$1].y / this$1._scaleFactor + this$1._offsetY;
  13384. }
  13385. if (pts.length === 2 && pts[0].equals2D(pts[1])) {
  13386. System.out.println(pts);
  13387. }
  13388. }
  13389. };
  13390. ScaledNoder.prototype.scale = function scale () {
  13391. var this$1 = this;
  13392. if (hasInterface(arguments[0], Collection)) {
  13393. var segStrings = arguments[0];
  13394. var nodedSegmentStrings = new ArrayList();
  13395. for (var i = segStrings.iterator(); i.hasNext();) {
  13396. var ss = i.next();
  13397. nodedSegmentStrings.add(new NodedSegmentString(this$1.scale(ss.getCoordinates()), ss.getData()));
  13398. }
  13399. return nodedSegmentStrings
  13400. } else if (arguments[0] instanceof Array) {
  13401. var pts = arguments[0];
  13402. var roundPts = new Array(pts.length).fill(null);
  13403. for (var i$1 = 0; i$1 < pts.length; i$1++) {
  13404. roundPts[i$1] = new Coordinate(Math.round((pts[i$1].x - this$1._offsetX) * this$1._scaleFactor), Math.round((pts[i$1].y - this$1._offsetY) * this$1._scaleFactor), pts[i$1].z);
  13405. }
  13406. var roundPtsNoDup = CoordinateArrays.removeRepeatedPoints(roundPts);
  13407. return roundPtsNoDup
  13408. }
  13409. };
  13410. ScaledNoder.prototype.isIntegerPrecision = function isIntegerPrecision () {
  13411. return this._scaleFactor === 1.0
  13412. };
  13413. ScaledNoder.prototype.getNodedSubstrings = function getNodedSubstrings () {
  13414. var splitSS = this._noder.getNodedSubstrings();
  13415. if (this._isScaled) { this.rescale(splitSS); }
  13416. return splitSS
  13417. };
  13418. ScaledNoder.prototype.computeNodes = function computeNodes (inputSegStrings) {
  13419. var intSegStrings = inputSegStrings;
  13420. if (this._isScaled) { intSegStrings = this.scale(inputSegStrings); }
  13421. this._noder.computeNodes(intSegStrings);
  13422. };
  13423. ScaledNoder.prototype.interfaces_ = function interfaces_ () {
  13424. return [Noder]
  13425. };
  13426. ScaledNoder.prototype.getClass = function getClass () {
  13427. return ScaledNoder
  13428. };
  13429. var NodingValidator = function NodingValidator () {
  13430. this._li = new RobustLineIntersector();
  13431. this._segStrings = null;
  13432. var segStrings = arguments[0];
  13433. this._segStrings = segStrings;
  13434. };
  13435. var staticAccessors$33 = { fact: { configurable: true } };
  13436. NodingValidator.prototype.checkEndPtVertexIntersections = function checkEndPtVertexIntersections () {
  13437. var this$1 = this;
  13438. if (arguments.length === 0) {
  13439. for (var i = this._segStrings.iterator(); i.hasNext();) {
  13440. var ss = i.next();
  13441. var pts = ss.getCoordinates();
  13442. this$1.checkEndPtVertexIntersections(pts[0], this$1._segStrings);
  13443. this$1.checkEndPtVertexIntersections(pts[pts.length - 1], this$1._segStrings);
  13444. }
  13445. } else if (arguments.length === 2) {
  13446. var testPt = arguments[0];
  13447. var segStrings = arguments[1];
  13448. for (var i$1 = segStrings.iterator(); i$1.hasNext();) {
  13449. var ss$1 = i$1.next();
  13450. var pts$1 = ss$1.getCoordinates();
  13451. for (var j = 1; j < pts$1.length - 1; j++) {
  13452. if (pts$1[j].equals(testPt)) { throw new RuntimeException('found endpt/interior pt intersection at index ' + j + ' :pt ' + testPt) }
  13453. }
  13454. }
  13455. }
  13456. };
  13457. NodingValidator.prototype.checkInteriorIntersections = function checkInteriorIntersections () {
  13458. var this$1 = this;
  13459. if (arguments.length === 0) {
  13460. for (var i = this._segStrings.iterator(); i.hasNext();) {
  13461. var ss0 = i.next();
  13462. for (var j = this._segStrings.iterator(); j.hasNext();) {
  13463. var ss1 = j.next();
  13464. this$1.checkInteriorIntersections(ss0, ss1);
  13465. }
  13466. }
  13467. } else if (arguments.length === 2) {
  13468. var ss0$1 = arguments[0];
  13469. var ss1$1 = arguments[1];
  13470. var pts0 = ss0$1.getCoordinates();
  13471. var pts1 = ss1$1.getCoordinates();
  13472. for (var i0 = 0; i0 < pts0.length - 1; i0++) {
  13473. for (var i1 = 0; i1 < pts1.length - 1; i1++) {
  13474. this$1.checkInteriorIntersections(ss0$1, i0, ss1$1, i1);
  13475. }
  13476. }
  13477. } else if (arguments.length === 4) {
  13478. var e0 = arguments[0];
  13479. var segIndex0 = arguments[1];
  13480. var e1 = arguments[2];
  13481. var segIndex1 = arguments[3];
  13482. if (e0 === e1 && segIndex0 === segIndex1) { return null }
  13483. var p00 = e0.getCoordinates()[segIndex0];
  13484. var p01 = e0.getCoordinates()[segIndex0 + 1];
  13485. var p10 = e1.getCoordinates()[segIndex1];
  13486. var p11 = e1.getCoordinates()[segIndex1 + 1];
  13487. this._li.computeIntersection(p00, p01, p10, p11);
  13488. if (this._li.hasIntersection()) {
  13489. if (this._li.isProper() || this.hasInteriorIntersection(this._li, p00, p01) || this.hasInteriorIntersection(this._li, p10, p11)) {
  13490. throw new RuntimeException('found non-noded intersection at ' + p00 + '-' + p01 + ' and ' + p10 + '-' + p11)
  13491. }
  13492. }
  13493. }
  13494. };
  13495. NodingValidator.prototype.checkValid = function checkValid () {
  13496. this.checkEndPtVertexIntersections();
  13497. this.checkInteriorIntersections();
  13498. this.checkCollapses();
  13499. };
  13500. NodingValidator.prototype.checkCollapses = function checkCollapses () {
  13501. var this$1 = this;
  13502. if (arguments.length === 0) {
  13503. for (var i = this._segStrings.iterator(); i.hasNext();) {
  13504. var ss = i.next();
  13505. this$1.checkCollapses(ss);
  13506. }
  13507. } else if (arguments.length === 1) {
  13508. var ss$1 = arguments[0];
  13509. var pts = ss$1.getCoordinates();
  13510. for (var i$1 = 0; i$1 < pts.length - 2; i$1++) {
  13511. this$1.checkCollapse(pts[i$1], pts[i$1 + 1], pts[i$1 + 2]);
  13512. }
  13513. }
  13514. };
  13515. NodingValidator.prototype.hasInteriorIntersection = function hasInteriorIntersection (li, p0, p1) {
  13516. for (var i = 0; i < li.getIntersectionNum(); i++) {
  13517. var intPt = li.getIntersection(i);
  13518. if (!(intPt.equals(p0) || intPt.equals(p1))) { return true }
  13519. }
  13520. return false
  13521. };
  13522. NodingValidator.prototype.checkCollapse = function checkCollapse (p0, p1, p2) {
  13523. if (p0.equals(p2)) { throw new RuntimeException('found non-noded collapse at ' + NodingValidator.fact.createLineString([p0, p1, p2])) }
  13524. };
  13525. NodingValidator.prototype.interfaces_ = function interfaces_ () {
  13526. return []
  13527. };
  13528. NodingValidator.prototype.getClass = function getClass () {
  13529. return NodingValidator
  13530. };
  13531. staticAccessors$33.fact.get = function () { return new GeometryFactory() };
  13532. Object.defineProperties( NodingValidator, staticAccessors$33 );
  13533. var HotPixel = function HotPixel () {
  13534. this._li = null;
  13535. this._pt = null;
  13536. this._originalPt = null;
  13537. this._ptScaled = null;
  13538. this._p0Scaled = null;
  13539. this._p1Scaled = null;
  13540. this._scaleFactor = null;
  13541. this._minx = null;
  13542. this._maxx = null;
  13543. this._miny = null;
  13544. this._maxy = null;
  13545. this._corner = new Array(4).fill(null);
  13546. this._safeEnv = null;
  13547. var pt = arguments[0];
  13548. var scaleFactor = arguments[1];
  13549. var li = arguments[2];
  13550. this._originalPt = pt;
  13551. this._pt = pt;
  13552. this._scaleFactor = scaleFactor;
  13553. this._li = li;
  13554. if (scaleFactor <= 0) { throw new IllegalArgumentException('Scale factor must be non-zero') }
  13555. if (scaleFactor !== 1.0) {
  13556. this._pt = new Coordinate(this.scale(pt.x), this.scale(pt.y));
  13557. this._p0Scaled = new Coordinate();
  13558. this._p1Scaled = new Coordinate();
  13559. }
  13560. this.initCorners(this._pt);
  13561. };
  13562. var staticAccessors$34 = { SAFE_ENV_EXPANSION_FACTOR: { configurable: true } };
  13563. HotPixel.prototype.intersectsScaled = function intersectsScaled (p0, p1) {
  13564. var segMinx = Math.min(p0.x, p1.x);
  13565. var segMaxx = Math.max(p0.x, p1.x);
  13566. var segMiny = Math.min(p0.y, p1.y);
  13567. var segMaxy = Math.max(p0.y, p1.y);
  13568. var isOutsidePixelEnv = this._maxx < segMinx || this._minx > segMaxx || this._maxy < segMiny || this._miny > segMaxy;
  13569. if (isOutsidePixelEnv) { return false }
  13570. var intersects = this.intersectsToleranceSquare(p0, p1);
  13571. Assert.isTrue(!(isOutsidePixelEnv && intersects), 'Found bad envelope test');
  13572. return intersects
  13573. };
  13574. HotPixel.prototype.initCorners = function initCorners (pt) {
  13575. var tolerance = 0.5;
  13576. this._minx = pt.x - tolerance;
  13577. this._maxx = pt.x + tolerance;
  13578. this._miny = pt.y - tolerance;
  13579. this._maxy = pt.y + tolerance;
  13580. this._corner[0] = new Coordinate(this._maxx, this._maxy);
  13581. this._corner[1] = new Coordinate(this._minx, this._maxy);
  13582. this._corner[2] = new Coordinate(this._minx, this._miny);
  13583. this._corner[3] = new Coordinate(this._maxx, this._miny);
  13584. };
  13585. HotPixel.prototype.intersects = function intersects (p0, p1) {
  13586. if (this._scaleFactor === 1.0) { return this.intersectsScaled(p0, p1) }
  13587. this.copyScaled(p0, this._p0Scaled);
  13588. this.copyScaled(p1, this._p1Scaled);
  13589. return this.intersectsScaled(this._p0Scaled, this._p1Scaled)
  13590. };
  13591. HotPixel.prototype.scale = function scale (val) {
  13592. return Math.round(val * this._scaleFactor)
  13593. };
  13594. HotPixel.prototype.getCoordinate = function getCoordinate () {
  13595. return this._originalPt
  13596. };
  13597. HotPixel.prototype.copyScaled = function copyScaled (p, pScaled) {
  13598. pScaled.x = this.scale(p.x);
  13599. pScaled.y = this.scale(p.y);
  13600. };
  13601. HotPixel.prototype.getSafeEnvelope = function getSafeEnvelope () {
  13602. if (this._safeEnv === null) {
  13603. var safeTolerance = HotPixel.SAFE_ENV_EXPANSION_FACTOR / this._scaleFactor;
  13604. this._safeEnv = new Envelope(this._originalPt.x - safeTolerance, this._originalPt.x + safeTolerance, this._originalPt.y - safeTolerance, this._originalPt.y + safeTolerance);
  13605. }
  13606. return this._safeEnv
  13607. };
  13608. HotPixel.prototype.intersectsPixelClosure = function intersectsPixelClosure (p0, p1) {
  13609. this._li.computeIntersection(p0, p1, this._corner[0], this._corner[1]);
  13610. if (this._li.hasIntersection()) { return true }
  13611. this._li.computeIntersection(p0, p1, this._corner[1], this._corner[2]);
  13612. if (this._li.hasIntersection()) { return true }
  13613. this._li.computeIntersection(p0, p1, this._corner[2], this._corner[3]);
  13614. if (this._li.hasIntersection()) { return true }
  13615. this._li.computeIntersection(p0, p1, this._corner[3], this._corner[0]);
  13616. if (this._li.hasIntersection()) { return true }
  13617. return false
  13618. };
  13619. HotPixel.prototype.intersectsToleranceSquare = function intersectsToleranceSquare (p0, p1) {
  13620. var intersectsLeft = false;
  13621. var intersectsBottom = false;
  13622. this._li.computeIntersection(p0, p1, this._corner[0], this._corner[1]);
  13623. if (this._li.isProper()) { return true }
  13624. this._li.computeIntersection(p0, p1, this._corner[1], this._corner[2]);
  13625. if (this._li.isProper()) { return true }
  13626. if (this._li.hasIntersection()) { intersectsLeft = true; }
  13627. this._li.computeIntersection(p0, p1, this._corner[2], this._corner[3]);
  13628. if (this._li.isProper()) { return true }
  13629. if (this._li.hasIntersection()) { intersectsBottom = true; }
  13630. this._li.computeIntersection(p0, p1, this._corner[3], this._corner[0]);
  13631. if (this._li.isProper()) { return true }
  13632. if (intersectsLeft && intersectsBottom) { return true }
  13633. if (p0.equals(this._pt)) { return true }
  13634. if (p1.equals(this._pt)) { return true }
  13635. return false
  13636. };
  13637. HotPixel.prototype.addSnappedNode = function addSnappedNode (segStr, segIndex) {
  13638. var p0 = segStr.getCoordinate(segIndex);
  13639. var p1 = segStr.getCoordinate(segIndex + 1);
  13640. if (this.intersects(p0, p1)) {
  13641. segStr.addIntersection(this.getCoordinate(), segIndex);
  13642. return true
  13643. }
  13644. return false
  13645. };
  13646. HotPixel.prototype.interfaces_ = function interfaces_ () {
  13647. return []
  13648. };
  13649. HotPixel.prototype.getClass = function getClass () {
  13650. return HotPixel
  13651. };
  13652. staticAccessors$34.SAFE_ENV_EXPANSION_FACTOR.get = function () { return 0.75 };
  13653. Object.defineProperties( HotPixel, staticAccessors$34 );
  13654. var MonotoneChainSelectAction = function MonotoneChainSelectAction () {
  13655. this.tempEnv1 = new Envelope();
  13656. this.selectedSegment = new LineSegment();
  13657. };
  13658. MonotoneChainSelectAction.prototype.select = function select () {
  13659. if (arguments.length === 1) {
  13660. // const seg = arguments[0]
  13661. } else if (arguments.length === 2) {
  13662. var mc = arguments[0];
  13663. var startIndex = arguments[1];
  13664. mc.getLineSegment(startIndex, this.selectedSegment);
  13665. this.select(this.selectedSegment);
  13666. }
  13667. };
  13668. MonotoneChainSelectAction.prototype.interfaces_ = function interfaces_ () {
  13669. return []
  13670. };
  13671. MonotoneChainSelectAction.prototype.getClass = function getClass () {
  13672. return MonotoneChainSelectAction
  13673. };
  13674. var MCIndexPointSnapper = function MCIndexPointSnapper () {
  13675. this._index = null;
  13676. var index = arguments[0];
  13677. this._index = index;
  13678. };
  13679. var staticAccessors$35 = { HotPixelSnapAction: { configurable: true } };
  13680. MCIndexPointSnapper.prototype.snap = function snap () {
  13681. if (arguments.length === 1) {
  13682. var hotPixel = arguments[0];
  13683. return this.snap(hotPixel, null, -1)
  13684. } else if (arguments.length === 3) {
  13685. var hotPixel$1 = arguments[0];
  13686. var parentEdge = arguments[1];
  13687. var hotPixelVertexIndex = arguments[2];
  13688. var pixelEnv = hotPixel$1.getSafeEnvelope();
  13689. var hotPixelSnapAction = new HotPixelSnapAction(hotPixel$1, parentEdge, hotPixelVertexIndex);
  13690. this._index.query(pixelEnv, {
  13691. interfaces_: function () {
  13692. return [ItemVisitor]
  13693. },
  13694. visitItem: function (item) {
  13695. var testChain = item;
  13696. testChain.select(pixelEnv, hotPixelSnapAction);
  13697. }
  13698. });
  13699. return hotPixelSnapAction.isNodeAdded()
  13700. }
  13701. };
  13702. MCIndexPointSnapper.prototype.interfaces_ = function interfaces_ () {
  13703. return []
  13704. };
  13705. MCIndexPointSnapper.prototype.getClass = function getClass () {
  13706. return MCIndexPointSnapper
  13707. };
  13708. staticAccessors$35.HotPixelSnapAction.get = function () { return HotPixelSnapAction };
  13709. Object.defineProperties( MCIndexPointSnapper, staticAccessors$35 );
  13710. var HotPixelSnapAction = (function (MonotoneChainSelectAction$$1) {
  13711. function HotPixelSnapAction () {
  13712. MonotoneChainSelectAction$$1.call(this);
  13713. this._hotPixel = null;
  13714. this._parentEdge = null;
  13715. this._hotPixelVertexIndex = null;
  13716. this._isNodeAdded = false;
  13717. var hotPixel = arguments[0];
  13718. var parentEdge = arguments[1];
  13719. var hotPixelVertexIndex = arguments[2];
  13720. this._hotPixel = hotPixel;
  13721. this._parentEdge = parentEdge;
  13722. this._hotPixelVertexIndex = hotPixelVertexIndex;
  13723. }
  13724. if ( MonotoneChainSelectAction$$1 ) HotPixelSnapAction.__proto__ = MonotoneChainSelectAction$$1;
  13725. HotPixelSnapAction.prototype = Object.create( MonotoneChainSelectAction$$1 && MonotoneChainSelectAction$$1.prototype );
  13726. HotPixelSnapAction.prototype.constructor = HotPixelSnapAction;
  13727. HotPixelSnapAction.prototype.isNodeAdded = function isNodeAdded () {
  13728. return this._isNodeAdded
  13729. };
  13730. HotPixelSnapAction.prototype.select = function select () {
  13731. if (arguments.length === 2) {
  13732. var mc = arguments[0];
  13733. var startIndex = arguments[1];
  13734. var ss = mc.getContext();
  13735. if (this._parentEdge !== null) {
  13736. if (ss === this._parentEdge && startIndex === this._hotPixelVertexIndex) { return null }
  13737. }
  13738. this._isNodeAdded = this._hotPixel.addSnappedNode(ss, startIndex);
  13739. } else { return MonotoneChainSelectAction$$1.prototype.select.apply(this, arguments) }
  13740. };
  13741. HotPixelSnapAction.prototype.interfaces_ = function interfaces_ () {
  13742. return []
  13743. };
  13744. HotPixelSnapAction.prototype.getClass = function getClass () {
  13745. return HotPixelSnapAction
  13746. };
  13747. return HotPixelSnapAction;
  13748. }(MonotoneChainSelectAction));
  13749. var InteriorIntersectionFinderAdder = function InteriorIntersectionFinderAdder () {
  13750. this._li = null;
  13751. this._interiorIntersections = null;
  13752. var li = arguments[0];
  13753. this._li = li;
  13754. this._interiorIntersections = new ArrayList();
  13755. };
  13756. InteriorIntersectionFinderAdder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {
  13757. var this$1 = this;
  13758. if (e0 === e1 && segIndex0 === segIndex1) { return null }
  13759. var p00 = e0.getCoordinates()[segIndex0];
  13760. var p01 = e0.getCoordinates()[segIndex0 + 1];
  13761. var p10 = e1.getCoordinates()[segIndex1];
  13762. var p11 = e1.getCoordinates()[segIndex1 + 1];
  13763. this._li.computeIntersection(p00, p01, p10, p11);
  13764. if (this._li.hasIntersection()) {
  13765. if (this._li.isInteriorIntersection()) {
  13766. for (var intIndex = 0; intIndex < this._li.getIntersectionNum(); intIndex++) {
  13767. this$1._interiorIntersections.add(this$1._li.getIntersection(intIndex));
  13768. }
  13769. e0.addIntersections(this._li, segIndex0, 0);
  13770. e1.addIntersections(this._li, segIndex1, 1);
  13771. }
  13772. }
  13773. };
  13774. InteriorIntersectionFinderAdder.prototype.isDone = function isDone () {
  13775. return false
  13776. };
  13777. InteriorIntersectionFinderAdder.prototype.getInteriorIntersections = function getInteriorIntersections () {
  13778. return this._interiorIntersections
  13779. };
  13780. InteriorIntersectionFinderAdder.prototype.interfaces_ = function interfaces_ () {
  13781. return [SegmentIntersector]
  13782. };
  13783. InteriorIntersectionFinderAdder.prototype.getClass = function getClass () {
  13784. return InteriorIntersectionFinderAdder
  13785. };
  13786. var MCIndexSnapRounder = function MCIndexSnapRounder () {
  13787. this._pm = null;
  13788. this._li = null;
  13789. this._scaleFactor = null;
  13790. this._noder = null;
  13791. this._pointSnapper = null;
  13792. this._nodedSegStrings = null;
  13793. var pm = arguments[0];
  13794. this._pm = pm;
  13795. this._li = new RobustLineIntersector();
  13796. this._li.setPrecisionModel(pm);
  13797. this._scaleFactor = pm.getScale();
  13798. };
  13799. MCIndexSnapRounder.prototype.checkCorrectness = function checkCorrectness (inputSegmentStrings) {
  13800. var resultSegStrings = NodedSegmentString.getNodedSubstrings(inputSegmentStrings);
  13801. var nv = new NodingValidator(resultSegStrings);
  13802. try {
  13803. nv.checkValid();
  13804. } catch (ex) {
  13805. if (ex instanceof Exception) {
  13806. ex.printStackTrace();
  13807. } else { throw ex }
  13808. } finally {}
  13809. };
  13810. MCIndexSnapRounder.prototype.getNodedSubstrings = function getNodedSubstrings () {
  13811. return NodedSegmentString.getNodedSubstrings(this._nodedSegStrings)
  13812. };
  13813. MCIndexSnapRounder.prototype.snapRound = function snapRound (segStrings, li) {
  13814. var intersections = this.findInteriorIntersections(segStrings, li);
  13815. this.computeIntersectionSnaps(intersections);
  13816. this.computeVertexSnaps(segStrings);
  13817. };
  13818. MCIndexSnapRounder.prototype.findInteriorIntersections = function findInteriorIntersections (segStrings, li) {
  13819. var intFinderAdder = new InteriorIntersectionFinderAdder(li);
  13820. this._noder.setSegmentIntersector(intFinderAdder);
  13821. this._noder.computeNodes(segStrings);
  13822. return intFinderAdder.getInteriorIntersections()
  13823. };
  13824. MCIndexSnapRounder.prototype.computeVertexSnaps = function computeVertexSnaps () {
  13825. var this$1 = this;
  13826. if (hasInterface(arguments[0], Collection)) {
  13827. var edges = arguments[0];
  13828. for (var i0 = edges.iterator(); i0.hasNext();) {
  13829. var edge0 = i0.next();
  13830. this$1.computeVertexSnaps(edge0);
  13831. }
  13832. } else if (arguments[0] instanceof NodedSegmentString) {
  13833. var e = arguments[0];
  13834. var pts0 = e.getCoordinates();
  13835. for (var i = 0; i < pts0.length; i++) {
  13836. var hotPixel = new HotPixel(pts0[i], this$1._scaleFactor, this$1._li);
  13837. var isNodeAdded = this$1._pointSnapper.snap(hotPixel, e, i);
  13838. if (isNodeAdded) {
  13839. e.addIntersection(pts0[i], i);
  13840. }
  13841. }
  13842. }
  13843. };
  13844. MCIndexSnapRounder.prototype.computeNodes = function computeNodes (inputSegmentStrings) {
  13845. this._nodedSegStrings = inputSegmentStrings;
  13846. this._noder = new MCIndexNoder();
  13847. this._pointSnapper = new MCIndexPointSnapper(this._noder.getIndex());
  13848. this.snapRound(inputSegmentStrings, this._li);
  13849. };
  13850. MCIndexSnapRounder.prototype.computeIntersectionSnaps = function computeIntersectionSnaps (snapPts) {
  13851. var this$1 = this;
  13852. for (var it = snapPts.iterator(); it.hasNext();) {
  13853. var snapPt = it.next();
  13854. var hotPixel = new HotPixel(snapPt, this$1._scaleFactor, this$1._li);
  13855. this$1._pointSnapper.snap(hotPixel);
  13856. }
  13857. };
  13858. MCIndexSnapRounder.prototype.interfaces_ = function interfaces_ () {
  13859. return [Noder]
  13860. };
  13861. MCIndexSnapRounder.prototype.getClass = function getClass () {
  13862. return MCIndexSnapRounder
  13863. };
  13864. var BufferOp = function BufferOp () {
  13865. this._argGeom = null;
  13866. this._distance = null;
  13867. this._bufParams = new BufferParameters();
  13868. this._resultGeometry = null;
  13869. this._saveException = null;
  13870. if (arguments.length === 1) {
  13871. var g = arguments[0];
  13872. this._argGeom = g;
  13873. } else if (arguments.length === 2) {
  13874. var g$1 = arguments[0];
  13875. var bufParams = arguments[1];
  13876. this._argGeom = g$1;
  13877. this._bufParams = bufParams;
  13878. }
  13879. };
  13880. var staticAccessors$32 = { CAP_ROUND: { configurable: true },CAP_BUTT: { configurable: true },CAP_FLAT: { configurable: true },CAP_SQUARE: { configurable: true },MAX_PRECISION_DIGITS: { configurable: true } };
  13881. BufferOp.prototype.bufferFixedPrecision = function bufferFixedPrecision (fixedPM) {
  13882. var noder = new ScaledNoder(new MCIndexSnapRounder(new PrecisionModel(1.0)), fixedPM.getScale());
  13883. var bufBuilder = new BufferBuilder(this._bufParams);
  13884. bufBuilder.setWorkingPrecisionModel(fixedPM);
  13885. bufBuilder.setNoder(noder);
  13886. this._resultGeometry = bufBuilder.buffer(this._argGeom, this._distance);
  13887. };
  13888. BufferOp.prototype.bufferReducedPrecision = function bufferReducedPrecision () {
  13889. var this$1 = this;
  13890. if (arguments.length === 0) {
  13891. for (var precDigits = BufferOp.MAX_PRECISION_DIGITS; precDigits >= 0; precDigits--) {
  13892. try {
  13893. this$1.bufferReducedPrecision(precDigits);
  13894. } catch (ex) {
  13895. if (ex instanceof TopologyException) {
  13896. this$1._saveException = ex;
  13897. } else { throw ex }
  13898. } finally {}
  13899. if (this$1._resultGeometry !== null) { return null }
  13900. }
  13901. throw this._saveException
  13902. } else if (arguments.length === 1) {
  13903. var precisionDigits = arguments[0];
  13904. var sizeBasedScaleFactor = BufferOp.precisionScaleFactor(this._argGeom, this._distance, precisionDigits);
  13905. var fixedPM = new PrecisionModel(sizeBasedScaleFactor);
  13906. this.bufferFixedPrecision(fixedPM);
  13907. }
  13908. };
  13909. BufferOp.prototype.computeGeometry = function computeGeometry () {
  13910. this.bufferOriginalPrecision();
  13911. if (this._resultGeometry !== null) { return null }
  13912. var argPM = this._argGeom.getFactory().getPrecisionModel();
  13913. if (argPM.getType() === PrecisionModel.FIXED) { this.bufferFixedPrecision(argPM); } else { this.bufferReducedPrecision(); }
  13914. };
  13915. BufferOp.prototype.setQuadrantSegments = function setQuadrantSegments (quadrantSegments) {
  13916. this._bufParams.setQuadrantSegments(quadrantSegments);
  13917. };
  13918. BufferOp.prototype.bufferOriginalPrecision = function bufferOriginalPrecision () {
  13919. try {
  13920. var bufBuilder = new BufferBuilder(this._bufParams);
  13921. this._resultGeometry = bufBuilder.buffer(this._argGeom, this._distance);
  13922. } catch (ex) {
  13923. if (ex instanceof RuntimeException) {
  13924. this._saveException = ex;
  13925. } else { throw ex }
  13926. } finally {}
  13927. };
  13928. BufferOp.prototype.getResultGeometry = function getResultGeometry (distance) {
  13929. this._distance = distance;
  13930. this.computeGeometry();
  13931. return this._resultGeometry
  13932. };
  13933. BufferOp.prototype.setEndCapStyle = function setEndCapStyle (endCapStyle) {
  13934. this._bufParams.setEndCapStyle(endCapStyle);
  13935. };
  13936. BufferOp.prototype.interfaces_ = function interfaces_ () {
  13937. return []
  13938. };
  13939. BufferOp.prototype.getClass = function getClass () {
  13940. return BufferOp
  13941. };
  13942. BufferOp.bufferOp = function bufferOp () {
  13943. if (arguments.length === 2) {
  13944. var g = arguments[0];
  13945. var distance = arguments[1];
  13946. var gBuf = new BufferOp(g);
  13947. var geomBuf = gBuf.getResultGeometry(distance);
  13948. return geomBuf
  13949. } else if (arguments.length === 3) {
  13950. if (Number.isInteger(arguments[2]) && (arguments[0] instanceof Geometry && typeof arguments[1] === 'number')) {
  13951. var g$1 = arguments[0];
  13952. var distance$1 = arguments[1];
  13953. var quadrantSegments = arguments[2];
  13954. var bufOp = new BufferOp(g$1);
  13955. bufOp.setQuadrantSegments(quadrantSegments);
  13956. var geomBuf$1 = bufOp.getResultGeometry(distance$1);
  13957. return geomBuf$1
  13958. } else if (arguments[2] instanceof BufferParameters && (arguments[0] instanceof Geometry && typeof arguments[1] === 'number')) {
  13959. var g$2 = arguments[0];
  13960. var distance$2 = arguments[1];
  13961. var params = arguments[2];
  13962. var bufOp$1 = new BufferOp(g$2, params);
  13963. var geomBuf$2 = bufOp$1.getResultGeometry(distance$2);
  13964. return geomBuf$2
  13965. }
  13966. } else if (arguments.length === 4) {
  13967. var g$3 = arguments[0];
  13968. var distance$3 = arguments[1];
  13969. var quadrantSegments$1 = arguments[2];
  13970. var endCapStyle = arguments[3];
  13971. var bufOp$2 = new BufferOp(g$3);
  13972. bufOp$2.setQuadrantSegments(quadrantSegments$1);
  13973. bufOp$2.setEndCapStyle(endCapStyle);
  13974. var geomBuf$3 = bufOp$2.getResultGeometry(distance$3);
  13975. return geomBuf$3
  13976. }
  13977. };
  13978. BufferOp.precisionScaleFactor = function precisionScaleFactor (g, distance, maxPrecisionDigits) {
  13979. var env = g.getEnvelopeInternal();
  13980. var envMax = MathUtil.max(Math.abs(env.getMaxX()), Math.abs(env.getMaxY()), Math.abs(env.getMinX()), Math.abs(env.getMinY()));
  13981. var expandByDistance = distance > 0.0 ? distance : 0.0;
  13982. var bufEnvMax = envMax + 2 * expandByDistance;
  13983. var bufEnvPrecisionDigits = Math.trunc(Math.log(bufEnvMax) / Math.log(10) + 1.0);
  13984. var minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;
  13985. var scaleFactor = Math.pow(10.0, minUnitLog10);
  13986. return scaleFactor
  13987. };
  13988. staticAccessors$32.CAP_ROUND.get = function () { return BufferParameters.CAP_ROUND };
  13989. staticAccessors$32.CAP_BUTT.get = function () { return BufferParameters.CAP_FLAT };
  13990. staticAccessors$32.CAP_FLAT.get = function () { return BufferParameters.CAP_FLAT };
  13991. staticAccessors$32.CAP_SQUARE.get = function () { return BufferParameters.CAP_SQUARE };
  13992. staticAccessors$32.MAX_PRECISION_DIGITS.get = function () { return 12 };
  13993. Object.defineProperties( BufferOp, staticAccessors$32 );
  13994. var PointPairDistance = function PointPairDistance () {
  13995. this._pt = [new Coordinate(), new Coordinate()];
  13996. this._distance = Double.NaN;
  13997. this._isNull = true;
  13998. };
  13999. PointPairDistance.prototype.getCoordinates = function getCoordinates () {
  14000. return this._pt
  14001. };
  14002. PointPairDistance.prototype.getCoordinate = function getCoordinate (i) {
  14003. return this._pt[i]
  14004. };
  14005. PointPairDistance.prototype.setMinimum = function setMinimum () {
  14006. if (arguments.length === 1) {
  14007. var ptDist = arguments[0];
  14008. this.setMinimum(ptDist._pt[0], ptDist._pt[1]);
  14009. } else if (arguments.length === 2) {
  14010. var p0 = arguments[0];
  14011. var p1 = arguments[1];
  14012. if (this._isNull) {
  14013. this.initialize(p0, p1);
  14014. return null
  14015. }
  14016. var dist = p0.distance(p1);
  14017. if (dist < this._distance) { this.initialize(p0, p1, dist); }
  14018. }
  14019. };
  14020. PointPairDistance.prototype.initialize = function initialize () {
  14021. if (arguments.length === 0) {
  14022. this._isNull = true;
  14023. } else if (arguments.length === 2) {
  14024. var p0 = arguments[0];
  14025. var p1 = arguments[1];
  14026. this._pt[0].setCoordinate(p0);
  14027. this._pt[1].setCoordinate(p1);
  14028. this._distance = p0.distance(p1);
  14029. this._isNull = false;
  14030. } else if (arguments.length === 3) {
  14031. var p0$1 = arguments[0];
  14032. var p1$1 = arguments[1];
  14033. var distance = arguments[2];
  14034. this._pt[0].setCoordinate(p0$1);
  14035. this._pt[1].setCoordinate(p1$1);
  14036. this._distance = distance;
  14037. this._isNull = false;
  14038. }
  14039. };
  14040. PointPairDistance.prototype.getDistance = function getDistance () {
  14041. return this._distance
  14042. };
  14043. PointPairDistance.prototype.setMaximum = function setMaximum () {
  14044. if (arguments.length === 1) {
  14045. var ptDist = arguments[0];
  14046. this.setMaximum(ptDist._pt[0], ptDist._pt[1]);
  14047. } else if (arguments.length === 2) {
  14048. var p0 = arguments[0];
  14049. var p1 = arguments[1];
  14050. if (this._isNull) {
  14051. this.initialize(p0, p1);
  14052. return null
  14053. }
  14054. var dist = p0.distance(p1);
  14055. if (dist > this._distance) { this.initialize(p0, p1, dist); }
  14056. }
  14057. };
  14058. PointPairDistance.prototype.interfaces_ = function interfaces_ () {
  14059. return []
  14060. };
  14061. PointPairDistance.prototype.getClass = function getClass () {
  14062. return PointPairDistance
  14063. };
  14064. var DistanceToPointFinder = function DistanceToPointFinder () {};
  14065. DistanceToPointFinder.prototype.interfaces_ = function interfaces_ () {
  14066. return []
  14067. };
  14068. DistanceToPointFinder.prototype.getClass = function getClass () {
  14069. return DistanceToPointFinder
  14070. };
  14071. DistanceToPointFinder.computeDistance = function computeDistance () {
  14072. if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof LineString && arguments[1] instanceof Coordinate)) {
  14073. var line = arguments[0];
  14074. var pt = arguments[1];
  14075. var ptDist = arguments[2];
  14076. var coords = line.getCoordinates();
  14077. var tempSegment = new LineSegment();
  14078. for (var i = 0; i < coords.length - 1; i++) {
  14079. tempSegment.setCoordinates(coords[i], coords[i + 1]);
  14080. var closestPt = tempSegment.closestPoint(pt);
  14081. ptDist.setMinimum(closestPt, pt);
  14082. }
  14083. } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof Polygon && arguments[1] instanceof Coordinate)) {
  14084. var poly = arguments[0];
  14085. var pt$1 = arguments[1];
  14086. var ptDist$1 = arguments[2];
  14087. DistanceToPointFinder.computeDistance(poly.getExteriorRing(), pt$1, ptDist$1);
  14088. for (var i$1 = 0; i$1 < poly.getNumInteriorRing(); i$1++) {
  14089. DistanceToPointFinder.computeDistance(poly.getInteriorRingN(i$1), pt$1, ptDist$1);
  14090. }
  14091. } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof Geometry && arguments[1] instanceof Coordinate)) {
  14092. var geom = arguments[0];
  14093. var pt$2 = arguments[1];
  14094. var ptDist$2 = arguments[2];
  14095. if (geom instanceof LineString) {
  14096. DistanceToPointFinder.computeDistance(geom, pt$2, ptDist$2);
  14097. } else if (geom instanceof Polygon) {
  14098. DistanceToPointFinder.computeDistance(geom, pt$2, ptDist$2);
  14099. } else if (geom instanceof GeometryCollection) {
  14100. var gc = geom;
  14101. for (var i$2 = 0; i$2 < gc.getNumGeometries(); i$2++) {
  14102. var g = gc.getGeometryN(i$2);
  14103. DistanceToPointFinder.computeDistance(g, pt$2, ptDist$2);
  14104. }
  14105. } else {
  14106. ptDist$2.setMinimum(geom.getCoordinate(), pt$2);
  14107. }
  14108. } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof LineSegment && arguments[1] instanceof Coordinate)) {
  14109. var segment = arguments[0];
  14110. var pt$3 = arguments[1];
  14111. var ptDist$3 = arguments[2];
  14112. var closestPt$1 = segment.closestPoint(pt$3);
  14113. ptDist$3.setMinimum(closestPt$1, pt$3);
  14114. }
  14115. };
  14116. var BufferCurveMaximumDistanceFinder = function BufferCurveMaximumDistanceFinder (inputGeom) {
  14117. this._maxPtDist = new PointPairDistance();
  14118. this._inputGeom = inputGeom || null;
  14119. };
  14120. var staticAccessors$36 = { MaxPointDistanceFilter: { configurable: true },MaxMidpointDistanceFilter: { configurable: true } };
  14121. BufferCurveMaximumDistanceFinder.prototype.computeMaxMidpointDistance = function computeMaxMidpointDistance (curve) {
  14122. var distFilter = new MaxMidpointDistanceFilter(this._inputGeom);
  14123. curve.apply(distFilter);
  14124. this._maxPtDist.setMaximum(distFilter.getMaxPointDistance());
  14125. };
  14126. BufferCurveMaximumDistanceFinder.prototype.computeMaxVertexDistance = function computeMaxVertexDistance (curve) {
  14127. var distFilter = new MaxPointDistanceFilter(this._inputGeom);
  14128. curve.apply(distFilter);
  14129. this._maxPtDist.setMaximum(distFilter.getMaxPointDistance());
  14130. };
  14131. BufferCurveMaximumDistanceFinder.prototype.findDistance = function findDistance (bufferCurve) {
  14132. this.computeMaxVertexDistance(bufferCurve);
  14133. this.computeMaxMidpointDistance(bufferCurve);
  14134. return this._maxPtDist.getDistance()
  14135. };
  14136. BufferCurveMaximumDistanceFinder.prototype.getDistancePoints = function getDistancePoints () {
  14137. return this._maxPtDist
  14138. };
  14139. BufferCurveMaximumDistanceFinder.prototype.interfaces_ = function interfaces_ () {
  14140. return []
  14141. };
  14142. BufferCurveMaximumDistanceFinder.prototype.getClass = function getClass () {
  14143. return BufferCurveMaximumDistanceFinder
  14144. };
  14145. staticAccessors$36.MaxPointDistanceFilter.get = function () { return MaxPointDistanceFilter };
  14146. staticAccessors$36.MaxMidpointDistanceFilter.get = function () { return MaxMidpointDistanceFilter };
  14147. Object.defineProperties( BufferCurveMaximumDistanceFinder, staticAccessors$36 );
  14148. var MaxPointDistanceFilter = function MaxPointDistanceFilter (geom) {
  14149. this._maxPtDist = new PointPairDistance();
  14150. this._minPtDist = new PointPairDistance();
  14151. this._geom = geom || null;
  14152. };
  14153. MaxPointDistanceFilter.prototype.filter = function filter (pt) {
  14154. this._minPtDist.initialize();
  14155. DistanceToPointFinder.computeDistance(this._geom, pt, this._minPtDist);
  14156. this._maxPtDist.setMaximum(this._minPtDist);
  14157. };
  14158. MaxPointDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {
  14159. return this._maxPtDist
  14160. };
  14161. MaxPointDistanceFilter.prototype.interfaces_ = function interfaces_ () {
  14162. return [CoordinateFilter]
  14163. };
  14164. MaxPointDistanceFilter.prototype.getClass = function getClass () {
  14165. return MaxPointDistanceFilter
  14166. };
  14167. var MaxMidpointDistanceFilter = function MaxMidpointDistanceFilter (geom) {
  14168. this._maxPtDist = new PointPairDistance();
  14169. this._minPtDist = new PointPairDistance();
  14170. this._geom = geom || null;
  14171. };
  14172. MaxMidpointDistanceFilter.prototype.filter = function filter (seq, index) {
  14173. if (index === 0) { return null }
  14174. var p0 = seq.getCoordinate(index - 1);
  14175. var p1 = seq.getCoordinate(index);
  14176. var midPt = new Coordinate((p0.x + p1.x) / 2, (p0.y + p1.y) / 2);
  14177. this._minPtDist.initialize();
  14178. DistanceToPointFinder.computeDistance(this._geom, midPt, this._minPtDist);
  14179. this._maxPtDist.setMaximum(this._minPtDist);
  14180. };
  14181. MaxMidpointDistanceFilter.prototype.isDone = function isDone () {
  14182. return false
  14183. };
  14184. MaxMidpointDistanceFilter.prototype.isGeometryChanged = function isGeometryChanged () {
  14185. return false
  14186. };
  14187. MaxMidpointDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {
  14188. return this._maxPtDist
  14189. };
  14190. MaxMidpointDistanceFilter.prototype.interfaces_ = function interfaces_ () {
  14191. return [CoordinateSequenceFilter]
  14192. };
  14193. MaxMidpointDistanceFilter.prototype.getClass = function getClass () {
  14194. return MaxMidpointDistanceFilter
  14195. };
  14196. var PolygonExtracter = function PolygonExtracter (comps) {
  14197. this._comps = comps || null;
  14198. };
  14199. PolygonExtracter.prototype.filter = function filter (geom) {
  14200. if (geom instanceof Polygon) { this._comps.add(geom); }
  14201. };
  14202. PolygonExtracter.prototype.interfaces_ = function interfaces_ () {
  14203. return [GeometryFilter]
  14204. };
  14205. PolygonExtracter.prototype.getClass = function getClass () {
  14206. return PolygonExtracter
  14207. };
  14208. PolygonExtracter.getPolygons = function getPolygons () {
  14209. if (arguments.length === 1) {
  14210. var geom = arguments[0];
  14211. return PolygonExtracter.getPolygons(geom, new ArrayList())
  14212. } else if (arguments.length === 2) {
  14213. var geom$1 = arguments[0];
  14214. var list = arguments[1];
  14215. if (geom$1 instanceof Polygon) {
  14216. list.add(geom$1);
  14217. } else if (geom$1 instanceof GeometryCollection) {
  14218. geom$1.apply(new PolygonExtracter(list));
  14219. }
  14220. return list
  14221. }
  14222. };
  14223. var LinearComponentExtracter = function LinearComponentExtracter () {
  14224. this._lines = null;
  14225. this._isForcedToLineString = false;
  14226. if (arguments.length === 1) {
  14227. var lines = arguments[0];
  14228. this._lines = lines;
  14229. } else if (arguments.length === 2) {
  14230. var lines$1 = arguments[0];
  14231. var isForcedToLineString = arguments[1];
  14232. this._lines = lines$1;
  14233. this._isForcedToLineString = isForcedToLineString;
  14234. }
  14235. };
  14236. LinearComponentExtracter.prototype.filter = function filter (geom) {
  14237. if (this._isForcedToLineString && geom instanceof LinearRing) {
  14238. var line = geom.getFactory().createLineString(geom.getCoordinateSequence());
  14239. this._lines.add(line);
  14240. return null
  14241. }
  14242. if (geom instanceof LineString) { this._lines.add(geom); }
  14243. };
  14244. LinearComponentExtracter.prototype.setForceToLineString = function setForceToLineString (isForcedToLineString) {
  14245. this._isForcedToLineString = isForcedToLineString;
  14246. };
  14247. LinearComponentExtracter.prototype.interfaces_ = function interfaces_ () {
  14248. return [GeometryComponentFilter]
  14249. };
  14250. LinearComponentExtracter.prototype.getClass = function getClass () {
  14251. return LinearComponentExtracter
  14252. };
  14253. LinearComponentExtracter.getGeometry = function getGeometry () {
  14254. if (arguments.length === 1) {
  14255. var geom = arguments[0];
  14256. return geom.getFactory().buildGeometry(LinearComponentExtracter.getLines(geom))
  14257. } else if (arguments.length === 2) {
  14258. var geom$1 = arguments[0];
  14259. var forceToLineString = arguments[1];
  14260. return geom$1.getFactory().buildGeometry(LinearComponentExtracter.getLines(geom$1, forceToLineString))
  14261. }
  14262. };
  14263. LinearComponentExtracter.getLines = function getLines () {
  14264. if (arguments.length === 1) {
  14265. var geom = arguments[0];
  14266. return LinearComponentExtracter.getLines(geom, false)
  14267. } else if (arguments.length === 2) {
  14268. if (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], Collection)) {
  14269. var geoms = arguments[0];
  14270. var lines$1 = arguments[1];
  14271. for (var i = geoms.iterator(); i.hasNext();) {
  14272. var g = i.next();
  14273. LinearComponentExtracter.getLines(g, lines$1);
  14274. }
  14275. return lines$1
  14276. } else if (arguments[0] instanceof Geometry && typeof arguments[1] === 'boolean') {
  14277. var geom$1 = arguments[0];
  14278. var forceToLineString = arguments[1];
  14279. var lines = new ArrayList();
  14280. geom$1.apply(new LinearComponentExtracter(lines, forceToLineString));
  14281. return lines
  14282. } else if (arguments[0] instanceof Geometry && hasInterface(arguments[1], Collection)) {
  14283. var geom$2 = arguments[0];
  14284. var lines$2 = arguments[1];
  14285. if (geom$2 instanceof LineString) {
  14286. lines$2.add(geom$2);
  14287. } else {
  14288. geom$2.apply(new LinearComponentExtracter(lines$2));
  14289. }
  14290. return lines$2
  14291. }
  14292. } else if (arguments.length === 3) {
  14293. if (typeof arguments[2] === 'boolean' && (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], Collection))) {
  14294. var geoms$1 = arguments[0];
  14295. var lines$3 = arguments[1];
  14296. var forceToLineString$1 = arguments[2];
  14297. for (var i$1 = geoms$1.iterator(); i$1.hasNext();) {
  14298. var g$1 = i$1.next();
  14299. LinearComponentExtracter.getLines(g$1, lines$3, forceToLineString$1);
  14300. }
  14301. return lines$3
  14302. } else if (typeof arguments[2] === 'boolean' && (arguments[0] instanceof Geometry && hasInterface(arguments[1], Collection))) {
  14303. var geom$3 = arguments[0];
  14304. var lines$4 = arguments[1];
  14305. var forceToLineString$2 = arguments[2];
  14306. geom$3.apply(new LinearComponentExtracter(lines$4, forceToLineString$2));
  14307. return lines$4
  14308. }
  14309. }
  14310. };
  14311. var PointLocator = function PointLocator () {
  14312. this._boundaryRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
  14313. this._isIn = null;
  14314. this._numBoundaries = null;
  14315. if (arguments.length === 0) {} else if (arguments.length === 1) {
  14316. var boundaryRule = arguments[0];
  14317. if (boundaryRule === null) { throw new IllegalArgumentException('Rule must be non-null') }
  14318. this._boundaryRule = boundaryRule;
  14319. }
  14320. };
  14321. PointLocator.prototype.locateInternal = function locateInternal () {
  14322. var this$1 = this;
  14323. if (arguments[0] instanceof Coordinate && arguments[1] instanceof Polygon) {
  14324. var p = arguments[0];
  14325. var poly = arguments[1];
  14326. if (poly.isEmpty()) { return Location.EXTERIOR }
  14327. var shell = poly.getExteriorRing();
  14328. var shellLoc = this.locateInPolygonRing(p, shell);
  14329. if (shellLoc === Location.EXTERIOR) { return Location.EXTERIOR }
  14330. if (shellLoc === Location.BOUNDARY) { return Location.BOUNDARY }
  14331. for (var i = 0; i < poly.getNumInteriorRing(); i++) {
  14332. var hole = poly.getInteriorRingN(i);
  14333. var holeLoc = this$1.locateInPolygonRing(p, hole);
  14334. if (holeLoc === Location.INTERIOR) { return Location.EXTERIOR }
  14335. if (holeLoc === Location.BOUNDARY) { return Location.BOUNDARY }
  14336. }
  14337. return Location.INTERIOR
  14338. } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof LineString) {
  14339. var p$1 = arguments[0];
  14340. var l = arguments[1];
  14341. if (!l.getEnvelopeInternal().intersects(p$1)) { return Location.EXTERIOR }
  14342. var pt = l.getCoordinates();
  14343. if (!l.isClosed()) {
  14344. if (p$1.equals(pt[0]) || p$1.equals(pt[pt.length - 1])) {
  14345. return Location.BOUNDARY
  14346. }
  14347. }
  14348. if (CGAlgorithms.isOnLine(p$1, pt)) { return Location.INTERIOR }
  14349. return Location.EXTERIOR
  14350. } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Point) {
  14351. var p$2 = arguments[0];
  14352. var pt$1 = arguments[1];
  14353. var ptCoord = pt$1.getCoordinate();
  14354. if (ptCoord.equals2D(p$2)) { return Location.INTERIOR }
  14355. return Location.EXTERIOR
  14356. }
  14357. };
  14358. PointLocator.prototype.locateInPolygonRing = function locateInPolygonRing (p, ring) {
  14359. if (!ring.getEnvelopeInternal().intersects(p)) { return Location.EXTERIOR }
  14360. return CGAlgorithms.locatePointInRing(p, ring.getCoordinates())
  14361. };
  14362. PointLocator.prototype.intersects = function intersects (p, geom) {
  14363. return this.locate(p, geom) !== Location.EXTERIOR
  14364. };
  14365. PointLocator.prototype.updateLocationInfo = function updateLocationInfo (loc) {
  14366. if (loc === Location.INTERIOR) { this._isIn = true; }
  14367. if (loc === Location.BOUNDARY) { this._numBoundaries++; }
  14368. };
  14369. PointLocator.prototype.computeLocation = function computeLocation (p, geom) {
  14370. var this$1 = this;
  14371. if (geom instanceof Point) {
  14372. this.updateLocationInfo(this.locateInternal(p, geom));
  14373. }
  14374. if (geom instanceof LineString) {
  14375. this.updateLocationInfo(this.locateInternal(p, geom));
  14376. } else if (geom instanceof Polygon) {
  14377. this.updateLocationInfo(this.locateInternal(p, geom));
  14378. } else if (geom instanceof MultiLineString) {
  14379. var ml = geom;
  14380. for (var i = 0; i < ml.getNumGeometries(); i++) {
  14381. var l = ml.getGeometryN(i);
  14382. this$1.updateLocationInfo(this$1.locateInternal(p, l));
  14383. }
  14384. } else if (geom instanceof MultiPolygon) {
  14385. var mpoly = geom;
  14386. for (var i$1 = 0; i$1 < mpoly.getNumGeometries(); i$1++) {
  14387. var poly = mpoly.getGeometryN(i$1);
  14388. this$1.updateLocationInfo(this$1.locateInternal(p, poly));
  14389. }
  14390. } else if (geom instanceof GeometryCollection) {
  14391. var geomi = new GeometryCollectionIterator(geom);
  14392. while (geomi.hasNext()) {
  14393. var g2 = geomi.next();
  14394. if (g2 !== geom) { this$1.computeLocation(p, g2); }
  14395. }
  14396. }
  14397. };
  14398. PointLocator.prototype.locate = function locate (p, geom) {
  14399. if (geom.isEmpty()) { return Location.EXTERIOR }
  14400. if (geom instanceof LineString) {
  14401. return this.locateInternal(p, geom)
  14402. } else if (geom instanceof Polygon) {
  14403. return this.locateInternal(p, geom)
  14404. }
  14405. this._isIn = false;
  14406. this._numBoundaries = 0;
  14407. this.computeLocation(p, geom);
  14408. if (this._boundaryRule.isInBoundary(this._numBoundaries)) { return Location.BOUNDARY }
  14409. if (this._numBoundaries > 0 || this._isIn) { return Location.INTERIOR }
  14410. return Location.EXTERIOR
  14411. };
  14412. PointLocator.prototype.interfaces_ = function interfaces_ () {
  14413. return []
  14414. };
  14415. PointLocator.prototype.getClass = function getClass () {
  14416. return PointLocator
  14417. };
  14418. var GeometryLocation = function GeometryLocation () {
  14419. this._component = null;
  14420. this._segIndex = null;
  14421. this._pt = null;
  14422. if (arguments.length === 2) {
  14423. var component = arguments[0];
  14424. var pt = arguments[1];
  14425. GeometryLocation.call(this, component, GeometryLocation.INSIDE_AREA, pt);
  14426. } else if (arguments.length === 3) {
  14427. var component$1 = arguments[0];
  14428. var segIndex = arguments[1];
  14429. var pt$1 = arguments[2];
  14430. this._component = component$1;
  14431. this._segIndex = segIndex;
  14432. this._pt = pt$1;
  14433. }
  14434. };
  14435. var staticAccessors$38 = { INSIDE_AREA: { configurable: true } };
  14436. GeometryLocation.prototype.isInsideArea = function isInsideArea () {
  14437. return this._segIndex === GeometryLocation.INSIDE_AREA
  14438. };
  14439. GeometryLocation.prototype.getCoordinate = function getCoordinate () {
  14440. return this._pt
  14441. };
  14442. GeometryLocation.prototype.getGeometryComponent = function getGeometryComponent () {
  14443. return this._component
  14444. };
  14445. GeometryLocation.prototype.getSegmentIndex = function getSegmentIndex () {
  14446. return this._segIndex
  14447. };
  14448. GeometryLocation.prototype.interfaces_ = function interfaces_ () {
  14449. return []
  14450. };
  14451. GeometryLocation.prototype.getClass = function getClass () {
  14452. return GeometryLocation
  14453. };
  14454. staticAccessors$38.INSIDE_AREA.get = function () { return -1 };
  14455. Object.defineProperties( GeometryLocation, staticAccessors$38 );
  14456. var PointExtracter = function PointExtracter (pts) {
  14457. this._pts = pts || null;
  14458. };
  14459. PointExtracter.prototype.filter = function filter (geom) {
  14460. if (geom instanceof Point) { this._pts.add(geom); }
  14461. };
  14462. PointExtracter.prototype.interfaces_ = function interfaces_ () {
  14463. return [GeometryFilter]
  14464. };
  14465. PointExtracter.prototype.getClass = function getClass () {
  14466. return PointExtracter
  14467. };
  14468. PointExtracter.getPoints = function getPoints () {
  14469. if (arguments.length === 1) {
  14470. var geom = arguments[0];
  14471. if (geom instanceof Point) {
  14472. return Collections.singletonList(geom)
  14473. }
  14474. return PointExtracter.getPoints(geom, new ArrayList())
  14475. } else if (arguments.length === 2) {
  14476. var geom$1 = arguments[0];
  14477. var list = arguments[1];
  14478. if (geom$1 instanceof Point) {
  14479. list.add(geom$1);
  14480. } else if (geom$1 instanceof GeometryCollection) {
  14481. geom$1.apply(new PointExtracter(list));
  14482. }
  14483. return list
  14484. }
  14485. };
  14486. var ConnectedElementLocationFilter = function ConnectedElementLocationFilter () {
  14487. this._locations = null;
  14488. var locations = arguments[0];
  14489. this._locations = locations;
  14490. };
  14491. ConnectedElementLocationFilter.prototype.filter = function filter (geom) {
  14492. if (geom instanceof Point || geom instanceof LineString || geom instanceof Polygon) { this._locations.add(new GeometryLocation(geom, 0, geom.getCoordinate())); }
  14493. };
  14494. ConnectedElementLocationFilter.prototype.interfaces_ = function interfaces_ () {
  14495. return [GeometryFilter]
  14496. };
  14497. ConnectedElementLocationFilter.prototype.getClass = function getClass () {
  14498. return ConnectedElementLocationFilter
  14499. };
  14500. ConnectedElementLocationFilter.getLocations = function getLocations (geom) {
  14501. var locations = new ArrayList();
  14502. geom.apply(new ConnectedElementLocationFilter(locations));
  14503. return locations
  14504. };
  14505. var DistanceOp = function DistanceOp () {
  14506. this._geom = null;
  14507. this._terminateDistance = 0.0;
  14508. this._ptLocator = new PointLocator();
  14509. this._minDistanceLocation = null;
  14510. this._minDistance = Double.MAX_VALUE;
  14511. if (arguments.length === 2) {
  14512. var g0 = arguments[0];
  14513. var g1 = arguments[1];
  14514. this._geom = [g0, g1];
  14515. this._terminateDistance = 0.0;
  14516. } else if (arguments.length === 3) {
  14517. var g0$1 = arguments[0];
  14518. var g1$1 = arguments[1];
  14519. var terminateDistance = arguments[2];
  14520. this._geom = new Array(2).fill(null);
  14521. this._geom[0] = g0$1;
  14522. this._geom[1] = g1$1;
  14523. this._terminateDistance = terminateDistance;
  14524. }
  14525. };
  14526. DistanceOp.prototype.computeContainmentDistance = function computeContainmentDistance () {
  14527. var this$1 = this;
  14528. if (arguments.length === 0) {
  14529. var locPtPoly = new Array(2).fill(null);
  14530. this.computeContainmentDistance(0, locPtPoly);
  14531. if (this._minDistance <= this._terminateDistance) { return null }
  14532. this.computeContainmentDistance(1, locPtPoly);
  14533. } else if (arguments.length === 2) {
  14534. var polyGeomIndex = arguments[0];
  14535. var locPtPoly$1 = arguments[1];
  14536. var locationsIndex = 1 - polyGeomIndex;
  14537. var polys = PolygonExtracter.getPolygons(this._geom[polyGeomIndex]);
  14538. if (polys.size() > 0) {
  14539. var insideLocs = ConnectedElementLocationFilter.getLocations(this._geom[locationsIndex]);
  14540. this.computeContainmentDistance(insideLocs, polys, locPtPoly$1);
  14541. if (this._minDistance <= this._terminateDistance) {
  14542. this._minDistanceLocation[locationsIndex] = locPtPoly$1[0];
  14543. this._minDistanceLocation[polyGeomIndex] = locPtPoly$1[1];
  14544. return null
  14545. }
  14546. }
  14547. } else if (arguments.length === 3) {
  14548. if (arguments[2] instanceof Array && (hasInterface(arguments[0], List) && hasInterface(arguments[1], List))) {
  14549. var locs = arguments[0];
  14550. var polys$1 = arguments[1];
  14551. var locPtPoly$2 = arguments[2];
  14552. for (var i = 0; i < locs.size(); i++) {
  14553. var loc = locs.get(i);
  14554. for (var j = 0; j < polys$1.size(); j++) {
  14555. this$1.computeContainmentDistance(loc, polys$1.get(j), locPtPoly$2);
  14556. if (this$1._minDistance <= this$1._terminateDistance) { return null }
  14557. }
  14558. }
  14559. } else if (arguments[2] instanceof Array && (arguments[0] instanceof GeometryLocation && arguments[1] instanceof Polygon)) {
  14560. var ptLoc = arguments[0];
  14561. var poly = arguments[1];
  14562. var locPtPoly$3 = arguments[2];
  14563. var pt = ptLoc.getCoordinate();
  14564. if (Location.EXTERIOR !== this._ptLocator.locate(pt, poly)) {
  14565. this._minDistance = 0.0;
  14566. locPtPoly$3[0] = ptLoc;
  14567. locPtPoly$3[1] = new GeometryLocation(poly, pt);
  14568. return null
  14569. }
  14570. }
  14571. }
  14572. };
  14573. DistanceOp.prototype.computeMinDistanceLinesPoints = function computeMinDistanceLinesPoints (lines, points, locGeom) {
  14574. var this$1 = this;
  14575. for (var i = 0; i < lines.size(); i++) {
  14576. var line = lines.get(i);
  14577. for (var j = 0; j < points.size(); j++) {
  14578. var pt = points.get(j);
  14579. this$1.computeMinDistance(line, pt, locGeom);
  14580. if (this$1._minDistance <= this$1._terminateDistance) { return null }
  14581. }
  14582. }
  14583. };
  14584. DistanceOp.prototype.computeFacetDistance = function computeFacetDistance () {
  14585. var locGeom = new Array(2).fill(null);
  14586. var lines0 = LinearComponentExtracter.getLines(this._geom[0]);
  14587. var lines1 = LinearComponentExtracter.getLines(this._geom[1]);
  14588. var pts0 = PointExtracter.getPoints(this._geom[0]);
  14589. var pts1 = PointExtracter.getPoints(this._geom[1]);
  14590. this.computeMinDistanceLines(lines0, lines1, locGeom);
  14591. this.updateMinDistance(locGeom, false);
  14592. if (this._minDistance <= this._terminateDistance) { return null }
  14593. locGeom[0] = null;
  14594. locGeom[1] = null;
  14595. this.computeMinDistanceLinesPoints(lines0, pts1, locGeom);
  14596. this.updateMinDistance(locGeom, false);
  14597. if (this._minDistance <= this._terminateDistance) { return null }
  14598. locGeom[0] = null;
  14599. locGeom[1] = null;
  14600. this.computeMinDistanceLinesPoints(lines1, pts0, locGeom);
  14601. this.updateMinDistance(locGeom, true);
  14602. if (this._minDistance <= this._terminateDistance) { return null }
  14603. locGeom[0] = null;
  14604. locGeom[1] = null;
  14605. this.computeMinDistancePoints(pts0, pts1, locGeom);
  14606. this.updateMinDistance(locGeom, false);
  14607. };
  14608. DistanceOp.prototype.nearestLocations = function nearestLocations () {
  14609. this.computeMinDistance();
  14610. return this._minDistanceLocation
  14611. };
  14612. DistanceOp.prototype.updateMinDistance = function updateMinDistance (locGeom, flip) {
  14613. if (locGeom[0] === null) { return null }
  14614. if (flip) {
  14615. this._minDistanceLocation[0] = locGeom[1];
  14616. this._minDistanceLocation[1] = locGeom[0];
  14617. } else {
  14618. this._minDistanceLocation[0] = locGeom[0];
  14619. this._minDistanceLocation[1] = locGeom[1];
  14620. }
  14621. };
  14622. DistanceOp.prototype.nearestPoints = function nearestPoints () {
  14623. this.computeMinDistance();
  14624. var nearestPts = [this._minDistanceLocation[0].getCoordinate(), this._minDistanceLocation[1].getCoordinate()];
  14625. return nearestPts
  14626. };
  14627. DistanceOp.prototype.computeMinDistance = function computeMinDistance () {
  14628. var this$1 = this;
  14629. if (arguments.length === 0) {
  14630. if (this._minDistanceLocation !== null) { return null }
  14631. this._minDistanceLocation = new Array(2).fill(null);
  14632. this.computeContainmentDistance();
  14633. if (this._minDistance <= this._terminateDistance) { return null }
  14634. this.computeFacetDistance();
  14635. } else if (arguments.length === 3) {
  14636. if (arguments[2] instanceof Array && (arguments[0] instanceof LineString && arguments[1] instanceof Point)) {
  14637. var line = arguments[0];
  14638. var pt = arguments[1];
  14639. var locGeom = arguments[2];
  14640. if (line.getEnvelopeInternal().distance(pt.getEnvelopeInternal()) > this._minDistance) { return null }
  14641. var coord0 = line.getCoordinates();
  14642. var coord = pt.getCoordinate();
  14643. for (var i = 0; i < coord0.length - 1; i++) {
  14644. var dist = CGAlgorithms.distancePointLine(coord, coord0[i], coord0[i + 1]);
  14645. if (dist < this$1._minDistance) {
  14646. this$1._minDistance = dist;
  14647. var seg = new LineSegment(coord0[i], coord0[i + 1]);
  14648. var segClosestPoint = seg.closestPoint(coord);
  14649. locGeom[0] = new GeometryLocation(line, i, segClosestPoint);
  14650. locGeom[1] = new GeometryLocation(pt, 0, coord);
  14651. }
  14652. if (this$1._minDistance <= this$1._terminateDistance) { return null }
  14653. }
  14654. } else if (arguments[2] instanceof Array && (arguments[0] instanceof LineString && arguments[1] instanceof LineString)) {
  14655. var line0 = arguments[0];
  14656. var line1 = arguments[1];
  14657. var locGeom$1 = arguments[2];
  14658. if (line0.getEnvelopeInternal().distance(line1.getEnvelopeInternal()) > this._minDistance) { return null }
  14659. var coord0$1 = line0.getCoordinates();
  14660. var coord1 = line1.getCoordinates();
  14661. for (var i$1 = 0; i$1 < coord0$1.length - 1; i$1++) {
  14662. for (var j = 0; j < coord1.length - 1; j++) {
  14663. var dist$1 = CGAlgorithms.distanceLineLine(coord0$1[i$1], coord0$1[i$1 + 1], coord1[j], coord1[j + 1]);
  14664. if (dist$1 < this$1._minDistance) {
  14665. this$1._minDistance = dist$1;
  14666. var seg0 = new LineSegment(coord0$1[i$1], coord0$1[i$1 + 1]);
  14667. var seg1 = new LineSegment(coord1[j], coord1[j + 1]);
  14668. var closestPt = seg0.closestPoints(seg1);
  14669. locGeom$1[0] = new GeometryLocation(line0, i$1, closestPt[0]);
  14670. locGeom$1[1] = new GeometryLocation(line1, j, closestPt[1]);
  14671. }
  14672. if (this$1._minDistance <= this$1._terminateDistance) { return null }
  14673. }
  14674. }
  14675. }
  14676. }
  14677. };
  14678. DistanceOp.prototype.computeMinDistancePoints = function computeMinDistancePoints (points0, points1, locGeom) {
  14679. var this$1 = this;
  14680. for (var i = 0; i < points0.size(); i++) {
  14681. var pt0 = points0.get(i);
  14682. for (var j = 0; j < points1.size(); j++) {
  14683. var pt1 = points1.get(j);
  14684. var dist = pt0.getCoordinate().distance(pt1.getCoordinate());
  14685. if (dist < this$1._minDistance) {
  14686. this$1._minDistance = dist;
  14687. locGeom[0] = new GeometryLocation(pt0, 0, pt0.getCoordinate());
  14688. locGeom[1] = new GeometryLocation(pt1, 0, pt1.getCoordinate());
  14689. }
  14690. if (this$1._minDistance <= this$1._terminateDistance) { return null }
  14691. }
  14692. }
  14693. };
  14694. DistanceOp.prototype.distance = function distance () {
  14695. if (this._geom[0] === null || this._geom[1] === null) { throw new IllegalArgumentException('null geometries are not supported') }
  14696. if (this._geom[0].isEmpty() || this._geom[1].isEmpty()) { return 0.0 }
  14697. this.computeMinDistance();
  14698. return this._minDistance
  14699. };
  14700. DistanceOp.prototype.computeMinDistanceLines = function computeMinDistanceLines (lines0, lines1, locGeom) {
  14701. var this$1 = this;
  14702. for (var i = 0; i < lines0.size(); i++) {
  14703. var line0 = lines0.get(i);
  14704. for (var j = 0; j < lines1.size(); j++) {
  14705. var line1 = lines1.get(j);
  14706. this$1.computeMinDistance(line0, line1, locGeom);
  14707. if (this$1._minDistance <= this$1._terminateDistance) { return null }
  14708. }
  14709. }
  14710. };
  14711. DistanceOp.prototype.interfaces_ = function interfaces_ () {
  14712. return []
  14713. };
  14714. DistanceOp.prototype.getClass = function getClass () {
  14715. return DistanceOp
  14716. };
  14717. DistanceOp.distance = function distance (g0, g1) {
  14718. var distOp = new DistanceOp(g0, g1);
  14719. return distOp.distance()
  14720. };
  14721. DistanceOp.isWithinDistance = function isWithinDistance (g0, g1, distance) {
  14722. var distOp = new DistanceOp(g0, g1, distance);
  14723. return distOp.distance() <= distance
  14724. };
  14725. DistanceOp.nearestPoints = function nearestPoints (g0, g1) {
  14726. var distOp = new DistanceOp(g0, g1);
  14727. return distOp.nearestPoints()
  14728. };
  14729. var PointPairDistance$2 = function PointPairDistance () {
  14730. this._pt = [new Coordinate(), new Coordinate()];
  14731. this._distance = Double.NaN;
  14732. this._isNull = true;
  14733. };
  14734. PointPairDistance$2.prototype.getCoordinates = function getCoordinates () {
  14735. return this._pt
  14736. };
  14737. PointPairDistance$2.prototype.getCoordinate = function getCoordinate (i) {
  14738. return this._pt[i]
  14739. };
  14740. PointPairDistance$2.prototype.setMinimum = function setMinimum () {
  14741. if (arguments.length === 1) {
  14742. var ptDist = arguments[0];
  14743. this.setMinimum(ptDist._pt[0], ptDist._pt[1]);
  14744. } else if (arguments.length === 2) {
  14745. var p0 = arguments[0];
  14746. var p1 = arguments[1];
  14747. if (this._isNull) {
  14748. this.initialize(p0, p1);
  14749. return null
  14750. }
  14751. var dist = p0.distance(p1);
  14752. if (dist < this._distance) { this.initialize(p0, p1, dist); }
  14753. }
  14754. };
  14755. PointPairDistance$2.prototype.initialize = function initialize () {
  14756. if (arguments.length === 0) {
  14757. this._isNull = true;
  14758. } else if (arguments.length === 2) {
  14759. var p0 = arguments[0];
  14760. var p1 = arguments[1];
  14761. this._pt[0].setCoordinate(p0);
  14762. this._pt[1].setCoordinate(p1);
  14763. this._distance = p0.distance(p1);
  14764. this._isNull = false;
  14765. } else if (arguments.length === 3) {
  14766. var p0$1 = arguments[0];
  14767. var p1$1 = arguments[1];
  14768. var distance = arguments[2];
  14769. this._pt[0].setCoordinate(p0$1);
  14770. this._pt[1].setCoordinate(p1$1);
  14771. this._distance = distance;
  14772. this._isNull = false;
  14773. }
  14774. };
  14775. PointPairDistance$2.prototype.toString = function toString () {
  14776. return WKTWriter.toLineString(this._pt[0], this._pt[1])
  14777. };
  14778. PointPairDistance$2.prototype.getDistance = function getDistance () {
  14779. return this._distance
  14780. };
  14781. PointPairDistance$2.prototype.setMaximum = function setMaximum () {
  14782. if (arguments.length === 1) {
  14783. var ptDist = arguments[0];
  14784. this.setMaximum(ptDist._pt[0], ptDist._pt[1]);
  14785. } else if (arguments.length === 2) {
  14786. var p0 = arguments[0];
  14787. var p1 = arguments[1];
  14788. if (this._isNull) {
  14789. this.initialize(p0, p1);
  14790. return null
  14791. }
  14792. var dist = p0.distance(p1);
  14793. if (dist > this._distance) { this.initialize(p0, p1, dist); }
  14794. }
  14795. };
  14796. PointPairDistance$2.prototype.interfaces_ = function interfaces_ () {
  14797. return []
  14798. };
  14799. PointPairDistance$2.prototype.getClass = function getClass () {
  14800. return PointPairDistance$2
  14801. };
  14802. var DistanceToPoint = function DistanceToPoint () {};
  14803. DistanceToPoint.prototype.interfaces_ = function interfaces_ () {
  14804. return []
  14805. };
  14806. DistanceToPoint.prototype.getClass = function getClass () {
  14807. return DistanceToPoint
  14808. };
  14809. DistanceToPoint.computeDistance = function computeDistance () {
  14810. if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof LineString && arguments[1] instanceof Coordinate)) {
  14811. var line = arguments[0];
  14812. var pt = arguments[1];
  14813. var ptDist = arguments[2];
  14814. var tempSegment = new LineSegment();
  14815. var coords = line.getCoordinates();
  14816. for (var i = 0; i < coords.length - 1; i++) {
  14817. tempSegment.setCoordinates(coords[i], coords[i + 1]);
  14818. var closestPt = tempSegment.closestPoint(pt);
  14819. ptDist.setMinimum(closestPt, pt);
  14820. }
  14821. } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof Polygon && arguments[1] instanceof Coordinate)) {
  14822. var poly = arguments[0];
  14823. var pt$1 = arguments[1];
  14824. var ptDist$1 = arguments[2];
  14825. DistanceToPoint.computeDistance(poly.getExteriorRing(), pt$1, ptDist$1);
  14826. for (var i$1 = 0; i$1 < poly.getNumInteriorRing(); i$1++) {
  14827. DistanceToPoint.computeDistance(poly.getInteriorRingN(i$1), pt$1, ptDist$1);
  14828. }
  14829. } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof Geometry && arguments[1] instanceof Coordinate)) {
  14830. var geom = arguments[0];
  14831. var pt$2 = arguments[1];
  14832. var ptDist$2 = arguments[2];
  14833. if (geom instanceof LineString) {
  14834. DistanceToPoint.computeDistance(geom, pt$2, ptDist$2);
  14835. } else if (geom instanceof Polygon) {
  14836. DistanceToPoint.computeDistance(geom, pt$2, ptDist$2);
  14837. } else if (geom instanceof GeometryCollection) {
  14838. var gc = geom;
  14839. for (var i$2 = 0; i$2 < gc.getNumGeometries(); i$2++) {
  14840. var g = gc.getGeometryN(i$2);
  14841. DistanceToPoint.computeDistance(g, pt$2, ptDist$2);
  14842. }
  14843. } else {
  14844. ptDist$2.setMinimum(geom.getCoordinate(), pt$2);
  14845. }
  14846. } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof LineSegment && arguments[1] instanceof Coordinate)) {
  14847. var segment = arguments[0];
  14848. var pt$3 = arguments[1];
  14849. var ptDist$3 = arguments[2];
  14850. var closestPt$1 = segment.closestPoint(pt$3);
  14851. ptDist$3.setMinimum(closestPt$1, pt$3);
  14852. }
  14853. };
  14854. var DiscreteHausdorffDistance = function DiscreteHausdorffDistance () {
  14855. this._g0 = null;
  14856. this._g1 = null;
  14857. this._ptDist = new PointPairDistance$2();
  14858. this._densifyFrac = 0.0;
  14859. var g0 = arguments[0];
  14860. var g1 = arguments[1];
  14861. this._g0 = g0;
  14862. this._g1 = g1;
  14863. };
  14864. var staticAccessors$39 = { MaxPointDistanceFilter: { configurable: true },MaxDensifiedByFractionDistanceFilter: { configurable: true } };
  14865. DiscreteHausdorffDistance.prototype.getCoordinates = function getCoordinates () {
  14866. return this._ptDist.getCoordinates()
  14867. };
  14868. DiscreteHausdorffDistance.prototype.setDensifyFraction = function setDensifyFraction (densifyFrac) {
  14869. if (densifyFrac > 1.0 || densifyFrac <= 0.0) { throw new IllegalArgumentException('Fraction is not in range (0.0 - 1.0]') }
  14870. this._densifyFrac = densifyFrac;
  14871. };
  14872. DiscreteHausdorffDistance.prototype.compute = function compute (g0, g1) {
  14873. this.computeOrientedDistance(g0, g1, this._ptDist);
  14874. this.computeOrientedDistance(g1, g0, this._ptDist);
  14875. };
  14876. DiscreteHausdorffDistance.prototype.distance = function distance () {
  14877. this.compute(this._g0, this._g1);
  14878. return this._ptDist.getDistance()
  14879. };
  14880. DiscreteHausdorffDistance.prototype.computeOrientedDistance = function computeOrientedDistance (discreteGeom, geom, ptDist) {
  14881. var distFilter = new MaxPointDistanceFilter$1(geom);
  14882. discreteGeom.apply(distFilter);
  14883. ptDist.setMaximum(distFilter.getMaxPointDistance());
  14884. if (this._densifyFrac > 0) {
  14885. var fracFilter = new MaxDensifiedByFractionDistanceFilter(geom, this._densifyFrac);
  14886. discreteGeom.apply(fracFilter);
  14887. ptDist.setMaximum(fracFilter.getMaxPointDistance());
  14888. }
  14889. };
  14890. DiscreteHausdorffDistance.prototype.orientedDistance = function orientedDistance () {
  14891. this.computeOrientedDistance(this._g0, this._g1, this._ptDist);
  14892. return this._ptDist.getDistance()
  14893. };
  14894. DiscreteHausdorffDistance.prototype.interfaces_ = function interfaces_ () {
  14895. return []
  14896. };
  14897. DiscreteHausdorffDistance.prototype.getClass = function getClass () {
  14898. return DiscreteHausdorffDistance
  14899. };
  14900. DiscreteHausdorffDistance.distance = function distance () {
  14901. if (arguments.length === 2) {
  14902. var g0 = arguments[0];
  14903. var g1 = arguments[1];
  14904. var dist = new DiscreteHausdorffDistance(g0, g1);
  14905. return dist.distance()
  14906. } else if (arguments.length === 3) {
  14907. var g0$1 = arguments[0];
  14908. var g1$1 = arguments[1];
  14909. var densifyFrac = arguments[2];
  14910. var dist$1 = new DiscreteHausdorffDistance(g0$1, g1$1);
  14911. dist$1.setDensifyFraction(densifyFrac);
  14912. return dist$1.distance()
  14913. }
  14914. };
  14915. staticAccessors$39.MaxPointDistanceFilter.get = function () { return MaxPointDistanceFilter$1 };
  14916. staticAccessors$39.MaxDensifiedByFractionDistanceFilter.get = function () { return MaxDensifiedByFractionDistanceFilter };
  14917. Object.defineProperties( DiscreteHausdorffDistance, staticAccessors$39 );
  14918. var MaxPointDistanceFilter$1 = function MaxPointDistanceFilter () {
  14919. this._maxPtDist = new PointPairDistance$2();
  14920. this._minPtDist = new PointPairDistance$2();
  14921. this._euclideanDist = new DistanceToPoint();
  14922. this._geom = null;
  14923. var geom = arguments[0];
  14924. this._geom = geom;
  14925. };
  14926. MaxPointDistanceFilter$1.prototype.filter = function filter (pt) {
  14927. this._minPtDist.initialize();
  14928. DistanceToPoint.computeDistance(this._geom, pt, this._minPtDist);
  14929. this._maxPtDist.setMaximum(this._minPtDist);
  14930. };
  14931. MaxPointDistanceFilter$1.prototype.getMaxPointDistance = function getMaxPointDistance () {
  14932. return this._maxPtDist
  14933. };
  14934. MaxPointDistanceFilter$1.prototype.interfaces_ = function interfaces_ () {
  14935. return [CoordinateFilter]
  14936. };
  14937. MaxPointDistanceFilter$1.prototype.getClass = function getClass () {
  14938. return MaxPointDistanceFilter$1
  14939. };
  14940. var MaxDensifiedByFractionDistanceFilter = function MaxDensifiedByFractionDistanceFilter () {
  14941. this._maxPtDist = new PointPairDistance$2();
  14942. this._minPtDist = new PointPairDistance$2();
  14943. this._geom = null;
  14944. this._numSubSegs = 0;
  14945. var geom = arguments[0];
  14946. var fraction = arguments[1];
  14947. this._geom = geom;
  14948. this._numSubSegs = Math.trunc(Math.round(1.0 / fraction));
  14949. };
  14950. MaxDensifiedByFractionDistanceFilter.prototype.filter = function filter (seq, index) {
  14951. var this$1 = this;
  14952. if (index === 0) { return null }
  14953. var p0 = seq.getCoordinate(index - 1);
  14954. var p1 = seq.getCoordinate(index);
  14955. var delx = (p1.x - p0.x) / this._numSubSegs;
  14956. var dely = (p1.y - p0.y) / this._numSubSegs;
  14957. for (var i = 0; i < this._numSubSegs; i++) {
  14958. var x = p0.x + i * delx;
  14959. var y = p0.y + i * dely;
  14960. var pt = new Coordinate(x, y);
  14961. this$1._minPtDist.initialize();
  14962. DistanceToPoint.computeDistance(this$1._geom, pt, this$1._minPtDist);
  14963. this$1._maxPtDist.setMaximum(this$1._minPtDist);
  14964. }
  14965. };
  14966. MaxDensifiedByFractionDistanceFilter.prototype.isDone = function isDone () {
  14967. return false
  14968. };
  14969. MaxDensifiedByFractionDistanceFilter.prototype.isGeometryChanged = function isGeometryChanged () {
  14970. return false
  14971. };
  14972. MaxDensifiedByFractionDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {
  14973. return this._maxPtDist
  14974. };
  14975. MaxDensifiedByFractionDistanceFilter.prototype.interfaces_ = function interfaces_ () {
  14976. return [CoordinateSequenceFilter]
  14977. };
  14978. MaxDensifiedByFractionDistanceFilter.prototype.getClass = function getClass () {
  14979. return MaxDensifiedByFractionDistanceFilter
  14980. };
  14981. var BufferDistanceValidator = function BufferDistanceValidator (input, bufDistance, result) {
  14982. this._minValidDistance = null;
  14983. this._maxValidDistance = null;
  14984. this._minDistanceFound = null;
  14985. this._maxDistanceFound = null;
  14986. this._isValid = true;
  14987. this._errMsg = null;
  14988. this._errorLocation = null;
  14989. this._errorIndicator = null;
  14990. this._input = input || null;
  14991. this._bufDistance = bufDistance || null;
  14992. this._result = result || null;
  14993. };
  14994. var staticAccessors$37 = { VERBOSE: { configurable: true },MAX_DISTANCE_DIFF_FRAC: { configurable: true } };
  14995. BufferDistanceValidator.prototype.checkMaximumDistance = function checkMaximumDistance (input, bufCurve, maxDist) {
  14996. var haus = new DiscreteHausdorffDistance(bufCurve, input);
  14997. haus.setDensifyFraction(0.25);
  14998. this._maxDistanceFound = haus.orientedDistance();
  14999. if (this._maxDistanceFound > maxDist) {
  15000. this._isValid = false;
  15001. var pts = haus.getCoordinates();
  15002. this._errorLocation = pts[1];
  15003. this._errorIndicator = input.getFactory().createLineString(pts);
  15004. this._errMsg = 'Distance between buffer curve and input is too large (' + this._maxDistanceFound + ' at ' + WKTWriter.toLineString(pts[0], pts[1]) + ')';
  15005. }
  15006. };
  15007. BufferDistanceValidator.prototype.isValid = function isValid () {
  15008. var posDistance = Math.abs(this._bufDistance);
  15009. var distDelta = BufferDistanceValidator.MAX_DISTANCE_DIFF_FRAC * posDistance;
  15010. this._minValidDistance = posDistance - distDelta;
  15011. this._maxValidDistance = posDistance + distDelta;
  15012. if (this._input.isEmpty() || this._result.isEmpty()) { return true }
  15013. if (this._bufDistance > 0.0) {
  15014. this.checkPositiveValid();
  15015. } else {
  15016. this.checkNegativeValid();
  15017. }
  15018. if (BufferDistanceValidator.VERBOSE) {
  15019. System.out.println('Min Dist= ' + this._minDistanceFound + ' err= ' + (1.0 - this._minDistanceFound / this._bufDistance) + ' Max Dist= ' + this._maxDistanceFound + ' err= ' + (this._maxDistanceFound / this._bufDistance - 1.0));
  15020. }
  15021. return this._isValid
  15022. };
  15023. BufferDistanceValidator.prototype.checkNegativeValid = function checkNegativeValid () {
  15024. if (!(this._input instanceof Polygon || this._input instanceof MultiPolygon || this._input instanceof GeometryCollection)) {
  15025. return null
  15026. }
  15027. var inputCurve = this.getPolygonLines(this._input);
  15028. this.checkMinimumDistance(inputCurve, this._result, this._minValidDistance);
  15029. if (!this._isValid) { return null }
  15030. this.checkMaximumDistance(inputCurve, this._result, this._maxValidDistance);
  15031. };
  15032. BufferDistanceValidator.prototype.getErrorIndicator = function getErrorIndicator () {
  15033. return this._errorIndicator
  15034. };
  15035. BufferDistanceValidator.prototype.checkMinimumDistance = function checkMinimumDistance (g1, g2, minDist) {
  15036. var distOp = new DistanceOp(g1, g2, minDist);
  15037. this._minDistanceFound = distOp.distance();
  15038. if (this._minDistanceFound < minDist) {
  15039. this._isValid = false;
  15040. var pts = distOp.nearestPoints();
  15041. this._errorLocation = distOp.nearestPoints()[1];
  15042. this._errorIndicator = g1.getFactory().createLineString(pts);
  15043. this._errMsg = 'Distance between buffer curve and input is too small (' + this._minDistanceFound + ' at ' + WKTWriter.toLineString(pts[0], pts[1]) + ' )';
  15044. }
  15045. };
  15046. BufferDistanceValidator.prototype.checkPositiveValid = function checkPositiveValid () {
  15047. var bufCurve = this._result.getBoundary();
  15048. this.checkMinimumDistance(this._input, bufCurve, this._minValidDistance);
  15049. if (!this._isValid) { return null }
  15050. this.checkMaximumDistance(this._input, bufCurve, this._maxValidDistance);
  15051. };
  15052. BufferDistanceValidator.prototype.getErrorLocation = function getErrorLocation () {
  15053. return this._errorLocation
  15054. };
  15055. BufferDistanceValidator.prototype.getPolygonLines = function getPolygonLines (g) {
  15056. var lines = new ArrayList();
  15057. var lineExtracter = new LinearComponentExtracter(lines);
  15058. var polys = PolygonExtracter.getPolygons(g);
  15059. for (var i = polys.iterator(); i.hasNext();) {
  15060. var poly = i.next();
  15061. poly.apply(lineExtracter);
  15062. }
  15063. return g.getFactory().buildGeometry(lines)
  15064. };
  15065. BufferDistanceValidator.prototype.getErrorMessage = function getErrorMessage () {
  15066. return this._errMsg
  15067. };
  15068. BufferDistanceValidator.prototype.interfaces_ = function interfaces_ () {
  15069. return []
  15070. };
  15071. BufferDistanceValidator.prototype.getClass = function getClass () {
  15072. return BufferDistanceValidator
  15073. };
  15074. staticAccessors$37.VERBOSE.get = function () { return false };
  15075. staticAccessors$37.MAX_DISTANCE_DIFF_FRAC.get = function () { return 0.012 };
  15076. Object.defineProperties( BufferDistanceValidator, staticAccessors$37 );
  15077. var BufferResultValidator = function BufferResultValidator (input, distance, result) {
  15078. this._isValid = true;
  15079. this._errorMsg = null;
  15080. this._errorLocation = null;
  15081. this._errorIndicator = null;
  15082. this._input = input || null;
  15083. this._distance = distance || null;
  15084. this._result = result || null;
  15085. };
  15086. var staticAccessors$40 = { VERBOSE: { configurable: true },MAX_ENV_DIFF_FRAC: { configurable: true } };
  15087. BufferResultValidator.prototype.isValid = function isValid () {
  15088. this.checkPolygonal();
  15089. if (!this._isValid) { return this._isValid }
  15090. this.checkExpectedEmpty();
  15091. if (!this._isValid) { return this._isValid }
  15092. this.checkEnvelope();
  15093. if (!this._isValid) { return this._isValid }
  15094. this.checkArea();
  15095. if (!this._isValid) { return this._isValid }
  15096. this.checkDistance();
  15097. return this._isValid
  15098. };
  15099. BufferResultValidator.prototype.checkEnvelope = function checkEnvelope () {
  15100. if (this._distance < 0.0) { return null }
  15101. var padding = this._distance * BufferResultValidator.MAX_ENV_DIFF_FRAC;
  15102. if (padding === 0.0) { padding = 0.001; }
  15103. var expectedEnv = new Envelope(this._input.getEnvelopeInternal());
  15104. expectedEnv.expandBy(this._distance);
  15105. var bufEnv = new Envelope(this._result.getEnvelopeInternal());
  15106. bufEnv.expandBy(padding);
  15107. if (!bufEnv.contains(expectedEnv)) {
  15108. this._isValid = false;
  15109. this._errorMsg = 'Buffer envelope is incorrect';
  15110. this._errorIndicator = this._input.getFactory().toGeometry(bufEnv);
  15111. }
  15112. this.report('Envelope');
  15113. };
  15114. BufferResultValidator.prototype.checkDistance = function checkDistance () {
  15115. var distValid = new BufferDistanceValidator(this._input, this._distance, this._result);
  15116. if (!distValid.isValid()) {
  15117. this._isValid = false;
  15118. this._errorMsg = distValid.getErrorMessage();
  15119. this._errorLocation = distValid.getErrorLocation();
  15120. this._errorIndicator = distValid.getErrorIndicator();
  15121. }
  15122. this.report('Distance');
  15123. };
  15124. BufferResultValidator.prototype.checkArea = function checkArea () {
  15125. var inputArea = this._input.getArea();
  15126. var resultArea = this._result.getArea();
  15127. if (this._distance > 0.0 && inputArea > resultArea) {
  15128. this._isValid = false;
  15129. this._errorMsg = 'Area of positive buffer is smaller than input';
  15130. this._errorIndicator = this._result;
  15131. }
  15132. if (this._distance < 0.0 && inputArea < resultArea) {
  15133. this._isValid = false;
  15134. this._errorMsg = 'Area of negative buffer is larger than input';
  15135. this._errorIndicator = this._result;
  15136. }
  15137. this.report('Area');
  15138. };
  15139. BufferResultValidator.prototype.checkPolygonal = function checkPolygonal () {
  15140. if (!(this._result instanceof Polygon || this._result instanceof MultiPolygon)) { this._isValid = false; }
  15141. this._errorMsg = 'Result is not polygonal';
  15142. this._errorIndicator = this._result;
  15143. this.report('Polygonal');
  15144. };
  15145. BufferResultValidator.prototype.getErrorIndicator = function getErrorIndicator () {
  15146. return this._errorIndicator
  15147. };
  15148. BufferResultValidator.prototype.getErrorLocation = function getErrorLocation () {
  15149. return this._errorLocation
  15150. };
  15151. BufferResultValidator.prototype.checkExpectedEmpty = function checkExpectedEmpty () {
  15152. if (this._input.getDimension() >= 2) { return null }
  15153. if (this._distance > 0.0) { return null }
  15154. if (!this._result.isEmpty()) {
  15155. this._isValid = false;
  15156. this._errorMsg = 'Result is non-empty';
  15157. this._errorIndicator = this._result;
  15158. }
  15159. this.report('ExpectedEmpty');
  15160. };
  15161. BufferResultValidator.prototype.report = function report (checkName) {
  15162. if (!BufferResultValidator.VERBOSE) { return null }
  15163. System.out.println('Check ' + checkName + ': ' + (this._isValid ? 'passed' : 'FAILED'));
  15164. };
  15165. BufferResultValidator.prototype.getErrorMessage = function getErrorMessage () {
  15166. return this._errorMsg
  15167. };
  15168. BufferResultValidator.prototype.interfaces_ = function interfaces_ () {
  15169. return []
  15170. };
  15171. BufferResultValidator.prototype.getClass = function getClass () {
  15172. return BufferResultValidator
  15173. };
  15174. BufferResultValidator.isValidMsg = function isValidMsg (g, distance, result) {
  15175. var validator = new BufferResultValidator(g, distance, result);
  15176. if (!validator.isValid()) { return validator.getErrorMessage() }
  15177. return null
  15178. };
  15179. BufferResultValidator.isValid = function isValid (g, distance, result) {
  15180. var validator = new BufferResultValidator(g, distance, result);
  15181. if (validator.isValid()) { return true }
  15182. return false
  15183. };
  15184. staticAccessors$40.VERBOSE.get = function () { return false };
  15185. staticAccessors$40.MAX_ENV_DIFF_FRAC.get = function () { return 0.012 };
  15186. Object.defineProperties( BufferResultValidator, staticAccessors$40 );
  15187. // operation.buffer
  15188. var BasicSegmentString = function BasicSegmentString () {
  15189. this._pts = null;
  15190. this._data = null;
  15191. var pts = arguments[0];
  15192. var data = arguments[1];
  15193. this._pts = pts;
  15194. this._data = data;
  15195. };
  15196. BasicSegmentString.prototype.getCoordinates = function getCoordinates () {
  15197. return this._pts
  15198. };
  15199. BasicSegmentString.prototype.size = function size () {
  15200. return this._pts.length
  15201. };
  15202. BasicSegmentString.prototype.getCoordinate = function getCoordinate (i) {
  15203. return this._pts[i]
  15204. };
  15205. BasicSegmentString.prototype.isClosed = function isClosed () {
  15206. return this._pts[0].equals(this._pts[this._pts.length - 1])
  15207. };
  15208. BasicSegmentString.prototype.getSegmentOctant = function getSegmentOctant (index) {
  15209. if (index === this._pts.length - 1) { return -1 }
  15210. return Octant.octant(this.getCoordinate(index), this.getCoordinate(index + 1))
  15211. };
  15212. BasicSegmentString.prototype.setData = function setData (data) {
  15213. this._data = data;
  15214. };
  15215. BasicSegmentString.prototype.getData = function getData () {
  15216. return this._data
  15217. };
  15218. BasicSegmentString.prototype.toString = function toString () {
  15219. return WKTWriter.toLineString(new CoordinateArraySequence(this._pts))
  15220. };
  15221. BasicSegmentString.prototype.interfaces_ = function interfaces_ () {
  15222. return [SegmentString]
  15223. };
  15224. BasicSegmentString.prototype.getClass = function getClass () {
  15225. return BasicSegmentString
  15226. };
  15227. var InteriorIntersectionFinder = function InteriorIntersectionFinder () {
  15228. this._findAllIntersections = false;
  15229. this._isCheckEndSegmentsOnly = false;
  15230. this._li = null;
  15231. this._interiorIntersection = null;
  15232. this._intSegments = null;
  15233. this._intersections = new ArrayList();
  15234. this._intersectionCount = 0;
  15235. this._keepIntersections = true;
  15236. var li = arguments[0];
  15237. this._li = li;
  15238. this._interiorIntersection = null;
  15239. };
  15240. InteriorIntersectionFinder.prototype.getInteriorIntersection = function getInteriorIntersection () {
  15241. return this._interiorIntersection
  15242. };
  15243. InteriorIntersectionFinder.prototype.setCheckEndSegmentsOnly = function setCheckEndSegmentsOnly (isCheckEndSegmentsOnly) {
  15244. this._isCheckEndSegmentsOnly = isCheckEndSegmentsOnly;
  15245. };
  15246. InteriorIntersectionFinder.prototype.getIntersectionSegments = function getIntersectionSegments () {
  15247. return this._intSegments
  15248. };
  15249. InteriorIntersectionFinder.prototype.count = function count () {
  15250. return this._intersectionCount
  15251. };
  15252. InteriorIntersectionFinder.prototype.getIntersections = function getIntersections () {
  15253. return this._intersections
  15254. };
  15255. InteriorIntersectionFinder.prototype.setFindAllIntersections = function setFindAllIntersections (findAllIntersections) {
  15256. this._findAllIntersections = findAllIntersections;
  15257. };
  15258. InteriorIntersectionFinder.prototype.setKeepIntersections = function setKeepIntersections (keepIntersections) {
  15259. this._keepIntersections = keepIntersections;
  15260. };
  15261. InteriorIntersectionFinder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {
  15262. if (!this._findAllIntersections && this.hasIntersection()) { return null }
  15263. if (e0 === e1 && segIndex0 === segIndex1) { return null }
  15264. if (this._isCheckEndSegmentsOnly) {
  15265. var isEndSegPresent = this.isEndSegment(e0, segIndex0) || this.isEndSegment(e1, segIndex1);
  15266. if (!isEndSegPresent) { return null }
  15267. }
  15268. var p00 = e0.getCoordinates()[segIndex0];
  15269. var p01 = e0.getCoordinates()[segIndex0 + 1];
  15270. var p10 = e1.getCoordinates()[segIndex1];
  15271. var p11 = e1.getCoordinates()[segIndex1 + 1];
  15272. this._li.computeIntersection(p00, p01, p10, p11);
  15273. if (this._li.hasIntersection()) {
  15274. if (this._li.isInteriorIntersection()) {
  15275. this._intSegments = new Array(4).fill(null);
  15276. this._intSegments[0] = p00;
  15277. this._intSegments[1] = p01;
  15278. this._intSegments[2] = p10;
  15279. this._intSegments[3] = p11;
  15280. this._interiorIntersection = this._li.getIntersection(0);
  15281. if (this._keepIntersections) { this._intersections.add(this._interiorIntersection); }
  15282. this._intersectionCount++;
  15283. }
  15284. }
  15285. };
  15286. InteriorIntersectionFinder.prototype.isEndSegment = function isEndSegment (segStr, index) {
  15287. if (index === 0) { return true }
  15288. if (index >= segStr.size() - 2) { return true }
  15289. return false
  15290. };
  15291. InteriorIntersectionFinder.prototype.hasIntersection = function hasIntersection () {
  15292. return this._interiorIntersection !== null
  15293. };
  15294. InteriorIntersectionFinder.prototype.isDone = function isDone () {
  15295. if (this._findAllIntersections) { return false }
  15296. return this._interiorIntersection !== null
  15297. };
  15298. InteriorIntersectionFinder.prototype.interfaces_ = function interfaces_ () {
  15299. return [SegmentIntersector]
  15300. };
  15301. InteriorIntersectionFinder.prototype.getClass = function getClass () {
  15302. return InteriorIntersectionFinder
  15303. };
  15304. InteriorIntersectionFinder.createAllIntersectionsFinder = function createAllIntersectionsFinder (li) {
  15305. var finder = new InteriorIntersectionFinder(li);
  15306. finder.setFindAllIntersections(true);
  15307. return finder
  15308. };
  15309. InteriorIntersectionFinder.createAnyIntersectionFinder = function createAnyIntersectionFinder (li) {
  15310. return new InteriorIntersectionFinder(li)
  15311. };
  15312. InteriorIntersectionFinder.createIntersectionCounter = function createIntersectionCounter (li) {
  15313. var finder = new InteriorIntersectionFinder(li);
  15314. finder.setFindAllIntersections(true);
  15315. finder.setKeepIntersections(false);
  15316. return finder
  15317. };
  15318. var FastNodingValidator = function FastNodingValidator () {
  15319. this._li = new RobustLineIntersector();
  15320. this._segStrings = null;
  15321. this._findAllIntersections = false;
  15322. this._segInt = null;
  15323. this._isValid = true;
  15324. var segStrings = arguments[0];
  15325. this._segStrings = segStrings;
  15326. };
  15327. FastNodingValidator.prototype.execute = function execute () {
  15328. if (this._segInt !== null) { return null }
  15329. this.checkInteriorIntersections();
  15330. };
  15331. FastNodingValidator.prototype.getIntersections = function getIntersections () {
  15332. return this._segInt.getIntersections()
  15333. };
  15334. FastNodingValidator.prototype.isValid = function isValid () {
  15335. this.execute();
  15336. return this._isValid
  15337. };
  15338. FastNodingValidator.prototype.setFindAllIntersections = function setFindAllIntersections (findAllIntersections) {
  15339. this._findAllIntersections = findAllIntersections;
  15340. };
  15341. FastNodingValidator.prototype.checkInteriorIntersections = function checkInteriorIntersections () {
  15342. this._isValid = true;
  15343. this._segInt = new InteriorIntersectionFinder(this._li);
  15344. this._segInt.setFindAllIntersections(this._findAllIntersections);
  15345. var noder = new MCIndexNoder();
  15346. noder.setSegmentIntersector(this._segInt);
  15347. noder.computeNodes(this._segStrings);
  15348. if (this._segInt.hasIntersection()) {
  15349. this._isValid = false;
  15350. return null
  15351. }
  15352. };
  15353. FastNodingValidator.prototype.checkValid = function checkValid () {
  15354. this.execute();
  15355. if (!this._isValid) { throw new TopologyException(this.getErrorMessage(), this._segInt.getInteriorIntersection()) }
  15356. };
  15357. FastNodingValidator.prototype.getErrorMessage = function getErrorMessage () {
  15358. if (this._isValid) { return 'no intersections found' }
  15359. var intSegs = this._segInt.getIntersectionSegments();
  15360. return 'found non-noded intersection between ' + WKTWriter.toLineString(intSegs[0], intSegs[1]) + ' and ' + WKTWriter.toLineString(intSegs[2], intSegs[3])
  15361. };
  15362. FastNodingValidator.prototype.interfaces_ = function interfaces_ () {
  15363. return []
  15364. };
  15365. FastNodingValidator.prototype.getClass = function getClass () {
  15366. return FastNodingValidator
  15367. };
  15368. FastNodingValidator.computeIntersections = function computeIntersections (segStrings) {
  15369. var nv = new FastNodingValidator(segStrings);
  15370. nv.setFindAllIntersections(true);
  15371. nv.isValid();
  15372. return nv.getIntersections()
  15373. };
  15374. var EdgeNodingValidator = function EdgeNodingValidator () {
  15375. this._nv = null;
  15376. var edges = arguments[0];
  15377. this._nv = new FastNodingValidator(EdgeNodingValidator.toSegmentStrings(edges));
  15378. };
  15379. EdgeNodingValidator.prototype.checkValid = function checkValid () {
  15380. this._nv.checkValid();
  15381. };
  15382. EdgeNodingValidator.prototype.interfaces_ = function interfaces_ () {
  15383. return []
  15384. };
  15385. EdgeNodingValidator.prototype.getClass = function getClass () {
  15386. return EdgeNodingValidator
  15387. };
  15388. EdgeNodingValidator.toSegmentStrings = function toSegmentStrings (edges) {
  15389. var segStrings = new ArrayList();
  15390. for (var i = edges.iterator(); i.hasNext();) {
  15391. var e = i.next();
  15392. segStrings.add(new BasicSegmentString(e.getCoordinates(), e));
  15393. }
  15394. return segStrings
  15395. };
  15396. EdgeNodingValidator.checkValid = function checkValid (edges) {
  15397. var validator = new EdgeNodingValidator(edges);
  15398. validator.checkValid();
  15399. };
  15400. var GeometryCollectionMapper = function GeometryCollectionMapper (mapOp) {
  15401. this._mapOp = mapOp;
  15402. };
  15403. GeometryCollectionMapper.prototype.map = function map (gc) {
  15404. var this$1 = this;
  15405. var mapped = new ArrayList();
  15406. for (var i = 0; i < gc.getNumGeometries(); i++) {
  15407. var g = this$1._mapOp.map(gc.getGeometryN(i));
  15408. if (!g.isEmpty()) { mapped.add(g); }
  15409. }
  15410. return gc.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(mapped))
  15411. };
  15412. GeometryCollectionMapper.prototype.interfaces_ = function interfaces_ () {
  15413. return []
  15414. };
  15415. GeometryCollectionMapper.prototype.getClass = function getClass () {
  15416. return GeometryCollectionMapper
  15417. };
  15418. GeometryCollectionMapper.map = function map (gc, op) {
  15419. var mapper = new GeometryCollectionMapper(op);
  15420. return mapper.map(gc)
  15421. };
  15422. var LineBuilder = function LineBuilder () {
  15423. this._op = null;
  15424. this._geometryFactory = null;
  15425. this._ptLocator = null;
  15426. this._lineEdgesList = new ArrayList();
  15427. this._resultLineList = new ArrayList();
  15428. var op = arguments[0];
  15429. var geometryFactory = arguments[1];
  15430. var ptLocator = arguments[2];
  15431. this._op = op;
  15432. this._geometryFactory = geometryFactory;
  15433. this._ptLocator = ptLocator;
  15434. };
  15435. LineBuilder.prototype.collectLines = function collectLines (opCode) {
  15436. var this$1 = this;
  15437. for (var it = this._op.getGraph().getEdgeEnds().iterator(); it.hasNext();) {
  15438. var de = it.next();
  15439. this$1.collectLineEdge(de, opCode, this$1._lineEdgesList);
  15440. this$1.collectBoundaryTouchEdge(de, opCode, this$1._lineEdgesList);
  15441. }
  15442. };
  15443. LineBuilder.prototype.labelIsolatedLine = function labelIsolatedLine (e, targetIndex) {
  15444. var loc = this._ptLocator.locate(e.getCoordinate(), this._op.getArgGeometry(targetIndex));
  15445. e.getLabel().setLocation(targetIndex, loc);
  15446. };
  15447. LineBuilder.prototype.build = function build (opCode) {
  15448. this.findCoveredLineEdges();
  15449. this.collectLines(opCode);
  15450. this.buildLines(opCode);
  15451. return this._resultLineList
  15452. };
  15453. LineBuilder.prototype.collectLineEdge = function collectLineEdge (de, opCode, edges) {
  15454. var label = de.getLabel();
  15455. var e = de.getEdge();
  15456. if (de.isLineEdge()) {
  15457. if (!de.isVisited() && OverlayOp.isResultOfOp(label, opCode) && !e.isCovered()) {
  15458. edges.add(e);
  15459. de.setVisitedEdge(true);
  15460. }
  15461. }
  15462. };
  15463. LineBuilder.prototype.findCoveredLineEdges = function findCoveredLineEdges () {
  15464. var this$1 = this;
  15465. for (var nodeit = this._op.getGraph().getNodes().iterator(); nodeit.hasNext();) {
  15466. var node = nodeit.next();
  15467. node.getEdges().findCoveredLineEdges();
  15468. }
  15469. for (var it = this._op.getGraph().getEdgeEnds().iterator(); it.hasNext();) {
  15470. var de = it.next();
  15471. var e = de.getEdge();
  15472. if (de.isLineEdge() && !e.isCoveredSet()) {
  15473. var isCovered = this$1._op.isCoveredByA(de.getCoordinate());
  15474. e.setCovered(isCovered);
  15475. }
  15476. }
  15477. };
  15478. LineBuilder.prototype.labelIsolatedLines = function labelIsolatedLines (edgesList) {
  15479. var this$1 = this;
  15480. for (var it = edgesList.iterator(); it.hasNext();) {
  15481. var e = it.next();
  15482. var label = e.getLabel();
  15483. if (e.isIsolated()) {
  15484. if (label.isNull(0)) { this$1.labelIsolatedLine(e, 0); } else { this$1.labelIsolatedLine(e, 1); }
  15485. }
  15486. }
  15487. };
  15488. LineBuilder.prototype.buildLines = function buildLines (opCode) {
  15489. var this$1 = this;
  15490. for (var it = this._lineEdgesList.iterator(); it.hasNext();) {
  15491. var e = it.next();
  15492. // const label = e.getLabel()
  15493. var line = this$1._geometryFactory.createLineString(e.getCoordinates());
  15494. this$1._resultLineList.add(line);
  15495. e.setInResult(true);
  15496. }
  15497. };
  15498. LineBuilder.prototype.collectBoundaryTouchEdge = function collectBoundaryTouchEdge (de, opCode, edges) {
  15499. var label = de.getLabel();
  15500. if (de.isLineEdge()) { return null }
  15501. if (de.isVisited()) { return null }
  15502. if (de.isInteriorAreaEdge()) { return null }
  15503. if (de.getEdge().isInResult()) { return null }
  15504. Assert.isTrue(!(de.isInResult() || de.getSym().isInResult()) || !de.getEdge().isInResult());
  15505. if (OverlayOp.isResultOfOp(label, opCode) && opCode === OverlayOp.INTERSECTION) {
  15506. edges.add(de.getEdge());
  15507. de.setVisitedEdge(true);
  15508. }
  15509. };
  15510. LineBuilder.prototype.interfaces_ = function interfaces_ () {
  15511. return []
  15512. };
  15513. LineBuilder.prototype.getClass = function getClass () {
  15514. return LineBuilder
  15515. };
  15516. var PointBuilder = function PointBuilder () {
  15517. this._op = null;
  15518. this._geometryFactory = null;
  15519. this._resultPointList = new ArrayList();
  15520. var op = arguments[0];
  15521. var geometryFactory = arguments[1];
  15522. // const ptLocator = arguments[2]
  15523. this._op = op;
  15524. this._geometryFactory = geometryFactory;
  15525. };
  15526. PointBuilder.prototype.filterCoveredNodeToPoint = function filterCoveredNodeToPoint (n) {
  15527. var coord = n.getCoordinate();
  15528. if (!this._op.isCoveredByLA(coord)) {
  15529. var pt = this._geometryFactory.createPoint(coord);
  15530. this._resultPointList.add(pt);
  15531. }
  15532. };
  15533. PointBuilder.prototype.extractNonCoveredResultNodes = function extractNonCoveredResultNodes (opCode) {
  15534. var this$1 = this;
  15535. for (var nodeit = this._op.getGraph().getNodes().iterator(); nodeit.hasNext();) {
  15536. var n = nodeit.next();
  15537. if (n.isInResult()) { continue }
  15538. if (n.isIncidentEdgeInResult()) { continue }
  15539. if (n.getEdges().getDegree() === 0 || opCode === OverlayOp.INTERSECTION) {
  15540. var label = n.getLabel();
  15541. if (OverlayOp.isResultOfOp(label, opCode)) {
  15542. this$1.filterCoveredNodeToPoint(n);
  15543. }
  15544. }
  15545. }
  15546. };
  15547. PointBuilder.prototype.build = function build (opCode) {
  15548. this.extractNonCoveredResultNodes(opCode);
  15549. return this._resultPointList
  15550. };
  15551. PointBuilder.prototype.interfaces_ = function interfaces_ () {
  15552. return []
  15553. };
  15554. PointBuilder.prototype.getClass = function getClass () {
  15555. return PointBuilder
  15556. };
  15557. var GeometryTransformer = function GeometryTransformer () {
  15558. this._inputGeom = null;
  15559. this._factory = null;
  15560. this._pruneEmptyGeometry = true;
  15561. this._preserveGeometryCollectionType = true;
  15562. this._preserveCollections = false;
  15563. this._preserveType = false;
  15564. };
  15565. GeometryTransformer.prototype.transformPoint = function transformPoint (geom, parent) {
  15566. return this._factory.createPoint(this.transformCoordinates(geom.getCoordinateSequence(), geom))
  15567. };
  15568. GeometryTransformer.prototype.transformPolygon = function transformPolygon (geom, parent) {
  15569. var this$1 = this;
  15570. var isAllValidLinearRings = true;
  15571. var shell = this.transformLinearRing(geom.getExteriorRing(), geom);
  15572. if (shell === null || !(shell instanceof LinearRing) || shell.isEmpty()) { isAllValidLinearRings = false; }
  15573. var holes = new ArrayList();
  15574. for (var i = 0; i < geom.getNumInteriorRing(); i++) {
  15575. var hole = this$1.transformLinearRing(geom.getInteriorRingN(i), geom);
  15576. if (hole === null || hole.isEmpty()) {
  15577. continue
  15578. }
  15579. if (!(hole instanceof LinearRing)) { isAllValidLinearRings = false; }
  15580. holes.add(hole);
  15581. }
  15582. if (isAllValidLinearRings) { return this._factory.createPolygon(shell, holes.toArray([])); } else {
  15583. var components = new ArrayList();
  15584. if (shell !== null) { components.add(shell); }
  15585. components.addAll(holes);
  15586. return this._factory.buildGeometry(components)
  15587. }
  15588. };
  15589. GeometryTransformer.prototype.createCoordinateSequence = function createCoordinateSequence (coords) {
  15590. return this._factory.getCoordinateSequenceFactory().create(coords)
  15591. };
  15592. GeometryTransformer.prototype.getInputGeometry = function getInputGeometry () {
  15593. return this._inputGeom
  15594. };
  15595. GeometryTransformer.prototype.transformMultiLineString = function transformMultiLineString (geom, parent) {
  15596. var this$1 = this;
  15597. var transGeomList = new ArrayList();
  15598. for (var i = 0; i < geom.getNumGeometries(); i++) {
  15599. var transformGeom = this$1.transformLineString(geom.getGeometryN(i), geom);
  15600. if (transformGeom === null) { continue }
  15601. if (transformGeom.isEmpty()) { continue }
  15602. transGeomList.add(transformGeom);
  15603. }
  15604. return this._factory.buildGeometry(transGeomList)
  15605. };
  15606. GeometryTransformer.prototype.transformCoordinates = function transformCoordinates (coords, parent) {
  15607. return this.copy(coords)
  15608. };
  15609. GeometryTransformer.prototype.transformLineString = function transformLineString (geom, parent) {
  15610. return this._factory.createLineString(this.transformCoordinates(geom.getCoordinateSequence(), geom))
  15611. };
  15612. GeometryTransformer.prototype.transformMultiPoint = function transformMultiPoint (geom, parent) {
  15613. var this$1 = this;
  15614. var transGeomList = new ArrayList();
  15615. for (var i = 0; i < geom.getNumGeometries(); i++) {
  15616. var transformGeom = this$1.transformPoint(geom.getGeometryN(i), geom);
  15617. if (transformGeom === null) { continue }
  15618. if (transformGeom.isEmpty()) { continue }
  15619. transGeomList.add(transformGeom);
  15620. }
  15621. return this._factory.buildGeometry(transGeomList)
  15622. };
  15623. GeometryTransformer.prototype.transformMultiPolygon = function transformMultiPolygon (geom, parent) {
  15624. var this$1 = this;
  15625. var transGeomList = new ArrayList();
  15626. for (var i = 0; i < geom.getNumGeometries(); i++) {
  15627. var transformGeom = this$1.transformPolygon(geom.getGeometryN(i), geom);
  15628. if (transformGeom === null) { continue }
  15629. if (transformGeom.isEmpty()) { continue }
  15630. transGeomList.add(transformGeom);
  15631. }
  15632. return this._factory.buildGeometry(transGeomList)
  15633. };
  15634. GeometryTransformer.prototype.copy = function copy (seq) {
  15635. return seq.copy()
  15636. };
  15637. GeometryTransformer.prototype.transformGeometryCollection = function transformGeometryCollection (geom, parent) {
  15638. var this$1 = this;
  15639. var transGeomList = new ArrayList();
  15640. for (var i = 0; i < geom.getNumGeometries(); i++) {
  15641. var transformGeom = this$1.transform(geom.getGeometryN(i));
  15642. if (transformGeom === null) { continue }
  15643. if (this$1._pruneEmptyGeometry && transformGeom.isEmpty()) { continue }
  15644. transGeomList.add(transformGeom);
  15645. }
  15646. if (this._preserveGeometryCollectionType) { return this._factory.createGeometryCollection(GeometryFactory.toGeometryArray(transGeomList)) }
  15647. return this._factory.buildGeometry(transGeomList)
  15648. };
  15649. GeometryTransformer.prototype.transform = function transform (inputGeom) {
  15650. this._inputGeom = inputGeom;
  15651. this._factory = inputGeom.getFactory();
  15652. if (inputGeom instanceof Point) { return this.transformPoint(inputGeom, null) }
  15653. if (inputGeom instanceof MultiPoint) { return this.transformMultiPoint(inputGeom, null) }
  15654. if (inputGeom instanceof LinearRing) { return this.transformLinearRing(inputGeom, null) }
  15655. if (inputGeom instanceof LineString) { return this.transformLineString(inputGeom, null) }
  15656. if (inputGeom instanceof MultiLineString) { return this.transformMultiLineString(inputGeom, null) }
  15657. if (inputGeom instanceof Polygon) { return this.transformPolygon(inputGeom, null) }
  15658. if (inputGeom instanceof MultiPolygon) { return this.transformMultiPolygon(inputGeom, null) }
  15659. if (inputGeom instanceof GeometryCollection) { return this.transformGeometryCollection(inputGeom, null) }
  15660. throw new IllegalArgumentException('Unknown Geometry subtype: ' + inputGeom.getClass().getName())
  15661. };
  15662. GeometryTransformer.prototype.transformLinearRing = function transformLinearRing (geom, parent) {
  15663. var seq = this.transformCoordinates(geom.getCoordinateSequence(), geom);
  15664. if (seq === null) { return this._factory.createLinearRing(null) }
  15665. var seqSize = seq.size();
  15666. if (seqSize > 0 && seqSize < 4 && !this._preserveType) { return this._factory.createLineString(seq) }
  15667. return this._factory.createLinearRing(seq)
  15668. };
  15669. GeometryTransformer.prototype.interfaces_ = function interfaces_ () {
  15670. return []
  15671. };
  15672. GeometryTransformer.prototype.getClass = function getClass () {
  15673. return GeometryTransformer
  15674. };
  15675. var LineStringSnapper = function LineStringSnapper () {
  15676. this._snapTolerance = 0.0;
  15677. this._srcPts = null;
  15678. this._seg = new LineSegment();
  15679. this._allowSnappingToSourceVertices = false;
  15680. this._isClosed = false;
  15681. if (arguments[0] instanceof LineString && typeof arguments[1] === 'number') {
  15682. var srcLine = arguments[0];
  15683. var snapTolerance = arguments[1];
  15684. LineStringSnapper.call(this, srcLine.getCoordinates(), snapTolerance);
  15685. } else if (arguments[0] instanceof Array && typeof arguments[1] === 'number') {
  15686. var srcPts = arguments[0];
  15687. var snapTolerance$1 = arguments[1];
  15688. this._srcPts = srcPts;
  15689. this._isClosed = LineStringSnapper.isClosed(srcPts);
  15690. this._snapTolerance = snapTolerance$1;
  15691. }
  15692. };
  15693. LineStringSnapper.prototype.snapVertices = function snapVertices (srcCoords, snapPts) {
  15694. var this$1 = this;
  15695. var end = this._isClosed ? srcCoords.size() - 1 : srcCoords.size();
  15696. for (var i = 0; i < end; i++) {
  15697. var srcPt = srcCoords.get(i);
  15698. var snapVert = this$1.findSnapForVertex(srcPt, snapPts);
  15699. if (snapVert !== null) {
  15700. srcCoords.set(i, new Coordinate(snapVert));
  15701. if (i === 0 && this$1._isClosed) { srcCoords.set(srcCoords.size() - 1, new Coordinate(snapVert)); }
  15702. }
  15703. }
  15704. };
  15705. LineStringSnapper.prototype.findSnapForVertex = function findSnapForVertex (pt, snapPts) {
  15706. var this$1 = this;
  15707. for (var i = 0; i < snapPts.length; i++) {
  15708. if (pt.equals2D(snapPts[i])) { return null }
  15709. if (pt.distance(snapPts[i]) < this$1._snapTolerance) { return snapPts[i] }
  15710. }
  15711. return null
  15712. };
  15713. LineStringSnapper.prototype.snapTo = function snapTo (snapPts) {
  15714. var coordList = new CoordinateList(this._srcPts);
  15715. this.snapVertices(coordList, snapPts);
  15716. this.snapSegments(coordList, snapPts);
  15717. var newPts = coordList.toCoordinateArray();
  15718. return newPts
  15719. };
  15720. LineStringSnapper.prototype.snapSegments = function snapSegments (srcCoords, snapPts) {
  15721. var this$1 = this;
  15722. if (snapPts.length === 0) { return null }
  15723. var distinctPtCount = snapPts.length;
  15724. if (snapPts[0].equals2D(snapPts[snapPts.length - 1])) { distinctPtCount = snapPts.length - 1; }
  15725. for (var i = 0; i < distinctPtCount; i++) {
  15726. var snapPt = snapPts[i];
  15727. var index = this$1.findSegmentIndexToSnap(snapPt, srcCoords);
  15728. if (index >= 0) {
  15729. srcCoords.add(index + 1, new Coordinate(snapPt), false);
  15730. }
  15731. }
  15732. };
  15733. LineStringSnapper.prototype.findSegmentIndexToSnap = function findSegmentIndexToSnap (snapPt, srcCoords) {
  15734. var this$1 = this;
  15735. var minDist = Double.MAX_VALUE;
  15736. var snapIndex = -1;
  15737. for (var i = 0; i < srcCoords.size() - 1; i++) {
  15738. this$1._seg.p0 = srcCoords.get(i);
  15739. this$1._seg.p1 = srcCoords.get(i + 1);
  15740. if (this$1._seg.p0.equals2D(snapPt) || this$1._seg.p1.equals2D(snapPt)) {
  15741. if (this$1._allowSnappingToSourceVertices) { continue; } else { return -1 }
  15742. }
  15743. var dist = this$1._seg.distance(snapPt);
  15744. if (dist < this$1._snapTolerance && dist < minDist) {
  15745. minDist = dist;
  15746. snapIndex = i;
  15747. }
  15748. }
  15749. return snapIndex
  15750. };
  15751. LineStringSnapper.prototype.setAllowSnappingToSourceVertices = function setAllowSnappingToSourceVertices (allowSnappingToSourceVertices) {
  15752. this._allowSnappingToSourceVertices = allowSnappingToSourceVertices;
  15753. };
  15754. LineStringSnapper.prototype.interfaces_ = function interfaces_ () {
  15755. return []
  15756. };
  15757. LineStringSnapper.prototype.getClass = function getClass () {
  15758. return LineStringSnapper
  15759. };
  15760. LineStringSnapper.isClosed = function isClosed (pts) {
  15761. if (pts.length <= 1) { return false }
  15762. return pts[0].equals2D(pts[pts.length - 1])
  15763. };
  15764. var GeometrySnapper = function GeometrySnapper (srcGeom) {
  15765. this._srcGeom = srcGeom || null;
  15766. };
  15767. var staticAccessors$41 = { SNAP_PRECISION_FACTOR: { configurable: true } };
  15768. GeometrySnapper.prototype.snapTo = function snapTo (snapGeom, snapTolerance) {
  15769. var snapPts = this.extractTargetCoordinates(snapGeom);
  15770. var snapTrans = new SnapTransformer(snapTolerance, snapPts);
  15771. return snapTrans.transform(this._srcGeom)
  15772. };
  15773. GeometrySnapper.prototype.snapToSelf = function snapToSelf (snapTolerance, cleanResult) {
  15774. var snapPts = this.extractTargetCoordinates(this._srcGeom);
  15775. var snapTrans = new SnapTransformer(snapTolerance, snapPts, true);
  15776. var snappedGeom = snapTrans.transform(this._srcGeom);
  15777. var result = snappedGeom;
  15778. if (cleanResult && hasInterface(result, Polygonal)) {
  15779. result = snappedGeom.buffer(0);
  15780. }
  15781. return result
  15782. };
  15783. GeometrySnapper.prototype.computeSnapTolerance = function computeSnapTolerance (ringPts) {
  15784. var minSegLen = this.computeMinimumSegmentLength(ringPts);
  15785. var snapTol = minSegLen / 10;
  15786. return snapTol
  15787. };
  15788. GeometrySnapper.prototype.extractTargetCoordinates = function extractTargetCoordinates (g) {
  15789. var ptSet = new TreeSet();
  15790. var pts = g.getCoordinates();
  15791. for (var i = 0; i < pts.length; i++) {
  15792. ptSet.add(pts[i]);
  15793. }
  15794. return ptSet.toArray(new Array(0).fill(null))
  15795. };
  15796. GeometrySnapper.prototype.computeMinimumSegmentLength = function computeMinimumSegmentLength (pts) {
  15797. var minSegLen = Double.MAX_VALUE;
  15798. for (var i = 0; i < pts.length - 1; i++) {
  15799. var segLen = pts[i].distance(pts[i + 1]);
  15800. if (segLen < minSegLen) { minSegLen = segLen; }
  15801. }
  15802. return minSegLen
  15803. };
  15804. GeometrySnapper.prototype.interfaces_ = function interfaces_ () {
  15805. return []
  15806. };
  15807. GeometrySnapper.prototype.getClass = function getClass () {
  15808. return GeometrySnapper
  15809. };
  15810. GeometrySnapper.snap = function snap (g0, g1, snapTolerance) {
  15811. var snapGeom = new Array(2).fill(null);
  15812. var snapper0 = new GeometrySnapper(g0);
  15813. snapGeom[0] = snapper0.snapTo(g1, snapTolerance);
  15814. var snapper1 = new GeometrySnapper(g1);
  15815. snapGeom[1] = snapper1.snapTo(snapGeom[0], snapTolerance);
  15816. return snapGeom
  15817. };
  15818. GeometrySnapper.computeOverlaySnapTolerance = function computeOverlaySnapTolerance () {
  15819. if (arguments.length === 1) {
  15820. var g = arguments[0];
  15821. var snapTolerance = GeometrySnapper.computeSizeBasedSnapTolerance(g);
  15822. var pm = g.getPrecisionModel();
  15823. if (pm.getType() === PrecisionModel.FIXED) {
  15824. var fixedSnapTol = 1 / pm.getScale() * 2 / 1.415;
  15825. if (fixedSnapTol > snapTolerance) { snapTolerance = fixedSnapTol; }
  15826. }
  15827. return snapTolerance
  15828. } else if (arguments.length === 2) {
  15829. var g0 = arguments[0];
  15830. var g1 = arguments[1];
  15831. return Math.min(GeometrySnapper.computeOverlaySnapTolerance(g0), GeometrySnapper.computeOverlaySnapTolerance(g1))
  15832. }
  15833. };
  15834. GeometrySnapper.computeSizeBasedSnapTolerance = function computeSizeBasedSnapTolerance (g) {
  15835. var env = g.getEnvelopeInternal();
  15836. var minDimension = Math.min(env.getHeight(), env.getWidth());
  15837. var snapTol = minDimension * GeometrySnapper.SNAP_PRECISION_FACTOR;
  15838. return snapTol
  15839. };
  15840. GeometrySnapper.snapToSelf = function snapToSelf (geom, snapTolerance, cleanResult) {
  15841. var snapper0 = new GeometrySnapper(geom);
  15842. return snapper0.snapToSelf(snapTolerance, cleanResult)
  15843. };
  15844. staticAccessors$41.SNAP_PRECISION_FACTOR.get = function () { return 1e-9 };
  15845. Object.defineProperties( GeometrySnapper, staticAccessors$41 );
  15846. var SnapTransformer = (function (GeometryTransformer$$1) {
  15847. function SnapTransformer (snapTolerance, snapPts, isSelfSnap) {
  15848. GeometryTransformer$$1.call(this);
  15849. this._snapTolerance = snapTolerance || null;
  15850. this._snapPts = snapPts || null;
  15851. this._isSelfSnap = (isSelfSnap !== undefined) ? isSelfSnap : false;
  15852. }
  15853. if ( GeometryTransformer$$1 ) SnapTransformer.__proto__ = GeometryTransformer$$1;
  15854. SnapTransformer.prototype = Object.create( GeometryTransformer$$1 && GeometryTransformer$$1.prototype );
  15855. SnapTransformer.prototype.constructor = SnapTransformer;
  15856. SnapTransformer.prototype.snapLine = function snapLine (srcPts, snapPts) {
  15857. var snapper = new LineStringSnapper(srcPts, this._snapTolerance);
  15858. snapper.setAllowSnappingToSourceVertices(this._isSelfSnap);
  15859. return snapper.snapTo(snapPts)
  15860. };
  15861. SnapTransformer.prototype.transformCoordinates = function transformCoordinates (coords, parent) {
  15862. var srcPts = coords.toCoordinateArray();
  15863. var newPts = this.snapLine(srcPts, this._snapPts);
  15864. return this._factory.getCoordinateSequenceFactory().create(newPts)
  15865. };
  15866. SnapTransformer.prototype.interfaces_ = function interfaces_ () {
  15867. return []
  15868. };
  15869. SnapTransformer.prototype.getClass = function getClass () {
  15870. return SnapTransformer
  15871. };
  15872. return SnapTransformer;
  15873. }(GeometryTransformer));
  15874. var CommonBits = function CommonBits () {
  15875. this._isFirst = true;
  15876. this._commonMantissaBitsCount = 53;
  15877. this._commonBits = 0;
  15878. this._commonSignExp = null;
  15879. };
  15880. CommonBits.prototype.getCommon = function getCommon () {
  15881. return Double.longBitsToDouble(this._commonBits)
  15882. };
  15883. CommonBits.prototype.add = function add (num) {
  15884. var numBits = Double.doubleToLongBits(num);
  15885. if (this._isFirst) {
  15886. this._commonBits = numBits;
  15887. this._commonSignExp = CommonBits.signExpBits(this._commonBits);
  15888. this._isFirst = false;
  15889. return null
  15890. }
  15891. var numSignExp = CommonBits.signExpBits(numBits);
  15892. if (numSignExp !== this._commonSignExp) {
  15893. this._commonBits = 0;
  15894. return null
  15895. }
  15896. this._commonMantissaBitsCount = CommonBits.numCommonMostSigMantissaBits(this._commonBits, numBits);
  15897. this._commonBits = CommonBits.zeroLowerBits(this._commonBits, 64 - (12 + this._commonMantissaBitsCount));
  15898. };
  15899. CommonBits.prototype.toString = function toString () {
  15900. if (arguments.length === 1) {
  15901. var bits = arguments[0];
  15902. var x = Double.longBitsToDouble(bits);
  15903. var numStr = Double.toBinaryString(bits);
  15904. var padStr = '0000000000000000000000000000000000000000000000000000000000000000' + numStr;
  15905. var bitStr = padStr.substring(padStr.length - 64);
  15906. var str = bitStr.substring(0, 1) + ' ' + bitStr.substring(1, 12) + '(exp) ' + bitStr.substring(12) + ' [ ' + x + ' ]';
  15907. return str
  15908. }
  15909. };
  15910. CommonBits.prototype.interfaces_ = function interfaces_ () {
  15911. return []
  15912. };
  15913. CommonBits.prototype.getClass = function getClass () {
  15914. return CommonBits
  15915. };
  15916. CommonBits.getBit = function getBit (bits, i) {
  15917. var mask = 1 << i;
  15918. return (bits & mask) !== 0 ? 1 : 0
  15919. };
  15920. CommonBits.signExpBits = function signExpBits (num) {
  15921. return num >> 52
  15922. };
  15923. CommonBits.zeroLowerBits = function zeroLowerBits (bits, nBits) {
  15924. var invMask = (1 << nBits) - 1;
  15925. var mask = ~invMask;
  15926. var zeroed = bits & mask;
  15927. return zeroed
  15928. };
  15929. CommonBits.numCommonMostSigMantissaBits = function numCommonMostSigMantissaBits (num1, num2) {
  15930. var count = 0;
  15931. for (var i = 52; i >= 0; i--) {
  15932. if (CommonBits.getBit(num1, i) !== CommonBits.getBit(num2, i)) { return count }
  15933. count++;
  15934. }
  15935. return 52
  15936. };
  15937. var CommonBitsRemover = function CommonBitsRemover () {
  15938. this._commonCoord = null;
  15939. this._ccFilter = new CommonCoordinateFilter();
  15940. };
  15941. var staticAccessors$42 = { CommonCoordinateFilter: { configurable: true },Translater: { configurable: true } };
  15942. CommonBitsRemover.prototype.addCommonBits = function addCommonBits (geom) {
  15943. var trans = new Translater(this._commonCoord);
  15944. geom.apply(trans);
  15945. geom.geometryChanged();
  15946. };
  15947. CommonBitsRemover.prototype.removeCommonBits = function removeCommonBits (geom) {
  15948. if (this._commonCoord.x === 0.0 && this._commonCoord.y === 0.0) { return geom }
  15949. var invCoord = new Coordinate(this._commonCoord);
  15950. invCoord.x = -invCoord.x;
  15951. invCoord.y = -invCoord.y;
  15952. var trans = new Translater(invCoord);
  15953. geom.apply(trans);
  15954. geom.geometryChanged();
  15955. return geom
  15956. };
  15957. CommonBitsRemover.prototype.getCommonCoordinate = function getCommonCoordinate () {
  15958. return this._commonCoord
  15959. };
  15960. CommonBitsRemover.prototype.add = function add (geom) {
  15961. geom.apply(this._ccFilter);
  15962. this._commonCoord = this._ccFilter.getCommonCoordinate();
  15963. };
  15964. CommonBitsRemover.prototype.interfaces_ = function interfaces_ () {
  15965. return []
  15966. };
  15967. CommonBitsRemover.prototype.getClass = function getClass () {
  15968. return CommonBitsRemover
  15969. };
  15970. staticAccessors$42.CommonCoordinateFilter.get = function () { return CommonCoordinateFilter };
  15971. staticAccessors$42.Translater.get = function () { return Translater };
  15972. Object.defineProperties( CommonBitsRemover, staticAccessors$42 );
  15973. var CommonCoordinateFilter = function CommonCoordinateFilter () {
  15974. this._commonBitsX = new CommonBits();
  15975. this._commonBitsY = new CommonBits();
  15976. };
  15977. CommonCoordinateFilter.prototype.filter = function filter (coord) {
  15978. this._commonBitsX.add(coord.x);
  15979. this._commonBitsY.add(coord.y);
  15980. };
  15981. CommonCoordinateFilter.prototype.getCommonCoordinate = function getCommonCoordinate () {
  15982. return new Coordinate(this._commonBitsX.getCommon(), this._commonBitsY.getCommon())
  15983. };
  15984. CommonCoordinateFilter.prototype.interfaces_ = function interfaces_ () {
  15985. return [CoordinateFilter]
  15986. };
  15987. CommonCoordinateFilter.prototype.getClass = function getClass () {
  15988. return CommonCoordinateFilter
  15989. };
  15990. var Translater = function Translater () {
  15991. this.trans = null;
  15992. var trans = arguments[0];
  15993. this.trans = trans;
  15994. };
  15995. Translater.prototype.filter = function filter (seq, i) {
  15996. var xp = seq.getOrdinate(i, 0) + this.trans.x;
  15997. var yp = seq.getOrdinate(i, 1) + this.trans.y;
  15998. seq.setOrdinate(i, 0, xp);
  15999. seq.setOrdinate(i, 1, yp);
  16000. };
  16001. Translater.prototype.isDone = function isDone () {
  16002. return false
  16003. };
  16004. Translater.prototype.isGeometryChanged = function isGeometryChanged () {
  16005. return true
  16006. };
  16007. Translater.prototype.interfaces_ = function interfaces_ () {
  16008. return [CoordinateSequenceFilter]
  16009. };
  16010. Translater.prototype.getClass = function getClass () {
  16011. return Translater
  16012. };
  16013. var SnapOverlayOp = function SnapOverlayOp (g1, g2) {
  16014. this._geom = new Array(2).fill(null);
  16015. this._snapTolerance = null;
  16016. this._cbr = null;
  16017. this._geom[0] = g1;
  16018. this._geom[1] = g2;
  16019. this.computeSnapTolerance();
  16020. };
  16021. SnapOverlayOp.prototype.selfSnap = function selfSnap (geom) {
  16022. var snapper0 = new GeometrySnapper(geom);
  16023. var snapGeom = snapper0.snapTo(geom, this._snapTolerance);
  16024. return snapGeom
  16025. };
  16026. SnapOverlayOp.prototype.removeCommonBits = function removeCommonBits (geom) {
  16027. this._cbr = new CommonBitsRemover();
  16028. this._cbr.add(geom[0]);
  16029. this._cbr.add(geom[1]);
  16030. var remGeom = new Array(2).fill(null);
  16031. remGeom[0] = this._cbr.removeCommonBits(geom[0].copy());
  16032. remGeom[1] = this._cbr.removeCommonBits(geom[1].copy());
  16033. return remGeom
  16034. };
  16035. SnapOverlayOp.prototype.prepareResult = function prepareResult (geom) {
  16036. this._cbr.addCommonBits(geom);
  16037. return geom
  16038. };
  16039. SnapOverlayOp.prototype.getResultGeometry = function getResultGeometry (opCode) {
  16040. var prepGeom = this.snap(this._geom);
  16041. var result = OverlayOp.overlayOp(prepGeom[0], prepGeom[1], opCode);
  16042. return this.prepareResult(result)
  16043. };
  16044. SnapOverlayOp.prototype.checkValid = function checkValid (g) {
  16045. if (!g.isValid()) {
  16046. System.out.println('Snapped geometry is invalid');
  16047. }
  16048. };
  16049. SnapOverlayOp.prototype.computeSnapTolerance = function computeSnapTolerance () {
  16050. this._snapTolerance = GeometrySnapper.computeOverlaySnapTolerance(this._geom[0], this._geom[1]);
  16051. };
  16052. SnapOverlayOp.prototype.snap = function snap (geom) {
  16053. var remGeom = this.removeCommonBits(geom);
  16054. var snapGeom = GeometrySnapper.snap(remGeom[0], remGeom[1], this._snapTolerance);
  16055. return snapGeom
  16056. };
  16057. SnapOverlayOp.prototype.interfaces_ = function interfaces_ () {
  16058. return []
  16059. };
  16060. SnapOverlayOp.prototype.getClass = function getClass () {
  16061. return SnapOverlayOp
  16062. };
  16063. SnapOverlayOp.overlayOp = function overlayOp (g0, g1, opCode) {
  16064. var op = new SnapOverlayOp(g0, g1);
  16065. return op.getResultGeometry(opCode)
  16066. };
  16067. SnapOverlayOp.union = function union (g0, g1) {
  16068. return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.UNION)
  16069. };
  16070. SnapOverlayOp.intersection = function intersection (g0, g1) {
  16071. return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.INTERSECTION)
  16072. };
  16073. SnapOverlayOp.symDifference = function symDifference (g0, g1) {
  16074. return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.SYMDIFFERENCE)
  16075. };
  16076. SnapOverlayOp.difference = function difference (g0, g1) {
  16077. return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.DIFFERENCE)
  16078. };
  16079. var SnapIfNeededOverlayOp = function SnapIfNeededOverlayOp (g1, g2) {
  16080. this._geom = new Array(2).fill(null);
  16081. this._geom[0] = g1;
  16082. this._geom[1] = g2;
  16083. };
  16084. SnapIfNeededOverlayOp.prototype.getResultGeometry = function getResultGeometry (opCode) {
  16085. var result = null;
  16086. var isSuccess = false;
  16087. var savedException = null;
  16088. try {
  16089. result = OverlayOp.overlayOp(this._geom[0], this._geom[1], opCode);
  16090. var isValid = true;
  16091. if (isValid) { isSuccess = true; }
  16092. } catch (ex) {
  16093. if (ex instanceof RuntimeException) {
  16094. savedException = ex;
  16095. } else { throw ex }
  16096. } finally {}
  16097. if (!isSuccess) {
  16098. try {
  16099. result = SnapOverlayOp.overlayOp(this._geom[0], this._geom[1], opCode);
  16100. } catch (ex) {
  16101. if (ex instanceof RuntimeException) {
  16102. throw savedException
  16103. } else { throw ex }
  16104. } finally {}
  16105. }
  16106. return result
  16107. };
  16108. SnapIfNeededOverlayOp.prototype.interfaces_ = function interfaces_ () {
  16109. return []
  16110. };
  16111. SnapIfNeededOverlayOp.prototype.getClass = function getClass () {
  16112. return SnapIfNeededOverlayOp
  16113. };
  16114. SnapIfNeededOverlayOp.overlayOp = function overlayOp (g0, g1, opCode) {
  16115. var op = new SnapIfNeededOverlayOp(g0, g1);
  16116. return op.getResultGeometry(opCode)
  16117. };
  16118. SnapIfNeededOverlayOp.union = function union (g0, g1) {
  16119. return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.UNION)
  16120. };
  16121. SnapIfNeededOverlayOp.intersection = function intersection (g0, g1) {
  16122. return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.INTERSECTION)
  16123. };
  16124. SnapIfNeededOverlayOp.symDifference = function symDifference (g0, g1) {
  16125. return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.SYMDIFFERENCE)
  16126. };
  16127. SnapIfNeededOverlayOp.difference = function difference (g0, g1) {
  16128. return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.DIFFERENCE)
  16129. };
  16130. var MonotoneChain$2 = function MonotoneChain () {
  16131. this.mce = null;
  16132. this.chainIndex = null;
  16133. var mce = arguments[0];
  16134. var chainIndex = arguments[1];
  16135. this.mce = mce;
  16136. this.chainIndex = chainIndex;
  16137. };
  16138. MonotoneChain$2.prototype.computeIntersections = function computeIntersections (mc, si) {
  16139. this.mce.computeIntersectsForChain(this.chainIndex, mc.mce, mc.chainIndex, si);
  16140. };
  16141. MonotoneChain$2.prototype.interfaces_ = function interfaces_ () {
  16142. return []
  16143. };
  16144. MonotoneChain$2.prototype.getClass = function getClass () {
  16145. return MonotoneChain$2
  16146. };
  16147. var SweepLineEvent = function SweepLineEvent () {
  16148. this._label = null;
  16149. this._xValue = null;
  16150. this._eventType = null;
  16151. this._insertEvent = null;
  16152. this._deleteEventIndex = null;
  16153. this._obj = null;
  16154. if (arguments.length === 2) {
  16155. var x = arguments[0];
  16156. var insertEvent = arguments[1];
  16157. this._eventType = SweepLineEvent.DELETE;
  16158. this._xValue = x;
  16159. this._insertEvent = insertEvent;
  16160. } else if (arguments.length === 3) {
  16161. var label = arguments[0];
  16162. var x$1 = arguments[1];
  16163. var obj = arguments[2];
  16164. this._eventType = SweepLineEvent.INSERT;
  16165. this._label = label;
  16166. this._xValue = x$1;
  16167. this._obj = obj;
  16168. }
  16169. };
  16170. var staticAccessors$43 = { INSERT: { configurable: true },DELETE: { configurable: true } };
  16171. SweepLineEvent.prototype.isDelete = function isDelete () {
  16172. return this._eventType === SweepLineEvent.DELETE
  16173. };
  16174. SweepLineEvent.prototype.setDeleteEventIndex = function setDeleteEventIndex (deleteEventIndex) {
  16175. this._deleteEventIndex = deleteEventIndex;
  16176. };
  16177. SweepLineEvent.prototype.getObject = function getObject () {
  16178. return this._obj
  16179. };
  16180. SweepLineEvent.prototype.compareTo = function compareTo (o) {
  16181. var pe = o;
  16182. if (this._xValue < pe._xValue) { return -1 }
  16183. if (this._xValue > pe._xValue) { return 1 }
  16184. if (this._eventType < pe._eventType) { return -1 }
  16185. if (this._eventType > pe._eventType) { return 1 }
  16186. return 0
  16187. };
  16188. SweepLineEvent.prototype.getInsertEvent = function getInsertEvent () {
  16189. return this._insertEvent
  16190. };
  16191. SweepLineEvent.prototype.isInsert = function isInsert () {
  16192. return this._eventType === SweepLineEvent.INSERT
  16193. };
  16194. SweepLineEvent.prototype.isSameLabel = function isSameLabel (ev) {
  16195. if (this._label === null) { return false }
  16196. return this._label === ev._label
  16197. };
  16198. SweepLineEvent.prototype.getDeleteEventIndex = function getDeleteEventIndex () {
  16199. return this._deleteEventIndex
  16200. };
  16201. SweepLineEvent.prototype.interfaces_ = function interfaces_ () {
  16202. return [Comparable]
  16203. };
  16204. SweepLineEvent.prototype.getClass = function getClass () {
  16205. return SweepLineEvent
  16206. };
  16207. staticAccessors$43.INSERT.get = function () { return 1 };
  16208. staticAccessors$43.DELETE.get = function () { return 2 };
  16209. Object.defineProperties( SweepLineEvent, staticAccessors$43 );
  16210. var EdgeSetIntersector = function EdgeSetIntersector () {};
  16211. EdgeSetIntersector.prototype.interfaces_ = function interfaces_ () {
  16212. return []
  16213. };
  16214. EdgeSetIntersector.prototype.getClass = function getClass () {
  16215. return EdgeSetIntersector
  16216. };
  16217. var SegmentIntersector$2 = function SegmentIntersector () {
  16218. this._hasIntersection = false;
  16219. this._hasProper = false;
  16220. this._hasProperInterior = false;
  16221. this._properIntersectionPoint = null;
  16222. this._li = null;
  16223. this._includeProper = null;
  16224. this._recordIsolated = null;
  16225. this._isSelfIntersection = null;
  16226. this._numIntersections = 0;
  16227. this.numTests = 0;
  16228. this._bdyNodes = null;
  16229. this._isDone = false;
  16230. this._isDoneWhenProperInt = false;
  16231. var li = arguments[0];
  16232. var includeProper = arguments[1];
  16233. var recordIsolated = arguments[2];
  16234. this._li = li;
  16235. this._includeProper = includeProper;
  16236. this._recordIsolated = recordIsolated;
  16237. };
  16238. SegmentIntersector$2.prototype.isTrivialIntersection = function isTrivialIntersection (e0, segIndex0, e1, segIndex1) {
  16239. if (e0 === e1) {
  16240. if (this._li.getIntersectionNum() === 1) {
  16241. if (SegmentIntersector$2.isAdjacentSegments(segIndex0, segIndex1)) { return true }
  16242. if (e0.isClosed()) {
  16243. var maxSegIndex = e0.getNumPoints() - 1;
  16244. if ((segIndex0 === 0 && segIndex1 === maxSegIndex) ||
  16245. (segIndex1 === 0 && segIndex0 === maxSegIndex)) {
  16246. return true
  16247. }
  16248. }
  16249. }
  16250. }
  16251. return false
  16252. };
  16253. SegmentIntersector$2.prototype.getProperIntersectionPoint = function getProperIntersectionPoint () {
  16254. return this._properIntersectionPoint
  16255. };
  16256. SegmentIntersector$2.prototype.setIsDoneIfProperInt = function setIsDoneIfProperInt (isDoneWhenProperInt) {
  16257. this._isDoneWhenProperInt = isDoneWhenProperInt;
  16258. };
  16259. SegmentIntersector$2.prototype.hasProperInteriorIntersection = function hasProperInteriorIntersection () {
  16260. return this._hasProperInterior
  16261. };
  16262. SegmentIntersector$2.prototype.isBoundaryPointInternal = function isBoundaryPointInternal (li, bdyNodes) {
  16263. for (var i = bdyNodes.iterator(); i.hasNext();) {
  16264. var node = i.next();
  16265. var pt = node.getCoordinate();
  16266. if (li.isIntersection(pt)) { return true }
  16267. }
  16268. return false
  16269. };
  16270. SegmentIntersector$2.prototype.hasProperIntersection = function hasProperIntersection () {
  16271. return this._hasProper
  16272. };
  16273. SegmentIntersector$2.prototype.hasIntersection = function hasIntersection () {
  16274. return this._hasIntersection
  16275. };
  16276. SegmentIntersector$2.prototype.isDone = function isDone () {
  16277. return this._isDone
  16278. };
  16279. SegmentIntersector$2.prototype.isBoundaryPoint = function isBoundaryPoint (li, bdyNodes) {
  16280. if (bdyNodes === null) { return false }
  16281. if (this.isBoundaryPointInternal(li, bdyNodes[0])) { return true }
  16282. if (this.isBoundaryPointInternal(li, bdyNodes[1])) { return true }
  16283. return false
  16284. };
  16285. SegmentIntersector$2.prototype.setBoundaryNodes = function setBoundaryNodes (bdyNodes0, bdyNodes1) {
  16286. this._bdyNodes = new Array(2).fill(null);
  16287. this._bdyNodes[0] = bdyNodes0;
  16288. this._bdyNodes[1] = bdyNodes1;
  16289. };
  16290. SegmentIntersector$2.prototype.addIntersections = function addIntersections (e0, segIndex0, e1, segIndex1) {
  16291. if (e0 === e1 && segIndex0 === segIndex1) { return null }
  16292. this.numTests++;
  16293. var p00 = e0.getCoordinates()[segIndex0];
  16294. var p01 = e0.getCoordinates()[segIndex0 + 1];
  16295. var p10 = e1.getCoordinates()[segIndex1];
  16296. var p11 = e1.getCoordinates()[segIndex1 + 1];
  16297. this._li.computeIntersection(p00, p01, p10, p11);
  16298. if (this._li.hasIntersection()) {
  16299. if (this._recordIsolated) {
  16300. e0.setIsolated(false);
  16301. e1.setIsolated(false);
  16302. }
  16303. this._numIntersections++;
  16304. if (!this.isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {
  16305. this._hasIntersection = true;
  16306. if (this._includeProper || !this._li.isProper()) {
  16307. e0.addIntersections(this._li, segIndex0, 0);
  16308. e1.addIntersections(this._li, segIndex1, 1);
  16309. }
  16310. if (this._li.isProper()) {
  16311. this._properIntersectionPoint = this._li.getIntersection(0).copy();
  16312. this._hasProper = true;
  16313. if (this._isDoneWhenProperInt) {
  16314. this._isDone = true;
  16315. }
  16316. if (!this.isBoundaryPoint(this._li, this._bdyNodes)) { this._hasProperInterior = true; }
  16317. }
  16318. }
  16319. }
  16320. };
  16321. SegmentIntersector$2.prototype.interfaces_ = function interfaces_ () {
  16322. return []
  16323. };
  16324. SegmentIntersector$2.prototype.getClass = function getClass () {
  16325. return SegmentIntersector$2
  16326. };
  16327. SegmentIntersector$2.isAdjacentSegments = function isAdjacentSegments (i1, i2) {
  16328. return Math.abs(i1 - i2) === 1
  16329. };
  16330. var SimpleMCSweepLineIntersector = (function (EdgeSetIntersector$$1) {
  16331. function SimpleMCSweepLineIntersector () {
  16332. EdgeSetIntersector$$1.call(this);
  16333. this.events = new ArrayList();
  16334. this.nOverlaps = null;
  16335. }
  16336. if ( EdgeSetIntersector$$1 ) SimpleMCSweepLineIntersector.__proto__ = EdgeSetIntersector$$1;
  16337. SimpleMCSweepLineIntersector.prototype = Object.create( EdgeSetIntersector$$1 && EdgeSetIntersector$$1.prototype );
  16338. SimpleMCSweepLineIntersector.prototype.constructor = SimpleMCSweepLineIntersector;
  16339. SimpleMCSweepLineIntersector.prototype.prepareEvents = function prepareEvents () {
  16340. var this$1 = this;
  16341. Collections.sort(this.events);
  16342. for (var i = 0; i < this.events.size(); i++) {
  16343. var ev = this$1.events.get(i);
  16344. if (ev.isDelete()) {
  16345. ev.getInsertEvent().setDeleteEventIndex(i);
  16346. }
  16347. }
  16348. };
  16349. SimpleMCSweepLineIntersector.prototype.computeIntersections = function computeIntersections () {
  16350. var this$1 = this;
  16351. if (arguments.length === 1) {
  16352. var si = arguments[0];
  16353. this.nOverlaps = 0;
  16354. this.prepareEvents();
  16355. for (var i = 0; i < this.events.size(); i++) {
  16356. var ev = this$1.events.get(i);
  16357. if (ev.isInsert()) {
  16358. this$1.processOverlaps(i, ev.getDeleteEventIndex(), ev, si);
  16359. }
  16360. if (si.isDone()) {
  16361. break
  16362. }
  16363. }
  16364. } else if (arguments.length === 3) {
  16365. if (arguments[2] instanceof SegmentIntersector$2 && (hasInterface(arguments[0], List) && hasInterface(arguments[1], List))) {
  16366. var edges0 = arguments[0];
  16367. var edges1 = arguments[1];
  16368. var si$1 = arguments[2];
  16369. this.addEdges(edges0, edges0);
  16370. this.addEdges(edges1, edges1);
  16371. this.computeIntersections(si$1);
  16372. } else if (typeof arguments[2] === 'boolean' && (hasInterface(arguments[0], List) && arguments[1] instanceof SegmentIntersector$2)) {
  16373. var edges = arguments[0];
  16374. var si$2 = arguments[1];
  16375. var testAllSegments = arguments[2];
  16376. if (testAllSegments) { this.addEdges(edges, null); } else { this.addEdges(edges); }
  16377. this.computeIntersections(si$2);
  16378. }
  16379. }
  16380. };
  16381. SimpleMCSweepLineIntersector.prototype.addEdge = function addEdge (edge, edgeSet) {
  16382. var this$1 = this;
  16383. var mce = edge.getMonotoneChainEdge();
  16384. var startIndex = mce.getStartIndexes();
  16385. for (var i = 0; i < startIndex.length - 1; i++) {
  16386. var mc = new MonotoneChain$2(mce, i);
  16387. var insertEvent = new SweepLineEvent(edgeSet, mce.getMinX(i), mc);
  16388. this$1.events.add(insertEvent);
  16389. this$1.events.add(new SweepLineEvent(mce.getMaxX(i), insertEvent));
  16390. }
  16391. };
  16392. SimpleMCSweepLineIntersector.prototype.processOverlaps = function processOverlaps (start, end, ev0, si) {
  16393. var this$1 = this;
  16394. var mc0 = ev0.getObject();
  16395. for (var i = start; i < end; i++) {
  16396. var ev1 = this$1.events.get(i);
  16397. if (ev1.isInsert()) {
  16398. var mc1 = ev1.getObject();
  16399. if (!ev0.isSameLabel(ev1)) {
  16400. mc0.computeIntersections(mc1, si);
  16401. this$1.nOverlaps++;
  16402. }
  16403. }
  16404. }
  16405. };
  16406. SimpleMCSweepLineIntersector.prototype.addEdges = function addEdges () {
  16407. var this$1 = this;
  16408. if (arguments.length === 1) {
  16409. var edges = arguments[0];
  16410. for (var i = edges.iterator(); i.hasNext();) {
  16411. var edge = i.next();
  16412. this$1.addEdge(edge, edge);
  16413. }
  16414. } else if (arguments.length === 2) {
  16415. var edges$1 = arguments[0];
  16416. var edgeSet = arguments[1];
  16417. for (var i$1 = edges$1.iterator(); i$1.hasNext();) {
  16418. var edge$1 = i$1.next();
  16419. this$1.addEdge(edge$1, edgeSet);
  16420. }
  16421. }
  16422. };
  16423. SimpleMCSweepLineIntersector.prototype.interfaces_ = function interfaces_ () {
  16424. return []
  16425. };
  16426. SimpleMCSweepLineIntersector.prototype.getClass = function getClass () {
  16427. return SimpleMCSweepLineIntersector
  16428. };
  16429. return SimpleMCSweepLineIntersector;
  16430. }(EdgeSetIntersector));
  16431. var IntervalRTreeNode = function IntervalRTreeNode () {
  16432. this._min = Double.POSITIVE_INFINITY;
  16433. this._max = Double.NEGATIVE_INFINITY;
  16434. };
  16435. var staticAccessors$45 = { NodeComparator: { configurable: true } };
  16436. IntervalRTreeNode.prototype.getMin = function getMin () {
  16437. return this._min
  16438. };
  16439. IntervalRTreeNode.prototype.intersects = function intersects (queryMin, queryMax) {
  16440. if (this._min > queryMax || this._max < queryMin) { return false }
  16441. return true
  16442. };
  16443. IntervalRTreeNode.prototype.getMax = function getMax () {
  16444. return this._max
  16445. };
  16446. IntervalRTreeNode.prototype.toString = function toString () {
  16447. return WKTWriter.toLineString(new Coordinate(this._min, 0), new Coordinate(this._max, 0))
  16448. };
  16449. IntervalRTreeNode.prototype.interfaces_ = function interfaces_ () {
  16450. return []
  16451. };
  16452. IntervalRTreeNode.prototype.getClass = function getClass () {
  16453. return IntervalRTreeNode
  16454. };
  16455. staticAccessors$45.NodeComparator.get = function () { return NodeComparator };
  16456. Object.defineProperties( IntervalRTreeNode, staticAccessors$45 );
  16457. var NodeComparator = function NodeComparator () {};
  16458. NodeComparator.prototype.compare = function compare (o1, o2) {
  16459. var n1 = o1;
  16460. var n2 = o2;
  16461. var mid1 = (n1._min + n1._max) / 2;
  16462. var mid2 = (n2._min + n2._max) / 2;
  16463. if (mid1 < mid2) { return -1 }
  16464. if (mid1 > mid2) { return 1 }
  16465. return 0
  16466. };
  16467. NodeComparator.prototype.interfaces_ = function interfaces_ () {
  16468. return [Comparator]
  16469. };
  16470. NodeComparator.prototype.getClass = function getClass () {
  16471. return NodeComparator
  16472. };
  16473. var IntervalRTreeLeafNode = (function (IntervalRTreeNode$$1) {
  16474. function IntervalRTreeLeafNode () {
  16475. IntervalRTreeNode$$1.call(this);
  16476. this._item = null;
  16477. var min = arguments[0];
  16478. var max = arguments[1];
  16479. var item = arguments[2];
  16480. this._min = min;
  16481. this._max = max;
  16482. this._item = item;
  16483. }
  16484. if ( IntervalRTreeNode$$1 ) IntervalRTreeLeafNode.__proto__ = IntervalRTreeNode$$1;
  16485. IntervalRTreeLeafNode.prototype = Object.create( IntervalRTreeNode$$1 && IntervalRTreeNode$$1.prototype );
  16486. IntervalRTreeLeafNode.prototype.constructor = IntervalRTreeLeafNode;
  16487. IntervalRTreeLeafNode.prototype.query = function query (queryMin, queryMax, visitor) {
  16488. if (!this.intersects(queryMin, queryMax)) { return null }
  16489. visitor.visitItem(this._item);
  16490. };
  16491. IntervalRTreeLeafNode.prototype.interfaces_ = function interfaces_ () {
  16492. return []
  16493. };
  16494. IntervalRTreeLeafNode.prototype.getClass = function getClass () {
  16495. return IntervalRTreeLeafNode
  16496. };
  16497. return IntervalRTreeLeafNode;
  16498. }(IntervalRTreeNode));
  16499. var IntervalRTreeBranchNode = (function (IntervalRTreeNode$$1) {
  16500. function IntervalRTreeBranchNode () {
  16501. IntervalRTreeNode$$1.call(this);
  16502. this._node1 = null;
  16503. this._node2 = null;
  16504. var n1 = arguments[0];
  16505. var n2 = arguments[1];
  16506. this._node1 = n1;
  16507. this._node2 = n2;
  16508. this.buildExtent(this._node1, this._node2);
  16509. }
  16510. if ( IntervalRTreeNode$$1 ) IntervalRTreeBranchNode.__proto__ = IntervalRTreeNode$$1;
  16511. IntervalRTreeBranchNode.prototype = Object.create( IntervalRTreeNode$$1 && IntervalRTreeNode$$1.prototype );
  16512. IntervalRTreeBranchNode.prototype.constructor = IntervalRTreeBranchNode;
  16513. IntervalRTreeBranchNode.prototype.buildExtent = function buildExtent (n1, n2) {
  16514. this._min = Math.min(n1._min, n2._min);
  16515. this._max = Math.max(n1._max, n2._max);
  16516. };
  16517. IntervalRTreeBranchNode.prototype.query = function query (queryMin, queryMax, visitor) {
  16518. if (!this.intersects(queryMin, queryMax)) {
  16519. return null
  16520. }
  16521. if (this._node1 !== null) { this._node1.query(queryMin, queryMax, visitor); }
  16522. if (this._node2 !== null) { this._node2.query(queryMin, queryMax, visitor); }
  16523. };
  16524. IntervalRTreeBranchNode.prototype.interfaces_ = function interfaces_ () {
  16525. return []
  16526. };
  16527. IntervalRTreeBranchNode.prototype.getClass = function getClass () {
  16528. return IntervalRTreeBranchNode
  16529. };
  16530. return IntervalRTreeBranchNode;
  16531. }(IntervalRTreeNode));
  16532. var SortedPackedIntervalRTree = function SortedPackedIntervalRTree () {
  16533. this._leaves = new ArrayList();
  16534. this._root = null;
  16535. this._level = 0;
  16536. };
  16537. SortedPackedIntervalRTree.prototype.buildTree = function buildTree () {
  16538. var this$1 = this;
  16539. Collections.sort(this._leaves, new IntervalRTreeNode.NodeComparator());
  16540. var src = this._leaves;
  16541. var temp = null;
  16542. var dest = new ArrayList();
  16543. while (true) {
  16544. this$1.buildLevel(src, dest);
  16545. if (dest.size() === 1) { return dest.get(0) }
  16546. temp = src;
  16547. src = dest;
  16548. dest = temp;
  16549. }
  16550. };
  16551. SortedPackedIntervalRTree.prototype.insert = function insert (min, max, item) {
  16552. if (this._root !== null) { throw new Error('Index cannot be added to once it has been queried') }
  16553. this._leaves.add(new IntervalRTreeLeafNode(min, max, item));
  16554. };
  16555. SortedPackedIntervalRTree.prototype.query = function query (min, max, visitor) {
  16556. this.init();
  16557. this._root.query(min, max, visitor);
  16558. };
  16559. SortedPackedIntervalRTree.prototype.buildRoot = function buildRoot () {
  16560. if (this._root !== null) { return null }
  16561. this._root = this.buildTree();
  16562. };
  16563. SortedPackedIntervalRTree.prototype.printNode = function printNode (node) {
  16564. System.out.println(WKTWriter.toLineString(new Coordinate(node._min, this._level), new Coordinate(node._max, this._level)));
  16565. };
  16566. SortedPackedIntervalRTree.prototype.init = function init () {
  16567. if (this._root !== null) { return null }
  16568. this.buildRoot();
  16569. };
  16570. SortedPackedIntervalRTree.prototype.buildLevel = function buildLevel (src, dest) {
  16571. this._level++;
  16572. dest.clear();
  16573. for (var i = 0; i < src.size(); i += 2) {
  16574. var n1 = src.get(i);
  16575. var n2 = i + 1 < src.size() ? src.get(i) : null;
  16576. if (n2 === null) {
  16577. dest.add(n1);
  16578. } else {
  16579. var node = new IntervalRTreeBranchNode(src.get(i), src.get(i + 1));
  16580. dest.add(node);
  16581. }
  16582. }
  16583. };
  16584. SortedPackedIntervalRTree.prototype.interfaces_ = function interfaces_ () {
  16585. return []
  16586. };
  16587. SortedPackedIntervalRTree.prototype.getClass = function getClass () {
  16588. return SortedPackedIntervalRTree
  16589. };
  16590. var ArrayListVisitor = function ArrayListVisitor () {
  16591. this._items = new ArrayList();
  16592. };
  16593. ArrayListVisitor.prototype.visitItem = function visitItem (item) {
  16594. this._items.add(item);
  16595. };
  16596. ArrayListVisitor.prototype.getItems = function getItems () {
  16597. return this._items
  16598. };
  16599. ArrayListVisitor.prototype.interfaces_ = function interfaces_ () {
  16600. return [ItemVisitor]
  16601. };
  16602. ArrayListVisitor.prototype.getClass = function getClass () {
  16603. return ArrayListVisitor
  16604. };
  16605. var IndexedPointInAreaLocator = function IndexedPointInAreaLocator () {
  16606. this._index = null;
  16607. var g = arguments[0];
  16608. if (!hasInterface(g, Polygonal)) { throw new IllegalArgumentException('Argument must be Polygonal') }
  16609. this._index = new IntervalIndexedGeometry(g);
  16610. };
  16611. var staticAccessors$44 = { SegmentVisitor: { configurable: true },IntervalIndexedGeometry: { configurable: true } };
  16612. IndexedPointInAreaLocator.prototype.locate = function locate (p) {
  16613. var rcc = new RayCrossingCounter(p);
  16614. var visitor = new SegmentVisitor(rcc);
  16615. this._index.query(p.y, p.y, visitor);
  16616. return rcc.getLocation()
  16617. };
  16618. IndexedPointInAreaLocator.prototype.interfaces_ = function interfaces_ () {
  16619. return [PointOnGeometryLocator]
  16620. };
  16621. IndexedPointInAreaLocator.prototype.getClass = function getClass () {
  16622. return IndexedPointInAreaLocator
  16623. };
  16624. staticAccessors$44.SegmentVisitor.get = function () { return SegmentVisitor };
  16625. staticAccessors$44.IntervalIndexedGeometry.get = function () { return IntervalIndexedGeometry };
  16626. Object.defineProperties( IndexedPointInAreaLocator, staticAccessors$44 );
  16627. var SegmentVisitor = function SegmentVisitor () {
  16628. this._counter = null;
  16629. var counter = arguments[0];
  16630. this._counter = counter;
  16631. };
  16632. SegmentVisitor.prototype.visitItem = function visitItem (item) {
  16633. var seg = item;
  16634. this._counter.countSegment(seg.getCoordinate(0), seg.getCoordinate(1));
  16635. };
  16636. SegmentVisitor.prototype.interfaces_ = function interfaces_ () {
  16637. return [ItemVisitor]
  16638. };
  16639. SegmentVisitor.prototype.getClass = function getClass () {
  16640. return SegmentVisitor
  16641. };
  16642. var IntervalIndexedGeometry = function IntervalIndexedGeometry () {
  16643. this._index = new SortedPackedIntervalRTree();
  16644. var geom = arguments[0];
  16645. this.init(geom);
  16646. };
  16647. IntervalIndexedGeometry.prototype.init = function init (geom) {
  16648. var this$1 = this;
  16649. var lines = LinearComponentExtracter.getLines(geom);
  16650. for (var i = lines.iterator(); i.hasNext();) {
  16651. var line = i.next();
  16652. var pts = line.getCoordinates();
  16653. this$1.addLine(pts);
  16654. }
  16655. };
  16656. IntervalIndexedGeometry.prototype.addLine = function addLine (pts) {
  16657. var this$1 = this;
  16658. for (var i = 1; i < pts.length; i++) {
  16659. var seg = new LineSegment(pts[i - 1], pts[i]);
  16660. var min = Math.min(seg.p0.y, seg.p1.y);
  16661. var max = Math.max(seg.p0.y, seg.p1.y);
  16662. this$1._index.insert(min, max, seg);
  16663. }
  16664. };
  16665. IntervalIndexedGeometry.prototype.query = function query () {
  16666. if (arguments.length === 2) {
  16667. var min = arguments[0];
  16668. var max = arguments[1];
  16669. var visitor = new ArrayListVisitor();
  16670. this._index.query(min, max, visitor);
  16671. return visitor.getItems()
  16672. } else if (arguments.length === 3) {
  16673. var min$1 = arguments[0];
  16674. var max$1 = arguments[1];
  16675. var visitor$1 = arguments[2];
  16676. this._index.query(min$1, max$1, visitor$1);
  16677. }
  16678. };
  16679. IntervalIndexedGeometry.prototype.interfaces_ = function interfaces_ () {
  16680. return []
  16681. };
  16682. IntervalIndexedGeometry.prototype.getClass = function getClass () {
  16683. return IntervalIndexedGeometry
  16684. };
  16685. var GeometryGraph = (function (PlanarGraph$$1) {
  16686. function GeometryGraph () {
  16687. PlanarGraph$$1.call(this);
  16688. this._parentGeom = null;
  16689. this._lineEdgeMap = new HashMap();
  16690. this._boundaryNodeRule = null;
  16691. this._useBoundaryDeterminationRule = true;
  16692. this._argIndex = null;
  16693. this._boundaryNodes = null;
  16694. this._hasTooFewPoints = false;
  16695. this._invalidPoint = null;
  16696. this._areaPtLocator = null;
  16697. this._ptLocator = new PointLocator();
  16698. if (arguments.length === 2) {
  16699. var argIndex = arguments[0];
  16700. var parentGeom = arguments[1];
  16701. var boundaryNodeRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
  16702. this._argIndex = argIndex;
  16703. this._parentGeom = parentGeom;
  16704. this._boundaryNodeRule = boundaryNodeRule;
  16705. if (parentGeom !== null) {
  16706. this.add(parentGeom);
  16707. }
  16708. } else if (arguments.length === 3) {
  16709. var argIndex$1 = arguments[0];
  16710. var parentGeom$1 = arguments[1];
  16711. var boundaryNodeRule$1 = arguments[2];
  16712. this._argIndex = argIndex$1;
  16713. this._parentGeom = parentGeom$1;
  16714. this._boundaryNodeRule = boundaryNodeRule$1;
  16715. if (parentGeom$1 !== null) {
  16716. this.add(parentGeom$1);
  16717. }
  16718. }
  16719. }
  16720. if ( PlanarGraph$$1 ) GeometryGraph.__proto__ = PlanarGraph$$1;
  16721. GeometryGraph.prototype = Object.create( PlanarGraph$$1 && PlanarGraph$$1.prototype );
  16722. GeometryGraph.prototype.constructor = GeometryGraph;
  16723. GeometryGraph.prototype.insertBoundaryPoint = function insertBoundaryPoint (argIndex, coord) {
  16724. var n = this._nodes.addNode(coord);
  16725. var lbl = n.getLabel();
  16726. var boundaryCount = 1;
  16727. var loc = Location.NONE;
  16728. loc = lbl.getLocation(argIndex, Position.ON);
  16729. if (loc === Location.BOUNDARY) { boundaryCount++; }
  16730. var newLoc = GeometryGraph.determineBoundary(this._boundaryNodeRule, boundaryCount);
  16731. lbl.setLocation(argIndex, newLoc);
  16732. };
  16733. GeometryGraph.prototype.computeSelfNodes = function computeSelfNodes () {
  16734. if (arguments.length === 2) {
  16735. var li = arguments[0];
  16736. var computeRingSelfNodes = arguments[1];
  16737. return this.computeSelfNodes(li, computeRingSelfNodes, false)
  16738. } else if (arguments.length === 3) {
  16739. var li$1 = arguments[0];
  16740. var computeRingSelfNodes$1 = arguments[1];
  16741. var isDoneIfProperInt = arguments[2];
  16742. var si = new SegmentIntersector$2(li$1, true, false);
  16743. si.setIsDoneIfProperInt(isDoneIfProperInt);
  16744. var esi = this.createEdgeSetIntersector();
  16745. var isRings = this._parentGeom instanceof LinearRing || this._parentGeom instanceof Polygon || this._parentGeom instanceof MultiPolygon;
  16746. var computeAllSegments = computeRingSelfNodes$1 || !isRings;
  16747. esi.computeIntersections(this._edges, si, computeAllSegments);
  16748. this.addSelfIntersectionNodes(this._argIndex);
  16749. return si
  16750. }
  16751. };
  16752. GeometryGraph.prototype.computeSplitEdges = function computeSplitEdges (edgelist) {
  16753. for (var i = this._edges.iterator(); i.hasNext();) {
  16754. var e = i.next();
  16755. e.eiList.addSplitEdges(edgelist);
  16756. }
  16757. };
  16758. GeometryGraph.prototype.computeEdgeIntersections = function computeEdgeIntersections (g, li, includeProper) {
  16759. var si = new SegmentIntersector$2(li, includeProper, true);
  16760. si.setBoundaryNodes(this.getBoundaryNodes(), g.getBoundaryNodes());
  16761. var esi = this.createEdgeSetIntersector();
  16762. esi.computeIntersections(this._edges, g._edges, si);
  16763. return si
  16764. };
  16765. GeometryGraph.prototype.getGeometry = function getGeometry () {
  16766. return this._parentGeom
  16767. };
  16768. GeometryGraph.prototype.getBoundaryNodeRule = function getBoundaryNodeRule () {
  16769. return this._boundaryNodeRule
  16770. };
  16771. GeometryGraph.prototype.hasTooFewPoints = function hasTooFewPoints () {
  16772. return this._hasTooFewPoints
  16773. };
  16774. GeometryGraph.prototype.addPoint = function addPoint () {
  16775. if (arguments[0] instanceof Point) {
  16776. var p = arguments[0];
  16777. var coord = p.getCoordinate();
  16778. this.insertPoint(this._argIndex, coord, Location.INTERIOR);
  16779. } else if (arguments[0] instanceof Coordinate) {
  16780. var pt = arguments[0];
  16781. this.insertPoint(this._argIndex, pt, Location.INTERIOR);
  16782. }
  16783. };
  16784. GeometryGraph.prototype.addPolygon = function addPolygon (p) {
  16785. var this$1 = this;
  16786. this.addPolygonRing(p.getExteriorRing(), Location.EXTERIOR, Location.INTERIOR);
  16787. for (var i = 0; i < p.getNumInteriorRing(); i++) {
  16788. var hole = p.getInteriorRingN(i);
  16789. this$1.addPolygonRing(hole, Location.INTERIOR, Location.EXTERIOR);
  16790. }
  16791. };
  16792. GeometryGraph.prototype.addEdge = function addEdge (e) {
  16793. this.insertEdge(e);
  16794. var coord = e.getCoordinates();
  16795. this.insertPoint(this._argIndex, coord[0], Location.BOUNDARY);
  16796. this.insertPoint(this._argIndex, coord[coord.length - 1], Location.BOUNDARY);
  16797. };
  16798. GeometryGraph.prototype.addLineString = function addLineString (line) {
  16799. var coord = CoordinateArrays.removeRepeatedPoints(line.getCoordinates());
  16800. if (coord.length < 2) {
  16801. this._hasTooFewPoints = true;
  16802. this._invalidPoint = coord[0];
  16803. return null
  16804. }
  16805. var e = new Edge(coord, new Label(this._argIndex, Location.INTERIOR));
  16806. this._lineEdgeMap.put(line, e);
  16807. this.insertEdge(e);
  16808. Assert.isTrue(coord.length >= 2, 'found LineString with single point');
  16809. this.insertBoundaryPoint(this._argIndex, coord[0]);
  16810. this.insertBoundaryPoint(this._argIndex, coord[coord.length - 1]);
  16811. };
  16812. GeometryGraph.prototype.getInvalidPoint = function getInvalidPoint () {
  16813. return this._invalidPoint
  16814. };
  16815. GeometryGraph.prototype.getBoundaryPoints = function getBoundaryPoints () {
  16816. var coll = this.getBoundaryNodes();
  16817. var pts = new Array(coll.size()).fill(null);
  16818. var i = 0;
  16819. for (var it = coll.iterator(); it.hasNext();) {
  16820. var node = it.next();
  16821. pts[i++] = node.getCoordinate().copy();
  16822. }
  16823. return pts
  16824. };
  16825. GeometryGraph.prototype.getBoundaryNodes = function getBoundaryNodes () {
  16826. if (this._boundaryNodes === null) { this._boundaryNodes = this._nodes.getBoundaryNodes(this._argIndex); }
  16827. return this._boundaryNodes
  16828. };
  16829. GeometryGraph.prototype.addSelfIntersectionNode = function addSelfIntersectionNode (argIndex, coord, loc) {
  16830. if (this.isBoundaryNode(argIndex, coord)) { return null }
  16831. if (loc === Location.BOUNDARY && this._useBoundaryDeterminationRule) { this.insertBoundaryPoint(argIndex, coord); } else { this.insertPoint(argIndex, coord, loc); }
  16832. };
  16833. GeometryGraph.prototype.addPolygonRing = function addPolygonRing (lr, cwLeft, cwRight) {
  16834. if (lr.isEmpty()) { return null }
  16835. var coord = CoordinateArrays.removeRepeatedPoints(lr.getCoordinates());
  16836. if (coord.length < 4) {
  16837. this._hasTooFewPoints = true;
  16838. this._invalidPoint = coord[0];
  16839. return null
  16840. }
  16841. var left = cwLeft;
  16842. var right = cwRight;
  16843. if (CGAlgorithms.isCCW(coord)) {
  16844. left = cwRight;
  16845. right = cwLeft;
  16846. }
  16847. var e = new Edge(coord, new Label(this._argIndex, Location.BOUNDARY, left, right));
  16848. this._lineEdgeMap.put(lr, e);
  16849. this.insertEdge(e);
  16850. this.insertPoint(this._argIndex, coord[0], Location.BOUNDARY);
  16851. };
  16852. GeometryGraph.prototype.insertPoint = function insertPoint (argIndex, coord, onLocation) {
  16853. var n = this._nodes.addNode(coord);
  16854. var lbl = n.getLabel();
  16855. if (lbl === null) {
  16856. n._label = new Label(argIndex, onLocation);
  16857. } else { lbl.setLocation(argIndex, onLocation); }
  16858. };
  16859. GeometryGraph.prototype.createEdgeSetIntersector = function createEdgeSetIntersector () {
  16860. return new SimpleMCSweepLineIntersector()
  16861. };
  16862. GeometryGraph.prototype.addSelfIntersectionNodes = function addSelfIntersectionNodes (argIndex) {
  16863. var this$1 = this;
  16864. for (var i = this._edges.iterator(); i.hasNext();) {
  16865. var e = i.next();
  16866. var eLoc = e.getLabel().getLocation(argIndex);
  16867. for (var eiIt = e.eiList.iterator(); eiIt.hasNext();) {
  16868. var ei = eiIt.next();
  16869. this$1.addSelfIntersectionNode(argIndex, ei.coord, eLoc);
  16870. }
  16871. }
  16872. };
  16873. GeometryGraph.prototype.add = function add () {
  16874. if (arguments.length === 1) {
  16875. var g = arguments[0];
  16876. if (g.isEmpty()) { return null }
  16877. if (g instanceof MultiPolygon) { this._useBoundaryDeterminationRule = false; }
  16878. if (g instanceof Polygon) { this.addPolygon(g); }
  16879. else if (g instanceof LineString) { this.addLineString(g); }
  16880. else if (g instanceof Point) { this.addPoint(g); }
  16881. else if (g instanceof MultiPoint) { this.addCollection(g); }
  16882. else if (g instanceof MultiLineString) { this.addCollection(g); }
  16883. else if (g instanceof MultiPolygon) { this.addCollection(g); }
  16884. else if (g instanceof GeometryCollection) { this.addCollection(g); }
  16885. else { throw new Error(g.getClass().getName()) }
  16886. } else { return PlanarGraph$$1.prototype.add.apply(this, arguments) }
  16887. };
  16888. GeometryGraph.prototype.addCollection = function addCollection (gc) {
  16889. var this$1 = this;
  16890. for (var i = 0; i < gc.getNumGeometries(); i++) {
  16891. var g = gc.getGeometryN(i);
  16892. this$1.add(g);
  16893. }
  16894. };
  16895. GeometryGraph.prototype.locate = function locate (pt) {
  16896. if (hasInterface(this._parentGeom, Polygonal) && this._parentGeom.getNumGeometries() > 50) {
  16897. if (this._areaPtLocator === null) {
  16898. this._areaPtLocator = new IndexedPointInAreaLocator(this._parentGeom);
  16899. }
  16900. return this._areaPtLocator.locate(pt)
  16901. }
  16902. return this._ptLocator.locate(pt, this._parentGeom)
  16903. };
  16904. GeometryGraph.prototype.findEdge = function findEdge () {
  16905. if (arguments.length === 1) {
  16906. var line = arguments[0];
  16907. return this._lineEdgeMap.get(line)
  16908. } else { return PlanarGraph$$1.prototype.findEdge.apply(this, arguments) }
  16909. };
  16910. GeometryGraph.prototype.interfaces_ = function interfaces_ () {
  16911. return []
  16912. };
  16913. GeometryGraph.prototype.getClass = function getClass () {
  16914. return GeometryGraph
  16915. };
  16916. GeometryGraph.determineBoundary = function determineBoundary (boundaryNodeRule, boundaryCount) {
  16917. return boundaryNodeRule.isInBoundary(boundaryCount) ? Location.BOUNDARY : Location.INTERIOR
  16918. };
  16919. return GeometryGraph;
  16920. }(PlanarGraph));
  16921. var GeometryGraphOp = function GeometryGraphOp () {
  16922. this._li = new RobustLineIntersector();
  16923. this._resultPrecisionModel = null;
  16924. this._arg = null;
  16925. if (arguments.length === 1) {
  16926. var g0 = arguments[0];
  16927. this.setComputationPrecision(g0.getPrecisionModel());
  16928. this._arg = new Array(1).fill(null);
  16929. this._arg[0] = new GeometryGraph(0, g0);
  16930. } else if (arguments.length === 2) {
  16931. var g0$1 = arguments[0];
  16932. var g1 = arguments[1];
  16933. var boundaryNodeRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
  16934. if (g0$1.getPrecisionModel().compareTo(g1.getPrecisionModel()) >= 0) { this.setComputationPrecision(g0$1.getPrecisionModel()); } else { this.setComputationPrecision(g1.getPrecisionModel()); }
  16935. this._arg = new Array(2).fill(null);
  16936. this._arg[0] = new GeometryGraph(0, g0$1, boundaryNodeRule);
  16937. this._arg[1] = new GeometryGraph(1, g1, boundaryNodeRule);
  16938. } else if (arguments.length === 3) {
  16939. var g0$2 = arguments[0];
  16940. var g1$1 = arguments[1];
  16941. var boundaryNodeRule$1 = arguments[2];
  16942. if (g0$2.getPrecisionModel().compareTo(g1$1.getPrecisionModel()) >= 0) { this.setComputationPrecision(g0$2.getPrecisionModel()); } else { this.setComputationPrecision(g1$1.getPrecisionModel()); }
  16943. this._arg = new Array(2).fill(null);
  16944. this._arg[0] = new GeometryGraph(0, g0$2, boundaryNodeRule$1);
  16945. this._arg[1] = new GeometryGraph(1, g1$1, boundaryNodeRule$1);
  16946. }
  16947. };
  16948. GeometryGraphOp.prototype.getArgGeometry = function getArgGeometry (i) {
  16949. return this._arg[i].getGeometry()
  16950. };
  16951. GeometryGraphOp.prototype.setComputationPrecision = function setComputationPrecision (pm) {
  16952. this._resultPrecisionModel = pm;
  16953. this._li.setPrecisionModel(this._resultPrecisionModel);
  16954. };
  16955. GeometryGraphOp.prototype.interfaces_ = function interfaces_ () {
  16956. return []
  16957. };
  16958. GeometryGraphOp.prototype.getClass = function getClass () {
  16959. return GeometryGraphOp
  16960. };
  16961. // operation.geometrygraph
  16962. var GeometryMapper = function GeometryMapper () {};
  16963. GeometryMapper.prototype.interfaces_ = function interfaces_ () {
  16964. return []
  16965. };
  16966. GeometryMapper.prototype.getClass = function getClass () {
  16967. return GeometryMapper
  16968. };
  16969. GeometryMapper.map = function map () {
  16970. if (arguments[0] instanceof Geometry && hasInterface(arguments[1], GeometryMapper.MapOp)) {
  16971. var geom = arguments[0];
  16972. var op = arguments[1];
  16973. var mapped = new ArrayList();
  16974. for (var i = 0; i < geom.getNumGeometries(); i++) {
  16975. var g = op.map(geom.getGeometryN(i));
  16976. if (g !== null) { mapped.add(g); }
  16977. }
  16978. return geom.getFactory().buildGeometry(mapped)
  16979. } else if (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], GeometryMapper.MapOp)) {
  16980. var geoms = arguments[0];
  16981. var op$1 = arguments[1];
  16982. var mapped$1 = new ArrayList();
  16983. for (var i$1 = geoms.iterator(); i$1.hasNext();) {
  16984. var g$1 = i$1.next();
  16985. var gr = op$1.map(g$1);
  16986. if (gr !== null) { mapped$1.add(gr); }
  16987. }
  16988. return mapped$1
  16989. }
  16990. };
  16991. GeometryMapper.MapOp = function MapOp () {};
  16992. var OverlayOp = (function (GeometryGraphOp) {
  16993. function OverlayOp () {
  16994. var g0 = arguments[0];
  16995. var g1 = arguments[1];
  16996. GeometryGraphOp.call(this, g0, g1);
  16997. this._ptLocator = new PointLocator();
  16998. this._geomFact = null;
  16999. this._resultGeom = null;
  17000. this._graph = null;
  17001. this._edgeList = new EdgeList();
  17002. this._resultPolyList = new ArrayList();
  17003. this._resultLineList = new ArrayList();
  17004. this._resultPointList = new ArrayList();
  17005. this._graph = new PlanarGraph(new OverlayNodeFactory());
  17006. this._geomFact = g0.getFactory();
  17007. }
  17008. if ( GeometryGraphOp ) OverlayOp.__proto__ = GeometryGraphOp;
  17009. OverlayOp.prototype = Object.create( GeometryGraphOp && GeometryGraphOp.prototype );
  17010. OverlayOp.prototype.constructor = OverlayOp;
  17011. OverlayOp.prototype.insertUniqueEdge = function insertUniqueEdge (e) {
  17012. var existingEdge = this._edgeList.findEqualEdge(e);
  17013. if (existingEdge !== null) {
  17014. var existingLabel = existingEdge.getLabel();
  17015. var labelToMerge = e.getLabel();
  17016. if (!existingEdge.isPointwiseEqual(e)) {
  17017. labelToMerge = new Label(e.getLabel());
  17018. labelToMerge.flip();
  17019. }
  17020. var depth = existingEdge.getDepth();
  17021. if (depth.isNull()) {
  17022. depth.add(existingLabel);
  17023. }
  17024. depth.add(labelToMerge);
  17025. existingLabel.merge(labelToMerge);
  17026. } else {
  17027. this._edgeList.add(e);
  17028. }
  17029. };
  17030. OverlayOp.prototype.getGraph = function getGraph () {
  17031. return this._graph
  17032. };
  17033. OverlayOp.prototype.cancelDuplicateResultEdges = function cancelDuplicateResultEdges () {
  17034. for (var it = this._graph.getEdgeEnds().iterator(); it.hasNext();) {
  17035. var de = it.next();
  17036. var sym = de.getSym();
  17037. if (de.isInResult() && sym.isInResult()) {
  17038. de.setInResult(false);
  17039. sym.setInResult(false);
  17040. }
  17041. }
  17042. };
  17043. OverlayOp.prototype.isCoveredByLA = function isCoveredByLA (coord) {
  17044. if (this.isCovered(coord, this._resultLineList)) { return true }
  17045. if (this.isCovered(coord, this._resultPolyList)) { return true }
  17046. return false
  17047. };
  17048. OverlayOp.prototype.computeGeometry = function computeGeometry (resultPointList, resultLineList, resultPolyList, opcode) {
  17049. var geomList = new ArrayList();
  17050. geomList.addAll(resultPointList);
  17051. geomList.addAll(resultLineList);
  17052. geomList.addAll(resultPolyList);
  17053. if (geomList.isEmpty()) { return OverlayOp.createEmptyResult(opcode, this._arg[0].getGeometry(), this._arg[1].getGeometry(), this._geomFact) }
  17054. return this._geomFact.buildGeometry(geomList)
  17055. };
  17056. OverlayOp.prototype.mergeSymLabels = function mergeSymLabels () {
  17057. for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {
  17058. var node = nodeit.next();
  17059. node.getEdges().mergeSymLabels();
  17060. }
  17061. };
  17062. OverlayOp.prototype.isCovered = function isCovered (coord, geomList) {
  17063. var this$1 = this;
  17064. for (var it = geomList.iterator(); it.hasNext();) {
  17065. var geom = it.next();
  17066. var loc = this$1._ptLocator.locate(coord, geom);
  17067. if (loc !== Location.EXTERIOR) { return true }
  17068. }
  17069. return false
  17070. };
  17071. OverlayOp.prototype.replaceCollapsedEdges = function replaceCollapsedEdges () {
  17072. var newEdges = new ArrayList();
  17073. for (var it = this._edgeList.iterator(); it.hasNext();) {
  17074. var e = it.next();
  17075. if (e.isCollapsed()) {
  17076. it.remove();
  17077. newEdges.add(e.getCollapsedEdge());
  17078. }
  17079. }
  17080. this._edgeList.addAll(newEdges);
  17081. };
  17082. OverlayOp.prototype.updateNodeLabelling = function updateNodeLabelling () {
  17083. for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {
  17084. var node = nodeit.next();
  17085. var lbl = node.getEdges().getLabel();
  17086. node.getLabel().merge(lbl);
  17087. }
  17088. };
  17089. OverlayOp.prototype.getResultGeometry = function getResultGeometry (overlayOpCode) {
  17090. this.computeOverlay(overlayOpCode);
  17091. return this._resultGeom
  17092. };
  17093. OverlayOp.prototype.insertUniqueEdges = function insertUniqueEdges (edges) {
  17094. var this$1 = this;
  17095. for (var i = edges.iterator(); i.hasNext();) {
  17096. var e = i.next();
  17097. this$1.insertUniqueEdge(e);
  17098. }
  17099. };
  17100. OverlayOp.prototype.computeOverlay = function computeOverlay (opCode) {
  17101. this.copyPoints(0);
  17102. this.copyPoints(1);
  17103. this._arg[0].computeSelfNodes(this._li, false);
  17104. this._arg[1].computeSelfNodes(this._li, false);
  17105. this._arg[0].computeEdgeIntersections(this._arg[1], this._li, true);
  17106. var baseSplitEdges = new ArrayList();
  17107. this._arg[0].computeSplitEdges(baseSplitEdges);
  17108. this._arg[1].computeSplitEdges(baseSplitEdges);
  17109. // const splitEdges = baseSplitEdges
  17110. this.insertUniqueEdges(baseSplitEdges);
  17111. this.computeLabelsFromDepths();
  17112. this.replaceCollapsedEdges();
  17113. EdgeNodingValidator.checkValid(this._edgeList.getEdges());
  17114. this._graph.addEdges(this._edgeList.getEdges());
  17115. this.computeLabelling();
  17116. this.labelIncompleteNodes();
  17117. this.findResultAreaEdges(opCode);
  17118. this.cancelDuplicateResultEdges();
  17119. var polyBuilder = new PolygonBuilder(this._geomFact);
  17120. polyBuilder.add(this._graph);
  17121. this._resultPolyList = polyBuilder.getPolygons();
  17122. var lineBuilder = new LineBuilder(this, this._geomFact, this._ptLocator);
  17123. this._resultLineList = lineBuilder.build(opCode);
  17124. var pointBuilder = new PointBuilder(this, this._geomFact, this._ptLocator);
  17125. this._resultPointList = pointBuilder.build(opCode);
  17126. this._resultGeom = this.computeGeometry(this._resultPointList, this._resultLineList, this._resultPolyList, opCode);
  17127. };
  17128. OverlayOp.prototype.labelIncompleteNode = function labelIncompleteNode (n, targetIndex) {
  17129. var loc = this._ptLocator.locate(n.getCoordinate(), this._arg[targetIndex].getGeometry());
  17130. n.getLabel().setLocation(targetIndex, loc);
  17131. };
  17132. OverlayOp.prototype.copyPoints = function copyPoints (argIndex) {
  17133. var this$1 = this;
  17134. for (var i = this._arg[argIndex].getNodeIterator(); i.hasNext();) {
  17135. var graphNode = i.next();
  17136. var newNode = this$1._graph.addNode(graphNode.getCoordinate());
  17137. newNode.setLabel(argIndex, graphNode.getLabel().getLocation(argIndex));
  17138. }
  17139. };
  17140. OverlayOp.prototype.findResultAreaEdges = function findResultAreaEdges (opCode) {
  17141. for (var it = this._graph.getEdgeEnds().iterator(); it.hasNext();) {
  17142. var de = it.next();
  17143. var label = de.getLabel();
  17144. if (label.isArea() && !de.isInteriorAreaEdge() && OverlayOp.isResultOfOp(label.getLocation(0, Position.RIGHT), label.getLocation(1, Position.RIGHT), opCode)) {
  17145. de.setInResult(true);
  17146. }
  17147. }
  17148. };
  17149. OverlayOp.prototype.computeLabelsFromDepths = function computeLabelsFromDepths () {
  17150. for (var it = this._edgeList.iterator(); it.hasNext();) {
  17151. var e = it.next();
  17152. var lbl = e.getLabel();
  17153. var depth = e.getDepth();
  17154. if (!depth.isNull()) {
  17155. depth.normalize();
  17156. for (var i = 0; i < 2; i++) {
  17157. if (!lbl.isNull(i) && lbl.isArea() && !depth.isNull(i)) {
  17158. if (depth.getDelta(i) === 0) {
  17159. lbl.toLine(i);
  17160. } else {
  17161. Assert.isTrue(!depth.isNull(i, Position.LEFT), 'depth of LEFT side has not been initialized');
  17162. lbl.setLocation(i, Position.LEFT, depth.getLocation(i, Position.LEFT));
  17163. Assert.isTrue(!depth.isNull(i, Position.RIGHT), 'depth of RIGHT side has not been initialized');
  17164. lbl.setLocation(i, Position.RIGHT, depth.getLocation(i, Position.RIGHT));
  17165. }
  17166. }
  17167. }
  17168. }
  17169. }
  17170. };
  17171. OverlayOp.prototype.computeLabelling = function computeLabelling () {
  17172. var this$1 = this;
  17173. for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {
  17174. var node = nodeit.next();
  17175. node.getEdges().computeLabelling(this$1._arg);
  17176. }
  17177. this.mergeSymLabels();
  17178. this.updateNodeLabelling();
  17179. };
  17180. OverlayOp.prototype.labelIncompleteNodes = function labelIncompleteNodes () {
  17181. var this$1 = this;
  17182. // let nodeCount = 0
  17183. for (var ni = this._graph.getNodes().iterator(); ni.hasNext();) {
  17184. var n = ni.next();
  17185. var label = n.getLabel();
  17186. if (n.isIsolated()) {
  17187. // nodeCount++
  17188. if (label.isNull(0)) { this$1.labelIncompleteNode(n, 0); } else { this$1.labelIncompleteNode(n, 1); }
  17189. }
  17190. n.getEdges().updateLabelling(label);
  17191. }
  17192. };
  17193. OverlayOp.prototype.isCoveredByA = function isCoveredByA (coord) {
  17194. if (this.isCovered(coord, this._resultPolyList)) { return true }
  17195. return false
  17196. };
  17197. OverlayOp.prototype.interfaces_ = function interfaces_ () {
  17198. return []
  17199. };
  17200. OverlayOp.prototype.getClass = function getClass () {
  17201. return OverlayOp
  17202. };
  17203. return OverlayOp;
  17204. }(GeometryGraphOp));
  17205. OverlayOp.overlayOp = function (geom0, geom1, opCode) {
  17206. var gov = new OverlayOp(geom0, geom1);
  17207. var geomOv = gov.getResultGeometry(opCode);
  17208. return geomOv
  17209. };
  17210. OverlayOp.intersection = function (g, other) {
  17211. if (g.isEmpty() || other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.INTERSECTION, g, other, g.getFactory()) }
  17212. if (g.isGeometryCollection()) {
  17213. var g2 = other;
  17214. return GeometryCollectionMapper.map(g, {
  17215. interfaces_: function () {
  17216. return [GeometryMapper.MapOp]
  17217. },
  17218. map: function (g) {
  17219. return g.intersection(g2)
  17220. }
  17221. })
  17222. }
  17223. g.checkNotGeometryCollection(g);
  17224. g.checkNotGeometryCollection(other);
  17225. return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.INTERSECTION)
  17226. };
  17227. OverlayOp.symDifference = function (g, other) {
  17228. if (g.isEmpty() || other.isEmpty()) {
  17229. if (g.isEmpty() && other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.SYMDIFFERENCE, g, other, g.getFactory()) }
  17230. if (g.isEmpty()) { return other.copy() }
  17231. if (other.isEmpty()) { return g.copy() }
  17232. }
  17233. g.checkNotGeometryCollection(g);
  17234. g.checkNotGeometryCollection(other);
  17235. return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.SYMDIFFERENCE)
  17236. };
  17237. OverlayOp.resultDimension = function (opCode, g0, g1) {
  17238. var dim0 = g0.getDimension();
  17239. var dim1 = g1.getDimension();
  17240. var resultDimension = -1;
  17241. switch (opCode) {
  17242. case OverlayOp.INTERSECTION:
  17243. resultDimension = Math.min(dim0, dim1);
  17244. break
  17245. case OverlayOp.UNION:
  17246. resultDimension = Math.max(dim0, dim1);
  17247. break
  17248. case OverlayOp.DIFFERENCE:
  17249. resultDimension = dim0;
  17250. break
  17251. case OverlayOp.SYMDIFFERENCE:
  17252. resultDimension = Math.max(dim0, dim1);
  17253. break
  17254. default:
  17255. }
  17256. return resultDimension
  17257. };
  17258. OverlayOp.createEmptyResult = function (overlayOpCode, a, b, geomFact) {
  17259. var result = null;
  17260. switch (OverlayOp.resultDimension(overlayOpCode, a, b)) {
  17261. case -1:
  17262. result = geomFact.createGeometryCollection(new Array(0).fill(null));
  17263. break
  17264. case 0:
  17265. result = geomFact.createPoint();
  17266. break
  17267. case 1:
  17268. result = geomFact.createLineString();
  17269. break
  17270. case 2:
  17271. result = geomFact.createPolygon();
  17272. break
  17273. default:
  17274. }
  17275. return result
  17276. };
  17277. OverlayOp.difference = function (g, other) {
  17278. if (g.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.DIFFERENCE, g, other, g.getFactory()) }
  17279. if (other.isEmpty()) { return g.copy() }
  17280. g.checkNotGeometryCollection(g);
  17281. g.checkNotGeometryCollection(other);
  17282. return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.DIFFERENCE)
  17283. };
  17284. OverlayOp.isResultOfOp = function () {
  17285. if (arguments.length === 2) {
  17286. var label = arguments[0];
  17287. var opCode = arguments[1];
  17288. var loc0 = label.getLocation(0);
  17289. var loc1 = label.getLocation(1);
  17290. return OverlayOp.isResultOfOp(loc0, loc1, opCode)
  17291. } else if (arguments.length === 3) {
  17292. var loc0$1 = arguments[0];
  17293. var loc1$1 = arguments[1];
  17294. var overlayOpCode = arguments[2];
  17295. if (loc0$1 === Location.BOUNDARY) { loc0$1 = Location.INTERIOR; }
  17296. if (loc1$1 === Location.BOUNDARY) { loc1$1 = Location.INTERIOR; }
  17297. switch (overlayOpCode) {
  17298. case OverlayOp.INTERSECTION:
  17299. return loc0$1 === Location.INTERIOR && loc1$1 === Location.INTERIOR
  17300. case OverlayOp.UNION:
  17301. return loc0$1 === Location.INTERIOR || loc1$1 === Location.INTERIOR
  17302. case OverlayOp.DIFFERENCE:
  17303. return loc0$1 === Location.INTERIOR && loc1$1 !== Location.INTERIOR
  17304. case OverlayOp.SYMDIFFERENCE:
  17305. return (loc0$1 === Location.INTERIOR && loc1$1 !== Location.INTERIOR) || (loc0$1 !== Location.INTERIOR && loc1$1 === Location.INTERIOR)
  17306. default:
  17307. }
  17308. return false
  17309. }
  17310. };
  17311. OverlayOp.INTERSECTION = 1;
  17312. OverlayOp.UNION = 2;
  17313. OverlayOp.DIFFERENCE = 3;
  17314. OverlayOp.SYMDIFFERENCE = 4;
  17315. var FuzzyPointLocator = function FuzzyPointLocator () {
  17316. this._g = null;
  17317. this._boundaryDistanceTolerance = null;
  17318. this._linework = null;
  17319. this._ptLocator = new PointLocator();
  17320. this._seg = new LineSegment();
  17321. var g = arguments[0];
  17322. var boundaryDistanceTolerance = arguments[1];
  17323. this._g = g;
  17324. this._boundaryDistanceTolerance = boundaryDistanceTolerance;
  17325. this._linework = this.extractLinework(g);
  17326. };
  17327. FuzzyPointLocator.prototype.isWithinToleranceOfBoundary = function isWithinToleranceOfBoundary (pt) {
  17328. var this$1 = this;
  17329. for (var i = 0; i < this._linework.getNumGeometries(); i++) {
  17330. var line = this$1._linework.getGeometryN(i);
  17331. var seq = line.getCoordinateSequence();
  17332. for (var j = 0; j < seq.size() - 1; j++) {
  17333. seq.getCoordinate(j, this$1._seg.p0);
  17334. seq.getCoordinate(j + 1, this$1._seg.p1);
  17335. var dist = this$1._seg.distance(pt);
  17336. if (dist <= this$1._boundaryDistanceTolerance) { return true }
  17337. }
  17338. }
  17339. return false
  17340. };
  17341. FuzzyPointLocator.prototype.getLocation = function getLocation (pt) {
  17342. if (this.isWithinToleranceOfBoundary(pt)) { return Location.BOUNDARY }
  17343. return this._ptLocator.locate(pt, this._g)
  17344. };
  17345. FuzzyPointLocator.prototype.extractLinework = function extractLinework (g) {
  17346. var extracter = new PolygonalLineworkExtracter();
  17347. g.apply(extracter);
  17348. var linework = extracter.getLinework();
  17349. var lines = GeometryFactory.toLineStringArray(linework);
  17350. return g.getFactory().createMultiLineString(lines)
  17351. };
  17352. FuzzyPointLocator.prototype.interfaces_ = function interfaces_ () {
  17353. return []
  17354. };
  17355. FuzzyPointLocator.prototype.getClass = function getClass () {
  17356. return FuzzyPointLocator
  17357. };
  17358. var PolygonalLineworkExtracter = function PolygonalLineworkExtracter () {
  17359. this._linework = null;
  17360. this._linework = new ArrayList();
  17361. };
  17362. PolygonalLineworkExtracter.prototype.getLinework = function getLinework () {
  17363. return this._linework
  17364. };
  17365. PolygonalLineworkExtracter.prototype.filter = function filter (g) {
  17366. var this$1 = this;
  17367. if (g instanceof Polygon) {
  17368. var poly = g;
  17369. this._linework.add(poly.getExteriorRing());
  17370. for (var i = 0; i < poly.getNumInteriorRing(); i++) {
  17371. this$1._linework.add(poly.getInteriorRingN(i));
  17372. }
  17373. }
  17374. };
  17375. PolygonalLineworkExtracter.prototype.interfaces_ = function interfaces_ () {
  17376. return [GeometryFilter]
  17377. };
  17378. PolygonalLineworkExtracter.prototype.getClass = function getClass () {
  17379. return PolygonalLineworkExtracter
  17380. };
  17381. var OffsetPointGenerator = function OffsetPointGenerator () {
  17382. this._g = null;
  17383. this._doLeft = true;
  17384. this._doRight = true;
  17385. var g = arguments[0];
  17386. this._g = g;
  17387. };
  17388. OffsetPointGenerator.prototype.extractPoints = function extractPoints (line, offsetDistance, offsetPts) {
  17389. var this$1 = this;
  17390. var pts = line.getCoordinates();
  17391. for (var i = 0; i < pts.length - 1; i++) {
  17392. this$1.computeOffsetPoints(pts[i], pts[i + 1], offsetDistance, offsetPts);
  17393. }
  17394. };
  17395. OffsetPointGenerator.prototype.setSidesToGenerate = function setSidesToGenerate (doLeft, doRight) {
  17396. this._doLeft = doLeft;
  17397. this._doRight = doRight;
  17398. };
  17399. OffsetPointGenerator.prototype.getPoints = function getPoints (offsetDistance) {
  17400. var this$1 = this;
  17401. var offsetPts = new ArrayList();
  17402. var lines = LinearComponentExtracter.getLines(this._g);
  17403. for (var i = lines.iterator(); i.hasNext();) {
  17404. var line = i.next();
  17405. this$1.extractPoints(line, offsetDistance, offsetPts);
  17406. }
  17407. return offsetPts
  17408. };
  17409. OffsetPointGenerator.prototype.computeOffsetPoints = function computeOffsetPoints (p0, p1, offsetDistance, offsetPts) {
  17410. var dx = p1.x - p0.x;
  17411. var dy = p1.y - p0.y;
  17412. var len = Math.sqrt(dx * dx + dy * dy);
  17413. var ux = offsetDistance * dx / len;
  17414. var uy = offsetDistance * dy / len;
  17415. var midX = (p1.x + p0.x) / 2;
  17416. var midY = (p1.y + p0.y) / 2;
  17417. if (this._doLeft) {
  17418. var offsetLeft = new Coordinate(midX - uy, midY + ux);
  17419. offsetPts.add(offsetLeft);
  17420. }
  17421. if (this._doRight) {
  17422. var offsetRight = new Coordinate(midX + uy, midY - ux);
  17423. offsetPts.add(offsetRight);
  17424. }
  17425. };
  17426. OffsetPointGenerator.prototype.interfaces_ = function interfaces_ () {
  17427. return []
  17428. };
  17429. OffsetPointGenerator.prototype.getClass = function getClass () {
  17430. return OffsetPointGenerator
  17431. };
  17432. var OverlayResultValidator = function OverlayResultValidator () {
  17433. this._geom = null;
  17434. this._locFinder = null;
  17435. this._location = new Array(3).fill(null);
  17436. this._invalidLocation = null;
  17437. this._boundaryDistanceTolerance = OverlayResultValidator.TOLERANCE;
  17438. this._testCoords = new ArrayList();
  17439. var a = arguments[0];
  17440. var b = arguments[1];
  17441. var result = arguments[2];
  17442. this._boundaryDistanceTolerance = OverlayResultValidator.computeBoundaryDistanceTolerance(a, b);
  17443. this._geom = [a, b, result];
  17444. this._locFinder = [new FuzzyPointLocator(this._geom[0], this._boundaryDistanceTolerance), new FuzzyPointLocator(this._geom[1], this._boundaryDistanceTolerance), new FuzzyPointLocator(this._geom[2], this._boundaryDistanceTolerance)];
  17445. };
  17446. var staticAccessors$46 = { TOLERANCE: { configurable: true } };
  17447. OverlayResultValidator.prototype.reportResult = function reportResult (overlayOp, location, expectedInterior) {
  17448. System.out.println('Overlay result invalid - A:' + Location.toLocationSymbol(location[0]) + ' B:' + Location.toLocationSymbol(location[1]) + ' expected:' + (expectedInterior ? 'i' : 'e') + ' actual:' + Location.toLocationSymbol(location[2]));
  17449. };
  17450. OverlayResultValidator.prototype.isValid = function isValid (overlayOp) {
  17451. this.addTestPts(this._geom[0]);
  17452. this.addTestPts(this._geom[1]);
  17453. var isValid = this.checkValid(overlayOp);
  17454. return isValid
  17455. };
  17456. OverlayResultValidator.prototype.checkValid = function checkValid () {
  17457. var this$1 = this;
  17458. if (arguments.length === 1) {
  17459. var overlayOp = arguments[0];
  17460. for (var i = 0; i < this._testCoords.size(); i++) {
  17461. var pt = this$1._testCoords.get(i);
  17462. if (!this$1.checkValid(overlayOp, pt)) {
  17463. this$1._invalidLocation = pt;
  17464. return false
  17465. }
  17466. }
  17467. return true
  17468. } else if (arguments.length === 2) {
  17469. var overlayOp$1 = arguments[0];
  17470. var pt$1 = arguments[1];
  17471. this._location[0] = this._locFinder[0].getLocation(pt$1);
  17472. this._location[1] = this._locFinder[1].getLocation(pt$1);
  17473. this._location[2] = this._locFinder[2].getLocation(pt$1);
  17474. if (OverlayResultValidator.hasLocation(this._location, Location.BOUNDARY)) { return true }
  17475. return this.isValidResult(overlayOp$1, this._location)
  17476. }
  17477. };
  17478. OverlayResultValidator.prototype.addTestPts = function addTestPts (g) {
  17479. var ptGen = new OffsetPointGenerator(g);
  17480. this._testCoords.addAll(ptGen.getPoints(5 * this._boundaryDistanceTolerance));
  17481. };
  17482. OverlayResultValidator.prototype.isValidResult = function isValidResult (overlayOp, location) {
  17483. var expectedInterior = OverlayOp.isResultOfOp(location[0], location[1], overlayOp);
  17484. var resultInInterior = location[2] === Location.INTERIOR;
  17485. var isValid = !(expectedInterior ^ resultInInterior);
  17486. if (!isValid) { this.reportResult(overlayOp, location, expectedInterior); }
  17487. return isValid
  17488. };
  17489. OverlayResultValidator.prototype.getInvalidLocation = function getInvalidLocation () {
  17490. return this._invalidLocation
  17491. };
  17492. OverlayResultValidator.prototype.interfaces_ = function interfaces_ () {
  17493. return []
  17494. };
  17495. OverlayResultValidator.prototype.getClass = function getClass () {
  17496. return OverlayResultValidator
  17497. };
  17498. OverlayResultValidator.hasLocation = function hasLocation (location, loc) {
  17499. for (var i = 0; i < 3; i++) {
  17500. if (location[i] === loc) { return true }
  17501. }
  17502. return false
  17503. };
  17504. OverlayResultValidator.computeBoundaryDistanceTolerance = function computeBoundaryDistanceTolerance (g0, g1) {
  17505. return Math.min(GeometrySnapper.computeSizeBasedSnapTolerance(g0), GeometrySnapper.computeSizeBasedSnapTolerance(g1))
  17506. };
  17507. OverlayResultValidator.isValid = function isValid (a, b, overlayOp, result) {
  17508. var validator = new OverlayResultValidator(a, b, result);
  17509. return validator.isValid(overlayOp)
  17510. };
  17511. staticAccessors$46.TOLERANCE.get = function () { return 0.000001 };
  17512. Object.defineProperties( OverlayResultValidator, staticAccessors$46 );
  17513. // operation.overlay
  17514. var GeometryCombiner = function GeometryCombiner (geoms) {
  17515. this._geomFactory = null;
  17516. this._skipEmpty = false;
  17517. this._inputGeoms = null;
  17518. this._geomFactory = GeometryCombiner.extractFactory(geoms);
  17519. this._inputGeoms = geoms;
  17520. };
  17521. GeometryCombiner.prototype.extractElements = function extractElements (geom, elems) {
  17522. var this$1 = this;
  17523. if (geom === null) { return null }
  17524. for (var i = 0; i < geom.getNumGeometries(); i++) {
  17525. var elemGeom = geom.getGeometryN(i);
  17526. if (this$1._skipEmpty && elemGeom.isEmpty()) { continue }
  17527. elems.add(elemGeom);
  17528. }
  17529. };
  17530. GeometryCombiner.prototype.combine = function combine () {
  17531. var this$1 = this;
  17532. var elems = new ArrayList();
  17533. for (var i = this._inputGeoms.iterator(); i.hasNext();) {
  17534. var g = i.next();
  17535. this$1.extractElements(g, elems);
  17536. }
  17537. if (elems.size() === 0) {
  17538. if (this._geomFactory !== null) {
  17539. return this._geomFactory.createGeometryCollection(null)
  17540. }
  17541. return null
  17542. }
  17543. return this._geomFactory.buildGeometry(elems)
  17544. };
  17545. GeometryCombiner.prototype.interfaces_ = function interfaces_ () {
  17546. return []
  17547. };
  17548. GeometryCombiner.prototype.getClass = function getClass () {
  17549. return GeometryCombiner
  17550. };
  17551. GeometryCombiner.combine = function combine () {
  17552. if (arguments.length === 1) {
  17553. var geoms = arguments[0];
  17554. var combiner = new GeometryCombiner(geoms);
  17555. return combiner.combine()
  17556. } else if (arguments.length === 2) {
  17557. var g0 = arguments[0];
  17558. var g1 = arguments[1];
  17559. var combiner$1 = new GeometryCombiner(GeometryCombiner.createList(g0, g1));
  17560. return combiner$1.combine()
  17561. } else if (arguments.length === 3) {
  17562. var g0$1 = arguments[0];
  17563. var g1$1 = arguments[1];
  17564. var g2 = arguments[2];
  17565. var combiner$2 = new GeometryCombiner(GeometryCombiner.createList(g0$1, g1$1, g2));
  17566. return combiner$2.combine()
  17567. }
  17568. };
  17569. GeometryCombiner.extractFactory = function extractFactory (geoms) {
  17570. if (geoms.isEmpty()) { return null }
  17571. return geoms.iterator().next().getFactory()
  17572. };
  17573. GeometryCombiner.createList = function createList () {
  17574. if (arguments.length === 2) {
  17575. var obj0 = arguments[0];
  17576. var obj1 = arguments[1];
  17577. var list = new ArrayList();
  17578. list.add(obj0);
  17579. list.add(obj1);
  17580. return list
  17581. } else if (arguments.length === 3) {
  17582. var obj0$1 = arguments[0];
  17583. var obj1$1 = arguments[1];
  17584. var obj2 = arguments[2];
  17585. var list$1 = new ArrayList();
  17586. list$1.add(obj0$1);
  17587. list$1.add(obj1$1);
  17588. list$1.add(obj2);
  17589. return list$1
  17590. }
  17591. };
  17592. var CascadedPolygonUnion = function CascadedPolygonUnion () {
  17593. this._inputPolys = null;
  17594. this._geomFactory = null;
  17595. var polys = arguments[0];
  17596. this._inputPolys = polys;
  17597. if (this._inputPolys === null) { this._inputPolys = new ArrayList(); }
  17598. };
  17599. var staticAccessors$47 = { STRTREE_NODE_CAPACITY: { configurable: true } };
  17600. CascadedPolygonUnion.prototype.reduceToGeometries = function reduceToGeometries (geomTree) {
  17601. var this$1 = this;
  17602. var geoms = new ArrayList();
  17603. for (var i = geomTree.iterator(); i.hasNext();) {
  17604. var o = i.next();
  17605. var geom = null;
  17606. if (hasInterface(o, List)) {
  17607. geom = this$1.unionTree(o);
  17608. } else if (o instanceof Geometry) {
  17609. geom = o;
  17610. }
  17611. geoms.add(geom);
  17612. }
  17613. return geoms
  17614. };
  17615. CascadedPolygonUnion.prototype.extractByEnvelope = function extractByEnvelope (env, geom, disjointGeoms) {
  17616. var intersectingGeoms = new ArrayList();
  17617. for (var i = 0; i < geom.getNumGeometries(); i++) {
  17618. var elem = geom.getGeometryN(i);
  17619. if (elem.getEnvelopeInternal().intersects(env)) { intersectingGeoms.add(elem); } else { disjointGeoms.add(elem); }
  17620. }
  17621. return this._geomFactory.buildGeometry(intersectingGeoms)
  17622. };
  17623. CascadedPolygonUnion.prototype.unionOptimized = function unionOptimized (g0, g1) {
  17624. var g0Env = g0.getEnvelopeInternal();
  17625. var g1Env = g1.getEnvelopeInternal();
  17626. if (!g0Env.intersects(g1Env)) {
  17627. var combo = GeometryCombiner.combine(g0, g1);
  17628. return combo
  17629. }
  17630. if (g0.getNumGeometries() <= 1 && g1.getNumGeometries() <= 1) { return this.unionActual(g0, g1) }
  17631. var commonEnv = g0Env.intersection(g1Env);
  17632. return this.unionUsingEnvelopeIntersection(g0, g1, commonEnv)
  17633. };
  17634. CascadedPolygonUnion.prototype.union = function union () {
  17635. if (this._inputPolys === null) { throw new Error('union() method cannot be called twice') }
  17636. if (this._inputPolys.isEmpty()) { return null }
  17637. this._geomFactory = this._inputPolys.iterator().next().getFactory();
  17638. var index = new STRtree(CascadedPolygonUnion.STRTREE_NODE_CAPACITY);
  17639. for (var i = this._inputPolys.iterator(); i.hasNext();) {
  17640. var item = i.next();
  17641. index.insert(item.getEnvelopeInternal(), item);
  17642. }
  17643. this._inputPolys = null;
  17644. var itemTree = index.itemsTree();
  17645. var unionAll = this.unionTree(itemTree);
  17646. return unionAll
  17647. };
  17648. CascadedPolygonUnion.prototype.binaryUnion = function binaryUnion () {
  17649. if (arguments.length === 1) {
  17650. var geoms = arguments[0];
  17651. return this.binaryUnion(geoms, 0, geoms.size())
  17652. } else if (arguments.length === 3) {
  17653. var geoms$1 = arguments[0];
  17654. var start = arguments[1];
  17655. var end = arguments[2];
  17656. if (end - start <= 1) {
  17657. var g0 = CascadedPolygonUnion.getGeometry(geoms$1, start);
  17658. return this.unionSafe(g0, null)
  17659. } else if (end - start === 2) {
  17660. return this.unionSafe(CascadedPolygonUnion.getGeometry(geoms$1, start), CascadedPolygonUnion.getGeometry(geoms$1, start + 1))
  17661. } else {
  17662. var mid = Math.trunc((end + start) / 2);
  17663. var g0$1 = this.binaryUnion(geoms$1, start, mid);
  17664. var g1 = this.binaryUnion(geoms$1, mid, end);
  17665. return this.unionSafe(g0$1, g1)
  17666. }
  17667. }
  17668. };
  17669. CascadedPolygonUnion.prototype.repeatedUnion = function repeatedUnion (geoms) {
  17670. var union = null;
  17671. for (var i = geoms.iterator(); i.hasNext();) {
  17672. var g = i.next();
  17673. if (union === null) { union = g.copy(); } else { union = union.union(g); }
  17674. }
  17675. return union
  17676. };
  17677. CascadedPolygonUnion.prototype.unionSafe = function unionSafe (g0, g1) {
  17678. if (g0 === null && g1 === null) { return null }
  17679. if (g0 === null) { return g1.copy() }
  17680. if (g1 === null) { return g0.copy() }
  17681. return this.unionOptimized(g0, g1)
  17682. };
  17683. CascadedPolygonUnion.prototype.unionActual = function unionActual (g0, g1) {
  17684. return CascadedPolygonUnion.restrictToPolygons(g0.union(g1))
  17685. };
  17686. CascadedPolygonUnion.prototype.unionTree = function unionTree (geomTree) {
  17687. var geoms = this.reduceToGeometries(geomTree);
  17688. var union = this.binaryUnion(geoms);
  17689. return union
  17690. };
  17691. CascadedPolygonUnion.prototype.unionUsingEnvelopeIntersection = function unionUsingEnvelopeIntersection (g0, g1, common) {
  17692. var disjointPolys = new ArrayList();
  17693. var g0Int = this.extractByEnvelope(common, g0, disjointPolys);
  17694. var g1Int = this.extractByEnvelope(common, g1, disjointPolys);
  17695. var union = this.unionActual(g0Int, g1Int);
  17696. disjointPolys.add(union);
  17697. var overallUnion = GeometryCombiner.combine(disjointPolys);
  17698. return overallUnion
  17699. };
  17700. CascadedPolygonUnion.prototype.bufferUnion = function bufferUnion () {
  17701. if (arguments.length === 1) {
  17702. var geoms = arguments[0];
  17703. var factory = geoms.get(0).getFactory();
  17704. var gColl = factory.buildGeometry(geoms);
  17705. var unionAll = gColl.buffer(0.0);
  17706. return unionAll
  17707. } else if (arguments.length === 2) {
  17708. var g0 = arguments[0];
  17709. var g1 = arguments[1];
  17710. var factory$1 = g0.getFactory();
  17711. var gColl$1 = factory$1.createGeometryCollection([g0, g1]);
  17712. var unionAll$1 = gColl$1.buffer(0.0);
  17713. return unionAll$1
  17714. }
  17715. };
  17716. CascadedPolygonUnion.prototype.interfaces_ = function interfaces_ () {
  17717. return []
  17718. };
  17719. CascadedPolygonUnion.prototype.getClass = function getClass () {
  17720. return CascadedPolygonUnion
  17721. };
  17722. CascadedPolygonUnion.restrictToPolygons = function restrictToPolygons (g) {
  17723. if (hasInterface(g, Polygonal)) {
  17724. return g
  17725. }
  17726. var polygons = PolygonExtracter.getPolygons(g);
  17727. if (polygons.size() === 1) { return polygons.get(0) }
  17728. return g.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons))
  17729. };
  17730. CascadedPolygonUnion.getGeometry = function getGeometry (list, index) {
  17731. if (index >= list.size()) { return null }
  17732. return list.get(index)
  17733. };
  17734. CascadedPolygonUnion.union = function union (polys) {
  17735. var op = new CascadedPolygonUnion(polys);
  17736. return op.union()
  17737. };
  17738. staticAccessors$47.STRTREE_NODE_CAPACITY.get = function () { return 4 };
  17739. Object.defineProperties( CascadedPolygonUnion, staticAccessors$47 );
  17740. var UnionOp = function UnionOp () {};
  17741. UnionOp.prototype.interfaces_ = function interfaces_ () {
  17742. return []
  17743. };
  17744. UnionOp.prototype.getClass = function getClass () {
  17745. return UnionOp
  17746. };
  17747. UnionOp.union = function union (g, other) {
  17748. if (g.isEmpty() || other.isEmpty()) {
  17749. if (g.isEmpty() && other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.UNION, g, other, g.getFactory()) }
  17750. if (g.isEmpty()) { return other.copy() }
  17751. if (other.isEmpty()) { return g.copy() }
  17752. }
  17753. g.checkNotGeometryCollection(g);
  17754. g.checkNotGeometryCollection(other);
  17755. return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.UNION)
  17756. };
  17757. // operation.union
  17758. // operation
  17759. /**
  17760. * Polyfill for IE support
  17761. */
  17762. export { GeoJSONReader, GeoJSONWriter, OverlayOp, UnionOp, BufferOp };