jsts.js 626 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. /* Polyfill service v3.13.0
  4. * For detailed credits and licence information see http://github.com/financial-times/polyfill-service
  5. *
  6. * - Array.prototype.fill, License: CC0 */
  7. if (!('fill' in Array.prototype)) {
  8. Object.defineProperty(Array.prototype, 'fill', {
  9. configurable: true,
  10. value: function fill (value) {
  11. if (this === undefined || this === null) {
  12. throw new TypeError(this + ' is not an object')
  13. }
  14. var arrayLike = Object(this);
  15. var length = Math.max(Math.min(arrayLike.length, 9007199254740991), 0) || 0;
  16. var relativeStart = 1 in arguments ? parseInt(Number(arguments[1]), 10) || 0 : 0;
  17. relativeStart = relativeStart < 0 ? Math.max(length + relativeStart, 0) : Math.min(relativeStart, length);
  18. var relativeEnd = 2 in arguments && arguments[2] !== undefined ? parseInt(Number(arguments[2]), 10) || 0 : length;
  19. relativeEnd = relativeEnd < 0 ? Math.max(length + arguments[2], 0) : Math.min(relativeEnd, length);
  20. while (relativeStart < relativeEnd) {
  21. arrayLike[relativeStart] = value;
  22. ++relativeStart;
  23. }
  24. return arrayLike
  25. },
  26. writable: true
  27. });
  28. }
  29. /**
  30. * Polyfill for IE support
  31. */
  32. Number.isFinite = Number.isFinite || function (value) {
  33. return typeof value === 'number' && isFinite(value)
  34. };
  35. Number.isInteger = Number.isInteger || function (val) {
  36. return typeof val === 'number' &&
  37. isFinite(val) &&
  38. Math.floor(val) === val
  39. };
  40. Number.parseFloat = Number.parseFloat || parseFloat;
  41. Number.isNaN = Number.isNaN || function (value) {
  42. return value !== value // eslint-disable-line
  43. };
  44. /**
  45. * Polyfill for IE support
  46. */
  47. Math.trunc = Math.trunc || function (x) {
  48. return x < 0 ? Math.ceil(x) : Math.floor(x)
  49. };
  50. var NumberUtil = function NumberUtil () {};
  51. NumberUtil.prototype.interfaces_ = function interfaces_ () {
  52. return []
  53. };
  54. NumberUtil.prototype.getClass = function getClass () {
  55. return NumberUtil
  56. };
  57. NumberUtil.prototype.equalsWithTolerance = function equalsWithTolerance (x1, x2, tolerance) {
  58. return Math.abs(x1 - x2) <= tolerance
  59. };
  60. var IllegalArgumentException = (function (Error) {
  61. function IllegalArgumentException (message) {
  62. Error.call(this, message);
  63. this.name = 'IllegalArgumentException';
  64. this.message = message;
  65. this.stack = (new Error()).stack;
  66. }
  67. if ( Error ) IllegalArgumentException.__proto__ = Error;
  68. IllegalArgumentException.prototype = Object.create( Error && Error.prototype );
  69. IllegalArgumentException.prototype.constructor = IllegalArgumentException;
  70. return IllegalArgumentException;
  71. }(Error));
  72. var Double = function Double () {};
  73. var staticAccessors$1 = { MAX_VALUE: { configurable: true } };
  74. Double.isNaN = function isNaN (n) { return Number.isNaN(n) };
  75. Double.doubleToLongBits = function doubleToLongBits (n) { return n };
  76. Double.longBitsToDouble = function longBitsToDouble (n) { return n };
  77. Double.isInfinite = function isInfinite (n) { return !Number.isFinite(n) };
  78. staticAccessors$1.MAX_VALUE.get = function () { return Number.MAX_VALUE };
  79. Object.defineProperties( Double, staticAccessors$1 );
  80. var Comparable = function Comparable () {};
  81. var Clonable = function Clonable () {};
  82. var Comparator = function Comparator () {};
  83. function Serializable () {}
  84. // import Assert from '../util/Assert'
  85. var Coordinate = function Coordinate () {
  86. this.x = null;
  87. this.y = null;
  88. this.z = null;
  89. if (arguments.length === 0) {
  90. this.x = 0.0;
  91. this.y = 0.0;
  92. this.z = Coordinate.NULL_ORDINATE;
  93. } else if (arguments.length === 1) {
  94. var c = arguments[0];
  95. this.x = c.x;
  96. this.y = c.y;
  97. this.z = c.z;
  98. } else if (arguments.length === 2) {
  99. this.x = arguments[0];
  100. this.y = arguments[1];
  101. this.z = Coordinate.NULL_ORDINATE;
  102. } else if (arguments.length === 3) {
  103. this.x = arguments[0];
  104. this.y = arguments[1];
  105. this.z = arguments[2];
  106. }
  107. };
  108. var staticAccessors = { DimensionalComparator: { configurable: true },serialVersionUID: { configurable: true },NULL_ORDINATE: { configurable: true },X: { configurable: true },Y: { configurable: true },Z: { configurable: true } };
  109. Coordinate.prototype.setOrdinate = function setOrdinate (ordinateIndex, value) {
  110. switch (ordinateIndex) {
  111. case Coordinate.X:
  112. this.x = value;
  113. break
  114. case Coordinate.Y:
  115. this.y = value;
  116. break
  117. case Coordinate.Z:
  118. this.z = value;
  119. break
  120. default:
  121. throw new IllegalArgumentException('Invalid ordinate index: ' + ordinateIndex)
  122. }
  123. };
  124. Coordinate.prototype.equals2D = function equals2D () {
  125. if (arguments.length === 1) {
  126. var other = arguments[0];
  127. if (this.x !== other.x) {
  128. return false
  129. }
  130. if (this.y !== other.y) {
  131. return false
  132. }
  133. return true
  134. } else if (arguments.length === 2) {
  135. var c = arguments[0];
  136. var tolerance = arguments[1];
  137. if (!NumberUtil.equalsWithTolerance(this.x, c.x, tolerance)) {
  138. return false
  139. }
  140. if (!NumberUtil.equalsWithTolerance(this.y, c.y, tolerance)) {
  141. return false
  142. }
  143. return true
  144. }
  145. };
  146. Coordinate.prototype.getOrdinate = function getOrdinate (ordinateIndex) {
  147. switch (ordinateIndex) {
  148. case Coordinate.X:
  149. return this.x
  150. case Coordinate.Y:
  151. return this.y
  152. case Coordinate.Z:
  153. return this.z
  154. default:
  155. }
  156. throw new IllegalArgumentException('Invalid ordinate index: ' + ordinateIndex)
  157. };
  158. Coordinate.prototype.equals3D = function equals3D (other) {
  159. return this.x === other.x &&
  160. this.y === other.y &&
  161. ((this.z === other.z || Double.isNaN(this.z)) &&
  162. Double.isNaN(other.z))
  163. };
  164. Coordinate.prototype.equals = function equals (other) {
  165. if (!(other instanceof Coordinate)) {
  166. return false
  167. }
  168. return this.equals2D(other)
  169. };
  170. Coordinate.prototype.equalInZ = function equalInZ (c, tolerance) {
  171. return NumberUtil.equalsWithTolerance(this.z, c.z, tolerance)
  172. };
  173. Coordinate.prototype.compareTo = function compareTo (o) {
  174. var other = o;
  175. if (this.x < other.x) { return -1 }
  176. if (this.x > other.x) { return 1 }
  177. if (this.y < other.y) { return -1 }
  178. if (this.y > other.y) { return 1 }
  179. return 0
  180. };
  181. Coordinate.prototype.clone = function clone () {
  182. // try {
  183. // var coord = null
  184. // return coord
  185. // } catch (e) {
  186. // if (e instanceof CloneNotSupportedException) {
  187. // Assert.shouldNeverReachHere("this shouldn't happen because this class is Cloneable")
  188. // return null
  189. // } else throw e
  190. // } finally {}
  191. };
  192. Coordinate.prototype.copy = function copy () {
  193. return new Coordinate(this)
  194. };
  195. Coordinate.prototype.toString = function toString () {
  196. return '(' + this.x + ', ' + this.y + ', ' + this.z + ')'
  197. };
  198. Coordinate.prototype.distance3D = function distance3D (c) {
  199. var dx = this.x - c.x;
  200. var dy = this.y - c.y;
  201. var dz = this.z - c.z;
  202. return Math.sqrt(dx * dx + dy * dy + dz * dz)
  203. };
  204. Coordinate.prototype.distance = function distance (c) {
  205. var dx = this.x - c.x;
  206. var dy = this.y - c.y;
  207. return Math.sqrt(dx * dx + dy * dy)
  208. };
  209. Coordinate.prototype.hashCode = function hashCode () {
  210. var result = 17;
  211. result = 37 * result + Coordinate.hashCode(this.x);
  212. result = 37 * result + Coordinate.hashCode(this.y);
  213. return result
  214. };
  215. Coordinate.prototype.setCoordinate = function setCoordinate (other) {
  216. this.x = other.x;
  217. this.y = other.y;
  218. this.z = other.z;
  219. };
  220. Coordinate.prototype.interfaces_ = function interfaces_ () {
  221. return [Comparable, Clonable, Serializable]
  222. };
  223. Coordinate.prototype.getClass = function getClass () {
  224. return Coordinate
  225. };
  226. Coordinate.hashCode = function hashCode () {
  227. if (arguments.length === 1) {
  228. var x = arguments[0];
  229. var f = Double.doubleToLongBits(x);
  230. return Math.trunc((f ^ f) >>> 32)
  231. }
  232. };
  233. staticAccessors.DimensionalComparator.get = function () { return DimensionalComparator };
  234. staticAccessors.serialVersionUID.get = function () { return 6683108902428366910 };
  235. staticAccessors.NULL_ORDINATE.get = function () { return Double.NaN };
  236. staticAccessors.X.get = function () { return 0 };
  237. staticAccessors.Y.get = function () { return 1 };
  238. staticAccessors.Z.get = function () { return 2 };
  239. Object.defineProperties( Coordinate, staticAccessors );
  240. var DimensionalComparator = function DimensionalComparator (dimensionsToTest) {
  241. this._dimensionsToTest = 2;
  242. if (arguments.length === 0) {} else if (arguments.length === 1) {
  243. var dimensionsToTest$1 = arguments[0];
  244. if (dimensionsToTest$1 !== 2 && dimensionsToTest$1 !== 3) { throw new IllegalArgumentException('only 2 or 3 dimensions may be specified') }
  245. this._dimensionsToTest = dimensionsToTest$1;
  246. }
  247. };
  248. DimensionalComparator.prototype.compare = function compare (o1, o2) {
  249. var c1 = o1;
  250. var c2 = o2;
  251. var compX = DimensionalComparator.compare(c1.x, c2.x);
  252. if (compX !== 0) { return compX }
  253. var compY = DimensionalComparator.compare(c1.y, c2.y);
  254. if (compY !== 0) { return compY }
  255. if (this._dimensionsToTest <= 2) { return 0 }
  256. var compZ = DimensionalComparator.compare(c1.z, c2.z);
  257. return compZ
  258. };
  259. DimensionalComparator.prototype.interfaces_ = function interfaces_ () {
  260. return [Comparator]
  261. };
  262. DimensionalComparator.prototype.getClass = function getClass () {
  263. return DimensionalComparator
  264. };
  265. DimensionalComparator.compare = function compare (a, b) {
  266. if (a < b) { return -1 }
  267. if (a > b) { return 1 }
  268. if (Double.isNaN(a)) {
  269. if (Double.isNaN(b)) { return 0 }
  270. return -1
  271. }
  272. if (Double.isNaN(b)) { return 1 }
  273. return 0
  274. };
  275. // import hasInterface from '../../../../hasInterface'
  276. // import CoordinateSequence from './CoordinateSequence'
  277. var CoordinateSequenceFactory = function CoordinateSequenceFactory () {};
  278. CoordinateSequenceFactory.prototype.create = function create () {
  279. // if (arguments.length === 1) {
  280. // if (arguments[0] instanceof Array) {
  281. // let coordinates = arguments[0]
  282. // } else if (hasInterface(arguments[0], CoordinateSequence)) {
  283. // let coordSeq = arguments[0]
  284. // }
  285. // } else if (arguments.length === 2) {
  286. // let size = arguments[0]
  287. // let dimension = arguments[1]
  288. // }
  289. };
  290. CoordinateSequenceFactory.prototype.interfaces_ = function interfaces_ () {
  291. return []
  292. };
  293. CoordinateSequenceFactory.prototype.getClass = function getClass () {
  294. return CoordinateSequenceFactory
  295. };
  296. var Location = function Location () {};
  297. var staticAccessors$4 = { INTERIOR: { configurable: true },BOUNDARY: { configurable: true },EXTERIOR: { configurable: true },NONE: { configurable: true } };
  298. Location.prototype.interfaces_ = function interfaces_ () {
  299. return []
  300. };
  301. Location.prototype.getClass = function getClass () {
  302. return Location
  303. };
  304. Location.toLocationSymbol = function toLocationSymbol (locationValue) {
  305. switch (locationValue) {
  306. case Location.EXTERIOR:
  307. return 'e'
  308. case Location.BOUNDARY:
  309. return 'b'
  310. case Location.INTERIOR:
  311. return 'i'
  312. case Location.NONE:
  313. return '-'
  314. default:
  315. }
  316. throw new IllegalArgumentException('Unknown location value: ' + locationValue)
  317. };
  318. staticAccessors$4.INTERIOR.get = function () { return 0 };
  319. staticAccessors$4.BOUNDARY.get = function () { return 1 };
  320. staticAccessors$4.EXTERIOR.get = function () { return 2 };
  321. staticAccessors$4.NONE.get = function () { return -1 };
  322. Object.defineProperties( Location, staticAccessors$4 );
  323. var hasInterface = function (o, i) {
  324. return o.interfaces_ && o.interfaces_().indexOf(i) > -1
  325. };
  326. var MathUtil = function MathUtil () {};
  327. var staticAccessors$5 = { LOG_10: { configurable: true } };
  328. MathUtil.prototype.interfaces_ = function interfaces_ () {
  329. return []
  330. };
  331. MathUtil.prototype.getClass = function getClass () {
  332. return MathUtil
  333. };
  334. MathUtil.log10 = function log10 (x) {
  335. var ln = Math.log(x);
  336. if (Double.isInfinite(ln)) { return ln }
  337. if (Double.isNaN(ln)) { return ln }
  338. return ln / MathUtil.LOG_10
  339. };
  340. MathUtil.min = function min (v1, v2, v3, v4) {
  341. var min = v1;
  342. if (v2 < min) { min = v2; }
  343. if (v3 < min) { min = v3; }
  344. if (v4 < min) { min = v4; }
  345. return min
  346. };
  347. MathUtil.clamp = function clamp () {
  348. if (typeof arguments[2] === 'number' && (typeof arguments[0] === 'number' && typeof arguments[1] === 'number')) {
  349. var x = arguments[0];
  350. var min = arguments[1];
  351. var max = arguments[2];
  352. if (x < min) { return min }
  353. if (x > max) { return max }
  354. return x
  355. } else if (Number.isInteger(arguments[2]) && (Number.isInteger(arguments[0]) && Number.isInteger(arguments[1]))) {
  356. var x$1 = arguments[0];
  357. var min$1 = arguments[1];
  358. var max$1 = arguments[2];
  359. if (x$1 < min$1) { return min$1 }
  360. if (x$1 > max$1) { return max$1 }
  361. return x$1
  362. }
  363. };
  364. MathUtil.wrap = function wrap (index, max) {
  365. if (index < 0) {
  366. return max - -index % max
  367. }
  368. return index % max
  369. };
  370. MathUtil.max = function max () {
  371. if (arguments.length === 3) {
  372. var v1 = arguments[0];
  373. var v2 = arguments[1];
  374. var v3 = arguments[2];
  375. var max = v1;
  376. if (v2 > max) { max = v2; }
  377. if (v3 > max) { max = v3; }
  378. return max
  379. } else if (arguments.length === 4) {
  380. var v1$1 = arguments[0];
  381. var v2$1 = arguments[1];
  382. var v3$1 = arguments[2];
  383. var v4 = arguments[3];
  384. var max$1 = v1$1;
  385. if (v2$1 > max$1) { max$1 = v2$1; }
  386. if (v3$1 > max$1) { max$1 = v3$1; }
  387. if (v4 > max$1) { max$1 = v4; }
  388. return max$1
  389. }
  390. };
  391. MathUtil.average = function average (x1, x2) {
  392. return (x1 + x2) / 2.0
  393. };
  394. staticAccessors$5.LOG_10.get = function () { return Math.log(10) };
  395. Object.defineProperties( MathUtil, staticAccessors$5 );
  396. var StringBuffer = function StringBuffer (str) {
  397. this.str = str;
  398. };
  399. StringBuffer.prototype.append = function append (e) {
  400. this.str += e;
  401. };
  402. StringBuffer.prototype.setCharAt = function setCharAt (i, c) {
  403. this.str = this.str.substr(0, i) + c + this.str.substr(i + 1);
  404. };
  405. StringBuffer.prototype.toString = function toString (e) {
  406. return this.str
  407. };
  408. var Integer = function Integer (value) {
  409. this.value = value;
  410. };
  411. Integer.prototype.intValue = function intValue () {
  412. return this.value
  413. };
  414. Integer.prototype.compareTo = function compareTo (o) {
  415. if (this.value < o) { return -1 }
  416. if (this.value > o) { return 1 }
  417. return 0
  418. };
  419. Integer.isNaN = function isNaN (n) { return Number.isNaN(n) };
  420. var Character = function Character () {};
  421. Character.isWhitespace = function isWhitespace (c) { return ((c <= 32 && c >= 0) || c === 127) };
  422. Character.toUpperCase = function toUpperCase (c) { return c.toUpperCase() };
  423. var DD = function DD () {
  424. this._hi = 0.0;
  425. this._lo = 0.0;
  426. if (arguments.length === 0) {
  427. this.init(0.0);
  428. } else if (arguments.length === 1) {
  429. if (typeof arguments[0] === 'number') {
  430. var x = arguments[0];
  431. this.init(x);
  432. } else if (arguments[0] instanceof DD) {
  433. var dd = arguments[0];
  434. this.init(dd);
  435. } else if (typeof arguments[0] === 'string') {
  436. var str = arguments[0];
  437. DD.call(this, DD.parse(str));
  438. }
  439. } else if (arguments.length === 2) {
  440. var hi = arguments[0];
  441. var lo = arguments[1];
  442. this.init(hi, lo);
  443. }
  444. };
  445. 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 } };
  446. DD.prototype.le = function le (y) {
  447. return (this._hi < y._hi || this._hi === y._hi) && this._lo <= y._lo
  448. };
  449. DD.prototype.extractSignificantDigits = function extractSignificantDigits (insertDecimalPoint, magnitude) {
  450. var y = this.abs();
  451. var mag = DD.magnitude(y._hi);
  452. var scale = DD.TEN.pow(mag);
  453. y = y.divide(scale);
  454. if (y.gt(DD.TEN)) {
  455. y = y.divide(DD.TEN);
  456. mag += 1;
  457. } else if (y.lt(DD.ONE)) {
  458. y = y.multiply(DD.TEN);
  459. mag -= 1;
  460. }
  461. var decimalPointPos = mag + 1;
  462. var buf = new StringBuffer();
  463. var numDigits = DD.MAX_PRINT_DIGITS - 1;
  464. for (var i = 0; i <= numDigits; i++) {
  465. if (insertDecimalPoint && i === decimalPointPos) {
  466. buf.append('.');
  467. }
  468. var digit = Math.trunc(y._hi);
  469. if (digit < 0) {
  470. break
  471. }
  472. var rebiasBy10 = false;
  473. var digitChar = 0;
  474. if (digit > 9) {
  475. rebiasBy10 = true;
  476. digitChar = '9';
  477. } else {
  478. digitChar = '0' + digit;
  479. }
  480. buf.append(digitChar);
  481. y = y.subtract(DD.valueOf(digit)).multiply(DD.TEN);
  482. if (rebiasBy10) { y.selfAdd(DD.TEN); }
  483. var continueExtractingDigits = true;
  484. var remMag = DD.magnitude(y._hi);
  485. if (remMag < 0 && Math.abs(remMag) >= numDigits - i) { continueExtractingDigits = false; }
  486. if (!continueExtractingDigits) { break }
  487. }
  488. magnitude[0] = mag;
  489. return buf.toString()
  490. };
  491. DD.prototype.sqr = function sqr () {
  492. return this.multiply(this)
  493. };
  494. DD.prototype.doubleValue = function doubleValue () {
  495. return this._hi + this._lo
  496. };
  497. DD.prototype.subtract = function subtract () {
  498. if (arguments[0] instanceof DD) {
  499. var y = arguments[0];
  500. return this.add(y.negate())
  501. } else if (typeof arguments[0] === 'number') {
  502. var y$1 = arguments[0];
  503. return this.add(-y$1)
  504. }
  505. };
  506. DD.prototype.equals = function equals () {
  507. if (arguments.length === 1) {
  508. var y = arguments[0];
  509. return this._hi === y._hi && this._lo === y._lo
  510. }
  511. };
  512. DD.prototype.isZero = function isZero () {
  513. return this._hi === 0.0 && this._lo === 0.0
  514. };
  515. DD.prototype.selfSubtract = function selfSubtract () {
  516. if (arguments[0] instanceof DD) {
  517. var y = arguments[0];
  518. if (this.isNaN()) { return this }
  519. return this.selfAdd(-y._hi, -y._lo)
  520. } else if (typeof arguments[0] === 'number') {
  521. var y$1 = arguments[0];
  522. if (this.isNaN()) { return this }
  523. return this.selfAdd(-y$1, 0.0)
  524. }
  525. };
  526. DD.prototype.getSpecialNumberString = function getSpecialNumberString () {
  527. if (this.isZero()) { return '0.0' }
  528. if (this.isNaN()) { return 'NaN ' }
  529. return null
  530. };
  531. DD.prototype.min = function min (x) {
  532. if (this.le(x)) {
  533. return this
  534. } else {
  535. return x
  536. }
  537. };
  538. DD.prototype.selfDivide = function selfDivide () {
  539. if (arguments.length === 1) {
  540. if (arguments[0] instanceof DD) {
  541. var y = arguments[0];
  542. return this.selfDivide(y._hi, y._lo)
  543. } else if (typeof arguments[0] === 'number') {
  544. var y$1 = arguments[0];
  545. return this.selfDivide(y$1, 0.0)
  546. }
  547. } else if (arguments.length === 2) {
  548. var yhi = arguments[0];
  549. var ylo = arguments[1];
  550. var hc = null;
  551. var tc = null;
  552. var hy = null;
  553. var ty = null;
  554. var C = null;
  555. var c = null;
  556. var U = null;
  557. var u = null;
  558. C = this._hi / yhi;
  559. c = DD.SPLIT * C;
  560. hc = c - C;
  561. u = DD.SPLIT * yhi;
  562. hc = c - hc;
  563. tc = C - hc;
  564. hy = u - yhi;
  565. U = C * yhi;
  566. hy = u - hy;
  567. ty = yhi - hy;
  568. u = hc * hy - U + hc * ty + tc * hy + tc * ty;
  569. c = (this._hi - U - u + this._lo - C * ylo) / yhi;
  570. u = C + c;
  571. this._hi = u;
  572. this._lo = C - u + c;
  573. return this
  574. }
  575. };
  576. DD.prototype.dump = function dump () {
  577. return 'DD<' + this._hi + ', ' + this._lo + '>'
  578. };
  579. DD.prototype.divide = function divide () {
  580. if (arguments[0] instanceof DD) {
  581. var y = arguments[0];
  582. var hc = null;
  583. var tc = null;
  584. var hy = null;
  585. var ty = null;
  586. var C = null;
  587. var c = null;
  588. var U = null;
  589. var u = null;
  590. C = this._hi / y._hi;
  591. c = DD.SPLIT * C;
  592. hc = c - C;
  593. u = DD.SPLIT * y._hi;
  594. hc = c - hc;
  595. tc = C - hc;
  596. hy = u - y._hi;
  597. U = C * y._hi;
  598. hy = u - hy;
  599. ty = y._hi - hy;
  600. u = hc * hy - U + hc * ty + tc * hy + tc * ty;
  601. c = (this._hi - U - u + this._lo - C * y._lo) / y._hi;
  602. u = C + c;
  603. var zhi = u;
  604. var zlo = C - u + c;
  605. return new DD(zhi, zlo)
  606. } else if (typeof arguments[0] === 'number') {
  607. var y$1 = arguments[0];
  608. if (Double.isNaN(y$1)) { return DD.createNaN() }
  609. return DD.copy(this).selfDivide(y$1, 0.0)
  610. }
  611. };
  612. DD.prototype.ge = function ge (y) {
  613. return (this._hi > y._hi || this._hi === y._hi) && this._lo >= y._lo
  614. };
  615. DD.prototype.pow = function pow (exp) {
  616. if (exp === 0.0) { return DD.valueOf(1.0) }
  617. var r = new DD(this);
  618. var s = DD.valueOf(1.0);
  619. var n = Math.abs(exp);
  620. if (n > 1) {
  621. while (n > 0) {
  622. if (n % 2 === 1) {
  623. s.selfMultiply(r);
  624. }
  625. n /= 2;
  626. if (n > 0) { r = r.sqr(); }
  627. }
  628. } else {
  629. s = r;
  630. }
  631. if (exp < 0) { return s.reciprocal() }
  632. return s
  633. };
  634. DD.prototype.ceil = function ceil () {
  635. if (this.isNaN()) { return DD.NaN }
  636. var fhi = Math.ceil(this._hi);
  637. var flo = 0.0;
  638. if (fhi === this._hi) {
  639. flo = Math.ceil(this._lo);
  640. }
  641. return new DD(fhi, flo)
  642. };
  643. DD.prototype.compareTo = function compareTo (o) {
  644. var other = o;
  645. if (this._hi < other._hi) { return -1 }
  646. if (this._hi > other._hi) { return 1 }
  647. if (this._lo < other._lo) { return -1 }
  648. if (this._lo > other._lo) { return 1 }
  649. return 0
  650. };
  651. DD.prototype.rint = function rint () {
  652. if (this.isNaN()) { return this }
  653. var plus5 = this.add(0.5);
  654. return plus5.floor()
  655. };
  656. DD.prototype.setValue = function setValue () {
  657. if (arguments[0] instanceof DD) {
  658. var value = arguments[0];
  659. this.init(value);
  660. return this
  661. } else if (typeof arguments[0] === 'number') {
  662. var value$1 = arguments[0];
  663. this.init(value$1);
  664. return this
  665. }
  666. };
  667. DD.prototype.max = function max (x) {
  668. if (this.ge(x)) {
  669. return this
  670. } else {
  671. return x
  672. }
  673. };
  674. DD.prototype.sqrt = function sqrt () {
  675. if (this.isZero()) { return DD.valueOf(0.0) }
  676. if (this.isNegative()) {
  677. return DD.NaN
  678. }
  679. var x = 1.0 / Math.sqrt(this._hi);
  680. var ax = this._hi * x;
  681. var axdd = DD.valueOf(ax);
  682. var diffSq = this.subtract(axdd.sqr());
  683. var d2 = diffSq._hi * (x * 0.5);
  684. return axdd.add(d2)
  685. };
  686. DD.prototype.selfAdd = function selfAdd () {
  687. if (arguments.length === 1) {
  688. if (arguments[0] instanceof DD) {
  689. var y = arguments[0];
  690. return this.selfAdd(y._hi, y._lo)
  691. } else if (typeof arguments[0] === 'number') {
  692. var y$1 = arguments[0];
  693. var H = null;
  694. var h = null;
  695. var S = null;
  696. var s = null;
  697. var e = null;
  698. var f = null;
  699. S = this._hi + y$1;
  700. e = S - this._hi;
  701. s = S - e;
  702. s = y$1 - e + (this._hi - s);
  703. f = s + this._lo;
  704. H = S + f;
  705. h = f + (S - H);
  706. this._hi = H + h;
  707. this._lo = h + (H - this._hi);
  708. return this
  709. }
  710. } else if (arguments.length === 2) {
  711. var yhi = arguments[0];
  712. var ylo = arguments[1];
  713. var H$1 = null;
  714. var h$1 = null;
  715. var T = null;
  716. var t = null;
  717. var S$1 = null;
  718. var s$1 = null;
  719. var e$1 = null;
  720. var f$1 = null;
  721. S$1 = this._hi + yhi;
  722. T = this._lo + ylo;
  723. e$1 = S$1 - this._hi;
  724. f$1 = T - this._lo;
  725. s$1 = S$1 - e$1;
  726. t = T - f$1;
  727. s$1 = yhi - e$1 + (this._hi - s$1);
  728. t = ylo - f$1 + (this._lo - t);
  729. e$1 = s$1 + T;
  730. H$1 = S$1 + e$1;
  731. h$1 = e$1 + (S$1 - H$1);
  732. e$1 = t + h$1;
  733. var zhi = H$1 + e$1;
  734. var zlo = e$1 + (H$1 - zhi);
  735. this._hi = zhi;
  736. this._lo = zlo;
  737. return this
  738. }
  739. };
  740. DD.prototype.selfMultiply = function selfMultiply () {
  741. if (arguments.length === 1) {
  742. if (arguments[0] instanceof DD) {
  743. var y = arguments[0];
  744. return this.selfMultiply(y._hi, y._lo)
  745. } else if (typeof arguments[0] === 'number') {
  746. var y$1 = arguments[0];
  747. return this.selfMultiply(y$1, 0.0)
  748. }
  749. } else if (arguments.length === 2) {
  750. var yhi = arguments[0];
  751. var ylo = arguments[1];
  752. var hx = null;
  753. var tx = null;
  754. var hy = null;
  755. var ty = null;
  756. var C = null;
  757. var c = null;
  758. C = DD.SPLIT * this._hi;
  759. hx = C - this._hi;
  760. c = DD.SPLIT * yhi;
  761. hx = C - hx;
  762. tx = this._hi - hx;
  763. hy = c - yhi;
  764. C = this._hi * yhi;
  765. hy = c - hy;
  766. ty = yhi - hy;
  767. c = hx * hy - C + hx * ty + tx * hy + tx * ty + (this._hi * ylo + this._lo * yhi);
  768. var zhi = C + c;
  769. hx = C - zhi;
  770. var zlo = c + hx;
  771. this._hi = zhi;
  772. this._lo = zlo;
  773. return this
  774. }
  775. };
  776. DD.prototype.selfSqr = function selfSqr () {
  777. return this.selfMultiply(this)
  778. };
  779. DD.prototype.floor = function floor () {
  780. if (this.isNaN()) { return DD.NaN }
  781. var fhi = Math.floor(this._hi);
  782. var flo = 0.0;
  783. if (fhi === this._hi) {
  784. flo = Math.floor(this._lo);
  785. }
  786. return new DD(fhi, flo)
  787. };
  788. DD.prototype.negate = function negate () {
  789. if (this.isNaN()) { return this }
  790. return new DD(-this._hi, -this._lo)
  791. };
  792. DD.prototype.clone = function clone () {
  793. // try {
  794. // return null
  795. // } catch (ex) {
  796. // if (ex instanceof CloneNotSupportedException) {
  797. // return null
  798. // } else throw ex
  799. // } finally {}
  800. };
  801. DD.prototype.multiply = function multiply () {
  802. if (arguments[0] instanceof DD) {
  803. var y = arguments[0];
  804. if (y.isNaN()) { return DD.createNaN() }
  805. return DD.copy(this).selfMultiply(y)
  806. } else if (typeof arguments[0] === 'number') {
  807. var y$1 = arguments[0];
  808. if (Double.isNaN(y$1)) { return DD.createNaN() }
  809. return DD.copy(this).selfMultiply(y$1, 0.0)
  810. }
  811. };
  812. DD.prototype.isNaN = function isNaN () {
  813. return Double.isNaN(this._hi)
  814. };
  815. DD.prototype.intValue = function intValue () {
  816. return Math.trunc(this._hi)
  817. };
  818. DD.prototype.toString = function toString () {
  819. var mag = DD.magnitude(this._hi);
  820. if (mag >= -3 && mag <= 20) { return this.toStandardNotation() }
  821. return this.toSciNotation()
  822. };
  823. DD.prototype.toStandardNotation = function toStandardNotation () {
  824. var specialStr = this.getSpecialNumberString();
  825. if (specialStr !== null) { return specialStr }
  826. var magnitude = new Array(1).fill(null);
  827. var sigDigits = this.extractSignificantDigits(true, magnitude);
  828. var decimalPointPos = magnitude[0] + 1;
  829. var num = sigDigits;
  830. if (sigDigits.charAt(0) === '.') {
  831. num = '0' + sigDigits;
  832. } else if (decimalPointPos < 0) {
  833. num = '0.' + DD.stringOfChar('0', -decimalPointPos) + sigDigits;
  834. } else if (sigDigits.indexOf('.') === -1) {
  835. var numZeroes = decimalPointPos - sigDigits.length;
  836. var zeroes = DD.stringOfChar('0', numZeroes);
  837. num = sigDigits + zeroes + '.0';
  838. }
  839. if (this.isNegative()) { return '-' + num }
  840. return num
  841. };
  842. DD.prototype.reciprocal = function reciprocal () {
  843. var hc = null;
  844. var tc = null;
  845. var hy = null;
  846. var ty = null;
  847. var C = null;
  848. var c = null;
  849. var U = null;
  850. var u = null;
  851. C = 1.0 / this._hi;
  852. c = DD.SPLIT * C;
  853. hc = c - C;
  854. u = DD.SPLIT * this._hi;
  855. hc = c - hc;
  856. tc = C - hc;
  857. hy = u - this._hi;
  858. U = C * this._hi;
  859. hy = u - hy;
  860. ty = this._hi - hy;
  861. u = hc * hy - U + hc * ty + tc * hy + tc * ty;
  862. c = (1.0 - U - u - C * this._lo) / this._hi;
  863. var zhi = C + c;
  864. var zlo = C - zhi + c;
  865. return new DD(zhi, zlo)
  866. };
  867. DD.prototype.toSciNotation = function toSciNotation () {
  868. if (this.isZero()) { return DD.SCI_NOT_ZERO }
  869. var specialStr = this.getSpecialNumberString();
  870. if (specialStr !== null) { return specialStr }
  871. var magnitude = new Array(1).fill(null);
  872. var digits = this.extractSignificantDigits(false, magnitude);
  873. var expStr = DD.SCI_NOT_EXPONENT_CHAR + magnitude[0];
  874. if (digits.charAt(0) === '0') {
  875. throw new Error('Found leading zero: ' + digits)
  876. }
  877. var trailingDigits = '';
  878. if (digits.length > 1) { trailingDigits = digits.substring(1); }
  879. var digitsWithDecimal = digits.charAt(0) + '.' + trailingDigits;
  880. if (this.isNegative()) { return '-' + digitsWithDecimal + expStr }
  881. return digitsWithDecimal + expStr
  882. };
  883. DD.prototype.abs = function abs () {
  884. if (this.isNaN()) { return DD.NaN }
  885. if (this.isNegative()) { return this.negate() }
  886. return new DD(this)
  887. };
  888. DD.prototype.isPositive = function isPositive () {
  889. return (this._hi > 0.0 || this._hi === 0.0) && this._lo > 0.0
  890. };
  891. DD.prototype.lt = function lt (y) {
  892. return (this._hi < y._hi || this._hi === y._hi) && this._lo < y._lo
  893. };
  894. DD.prototype.add = function add () {
  895. if (arguments[0] instanceof DD) {
  896. var y = arguments[0];
  897. return DD.copy(this).selfAdd(y)
  898. } else if (typeof arguments[0] === 'number') {
  899. var y$1 = arguments[0];
  900. return DD.copy(this).selfAdd(y$1)
  901. }
  902. };
  903. DD.prototype.init = function init () {
  904. if (arguments.length === 1) {
  905. if (typeof arguments[0] === 'number') {
  906. var x = arguments[0];
  907. this._hi = x;
  908. this._lo = 0.0;
  909. } else if (arguments[0] instanceof DD) {
  910. var dd = arguments[0];
  911. this._hi = dd._hi;
  912. this._lo = dd._lo;
  913. }
  914. } else if (arguments.length === 2) {
  915. var hi = arguments[0];
  916. var lo = arguments[1];
  917. this._hi = hi;
  918. this._lo = lo;
  919. }
  920. };
  921. DD.prototype.gt = function gt (y) {
  922. return (this._hi > y._hi || this._hi === y._hi) && this._lo > y._lo
  923. };
  924. DD.prototype.isNegative = function isNegative () {
  925. return (this._hi < 0.0 || this._hi === 0.0) && this._lo < 0.0
  926. };
  927. DD.prototype.trunc = function trunc () {
  928. if (this.isNaN()) { return DD.NaN }
  929. if (this.isPositive()) { return this.floor(); } else { return this.ceil() }
  930. };
  931. DD.prototype.signum = function signum () {
  932. if (this._hi > 0) { return 1 }
  933. if (this._hi < 0) { return -1 }
  934. if (this._lo > 0) { return 1 }
  935. if (this._lo < 0) { return -1 }
  936. return 0
  937. };
  938. DD.prototype.interfaces_ = function interfaces_ () {
  939. return [Serializable, Comparable, Clonable]
  940. };
  941. DD.prototype.getClass = function getClass () {
  942. return DD
  943. };
  944. DD.sqr = function sqr (x) {
  945. return DD.valueOf(x).selfMultiply(x)
  946. };
  947. DD.valueOf = function valueOf () {
  948. if (typeof arguments[0] === 'string') {
  949. var str = arguments[0];
  950. return DD.parse(str)
  951. } else if (typeof arguments[0] === 'number') {
  952. var x = arguments[0];
  953. return new DD(x)
  954. }
  955. };
  956. DD.sqrt = function sqrt (x) {
  957. return DD.valueOf(x).sqrt()
  958. };
  959. DD.parse = function parse (str) {
  960. var i = 0;
  961. var strlen = str.length;
  962. while (Character.isWhitespace(str.charAt(i))) { i++; }
  963. var isNegative = false;
  964. if (i < strlen) {
  965. var signCh = str.charAt(i);
  966. if (signCh === '-' || signCh === '+') {
  967. i++;
  968. if (signCh === '-') { isNegative = true; }
  969. }
  970. }
  971. var val = new DD();
  972. var numDigits = 0;
  973. var numBeforeDec = 0;
  974. var exp = 0;
  975. while (true) {
  976. if (i >= strlen) { break }
  977. var ch = str.charAt(i);
  978. i++;
  979. if (Character.isDigit(ch)) {
  980. var d = ch - '0';
  981. val.selfMultiply(DD.TEN);
  982. val.selfAdd(d);
  983. numDigits++;
  984. continue
  985. }
  986. if (ch === '.') {
  987. numBeforeDec = numDigits;
  988. continue
  989. }
  990. if (ch === 'e' || ch === 'E') {
  991. var expStr = str.substring(i);
  992. try {
  993. exp = Integer.parseInt(expStr);
  994. } catch (ex) {
  995. if (ex instanceof Error) {
  996. throw new Error('Invalid exponent ' + expStr + ' in string ' + str)
  997. } else { throw ex }
  998. } finally {}
  999. break
  1000. }
  1001. throw new Error("Unexpected character '" + ch + "' at position " + i + ' in string ' + str)
  1002. }
  1003. var val2 = val;
  1004. var numDecPlaces = numDigits - numBeforeDec - exp;
  1005. if (numDecPlaces === 0) {
  1006. val2 = val;
  1007. } else if (numDecPlaces > 0) {
  1008. var scale = DD.TEN.pow(numDecPlaces);
  1009. val2 = val.divide(scale);
  1010. } else if (numDecPlaces < 0) {
  1011. var scale$1 = DD.TEN.pow(-numDecPlaces);
  1012. val2 = val.multiply(scale$1);
  1013. }
  1014. if (isNegative) {
  1015. return val2.negate()
  1016. }
  1017. return val2
  1018. };
  1019. DD.createNaN = function createNaN () {
  1020. return new DD(Double.NaN, Double.NaN)
  1021. };
  1022. DD.copy = function copy (dd) {
  1023. return new DD(dd)
  1024. };
  1025. DD.magnitude = function magnitude (x) {
  1026. var xAbs = Math.abs(x);
  1027. var xLog10 = Math.log(xAbs) / Math.log(10);
  1028. var xMag = Math.trunc(Math.floor(xLog10));
  1029. var xApprox = Math.pow(10, xMag);
  1030. if (xApprox * 10 <= xAbs) { xMag += 1; }
  1031. return xMag
  1032. };
  1033. DD.stringOfChar = function stringOfChar (ch, len) {
  1034. var buf = new StringBuffer();
  1035. for (var i = 0; i < len; i++) {
  1036. buf.append(ch);
  1037. }
  1038. return buf.toString()
  1039. };
  1040. staticAccessors$7.PI.get = function () { return new DD(3.141592653589793116e+00, 1.224646799147353207e-16) };
  1041. staticAccessors$7.TWO_PI.get = function () { return new DD(6.283185307179586232e+00, 2.449293598294706414e-16) };
  1042. staticAccessors$7.PI_2.get = function () { return new DD(1.570796326794896558e+00, 6.123233995736766036e-17) };
  1043. staticAccessors$7.E.get = function () { return new DD(2.718281828459045091e+00, 1.445646891729250158e-16) };
  1044. staticAccessors$7.NaN.get = function () { return new DD(Double.NaN, Double.NaN) };
  1045. staticAccessors$7.EPS.get = function () { return 1.23259516440783e-32 };
  1046. staticAccessors$7.SPLIT.get = function () { return 134217729.0 };
  1047. staticAccessors$7.MAX_PRINT_DIGITS.get = function () { return 32 };
  1048. staticAccessors$7.TEN.get = function () { return DD.valueOf(10.0) };
  1049. staticAccessors$7.ONE.get = function () { return DD.valueOf(1.0) };
  1050. staticAccessors$7.SCI_NOT_EXPONENT_CHAR.get = function () { return 'E' };
  1051. staticAccessors$7.SCI_NOT_ZERO.get = function () { return '0.0E0' };
  1052. Object.defineProperties( DD, staticAccessors$7 );
  1053. var CGAlgorithmsDD = function CGAlgorithmsDD () {};
  1054. var staticAccessors$6 = { DP_SAFE_EPSILON: { configurable: true } };
  1055. CGAlgorithmsDD.prototype.interfaces_ = function interfaces_ () {
  1056. return []
  1057. };
  1058. CGAlgorithmsDD.prototype.getClass = function getClass () {
  1059. return CGAlgorithmsDD
  1060. };
  1061. CGAlgorithmsDD.orientationIndex = function orientationIndex (p1, p2, q) {
  1062. var index = CGAlgorithmsDD.orientationIndexFilter(p1, p2, q);
  1063. if (index <= 1) { return index }
  1064. var dx1 = DD.valueOf(p2.x).selfAdd(-p1.x);
  1065. var dy1 = DD.valueOf(p2.y).selfAdd(-p1.y);
  1066. var dx2 = DD.valueOf(q.x).selfAdd(-p2.x);
  1067. var dy2 = DD.valueOf(q.y).selfAdd(-p2.y);
  1068. return dx1.selfMultiply(dy2).selfSubtract(dy1.selfMultiply(dx2)).signum()
  1069. };
  1070. CGAlgorithmsDD.signOfDet2x2 = function signOfDet2x2 (x1, y1, x2, y2) {
  1071. var det = x1.multiply(y2).selfSubtract(y1.multiply(x2));
  1072. return det.signum()
  1073. };
  1074. CGAlgorithmsDD.intersection = function intersection (p1, p2, q1, q2) {
  1075. var denom1 = DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(DD.valueOf(p2.x).selfSubtract(p1.x));
  1076. var denom2 = DD.valueOf(q2.x).selfSubtract(q1.x).selfMultiply(DD.valueOf(p2.y).selfSubtract(p1.y));
  1077. var denom = denom1.subtract(denom2);
  1078. var numx1 = DD.valueOf(q2.x).selfSubtract(q1.x).selfMultiply(DD.valueOf(p1.y).selfSubtract(q1.y));
  1079. var numx2 = DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(DD.valueOf(p1.x).selfSubtract(q1.x));
  1080. var numx = numx1.subtract(numx2);
  1081. var fracP = numx.selfDivide(denom).doubleValue();
  1082. var x = DD.valueOf(p1.x).selfAdd(DD.valueOf(p2.x).selfSubtract(p1.x).selfMultiply(fracP)).doubleValue();
  1083. var numy1 = DD.valueOf(p2.x).selfSubtract(p1.x).selfMultiply(DD.valueOf(p1.y).selfSubtract(q1.y));
  1084. var numy2 = DD.valueOf(p2.y).selfSubtract(p1.y).selfMultiply(DD.valueOf(p1.x).selfSubtract(q1.x));
  1085. var numy = numy1.subtract(numy2);
  1086. var fracQ = numy.selfDivide(denom).doubleValue();
  1087. var y = DD.valueOf(q1.y).selfAdd(DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(fracQ)).doubleValue();
  1088. return new Coordinate(x, y)
  1089. };
  1090. CGAlgorithmsDD.orientationIndexFilter = function orientationIndexFilter (pa, pb, pc) {
  1091. var detsum = null;
  1092. var detleft = (pa.x - pc.x) * (pb.y - pc.y);
  1093. var detright = (pa.y - pc.y) * (pb.x - pc.x);
  1094. var det = detleft - detright;
  1095. if (detleft > 0.0) {
  1096. if (detright <= 0.0) {
  1097. return CGAlgorithmsDD.signum(det)
  1098. } else {
  1099. detsum = detleft + detright;
  1100. }
  1101. } else if (detleft < 0.0) {
  1102. if (detright >= 0.0) {
  1103. return CGAlgorithmsDD.signum(det)
  1104. } else {
  1105. detsum = -detleft - detright;
  1106. }
  1107. } else {
  1108. return CGAlgorithmsDD.signum(det)
  1109. }
  1110. var errbound = CGAlgorithmsDD.DP_SAFE_EPSILON * detsum;
  1111. if (det >= errbound || -det >= errbound) {
  1112. return CGAlgorithmsDD.signum(det)
  1113. }
  1114. return 2
  1115. };
  1116. CGAlgorithmsDD.signum = function signum (x) {
  1117. if (x > 0) { return 1 }
  1118. if (x < 0) { return -1 }
  1119. return 0
  1120. };
  1121. staticAccessors$6.DP_SAFE_EPSILON.get = function () { return 1e-15 };
  1122. Object.defineProperties( CGAlgorithmsDD, staticAccessors$6 );
  1123. var CoordinateSequence = function CoordinateSequence () {};
  1124. var staticAccessors$8 = { X: { configurable: true },Y: { configurable: true },Z: { configurable: true },M: { configurable: true } };
  1125. staticAccessors$8.X.get = function () { return 0 };
  1126. staticAccessors$8.Y.get = function () { return 1 };
  1127. staticAccessors$8.Z.get = function () { return 2 };
  1128. staticAccessors$8.M.get = function () { return 3 };
  1129. CoordinateSequence.prototype.setOrdinate = function setOrdinate (index, ordinateIndex, value) {};
  1130. CoordinateSequence.prototype.size = function size () {};
  1131. CoordinateSequence.prototype.getOrdinate = function getOrdinate (index, ordinateIndex) {};
  1132. CoordinateSequence.prototype.getCoordinate = function getCoordinate () {};
  1133. CoordinateSequence.prototype.getCoordinateCopy = function getCoordinateCopy (i) {};
  1134. CoordinateSequence.prototype.getDimension = function getDimension () {};
  1135. CoordinateSequence.prototype.getX = function getX (index) {};
  1136. CoordinateSequence.prototype.clone = function clone () {};
  1137. CoordinateSequence.prototype.expandEnvelope = function expandEnvelope (env) {};
  1138. CoordinateSequence.prototype.copy = function copy () {};
  1139. CoordinateSequence.prototype.getY = function getY (index) {};
  1140. CoordinateSequence.prototype.toCoordinateArray = function toCoordinateArray () {};
  1141. CoordinateSequence.prototype.interfaces_ = function interfaces_ () {
  1142. return [Clonable]
  1143. };
  1144. CoordinateSequence.prototype.getClass = function getClass () {
  1145. return CoordinateSequence
  1146. };
  1147. Object.defineProperties( CoordinateSequence, staticAccessors$8 );
  1148. var Exception = function Exception () {};
  1149. var NotRepresentableException = (function (Exception$$1) {
  1150. function NotRepresentableException () {
  1151. Exception$$1.call(this, 'Projective point not representable on the Cartesian plane.');
  1152. }
  1153. if ( Exception$$1 ) NotRepresentableException.__proto__ = Exception$$1;
  1154. NotRepresentableException.prototype = Object.create( Exception$$1 && Exception$$1.prototype );
  1155. NotRepresentableException.prototype.constructor = NotRepresentableException;
  1156. NotRepresentableException.prototype.interfaces_ = function interfaces_ () {
  1157. return []
  1158. };
  1159. NotRepresentableException.prototype.getClass = function getClass () {
  1160. return NotRepresentableException
  1161. };
  1162. return NotRepresentableException;
  1163. }(Exception));
  1164. var System = function System () {};
  1165. System.arraycopy = function arraycopy (src, srcPos, dest, destPos, len) {
  1166. var c = 0;
  1167. for (var i = srcPos; i < srcPos + len; i++) {
  1168. dest[destPos + c] = src[i];
  1169. c++;
  1170. }
  1171. };
  1172. System.getProperty = function getProperty (name) {
  1173. return {
  1174. 'line.separator': '\n'
  1175. }[name]
  1176. };
  1177. var HCoordinate = function HCoordinate () {
  1178. this.x = null;
  1179. this.y = null;
  1180. this.w = null;
  1181. if (arguments.length === 0) {
  1182. this.x = 0.0;
  1183. this.y = 0.0;
  1184. this.w = 1.0;
  1185. } else if (arguments.length === 1) {
  1186. var p = arguments[0];
  1187. this.x = p.x;
  1188. this.y = p.y;
  1189. this.w = 1.0;
  1190. } else if (arguments.length === 2) {
  1191. if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
  1192. var _x = arguments[0];
  1193. var _y = arguments[1];
  1194. this.x = _x;
  1195. this.y = _y;
  1196. this.w = 1.0;
  1197. } else if (arguments[0] instanceof HCoordinate && arguments[1] instanceof HCoordinate) {
  1198. var p1 = arguments[0];
  1199. var p2 = arguments[1];
  1200. this.x = p1.y * p2.w - p2.y * p1.w;
  1201. this.y = p2.x * p1.w - p1.x * p2.w;
  1202. this.w = p1.x * p2.y - p2.x * p1.y;
  1203. } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {
  1204. var p1$1 = arguments[0];
  1205. var p2$1 = arguments[1];
  1206. this.x = p1$1.y - p2$1.y;
  1207. this.y = p2$1.x - p1$1.x;
  1208. this.w = p1$1.x * p2$1.y - p2$1.x * p1$1.y;
  1209. }
  1210. } else if (arguments.length === 3) {
  1211. var _x$1 = arguments[0];
  1212. var _y$1 = arguments[1];
  1213. var _w = arguments[2];
  1214. this.x = _x$1;
  1215. this.y = _y$1;
  1216. this.w = _w;
  1217. } else if (arguments.length === 4) {
  1218. var p1$2 = arguments[0];
  1219. var p2$2 = arguments[1];
  1220. var q1 = arguments[2];
  1221. var q2 = arguments[3];
  1222. var px = p1$2.y - p2$2.y;
  1223. var py = p2$2.x - p1$2.x;
  1224. var pw = p1$2.x * p2$2.y - p2$2.x * p1$2.y;
  1225. var qx = q1.y - q2.y;
  1226. var qy = q2.x - q1.x;
  1227. var qw = q1.x * q2.y - q2.x * q1.y;
  1228. this.x = py * qw - qy * pw;
  1229. this.y = qx * pw - px * qw;
  1230. this.w = px * qy - qx * py;
  1231. }
  1232. };
  1233. HCoordinate.prototype.getY = function getY () {
  1234. var a = this.y / this.w;
  1235. if (Double.isNaN(a) || Double.isInfinite(a)) {
  1236. throw new NotRepresentableException()
  1237. }
  1238. return a
  1239. };
  1240. HCoordinate.prototype.getX = function getX () {
  1241. var a = this.x / this.w;
  1242. if (Double.isNaN(a) || Double.isInfinite(a)) {
  1243. throw new NotRepresentableException()
  1244. }
  1245. return a
  1246. };
  1247. HCoordinate.prototype.getCoordinate = function getCoordinate () {
  1248. var p = new Coordinate();
  1249. p.x = this.getX();
  1250. p.y = this.getY();
  1251. return p
  1252. };
  1253. HCoordinate.prototype.interfaces_ = function interfaces_ () {
  1254. return []
  1255. };
  1256. HCoordinate.prototype.getClass = function getClass () {
  1257. return HCoordinate
  1258. };
  1259. HCoordinate.intersection = function intersection (p1, p2, q1, q2) {
  1260. var px = p1.y - p2.y;
  1261. var py = p2.x - p1.x;
  1262. var pw = p1.x * p2.y - p2.x * p1.y;
  1263. var qx = q1.y - q2.y;
  1264. var qy = q2.x - q1.x;
  1265. var qw = q1.x * q2.y - q2.x * q1.y;
  1266. var x = py * qw - qy * pw;
  1267. var y = qx * pw - px * qw;
  1268. var w = px * qy - qx * py;
  1269. var xInt = x / w;
  1270. var yInt = y / w;
  1271. if (Double.isNaN(xInt) || (Double.isInfinite(xInt) || Double.isNaN(yInt)) || Double.isInfinite(yInt)) {
  1272. throw new NotRepresentableException()
  1273. }
  1274. return new Coordinate(xInt, yInt)
  1275. };
  1276. var Envelope = function Envelope () {
  1277. this._minx = null;
  1278. this._maxx = null;
  1279. this._miny = null;
  1280. this._maxy = null;
  1281. if (arguments.length === 0) {
  1282. this.init();
  1283. } else if (arguments.length === 1) {
  1284. if (arguments[0] instanceof Coordinate) {
  1285. var p = arguments[0];
  1286. this.init(p.x, p.x, p.y, p.y);
  1287. } else if (arguments[0] instanceof Envelope) {
  1288. var env = arguments[0];
  1289. this.init(env);
  1290. }
  1291. } else if (arguments.length === 2) {
  1292. var p1 = arguments[0];
  1293. var p2 = arguments[1];
  1294. this.init(p1.x, p2.x, p1.y, p2.y);
  1295. } else if (arguments.length === 4) {
  1296. var x1 = arguments[0];
  1297. var x2 = arguments[1];
  1298. var y1 = arguments[2];
  1299. var y2 = arguments[3];
  1300. this.init(x1, x2, y1, y2);
  1301. }
  1302. };
  1303. var staticAccessors$9 = { serialVersionUID: { configurable: true } };
  1304. Envelope.prototype.getArea = function getArea () {
  1305. return this.getWidth() * this.getHeight()
  1306. };
  1307. Envelope.prototype.equals = function equals (other) {
  1308. if (!(other instanceof Envelope)) {
  1309. return false
  1310. }
  1311. var otherEnvelope = other;
  1312. if (this.isNull()) {
  1313. return otherEnvelope.isNull()
  1314. }
  1315. return this._maxx === otherEnvelope.getMaxX() && this._maxy === otherEnvelope.getMaxY() && this._minx === otherEnvelope.getMinX() && this._miny === otherEnvelope.getMinY()
  1316. };
  1317. Envelope.prototype.intersection = function intersection (env) {
  1318. if (this.isNull() || env.isNull() || !this.intersects(env)) { return new Envelope() }
  1319. var intMinX = this._minx > env._minx ? this._minx : env._minx;
  1320. var intMinY = this._miny > env._miny ? this._miny : env._miny;
  1321. var intMaxX = this._maxx < env._maxx ? this._maxx : env._maxx;
  1322. var intMaxY = this._maxy < env._maxy ? this._maxy : env._maxy;
  1323. return new Envelope(intMinX, intMaxX, intMinY, intMaxY)
  1324. };
  1325. Envelope.prototype.isNull = function isNull () {
  1326. return this._maxx < this._minx
  1327. };
  1328. Envelope.prototype.getMaxX = function getMaxX () {
  1329. return this._maxx
  1330. };
  1331. Envelope.prototype.covers = function covers () {
  1332. if (arguments.length === 1) {
  1333. if (arguments[0] instanceof Coordinate) {
  1334. var p = arguments[0];
  1335. return this.covers(p.x, p.y)
  1336. } else if (arguments[0] instanceof Envelope) {
  1337. var other = arguments[0];
  1338. if (this.isNull() || other.isNull()) {
  1339. return false
  1340. }
  1341. return other.getMinX() >= this._minx && other.getMaxX() <= this._maxx && other.getMinY() >= this._miny && other.getMaxY() <= this._maxy
  1342. }
  1343. } else if (arguments.length === 2) {
  1344. var x = arguments[0];
  1345. var y = arguments[1];
  1346. if (this.isNull()) { return false }
  1347. return x >= this._minx && x <= this._maxx && y >= this._miny && y <= this._maxy
  1348. }
  1349. };
  1350. Envelope.prototype.intersects = function intersects () {
  1351. if (arguments.length === 1) {
  1352. if (arguments[0] instanceof Envelope) {
  1353. var other = arguments[0];
  1354. if (this.isNull() || other.isNull()) {
  1355. return false
  1356. }
  1357. return !(other._minx > this._maxx || other._maxx < this._minx || other._miny > this._maxy || other._maxy < this._miny)
  1358. } else if (arguments[0] instanceof Coordinate) {
  1359. var p = arguments[0];
  1360. return this.intersects(p.x, p.y)
  1361. }
  1362. } else if (arguments.length === 2) {
  1363. var x = arguments[0];
  1364. var y = arguments[1];
  1365. if (this.isNull()) { return false }
  1366. return !(x > this._maxx || x < this._minx || y > this._maxy || y < this._miny)
  1367. }
  1368. };
  1369. Envelope.prototype.getMinY = function getMinY () {
  1370. return this._miny
  1371. };
  1372. Envelope.prototype.getMinX = function getMinX () {
  1373. return this._minx
  1374. };
  1375. Envelope.prototype.expandToInclude = function expandToInclude () {
  1376. if (arguments.length === 1) {
  1377. if (arguments[0] instanceof Coordinate) {
  1378. var p = arguments[0];
  1379. this.expandToInclude(p.x, p.y);
  1380. } else if (arguments[0] instanceof Envelope) {
  1381. var other = arguments[0];
  1382. if (other.isNull()) {
  1383. return null
  1384. }
  1385. if (this.isNull()) {
  1386. this._minx = other.getMinX();
  1387. this._maxx = other.getMaxX();
  1388. this._miny = other.getMinY();
  1389. this._maxy = other.getMaxY();
  1390. } else {
  1391. if (other._minx < this._minx) {
  1392. this._minx = other._minx;
  1393. }
  1394. if (other._maxx > this._maxx) {
  1395. this._maxx = other._maxx;
  1396. }
  1397. if (other._miny < this._miny) {
  1398. this._miny = other._miny;
  1399. }
  1400. if (other._maxy > this._maxy) {
  1401. this._maxy = other._maxy;
  1402. }
  1403. }
  1404. }
  1405. } else if (arguments.length === 2) {
  1406. var x = arguments[0];
  1407. var y = arguments[1];
  1408. if (this.isNull()) {
  1409. this._minx = x;
  1410. this._maxx = x;
  1411. this._miny = y;
  1412. this._maxy = y;
  1413. } else {
  1414. if (x < this._minx) {
  1415. this._minx = x;
  1416. }
  1417. if (x > this._maxx) {
  1418. this._maxx = x;
  1419. }
  1420. if (y < this._miny) {
  1421. this._miny = y;
  1422. }
  1423. if (y > this._maxy) {
  1424. this._maxy = y;
  1425. }
  1426. }
  1427. }
  1428. };
  1429. Envelope.prototype.minExtent = function minExtent () {
  1430. if (this.isNull()) { return 0.0 }
  1431. var w = this.getWidth();
  1432. var h = this.getHeight();
  1433. if (w < h) { return w }
  1434. return h
  1435. };
  1436. Envelope.prototype.getWidth = function getWidth () {
  1437. if (this.isNull()) {
  1438. return 0
  1439. }
  1440. return this._maxx - this._minx
  1441. };
  1442. Envelope.prototype.compareTo = function compareTo (o) {
  1443. var env = o;
  1444. if (this.isNull()) {
  1445. if (env.isNull()) { return 0 }
  1446. return -1
  1447. } else {
  1448. if (env.isNull()) { return 1 }
  1449. }
  1450. if (this._minx < env._minx) { return -1 }
  1451. if (this._minx > env._minx) { return 1 }
  1452. if (this._miny < env._miny) { return -1 }
  1453. if (this._miny > env._miny) { return 1 }
  1454. if (this._maxx < env._maxx) { return -1 }
  1455. if (this._maxx > env._maxx) { return 1 }
  1456. if (this._maxy < env._maxy) { return -1 }
  1457. if (this._maxy > env._maxy) { return 1 }
  1458. return 0
  1459. };
  1460. Envelope.prototype.translate = function translate (transX, transY) {
  1461. if (this.isNull()) {
  1462. return null
  1463. }
  1464. this.init(this.getMinX() + transX, this.getMaxX() + transX, this.getMinY() + transY, this.getMaxY() + transY);
  1465. };
  1466. Envelope.prototype.toString = function toString () {
  1467. return 'Env[' + this._minx + ' : ' + this._maxx + ', ' + this._miny + ' : ' + this._maxy + ']'
  1468. };
  1469. Envelope.prototype.setToNull = function setToNull () {
  1470. this._minx = 0;
  1471. this._maxx = -1;
  1472. this._miny = 0;
  1473. this._maxy = -1;
  1474. };
  1475. Envelope.prototype.getHeight = function getHeight () {
  1476. if (this.isNull()) {
  1477. return 0
  1478. }
  1479. return this._maxy - this._miny
  1480. };
  1481. Envelope.prototype.maxExtent = function maxExtent () {
  1482. if (this.isNull()) { return 0.0 }
  1483. var w = this.getWidth();
  1484. var h = this.getHeight();
  1485. if (w > h) { return w }
  1486. return h
  1487. };
  1488. Envelope.prototype.expandBy = function expandBy () {
  1489. if (arguments.length === 1) {
  1490. var distance = arguments[0];
  1491. this.expandBy(distance, distance);
  1492. } else if (arguments.length === 2) {
  1493. var deltaX = arguments[0];
  1494. var deltaY = arguments[1];
  1495. if (this.isNull()) { return null }
  1496. this._minx -= deltaX;
  1497. this._maxx += deltaX;
  1498. this._miny -= deltaY;
  1499. this._maxy += deltaY;
  1500. if (this._minx > this._maxx || this._miny > this._maxy) { this.setToNull(); }
  1501. }
  1502. };
  1503. Envelope.prototype.contains = function contains () {
  1504. if (arguments.length === 1) {
  1505. if (arguments[0] instanceof Envelope) {
  1506. var other = arguments[0];
  1507. return this.covers(other)
  1508. } else if (arguments[0] instanceof Coordinate) {
  1509. var p = arguments[0];
  1510. return this.covers(p)
  1511. }
  1512. } else if (arguments.length === 2) {
  1513. var x = arguments[0];
  1514. var y = arguments[1];
  1515. return this.covers(x, y)
  1516. }
  1517. };
  1518. Envelope.prototype.centre = function centre () {
  1519. if (this.isNull()) { return null }
  1520. return new Coordinate((this.getMinX() + this.getMaxX()) / 2.0, (this.getMinY() + this.getMaxY()) / 2.0)
  1521. };
  1522. Envelope.prototype.init = function init () {
  1523. if (arguments.length === 0) {
  1524. this.setToNull();
  1525. } else if (arguments.length === 1) {
  1526. if (arguments[0] instanceof Coordinate) {
  1527. var p = arguments[0];
  1528. this.init(p.x, p.x, p.y, p.y);
  1529. } else if (arguments[0] instanceof Envelope) {
  1530. var env = arguments[0];
  1531. this._minx = env._minx;
  1532. this._maxx = env._maxx;
  1533. this._miny = env._miny;
  1534. this._maxy = env._maxy;
  1535. }
  1536. } else if (arguments.length === 2) {
  1537. var p1 = arguments[0];
  1538. var p2 = arguments[1];
  1539. this.init(p1.x, p2.x, p1.y, p2.y);
  1540. } else if (arguments.length === 4) {
  1541. var x1 = arguments[0];
  1542. var x2 = arguments[1];
  1543. var y1 = arguments[2];
  1544. var y2 = arguments[3];
  1545. if (x1 < x2) {
  1546. this._minx = x1;
  1547. this._maxx = x2;
  1548. } else {
  1549. this._minx = x2;
  1550. this._maxx = x1;
  1551. }
  1552. if (y1 < y2) {
  1553. this._miny = y1;
  1554. this._maxy = y2;
  1555. } else {
  1556. this._miny = y2;
  1557. this._maxy = y1;
  1558. }
  1559. }
  1560. };
  1561. Envelope.prototype.getMaxY = function getMaxY () {
  1562. return this._maxy
  1563. };
  1564. Envelope.prototype.distance = function distance (env) {
  1565. if (this.intersects(env)) { return 0 }
  1566. var dx = 0.0;
  1567. if (this._maxx < env._minx) { dx = env._minx - this._maxx; } else if (this._minx > env._maxx) { dx = this._minx - env._maxx; }
  1568. var dy = 0.0;
  1569. if (this._maxy < env._miny) { dy = env._miny - this._maxy; } else if (this._miny > env._maxy) { dy = this._miny - env._maxy; }
  1570. if (dx === 0.0) { return dy }
  1571. if (dy === 0.0) { return dx }
  1572. return Math.sqrt(dx * dx + dy * dy)
  1573. };
  1574. Envelope.prototype.hashCode = function hashCode () {
  1575. var result = 17;
  1576. result = 37 * result + Coordinate.hashCode(this._minx);
  1577. result = 37 * result + Coordinate.hashCode(this._maxx);
  1578. result = 37 * result + Coordinate.hashCode(this._miny);
  1579. result = 37 * result + Coordinate.hashCode(this._maxy);
  1580. return result
  1581. };
  1582. Envelope.prototype.interfaces_ = function interfaces_ () {
  1583. return [Comparable, Serializable]
  1584. };
  1585. Envelope.prototype.getClass = function getClass () {
  1586. return Envelope
  1587. };
  1588. Envelope.intersects = function intersects () {
  1589. if (arguments.length === 3) {
  1590. var p1 = arguments[0];
  1591. var p2 = arguments[1];
  1592. var q = arguments[2];
  1593. 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))) {
  1594. return true
  1595. }
  1596. return false
  1597. } else if (arguments.length === 4) {
  1598. var p1$1 = arguments[0];
  1599. var p2$1 = arguments[1];
  1600. var q1 = arguments[2];
  1601. var q2 = arguments[3];
  1602. var minq = Math.min(q1.x, q2.x);
  1603. var maxq = Math.max(q1.x, q2.x);
  1604. var minp = Math.min(p1$1.x, p2$1.x);
  1605. var maxp = Math.max(p1$1.x, p2$1.x);
  1606. if (minp > maxq) { return false }
  1607. if (maxp < minq) { return false }
  1608. minq = Math.min(q1.y, q2.y);
  1609. maxq = Math.max(q1.y, q2.y);
  1610. minp = Math.min(p1$1.y, p2$1.y);
  1611. maxp = Math.max(p1$1.y, p2$1.y);
  1612. if (minp > maxq) { return false }
  1613. if (maxp < minq) { return false }
  1614. return true
  1615. }
  1616. };
  1617. staticAccessors$9.serialVersionUID.get = function () { return 5873921885273102420 };
  1618. Object.defineProperties( Envelope, staticAccessors$9 );
  1619. var regExes = {
  1620. 'typeStr': /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/,
  1621. 'emptyTypeStr': /^\s*(\w+)\s*EMPTY\s*$/,
  1622. 'spaces': /\s+/,
  1623. 'parenComma': /\)\s*,\s*\(/,
  1624. 'doubleParenComma': /\)\s*\)\s*,\s*\(\s*\(/, // can't use {2} here
  1625. 'trimParens': /^\s*\(?(.*?)\)?\s*$/
  1626. };
  1627. /**
  1628. * Class for reading and writing Well-Known Text.
  1629. *
  1630. * NOTE: Adapted from OpenLayers 2.11 implementation.
  1631. */
  1632. /** Create a new parser for WKT
  1633. *
  1634. * @param {GeometryFactory} geometryFactory
  1635. * @return An instance of WKTParser.
  1636. * @constructor
  1637. * @private
  1638. */
  1639. var WKTParser = function WKTParser (geometryFactory) {
  1640. this.geometryFactory = geometryFactory || new GeometryFactory();
  1641. };
  1642. /**
  1643. * Deserialize a WKT string and return a geometry. Supports WKT for POINT,
  1644. * MULTIPOINT, LINESTRING, LINEARRING, MULTILINESTRING, POLYGON, MULTIPOLYGON,
  1645. * and GEOMETRYCOLLECTION.
  1646. *
  1647. * @param {String} wkt A WKT string.
  1648. * @return {Geometry} A geometry instance.
  1649. * @private
  1650. */
  1651. WKTParser.prototype.read = function read (wkt) {
  1652. var geometry, type, str;
  1653. wkt = wkt.replace(/[\n\r]/g, ' ');
  1654. var matches = regExes.typeStr.exec(wkt);
  1655. if (wkt.search('EMPTY') !== -1) {
  1656. matches = regExes.emptyTypeStr.exec(wkt);
  1657. matches[2] = undefined;
  1658. }
  1659. if (matches) {
  1660. type = matches[1].toLowerCase();
  1661. str = matches[2];
  1662. if (parse$1[type]) {
  1663. geometry = parse$1[type].apply(this, [str]);
  1664. }
  1665. }
  1666. if (geometry === undefined) { throw new Error('Could not parse WKT ' + wkt) }
  1667. return geometry
  1668. };
  1669. /**
  1670. * Serialize a geometry into a WKT string.
  1671. *
  1672. * @param {Geometry} geometry A feature or array of features.
  1673. * @return {String} The WKT string representation of the input geometries.
  1674. * @private
  1675. */
  1676. WKTParser.prototype.write = function write (geometry) {
  1677. return this.extractGeometry(geometry)
  1678. };
  1679. /**
  1680. * Entry point to construct the WKT for a single Geometry object.
  1681. *
  1682. * @param {Geometry} geometry
  1683. * @return {String} A WKT string of representing the geometry.
  1684. * @private
  1685. */
  1686. WKTParser.prototype.extractGeometry = function extractGeometry (geometry) {
  1687. var type = geometry.getGeometryType().toLowerCase();
  1688. if (!extract$1[type]) {
  1689. return null
  1690. }
  1691. var wktType = type.toUpperCase();
  1692. var data;
  1693. if (geometry.isEmpty()) {
  1694. data = wktType + ' EMPTY';
  1695. } else {
  1696. data = wktType + '(' + extract$1[type].apply(this, [geometry]) + ')';
  1697. }
  1698. return data
  1699. };
  1700. /**
  1701. * Object with properties corresponding to the geometry types. Property values
  1702. * are functions that do the actual data extraction.
  1703. * @private
  1704. */
  1705. var extract$1 = {
  1706. coordinate: function coordinate (coordinate$1) {
  1707. return coordinate$1.x + ' ' + coordinate$1.y
  1708. },
  1709. /**
  1710. * Return a space delimited string of point coordinates.
  1711. *
  1712. * @param {Point}
  1713. * point
  1714. * @return {String} A string of coordinates representing the point.
  1715. */
  1716. point: function point (point$1) {
  1717. return extract$1.coordinate.call(this, point$1._coordinates._coordinates[0])
  1718. },
  1719. /**
  1720. * Return a comma delimited string of point coordinates from a multipoint.
  1721. *
  1722. * @param {MultiPoint}
  1723. * multipoint
  1724. * @return {String} A string of point coordinate strings representing the
  1725. * multipoint.
  1726. */
  1727. multipoint: function multipoint (multipoint$1) {
  1728. var this$1 = this;
  1729. var array = [];
  1730. for (var i = 0, len = multipoint$1._geometries.length; i < len; ++i) {
  1731. array.push('(' + extract$1.point.apply(this$1, [multipoint$1._geometries[i]]) + ')');
  1732. }
  1733. return array.join(',')
  1734. },
  1735. /**
  1736. * Return a comma delimited string of point coordinates from a line.
  1737. *
  1738. * @param {LineString} linestring
  1739. * @return {String} A string of point coordinate strings representing the linestring.
  1740. */
  1741. linestring: function linestring (linestring$1) {
  1742. var this$1 = this;
  1743. var array = [];
  1744. for (var i = 0, len = linestring$1._points._coordinates.length; i < len; ++i) {
  1745. array.push(extract$1.coordinate.apply(this$1, [linestring$1._points._coordinates[i]]));
  1746. }
  1747. return array.join(',')
  1748. },
  1749. linearring: function linearring (linearring$1) {
  1750. var this$1 = this;
  1751. var array = [];
  1752. for (var i = 0, len = linearring$1._points._coordinates.length; i < len; ++i) {
  1753. array.push(extract$1.coordinate.apply(this$1, [linearring$1._points._coordinates[i]]));
  1754. }
  1755. return array.join(',')
  1756. },
  1757. /**
  1758. * Return a comma delimited string of linestring strings from a
  1759. * multilinestring.
  1760. *
  1761. * @param {MultiLineString} multilinestring
  1762. * @return {String} A string of of linestring strings representing the multilinestring.
  1763. */
  1764. multilinestring: function multilinestring (multilinestring$1) {
  1765. var this$1 = this;
  1766. var array = [];
  1767. for (var i = 0, len = multilinestring$1._geometries.length; i < len; ++i) {
  1768. array.push('(' +
  1769. extract$1.linestring.apply(this$1, [multilinestring$1._geometries[i]]) +
  1770. ')');
  1771. }
  1772. return array.join(',')
  1773. },
  1774. /**
  1775. * Return a comma delimited string of linear ring arrays from a polygon.
  1776. *
  1777. * @param {Polygon} polygon
  1778. * @return {String} An array of linear ring arrays representing the polygon.
  1779. */
  1780. polygon: function polygon (polygon$1) {
  1781. var this$1 = this;
  1782. var array = [];
  1783. array.push('(' + extract$1.linestring.apply(this, [polygon$1._shell]) + ')');
  1784. for (var i = 0, len = polygon$1._holes.length; i < len; ++i) {
  1785. array.push('(' + extract$1.linestring.apply(this$1, [polygon$1._holes[i]]) + ')');
  1786. }
  1787. return array.join(',')
  1788. },
  1789. /**
  1790. * Return an array of polygon arrays from a multipolygon.
  1791. *
  1792. * @param {MultiPolygon} multipolygon
  1793. * @return {String} An array of polygon arrays representing the multipolygon.
  1794. */
  1795. multipolygon: function multipolygon (multipolygon$1) {
  1796. var this$1 = this;
  1797. var array = [];
  1798. for (var i = 0, len = multipolygon$1._geometries.length; i < len; ++i) {
  1799. array.push('(' + extract$1.polygon.apply(this$1, [multipolygon$1._geometries[i]]) + ')');
  1800. }
  1801. return array.join(',')
  1802. },
  1803. /**
  1804. * Return the WKT portion between 'GEOMETRYCOLLECTION(' and ')' for an
  1805. * geometrycollection.
  1806. *
  1807. * @param {GeometryCollection} collection
  1808. * @return {String} internal WKT representation of the collection.
  1809. */
  1810. geometrycollection: function geometrycollection (collection) {
  1811. var this$1 = this;
  1812. var array = [];
  1813. for (var i = 0, len = collection._geometries.length; i < len; ++i) {
  1814. array.push(this$1.extractGeometry(collection._geometries[i]));
  1815. }
  1816. return array.join(',')
  1817. }
  1818. };
  1819. /**
  1820. * Object with properties corresponding to the geometry types. Property values
  1821. * are functions that do the actual parsing.
  1822. * @private
  1823. */
  1824. var parse$1 = {
  1825. /**
  1826. * Return point geometry given a point WKT fragment.
  1827. *
  1828. * @param {String} str A WKT fragment representing the point.
  1829. * @return {Point} A point geometry.
  1830. * @private
  1831. */
  1832. point: function point (str) {
  1833. if (str === undefined) {
  1834. return this.geometryFactory.createPoint()
  1835. }
  1836. var coords = str.trim().split(regExes.spaces);
  1837. return this.geometryFactory.createPoint(new Coordinate(Number.parseFloat(coords[0]),
  1838. Number.parseFloat(coords[1])))
  1839. },
  1840. /**
  1841. * Return a multipoint geometry given a multipoint WKT fragment.
  1842. *
  1843. * @param {String} str A WKT fragment representing the multipoint.
  1844. * @return {Point} A multipoint feature.
  1845. * @private
  1846. */
  1847. multipoint: function multipoint (str) {
  1848. var this$1 = this;
  1849. if (str === undefined) {
  1850. return this.geometryFactory.createMultiPoint()
  1851. }
  1852. var point;
  1853. var points = str.trim().split(',');
  1854. var components = [];
  1855. for (var i = 0, len = points.length; i < len; ++i) {
  1856. point = points[i].replace(regExes.trimParens, '$1');
  1857. components.push(parse$1.point.apply(this$1, [point]));
  1858. }
  1859. return this.geometryFactory.createMultiPoint(components)
  1860. },
  1861. /**
  1862. * Return a linestring geometry given a linestring WKT fragment.
  1863. *
  1864. * @param {String} str A WKT fragment representing the linestring.
  1865. * @return {LineString} A linestring geometry.
  1866. * @private
  1867. */
  1868. linestring: function linestring (str) {
  1869. if (str === undefined) {
  1870. return this.geometryFactory.createLineString()
  1871. }
  1872. var points = str.trim().split(',');
  1873. var components = [];
  1874. var coords;
  1875. for (var i = 0, len = points.length; i < len; ++i) {
  1876. coords = points[i].trim().split(regExes.spaces);
  1877. components.push(new Coordinate(Number.parseFloat(coords[0]), Number.parseFloat(coords[1])));
  1878. }
  1879. return this.geometryFactory.createLineString(components)
  1880. },
  1881. /**
  1882. * Return a linearring geometry given a linearring WKT fragment.
  1883. *
  1884. * @param {String} str A WKT fragment representing the linearring.
  1885. * @return {LinearRing} A linearring geometry.
  1886. * @private
  1887. */
  1888. linearring: function linearring (str) {
  1889. if (str === undefined) {
  1890. return this.geometryFactory.createLinearRing()
  1891. }
  1892. var points = str.trim().split(',');
  1893. var components = [];
  1894. var coords;
  1895. for (var i = 0, len = points.length; i < len; ++i) {
  1896. coords = points[i].trim().split(regExes.spaces);
  1897. components.push(new Coordinate(Number.parseFloat(coords[0]), Number.parseFloat(coords[1])));
  1898. }
  1899. return this.geometryFactory.createLinearRing(components)
  1900. },
  1901. /**
  1902. * Return a multilinestring geometry given a multilinestring WKT fragment.
  1903. *
  1904. * @param {String} str A WKT fragment representing the multilinestring.
  1905. * @return {MultiLineString} A multilinestring geometry.
  1906. * @private
  1907. */
  1908. multilinestring: function multilinestring (str) {
  1909. var this$1 = this;
  1910. if (str === undefined) {
  1911. return this.geometryFactory.createMultiLineString()
  1912. }
  1913. var line;
  1914. var lines = str.trim().split(regExes.parenComma);
  1915. var components = [];
  1916. for (var i = 0, len = lines.length; i < len; ++i) {
  1917. line = lines[i].replace(regExes.trimParens, '$1');
  1918. components.push(parse$1.linestring.apply(this$1, [line]));
  1919. }
  1920. return this.geometryFactory.createMultiLineString(components)
  1921. },
  1922. /**
  1923. * Return a polygon geometry given a polygon WKT fragment.
  1924. *
  1925. * @param {String} str A WKT fragment representing the polygon.
  1926. * @return {Polygon} A polygon geometry.
  1927. * @private
  1928. */
  1929. polygon: function polygon (str) {
  1930. var this$1 = this;
  1931. if (str === undefined) {
  1932. return this.geometryFactory.createPolygon()
  1933. }
  1934. var ring, linestring, linearring;
  1935. var rings = str.trim().split(regExes.parenComma);
  1936. var shell;
  1937. var holes = [];
  1938. for (var i = 0, len = rings.length; i < len; ++i) {
  1939. ring = rings[i].replace(regExes.trimParens, '$1');
  1940. linestring = parse$1.linestring.apply(this$1, [ring]);
  1941. linearring = this$1.geometryFactory.createLinearRing(linestring._points);
  1942. if (i === 0) {
  1943. shell = linearring;
  1944. } else {
  1945. holes.push(linearring);
  1946. }
  1947. }
  1948. return this.geometryFactory.createPolygon(shell, holes)
  1949. },
  1950. /**
  1951. * Return a multipolygon geometry given a multipolygon WKT fragment.
  1952. *
  1953. * @param {String} str A WKT fragment representing the multipolygon.
  1954. * @return {MultiPolygon} A multipolygon geometry.
  1955. * @private
  1956. */
  1957. multipolygon: function multipolygon (str) {
  1958. var this$1 = this;
  1959. if (str === undefined) {
  1960. return this.geometryFactory.createMultiPolygon()
  1961. }
  1962. var polygon;
  1963. var polygons = str.trim().split(regExes.doubleParenComma);
  1964. var components = [];
  1965. for (var i = 0, len = polygons.length; i < len; ++i) {
  1966. polygon = polygons[i].replace(regExes.trimParens, '$1');
  1967. components.push(parse$1.polygon.apply(this$1, [polygon]));
  1968. }
  1969. return this.geometryFactory.createMultiPolygon(components)
  1970. },
  1971. /**
  1972. * Return a geometrycollection given a geometrycollection WKT fragment.
  1973. *
  1974. * @param {String} str A WKT fragment representing the geometrycollection.
  1975. * @return {GeometryCollection}
  1976. * @private
  1977. */
  1978. geometrycollection: function geometrycollection (str) {
  1979. var this$1 = this;
  1980. if (str === undefined) {
  1981. return this.geometryFactory.createGeometryCollection()
  1982. }
  1983. // separate components of the collection with |
  1984. str = str.replace(/,\s*([A-Za-z])/g, '|$1');
  1985. var wktArray = str.trim().split('|');
  1986. var components = [];
  1987. for (var i = 0, len = wktArray.length; i < len; ++i) {
  1988. components.push(this$1.read(wktArray[i]));
  1989. }
  1990. return this.geometryFactory.createGeometryCollection(components)
  1991. }
  1992. };
  1993. /**
  1994. * Writes the Well-Known Text representation of a {@link Geometry}. The
  1995. * Well-Known Text format is defined in the <A
  1996. * HREF="http://www.opengis.org/techno/specs.htm"> OGC Simple Features
  1997. * Specification for SQL</A>.
  1998. * <p>
  1999. * The <code>WKTWriter</code> outputs coordinates rounded to the precision
  2000. * model. Only the maximum number of decimal places necessary to represent the
  2001. * ordinates to the required precision will be output.
  2002. * <p>
  2003. * The SFS WKT spec does not define a special tag for {@link LinearRing}s.
  2004. * Under the spec, rings are output as <code>LINESTRING</code>s.
  2005. */
  2006. /**
  2007. * @param {GeometryFactory} geometryFactory
  2008. * @constructor
  2009. */
  2010. var WKTWriter = function WKTWriter (geometryFactory) {
  2011. this.parser = new WKTParser(geometryFactory);
  2012. };
  2013. /**
  2014. * Converts a <code>Geometry</code> to its Well-known Text representation.
  2015. *
  2016. * @param {Geometry} geometry a <code>Geometry</code> to process.
  2017. * @return {string} a <Geometry Tagged Text> string (see the OpenGIS Simple
  2018. * Features Specification).
  2019. * @memberof WKTWriter
  2020. */
  2021. WKTWriter.prototype.write = function write (geometry) {
  2022. return this.parser.write(geometry)
  2023. };
  2024. /**
  2025. * Generates the WKT for a <tt>LINESTRING</tt> specified by two
  2026. * {@link Coordinate}s.
  2027. *
  2028. * @param p0 the first coordinate.
  2029. * @param p1 the second coordinate.
  2030. *
  2031. * @return the WKT.
  2032. * @private
  2033. */
  2034. WKTWriter.toLineString = function toLineString (p0, p1) {
  2035. if (arguments.length !== 2) {
  2036. throw new Error('Not implemented')
  2037. }
  2038. return 'LINESTRING ( ' + p0.x + ' ' + p0.y + ', ' + p1.x + ' ' + p1.y + ' )'
  2039. };
  2040. var RuntimeException = (function (Error) {
  2041. function RuntimeException (message) {
  2042. Error.call(this, message);
  2043. this.name = 'RuntimeException';
  2044. this.message = message;
  2045. this.stack = (new Error()).stack;
  2046. }
  2047. if ( Error ) RuntimeException.__proto__ = Error;
  2048. RuntimeException.prototype = Object.create( Error && Error.prototype );
  2049. RuntimeException.prototype.constructor = RuntimeException;
  2050. return RuntimeException;
  2051. }(Error));
  2052. var AssertionFailedException = (function (RuntimeException$$1) {
  2053. function AssertionFailedException () {
  2054. RuntimeException$$1.call(this);
  2055. if (arguments.length === 0) {
  2056. RuntimeException$$1.call(this);
  2057. } else if (arguments.length === 1) {
  2058. var message = arguments[0];
  2059. RuntimeException$$1.call(this, message);
  2060. }
  2061. }
  2062. if ( RuntimeException$$1 ) AssertionFailedException.__proto__ = RuntimeException$$1;
  2063. AssertionFailedException.prototype = Object.create( RuntimeException$$1 && RuntimeException$$1.prototype );
  2064. AssertionFailedException.prototype.constructor = AssertionFailedException;
  2065. AssertionFailedException.prototype.interfaces_ = function interfaces_ () {
  2066. return []
  2067. };
  2068. AssertionFailedException.prototype.getClass = function getClass () {
  2069. return AssertionFailedException
  2070. };
  2071. return AssertionFailedException;
  2072. }(RuntimeException));
  2073. var Assert = function Assert () {};
  2074. Assert.prototype.interfaces_ = function interfaces_ () {
  2075. return []
  2076. };
  2077. Assert.prototype.getClass = function getClass () {
  2078. return Assert
  2079. };
  2080. Assert.shouldNeverReachHere = function shouldNeverReachHere () {
  2081. if (arguments.length === 0) {
  2082. Assert.shouldNeverReachHere(null);
  2083. } else if (arguments.length === 1) {
  2084. var message = arguments[0];
  2085. throw new AssertionFailedException('Should never reach here' + (message !== null ? ': ' + message : ''))
  2086. }
  2087. };
  2088. Assert.isTrue = function isTrue () {
  2089. var assertion;
  2090. var message;
  2091. if (arguments.length === 1) {
  2092. assertion = arguments[0];
  2093. Assert.isTrue(assertion, null);
  2094. } else if (arguments.length === 2) {
  2095. assertion = arguments[0];
  2096. message = arguments[1];
  2097. if (!assertion) {
  2098. if (message === null) {
  2099. throw new AssertionFailedException()
  2100. } else {
  2101. throw new AssertionFailedException(message)
  2102. }
  2103. }
  2104. }
  2105. };
  2106. Assert.equals = function equals () {
  2107. var expectedValue;
  2108. var actualValue;
  2109. var message;
  2110. if (arguments.length === 2) {
  2111. expectedValue = arguments[0];
  2112. actualValue = arguments[1];
  2113. Assert.equals(expectedValue, actualValue, null);
  2114. } else if (arguments.length === 3) {
  2115. expectedValue = arguments[0];
  2116. actualValue = arguments[1];
  2117. message = arguments[2];
  2118. if (!actualValue.equals(expectedValue)) {
  2119. throw new AssertionFailedException('Expected ' + expectedValue + ' but encountered ' + actualValue + (message !== null ? ': ' + message : ''))
  2120. }
  2121. }
  2122. };
  2123. var LineIntersector = function LineIntersector () {
  2124. this._result = null;
  2125. this._inputLines = Array(2).fill().map(function () { return Array(2); });
  2126. this._intPt = new Array(2).fill(null);
  2127. this._intLineIndex = null;
  2128. this._isProper = null;
  2129. this._pa = null;
  2130. this._pb = null;
  2131. this._precisionModel = null;
  2132. this._intPt[0] = new Coordinate();
  2133. this._intPt[1] = new Coordinate();
  2134. this._pa = this._intPt[0];
  2135. this._pb = this._intPt[1];
  2136. this._result = 0;
  2137. };
  2138. 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 } };
  2139. LineIntersector.prototype.getIndexAlongSegment = function getIndexAlongSegment (segmentIndex, intIndex) {
  2140. this.computeIntLineIndex();
  2141. return this._intLineIndex[segmentIndex][intIndex]
  2142. };
  2143. LineIntersector.prototype.getTopologySummary = function getTopologySummary () {
  2144. var catBuf = new StringBuffer();
  2145. if (this.isEndPoint()) { catBuf.append(' endpoint'); }
  2146. if (this._isProper) { catBuf.append(' proper'); }
  2147. if (this.isCollinear()) { catBuf.append(' collinear'); }
  2148. return catBuf.toString()
  2149. };
  2150. LineIntersector.prototype.computeIntersection = function computeIntersection (p1, p2, p3, p4) {
  2151. this._inputLines[0][0] = p1;
  2152. this._inputLines[0][1] = p2;
  2153. this._inputLines[1][0] = p3;
  2154. this._inputLines[1][1] = p4;
  2155. this._result = this.computeIntersect(p1, p2, p3, p4);
  2156. };
  2157. LineIntersector.prototype.getIntersectionNum = function getIntersectionNum () {
  2158. return this._result
  2159. };
  2160. LineIntersector.prototype.computeIntLineIndex = function computeIntLineIndex () {
  2161. if (arguments.length === 0) {
  2162. if (this._intLineIndex === null) {
  2163. this._intLineIndex = Array(2).fill().map(function () { return Array(2); });
  2164. this.computeIntLineIndex(0);
  2165. this.computeIntLineIndex(1);
  2166. }
  2167. } else if (arguments.length === 1) {
  2168. var segmentIndex = arguments[0];
  2169. var dist0 = this.getEdgeDistance(segmentIndex, 0);
  2170. var dist1 = this.getEdgeDistance(segmentIndex, 1);
  2171. if (dist0 > dist1) {
  2172. this._intLineIndex[segmentIndex][0] = 0;
  2173. this._intLineIndex[segmentIndex][1] = 1;
  2174. } else {
  2175. this._intLineIndex[segmentIndex][0] = 1;
  2176. this._intLineIndex[segmentIndex][1] = 0;
  2177. }
  2178. }
  2179. };
  2180. LineIntersector.prototype.isProper = function isProper () {
  2181. return this.hasIntersection() && this._isProper
  2182. };
  2183. LineIntersector.prototype.setPrecisionModel = function setPrecisionModel (precisionModel) {
  2184. this._precisionModel = precisionModel;
  2185. };
  2186. LineIntersector.prototype.isInteriorIntersection = function isInteriorIntersection () {
  2187. var this$1 = this;
  2188. if (arguments.length === 0) {
  2189. if (this.isInteriorIntersection(0)) { return true }
  2190. if (this.isInteriorIntersection(1)) { return true }
  2191. return false
  2192. } else if (arguments.length === 1) {
  2193. var inputLineIndex = arguments[0];
  2194. for (var i = 0; i < this._result; i++) {
  2195. if (!(this$1._intPt[i].equals2D(this$1._inputLines[inputLineIndex][0]) || this$1._intPt[i].equals2D(this$1._inputLines[inputLineIndex][1]))) {
  2196. return true
  2197. }
  2198. }
  2199. return false
  2200. }
  2201. };
  2202. LineIntersector.prototype.getIntersection = function getIntersection (intIndex) {
  2203. return this._intPt[intIndex]
  2204. };
  2205. LineIntersector.prototype.isEndPoint = function isEndPoint () {
  2206. return this.hasIntersection() && !this._isProper
  2207. };
  2208. LineIntersector.prototype.hasIntersection = function hasIntersection () {
  2209. return this._result !== LineIntersector.NO_INTERSECTION
  2210. };
  2211. LineIntersector.prototype.getEdgeDistance = function getEdgeDistance (segmentIndex, intIndex) {
  2212. var dist = LineIntersector.computeEdgeDistance(this._intPt[intIndex], this._inputLines[segmentIndex][0], this._inputLines[segmentIndex][1]);
  2213. return dist
  2214. };
  2215. LineIntersector.prototype.isCollinear = function isCollinear () {
  2216. return this._result === LineIntersector.COLLINEAR_INTERSECTION
  2217. };
  2218. LineIntersector.prototype.toString = function toString () {
  2219. return WKTWriter.toLineString(this._inputLines[0][0], this._inputLines[0][1]) + ' - ' + WKTWriter.toLineString(this._inputLines[1][0], this._inputLines[1][1]) + this.getTopologySummary()
  2220. };
  2221. LineIntersector.prototype.getEndpoint = function getEndpoint (segmentIndex, ptIndex) {
  2222. return this._inputLines[segmentIndex][ptIndex]
  2223. };
  2224. LineIntersector.prototype.isIntersection = function isIntersection (pt) {
  2225. var this$1 = this;
  2226. for (var i = 0; i < this._result; i++) {
  2227. if (this$1._intPt[i].equals2D(pt)) {
  2228. return true
  2229. }
  2230. }
  2231. return false
  2232. };
  2233. LineIntersector.prototype.getIntersectionAlongSegment = function getIntersectionAlongSegment (segmentIndex, intIndex) {
  2234. this.computeIntLineIndex();
  2235. return this._intPt[this._intLineIndex[segmentIndex][intIndex]]
  2236. };
  2237. LineIntersector.prototype.interfaces_ = function interfaces_ () {
  2238. return []
  2239. };
  2240. LineIntersector.prototype.getClass = function getClass () {
  2241. return LineIntersector
  2242. };
  2243. LineIntersector.computeEdgeDistance = function computeEdgeDistance (p, p0, p1) {
  2244. var dx = Math.abs(p1.x - p0.x);
  2245. var dy = Math.abs(p1.y - p0.y);
  2246. var dist = -1.0;
  2247. if (p.equals(p0)) {
  2248. dist = 0.0;
  2249. } else if (p.equals(p1)) {
  2250. if (dx > dy) { dist = dx; } else { dist = dy; }
  2251. } else {
  2252. var pdx = Math.abs(p.x - p0.x);
  2253. var pdy = Math.abs(p.y - p0.y);
  2254. if (dx > dy) { dist = pdx; } else { dist = pdy; }
  2255. if (dist === 0.0 && !p.equals(p0)) {
  2256. dist = Math.max(pdx, pdy);
  2257. }
  2258. }
  2259. Assert.isTrue(!(dist === 0.0 && !p.equals(p0)), 'Bad distance calculation');
  2260. return dist
  2261. };
  2262. LineIntersector.nonRobustComputeEdgeDistance = function nonRobustComputeEdgeDistance (p, p1, p2) {
  2263. var dx = p.x - p1.x;
  2264. var dy = p.y - p1.y;
  2265. var dist = Math.sqrt(dx * dx + dy * dy);
  2266. Assert.isTrue(!(dist === 0.0 && !p.equals(p1)), 'Invalid distance calculation');
  2267. return dist
  2268. };
  2269. staticAccessors$10.DONT_INTERSECT.get = function () { return 0 };
  2270. staticAccessors$10.DO_INTERSECT.get = function () { return 1 };
  2271. staticAccessors$10.COLLINEAR.get = function () { return 2 };
  2272. staticAccessors$10.NO_INTERSECTION.get = function () { return 0 };
  2273. staticAccessors$10.POINT_INTERSECTION.get = function () { return 1 };
  2274. staticAccessors$10.COLLINEAR_INTERSECTION.get = function () { return 2 };
  2275. Object.defineProperties( LineIntersector, staticAccessors$10 );
  2276. var RobustLineIntersector = (function (LineIntersector$$1) {
  2277. function RobustLineIntersector () {
  2278. LineIntersector$$1.apply(this, arguments);
  2279. }
  2280. if ( LineIntersector$$1 ) RobustLineIntersector.__proto__ = LineIntersector$$1;
  2281. RobustLineIntersector.prototype = Object.create( LineIntersector$$1 && LineIntersector$$1.prototype );
  2282. RobustLineIntersector.prototype.constructor = RobustLineIntersector;
  2283. RobustLineIntersector.prototype.isInSegmentEnvelopes = function isInSegmentEnvelopes (intPt) {
  2284. var env0 = new Envelope(this._inputLines[0][0], this._inputLines[0][1]);
  2285. var env1 = new Envelope(this._inputLines[1][0], this._inputLines[1][1]);
  2286. return env0.contains(intPt) && env1.contains(intPt)
  2287. };
  2288. RobustLineIntersector.prototype.computeIntersection = function computeIntersection () {
  2289. if (arguments.length === 3) {
  2290. var p = arguments[0];
  2291. var p1 = arguments[1];
  2292. var p2 = arguments[2];
  2293. this._isProper = false;
  2294. if (Envelope.intersects(p1, p2, p)) {
  2295. if (CGAlgorithms.orientationIndex(p1, p2, p) === 0 && CGAlgorithms.orientationIndex(p2, p1, p) === 0) {
  2296. this._isProper = true;
  2297. if (p.equals(p1) || p.equals(p2)) {
  2298. this._isProper = false;
  2299. }
  2300. this._result = LineIntersector$$1.POINT_INTERSECTION;
  2301. return null
  2302. }
  2303. }
  2304. this._result = LineIntersector$$1.NO_INTERSECTION;
  2305. } else { return LineIntersector$$1.prototype.computeIntersection.apply(this, arguments) }
  2306. };
  2307. RobustLineIntersector.prototype.normalizeToMinimum = function normalizeToMinimum (n1, n2, n3, n4, normPt) {
  2308. normPt.x = this.smallestInAbsValue(n1.x, n2.x, n3.x, n4.x);
  2309. normPt.y = this.smallestInAbsValue(n1.y, n2.y, n3.y, n4.y);
  2310. n1.x -= normPt.x;
  2311. n1.y -= normPt.y;
  2312. n2.x -= normPt.x;
  2313. n2.y -= normPt.y;
  2314. n3.x -= normPt.x;
  2315. n3.y -= normPt.y;
  2316. n4.x -= normPt.x;
  2317. n4.y -= normPt.y;
  2318. };
  2319. RobustLineIntersector.prototype.safeHCoordinateIntersection = function safeHCoordinateIntersection (p1, p2, q1, q2) {
  2320. var intPt = null;
  2321. try {
  2322. intPt = HCoordinate.intersection(p1, p2, q1, q2);
  2323. } catch (e) {
  2324. if (e instanceof NotRepresentableException) {
  2325. intPt = RobustLineIntersector.nearestEndpoint(p1, p2, q1, q2);
  2326. } else { throw e }
  2327. } finally {}
  2328. return intPt
  2329. };
  2330. RobustLineIntersector.prototype.intersection = function intersection (p1, p2, q1, q2) {
  2331. var intPt = this.intersectionWithNormalization(p1, p2, q1, q2);
  2332. if (!this.isInSegmentEnvelopes(intPt)) {
  2333. intPt = new Coordinate(RobustLineIntersector.nearestEndpoint(p1, p2, q1, q2));
  2334. }
  2335. if (this._precisionModel !== null) {
  2336. this._precisionModel.makePrecise(intPt);
  2337. }
  2338. return intPt
  2339. };
  2340. RobustLineIntersector.prototype.smallestInAbsValue = function smallestInAbsValue (x1, x2, x3, x4) {
  2341. var x = x1;
  2342. var xabs = Math.abs(x);
  2343. if (Math.abs(x2) < xabs) {
  2344. x = x2;
  2345. xabs = Math.abs(x2);
  2346. }
  2347. if (Math.abs(x3) < xabs) {
  2348. x = x3;
  2349. xabs = Math.abs(x3);
  2350. }
  2351. if (Math.abs(x4) < xabs) {
  2352. x = x4;
  2353. }
  2354. return x
  2355. };
  2356. RobustLineIntersector.prototype.checkDD = function checkDD (p1, p2, q1, q2, intPt) {
  2357. var intPtDD = CGAlgorithmsDD.intersection(p1, p2, q1, q2);
  2358. var isIn = this.isInSegmentEnvelopes(intPtDD);
  2359. System.out.println('DD in env = ' + isIn + ' --------------------- ' + intPtDD);
  2360. if (intPt.distance(intPtDD) > 0.0001) {
  2361. System.out.println('Distance = ' + intPt.distance(intPtDD));
  2362. }
  2363. };
  2364. RobustLineIntersector.prototype.intersectionWithNormalization = function intersectionWithNormalization (p1, p2, q1, q2) {
  2365. var n1 = new Coordinate(p1);
  2366. var n2 = new Coordinate(p2);
  2367. var n3 = new Coordinate(q1);
  2368. var n4 = new Coordinate(q2);
  2369. var normPt = new Coordinate();
  2370. this.normalizeToEnvCentre(n1, n2, n3, n4, normPt);
  2371. var intPt = this.safeHCoordinateIntersection(n1, n2, n3, n4);
  2372. intPt.x += normPt.x;
  2373. intPt.y += normPt.y;
  2374. return intPt
  2375. };
  2376. RobustLineIntersector.prototype.computeCollinearIntersection = function computeCollinearIntersection (p1, p2, q1, q2) {
  2377. var p1q1p2 = Envelope.intersects(p1, p2, q1);
  2378. var p1q2p2 = Envelope.intersects(p1, p2, q2);
  2379. var q1p1q2 = Envelope.intersects(q1, q2, p1);
  2380. var q1p2q2 = Envelope.intersects(q1, q2, p2);
  2381. if (p1q1p2 && p1q2p2) {
  2382. this._intPt[0] = q1;
  2383. this._intPt[1] = q2;
  2384. return LineIntersector$$1.COLLINEAR_INTERSECTION
  2385. }
  2386. if (q1p1q2 && q1p2q2) {
  2387. this._intPt[0] = p1;
  2388. this._intPt[1] = p2;
  2389. return LineIntersector$$1.COLLINEAR_INTERSECTION
  2390. }
  2391. if (p1q1p2 && q1p1q2) {
  2392. this._intPt[0] = q1;
  2393. this._intPt[1] = p1;
  2394. return q1.equals(p1) && !p1q2p2 && !q1p2q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
  2395. }
  2396. if (p1q1p2 && q1p2q2) {
  2397. this._intPt[0] = q1;
  2398. this._intPt[1] = p2;
  2399. return q1.equals(p2) && !p1q2p2 && !q1p1q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
  2400. }
  2401. if (p1q2p2 && q1p1q2) {
  2402. this._intPt[0] = q2;
  2403. this._intPt[1] = p1;
  2404. return q2.equals(p1) && !p1q1p2 && !q1p2q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
  2405. }
  2406. if (p1q2p2 && q1p2q2) {
  2407. this._intPt[0] = q2;
  2408. this._intPt[1] = p2;
  2409. return q2.equals(p2) && !p1q1p2 && !q1p1q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
  2410. }
  2411. return LineIntersector$$1.NO_INTERSECTION
  2412. };
  2413. RobustLineIntersector.prototype.normalizeToEnvCentre = function normalizeToEnvCentre (n00, n01, n10, n11, normPt) {
  2414. var minX0 = n00.x < n01.x ? n00.x : n01.x;
  2415. var minY0 = n00.y < n01.y ? n00.y : n01.y;
  2416. var maxX0 = n00.x > n01.x ? n00.x : n01.x;
  2417. var maxY0 = n00.y > n01.y ? n00.y : n01.y;
  2418. var minX1 = n10.x < n11.x ? n10.x : n11.x;
  2419. var minY1 = n10.y < n11.y ? n10.y : n11.y;
  2420. var maxX1 = n10.x > n11.x ? n10.x : n11.x;
  2421. var maxY1 = n10.y > n11.y ? n10.y : n11.y;
  2422. var intMinX = minX0 > minX1 ? minX0 : minX1;
  2423. var intMaxX = maxX0 < maxX1 ? maxX0 : maxX1;
  2424. var intMinY = minY0 > minY1 ? minY0 : minY1;
  2425. var intMaxY = maxY0 < maxY1 ? maxY0 : maxY1;
  2426. var intMidX = (intMinX + intMaxX) / 2.0;
  2427. var intMidY = (intMinY + intMaxY) / 2.0;
  2428. normPt.x = intMidX;
  2429. normPt.y = intMidY;
  2430. n00.x -= normPt.x;
  2431. n00.y -= normPt.y;
  2432. n01.x -= normPt.x;
  2433. n01.y -= normPt.y;
  2434. n10.x -= normPt.x;
  2435. n10.y -= normPt.y;
  2436. n11.x -= normPt.x;
  2437. n11.y -= normPt.y;
  2438. };
  2439. RobustLineIntersector.prototype.computeIntersect = function computeIntersect (p1, p2, q1, q2) {
  2440. this._isProper = false;
  2441. if (!Envelope.intersects(p1, p2, q1, q2)) { return LineIntersector$$1.NO_INTERSECTION }
  2442. var Pq1 = CGAlgorithms.orientationIndex(p1, p2, q1);
  2443. var Pq2 = CGAlgorithms.orientationIndex(p1, p2, q2);
  2444. if ((Pq1 > 0 && Pq2 > 0) || (Pq1 < 0 && Pq2 < 0)) {
  2445. return LineIntersector$$1.NO_INTERSECTION
  2446. }
  2447. var Qp1 = CGAlgorithms.orientationIndex(q1, q2, p1);
  2448. var Qp2 = CGAlgorithms.orientationIndex(q1, q2, p2);
  2449. if ((Qp1 > 0 && Qp2 > 0) || (Qp1 < 0 && Qp2 < 0)) {
  2450. return LineIntersector$$1.NO_INTERSECTION
  2451. }
  2452. var collinear = Pq1 === 0 && Pq2 === 0 && Qp1 === 0 && Qp2 === 0;
  2453. if (collinear) {
  2454. return this.computeCollinearIntersection(p1, p2, q1, q2)
  2455. }
  2456. if (Pq1 === 0 || Pq2 === 0 || Qp1 === 0 || Qp2 === 0) {
  2457. this._isProper = false;
  2458. if (p1.equals2D(q1) || p1.equals2D(q2)) {
  2459. this._intPt[0] = p1;
  2460. } else if (p2.equals2D(q1) || p2.equals2D(q2)) {
  2461. this._intPt[0] = p2;
  2462. } else if (Pq1 === 0) {
  2463. this._intPt[0] = new Coordinate(q1);
  2464. } else if (Pq2 === 0) {
  2465. this._intPt[0] = new Coordinate(q2);
  2466. } else if (Qp1 === 0) {
  2467. this._intPt[0] = new Coordinate(p1);
  2468. } else if (Qp2 === 0) {
  2469. this._intPt[0] = new Coordinate(p2);
  2470. }
  2471. } else {
  2472. this._isProper = true;
  2473. this._intPt[0] = this.intersection(p1, p2, q1, q2);
  2474. }
  2475. return LineIntersector$$1.POINT_INTERSECTION
  2476. };
  2477. RobustLineIntersector.prototype.interfaces_ = function interfaces_ () {
  2478. return []
  2479. };
  2480. RobustLineIntersector.prototype.getClass = function getClass () {
  2481. return RobustLineIntersector
  2482. };
  2483. RobustLineIntersector.nearestEndpoint = function nearestEndpoint (p1, p2, q1, q2) {
  2484. var nearestPt = p1;
  2485. var minDist = CGAlgorithms.distancePointLine(p1, q1, q2);
  2486. var dist = CGAlgorithms.distancePointLine(p2, q1, q2);
  2487. if (dist < minDist) {
  2488. minDist = dist;
  2489. nearestPt = p2;
  2490. }
  2491. dist = CGAlgorithms.distancePointLine(q1, p1, p2);
  2492. if (dist < minDist) {
  2493. minDist = dist;
  2494. nearestPt = q1;
  2495. }
  2496. dist = CGAlgorithms.distancePointLine(q2, p1, p2);
  2497. if (dist < minDist) {
  2498. minDist = dist;
  2499. nearestPt = q2;
  2500. }
  2501. return nearestPt
  2502. };
  2503. return RobustLineIntersector;
  2504. }(LineIntersector));
  2505. var RobustDeterminant = function RobustDeterminant () {};
  2506. RobustDeterminant.prototype.interfaces_ = function interfaces_ () {
  2507. return []
  2508. };
  2509. RobustDeterminant.prototype.getClass = function getClass () {
  2510. return RobustDeterminant
  2511. };
  2512. RobustDeterminant.orientationIndex = function orientationIndex (p1, p2, q) {
  2513. var dx1 = p2.x - p1.x;
  2514. var dy1 = p2.y - p1.y;
  2515. var dx2 = q.x - p2.x;
  2516. var dy2 = q.y - p2.y;
  2517. return RobustDeterminant.signOfDet2x2(dx1, dy1, dx2, dy2)
  2518. };
  2519. RobustDeterminant.signOfDet2x2 = function signOfDet2x2 (x1, y1, x2, y2) {
  2520. var sign = null;
  2521. var swap = null;
  2522. var k = null;
  2523. sign = 1;
  2524. if (x1 === 0.0 || y2 === 0.0) {
  2525. if (y1 === 0.0 || x2 === 0.0) {
  2526. return 0
  2527. } else if (y1 > 0) {
  2528. if (x2 > 0) {
  2529. return -sign
  2530. } else {
  2531. return sign
  2532. }
  2533. } else {
  2534. if (x2 > 0) {
  2535. return sign
  2536. } else {
  2537. return -sign
  2538. }
  2539. }
  2540. }
  2541. if (y1 === 0.0 || x2 === 0.0) {
  2542. if (y2 > 0) {
  2543. if (x1 > 0) {
  2544. return sign
  2545. } else {
  2546. return -sign
  2547. }
  2548. } else {
  2549. if (x1 > 0) {
  2550. return -sign
  2551. } else {
  2552. return sign
  2553. }
  2554. }
  2555. }
  2556. if (y1 > 0.0) {
  2557. if (y2 > 0.0) {
  2558. if (y1 <= y2) {
  2559. } else {
  2560. sign = -sign;
  2561. swap = x1;
  2562. x1 = x2;
  2563. x2 = swap;
  2564. swap = y1;
  2565. y1 = y2;
  2566. y2 = swap;
  2567. }
  2568. } else {
  2569. if (y1 <= -y2) {
  2570. sign = -sign;
  2571. x2 = -x2;
  2572. y2 = -y2;
  2573. } else {
  2574. swap = x1;
  2575. x1 = -x2;
  2576. x2 = swap;
  2577. swap = y1;
  2578. y1 = -y2;
  2579. y2 = swap;
  2580. }
  2581. }
  2582. } else {
  2583. if (y2 > 0.0) {
  2584. if (-y1 <= y2) {
  2585. sign = -sign;
  2586. x1 = -x1;
  2587. y1 = -y1;
  2588. } else {
  2589. swap = -x1;
  2590. x1 = x2;
  2591. x2 = swap;
  2592. swap = -y1;
  2593. y1 = y2;
  2594. y2 = swap;
  2595. }
  2596. } else {
  2597. if (y1 >= y2) {
  2598. x1 = -x1;
  2599. y1 = -y1;
  2600. x2 = -x2;
  2601. y2 = -y2;
  2602. } else {
  2603. sign = -sign;
  2604. swap = -x1;
  2605. x1 = -x2;
  2606. x2 = swap;
  2607. swap = -y1;
  2608. y1 = -y2;
  2609. y2 = swap;
  2610. }
  2611. }
  2612. }
  2613. if (x1 > 0.0) {
  2614. if (x2 > 0.0) {
  2615. if (x1 <= x2) {
  2616. } else {
  2617. return sign
  2618. }
  2619. } else {
  2620. return sign
  2621. }
  2622. } else {
  2623. if (x2 > 0.0) {
  2624. return -sign
  2625. } else {
  2626. if (x1 >= x2) {
  2627. sign = -sign;
  2628. x1 = -x1;
  2629. x2 = -x2;
  2630. } else {
  2631. return -sign
  2632. }
  2633. }
  2634. }
  2635. while (true) {
  2636. k = Math.floor(x2 / x1);
  2637. x2 = x2 - k * x1;
  2638. y2 = y2 - k * y1;
  2639. if (y2 < 0.0) {
  2640. return -sign
  2641. }
  2642. if (y2 > y1) {
  2643. return sign
  2644. }
  2645. if (x1 > x2 + x2) {
  2646. if (y1 < y2 + y2) {
  2647. return sign
  2648. }
  2649. } else {
  2650. if (y1 > y2 + y2) {
  2651. return -sign
  2652. } else {
  2653. x2 = x1 - x2;
  2654. y2 = y1 - y2;
  2655. sign = -sign;
  2656. }
  2657. }
  2658. if (y2 === 0.0) {
  2659. if (x2 === 0.0) {
  2660. return 0
  2661. } else {
  2662. return -sign
  2663. }
  2664. }
  2665. if (x2 === 0.0) {
  2666. return sign
  2667. }
  2668. k = Math.floor(x1 / x2);
  2669. x1 = x1 - k * x2;
  2670. y1 = y1 - k * y2;
  2671. if (y1 < 0.0) {
  2672. return sign
  2673. }
  2674. if (y1 > y2) {
  2675. return -sign
  2676. }
  2677. if (x2 > x1 + x1) {
  2678. if (y2 < y1 + y1) {
  2679. return -sign
  2680. }
  2681. } else {
  2682. if (y2 > y1 + y1) {
  2683. return sign
  2684. } else {
  2685. x1 = x2 - x1;
  2686. y1 = y2 - y1;
  2687. sign = -sign;
  2688. }
  2689. }
  2690. if (y1 === 0.0) {
  2691. if (x1 === 0.0) {
  2692. return 0
  2693. } else {
  2694. return sign
  2695. }
  2696. }
  2697. if (x1 === 0.0) {
  2698. return -sign
  2699. }
  2700. }
  2701. };
  2702. var RayCrossingCounter = function RayCrossingCounter () {
  2703. this._p = null;
  2704. this._crossingCount = 0;
  2705. this._isPointOnSegment = false;
  2706. var p = arguments[0];
  2707. this._p = p;
  2708. };
  2709. RayCrossingCounter.prototype.countSegment = function countSegment (p1, p2) {
  2710. if (p1.x < this._p.x && p2.x < this._p.x) { return null }
  2711. if (this._p.x === p2.x && this._p.y === p2.y) {
  2712. this._isPointOnSegment = true;
  2713. return null
  2714. }
  2715. if (p1.y === this._p.y && p2.y === this._p.y) {
  2716. var minx = p1.x;
  2717. var maxx = p2.x;
  2718. if (minx > maxx) {
  2719. minx = p2.x;
  2720. maxx = p1.x;
  2721. }
  2722. if (this._p.x >= minx && this._p.x <= maxx) {
  2723. this._isPointOnSegment = true;
  2724. }
  2725. return null
  2726. }
  2727. if ((p1.y > this._p.y && p2.y <= this._p.y) || (p2.y > this._p.y && p1.y <= this._p.y)) {
  2728. var x1 = p1.x - this._p.x;
  2729. var y1 = p1.y - this._p.y;
  2730. var x2 = p2.x - this._p.x;
  2731. var y2 = p2.y - this._p.y;
  2732. var xIntSign = RobustDeterminant.signOfDet2x2(x1, y1, x2, y2);
  2733. if (xIntSign === 0.0) {
  2734. this._isPointOnSegment = true;
  2735. return null
  2736. }
  2737. if (y2 < y1) { xIntSign = -xIntSign; }
  2738. if (xIntSign > 0.0) {
  2739. this._crossingCount++;
  2740. }
  2741. }
  2742. };
  2743. RayCrossingCounter.prototype.isPointInPolygon = function isPointInPolygon () {
  2744. return this.getLocation() !== Location.EXTERIOR
  2745. };
  2746. RayCrossingCounter.prototype.getLocation = function getLocation () {
  2747. if (this._isPointOnSegment) { return Location.BOUNDARY }
  2748. if (this._crossingCount % 2 === 1) {
  2749. return Location.INTERIOR
  2750. }
  2751. return Location.EXTERIOR
  2752. };
  2753. RayCrossingCounter.prototype.isOnSegment = function isOnSegment () {
  2754. return this._isPointOnSegment
  2755. };
  2756. RayCrossingCounter.prototype.interfaces_ = function interfaces_ () {
  2757. return []
  2758. };
  2759. RayCrossingCounter.prototype.getClass = function getClass () {
  2760. return RayCrossingCounter
  2761. };
  2762. RayCrossingCounter.locatePointInRing = function locatePointInRing () {
  2763. if (arguments[0] instanceof Coordinate && hasInterface(arguments[1], CoordinateSequence)) {
  2764. var p = arguments[0];
  2765. var ring = arguments[1];
  2766. var counter = new RayCrossingCounter(p);
  2767. var p1 = new Coordinate();
  2768. var p2 = new Coordinate();
  2769. for (var i = 1; i < ring.size(); i++) {
  2770. ring.getCoordinate(i, p1);
  2771. ring.getCoordinate(i - 1, p2);
  2772. counter.countSegment(p1, p2);
  2773. if (counter.isOnSegment()) { return counter.getLocation() }
  2774. }
  2775. return counter.getLocation()
  2776. } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Array) {
  2777. var p$1 = arguments[0];
  2778. var ring$1 = arguments[1];
  2779. var counter$1 = new RayCrossingCounter(p$1);
  2780. for (var i$1 = 1; i$1 < ring$1.length; i$1++) {
  2781. var p1$1 = ring$1[i$1];
  2782. var p2$1 = ring$1[i$1 - 1];
  2783. counter$1.countSegment(p1$1, p2$1);
  2784. if (counter$1.isOnSegment()) { return counter$1.getLocation() }
  2785. }
  2786. return counter$1.getLocation()
  2787. }
  2788. };
  2789. var CGAlgorithms = function CGAlgorithms () {};
  2790. var staticAccessors$3 = { CLOCKWISE: { configurable: true },RIGHT: { configurable: true },COUNTERCLOCKWISE: { configurable: true },LEFT: { configurable: true },COLLINEAR: { configurable: true },STRAIGHT: { configurable: true } };
  2791. CGAlgorithms.prototype.interfaces_ = function interfaces_ () {
  2792. return []
  2793. };
  2794. CGAlgorithms.prototype.getClass = function getClass () {
  2795. return CGAlgorithms
  2796. };
  2797. CGAlgorithms.orientationIndex = function orientationIndex (p1, p2, q) {
  2798. return CGAlgorithmsDD.orientationIndex(p1, p2, q)
  2799. };
  2800. CGAlgorithms.signedArea = function signedArea () {
  2801. if (arguments[0] instanceof Array) {
  2802. var ring = arguments[0];
  2803. if (ring.length < 3) { return 0.0 }
  2804. var sum = 0.0;
  2805. var x0 = ring[0].x;
  2806. for (var i = 1; i < ring.length - 1; i++) {
  2807. var x = ring[i].x - x0;
  2808. var y1 = ring[i + 1].y;
  2809. var y2 = ring[i - 1].y;
  2810. sum += x * (y2 - y1);
  2811. }
  2812. return sum / 2.0
  2813. } else if (hasInterface(arguments[0], CoordinateSequence)) {
  2814. var ring$1 = arguments[0];
  2815. var n = ring$1.size();
  2816. if (n < 3) { return 0.0 }
  2817. var p0 = new Coordinate();
  2818. var p1 = new Coordinate();
  2819. var p2 = new Coordinate();
  2820. ring$1.getCoordinate(0, p1);
  2821. ring$1.getCoordinate(1, p2);
  2822. var x0$1 = p1.x;
  2823. p2.x -= x0$1;
  2824. var sum$1 = 0.0;
  2825. for (var i$1 = 1; i$1 < n - 1; i$1++) {
  2826. p0.y = p1.y;
  2827. p1.x = p2.x;
  2828. p1.y = p2.y;
  2829. ring$1.getCoordinate(i$1 + 1, p2);
  2830. p2.x -= x0$1;
  2831. sum$1 += p1.x * (p0.y - p2.y);
  2832. }
  2833. return sum$1 / 2.0
  2834. }
  2835. };
  2836. CGAlgorithms.distanceLineLine = function distanceLineLine (A, B, C, D) {
  2837. if (A.equals(B)) { return CGAlgorithms.distancePointLine(A, C, D) }
  2838. if (C.equals(D)) { return CGAlgorithms.distancePointLine(D, A, B) }
  2839. var noIntersection = false;
  2840. if (!Envelope.intersects(A, B, C, D)) {
  2841. noIntersection = true;
  2842. } else {
  2843. var denom = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);
  2844. if (denom === 0) {
  2845. noIntersection = true;
  2846. } else {
  2847. var rNumb = (A.y - C.y) * (D.x - C.x) - (A.x - C.x) * (D.y - C.y);
  2848. var sNum = (A.y - C.y) * (B.x - A.x) - (A.x - C.x) * (B.y - A.y);
  2849. var s = sNum / denom;
  2850. var r = rNumb / denom;
  2851. if (r < 0 || r > 1 || s < 0 || s > 1) {
  2852. noIntersection = true;
  2853. }
  2854. }
  2855. }
  2856. if (noIntersection) {
  2857. return MathUtil.min(CGAlgorithms.distancePointLine(A, C, D), CGAlgorithms.distancePointLine(B, C, D), CGAlgorithms.distancePointLine(C, A, B), CGAlgorithms.distancePointLine(D, A, B))
  2858. }
  2859. return 0.0
  2860. };
  2861. CGAlgorithms.isPointInRing = function isPointInRing (p, ring) {
  2862. return CGAlgorithms.locatePointInRing(p, ring) !== Location.EXTERIOR
  2863. };
  2864. CGAlgorithms.computeLength = function computeLength (pts) {
  2865. var n = pts.size();
  2866. if (n <= 1) { return 0.0 }
  2867. var len = 0.0;
  2868. var p = new Coordinate();
  2869. pts.getCoordinate(0, p);
  2870. var x0 = p.x;
  2871. var y0 = p.y;
  2872. for (var i = 1; i < n; i++) {
  2873. pts.getCoordinate(i, p);
  2874. var x1 = p.x;
  2875. var y1 = p.y;
  2876. var dx = x1 - x0;
  2877. var dy = y1 - y0;
  2878. len += Math.sqrt(dx * dx + dy * dy);
  2879. x0 = x1;
  2880. y0 = y1;
  2881. }
  2882. return len
  2883. };
  2884. CGAlgorithms.isCCW = function isCCW (ring) {
  2885. var nPts = ring.length - 1;
  2886. if (nPts < 3) { throw new IllegalArgumentException('Ring has fewer than 4 points, so orientation cannot be determined') }
  2887. var hiPt = ring[0];
  2888. var hiIndex = 0;
  2889. for (var i = 1; i <= nPts; i++) {
  2890. var p = ring[i];
  2891. if (p.y > hiPt.y) {
  2892. hiPt = p;
  2893. hiIndex = i;
  2894. }
  2895. }
  2896. var iPrev = hiIndex;
  2897. do {
  2898. iPrev = iPrev - 1;
  2899. if (iPrev < 0) { iPrev = nPts; }
  2900. } while (ring[iPrev].equals2D(hiPt) && iPrev !== hiIndex)
  2901. var iNext = hiIndex;
  2902. do {
  2903. iNext = (iNext + 1) % nPts;
  2904. } while (ring[iNext].equals2D(hiPt) && iNext !== hiIndex)
  2905. var prev = ring[iPrev];
  2906. var next = ring[iNext];
  2907. if (prev.equals2D(hiPt) || next.equals2D(hiPt) || prev.equals2D(next)) { return false }
  2908. var disc = CGAlgorithms.computeOrientation(prev, hiPt, next);
  2909. var isCCW = false;
  2910. if (disc === 0) {
  2911. isCCW = prev.x > next.x;
  2912. } else {
  2913. isCCW = disc > 0;
  2914. }
  2915. return isCCW
  2916. };
  2917. CGAlgorithms.locatePointInRing = function locatePointInRing (p, ring) {
  2918. return RayCrossingCounter.locatePointInRing(p, ring)
  2919. };
  2920. CGAlgorithms.distancePointLinePerpendicular = function distancePointLinePerpendicular (p, A, B) {
  2921. var len2 = (B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y);
  2922. var s = ((A.y - p.y) * (B.x - A.x) - (A.x - p.x) * (B.y - A.y)) / len2;
  2923. return Math.abs(s) * Math.sqrt(len2)
  2924. };
  2925. CGAlgorithms.computeOrientation = function computeOrientation (p1, p2, q) {
  2926. return CGAlgorithms.orientationIndex(p1, p2, q)
  2927. };
  2928. CGAlgorithms.distancePointLine = function distancePointLine () {
  2929. if (arguments.length === 2) {
  2930. var p = arguments[0];
  2931. var line = arguments[1];
  2932. if (line.length === 0) { throw new IllegalArgumentException('Line array must contain at least one vertex') }
  2933. var minDistance = p.distance(line[0]);
  2934. for (var i = 0; i < line.length - 1; i++) {
  2935. var dist = CGAlgorithms.distancePointLine(p, line[i], line[i + 1]);
  2936. if (dist < minDistance) {
  2937. minDistance = dist;
  2938. }
  2939. }
  2940. return minDistance
  2941. } else if (arguments.length === 3) {
  2942. var p$1 = arguments[0];
  2943. var A = arguments[1];
  2944. var B = arguments[2];
  2945. if (A.x === B.x && A.y === B.y) { return p$1.distance(A) }
  2946. var len2 = (B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y);
  2947. var r = ((p$1.x - A.x) * (B.x - A.x) + (p$1.y - A.y) * (B.y - A.y)) / len2;
  2948. if (r <= 0.0) { return p$1.distance(A) }
  2949. if (r >= 1.0) { return p$1.distance(B) }
  2950. var s = ((A.y - p$1.y) * (B.x - A.x) - (A.x - p$1.x) * (B.y - A.y)) / len2;
  2951. return Math.abs(s) * Math.sqrt(len2)
  2952. }
  2953. };
  2954. CGAlgorithms.isOnLine = function isOnLine (p, pt) {
  2955. var lineIntersector = new RobustLineIntersector();
  2956. for (var i = 1; i < pt.length; i++) {
  2957. var p0 = pt[i - 1];
  2958. var p1 = pt[i];
  2959. lineIntersector.computeIntersection(p, p0, p1);
  2960. if (lineIntersector.hasIntersection()) {
  2961. return true
  2962. }
  2963. }
  2964. return false
  2965. };
  2966. staticAccessors$3.CLOCKWISE.get = function () { return -1 };
  2967. staticAccessors$3.RIGHT.get = function () { return CGAlgorithms.CLOCKWISE };
  2968. staticAccessors$3.COUNTERCLOCKWISE.get = function () { return 1 };
  2969. staticAccessors$3.LEFT.get = function () { return CGAlgorithms.COUNTERCLOCKWISE };
  2970. staticAccessors$3.COLLINEAR.get = function () { return 0 };
  2971. staticAccessors$3.STRAIGHT.get = function () { return CGAlgorithms.COLLINEAR };
  2972. Object.defineProperties( CGAlgorithms, staticAccessors$3 );
  2973. var GeometryComponentFilter = function GeometryComponentFilter () {};
  2974. GeometryComponentFilter.prototype.filter = function filter (geom) {};
  2975. GeometryComponentFilter.prototype.interfaces_ = function interfaces_ () {
  2976. return []
  2977. };
  2978. GeometryComponentFilter.prototype.getClass = function getClass () {
  2979. return GeometryComponentFilter
  2980. };
  2981. var Geometry = function Geometry () {
  2982. var factory = arguments[0];
  2983. this._envelope = null;
  2984. this._factory = null;
  2985. this._SRID = null;
  2986. this._userData = null;
  2987. this._factory = factory;
  2988. this._SRID = factory.getSRID();
  2989. };
  2990. 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 } };
  2991. Geometry.prototype.isGeometryCollection = function isGeometryCollection () {
  2992. return this.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION
  2993. };
  2994. Geometry.prototype.getFactory = function getFactory () {
  2995. return this._factory
  2996. };
  2997. Geometry.prototype.getGeometryN = function getGeometryN (n) {
  2998. return this
  2999. };
  3000. Geometry.prototype.getArea = function getArea () {
  3001. return 0.0
  3002. };
  3003. Geometry.prototype.isRectangle = function isRectangle () {
  3004. return false
  3005. };
  3006. Geometry.prototype.equals = function equals () {
  3007. if (arguments[0] instanceof Geometry) {
  3008. var g$1 = arguments[0];
  3009. if (g$1 === null) { return false }
  3010. return this.equalsTopo(g$1)
  3011. } else if (arguments[0] instanceof Object) {
  3012. var o = arguments[0];
  3013. if (!(o instanceof Geometry)) { return false }
  3014. var g = o;
  3015. return this.equalsExact(g)
  3016. }
  3017. };
  3018. Geometry.prototype.equalsExact = function equalsExact (other) {
  3019. return this === other || this.equalsExact(other, 0)
  3020. };
  3021. Geometry.prototype.geometryChanged = function geometryChanged () {
  3022. this.apply(Geometry.geometryChangedFilter);
  3023. };
  3024. Geometry.prototype.geometryChangedAction = function geometryChangedAction () {
  3025. this._envelope = null;
  3026. };
  3027. Geometry.prototype.equalsNorm = function equalsNorm (g) {
  3028. if (g === null) { return false }
  3029. return this.norm().equalsExact(g.norm())
  3030. };
  3031. Geometry.prototype.getLength = function getLength () {
  3032. return 0.0
  3033. };
  3034. Geometry.prototype.getNumGeometries = function getNumGeometries () {
  3035. return 1
  3036. };
  3037. Geometry.prototype.compareTo = function compareTo () {
  3038. if (arguments.length === 1) {
  3039. var o = arguments[0];
  3040. var other = o;
  3041. if (this.getSortIndex() !== other.getSortIndex()) {
  3042. return this.getSortIndex() - other.getSortIndex()
  3043. }
  3044. if (this.isEmpty() && other.isEmpty()) {
  3045. return 0
  3046. }
  3047. if (this.isEmpty()) {
  3048. return -1
  3049. }
  3050. if (other.isEmpty()) {
  3051. return 1
  3052. }
  3053. return this.compareToSameClass(o)
  3054. } else if (arguments.length === 2) {
  3055. var other$1 = arguments[0];
  3056. var comp = arguments[1];
  3057. if (this.getSortIndex() !== other$1.getSortIndex()) {
  3058. return this.getSortIndex() - other$1.getSortIndex()
  3059. }
  3060. if (this.isEmpty() && other$1.isEmpty()) {
  3061. return 0
  3062. }
  3063. if (this.isEmpty()) {
  3064. return -1
  3065. }
  3066. if (other$1.isEmpty()) {
  3067. return 1
  3068. }
  3069. return this.compareToSameClass(other$1, comp)
  3070. }
  3071. };
  3072. Geometry.prototype.getUserData = function getUserData () {
  3073. return this._userData
  3074. };
  3075. Geometry.prototype.getSRID = function getSRID () {
  3076. return this._SRID
  3077. };
  3078. Geometry.prototype.getEnvelope = function getEnvelope () {
  3079. return this.getFactory().toGeometry(this.getEnvelopeInternal())
  3080. };
  3081. Geometry.prototype.checkNotGeometryCollection = function checkNotGeometryCollection (g) {
  3082. if (g.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION) {
  3083. throw new IllegalArgumentException('This method does not support GeometryCollection arguments')
  3084. }
  3085. };
  3086. Geometry.prototype.equal = function equal (a, b, tolerance) {
  3087. if (tolerance === 0) {
  3088. return a.equals(b)
  3089. }
  3090. return a.distance(b) <= tolerance
  3091. };
  3092. Geometry.prototype.norm = function norm () {
  3093. var copy = this.copy();
  3094. copy.normalize();
  3095. return copy
  3096. };
  3097. Geometry.prototype.getPrecisionModel = function getPrecisionModel () {
  3098. return this._factory.getPrecisionModel()
  3099. };
  3100. Geometry.prototype.getEnvelopeInternal = function getEnvelopeInternal () {
  3101. if (this._envelope === null) {
  3102. this._envelope = this.computeEnvelopeInternal();
  3103. }
  3104. return new Envelope(this._envelope)
  3105. };
  3106. Geometry.prototype.setSRID = function setSRID (SRID) {
  3107. this._SRID = SRID;
  3108. };
  3109. Geometry.prototype.setUserData = function setUserData (userData) {
  3110. this._userData = userData;
  3111. };
  3112. Geometry.prototype.compare = function compare (a, b) {
  3113. var i = a.iterator();
  3114. var j = b.iterator();
  3115. while (i.hasNext() && j.hasNext()) {
  3116. var aElement = i.next();
  3117. var bElement = j.next();
  3118. var comparison = aElement.compareTo(bElement);
  3119. if (comparison !== 0) {
  3120. return comparison
  3121. }
  3122. }
  3123. if (i.hasNext()) {
  3124. return 1
  3125. }
  3126. if (j.hasNext()) {
  3127. return -1
  3128. }
  3129. return 0
  3130. };
  3131. Geometry.prototype.hashCode = function hashCode () {
  3132. return this.getEnvelopeInternal().hashCode()
  3133. };
  3134. Geometry.prototype.isGeometryCollectionOrDerived = function isGeometryCollectionOrDerived () {
  3135. if (this.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION || this.getSortIndex() === Geometry.SORTINDEX_MULTIPOINT || this.getSortIndex() === Geometry.SORTINDEX_MULTILINESTRING || this.getSortIndex() === Geometry.SORTINDEX_MULTIPOLYGON) {
  3136. return true
  3137. }
  3138. return false
  3139. };
  3140. Geometry.prototype.interfaces_ = function interfaces_ () {
  3141. return [Clonable, Comparable, Serializable]
  3142. };
  3143. Geometry.prototype.getClass = function getClass () {
  3144. return Geometry
  3145. };
  3146. Geometry.hasNonEmptyElements = function hasNonEmptyElements (geometries) {
  3147. for (var i = 0; i < geometries.length; i++) {
  3148. if (!geometries[i].isEmpty()) {
  3149. return true
  3150. }
  3151. }
  3152. return false
  3153. };
  3154. Geometry.hasNullElements = function hasNullElements (array) {
  3155. for (var i = 0; i < array.length; i++) {
  3156. if (array[i] === null) {
  3157. return true
  3158. }
  3159. }
  3160. return false
  3161. };
  3162. staticAccessors$11.serialVersionUID.get = function () { return 8763622679187376702 };
  3163. staticAccessors$11.SORTINDEX_POINT.get = function () { return 0 };
  3164. staticAccessors$11.SORTINDEX_MULTIPOINT.get = function () { return 1 };
  3165. staticAccessors$11.SORTINDEX_LINESTRING.get = function () { return 2 };
  3166. staticAccessors$11.SORTINDEX_LINEARRING.get = function () { return 3 };
  3167. staticAccessors$11.SORTINDEX_MULTILINESTRING.get = function () { return 4 };
  3168. staticAccessors$11.SORTINDEX_POLYGON.get = function () { return 5 };
  3169. staticAccessors$11.SORTINDEX_MULTIPOLYGON.get = function () { return 6 };
  3170. staticAccessors$11.SORTINDEX_GEOMETRYCOLLECTION.get = function () { return 7 };
  3171. staticAccessors$11.geometryChangedFilter.get = function () { return geometryChangedFilter };
  3172. Object.defineProperties( Geometry, staticAccessors$11 );
  3173. var geometryChangedFilter = function geometryChangedFilter () {};
  3174. geometryChangedFilter.interfaces_ = function interfaces_ () {
  3175. return [GeometryComponentFilter]
  3176. };
  3177. geometryChangedFilter.filter = function filter (geom) {
  3178. geom.geometryChangedAction();
  3179. };
  3180. var CoordinateFilter = function CoordinateFilter () {};
  3181. CoordinateFilter.prototype.filter = function filter (coord) {};
  3182. CoordinateFilter.prototype.interfaces_ = function interfaces_ () {
  3183. return []
  3184. };
  3185. CoordinateFilter.prototype.getClass = function getClass () {
  3186. return CoordinateFilter
  3187. };
  3188. var BoundaryNodeRule = function BoundaryNodeRule () {};
  3189. 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 } };
  3190. BoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {};
  3191. BoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
  3192. return []
  3193. };
  3194. BoundaryNodeRule.prototype.getClass = function getClass () {
  3195. return BoundaryNodeRule
  3196. };
  3197. staticAccessors$12.Mod2BoundaryNodeRule.get = function () { return Mod2BoundaryNodeRule };
  3198. staticAccessors$12.EndPointBoundaryNodeRule.get = function () { return EndPointBoundaryNodeRule };
  3199. staticAccessors$12.MultiValentEndPointBoundaryNodeRule.get = function () { return MultiValentEndPointBoundaryNodeRule };
  3200. staticAccessors$12.MonoValentEndPointBoundaryNodeRule.get = function () { return MonoValentEndPointBoundaryNodeRule };
  3201. staticAccessors$12.MOD2_BOUNDARY_RULE.get = function () { return new Mod2BoundaryNodeRule() };
  3202. staticAccessors$12.ENDPOINT_BOUNDARY_RULE.get = function () { return new EndPointBoundaryNodeRule() };
  3203. staticAccessors$12.MULTIVALENT_ENDPOINT_BOUNDARY_RULE.get = function () { return new MultiValentEndPointBoundaryNodeRule() };
  3204. staticAccessors$12.MONOVALENT_ENDPOINT_BOUNDARY_RULE.get = function () { return new MonoValentEndPointBoundaryNodeRule() };
  3205. staticAccessors$12.OGC_SFS_BOUNDARY_RULE.get = function () { return BoundaryNodeRule.MOD2_BOUNDARY_RULE };
  3206. Object.defineProperties( BoundaryNodeRule, staticAccessors$12 );
  3207. var Mod2BoundaryNodeRule = function Mod2BoundaryNodeRule () {};
  3208. Mod2BoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
  3209. return boundaryCount % 2 === 1
  3210. };
  3211. Mod2BoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
  3212. return [BoundaryNodeRule]
  3213. };
  3214. Mod2BoundaryNodeRule.prototype.getClass = function getClass () {
  3215. return Mod2BoundaryNodeRule
  3216. };
  3217. var EndPointBoundaryNodeRule = function EndPointBoundaryNodeRule () {};
  3218. EndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
  3219. return boundaryCount > 0
  3220. };
  3221. EndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
  3222. return [BoundaryNodeRule]
  3223. };
  3224. EndPointBoundaryNodeRule.prototype.getClass = function getClass () {
  3225. return EndPointBoundaryNodeRule
  3226. };
  3227. var MultiValentEndPointBoundaryNodeRule = function MultiValentEndPointBoundaryNodeRule () {};
  3228. MultiValentEndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
  3229. return boundaryCount > 1
  3230. };
  3231. MultiValentEndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
  3232. return [BoundaryNodeRule]
  3233. };
  3234. MultiValentEndPointBoundaryNodeRule.prototype.getClass = function getClass () {
  3235. return MultiValentEndPointBoundaryNodeRule
  3236. };
  3237. var MonoValentEndPointBoundaryNodeRule = function MonoValentEndPointBoundaryNodeRule () {};
  3238. MonoValentEndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
  3239. return boundaryCount === 1
  3240. };
  3241. MonoValentEndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
  3242. return [BoundaryNodeRule]
  3243. };
  3244. MonoValentEndPointBoundaryNodeRule.prototype.getClass = function getClass () {
  3245. return MonoValentEndPointBoundaryNodeRule
  3246. };
  3247. // import Iterator from './Iterator'
  3248. /**
  3249. * @see http://download.oracle.com/javase/6/docs/api/java/util/Collection.html
  3250. *
  3251. * @constructor
  3252. * @private
  3253. */
  3254. var Collection = function Collection () {};
  3255. Collection.prototype.add = function add () {};
  3256. /**
  3257. * Appends all of the elements in the specified collection to the end of this
  3258. * list, in the order that they are returned by the specified collection's
  3259. * iterator (optional operation).
  3260. * @param {javascript.util.Collection} c
  3261. * @return {boolean}
  3262. */
  3263. Collection.prototype.addAll = function addAll () {};
  3264. /**
  3265. * Returns true if this collection contains no elements.
  3266. * @return {boolean}
  3267. */
  3268. Collection.prototype.isEmpty = function isEmpty () {};
  3269. /**
  3270. * Returns an iterator over the elements in this collection.
  3271. * @return {javascript.util.Iterator}
  3272. */
  3273. Collection.prototype.iterator = function iterator () {};
  3274. /**
  3275. * Returns an iterator over the elements in this collection.
  3276. * @return {number}
  3277. */
  3278. Collection.prototype.size = function size () {};
  3279. /**
  3280. * Returns an array containing all of the elements in this collection.
  3281. * @return {Array}
  3282. */
  3283. Collection.prototype.toArray = function toArray () {};
  3284. /**
  3285. * Removes a single instance of the specified element from this collection if it
  3286. * is present. (optional)
  3287. * @param {Object} e
  3288. * @return {boolean}
  3289. */
  3290. Collection.prototype.remove = function remove () {};
  3291. /**
  3292. * @param {string=} message Optional message
  3293. * @extends {Error}
  3294. * @constructor
  3295. * @private
  3296. */
  3297. function IndexOutOfBoundsException (message) {
  3298. this.message = message || '';
  3299. }
  3300. IndexOutOfBoundsException.prototype = new Error();
  3301. /**
  3302. * @type {string}
  3303. */
  3304. IndexOutOfBoundsException.prototype.name = 'IndexOutOfBoundsException';
  3305. /**
  3306. * @see http://download.oracle.com/javase/6/docs/api/java/util/Iterator.html
  3307. * @constructor
  3308. * @private
  3309. */
  3310. var Iterator = function Iterator () {};
  3311. Iterator.prototype.hasNext = function hasNext () {};
  3312. /**
  3313. * Returns the next element in the iteration.
  3314. * @return {Object}
  3315. */
  3316. Iterator.prototype.next = function next () {};
  3317. /**
  3318. * Removes from the underlying collection the last element returned by the
  3319. * iterator (optional operation).
  3320. */
  3321. Iterator.prototype.remove = function remove () {};
  3322. /**
  3323. * @see http://download.oracle.com/javase/6/docs/api/java/util/List.html
  3324. *
  3325. * @extends {javascript.util.Collection}
  3326. * @constructor
  3327. * @private
  3328. */
  3329. var List = (function (Collection$$1) {
  3330. function List () {
  3331. Collection$$1.apply(this, arguments);
  3332. }
  3333. if ( Collection$$1 ) List.__proto__ = Collection$$1;
  3334. List.prototype = Object.create( Collection$$1 && Collection$$1.prototype );
  3335. List.prototype.constructor = List;
  3336. List.prototype.get = function get () { };
  3337. /**
  3338. * Replaces the element at the specified position in this list with the
  3339. * specified element (optional operation).
  3340. * @param {number} index
  3341. * @param {Object} e
  3342. * @return {Object}
  3343. */
  3344. List.prototype.set = function set () { };
  3345. /**
  3346. * Returns true if this collection contains no elements.
  3347. * @return {boolean}
  3348. */
  3349. List.prototype.isEmpty = function isEmpty () { };
  3350. return List;
  3351. }(Collection));
  3352. /**
  3353. * @param {string=} message Optional message
  3354. * @extends {Error}
  3355. * @constructor
  3356. * @private
  3357. */
  3358. function NoSuchElementException (message) {
  3359. this.message = message || '';
  3360. }
  3361. NoSuchElementException.prototype = new Error();
  3362. /**
  3363. * @type {string}
  3364. */
  3365. NoSuchElementException.prototype.name = 'NoSuchElementException';
  3366. // import OperationNotSupported from './OperationNotSupported'
  3367. /**
  3368. * @see http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html
  3369. *
  3370. * @extends List
  3371. * @private
  3372. */
  3373. var ArrayList = (function (List$$1) {
  3374. function ArrayList () {
  3375. List$$1.call(this);
  3376. this.array_ = [];
  3377. if (arguments[0] instanceof Collection) {
  3378. this.addAll(arguments[0]);
  3379. }
  3380. }
  3381. if ( List$$1 ) ArrayList.__proto__ = List$$1;
  3382. ArrayList.prototype = Object.create( List$$1 && List$$1.prototype );
  3383. ArrayList.prototype.constructor = ArrayList;
  3384. ArrayList.prototype.ensureCapacity = function ensureCapacity () {};
  3385. ArrayList.prototype.interfaces_ = function interfaces_ () { return [List$$1, Collection] };
  3386. /**
  3387. * @override
  3388. */
  3389. ArrayList.prototype.add = function add (e) {
  3390. if (arguments.length === 1) {
  3391. this.array_.push(e);
  3392. } else {
  3393. this.array_.splice(arguments[0], arguments[1]);
  3394. }
  3395. return true
  3396. };
  3397. ArrayList.prototype.clear = function clear () {
  3398. this.array_ = [];
  3399. };
  3400. /**
  3401. * @override
  3402. */
  3403. ArrayList.prototype.addAll = function addAll (c) {
  3404. var this$1 = this;
  3405. for (var i = c.iterator(); i.hasNext();) {
  3406. this$1.add(i.next());
  3407. }
  3408. return true
  3409. };
  3410. /**
  3411. * @override
  3412. */
  3413. ArrayList.prototype.set = function set (index, element) {
  3414. var oldElement = this.array_[index];
  3415. this.array_[index] = element;
  3416. return oldElement
  3417. };
  3418. /**
  3419. * @override
  3420. */
  3421. ArrayList.prototype.iterator = function iterator () {
  3422. return new Iterator_(this)
  3423. };
  3424. /**
  3425. * @override
  3426. */
  3427. ArrayList.prototype.get = function get (index) {
  3428. if (index < 0 || index >= this.size()) {
  3429. throw new IndexOutOfBoundsException()
  3430. }
  3431. return this.array_[index]
  3432. };
  3433. /**
  3434. * @override
  3435. */
  3436. ArrayList.prototype.isEmpty = function isEmpty () {
  3437. return this.array_.length === 0
  3438. };
  3439. /**
  3440. * @override
  3441. */
  3442. ArrayList.prototype.size = function size () {
  3443. return this.array_.length
  3444. };
  3445. /**
  3446. * @override
  3447. */
  3448. ArrayList.prototype.toArray = function toArray () {
  3449. var this$1 = this;
  3450. var array = [];
  3451. for (var i = 0, len = this.array_.length; i < len; i++) {
  3452. array.push(this$1.array_[i]);
  3453. }
  3454. return array
  3455. };
  3456. /**
  3457. * @override
  3458. */
  3459. ArrayList.prototype.remove = function remove (o) {
  3460. var this$1 = this;
  3461. var found = false;
  3462. for (var i = 0, len = this.array_.length; i < len; i++) {
  3463. if (this$1.array_[i] === o) {
  3464. this$1.array_.splice(i, 1);
  3465. found = true;
  3466. break
  3467. }
  3468. }
  3469. return found
  3470. };
  3471. return ArrayList;
  3472. }(List));
  3473. /**
  3474. * @extends {Iterator}
  3475. * @param {ArrayList} arrayList
  3476. * @constructor
  3477. * @private
  3478. */
  3479. var Iterator_ = (function (Iterator$$1) {
  3480. function Iterator_ (arrayList) {
  3481. Iterator$$1.call(this);
  3482. /**
  3483. * @type {ArrayList}
  3484. * @private
  3485. */
  3486. this.arrayList_ = arrayList;
  3487. /**
  3488. * @type {number}
  3489. * @private
  3490. */
  3491. this.position_ = 0;
  3492. }
  3493. if ( Iterator$$1 ) Iterator_.__proto__ = Iterator$$1;
  3494. Iterator_.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
  3495. Iterator_.prototype.constructor = Iterator_;
  3496. /**
  3497. * @override
  3498. */
  3499. Iterator_.prototype.next = function next () {
  3500. if (this.position_ === this.arrayList_.size()) {
  3501. throw new NoSuchElementException()
  3502. }
  3503. return this.arrayList_.get(this.position_++)
  3504. };
  3505. /**
  3506. * @override
  3507. */
  3508. Iterator_.prototype.hasNext = function hasNext () {
  3509. if (this.position_ < this.arrayList_.size()) {
  3510. return true
  3511. } else {
  3512. return false
  3513. }
  3514. };
  3515. /**
  3516. * TODO: should be in ListIterator
  3517. * @override
  3518. */
  3519. Iterator_.prototype.set = function set (element) {
  3520. return this.arrayList_.set(this.position_ - 1, element)
  3521. };
  3522. /**
  3523. * @override
  3524. */
  3525. Iterator_.prototype.remove = function remove () {
  3526. this.arrayList_.remove(this.arrayList_.get(this.position_));
  3527. };
  3528. return Iterator_;
  3529. }(Iterator));
  3530. var CoordinateList = (function (ArrayList$$1) {
  3531. function CoordinateList () {
  3532. ArrayList$$1.call(this);
  3533. if (arguments.length === 0) {
  3534. } else if (arguments.length === 1) {
  3535. var coord = arguments[0];
  3536. this.ensureCapacity(coord.length);
  3537. this.add(coord, true);
  3538. } else if (arguments.length === 2) {
  3539. var coord$1 = arguments[0];
  3540. var allowRepeated = arguments[1];
  3541. this.ensureCapacity(coord$1.length);
  3542. this.add(coord$1, allowRepeated);
  3543. }
  3544. }
  3545. if ( ArrayList$$1 ) CoordinateList.__proto__ = ArrayList$$1;
  3546. CoordinateList.prototype = Object.create( ArrayList$$1 && ArrayList$$1.prototype );
  3547. CoordinateList.prototype.constructor = CoordinateList;
  3548. var staticAccessors = { coordArrayType: { configurable: true } };
  3549. staticAccessors.coordArrayType.get = function () { return new Array(0).fill(null) };
  3550. CoordinateList.prototype.getCoordinate = function getCoordinate (i) {
  3551. return this.get(i)
  3552. };
  3553. CoordinateList.prototype.addAll = function addAll () {
  3554. var this$1 = this;
  3555. if (arguments.length === 2) {
  3556. var coll = arguments[0];
  3557. var allowRepeated = arguments[1];
  3558. var isChanged = false;
  3559. for (var i = coll.iterator(); i.hasNext();) {
  3560. this$1.add(i.next(), allowRepeated);
  3561. isChanged = true;
  3562. }
  3563. return isChanged
  3564. } else { return ArrayList$$1.prototype.addAll.apply(this, arguments) }
  3565. };
  3566. CoordinateList.prototype.clone = function clone () {
  3567. var this$1 = this;
  3568. var clone = ArrayList$$1.prototype.clone.call(this);
  3569. for (var i = 0; i < this.size(); i++) {
  3570. clone.add(i, this$1.get(i).copy());
  3571. }
  3572. return clone
  3573. };
  3574. CoordinateList.prototype.toCoordinateArray = function toCoordinateArray () {
  3575. return this.toArray(CoordinateList.coordArrayType)
  3576. };
  3577. CoordinateList.prototype.add = function add () {
  3578. var this$1 = this;
  3579. if (arguments.length === 1) {
  3580. var coord = arguments[0];
  3581. ArrayList$$1.prototype.add.call(this, coord);
  3582. } else if (arguments.length === 2) {
  3583. if (arguments[0] instanceof Array && typeof arguments[1] === 'boolean') {
  3584. var coord$1 = arguments[0];
  3585. var allowRepeated = arguments[1];
  3586. this.add(coord$1, allowRepeated, true);
  3587. return true
  3588. } else if (arguments[0] instanceof Coordinate && typeof arguments[1] === 'boolean') {
  3589. var coord$2 = arguments[0];
  3590. var allowRepeated$1 = arguments[1];
  3591. if (!allowRepeated$1) {
  3592. if (this.size() >= 1) {
  3593. var last = this.get(this.size() - 1);
  3594. if (last.equals2D(coord$2)) { return null }
  3595. }
  3596. }
  3597. ArrayList$$1.prototype.add.call(this, coord$2);
  3598. } else if (arguments[0] instanceof Object && typeof arguments[1] === 'boolean') {
  3599. var obj = arguments[0];
  3600. var allowRepeated$2 = arguments[1];
  3601. this.add(obj, allowRepeated$2);
  3602. return true
  3603. }
  3604. } else if (arguments.length === 3) {
  3605. if (typeof arguments[2] === 'boolean' && (arguments[0] instanceof Array && typeof arguments[1] === 'boolean')) {
  3606. var coord$3 = arguments[0];
  3607. var allowRepeated$3 = arguments[1];
  3608. var direction = arguments[2];
  3609. if (direction) {
  3610. for (var i$1 = 0; i$1 < coord$3.length; i$1++) {
  3611. this$1.add(coord$3[i$1], allowRepeated$3);
  3612. }
  3613. } else {
  3614. for (var i$2 = coord$3.length - 1; i$2 >= 0; i$2--) {
  3615. this$1.add(coord$3[i$2], allowRepeated$3);
  3616. }
  3617. }
  3618. return true
  3619. } else if (typeof arguments[2] === 'boolean' && (Number.isInteger(arguments[0]) && arguments[1] instanceof Coordinate)) {
  3620. var i$3 = arguments[0];
  3621. var coord$4 = arguments[1];
  3622. var allowRepeated$4 = arguments[2];
  3623. if (!allowRepeated$4) {
  3624. var size = this.size();
  3625. if (size > 0) {
  3626. if (i$3 > 0) {
  3627. var prev = this.get(i$3 - 1);
  3628. if (prev.equals2D(coord$4)) { return null }
  3629. }
  3630. if (i$3 < size) {
  3631. var next = this.get(i$3);
  3632. if (next.equals2D(coord$4)) { return null }
  3633. }
  3634. }
  3635. }
  3636. ArrayList$$1.prototype.add.call(this, i$3, coord$4);
  3637. }
  3638. } else if (arguments.length === 4) {
  3639. var coord$5 = arguments[0];
  3640. var allowRepeated$5 = arguments[1];
  3641. var start = arguments[2];
  3642. var end = arguments[3];
  3643. var inc = 1;
  3644. if (start > end) { inc = -1; }
  3645. for (var i = start; i !== end; i += inc) {
  3646. this$1.add(coord$5[i], allowRepeated$5);
  3647. }
  3648. return true
  3649. }
  3650. };
  3651. CoordinateList.prototype.closeRing = function closeRing () {
  3652. if (this.size() > 0) { this.add(new Coordinate(this.get(0)), false); }
  3653. };
  3654. CoordinateList.prototype.interfaces_ = function interfaces_ () {
  3655. return []
  3656. };
  3657. CoordinateList.prototype.getClass = function getClass () {
  3658. return CoordinateList
  3659. };
  3660. Object.defineProperties( CoordinateList, staticAccessors );
  3661. return CoordinateList;
  3662. }(ArrayList));
  3663. var CoordinateArrays = function CoordinateArrays () {};
  3664. var staticAccessors$13 = { ForwardComparator: { configurable: true },BidirectionalComparator: { configurable: true },coordArrayType: { configurable: true } };
  3665. staticAccessors$13.ForwardComparator.get = function () { return ForwardComparator };
  3666. staticAccessors$13.BidirectionalComparator.get = function () { return BidirectionalComparator };
  3667. staticAccessors$13.coordArrayType.get = function () { return new Array(0).fill(null) };
  3668. CoordinateArrays.prototype.interfaces_ = function interfaces_ () {
  3669. return []
  3670. };
  3671. CoordinateArrays.prototype.getClass = function getClass () {
  3672. return CoordinateArrays
  3673. };
  3674. CoordinateArrays.isRing = function isRing (pts) {
  3675. if (pts.length < 4) { return false }
  3676. if (!pts[0].equals2D(pts[pts.length - 1])) { return false }
  3677. return true
  3678. };
  3679. CoordinateArrays.ptNotInList = function ptNotInList (testPts, pts) {
  3680. for (var i = 0; i < testPts.length; i++) {
  3681. var testPt = testPts[i];
  3682. if (CoordinateArrays.indexOf(testPt, pts) < 0) { return testPt }
  3683. }
  3684. return null
  3685. };
  3686. CoordinateArrays.scroll = function scroll (coordinates, firstCoordinate) {
  3687. var i = CoordinateArrays.indexOf(firstCoordinate, coordinates);
  3688. if (i < 0) { return null }
  3689. var newCoordinates = new Array(coordinates.length).fill(null);
  3690. System.arraycopy(coordinates, i, newCoordinates, 0, coordinates.length - i);
  3691. System.arraycopy(coordinates, 0, newCoordinates, coordinates.length - i, i);
  3692. System.arraycopy(newCoordinates, 0, coordinates, 0, coordinates.length);
  3693. };
  3694. CoordinateArrays.equals = function equals () {
  3695. if (arguments.length === 2) {
  3696. var coord1 = arguments[0];
  3697. var coord2 = arguments[1];
  3698. if (coord1 === coord2) { return true }
  3699. if (coord1 === null || coord2 === null) { return false }
  3700. if (coord1.length !== coord2.length) { return false }
  3701. for (var i = 0; i < coord1.length; i++) {
  3702. if (!coord1[i].equals(coord2[i])) { return false }
  3703. }
  3704. return true
  3705. } else if (arguments.length === 3) {
  3706. var coord1$1 = arguments[0];
  3707. var coord2$1 = arguments[1];
  3708. var coordinateComparator = arguments[2];
  3709. if (coord1$1 === coord2$1) { return true }
  3710. if (coord1$1 === null || coord2$1 === null) { return false }
  3711. if (coord1$1.length !== coord2$1.length) { return false }
  3712. for (var i$1 = 0; i$1 < coord1$1.length; i$1++) {
  3713. if (coordinateComparator.compare(coord1$1[i$1], coord2$1[i$1]) !== 0) { return false }
  3714. }
  3715. return true
  3716. }
  3717. };
  3718. CoordinateArrays.intersection = function intersection (coordinates, env) {
  3719. var coordList = new CoordinateList();
  3720. for (var i = 0; i < coordinates.length; i++) {
  3721. if (env.intersects(coordinates[i])) { coordList.add(coordinates[i], true); }
  3722. }
  3723. return coordList.toCoordinateArray()
  3724. };
  3725. CoordinateArrays.hasRepeatedPoints = function hasRepeatedPoints (coord) {
  3726. for (var i = 1; i < coord.length; i++) {
  3727. if (coord[i - 1].equals(coord[i])) {
  3728. return true
  3729. }
  3730. }
  3731. return false
  3732. };
  3733. CoordinateArrays.removeRepeatedPoints = function removeRepeatedPoints (coord) {
  3734. if (!CoordinateArrays.hasRepeatedPoints(coord)) { return coord }
  3735. var coordList = new CoordinateList(coord, false);
  3736. return coordList.toCoordinateArray()
  3737. };
  3738. CoordinateArrays.reverse = function reverse (coord) {
  3739. var last = coord.length - 1;
  3740. var mid = Math.trunc(last / 2);
  3741. for (var i = 0; i <= mid; i++) {
  3742. var tmp = coord[i];
  3743. coord[i] = coord[last - i];
  3744. coord[last - i] = tmp;
  3745. }
  3746. };
  3747. CoordinateArrays.removeNull = function removeNull (coord) {
  3748. var nonNull = 0;
  3749. for (var i = 0; i < coord.length; i++) {
  3750. if (coord[i] !== null) { nonNull++; }
  3751. }
  3752. var newCoord = new Array(nonNull).fill(null);
  3753. if (nonNull === 0) { return newCoord }
  3754. var j = 0;
  3755. for (var i$1 = 0; i$1 < coord.length; i$1++) {
  3756. if (coord[i$1] !== null) { newCoord[j++] = coord[i$1]; }
  3757. }
  3758. return newCoord
  3759. };
  3760. CoordinateArrays.copyDeep = function copyDeep () {
  3761. if (arguments.length === 1) {
  3762. var coordinates = arguments[0];
  3763. var copy = new Array(coordinates.length).fill(null);
  3764. for (var i = 0; i < coordinates.length; i++) {
  3765. copy[i] = new Coordinate(coordinates[i]);
  3766. }
  3767. return copy
  3768. } else if (arguments.length === 5) {
  3769. var src = arguments[0];
  3770. var srcStart = arguments[1];
  3771. var dest = arguments[2];
  3772. var destStart = arguments[3];
  3773. var length = arguments[4];
  3774. for (var i$1 = 0; i$1 < length; i$1++) {
  3775. dest[destStart + i$1] = new Coordinate(src[srcStart + i$1]);
  3776. }
  3777. }
  3778. };
  3779. CoordinateArrays.isEqualReversed = function isEqualReversed (pts1, pts2) {
  3780. for (var i = 0; i < pts1.length; i++) {
  3781. var p1 = pts1[i];
  3782. var p2 = pts2[pts1.length - i - 1];
  3783. if (p1.compareTo(p2) !== 0) { return false }
  3784. }
  3785. return true
  3786. };
  3787. CoordinateArrays.envelope = function envelope (coordinates) {
  3788. var env = new Envelope();
  3789. for (var i = 0; i < coordinates.length; i++) {
  3790. env.expandToInclude(coordinates[i]);
  3791. }
  3792. return env
  3793. };
  3794. CoordinateArrays.toCoordinateArray = function toCoordinateArray (coordList) {
  3795. return coordList.toArray(CoordinateArrays.coordArrayType)
  3796. };
  3797. CoordinateArrays.atLeastNCoordinatesOrNothing = function atLeastNCoordinatesOrNothing (n, c) {
  3798. return c.length >= n ? c : []
  3799. };
  3800. CoordinateArrays.indexOf = function indexOf (coordinate, coordinates) {
  3801. for (var i = 0; i < coordinates.length; i++) {
  3802. if (coordinate.equals(coordinates[i])) {
  3803. return i
  3804. }
  3805. }
  3806. return -1
  3807. };
  3808. CoordinateArrays.increasingDirection = function increasingDirection (pts) {
  3809. for (var i = 0; i < Math.trunc(pts.length / 2); i++) {
  3810. var j = pts.length - 1 - i;
  3811. var comp = pts[i].compareTo(pts[j]);
  3812. if (comp !== 0) { return comp }
  3813. }
  3814. return 1
  3815. };
  3816. CoordinateArrays.compare = function compare (pts1, pts2) {
  3817. var i = 0;
  3818. while (i < pts1.length && i < pts2.length) {
  3819. var compare = pts1[i].compareTo(pts2[i]);
  3820. if (compare !== 0) { return compare }
  3821. i++;
  3822. }
  3823. if (i < pts2.length) { return -1 }
  3824. if (i < pts1.length) { return 1 }
  3825. return 0
  3826. };
  3827. CoordinateArrays.minCoordinate = function minCoordinate (coordinates) {
  3828. var minCoord = null;
  3829. for (var i = 0; i < coordinates.length; i++) {
  3830. if (minCoord === null || minCoord.compareTo(coordinates[i]) > 0) {
  3831. minCoord = coordinates[i];
  3832. }
  3833. }
  3834. return minCoord
  3835. };
  3836. CoordinateArrays.extract = function extract (pts, start, end) {
  3837. start = MathUtil.clamp(start, 0, pts.length);
  3838. end = MathUtil.clamp(end, -1, pts.length);
  3839. var npts = end - start + 1;
  3840. if (end < 0) { npts = 0; }
  3841. if (start >= pts.length) { npts = 0; }
  3842. if (end < start) { npts = 0; }
  3843. var extractPts = new Array(npts).fill(null);
  3844. if (npts === 0) { return extractPts }
  3845. var iPts = 0;
  3846. for (var i = start; i <= end; i++) {
  3847. extractPts[iPts++] = pts[i];
  3848. }
  3849. return extractPts
  3850. };
  3851. Object.defineProperties( CoordinateArrays, staticAccessors$13 );
  3852. var ForwardComparator = function ForwardComparator () {};
  3853. ForwardComparator.prototype.compare = function compare (o1, o2) {
  3854. var pts1 = o1;
  3855. var pts2 = o2;
  3856. return CoordinateArrays.compare(pts1, pts2)
  3857. };
  3858. ForwardComparator.prototype.interfaces_ = function interfaces_ () {
  3859. return [Comparator]
  3860. };
  3861. ForwardComparator.prototype.getClass = function getClass () {
  3862. return ForwardComparator
  3863. };
  3864. var BidirectionalComparator = function BidirectionalComparator () {};
  3865. BidirectionalComparator.prototype.compare = function compare (o1, o2) {
  3866. var pts1 = o1;
  3867. var pts2 = o2;
  3868. if (pts1.length < pts2.length) { return -1 }
  3869. if (pts1.length > pts2.length) { return 1 }
  3870. if (pts1.length === 0) { return 0 }
  3871. var forwardComp = CoordinateArrays.compare(pts1, pts2);
  3872. var isEqualRev = CoordinateArrays.isEqualReversed(pts1, pts2);
  3873. if (isEqualRev) { return 0 }
  3874. return forwardComp
  3875. };
  3876. BidirectionalComparator.prototype.OLDcompare = function OLDcompare (o1, o2) {
  3877. var pts1 = o1;
  3878. var pts2 = o2;
  3879. if (pts1.length < pts2.length) { return -1 }
  3880. if (pts1.length > pts2.length) { return 1 }
  3881. if (pts1.length === 0) { return 0 }
  3882. var dir1 = CoordinateArrays.increasingDirection(pts1);
  3883. var dir2 = CoordinateArrays.increasingDirection(pts2);
  3884. var i1 = dir1 > 0 ? 0 : pts1.length - 1;
  3885. var i2 = dir2 > 0 ? 0 : pts1.length - 1;
  3886. for (var i = 0; i < pts1.length; i++) {
  3887. var comparePt = pts1[i1].compareTo(pts2[i2]);
  3888. if (comparePt !== 0) { return comparePt }
  3889. i1 += dir1;
  3890. i2 += dir2;
  3891. }
  3892. return 0
  3893. };
  3894. BidirectionalComparator.prototype.interfaces_ = function interfaces_ () {
  3895. return [Comparator]
  3896. };
  3897. BidirectionalComparator.prototype.getClass = function getClass () {
  3898. return BidirectionalComparator
  3899. };
  3900. /**
  3901. * @see http://download.oracle.com/javase/6/docs/api/java/util/Map.html
  3902. *
  3903. * @constructor
  3904. * @private
  3905. */
  3906. var Map$1 = function Map () {};
  3907. Map$1.prototype.get = function get () {};
  3908. /**
  3909. * Associates the specified value with the specified key in this map (optional
  3910. * operation).
  3911. * @param {Object} key
  3912. * @param {Object} value
  3913. * @return {Object}
  3914. */
  3915. Map$1.prototype.put = function put () {};
  3916. /**
  3917. * Returns the number of key-value mappings in this map.
  3918. * @return {number}
  3919. */
  3920. Map$1.prototype.size = function size () {};
  3921. /**
  3922. * Returns a Collection view of the values contained in this map.
  3923. * @return {javascript.util.Collection}
  3924. */
  3925. Map$1.prototype.values = function values () {};
  3926. /**
  3927. * Returns a {@link Set} view of the mappings contained in this map.
  3928. * The set is backed by the map, so changes to the map are
  3929. * reflected in the set, and vice-versa.If the map is modified
  3930. * while an iteration over the set is in progress (except through
  3931. * the iterator's own <tt>remove</tt> operation, or through the
  3932. * <tt>setValue</tt> operation on a map entry returned by the
  3933. * iterator) the results of the iteration are undefined.The set
  3934. * supports element removal, which removes the corresponding
  3935. * mapping from the map, via the <tt>Iterator.remove</tt>,
  3936. * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
  3937. * <tt>clear</tt> operations.It does not support the
  3938. * <tt>add</tt> or <tt>addAll</tt> operations.
  3939. *
  3940. * @return {Set} a set view of the mappings contained in this map
  3941. */
  3942. Map$1.prototype.entrySet = function entrySet () {};
  3943. /**
  3944. * @see http://download.oracle.com/javase/6/docs/api/java/util/SortedMap.html
  3945. *
  3946. * @extends {Map}
  3947. * @constructor
  3948. * @private
  3949. */
  3950. var SortedMap = (function (Map) {
  3951. function SortedMap () {
  3952. Map.apply(this, arguments);
  3953. }if ( Map ) SortedMap.__proto__ = Map;
  3954. SortedMap.prototype = Object.create( Map && Map.prototype );
  3955. SortedMap.prototype.constructor = SortedMap;
  3956. return SortedMap;
  3957. }(Map$1));
  3958. /**
  3959. * @param {string=} message Optional message
  3960. * @extends {Error}
  3961. * @constructor
  3962. * @private
  3963. */
  3964. function OperationNotSupported (message) {
  3965. this.message = message || '';
  3966. }
  3967. OperationNotSupported.prototype = new Error();
  3968. /**
  3969. * @type {string}
  3970. */
  3971. OperationNotSupported.prototype.name = 'OperationNotSupported';
  3972. /**
  3973. * @see http://download.oracle.com/javase/6/docs/api/java/util/Set.html
  3974. *
  3975. * @extends {Collection}
  3976. * @constructor
  3977. * @private
  3978. */
  3979. function Set() {}
  3980. Set.prototype = new Collection();
  3981. /**
  3982. * Returns true if this set contains the specified element. More formally,
  3983. * returns true if and only if this set contains an element e such that (o==null ?
  3984. * e==null : o.equals(e)).
  3985. * @param {Object} e
  3986. * @return {boolean}
  3987. */
  3988. Set.prototype.contains = function() {};
  3989. /**
  3990. * @see http://docs.oracle.com/javase/6/docs/api/java/util/HashSet.html
  3991. *
  3992. * @extends {javascript.util.Set}
  3993. * @constructor
  3994. * @private
  3995. */
  3996. var HashSet = (function (Set$$1) {
  3997. function HashSet () {
  3998. Set$$1.call(this);
  3999. this.array_ = [];
  4000. if (arguments[0] instanceof Collection) {
  4001. this.addAll(arguments[0]);
  4002. }
  4003. }
  4004. if ( Set$$1 ) HashSet.__proto__ = Set$$1;
  4005. HashSet.prototype = Object.create( Set$$1 && Set$$1.prototype );
  4006. HashSet.prototype.constructor = HashSet;
  4007. /**
  4008. * @override
  4009. */
  4010. HashSet.prototype.contains = function contains (o) {
  4011. var this$1 = this;
  4012. for (var i = 0, len = this.array_.length; i < len; i++) {
  4013. var e = this$1.array_[i];
  4014. if (e === o) {
  4015. return true
  4016. }
  4017. }
  4018. return false
  4019. };
  4020. /**
  4021. * @override
  4022. */
  4023. HashSet.prototype.add = function add (o) {
  4024. if (this.contains(o)) {
  4025. return false
  4026. }
  4027. this.array_.push(o);
  4028. return true
  4029. };
  4030. /**
  4031. * @override
  4032. */
  4033. HashSet.prototype.addAll = function addAll (c) {
  4034. var this$1 = this;
  4035. for (var i = c.iterator(); i.hasNext();) {
  4036. this$1.add(i.next());
  4037. }
  4038. return true
  4039. };
  4040. /**
  4041. * @override
  4042. */
  4043. HashSet.prototype.remove = function remove (o) {
  4044. // throw new javascript.util.OperationNotSupported()
  4045. throw new Error()
  4046. };
  4047. /**
  4048. * @override
  4049. */
  4050. HashSet.prototype.size = function size () {
  4051. return this.array_.length
  4052. };
  4053. /**
  4054. * @override
  4055. */
  4056. HashSet.prototype.isEmpty = function isEmpty () {
  4057. return this.array_.length === 0
  4058. };
  4059. /**
  4060. * @override
  4061. */
  4062. HashSet.prototype.toArray = function toArray () {
  4063. var this$1 = this;
  4064. var array = [];
  4065. for (var i = 0, len = this.array_.length; i < len; i++) {
  4066. array.push(this$1.array_[i]);
  4067. }
  4068. return array
  4069. };
  4070. /**
  4071. * @override
  4072. */
  4073. HashSet.prototype.iterator = function iterator () {
  4074. return new Iterator_$1(this)
  4075. };
  4076. return HashSet;
  4077. }(Set));
  4078. /**
  4079. * @extends {Iterator}
  4080. * @param {HashSet} hashSet
  4081. * @constructor
  4082. * @private
  4083. */
  4084. var Iterator_$1 = (function (Iterator$$1) {
  4085. function Iterator_ (hashSet) {
  4086. Iterator$$1.call(this);
  4087. /**
  4088. * @type {HashSet}
  4089. * @private
  4090. */
  4091. this.hashSet_ = hashSet;
  4092. /**
  4093. * @type {number}
  4094. * @private
  4095. */
  4096. this.position_ = 0;
  4097. }
  4098. if ( Iterator$$1 ) Iterator_.__proto__ = Iterator$$1;
  4099. Iterator_.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
  4100. Iterator_.prototype.constructor = Iterator_;
  4101. /**
  4102. * @override
  4103. */
  4104. Iterator_.prototype.next = function next () {
  4105. if (this.position_ === this.hashSet_.size()) {
  4106. throw new NoSuchElementException()
  4107. }
  4108. return this.hashSet_.array_[this.position_++]
  4109. };
  4110. /**
  4111. * @override
  4112. */
  4113. Iterator_.prototype.hasNext = function hasNext () {
  4114. if (this.position_ < this.hashSet_.size()) {
  4115. return true
  4116. } else {
  4117. return false
  4118. }
  4119. };
  4120. /**
  4121. * @override
  4122. */
  4123. Iterator_.prototype.remove = function remove () {
  4124. throw new OperationNotSupported()
  4125. };
  4126. return Iterator_;
  4127. }(Iterator));
  4128. var BLACK = 0;
  4129. var RED = 1;
  4130. function colorOf (p) { return (p === null ? BLACK : p.color) }
  4131. function parentOf (p) { return (p === null ? null : p.parent) }
  4132. function setColor (p, c) { if (p !== null) { p.color = c; } }
  4133. function leftOf (p) { return (p === null ? null : p.left) }
  4134. function rightOf (p) { return (p === null ? null : p.right) }
  4135. /**
  4136. * @see http://download.oracle.com/javase/6/docs/api/java/util/TreeMap.html
  4137. *
  4138. * @extends {SortedMap}
  4139. * @constructor
  4140. * @private
  4141. */
  4142. function TreeMap () {
  4143. /**
  4144. * @type {Object}
  4145. * @private
  4146. */
  4147. this.root_ = null;
  4148. /**
  4149. * @type {number}
  4150. * @private
  4151. */
  4152. this.size_ = 0;
  4153. }
  4154. TreeMap.prototype = new SortedMap();
  4155. /**
  4156. * @override
  4157. */
  4158. TreeMap.prototype.get = function (key) {
  4159. var p = this.root_;
  4160. while (p !== null) {
  4161. var cmp = key['compareTo'](p.key);
  4162. if (cmp < 0) { p = p.left; }
  4163. else if (cmp > 0) { p = p.right; }
  4164. else { return p.value }
  4165. }
  4166. return null
  4167. };
  4168. /**
  4169. * @override
  4170. */
  4171. TreeMap.prototype.put = function (key, value) {
  4172. if (this.root_ === null) {
  4173. this.root_ = {
  4174. key: key,
  4175. value: value,
  4176. left: null,
  4177. right: null,
  4178. parent: null,
  4179. color: BLACK,
  4180. getValue: function getValue () { return this.value },
  4181. getKey: function getKey () { return this.key }
  4182. };
  4183. this.size_ = 1;
  4184. return null
  4185. }
  4186. var t = this.root_;
  4187. var parent;
  4188. var cmp;
  4189. do {
  4190. parent = t;
  4191. cmp = key['compareTo'](t.key);
  4192. if (cmp < 0) {
  4193. t = t.left;
  4194. } else if (cmp > 0) {
  4195. t = t.right;
  4196. } else {
  4197. var oldValue = t.value;
  4198. t.value = value;
  4199. return oldValue
  4200. }
  4201. } while (t !== null)
  4202. var e = {
  4203. key: key,
  4204. left: null,
  4205. right: null,
  4206. value: value,
  4207. parent: parent,
  4208. color: BLACK,
  4209. getValue: function getValue () { return this.value },
  4210. getKey: function getKey () { return this.key }
  4211. };
  4212. if (cmp < 0) {
  4213. parent.left = e;
  4214. } else {
  4215. parent.right = e;
  4216. }
  4217. this.fixAfterInsertion(e);
  4218. this.size_++;
  4219. return null
  4220. };
  4221. /**
  4222. * @param {Object} x
  4223. */
  4224. TreeMap.prototype.fixAfterInsertion = function (x) {
  4225. var this$1 = this;
  4226. x.color = RED;
  4227. while (x != null && x !== this.root_ && x.parent.color === RED) {
  4228. if (parentOf(x) === leftOf(parentOf(parentOf(x)))) {
  4229. var y = rightOf(parentOf(parentOf(x)));
  4230. if (colorOf(y) === RED) {
  4231. setColor(parentOf(x), BLACK);
  4232. setColor(y, BLACK);
  4233. setColor(parentOf(parentOf(x)), RED);
  4234. x = parentOf(parentOf(x));
  4235. } else {
  4236. if (x === rightOf(parentOf(x))) {
  4237. x = parentOf(x);
  4238. this$1.rotateLeft(x);
  4239. }
  4240. setColor(parentOf(x), BLACK);
  4241. setColor(parentOf(parentOf(x)), RED);
  4242. this$1.rotateRight(parentOf(parentOf(x)));
  4243. }
  4244. } else {
  4245. var y$1 = leftOf(parentOf(parentOf(x)));
  4246. if (colorOf(y$1) === RED) {
  4247. setColor(parentOf(x), BLACK);
  4248. setColor(y$1, BLACK);
  4249. setColor(parentOf(parentOf(x)), RED);
  4250. x = parentOf(parentOf(x));
  4251. } else {
  4252. if (x === leftOf(parentOf(x))) {
  4253. x = parentOf(x);
  4254. this$1.rotateRight(x);
  4255. }
  4256. setColor(parentOf(x), BLACK);
  4257. setColor(parentOf(parentOf(x)), RED);
  4258. this$1.rotateLeft(parentOf(parentOf(x)));
  4259. }
  4260. }
  4261. }
  4262. this.root_.color = BLACK;
  4263. };
  4264. /**
  4265. * @override
  4266. */
  4267. TreeMap.prototype.values = function () {
  4268. var arrayList = new ArrayList();
  4269. var p = this.getFirstEntry();
  4270. if (p !== null) {
  4271. arrayList.add(p.value);
  4272. while ((p = TreeMap.successor(p)) !== null) {
  4273. arrayList.add(p.value);
  4274. }
  4275. }
  4276. return arrayList
  4277. };
  4278. /**
  4279. * @override
  4280. */
  4281. TreeMap.prototype.entrySet = function () {
  4282. var hashSet = new HashSet();
  4283. var p = this.getFirstEntry();
  4284. if (p !== null) {
  4285. hashSet.add(p);
  4286. while ((p = TreeMap.successor(p)) !== null) {
  4287. hashSet.add(p);
  4288. }
  4289. }
  4290. return hashSet
  4291. };
  4292. /**
  4293. * @param {Object} p
  4294. */
  4295. TreeMap.prototype.rotateLeft = function (p) {
  4296. if (p != null) {
  4297. var r = p.right;
  4298. p.right = r.left;
  4299. if (r.left != null) { r.left.parent = p; }
  4300. r.parent = p.parent;
  4301. if (p.parent === null) { this.root_ = r; } else if (p.parent.left === p) { p.parent.left = r; } else { p.parent.right = r; }
  4302. r.left = p;
  4303. p.parent = r;
  4304. }
  4305. };
  4306. /**
  4307. * @param {Object} p
  4308. */
  4309. TreeMap.prototype.rotateRight = function (p) {
  4310. if (p != null) {
  4311. var l = p.left;
  4312. p.left = l.right;
  4313. if (l.right != null) { l.right.parent = p; }
  4314. l.parent = p.parent;
  4315. if (p.parent === null) { this.root_ = l; } else if (p.parent.right === p) { p.parent.right = l; } else { p.parent.left = l; }
  4316. l.right = p;
  4317. p.parent = l;
  4318. }
  4319. };
  4320. /**
  4321. * @return {Object}
  4322. */
  4323. TreeMap.prototype.getFirstEntry = function () {
  4324. var p = this.root_;
  4325. if (p != null) {
  4326. while (p.left != null) {
  4327. p = p.left;
  4328. }
  4329. }
  4330. return p
  4331. };
  4332. /**
  4333. * @param {Object} t
  4334. * @return {Object}
  4335. * @private
  4336. */
  4337. TreeMap.successor = function (t) {
  4338. if (t === null) { return null } else if (t.right !== null) {
  4339. var p = t.right;
  4340. while (p.left !== null) {
  4341. p = p.left;
  4342. }
  4343. return p
  4344. } else {
  4345. var p$1 = t.parent;
  4346. var ch = t;
  4347. while (p$1 !== null && ch === p$1.right) {
  4348. ch = p$1;
  4349. p$1 = p$1.parent;
  4350. }
  4351. return p$1
  4352. }
  4353. };
  4354. /**
  4355. * @override
  4356. */
  4357. TreeMap.prototype.size = function () {
  4358. return this.size_
  4359. };
  4360. var Lineal = function Lineal () {};
  4361. Lineal.prototype.interfaces_ = function interfaces_ () {
  4362. return []
  4363. };
  4364. Lineal.prototype.getClass = function getClass () {
  4365. return Lineal
  4366. };
  4367. /**
  4368. * @see http://download.oracle.com/javase/6/docs/api/java/util/SortedSet.html
  4369. *
  4370. * @extends {Set}
  4371. * @constructor
  4372. * @private
  4373. */
  4374. function SortedSet () {}
  4375. SortedSet.prototype = new Set();
  4376. // import Iterator from './Iterator'
  4377. /**
  4378. * @see http://download.oracle.com/javase/6/docs/api/java/util/TreeSet.html
  4379. *
  4380. * @extends {SortedSet}
  4381. * @constructor
  4382. * @private
  4383. */
  4384. function TreeSet () {
  4385. /**
  4386. * @type {Array}
  4387. * @private
  4388. */
  4389. this.array_ = [];
  4390. if (arguments[0] instanceof Collection) {
  4391. this.addAll(arguments[0]);
  4392. }
  4393. }
  4394. TreeSet.prototype = new SortedSet();
  4395. /**
  4396. * @override
  4397. */
  4398. TreeSet.prototype.contains = function (o) {
  4399. var this$1 = this;
  4400. for (var i = 0, len = this.array_.length; i < len; i++) {
  4401. var e = this$1.array_[i];
  4402. if (e['compareTo'](o) === 0) {
  4403. return true
  4404. }
  4405. }
  4406. return false
  4407. };
  4408. /**
  4409. * @override
  4410. */
  4411. TreeSet.prototype.add = function (o) {
  4412. var this$1 = this;
  4413. if (this.contains(o)) {
  4414. return false
  4415. }
  4416. for (var i = 0, len = this.array_.length; i < len; i++) {
  4417. var e = this$1.array_[i];
  4418. if (e['compareTo'](o) === 1) {
  4419. this$1.array_.splice(i, 0, o);
  4420. return true
  4421. }
  4422. }
  4423. this.array_.push(o);
  4424. return true
  4425. };
  4426. /**
  4427. * @override
  4428. */
  4429. TreeSet.prototype.addAll = function (c) {
  4430. var this$1 = this;
  4431. for (var i = c.iterator(); i.hasNext();) {
  4432. this$1.add(i.next());
  4433. }
  4434. return true
  4435. };
  4436. /**
  4437. * @override
  4438. */
  4439. TreeSet.prototype.remove = function (e) {
  4440. throw new OperationNotSupported()
  4441. };
  4442. /**
  4443. * @override
  4444. */
  4445. TreeSet.prototype.size = function () {
  4446. return this.array_.length
  4447. };
  4448. /**
  4449. * @override
  4450. */
  4451. TreeSet.prototype.isEmpty = function () {
  4452. return this.array_.length === 0
  4453. };
  4454. /**
  4455. * @override
  4456. */
  4457. TreeSet.prototype.toArray = function () {
  4458. var this$1 = this;
  4459. var array = [];
  4460. for (var i = 0, len = this.array_.length; i < len; i++) {
  4461. array.push(this$1.array_[i]);
  4462. }
  4463. return array
  4464. };
  4465. /**
  4466. * @override
  4467. */
  4468. TreeSet.prototype.iterator = function () {
  4469. return new Iterator_$2(this)
  4470. };
  4471. /**
  4472. * @extends {javascript.util.Iterator}
  4473. * @param {javascript.util.TreeSet} treeSet
  4474. * @constructor
  4475. * @private
  4476. */
  4477. var Iterator_$2 = function (treeSet) {
  4478. /**
  4479. * @type {javascript.util.TreeSet}
  4480. * @private
  4481. */
  4482. this.treeSet_ = treeSet;
  4483. /**
  4484. * @type {number}
  4485. * @private
  4486. */
  4487. this.position_ = 0;
  4488. };
  4489. /**
  4490. * @override
  4491. */
  4492. Iterator_$2.prototype.next = function () {
  4493. if (this.position_ === this.treeSet_.size()) {
  4494. throw new NoSuchElementException()
  4495. }
  4496. return this.treeSet_.array_[this.position_++]
  4497. };
  4498. /**
  4499. * @override
  4500. */
  4501. Iterator_$2.prototype.hasNext = function () {
  4502. if (this.position_ < this.treeSet_.size()) {
  4503. return true
  4504. } else {
  4505. return false
  4506. }
  4507. };
  4508. /**
  4509. * @override
  4510. */
  4511. Iterator_$2.prototype.remove = function () {
  4512. throw new OperationNotSupported()
  4513. };
  4514. /**
  4515. * @see http://download.oracle.com/javase/6/docs/api/java/util/Arrays.html
  4516. *
  4517. * @constructor
  4518. * @private
  4519. */
  4520. var Arrays = function Arrays () {};
  4521. Arrays.sort = function sort () {
  4522. var a = arguments[0];
  4523. var i;
  4524. var t;
  4525. var comparator;
  4526. var compare;
  4527. if (arguments.length === 1) {
  4528. compare = function (a, b) {
  4529. return a.compareTo(b)
  4530. };
  4531. a.sort(compare);
  4532. } else if (arguments.length === 2) {
  4533. comparator = arguments[1];
  4534. compare = function (a, b) {
  4535. return comparator['compare'](a, b)
  4536. };
  4537. a.sort(compare);
  4538. } else if (arguments.length === 3) {
  4539. t = a.slice(arguments[1], arguments[2]);
  4540. t.sort();
  4541. var r = a.slice(0, arguments[1]).concat(t, a.slice(arguments[2], a.length));
  4542. a.splice(0, a.length);
  4543. for (i = 0; i < r.length; i++) {
  4544. a.push(r[i]);
  4545. }
  4546. } else if (arguments.length === 4) {
  4547. t = a.slice(arguments[1], arguments[2]);
  4548. comparator = arguments[3];
  4549. compare = function (a, b) {
  4550. return comparator['compare'](a, b)
  4551. };
  4552. t.sort(compare);
  4553. r = a.slice(0, arguments[1]).concat(t, a.slice(arguments[2], a.length));
  4554. a.splice(0, a.length);
  4555. for (i = 0; i < r.length; i++) {
  4556. a.push(r[i]);
  4557. }
  4558. }
  4559. };
  4560. /**
  4561. * @param {Array} array
  4562. * @return {ArrayList}
  4563. */
  4564. Arrays.asList = function asList (array) {
  4565. var arrayList = new ArrayList();
  4566. for (var i = 0, len = array.length; i < len; i++) {
  4567. arrayList.add(array[i]);
  4568. }
  4569. return arrayList
  4570. };
  4571. var Dimension = function Dimension () {};
  4572. 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 } };
  4573. staticAccessors$14.P.get = function () { return 0 };
  4574. staticAccessors$14.L.get = function () { return 1 };
  4575. staticAccessors$14.A.get = function () { return 2 };
  4576. staticAccessors$14.FALSE.get = function () { return -1 };
  4577. staticAccessors$14.TRUE.get = function () { return -2 };
  4578. staticAccessors$14.DONTCARE.get = function () { return -3 };
  4579. staticAccessors$14.SYM_FALSE.get = function () { return 'F' };
  4580. staticAccessors$14.SYM_TRUE.get = function () { return 'T' };
  4581. staticAccessors$14.SYM_DONTCARE.get = function () { return '*' };
  4582. staticAccessors$14.SYM_P.get = function () { return '0' };
  4583. staticAccessors$14.SYM_L.get = function () { return '1' };
  4584. staticAccessors$14.SYM_A.get = function () { return '2' };
  4585. Dimension.prototype.interfaces_ = function interfaces_ () {
  4586. return []
  4587. };
  4588. Dimension.prototype.getClass = function getClass () {
  4589. return Dimension
  4590. };
  4591. Dimension.toDimensionSymbol = function toDimensionSymbol (dimensionValue) {
  4592. switch (dimensionValue) {
  4593. case Dimension.FALSE:
  4594. return Dimension.SYM_FALSE
  4595. case Dimension.TRUE:
  4596. return Dimension.SYM_TRUE
  4597. case Dimension.DONTCARE:
  4598. return Dimension.SYM_DONTCARE
  4599. case Dimension.P:
  4600. return Dimension.SYM_P
  4601. case Dimension.L:
  4602. return Dimension.SYM_L
  4603. case Dimension.A:
  4604. return Dimension.SYM_A
  4605. default:
  4606. }
  4607. throw new IllegalArgumentException('Unknown dimension value: ' + dimensionValue)
  4608. };
  4609. Dimension.toDimensionValue = function toDimensionValue (dimensionSymbol) {
  4610. switch (Character.toUpperCase(dimensionSymbol)) {
  4611. case Dimension.SYM_FALSE:
  4612. return Dimension.FALSE
  4613. case Dimension.SYM_TRUE:
  4614. return Dimension.TRUE
  4615. case Dimension.SYM_DONTCARE:
  4616. return Dimension.DONTCARE
  4617. case Dimension.SYM_P:
  4618. return Dimension.P
  4619. case Dimension.SYM_L:
  4620. return Dimension.L
  4621. case Dimension.SYM_A:
  4622. return Dimension.A
  4623. default:
  4624. }
  4625. throw new IllegalArgumentException('Unknown dimension symbol: ' + dimensionSymbol)
  4626. };
  4627. Object.defineProperties( Dimension, staticAccessors$14 );
  4628. var GeometryFilter = function GeometryFilter () {};
  4629. GeometryFilter.prototype.filter = function filter (geom) {};
  4630. GeometryFilter.prototype.interfaces_ = function interfaces_ () {
  4631. return []
  4632. };
  4633. GeometryFilter.prototype.getClass = function getClass () {
  4634. return GeometryFilter
  4635. };
  4636. var CoordinateSequenceFilter = function CoordinateSequenceFilter () {};
  4637. CoordinateSequenceFilter.prototype.filter = function filter (seq, i) {};
  4638. CoordinateSequenceFilter.prototype.isDone = function isDone () {};
  4639. CoordinateSequenceFilter.prototype.isGeometryChanged = function isGeometryChanged () {};
  4640. CoordinateSequenceFilter.prototype.interfaces_ = function interfaces_ () {
  4641. return []
  4642. };
  4643. CoordinateSequenceFilter.prototype.getClass = function getClass () {
  4644. return CoordinateSequenceFilter
  4645. };
  4646. var GeometryCollection = (function (Geometry$$1) {
  4647. function GeometryCollection (geometries, factory) {
  4648. Geometry$$1.call(this, factory);
  4649. this._geometries = geometries || [];
  4650. if (Geometry$$1.hasNullElements(this._geometries)) {
  4651. throw new IllegalArgumentException('geometries must not contain null elements')
  4652. }
  4653. }
  4654. if ( Geometry$$1 ) GeometryCollection.__proto__ = Geometry$$1;
  4655. GeometryCollection.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
  4656. GeometryCollection.prototype.constructor = GeometryCollection;
  4657. var staticAccessors = { serialVersionUID: { configurable: true } };
  4658. GeometryCollection.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
  4659. var this$1 = this;
  4660. var envelope = new Envelope();
  4661. for (var i = 0; i < this._geometries.length; i++) {
  4662. envelope.expandToInclude(this$1._geometries[i].getEnvelopeInternal());
  4663. }
  4664. return envelope
  4665. };
  4666. GeometryCollection.prototype.getGeometryN = function getGeometryN (n) {
  4667. return this._geometries[n]
  4668. };
  4669. GeometryCollection.prototype.getSortIndex = function getSortIndex () {
  4670. return Geometry$$1.SORTINDEX_GEOMETRYCOLLECTION
  4671. };
  4672. GeometryCollection.prototype.getCoordinates = function getCoordinates () {
  4673. var this$1 = this;
  4674. var coordinates = new Array(this.getNumPoints()).fill(null);
  4675. var k = -1;
  4676. for (var i = 0; i < this._geometries.length; i++) {
  4677. var childCoordinates = this$1._geometries[i].getCoordinates();
  4678. for (var j = 0; j < childCoordinates.length; j++) {
  4679. k++;
  4680. coordinates[k] = childCoordinates[j];
  4681. }
  4682. }
  4683. return coordinates
  4684. };
  4685. GeometryCollection.prototype.getArea = function getArea () {
  4686. var this$1 = this;
  4687. var area = 0.0;
  4688. for (var i = 0; i < this._geometries.length; i++) {
  4689. area += this$1._geometries[i].getArea();
  4690. }
  4691. return area
  4692. };
  4693. GeometryCollection.prototype.equalsExact = function equalsExact () {
  4694. var this$1 = this;
  4695. if (arguments.length === 2) {
  4696. var other = arguments[0];
  4697. var tolerance = arguments[1];
  4698. if (!this.isEquivalentClass(other)) {
  4699. return false
  4700. }
  4701. var otherCollection = other;
  4702. if (this._geometries.length !== otherCollection._geometries.length) {
  4703. return false
  4704. }
  4705. for (var i = 0; i < this._geometries.length; i++) {
  4706. if (!this$1._geometries[i].equalsExact(otherCollection._geometries[i], tolerance)) {
  4707. return false
  4708. }
  4709. }
  4710. return true
  4711. } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
  4712. };
  4713. GeometryCollection.prototype.normalize = function normalize () {
  4714. var this$1 = this;
  4715. for (var i = 0; i < this._geometries.length; i++) {
  4716. this$1._geometries[i].normalize();
  4717. }
  4718. Arrays.sort(this._geometries);
  4719. };
  4720. GeometryCollection.prototype.getCoordinate = function getCoordinate () {
  4721. if (this.isEmpty()) { return null }
  4722. return this._geometries[0].getCoordinate()
  4723. };
  4724. GeometryCollection.prototype.getBoundaryDimension = function getBoundaryDimension () {
  4725. var this$1 = this;
  4726. var dimension = Dimension.FALSE;
  4727. for (var i = 0; i < this._geometries.length; i++) {
  4728. dimension = Math.max(dimension, this$1._geometries[i].getBoundaryDimension());
  4729. }
  4730. return dimension
  4731. };
  4732. GeometryCollection.prototype.getDimension = function getDimension () {
  4733. var this$1 = this;
  4734. var dimension = Dimension.FALSE;
  4735. for (var i = 0; i < this._geometries.length; i++) {
  4736. dimension = Math.max(dimension, this$1._geometries[i].getDimension());
  4737. }
  4738. return dimension
  4739. };
  4740. GeometryCollection.prototype.getLength = function getLength () {
  4741. var this$1 = this;
  4742. var sum = 0.0;
  4743. for (var i = 0; i < this._geometries.length; i++) {
  4744. sum += this$1._geometries[i].getLength();
  4745. }
  4746. return sum
  4747. };
  4748. GeometryCollection.prototype.getNumPoints = function getNumPoints () {
  4749. var this$1 = this;
  4750. var numPoints = 0;
  4751. for (var i = 0; i < this._geometries.length; i++) {
  4752. numPoints += this$1._geometries[i].getNumPoints();
  4753. }
  4754. return numPoints
  4755. };
  4756. GeometryCollection.prototype.getNumGeometries = function getNumGeometries () {
  4757. return this._geometries.length
  4758. };
  4759. GeometryCollection.prototype.reverse = function reverse () {
  4760. var this$1 = this;
  4761. var n = this._geometries.length;
  4762. var revGeoms = new Array(n).fill(null);
  4763. for (var i = 0; i < this._geometries.length; i++) {
  4764. revGeoms[i] = this$1._geometries[i].reverse();
  4765. }
  4766. return this.getFactory().createGeometryCollection(revGeoms)
  4767. };
  4768. GeometryCollection.prototype.compareToSameClass = function compareToSameClass () {
  4769. var this$1 = this;
  4770. if (arguments.length === 1) {
  4771. var o = arguments[0];
  4772. var theseElements = new TreeSet(Arrays.asList(this._geometries));
  4773. var otherElements = new TreeSet(Arrays.asList(o._geometries));
  4774. return this.compare(theseElements, otherElements)
  4775. } else if (arguments.length === 2) {
  4776. var o$1 = arguments[0];
  4777. var comp = arguments[1];
  4778. var gc = o$1;
  4779. var n1 = this.getNumGeometries();
  4780. var n2 = gc.getNumGeometries();
  4781. var i = 0;
  4782. while (i < n1 && i < n2) {
  4783. var thisGeom = this$1.getGeometryN(i);
  4784. var otherGeom = gc.getGeometryN(i);
  4785. var holeComp = thisGeom.compareToSameClass(otherGeom, comp);
  4786. if (holeComp !== 0) { return holeComp }
  4787. i++;
  4788. }
  4789. if (i < n1) { return 1 }
  4790. if (i < n2) { return -1 }
  4791. return 0
  4792. }
  4793. };
  4794. GeometryCollection.prototype.apply = function apply () {
  4795. var this$1 = this;
  4796. if (hasInterface(arguments[0], CoordinateFilter)) {
  4797. var filter = arguments[0];
  4798. for (var i = 0; i < this._geometries.length; i++) {
  4799. this$1._geometries[i].apply(filter);
  4800. }
  4801. } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {
  4802. var filter$1 = arguments[0];
  4803. if (this._geometries.length === 0) { return null }
  4804. for (var i$1 = 0; i$1 < this._geometries.length; i$1++) {
  4805. this$1._geometries[i$1].apply(filter$1);
  4806. if (filter$1.isDone()) {
  4807. break
  4808. }
  4809. }
  4810. if (filter$1.isGeometryChanged()) { this.geometryChanged(); }
  4811. } else if (hasInterface(arguments[0], GeometryFilter)) {
  4812. var filter$2 = arguments[0];
  4813. filter$2.filter(this);
  4814. for (var i$2 = 0; i$2 < this._geometries.length; i$2++) {
  4815. this$1._geometries[i$2].apply(filter$2);
  4816. }
  4817. } else if (hasInterface(arguments[0], GeometryComponentFilter)) {
  4818. var filter$3 = arguments[0];
  4819. filter$3.filter(this);
  4820. for (var i$3 = 0; i$3 < this._geometries.length; i$3++) {
  4821. this$1._geometries[i$3].apply(filter$3);
  4822. }
  4823. }
  4824. };
  4825. GeometryCollection.prototype.getBoundary = function getBoundary () {
  4826. this.checkNotGeometryCollection(this);
  4827. Assert.shouldNeverReachHere();
  4828. return null
  4829. };
  4830. GeometryCollection.prototype.clone = function clone () {
  4831. var this$1 = this;
  4832. var gc = Geometry$$1.prototype.clone.call(this);
  4833. gc._geometries = new Array(this._geometries.length).fill(null);
  4834. for (var i = 0; i < this._geometries.length; i++) {
  4835. gc._geometries[i] = this$1._geometries[i].clone();
  4836. }
  4837. return gc
  4838. };
  4839. GeometryCollection.prototype.getGeometryType = function getGeometryType () {
  4840. return 'GeometryCollection'
  4841. };
  4842. GeometryCollection.prototype.copy = function copy () {
  4843. var this$1 = this;
  4844. var geometries = new Array(this._geometries.length).fill(null);
  4845. for (var i = 0; i < geometries.length; i++) {
  4846. geometries[i] = this$1._geometries[i].copy();
  4847. }
  4848. return new GeometryCollection(geometries, this._factory)
  4849. };
  4850. GeometryCollection.prototype.isEmpty = function isEmpty () {
  4851. var this$1 = this;
  4852. for (var i = 0; i < this._geometries.length; i++) {
  4853. if (!this$1._geometries[i].isEmpty()) {
  4854. return false
  4855. }
  4856. }
  4857. return true
  4858. };
  4859. GeometryCollection.prototype.interfaces_ = function interfaces_ () {
  4860. return []
  4861. };
  4862. GeometryCollection.prototype.getClass = function getClass () {
  4863. return GeometryCollection
  4864. };
  4865. staticAccessors.serialVersionUID.get = function () { return -5694727726395021467 };
  4866. Object.defineProperties( GeometryCollection, staticAccessors );
  4867. return GeometryCollection;
  4868. }(Geometry));
  4869. var MultiLineString = (function (GeometryCollection$$1) {
  4870. function MultiLineString () {
  4871. GeometryCollection$$1.apply(this, arguments);
  4872. }
  4873. if ( GeometryCollection$$1 ) MultiLineString.__proto__ = GeometryCollection$$1;
  4874. MultiLineString.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );
  4875. MultiLineString.prototype.constructor = MultiLineString;
  4876. var staticAccessors = { serialVersionUID: { configurable: true } };
  4877. MultiLineString.prototype.getSortIndex = function getSortIndex () {
  4878. return Geometry.SORTINDEX_MULTILINESTRING
  4879. };
  4880. MultiLineString.prototype.equalsExact = function equalsExact () {
  4881. if (arguments.length === 2) {
  4882. var other = arguments[0];
  4883. var tolerance = arguments[1];
  4884. if (!this.isEquivalentClass(other)) {
  4885. return false
  4886. }
  4887. return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)
  4888. } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }
  4889. };
  4890. MultiLineString.prototype.getBoundaryDimension = function getBoundaryDimension () {
  4891. if (this.isClosed()) {
  4892. return Dimension.FALSE
  4893. }
  4894. return 0
  4895. };
  4896. MultiLineString.prototype.isClosed = function isClosed () {
  4897. var this$1 = this;
  4898. if (this.isEmpty()) {
  4899. return false
  4900. }
  4901. for (var i = 0; i < this._geometries.length; i++) {
  4902. if (!this$1._geometries[i].isClosed()) {
  4903. return false
  4904. }
  4905. }
  4906. return true
  4907. };
  4908. MultiLineString.prototype.getDimension = function getDimension () {
  4909. return 1
  4910. };
  4911. MultiLineString.prototype.reverse = function reverse () {
  4912. var this$1 = this;
  4913. var nLines = this._geometries.length;
  4914. var revLines = new Array(nLines).fill(null);
  4915. for (var i = 0; i < this._geometries.length; i++) {
  4916. revLines[nLines - 1 - i] = this$1._geometries[i].reverse();
  4917. }
  4918. return this.getFactory().createMultiLineString(revLines)
  4919. };
  4920. MultiLineString.prototype.getBoundary = function getBoundary () {
  4921. return new BoundaryOp(this).getBoundary()
  4922. };
  4923. MultiLineString.prototype.getGeometryType = function getGeometryType () {
  4924. return 'MultiLineString'
  4925. };
  4926. MultiLineString.prototype.copy = function copy () {
  4927. var this$1 = this;
  4928. var lineStrings = new Array(this._geometries.length).fill(null);
  4929. for (var i = 0; i < lineStrings.length; i++) {
  4930. lineStrings[i] = this$1._geometries[i].copy();
  4931. }
  4932. return new MultiLineString(lineStrings, this._factory)
  4933. };
  4934. MultiLineString.prototype.interfaces_ = function interfaces_ () {
  4935. return [Lineal]
  4936. };
  4937. MultiLineString.prototype.getClass = function getClass () {
  4938. return MultiLineString
  4939. };
  4940. staticAccessors.serialVersionUID.get = function () { return 8166665132445433741 };
  4941. Object.defineProperties( MultiLineString, staticAccessors );
  4942. return MultiLineString;
  4943. }(GeometryCollection));
  4944. var BoundaryOp = function BoundaryOp () {
  4945. this._geom = null;
  4946. this._geomFact = null;
  4947. this._bnRule = null;
  4948. this._endpointMap = null;
  4949. if (arguments.length === 1) {
  4950. var geom = arguments[0];
  4951. var bnRule = BoundaryNodeRule.MOD2_BOUNDARY_RULE;
  4952. this._geom = geom;
  4953. this._geomFact = geom.getFactory();
  4954. this._bnRule = bnRule;
  4955. } else if (arguments.length === 2) {
  4956. var geom$1 = arguments[0];
  4957. var bnRule$1 = arguments[1];
  4958. this._geom = geom$1;
  4959. this._geomFact = geom$1.getFactory();
  4960. this._bnRule = bnRule$1;
  4961. }
  4962. };
  4963. BoundaryOp.prototype.boundaryMultiLineString = function boundaryMultiLineString (mLine) {
  4964. if (this._geom.isEmpty()) {
  4965. return this.getEmptyMultiPoint()
  4966. }
  4967. var bdyPts = this.computeBoundaryCoordinates(mLine);
  4968. if (bdyPts.length === 1) {
  4969. return this._geomFact.createPoint(bdyPts[0])
  4970. }
  4971. return this._geomFact.createMultiPointFromCoords(bdyPts)
  4972. };
  4973. BoundaryOp.prototype.getBoundary = function getBoundary () {
  4974. if (this._geom instanceof LineString) { return this.boundaryLineString(this._geom) }
  4975. if (this._geom instanceof MultiLineString) { return this.boundaryMultiLineString(this._geom) }
  4976. return this._geom.getBoundary()
  4977. };
  4978. BoundaryOp.prototype.boundaryLineString = function boundaryLineString (line) {
  4979. if (this._geom.isEmpty()) {
  4980. return this.getEmptyMultiPoint()
  4981. }
  4982. if (line.isClosed()) {
  4983. var closedEndpointOnBoundary = this._bnRule.isInBoundary(2);
  4984. if (closedEndpointOnBoundary) {
  4985. return line.getStartPoint()
  4986. } else {
  4987. return this._geomFact.createMultiPoint()
  4988. }
  4989. }
  4990. return this._geomFact.createMultiPoint([line.getStartPoint(), line.getEndPoint()])
  4991. };
  4992. BoundaryOp.prototype.getEmptyMultiPoint = function getEmptyMultiPoint () {
  4993. return this._geomFact.createMultiPoint()
  4994. };
  4995. BoundaryOp.prototype.computeBoundaryCoordinates = function computeBoundaryCoordinates (mLine) {
  4996. var this$1 = this;
  4997. var bdyPts = new ArrayList();
  4998. this._endpointMap = new TreeMap();
  4999. for (var i = 0; i < mLine.getNumGeometries(); i++) {
  5000. var line = mLine.getGeometryN(i);
  5001. if (line.getNumPoints() === 0) { continue }
  5002. this$1.addEndpoint(line.getCoordinateN(0));
  5003. this$1.addEndpoint(line.getCoordinateN(line.getNumPoints() - 1));
  5004. }
  5005. for (var it = this._endpointMap.entrySet().iterator(); it.hasNext();) {
  5006. var entry = it.next();
  5007. var counter = entry.getValue();
  5008. var valence = counter.count;
  5009. if (this$1._bnRule.isInBoundary(valence)) {
  5010. bdyPts.add(entry.getKey());
  5011. }
  5012. }
  5013. return CoordinateArrays.toCoordinateArray(bdyPts)
  5014. };
  5015. BoundaryOp.prototype.addEndpoint = function addEndpoint (pt) {
  5016. var counter = this._endpointMap.get(pt);
  5017. if (counter === null) {
  5018. counter = new Counter();
  5019. this._endpointMap.put(pt, counter);
  5020. }
  5021. counter.count++;
  5022. };
  5023. BoundaryOp.prototype.interfaces_ = function interfaces_ () {
  5024. return []
  5025. };
  5026. BoundaryOp.prototype.getClass = function getClass () {
  5027. return BoundaryOp
  5028. };
  5029. BoundaryOp.getBoundary = function getBoundary () {
  5030. if (arguments.length === 1) {
  5031. var g = arguments[0];
  5032. var bop = new BoundaryOp(g);
  5033. return bop.getBoundary()
  5034. } else if (arguments.length === 2) {
  5035. var g$1 = arguments[0];
  5036. var bnRule = arguments[1];
  5037. var bop$1 = new BoundaryOp(g$1, bnRule);
  5038. return bop$1.getBoundary()
  5039. }
  5040. };
  5041. var Counter = function Counter () {
  5042. this.count = null;
  5043. };
  5044. Counter.prototype.interfaces_ = function interfaces_ () {
  5045. return []
  5046. };
  5047. Counter.prototype.getClass = function getClass () {
  5048. return Counter
  5049. };
  5050. // boundary
  5051. function PrintStream () {}
  5052. function StringReader () {}
  5053. var DecimalFormat = function DecimalFormat () {};
  5054. function ByteArrayOutputStream () {}
  5055. function IOException () {}
  5056. function LineNumberReader () {}
  5057. var StringUtil = function StringUtil () {};
  5058. var staticAccessors$15 = { NEWLINE: { configurable: true },SIMPLE_ORDINATE_FORMAT: { configurable: true } };
  5059. StringUtil.prototype.interfaces_ = function interfaces_ () {
  5060. return []
  5061. };
  5062. StringUtil.prototype.getClass = function getClass () {
  5063. return StringUtil
  5064. };
  5065. StringUtil.chars = function chars (c, n) {
  5066. var ch = new Array(n).fill(null);
  5067. for (var i = 0; i < n; i++) {
  5068. ch[i] = c;
  5069. }
  5070. return String(ch)
  5071. };
  5072. StringUtil.getStackTrace = function getStackTrace () {
  5073. if (arguments.length === 1) {
  5074. var t = arguments[0];
  5075. var os = new ByteArrayOutputStream();
  5076. var ps = new PrintStream(os);
  5077. t.printStackTrace(ps);
  5078. return os.toString()
  5079. } else if (arguments.length === 2) {
  5080. var t$1 = arguments[0];
  5081. var depth = arguments[1];
  5082. var stackTrace = '';
  5083. var stringReader = new StringReader(StringUtil.getStackTrace(t$1));
  5084. var lineNumberReader = new LineNumberReader(stringReader);
  5085. for (var i = 0; i < depth; i++) {
  5086. try {
  5087. stackTrace += lineNumberReader.readLine() + StringUtil.NEWLINE;
  5088. } catch (e) {
  5089. if (e instanceof IOException) {
  5090. Assert.shouldNeverReachHere();
  5091. } else { throw e }
  5092. } finally {}
  5093. }
  5094. return stackTrace
  5095. }
  5096. };
  5097. StringUtil.split = function split (s, separator) {
  5098. var separatorlen = separator.length;
  5099. var tokenList = new ArrayList();
  5100. var tmpString = '' + s;
  5101. var pos = tmpString.indexOf(separator);
  5102. while (pos >= 0) {
  5103. var token = tmpString.substring(0, pos);
  5104. tokenList.add(token);
  5105. tmpString = tmpString.substring(pos + separatorlen);
  5106. pos = tmpString.indexOf(separator);
  5107. }
  5108. if (tmpString.length > 0) { tokenList.add(tmpString); }
  5109. var res = new Array(tokenList.size()).fill(null);
  5110. for (var i = 0; i < res.length; i++) {
  5111. res[i] = tokenList.get(i);
  5112. }
  5113. return res
  5114. };
  5115. StringUtil.toString = function toString () {
  5116. if (arguments.length === 1) {
  5117. var d = arguments[0];
  5118. return StringUtil.SIMPLE_ORDINATE_FORMAT.format(d)
  5119. }
  5120. };
  5121. StringUtil.spaces = function spaces (n) {
  5122. return StringUtil.chars(' ', n)
  5123. };
  5124. staticAccessors$15.NEWLINE.get = function () { return System.getProperty('line.separator') };
  5125. staticAccessors$15.SIMPLE_ORDINATE_FORMAT.get = function () { return new DecimalFormat('0.#') };
  5126. Object.defineProperties( StringUtil, staticAccessors$15 );
  5127. var CoordinateSequences = function CoordinateSequences () {};
  5128. CoordinateSequences.prototype.interfaces_ = function interfaces_ () {
  5129. return []
  5130. };
  5131. CoordinateSequences.prototype.getClass = function getClass () {
  5132. return CoordinateSequences
  5133. };
  5134. CoordinateSequences.copyCoord = function copyCoord (src, srcPos, dest, destPos) {
  5135. var minDim = Math.min(src.getDimension(), dest.getDimension());
  5136. for (var dim = 0; dim < minDim; dim++) {
  5137. dest.setOrdinate(destPos, dim, src.getOrdinate(srcPos, dim));
  5138. }
  5139. };
  5140. CoordinateSequences.isRing = function isRing (seq) {
  5141. var n = seq.size();
  5142. if (n === 0) { return true }
  5143. if (n <= 3) { return false }
  5144. return seq.getOrdinate(0, CoordinateSequence.X) === seq.getOrdinate(n - 1, CoordinateSequence.X) && seq.getOrdinate(0, CoordinateSequence.Y) === seq.getOrdinate(n - 1, CoordinateSequence.Y)
  5145. };
  5146. CoordinateSequences.isEqual = function isEqual (cs1, cs2) {
  5147. var cs1Size = cs1.size();
  5148. var cs2Size = cs2.size();
  5149. if (cs1Size !== cs2Size) { return false }
  5150. var dim = Math.min(cs1.getDimension(), cs2.getDimension());
  5151. for (var i = 0; i < cs1Size; i++) {
  5152. for (var d = 0; d < dim; d++) {
  5153. var v1 = cs1.getOrdinate(i, d);
  5154. var v2 = cs2.getOrdinate(i, d);
  5155. if (cs1.getOrdinate(i, d) === cs2.getOrdinate(i, d)) { continue }
  5156. if (Double.isNaN(v1) && Double.isNaN(v2)) { continue }
  5157. return false
  5158. }
  5159. }
  5160. return true
  5161. };
  5162. CoordinateSequences.extend = function extend (fact, seq, size) {
  5163. var newseq = fact.create(size, seq.getDimension());
  5164. var n = seq.size();
  5165. CoordinateSequences.copy(seq, 0, newseq, 0, n);
  5166. if (n > 0) {
  5167. for (var i = n; i < size; i++) { CoordinateSequences.copy(seq, n - 1, newseq, i, 1); }
  5168. }
  5169. return newseq
  5170. };
  5171. CoordinateSequences.reverse = function reverse (seq) {
  5172. var last = seq.size() - 1;
  5173. var mid = Math.trunc(last / 2);
  5174. for (var i = 0; i <= mid; i++) {
  5175. CoordinateSequences.swap(seq, i, last - i);
  5176. }
  5177. };
  5178. CoordinateSequences.swap = function swap (seq, i, j) {
  5179. if (i === j) { return null }
  5180. for (var dim = 0; dim < seq.getDimension(); dim++) {
  5181. var tmp = seq.getOrdinate(i, dim);
  5182. seq.setOrdinate(i, dim, seq.getOrdinate(j, dim));
  5183. seq.setOrdinate(j, dim, tmp);
  5184. }
  5185. };
  5186. CoordinateSequences.copy = function copy (src, srcPos, dest, destPos, length) {
  5187. for (var i = 0; i < length; i++) {
  5188. CoordinateSequences.copyCoord(src, srcPos + i, dest, destPos + i);
  5189. }
  5190. };
  5191. CoordinateSequences.toString = function toString () {
  5192. if (arguments.length === 1) {
  5193. var cs = arguments[0];
  5194. var size = cs.size();
  5195. if (size === 0) { return '()' }
  5196. var dim = cs.getDimension();
  5197. var buf = new StringBuffer();
  5198. buf.append('(');
  5199. for (var i = 0; i < size; i++) {
  5200. if (i > 0) { buf.append(' '); }
  5201. for (var d = 0; d < dim; d++) {
  5202. if (d > 0) { buf.append(','); }
  5203. buf.append(StringUtil.toString(cs.getOrdinate(i, d)));
  5204. }
  5205. }
  5206. buf.append(')');
  5207. return buf.toString()
  5208. }
  5209. };
  5210. CoordinateSequences.ensureValidRing = function ensureValidRing (fact, seq) {
  5211. var n = seq.size();
  5212. if (n === 0) { return seq }
  5213. if (n <= 3) { return CoordinateSequences.createClosedRing(fact, seq, 4) }
  5214. var isClosed = seq.getOrdinate(0, CoordinateSequence.X) === seq.getOrdinate(n - 1, CoordinateSequence.X) && seq.getOrdinate(0, CoordinateSequence.Y) === seq.getOrdinate(n - 1, CoordinateSequence.Y);
  5215. if (isClosed) { return seq }
  5216. return CoordinateSequences.createClosedRing(fact, seq, n + 1)
  5217. };
  5218. CoordinateSequences.createClosedRing = function createClosedRing (fact, seq, size) {
  5219. var newseq = fact.create(size, seq.getDimension());
  5220. var n = seq.size();
  5221. CoordinateSequences.copy(seq, 0, newseq, 0, n);
  5222. for (var i = n; i < size; i++) { CoordinateSequences.copy(seq, 0, newseq, i, 1); }
  5223. return newseq
  5224. };
  5225. var LineString = (function (Geometry$$1) {
  5226. function LineString (points, factory) {
  5227. Geometry$$1.call(this, factory);
  5228. this._points = null;
  5229. this.init(points);
  5230. }
  5231. if ( Geometry$$1 ) LineString.__proto__ = Geometry$$1;
  5232. LineString.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
  5233. LineString.prototype.constructor = LineString;
  5234. var staticAccessors = { serialVersionUID: { configurable: true } };
  5235. LineString.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
  5236. if (this.isEmpty()) {
  5237. return new Envelope()
  5238. }
  5239. return this._points.expandEnvelope(new Envelope())
  5240. };
  5241. LineString.prototype.isRing = function isRing () {
  5242. return this.isClosed() && this.isSimple()
  5243. };
  5244. LineString.prototype.getSortIndex = function getSortIndex () {
  5245. return Geometry$$1.SORTINDEX_LINESTRING
  5246. };
  5247. LineString.prototype.getCoordinates = function getCoordinates () {
  5248. return this._points.toCoordinateArray()
  5249. };
  5250. LineString.prototype.equalsExact = function equalsExact () {
  5251. var this$1 = this;
  5252. if (arguments.length === 2) {
  5253. var other = arguments[0];
  5254. var tolerance = arguments[1];
  5255. if (!this.isEquivalentClass(other)) {
  5256. return false
  5257. }
  5258. var otherLineString = other;
  5259. if (this._points.size() !== otherLineString._points.size()) {
  5260. return false
  5261. }
  5262. for (var i = 0; i < this._points.size(); i++) {
  5263. if (!this$1.equal(this$1._points.getCoordinate(i), otherLineString._points.getCoordinate(i), tolerance)) {
  5264. return false
  5265. }
  5266. }
  5267. return true
  5268. } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
  5269. };
  5270. LineString.prototype.normalize = function normalize () {
  5271. var this$1 = this;
  5272. for (var i = 0; i < Math.trunc(this._points.size() / 2); i++) {
  5273. var j = this$1._points.size() - 1 - i;
  5274. if (!this$1._points.getCoordinate(i).equals(this$1._points.getCoordinate(j))) {
  5275. if (this$1._points.getCoordinate(i).compareTo(this$1._points.getCoordinate(j)) > 0) {
  5276. CoordinateSequences.reverse(this$1._points);
  5277. }
  5278. return null
  5279. }
  5280. }
  5281. };
  5282. LineString.prototype.getCoordinate = function getCoordinate () {
  5283. if (this.isEmpty()) { return null }
  5284. return this._points.getCoordinate(0)
  5285. };
  5286. LineString.prototype.getBoundaryDimension = function getBoundaryDimension () {
  5287. if (this.isClosed()) {
  5288. return Dimension.FALSE
  5289. }
  5290. return 0
  5291. };
  5292. LineString.prototype.isClosed = function isClosed () {
  5293. if (this.isEmpty()) {
  5294. return false
  5295. }
  5296. return this.getCoordinateN(0).equals2D(this.getCoordinateN(this.getNumPoints() - 1))
  5297. };
  5298. LineString.prototype.getEndPoint = function getEndPoint () {
  5299. if (this.isEmpty()) {
  5300. return null
  5301. }
  5302. return this.getPointN(this.getNumPoints() - 1)
  5303. };
  5304. LineString.prototype.getDimension = function getDimension () {
  5305. return 1
  5306. };
  5307. LineString.prototype.getLength = function getLength () {
  5308. return CGAlgorithms.computeLength(this._points)
  5309. };
  5310. LineString.prototype.getNumPoints = function getNumPoints () {
  5311. return this._points.size()
  5312. };
  5313. LineString.prototype.reverse = function reverse () {
  5314. var seq = this._points.copy();
  5315. CoordinateSequences.reverse(seq);
  5316. var revLine = this.getFactory().createLineString(seq);
  5317. return revLine
  5318. };
  5319. LineString.prototype.compareToSameClass = function compareToSameClass () {
  5320. var this$1 = this;
  5321. if (arguments.length === 1) {
  5322. var o = arguments[0];
  5323. var line = o;
  5324. var i = 0;
  5325. var j = 0;
  5326. while (i < this._points.size() && j < line._points.size()) {
  5327. var comparison = this$1._points.getCoordinate(i).compareTo(line._points.getCoordinate(j));
  5328. if (comparison !== 0) {
  5329. return comparison
  5330. }
  5331. i++;
  5332. j++;
  5333. }
  5334. if (i < this._points.size()) {
  5335. return 1
  5336. }
  5337. if (j < line._points.size()) {
  5338. return -1
  5339. }
  5340. return 0
  5341. } else if (arguments.length === 2) {
  5342. var o$1 = arguments[0];
  5343. var comp = arguments[1];
  5344. var line$1 = o$1;
  5345. return comp.compare(this._points, line$1._points)
  5346. }
  5347. };
  5348. LineString.prototype.apply = function apply () {
  5349. var this$1 = this;
  5350. if (hasInterface(arguments[0], CoordinateFilter)) {
  5351. var filter = arguments[0];
  5352. for (var i = 0; i < this._points.size(); i++) {
  5353. filter.filter(this$1._points.getCoordinate(i));
  5354. }
  5355. } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {
  5356. var filter$1 = arguments[0];
  5357. if (this._points.size() === 0) { return null }
  5358. for (var i$1 = 0; i$1 < this._points.size(); i$1++) {
  5359. filter$1.filter(this$1._points, i$1);
  5360. if (filter$1.isDone()) { break }
  5361. }
  5362. if (filter$1.isGeometryChanged()) { this.geometryChanged(); }
  5363. } else if (hasInterface(arguments[0], GeometryFilter)) {
  5364. var filter$2 = arguments[0];
  5365. filter$2.filter(this);
  5366. } else if (hasInterface(arguments[0], GeometryComponentFilter)) {
  5367. var filter$3 = arguments[0];
  5368. filter$3.filter(this);
  5369. }
  5370. };
  5371. LineString.prototype.getBoundary = function getBoundary () {
  5372. return new BoundaryOp(this).getBoundary()
  5373. };
  5374. LineString.prototype.isEquivalentClass = function isEquivalentClass (other) {
  5375. return other instanceof LineString
  5376. };
  5377. LineString.prototype.clone = function clone () {
  5378. var ls = Geometry$$1.prototype.clone.call(this);
  5379. ls._points = this._points.clone();
  5380. return ls
  5381. };
  5382. LineString.prototype.getCoordinateN = function getCoordinateN (n) {
  5383. return this._points.getCoordinate(n)
  5384. };
  5385. LineString.prototype.getGeometryType = function getGeometryType () {
  5386. return 'LineString'
  5387. };
  5388. LineString.prototype.copy = function copy () {
  5389. return new LineString(this._points.copy(), this._factory)
  5390. };
  5391. LineString.prototype.getCoordinateSequence = function getCoordinateSequence () {
  5392. return this._points
  5393. };
  5394. LineString.prototype.isEmpty = function isEmpty () {
  5395. return this._points.size() === 0
  5396. };
  5397. LineString.prototype.init = function init (points) {
  5398. if (points === null) {
  5399. points = this.getFactory().getCoordinateSequenceFactory().create([]);
  5400. }
  5401. if (points.size() === 1) {
  5402. throw new IllegalArgumentException('Invalid number of points in LineString (found ' + points.size() + ' - must be 0 or >= 2)')
  5403. }
  5404. this._points = points;
  5405. };
  5406. LineString.prototype.isCoordinate = function isCoordinate (pt) {
  5407. var this$1 = this;
  5408. for (var i = 0; i < this._points.size(); i++) {
  5409. if (this$1._points.getCoordinate(i).equals(pt)) {
  5410. return true
  5411. }
  5412. }
  5413. return false
  5414. };
  5415. LineString.prototype.getStartPoint = function getStartPoint () {
  5416. if (this.isEmpty()) {
  5417. return null
  5418. }
  5419. return this.getPointN(0)
  5420. };
  5421. LineString.prototype.getPointN = function getPointN (n) {
  5422. return this.getFactory().createPoint(this._points.getCoordinate(n))
  5423. };
  5424. LineString.prototype.interfaces_ = function interfaces_ () {
  5425. return [Lineal]
  5426. };
  5427. LineString.prototype.getClass = function getClass () {
  5428. return LineString
  5429. };
  5430. staticAccessors.serialVersionUID.get = function () { return 3110669828065365560 };
  5431. Object.defineProperties( LineString, staticAccessors );
  5432. return LineString;
  5433. }(Geometry));
  5434. var Puntal = function Puntal () {};
  5435. Puntal.prototype.interfaces_ = function interfaces_ () {
  5436. return []
  5437. };
  5438. Puntal.prototype.getClass = function getClass () {
  5439. return Puntal
  5440. };
  5441. var Point = (function (Geometry$$1) {
  5442. function Point (coordinates, factory) {
  5443. Geometry$$1.call(this, factory);
  5444. this._coordinates = coordinates || null;
  5445. this.init(this._coordinates);
  5446. }
  5447. if ( Geometry$$1 ) Point.__proto__ = Geometry$$1;
  5448. Point.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
  5449. Point.prototype.constructor = Point;
  5450. var staticAccessors = { serialVersionUID: { configurable: true } };
  5451. Point.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
  5452. if (this.isEmpty()) {
  5453. return new Envelope()
  5454. }
  5455. var env = new Envelope();
  5456. env.expandToInclude(this._coordinates.getX(0), this._coordinates.getY(0));
  5457. return env
  5458. };
  5459. Point.prototype.getSortIndex = function getSortIndex () {
  5460. return Geometry$$1.SORTINDEX_POINT
  5461. };
  5462. Point.prototype.getCoordinates = function getCoordinates () {
  5463. return this.isEmpty() ? [] : [this.getCoordinate()]
  5464. };
  5465. Point.prototype.equalsExact = function equalsExact () {
  5466. if (arguments.length === 2) {
  5467. var other = arguments[0];
  5468. var tolerance = arguments[1];
  5469. if (!this.isEquivalentClass(other)) {
  5470. return false
  5471. }
  5472. if (this.isEmpty() && other.isEmpty()) {
  5473. return true
  5474. }
  5475. if (this.isEmpty() !== other.isEmpty()) {
  5476. return false
  5477. }
  5478. return this.equal(other.getCoordinate(), this.getCoordinate(), tolerance)
  5479. } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
  5480. };
  5481. Point.prototype.normalize = function normalize () {};
  5482. Point.prototype.getCoordinate = function getCoordinate () {
  5483. return this._coordinates.size() !== 0 ? this._coordinates.getCoordinate(0) : null
  5484. };
  5485. Point.prototype.getBoundaryDimension = function getBoundaryDimension () {
  5486. return Dimension.FALSE
  5487. };
  5488. Point.prototype.getDimension = function getDimension () {
  5489. return 0
  5490. };
  5491. Point.prototype.getNumPoints = function getNumPoints () {
  5492. return this.isEmpty() ? 0 : 1
  5493. };
  5494. Point.prototype.reverse = function reverse () {
  5495. return this.copy()
  5496. };
  5497. Point.prototype.getX = function getX () {
  5498. if (this.getCoordinate() === null) {
  5499. throw new Error('getX called on empty Point')
  5500. }
  5501. return this.getCoordinate().x
  5502. };
  5503. Point.prototype.compareToSameClass = function compareToSameClass () {
  5504. if (arguments.length === 1) {
  5505. var other = arguments[0];
  5506. var point$1 = other;
  5507. return this.getCoordinate().compareTo(point$1.getCoordinate())
  5508. } else if (arguments.length === 2) {
  5509. var other$1 = arguments[0];
  5510. var comp = arguments[1];
  5511. var point = other$1;
  5512. return comp.compare(this._coordinates, point._coordinates)
  5513. }
  5514. };
  5515. Point.prototype.apply = function apply () {
  5516. if (hasInterface(arguments[0], CoordinateFilter)) {
  5517. var filter = arguments[0];
  5518. if (this.isEmpty()) {
  5519. return null
  5520. }
  5521. filter.filter(this.getCoordinate());
  5522. } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {
  5523. var filter$1 = arguments[0];
  5524. if (this.isEmpty()) { return null }
  5525. filter$1.filter(this._coordinates, 0);
  5526. if (filter$1.isGeometryChanged()) { this.geometryChanged(); }
  5527. } else if (hasInterface(arguments[0], GeometryFilter)) {
  5528. var filter$2 = arguments[0];
  5529. filter$2.filter(this);
  5530. } else if (hasInterface(arguments[0], GeometryComponentFilter)) {
  5531. var filter$3 = arguments[0];
  5532. filter$3.filter(this);
  5533. }
  5534. };
  5535. Point.prototype.getBoundary = function getBoundary () {
  5536. return this.getFactory().createGeometryCollection(null)
  5537. };
  5538. Point.prototype.clone = function clone () {
  5539. var p = Geometry$$1.prototype.clone.call(this);
  5540. p._coordinates = this._coordinates.clone();
  5541. return p
  5542. };
  5543. Point.prototype.getGeometryType = function getGeometryType () {
  5544. return 'Point'
  5545. };
  5546. Point.prototype.copy = function copy () {
  5547. return new Point(this._coordinates.copy(), this._factory)
  5548. };
  5549. Point.prototype.getCoordinateSequence = function getCoordinateSequence () {
  5550. return this._coordinates
  5551. };
  5552. Point.prototype.getY = function getY () {
  5553. if (this.getCoordinate() === null) {
  5554. throw new Error('getY called on empty Point')
  5555. }
  5556. return this.getCoordinate().y
  5557. };
  5558. Point.prototype.isEmpty = function isEmpty () {
  5559. return this._coordinates.size() === 0
  5560. };
  5561. Point.prototype.init = function init (coordinates) {
  5562. if (coordinates === null) {
  5563. coordinates = this.getFactory().getCoordinateSequenceFactory().create([]);
  5564. }
  5565. Assert.isTrue(coordinates.size() <= 1);
  5566. this._coordinates = coordinates;
  5567. };
  5568. Point.prototype.isSimple = function isSimple () {
  5569. return true
  5570. };
  5571. Point.prototype.interfaces_ = function interfaces_ () {
  5572. return [Puntal]
  5573. };
  5574. Point.prototype.getClass = function getClass () {
  5575. return Point
  5576. };
  5577. staticAccessors.serialVersionUID.get = function () { return 4902022702746614570 };
  5578. Object.defineProperties( Point, staticAccessors );
  5579. return Point;
  5580. }(Geometry));
  5581. var Polygonal = function Polygonal () {};
  5582. Polygonal.prototype.interfaces_ = function interfaces_ () {
  5583. return []
  5584. };
  5585. Polygonal.prototype.getClass = function getClass () {
  5586. return Polygonal
  5587. };
  5588. var Polygon = (function (Geometry$$1) {
  5589. function Polygon (shell, holes, factory) {
  5590. Geometry$$1.call(this, factory);
  5591. this._shell = null;
  5592. this._holes = null;
  5593. if (shell === null) {
  5594. shell = this.getFactory().createLinearRing();
  5595. }
  5596. if (holes === null) {
  5597. holes = [];
  5598. }
  5599. if (Geometry$$1.hasNullElements(holes)) {
  5600. throw new IllegalArgumentException('holes must not contain null elements')
  5601. }
  5602. if (shell.isEmpty() && Geometry$$1.hasNonEmptyElements(holes)) {
  5603. throw new IllegalArgumentException('shell is empty but holes are not')
  5604. }
  5605. this._shell = shell;
  5606. this._holes = holes;
  5607. }
  5608. if ( Geometry$$1 ) Polygon.__proto__ = Geometry$$1;
  5609. Polygon.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
  5610. Polygon.prototype.constructor = Polygon;
  5611. var staticAccessors = { serialVersionUID: { configurable: true } };
  5612. Polygon.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
  5613. return this._shell.getEnvelopeInternal()
  5614. };
  5615. Polygon.prototype.getSortIndex = function getSortIndex () {
  5616. return Geometry$$1.SORTINDEX_POLYGON
  5617. };
  5618. Polygon.prototype.getCoordinates = function getCoordinates () {
  5619. var this$1 = this;
  5620. if (this.isEmpty()) {
  5621. return []
  5622. }
  5623. var coordinates = new Array(this.getNumPoints()).fill(null);
  5624. var k = -1;
  5625. var shellCoordinates = this._shell.getCoordinates();
  5626. for (var x = 0; x < shellCoordinates.length; x++) {
  5627. k++;
  5628. coordinates[k] = shellCoordinates[x];
  5629. }
  5630. for (var i = 0; i < this._holes.length; i++) {
  5631. var childCoordinates = this$1._holes[i].getCoordinates();
  5632. for (var j = 0; j < childCoordinates.length; j++) {
  5633. k++;
  5634. coordinates[k] = childCoordinates[j];
  5635. }
  5636. }
  5637. return coordinates
  5638. };
  5639. Polygon.prototype.getArea = function getArea () {
  5640. var this$1 = this;
  5641. var area = 0.0;
  5642. area += Math.abs(CGAlgorithms.signedArea(this._shell.getCoordinateSequence()));
  5643. for (var i = 0; i < this._holes.length; i++) {
  5644. area -= Math.abs(CGAlgorithms.signedArea(this$1._holes[i].getCoordinateSequence()));
  5645. }
  5646. return area
  5647. };
  5648. Polygon.prototype.isRectangle = function isRectangle () {
  5649. if (this.getNumInteriorRing() !== 0) { return false }
  5650. if (this._shell === null) { return false }
  5651. if (this._shell.getNumPoints() !== 5) { return false }
  5652. var seq = this._shell.getCoordinateSequence();
  5653. var env = this.getEnvelopeInternal();
  5654. for (var i = 0; i < 5; i++) {
  5655. var x = seq.getX(i);
  5656. if (!(x === env.getMinX() || x === env.getMaxX())) { return false }
  5657. var y = seq.getY(i);
  5658. if (!(y === env.getMinY() || y === env.getMaxY())) { return false }
  5659. }
  5660. var prevX = seq.getX(0);
  5661. var prevY = seq.getY(0);
  5662. for (var i$1 = 1; i$1 <= 4; i$1++) {
  5663. var x$1 = seq.getX(i$1);
  5664. var y$1 = seq.getY(i$1);
  5665. var xChanged = x$1 !== prevX;
  5666. var yChanged = y$1 !== prevY;
  5667. if (xChanged === yChanged) { return false }
  5668. prevX = x$1;
  5669. prevY = y$1;
  5670. }
  5671. return true
  5672. };
  5673. Polygon.prototype.equalsExact = function equalsExact () {
  5674. var this$1 = this;
  5675. if (arguments.length === 2) {
  5676. var other = arguments[0];
  5677. var tolerance = arguments[1];
  5678. if (!this.isEquivalentClass(other)) {
  5679. return false
  5680. }
  5681. var otherPolygon = other;
  5682. var thisShell = this._shell;
  5683. var otherPolygonShell = otherPolygon._shell;
  5684. if (!thisShell.equalsExact(otherPolygonShell, tolerance)) {
  5685. return false
  5686. }
  5687. if (this._holes.length !== otherPolygon._holes.length) {
  5688. return false
  5689. }
  5690. for (var i = 0; i < this._holes.length; i++) {
  5691. if (!this$1._holes[i].equalsExact(otherPolygon._holes[i], tolerance)) {
  5692. return false
  5693. }
  5694. }
  5695. return true
  5696. } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
  5697. };
  5698. Polygon.prototype.normalize = function normalize () {
  5699. var this$1 = this;
  5700. if (arguments.length === 0) {
  5701. this.normalize(this._shell, true);
  5702. for (var i = 0; i < this._holes.length; i++) {
  5703. this$1.normalize(this$1._holes[i], false);
  5704. }
  5705. Arrays.sort(this._holes);
  5706. } else if (arguments.length === 2) {
  5707. var ring = arguments[0];
  5708. var clockwise = arguments[1];
  5709. if (ring.isEmpty()) {
  5710. return null
  5711. }
  5712. var uniqueCoordinates = new Array(ring.getCoordinates().length - 1).fill(null);
  5713. System.arraycopy(ring.getCoordinates(), 0, uniqueCoordinates, 0, uniqueCoordinates.length);
  5714. var minCoordinate = CoordinateArrays.minCoordinate(ring.getCoordinates());
  5715. CoordinateArrays.scroll(uniqueCoordinates, minCoordinate);
  5716. System.arraycopy(uniqueCoordinates, 0, ring.getCoordinates(), 0, uniqueCoordinates.length);
  5717. ring.getCoordinates()[uniqueCoordinates.length] = uniqueCoordinates[0];
  5718. if (CGAlgorithms.isCCW(ring.getCoordinates()) === clockwise) {
  5719. CoordinateArrays.reverse(ring.getCoordinates());
  5720. }
  5721. }
  5722. };
  5723. Polygon.prototype.getCoordinate = function getCoordinate () {
  5724. return this._shell.getCoordinate()
  5725. };
  5726. Polygon.prototype.getNumInteriorRing = function getNumInteriorRing () {
  5727. return this._holes.length
  5728. };
  5729. Polygon.prototype.getBoundaryDimension = function getBoundaryDimension () {
  5730. return 1
  5731. };
  5732. Polygon.prototype.getDimension = function getDimension () {
  5733. return 2
  5734. };
  5735. Polygon.prototype.getLength = function getLength () {
  5736. var this$1 = this;
  5737. var len = 0.0;
  5738. len += this._shell.getLength();
  5739. for (var i = 0; i < this._holes.length; i++) {
  5740. len += this$1._holes[i].getLength();
  5741. }
  5742. return len
  5743. };
  5744. Polygon.prototype.getNumPoints = function getNumPoints () {
  5745. var this$1 = this;
  5746. var numPoints = this._shell.getNumPoints();
  5747. for (var i = 0; i < this._holes.length; i++) {
  5748. numPoints += this$1._holes[i].getNumPoints();
  5749. }
  5750. return numPoints
  5751. };
  5752. Polygon.prototype.reverse = function reverse () {
  5753. var this$1 = this;
  5754. var poly = this.copy();
  5755. poly._shell = this._shell.copy().reverse();
  5756. poly._holes = new Array(this._holes.length).fill(null);
  5757. for (var i = 0; i < this._holes.length; i++) {
  5758. poly._holes[i] = this$1._holes[i].copy().reverse();
  5759. }
  5760. return poly
  5761. };
  5762. Polygon.prototype.convexHull = function convexHull () {
  5763. return this.getExteriorRing().convexHull()
  5764. };
  5765. Polygon.prototype.compareToSameClass = function compareToSameClass () {
  5766. var this$1 = this;
  5767. if (arguments.length === 1) {
  5768. var o = arguments[0];
  5769. var thisShell = this._shell;
  5770. var otherShell = o._shell;
  5771. return thisShell.compareToSameClass(otherShell)
  5772. } else if (arguments.length === 2) {
  5773. var o$1 = arguments[0];
  5774. var comp = arguments[1];
  5775. var poly = o$1;
  5776. var thisShell$1 = this._shell;
  5777. var otherShell$1 = poly._shell;
  5778. var shellComp = thisShell$1.compareToSameClass(otherShell$1, comp);
  5779. if (shellComp !== 0) { return shellComp }
  5780. var nHole1 = this.getNumInteriorRing();
  5781. var nHole2 = poly.getNumInteriorRing();
  5782. var i = 0;
  5783. while (i < nHole1 && i < nHole2) {
  5784. var thisHole = this$1.getInteriorRingN(i);
  5785. var otherHole = poly.getInteriorRingN(i);
  5786. var holeComp = thisHole.compareToSameClass(otherHole, comp);
  5787. if (holeComp !== 0) { return holeComp }
  5788. i++;
  5789. }
  5790. if (i < nHole1) { return 1 }
  5791. if (i < nHole2) { return -1 }
  5792. return 0
  5793. }
  5794. };
  5795. Polygon.prototype.apply = function apply (filter) {
  5796. var this$1 = this;
  5797. if (hasInterface(filter, CoordinateFilter)) {
  5798. this._shell.apply(filter);
  5799. for (var i$1 = 0; i$1 < this._holes.length; i$1++) {
  5800. this$1._holes[i$1].apply(filter);
  5801. }
  5802. } else if (hasInterface(filter, CoordinateSequenceFilter)) {
  5803. this._shell.apply(filter);
  5804. if (!filter.isDone()) {
  5805. for (var i$2 = 0; i$2 < this._holes.length; i$2++) {
  5806. this$1._holes[i$2].apply(filter);
  5807. if (filter.isDone()) { break }
  5808. }
  5809. }
  5810. if (filter.isGeometryChanged()) { this.geometryChanged(); }
  5811. } else if (hasInterface(filter, GeometryFilter)) {
  5812. filter.filter(this);
  5813. } else if (hasInterface(filter, GeometryComponentFilter)) {
  5814. filter.filter(this);
  5815. this._shell.apply(filter);
  5816. for (var i = 0; i < this._holes.length; i++) {
  5817. this$1._holes[i].apply(filter);
  5818. }
  5819. }
  5820. };
  5821. Polygon.prototype.getBoundary = function getBoundary () {
  5822. var this$1 = this;
  5823. if (this.isEmpty()) {
  5824. return this.getFactory().createMultiLineString()
  5825. }
  5826. var rings = new Array(this._holes.length + 1).fill(null);
  5827. rings[0] = this._shell;
  5828. for (var i = 0; i < this._holes.length; i++) {
  5829. rings[i + 1] = this$1._holes[i];
  5830. }
  5831. if (rings.length <= 1) { return this.getFactory().createLinearRing(rings[0].getCoordinateSequence()) }
  5832. return this.getFactory().createMultiLineString(rings)
  5833. };
  5834. Polygon.prototype.clone = function clone () {
  5835. var this$1 = this;
  5836. var poly = Geometry$$1.prototype.clone.call(this);
  5837. poly._shell = this._shell.clone();
  5838. poly._holes = new Array(this._holes.length).fill(null);
  5839. for (var i = 0; i < this._holes.length; i++) {
  5840. poly._holes[i] = this$1._holes[i].clone();
  5841. }
  5842. return poly
  5843. };
  5844. Polygon.prototype.getGeometryType = function getGeometryType () {
  5845. return 'Polygon'
  5846. };
  5847. Polygon.prototype.copy = function copy () {
  5848. var this$1 = this;
  5849. var shell = this._shell.copy();
  5850. var holes = new Array(this._holes.length).fill(null);
  5851. for (var i = 0; i < holes.length; i++) {
  5852. holes[i] = this$1._holes[i].copy();
  5853. }
  5854. return new Polygon(shell, holes, this._factory)
  5855. };
  5856. Polygon.prototype.getExteriorRing = function getExteriorRing () {
  5857. return this._shell
  5858. };
  5859. Polygon.prototype.isEmpty = function isEmpty () {
  5860. return this._shell.isEmpty()
  5861. };
  5862. Polygon.prototype.getInteriorRingN = function getInteriorRingN (n) {
  5863. return this._holes[n]
  5864. };
  5865. Polygon.prototype.interfaces_ = function interfaces_ () {
  5866. return [Polygonal]
  5867. };
  5868. Polygon.prototype.getClass = function getClass () {
  5869. return Polygon
  5870. };
  5871. staticAccessors.serialVersionUID.get = function () { return -3494792200821764533 };
  5872. Object.defineProperties( Polygon, staticAccessors );
  5873. return Polygon;
  5874. }(Geometry));
  5875. var MultiPoint = (function (GeometryCollection$$1) {
  5876. function MultiPoint () {
  5877. GeometryCollection$$1.apply(this, arguments);
  5878. }
  5879. if ( GeometryCollection$$1 ) MultiPoint.__proto__ = GeometryCollection$$1;
  5880. MultiPoint.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );
  5881. MultiPoint.prototype.constructor = MultiPoint;
  5882. var staticAccessors = { serialVersionUID: { configurable: true } };
  5883. MultiPoint.prototype.getSortIndex = function getSortIndex () {
  5884. return Geometry.SORTINDEX_MULTIPOINT
  5885. };
  5886. MultiPoint.prototype.isValid = function isValid () {
  5887. return true
  5888. };
  5889. MultiPoint.prototype.equalsExact = function equalsExact () {
  5890. if (arguments.length === 2) {
  5891. var other = arguments[0];
  5892. var tolerance = arguments[1];
  5893. if (!this.isEquivalentClass(other)) {
  5894. return false
  5895. }
  5896. return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)
  5897. } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }
  5898. };
  5899. MultiPoint.prototype.getCoordinate = function getCoordinate () {
  5900. if (arguments.length === 1) {
  5901. var n = arguments[0];
  5902. return this._geometries[n].getCoordinate()
  5903. } else { return GeometryCollection$$1.prototype.getCoordinate.apply(this, arguments) }
  5904. };
  5905. MultiPoint.prototype.getBoundaryDimension = function getBoundaryDimension () {
  5906. return Dimension.FALSE
  5907. };
  5908. MultiPoint.prototype.getDimension = function getDimension () {
  5909. return 0
  5910. };
  5911. MultiPoint.prototype.getBoundary = function getBoundary () {
  5912. return this.getFactory().createGeometryCollection(null)
  5913. };
  5914. MultiPoint.prototype.getGeometryType = function getGeometryType () {
  5915. return 'MultiPoint'
  5916. };
  5917. MultiPoint.prototype.copy = function copy () {
  5918. var this$1 = this;
  5919. var points = new Array(this._geometries.length).fill(null);
  5920. for (var i = 0; i < points.length; i++) {
  5921. points[i] = this$1._geometries[i].copy();
  5922. }
  5923. return new MultiPoint(points, this._factory)
  5924. };
  5925. MultiPoint.prototype.interfaces_ = function interfaces_ () {
  5926. return [Puntal]
  5927. };
  5928. MultiPoint.prototype.getClass = function getClass () {
  5929. return MultiPoint
  5930. };
  5931. staticAccessors.serialVersionUID.get = function () { return -8048474874175355449 };
  5932. Object.defineProperties( MultiPoint, staticAccessors );
  5933. return MultiPoint;
  5934. }(GeometryCollection));
  5935. var LinearRing = (function (LineString$$1) {
  5936. function LinearRing (points, factory) {
  5937. if (points instanceof Coordinate && factory instanceof GeometryFactory) {
  5938. points = factory.getCoordinateSequenceFactory().create(points);
  5939. }
  5940. LineString$$1.call(this, points, factory);
  5941. this.validateConstruction();
  5942. }
  5943. if ( LineString$$1 ) LinearRing.__proto__ = LineString$$1;
  5944. LinearRing.prototype = Object.create( LineString$$1 && LineString$$1.prototype );
  5945. LinearRing.prototype.constructor = LinearRing;
  5946. var staticAccessors = { MINIMUM_VALID_SIZE: { configurable: true },serialVersionUID: { configurable: true } };
  5947. LinearRing.prototype.getSortIndex = function getSortIndex () {
  5948. return Geometry.SORTINDEX_LINEARRING
  5949. };
  5950. LinearRing.prototype.getBoundaryDimension = function getBoundaryDimension () {
  5951. return Dimension.FALSE
  5952. };
  5953. LinearRing.prototype.isClosed = function isClosed () {
  5954. if (this.isEmpty()) {
  5955. return true
  5956. }
  5957. return LineString$$1.prototype.isClosed.call(this)
  5958. };
  5959. LinearRing.prototype.reverse = function reverse () {
  5960. var seq = this._points.copy();
  5961. CoordinateSequences.reverse(seq);
  5962. var rev = this.getFactory().createLinearRing(seq);
  5963. return rev
  5964. };
  5965. LinearRing.prototype.validateConstruction = function validateConstruction () {
  5966. if (!this.isEmpty() && !LineString$$1.prototype.isClosed.call(this)) {
  5967. throw new IllegalArgumentException('Points of LinearRing do not form a closed linestring')
  5968. }
  5969. if (this.getCoordinateSequence().size() >= 1 && this.getCoordinateSequence().size() < LinearRing.MINIMUM_VALID_SIZE) {
  5970. throw new IllegalArgumentException('Invalid number of points in LinearRing (found ' + this.getCoordinateSequence().size() + ' - must be 0 or >= 4)')
  5971. }
  5972. };
  5973. LinearRing.prototype.getGeometryType = function getGeometryType () {
  5974. return 'LinearRing'
  5975. };
  5976. LinearRing.prototype.copy = function copy () {
  5977. return new LinearRing(this._points.copy(), this._factory)
  5978. };
  5979. LinearRing.prototype.interfaces_ = function interfaces_ () {
  5980. return []
  5981. };
  5982. LinearRing.prototype.getClass = function getClass () {
  5983. return LinearRing
  5984. };
  5985. staticAccessors.MINIMUM_VALID_SIZE.get = function () { return 4 };
  5986. staticAccessors.serialVersionUID.get = function () { return -4261142084085851829 };
  5987. Object.defineProperties( LinearRing, staticAccessors );
  5988. return LinearRing;
  5989. }(LineString));
  5990. var MultiPolygon = (function (GeometryCollection$$1) {
  5991. function MultiPolygon () {
  5992. GeometryCollection$$1.apply(this, arguments);
  5993. }
  5994. if ( GeometryCollection$$1 ) MultiPolygon.__proto__ = GeometryCollection$$1;
  5995. MultiPolygon.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );
  5996. MultiPolygon.prototype.constructor = MultiPolygon;
  5997. var staticAccessors = { serialVersionUID: { configurable: true } };
  5998. MultiPolygon.prototype.getSortIndex = function getSortIndex () {
  5999. return Geometry.SORTINDEX_MULTIPOLYGON
  6000. };
  6001. MultiPolygon.prototype.equalsExact = function equalsExact () {
  6002. if (arguments.length === 2) {
  6003. var other = arguments[0];
  6004. var tolerance = arguments[1];
  6005. if (!this.isEquivalentClass(other)) {
  6006. return false
  6007. }
  6008. return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)
  6009. } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }
  6010. };
  6011. MultiPolygon.prototype.getBoundaryDimension = function getBoundaryDimension () {
  6012. return 1
  6013. };
  6014. MultiPolygon.prototype.getDimension = function getDimension () {
  6015. return 2
  6016. };
  6017. MultiPolygon.prototype.reverse = function reverse () {
  6018. var this$1 = this;
  6019. var n = this._geometries.length;
  6020. var revGeoms = new Array(n).fill(null);
  6021. for (var i = 0; i < this._geometries.length; i++) {
  6022. revGeoms[i] = this$1._geometries[i].reverse();
  6023. }
  6024. return this.getFactory().createMultiPolygon(revGeoms)
  6025. };
  6026. MultiPolygon.prototype.getBoundary = function getBoundary () {
  6027. var this$1 = this;
  6028. if (this.isEmpty()) {
  6029. return this.getFactory().createMultiLineString()
  6030. }
  6031. var allRings = new ArrayList();
  6032. for (var i = 0; i < this._geometries.length; i++) {
  6033. var polygon = this$1._geometries[i];
  6034. var rings = polygon.getBoundary();
  6035. for (var j = 0; j < rings.getNumGeometries(); j++) {
  6036. allRings.add(rings.getGeometryN(j));
  6037. }
  6038. }
  6039. var allRingsArray = new Array(allRings.size()).fill(null);
  6040. return this.getFactory().createMultiLineString(allRings.toArray(allRingsArray))
  6041. };
  6042. MultiPolygon.prototype.getGeometryType = function getGeometryType () {
  6043. return 'MultiPolygon'
  6044. };
  6045. MultiPolygon.prototype.copy = function copy () {
  6046. var this$1 = this;
  6047. var polygons = new Array(this._geometries.length).fill(null);
  6048. for (var i = 0; i < polygons.length; i++) {
  6049. polygons[i] = this$1._geometries[i].copy();
  6050. }
  6051. return new MultiPolygon(polygons, this._factory)
  6052. };
  6053. MultiPolygon.prototype.interfaces_ = function interfaces_ () {
  6054. return [Polygonal]
  6055. };
  6056. MultiPolygon.prototype.getClass = function getClass () {
  6057. return MultiPolygon
  6058. };
  6059. staticAccessors.serialVersionUID.get = function () { return -551033529766975875 };
  6060. Object.defineProperties( MultiPolygon, staticAccessors );
  6061. return MultiPolygon;
  6062. }(GeometryCollection));
  6063. var GeometryEditor = function GeometryEditor (factory) {
  6064. this._factory = factory || null;
  6065. this._isUserDataCopied = false;
  6066. };
  6067. var staticAccessors$16 = { NoOpGeometryOperation: { configurable: true },CoordinateOperation: { configurable: true },CoordinateSequenceOperation: { configurable: true } };
  6068. GeometryEditor.prototype.setCopyUserData = function setCopyUserData (isUserDataCopied) {
  6069. this._isUserDataCopied = isUserDataCopied;
  6070. };
  6071. GeometryEditor.prototype.edit = function edit (geometry, operation) {
  6072. if (geometry === null) { return null }
  6073. var result = this.editInternal(geometry, operation);
  6074. if (this._isUserDataCopied) {
  6075. result.setUserData(geometry.getUserData());
  6076. }
  6077. return result
  6078. };
  6079. GeometryEditor.prototype.editInternal = function editInternal (geometry, operation) {
  6080. if (this._factory === null) { this._factory = geometry.getFactory(); }
  6081. if (geometry instanceof GeometryCollection) {
  6082. return this.editGeometryCollection(geometry, operation)
  6083. }
  6084. if (geometry instanceof Polygon) {
  6085. return this.editPolygon(geometry, operation)
  6086. }
  6087. if (geometry instanceof Point) {
  6088. return operation.edit(geometry, this._factory)
  6089. }
  6090. if (geometry instanceof LineString) {
  6091. return operation.edit(geometry, this._factory)
  6092. }
  6093. Assert.shouldNeverReachHere('Unsupported Geometry class: ' + geometry.getClass().getName());
  6094. return null
  6095. };
  6096. GeometryEditor.prototype.editGeometryCollection = function editGeometryCollection (collection, operation) {
  6097. var this$1 = this;
  6098. var collectionForType = operation.edit(collection, this._factory);
  6099. var geometries = new ArrayList();
  6100. for (var i = 0; i < collectionForType.getNumGeometries(); i++) {
  6101. var geometry = this$1.edit(collectionForType.getGeometryN(i), operation);
  6102. if (geometry === null || geometry.isEmpty()) {
  6103. continue
  6104. }
  6105. geometries.add(geometry);
  6106. }
  6107. if (collectionForType.getClass() === MultiPoint) {
  6108. return this._factory.createMultiPoint(geometries.toArray([]))
  6109. }
  6110. if (collectionForType.getClass() === MultiLineString) {
  6111. return this._factory.createMultiLineString(geometries.toArray([]))
  6112. }
  6113. if (collectionForType.getClass() === MultiPolygon) {
  6114. return this._factory.createMultiPolygon(geometries.toArray([]))
  6115. }
  6116. return this._factory.createGeometryCollection(geometries.toArray([]))
  6117. };
  6118. GeometryEditor.prototype.editPolygon = function editPolygon (polygon, operation) {
  6119. var this$1 = this;
  6120. var newPolygon = operation.edit(polygon, this._factory);
  6121. if (newPolygon === null) { newPolygon = this._factory.createPolygon(null); }
  6122. if (newPolygon.isEmpty()) {
  6123. return newPolygon
  6124. }
  6125. var shell = this.edit(newPolygon.getExteriorRing(), operation);
  6126. if (shell === null || shell.isEmpty()) {
  6127. return this._factory.createPolygon()
  6128. }
  6129. var holes = new ArrayList();
  6130. for (var i = 0; i < newPolygon.getNumInteriorRing(); i++) {
  6131. var hole = this$1.edit(newPolygon.getInteriorRingN(i), operation);
  6132. if (hole === null || hole.isEmpty()) {
  6133. continue
  6134. }
  6135. holes.add(hole);
  6136. }
  6137. return this._factory.createPolygon(shell, holes.toArray([]))
  6138. };
  6139. GeometryEditor.prototype.interfaces_ = function interfaces_ () {
  6140. return []
  6141. };
  6142. GeometryEditor.prototype.getClass = function getClass () {
  6143. return GeometryEditor
  6144. };
  6145. GeometryEditor.GeometryEditorOperation = function GeometryEditorOperation () {};
  6146. staticAccessors$16.NoOpGeometryOperation.get = function () { return NoOpGeometryOperation };
  6147. staticAccessors$16.CoordinateOperation.get = function () { return CoordinateOperation };
  6148. staticAccessors$16.CoordinateSequenceOperation.get = function () { return CoordinateSequenceOperation };
  6149. Object.defineProperties( GeometryEditor, staticAccessors$16 );
  6150. var NoOpGeometryOperation = function NoOpGeometryOperation () {};
  6151. NoOpGeometryOperation.prototype.edit = function edit (geometry, factory) {
  6152. return geometry
  6153. };
  6154. NoOpGeometryOperation.prototype.interfaces_ = function interfaces_ () {
  6155. return [GeometryEditor.GeometryEditorOperation]
  6156. };
  6157. NoOpGeometryOperation.prototype.getClass = function getClass () {
  6158. return NoOpGeometryOperation
  6159. };
  6160. var CoordinateOperation = function CoordinateOperation () {};
  6161. CoordinateOperation.prototype.edit = function edit (geometry, factory) {
  6162. var coords = this.editCoordinates(geometry.getCoordinates(), geometry);
  6163. if (coords === null) { return geometry }
  6164. if (geometry instanceof LinearRing) {
  6165. return factory.createLinearRing(coords)
  6166. }
  6167. if (geometry instanceof LineString) {
  6168. return factory.createLineString(coords)
  6169. }
  6170. if (geometry instanceof Point) {
  6171. if (coords.length > 0) {
  6172. return factory.createPoint(coords[0])
  6173. } else {
  6174. return factory.createPoint()
  6175. }
  6176. }
  6177. return geometry
  6178. };
  6179. CoordinateOperation.prototype.interfaces_ = function interfaces_ () {
  6180. return [GeometryEditor.GeometryEditorOperation]
  6181. };
  6182. CoordinateOperation.prototype.getClass = function getClass () {
  6183. return CoordinateOperation
  6184. };
  6185. var CoordinateSequenceOperation = function CoordinateSequenceOperation () {};
  6186. CoordinateSequenceOperation.prototype.edit = function edit (geometry, factory) {
  6187. if (geometry instanceof LinearRing) {
  6188. return factory.createLinearRing(this.edit(geometry.getCoordinateSequence(), geometry))
  6189. }
  6190. if (geometry instanceof LineString) {
  6191. return factory.createLineString(this.edit(geometry.getCoordinateSequence(), geometry))
  6192. }
  6193. if (geometry instanceof Point) {
  6194. return factory.createPoint(this.edit(geometry.getCoordinateSequence(), geometry))
  6195. }
  6196. return geometry
  6197. };
  6198. CoordinateSequenceOperation.prototype.interfaces_ = function interfaces_ () {
  6199. return [GeometryEditor.GeometryEditorOperation]
  6200. };
  6201. CoordinateSequenceOperation.prototype.getClass = function getClass () {
  6202. return CoordinateSequenceOperation
  6203. };
  6204. var CoordinateArraySequence = function CoordinateArraySequence () {
  6205. var this$1 = this;
  6206. this._dimension = 3;
  6207. this._coordinates = null;
  6208. if (arguments.length === 1) {
  6209. if (arguments[0] instanceof Array) {
  6210. this._coordinates = arguments[0];
  6211. this._dimension = 3;
  6212. } else if (Number.isInteger(arguments[0])) {
  6213. var size = arguments[0];
  6214. this._coordinates = new Array(size).fill(null);
  6215. for (var i = 0; i < size; i++) {
  6216. this$1._coordinates[i] = new Coordinate();
  6217. }
  6218. } else if (hasInterface(arguments[0], CoordinateSequence)) {
  6219. var coordSeq = arguments[0];
  6220. if (coordSeq === null) {
  6221. this._coordinates = new Array(0).fill(null);
  6222. return null
  6223. }
  6224. this._dimension = coordSeq.getDimension();
  6225. this._coordinates = new Array(coordSeq.size()).fill(null);
  6226. for (var i$1 = 0; i$1 < this._coordinates.length; i$1++) {
  6227. this$1._coordinates[i$1] = coordSeq.getCoordinateCopy(i$1);
  6228. }
  6229. }
  6230. } else if (arguments.length === 2) {
  6231. if (arguments[0] instanceof Array && Number.isInteger(arguments[1])) {
  6232. var coordinates = arguments[0];
  6233. var dimension = arguments[1];
  6234. this._coordinates = coordinates;
  6235. this._dimension = dimension;
  6236. if (coordinates === null) { this._coordinates = new Array(0).fill(null); }
  6237. } else if (Number.isInteger(arguments[0]) && Number.isInteger(arguments[1])) {
  6238. var size$1 = arguments[0];
  6239. var dimension$1 = arguments[1];
  6240. this._coordinates = new Array(size$1).fill(null);
  6241. this._dimension = dimension$1;
  6242. for (var i$2 = 0; i$2 < size$1; i$2++) {
  6243. this$1._coordinates[i$2] = new Coordinate();
  6244. }
  6245. }
  6246. }
  6247. };
  6248. var staticAccessors$18 = { serialVersionUID: { configurable: true } };
  6249. CoordinateArraySequence.prototype.setOrdinate = function setOrdinate (index, ordinateIndex, value) {
  6250. switch (ordinateIndex) {
  6251. case CoordinateSequence.X:
  6252. this._coordinates[index].x = value;
  6253. break
  6254. case CoordinateSequence.Y:
  6255. this._coordinates[index].y = value;
  6256. break
  6257. case CoordinateSequence.Z:
  6258. this._coordinates[index].z = value;
  6259. break
  6260. default:
  6261. throw new IllegalArgumentException('invalid ordinateIndex')
  6262. }
  6263. };
  6264. CoordinateArraySequence.prototype.size = function size () {
  6265. return this._coordinates.length
  6266. };
  6267. CoordinateArraySequence.prototype.getOrdinate = function getOrdinate (index, ordinateIndex) {
  6268. switch (ordinateIndex) {
  6269. case CoordinateSequence.X:
  6270. return this._coordinates[index].x
  6271. case CoordinateSequence.Y:
  6272. return this._coordinates[index].y
  6273. case CoordinateSequence.Z:
  6274. return this._coordinates[index].z
  6275. default:
  6276. }
  6277. return Double.NaN
  6278. };
  6279. CoordinateArraySequence.prototype.getCoordinate = function getCoordinate () {
  6280. if (arguments.length === 1) {
  6281. var i = arguments[0];
  6282. return this._coordinates[i]
  6283. } else if (arguments.length === 2) {
  6284. var index = arguments[0];
  6285. var coord = arguments[1];
  6286. coord.x = this._coordinates[index].x;
  6287. coord.y = this._coordinates[index].y;
  6288. coord.z = this._coordinates[index].z;
  6289. }
  6290. };
  6291. CoordinateArraySequence.prototype.getCoordinateCopy = function getCoordinateCopy (i) {
  6292. return new Coordinate(this._coordinates[i])
  6293. };
  6294. CoordinateArraySequence.prototype.getDimension = function getDimension () {
  6295. return this._dimension
  6296. };
  6297. CoordinateArraySequence.prototype.getX = function getX (index) {
  6298. return this._coordinates[index].x
  6299. };
  6300. CoordinateArraySequence.prototype.clone = function clone () {
  6301. var this$1 = this;
  6302. var cloneCoordinates = new Array(this.size()).fill(null);
  6303. for (var i = 0; i < this._coordinates.length; i++) {
  6304. cloneCoordinates[i] = this$1._coordinates[i].clone();
  6305. }
  6306. return new CoordinateArraySequence(cloneCoordinates, this._dimension)
  6307. };
  6308. CoordinateArraySequence.prototype.expandEnvelope = function expandEnvelope (env) {
  6309. var this$1 = this;
  6310. for (var i = 0; i < this._coordinates.length; i++) {
  6311. env.expandToInclude(this$1._coordinates[i]);
  6312. }
  6313. return env
  6314. };
  6315. CoordinateArraySequence.prototype.copy = function copy () {
  6316. var this$1 = this;
  6317. var cloneCoordinates = new Array(this.size()).fill(null);
  6318. for (var i = 0; i < this._coordinates.length; i++) {
  6319. cloneCoordinates[i] = this$1._coordinates[i].copy();
  6320. }
  6321. return new CoordinateArraySequence(cloneCoordinates, this._dimension)
  6322. };
  6323. CoordinateArraySequence.prototype.toString = function toString () {
  6324. var this$1 = this;
  6325. if (this._coordinates.length > 0) {
  6326. var strBuf = new StringBuffer(17 * this._coordinates.length);
  6327. strBuf.append('(');
  6328. strBuf.append(this._coordinates[0]);
  6329. for (var i = 1; i < this._coordinates.length; i++) {
  6330. strBuf.append(', ');
  6331. strBuf.append(this$1._coordinates[i]);
  6332. }
  6333. strBuf.append(')');
  6334. return strBuf.toString()
  6335. } else {
  6336. return '()'
  6337. }
  6338. };
  6339. CoordinateArraySequence.prototype.getY = function getY (index) {
  6340. return this._coordinates[index].y
  6341. };
  6342. CoordinateArraySequence.prototype.toCoordinateArray = function toCoordinateArray () {
  6343. return this._coordinates
  6344. };
  6345. CoordinateArraySequence.prototype.interfaces_ = function interfaces_ () {
  6346. return [CoordinateSequence, Serializable]
  6347. };
  6348. CoordinateArraySequence.prototype.getClass = function getClass () {
  6349. return CoordinateArraySequence
  6350. };
  6351. staticAccessors$18.serialVersionUID.get = function () { return -915438501601840650 };
  6352. Object.defineProperties( CoordinateArraySequence, staticAccessors$18 );
  6353. var CoordinateArraySequenceFactory = function CoordinateArraySequenceFactory () {};
  6354. var staticAccessors$17 = { serialVersionUID: { configurable: true },instanceObject: { configurable: true } };
  6355. CoordinateArraySequenceFactory.prototype.readResolve = function readResolve () {
  6356. return CoordinateArraySequenceFactory.instance()
  6357. };
  6358. CoordinateArraySequenceFactory.prototype.create = function create () {
  6359. if (arguments.length === 1) {
  6360. if (arguments[0] instanceof Array) {
  6361. var coordinates = arguments[0];
  6362. return new CoordinateArraySequence(coordinates)
  6363. } else if (hasInterface(arguments[0], CoordinateSequence)) {
  6364. var coordSeq = arguments[0];
  6365. return new CoordinateArraySequence(coordSeq)
  6366. }
  6367. } else if (arguments.length === 2) {
  6368. var size = arguments[0];
  6369. var dimension = arguments[1];
  6370. if (dimension > 3) { dimension = 3; }
  6371. if (dimension < 2) { return new CoordinateArraySequence(size) }
  6372. return new CoordinateArraySequence(size, dimension)
  6373. }
  6374. };
  6375. CoordinateArraySequenceFactory.prototype.interfaces_ = function interfaces_ () {
  6376. return [CoordinateSequenceFactory, Serializable]
  6377. };
  6378. CoordinateArraySequenceFactory.prototype.getClass = function getClass () {
  6379. return CoordinateArraySequenceFactory
  6380. };
  6381. CoordinateArraySequenceFactory.instance = function instance () {
  6382. return CoordinateArraySequenceFactory.instanceObject
  6383. };
  6384. staticAccessors$17.serialVersionUID.get = function () { return -4099577099607551657 };
  6385. staticAccessors$17.instanceObject.get = function () { return new CoordinateArraySequenceFactory() };
  6386. Object.defineProperties( CoordinateArraySequenceFactory, staticAccessors$17 );
  6387. /**
  6388. * @see http://download.oracle.com/javase/6/docs/api/java/util/HashMap.html
  6389. *
  6390. * @extends {javascript.util.Map}
  6391. * @constructor
  6392. * @private
  6393. */
  6394. var HashMap = (function (MapInterface) {
  6395. function HashMap () {
  6396. MapInterface.call(this);
  6397. this.map_ = new Map();
  6398. }
  6399. if ( MapInterface ) HashMap.__proto__ = MapInterface;
  6400. HashMap.prototype = Object.create( MapInterface && MapInterface.prototype );
  6401. HashMap.prototype.constructor = HashMap;
  6402. /**
  6403. * @override
  6404. */
  6405. HashMap.prototype.get = function get (key) {
  6406. return this.map_.get(key) || null
  6407. };
  6408. /**
  6409. * @override
  6410. */
  6411. HashMap.prototype.put = function put (key, value) {
  6412. this.map_.set(key, value);
  6413. return value
  6414. };
  6415. /**
  6416. * @override
  6417. */
  6418. HashMap.prototype.values = function values () {
  6419. var arrayList = new ArrayList();
  6420. var it = this.map_.values();
  6421. var o = it.next();
  6422. while (!o.done) {
  6423. arrayList.add(o.value);
  6424. o = it.next();
  6425. }
  6426. return arrayList
  6427. };
  6428. /**
  6429. * @override
  6430. */
  6431. HashMap.prototype.entrySet = function entrySet () {
  6432. var hashSet = new HashSet();
  6433. this.map_.entries().forEach(function (entry) { return hashSet.add(entry); });
  6434. return hashSet
  6435. };
  6436. /**
  6437. * @override
  6438. */
  6439. HashMap.prototype.size = function size () {
  6440. return this.map_.size()
  6441. };
  6442. return HashMap;
  6443. }(Map$1));
  6444. var PrecisionModel = function PrecisionModel () {
  6445. this._modelType = null;
  6446. this._scale = null;
  6447. if (arguments.length === 0) {
  6448. this._modelType = PrecisionModel.FLOATING;
  6449. } else if (arguments.length === 1) {
  6450. if (arguments[0] instanceof Type) {
  6451. var modelType = arguments[0];
  6452. this._modelType = modelType;
  6453. if (modelType === PrecisionModel.FIXED) {
  6454. this.setScale(1.0);
  6455. }
  6456. } else if (typeof arguments[0] === 'number') {
  6457. var scale = arguments[0];
  6458. this._modelType = PrecisionModel.FIXED;
  6459. this.setScale(scale);
  6460. } else if (arguments[0] instanceof PrecisionModel) {
  6461. var pm = arguments[0];
  6462. this._modelType = pm._modelType;
  6463. this._scale = pm._scale;
  6464. }
  6465. }
  6466. };
  6467. var staticAccessors$19 = { serialVersionUID: { configurable: true },maximumPreciseValue: { configurable: true } };
  6468. PrecisionModel.prototype.equals = function equals (other) {
  6469. if (!(other instanceof PrecisionModel)) {
  6470. return false
  6471. }
  6472. var otherPrecisionModel = other;
  6473. return this._modelType === otherPrecisionModel._modelType && this._scale === otherPrecisionModel._scale
  6474. };
  6475. PrecisionModel.prototype.compareTo = function compareTo (o) {
  6476. var other = o;
  6477. var sigDigits = this.getMaximumSignificantDigits();
  6478. var otherSigDigits = other.getMaximumSignificantDigits();
  6479. return new Integer(sigDigits).compareTo(new Integer(otherSigDigits))
  6480. };
  6481. PrecisionModel.prototype.getScale = function getScale () {
  6482. return this._scale
  6483. };
  6484. PrecisionModel.prototype.isFloating = function isFloating () {
  6485. return this._modelType === PrecisionModel.FLOATING || this._modelType === PrecisionModel.FLOATING_SINGLE
  6486. };
  6487. PrecisionModel.prototype.getType = function getType () {
  6488. return this._modelType
  6489. };
  6490. PrecisionModel.prototype.toString = function toString () {
  6491. var description = 'UNKNOWN';
  6492. if (this._modelType === PrecisionModel.FLOATING) {
  6493. description = 'Floating';
  6494. } else if (this._modelType === PrecisionModel.FLOATING_SINGLE) {
  6495. description = 'Floating-Single';
  6496. } else if (this._modelType === PrecisionModel.FIXED) {
  6497. description = 'Fixed (Scale=' + this.getScale() + ')';
  6498. }
  6499. return description
  6500. };
  6501. PrecisionModel.prototype.makePrecise = function makePrecise () {
  6502. if (typeof arguments[0] === 'number') {
  6503. var val = arguments[0];
  6504. if (Double.isNaN(val)) { return val }
  6505. if (this._modelType === PrecisionModel.FLOATING_SINGLE) {
  6506. var floatSingleVal = val;
  6507. return floatSingleVal
  6508. }
  6509. if (this._modelType === PrecisionModel.FIXED) {
  6510. return Math.round(val * this._scale) / this._scale
  6511. }
  6512. return val
  6513. } else if (arguments[0] instanceof Coordinate) {
  6514. var coord = arguments[0];
  6515. if (this._modelType === PrecisionModel.FLOATING) { return null }
  6516. coord.x = this.makePrecise(coord.x);
  6517. coord.y = this.makePrecise(coord.y);
  6518. }
  6519. };
  6520. PrecisionModel.prototype.getMaximumSignificantDigits = function getMaximumSignificantDigits () {
  6521. var maxSigDigits = 16;
  6522. if (this._modelType === PrecisionModel.FLOATING) {
  6523. maxSigDigits = 16;
  6524. } else if (this._modelType === PrecisionModel.FLOATING_SINGLE) {
  6525. maxSigDigits = 6;
  6526. } else if (this._modelType === PrecisionModel.FIXED) {
  6527. maxSigDigits = 1 + Math.trunc(Math.ceil(Math.log(this.getScale()) / Math.log(10)));
  6528. }
  6529. return maxSigDigits
  6530. };
  6531. PrecisionModel.prototype.setScale = function setScale (scale) {
  6532. this._scale = Math.abs(scale);
  6533. };
  6534. PrecisionModel.prototype.interfaces_ = function interfaces_ () {
  6535. return [Serializable, Comparable]
  6536. };
  6537. PrecisionModel.prototype.getClass = function getClass () {
  6538. return PrecisionModel
  6539. };
  6540. PrecisionModel.mostPrecise = function mostPrecise (pm1, pm2) {
  6541. if (pm1.compareTo(pm2) >= 0) { return pm1 }
  6542. return pm2
  6543. };
  6544. staticAccessors$19.serialVersionUID.get = function () { return 7777263578777803835 };
  6545. staticAccessors$19.maximumPreciseValue.get = function () { return 9007199254740992.0 };
  6546. Object.defineProperties( PrecisionModel, staticAccessors$19 );
  6547. var Type = function Type (name) {
  6548. this._name = name || null;
  6549. Type.nameToTypeMap.put(name, this);
  6550. };
  6551. var staticAccessors$1$1 = { serialVersionUID: { configurable: true },nameToTypeMap: { configurable: true } };
  6552. Type.prototype.readResolve = function readResolve () {
  6553. return Type.nameToTypeMap.get(this._name)
  6554. };
  6555. Type.prototype.toString = function toString () {
  6556. return this._name
  6557. };
  6558. Type.prototype.interfaces_ = function interfaces_ () {
  6559. return [Serializable]
  6560. };
  6561. Type.prototype.getClass = function getClass () {
  6562. return Type
  6563. };
  6564. staticAccessors$1$1.serialVersionUID.get = function () { return -5528602631731589822 };
  6565. staticAccessors$1$1.nameToTypeMap.get = function () { return new HashMap() };
  6566. Object.defineProperties( Type, staticAccessors$1$1 );
  6567. PrecisionModel.Type = Type;
  6568. PrecisionModel.FIXED = new Type('FIXED');
  6569. PrecisionModel.FLOATING = new Type('FLOATING');
  6570. PrecisionModel.FLOATING_SINGLE = new Type('FLOATING SINGLE');
  6571. var GeometryFactory = function GeometryFactory () {
  6572. this._precisionModel = new PrecisionModel();
  6573. this._SRID = 0;
  6574. this._coordinateSequenceFactory = GeometryFactory.getDefaultCoordinateSequenceFactory();
  6575. if (arguments.length === 0) {
  6576. } else if (arguments.length === 1) {
  6577. if (hasInterface(arguments[0], CoordinateSequenceFactory)) {
  6578. this._coordinateSequenceFactory = arguments[0];
  6579. } else if (arguments[0] instanceof PrecisionModel) {
  6580. this._precisionModel = arguments[0];
  6581. }
  6582. } else if (arguments.length === 2) {
  6583. this._precisionModel = arguments[0];
  6584. this._SRID = arguments[1];
  6585. } else if (arguments.length === 3) {
  6586. this._precisionModel = arguments[0];
  6587. this._SRID = arguments[1];
  6588. this._coordinateSequenceFactory = arguments[2];
  6589. }
  6590. };
  6591. var staticAccessors$2 = { serialVersionUID: { configurable: true } };
  6592. GeometryFactory.prototype.toGeometry = function toGeometry (envelope) {
  6593. if (envelope.isNull()) {
  6594. return this.createPoint(null)
  6595. }
  6596. if (envelope.getMinX() === envelope.getMaxX() && envelope.getMinY() === envelope.getMaxY()) {
  6597. return this.createPoint(new Coordinate(envelope.getMinX(), envelope.getMinY()))
  6598. }
  6599. if (envelope.getMinX() === envelope.getMaxX() || envelope.getMinY() === envelope.getMaxY()) {
  6600. return this.createLineString([new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY())])
  6601. }
  6602. 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)
  6603. };
  6604. GeometryFactory.prototype.createLineString = function createLineString (coordinates) {
  6605. if (!coordinates) { return new LineString(this.getCoordinateSequenceFactory().create([]), this) }
  6606. else if (coordinates instanceof Array) { return new LineString(this.getCoordinateSequenceFactory().create(coordinates), this) }
  6607. else if (hasInterface(coordinates, CoordinateSequence)) { return new LineString(coordinates, this) }
  6608. };
  6609. GeometryFactory.prototype.createMultiLineString = function createMultiLineString () {
  6610. if (arguments.length === 0) {
  6611. return new MultiLineString(null, this)
  6612. } else if (arguments.length === 1) {
  6613. var lineStrings = arguments[0];
  6614. return new MultiLineString(lineStrings, this)
  6615. }
  6616. };
  6617. GeometryFactory.prototype.buildGeometry = function buildGeometry (geomList) {
  6618. var geomClass = null;
  6619. var isHeterogeneous = false;
  6620. var hasGeometryCollection = false;
  6621. for (var i = geomList.iterator(); i.hasNext();) {
  6622. var geom = i.next();
  6623. var partClass = geom.getClass();
  6624. if (geomClass === null) {
  6625. geomClass = partClass;
  6626. }
  6627. if (partClass !== geomClass) {
  6628. isHeterogeneous = true;
  6629. }
  6630. if (geom.isGeometryCollectionOrDerived()) { hasGeometryCollection = true; }
  6631. }
  6632. if (geomClass === null) {
  6633. return this.createGeometryCollection()
  6634. }
  6635. if (isHeterogeneous || hasGeometryCollection) {
  6636. return this.createGeometryCollection(GeometryFactory.toGeometryArray(geomList))
  6637. }
  6638. var geom0 = geomList.iterator().next();
  6639. var isCollection = geomList.size() > 1;
  6640. if (isCollection) {
  6641. if (geom0 instanceof Polygon) {
  6642. return this.createMultiPolygon(GeometryFactory.toPolygonArray(geomList))
  6643. } else if (geom0 instanceof LineString) {
  6644. return this.createMultiLineString(GeometryFactory.toLineStringArray(geomList))
  6645. } else if (geom0 instanceof Point) {
  6646. return this.createMultiPoint(GeometryFactory.toPointArray(geomList))
  6647. }
  6648. Assert.shouldNeverReachHere('Unhandled class: ' + geom0.getClass().getName());
  6649. }
  6650. return geom0
  6651. };
  6652. GeometryFactory.prototype.createMultiPointFromCoords = function createMultiPointFromCoords (coordinates) {
  6653. return this.createMultiPoint(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)
  6654. };
  6655. GeometryFactory.prototype.createPoint = function createPoint () {
  6656. if (arguments.length === 0) {
  6657. return this.createPoint(this.getCoordinateSequenceFactory().create([]))
  6658. } else if (arguments.length === 1) {
  6659. if (arguments[0] instanceof Coordinate) {
  6660. var coordinate = arguments[0];
  6661. return this.createPoint(coordinate !== null ? this.getCoordinateSequenceFactory().create([coordinate]) : null)
  6662. } else if (hasInterface(arguments[0], CoordinateSequence)) {
  6663. var coordinates = arguments[0];
  6664. return new Point(coordinates, this)
  6665. }
  6666. }
  6667. };
  6668. GeometryFactory.prototype.getCoordinateSequenceFactory = function getCoordinateSequenceFactory () {
  6669. return this._coordinateSequenceFactory
  6670. };
  6671. GeometryFactory.prototype.createPolygon = function createPolygon () {
  6672. if (arguments.length === 0) {
  6673. return new Polygon(null, null, this)
  6674. } else if (arguments.length === 1) {
  6675. if (hasInterface(arguments[0], CoordinateSequence)) {
  6676. var coordinates = arguments[0];
  6677. return this.createPolygon(this.createLinearRing(coordinates))
  6678. } else if (arguments[0] instanceof Array) {
  6679. var coordinates$1 = arguments[0];
  6680. return this.createPolygon(this.createLinearRing(coordinates$1))
  6681. } else if (arguments[0] instanceof LinearRing) {
  6682. var shell = arguments[0];
  6683. return this.createPolygon(shell, null)
  6684. }
  6685. } else if (arguments.length === 2) {
  6686. var shell$1 = arguments[0];
  6687. var holes = arguments[1];
  6688. return new Polygon(shell$1, holes, this)
  6689. }
  6690. };
  6691. GeometryFactory.prototype.getSRID = function getSRID () {
  6692. return this._SRID
  6693. };
  6694. GeometryFactory.prototype.createGeometryCollection = function createGeometryCollection () {
  6695. if (arguments.length === 0) {
  6696. return new GeometryCollection(null, this)
  6697. } else if (arguments.length === 1) {
  6698. var geometries = arguments[0];
  6699. return new GeometryCollection(geometries, this)
  6700. }
  6701. };
  6702. GeometryFactory.prototype.createGeometry = function createGeometry (g) {
  6703. var editor = new GeometryEditor(this);
  6704. return editor.edit(g, {
  6705. edit: function () {
  6706. if (arguments.length === 2) {
  6707. var coordSeq = arguments[0];
  6708. // const geometry = arguments[1]
  6709. return this._coordinateSequenceFactory.create(coordSeq)
  6710. }
  6711. }
  6712. })
  6713. };
  6714. GeometryFactory.prototype.getPrecisionModel = function getPrecisionModel () {
  6715. return this._precisionModel
  6716. };
  6717. GeometryFactory.prototype.createLinearRing = function createLinearRing () {
  6718. if (arguments.length === 0) {
  6719. return this.createLinearRing(this.getCoordinateSequenceFactory().create([]))
  6720. } else if (arguments.length === 1) {
  6721. if (arguments[0] instanceof Array) {
  6722. var coordinates = arguments[0];
  6723. return this.createLinearRing(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)
  6724. } else if (hasInterface(arguments[0], CoordinateSequence)) {
  6725. var coordinates$1 = arguments[0];
  6726. return new LinearRing(coordinates$1, this)
  6727. }
  6728. }
  6729. };
  6730. GeometryFactory.prototype.createMultiPolygon = function createMultiPolygon () {
  6731. if (arguments.length === 0) {
  6732. return new MultiPolygon(null, this)
  6733. } else if (arguments.length === 1) {
  6734. var polygons = arguments[0];
  6735. return new MultiPolygon(polygons, this)
  6736. }
  6737. };
  6738. GeometryFactory.prototype.createMultiPoint = function createMultiPoint () {
  6739. var this$1 = this;
  6740. if (arguments.length === 0) {
  6741. return new MultiPoint(null, this)
  6742. } else if (arguments.length === 1) {
  6743. if (arguments[0] instanceof Array) {
  6744. var point = arguments[0];
  6745. return new MultiPoint(point, this)
  6746. } else if (arguments[0] instanceof Array) {
  6747. var coordinates = arguments[0];
  6748. return this.createMultiPoint(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)
  6749. } else if (hasInterface(arguments[0], CoordinateSequence)) {
  6750. var coordinates$1 = arguments[0];
  6751. if (coordinates$1 === null) {
  6752. return this.createMultiPoint(new Array(0).fill(null))
  6753. }
  6754. var points = new Array(coordinates$1.size()).fill(null);
  6755. for (var i = 0; i < coordinates$1.size(); i++) {
  6756. var ptSeq = this$1.getCoordinateSequenceFactory().create(1, coordinates$1.getDimension());
  6757. CoordinateSequences.copy(coordinates$1, i, ptSeq, 0, 1);
  6758. points[i] = this$1.createPoint(ptSeq);
  6759. }
  6760. return this.createMultiPoint(points)
  6761. }
  6762. }
  6763. };
  6764. GeometryFactory.prototype.interfaces_ = function interfaces_ () {
  6765. return [Serializable]
  6766. };
  6767. GeometryFactory.prototype.getClass = function getClass () {
  6768. return GeometryFactory
  6769. };
  6770. GeometryFactory.toMultiPolygonArray = function toMultiPolygonArray (multiPolygons) {
  6771. var multiPolygonArray = new Array(multiPolygons.size()).fill(null);
  6772. return multiPolygons.toArray(multiPolygonArray)
  6773. };
  6774. GeometryFactory.toGeometryArray = function toGeometryArray (geometries) {
  6775. if (geometries === null) { return null }
  6776. var geometryArray = new Array(geometries.size()).fill(null);
  6777. return geometries.toArray(geometryArray)
  6778. };
  6779. GeometryFactory.getDefaultCoordinateSequenceFactory = function getDefaultCoordinateSequenceFactory () {
  6780. return CoordinateArraySequenceFactory.instance()
  6781. };
  6782. GeometryFactory.toMultiLineStringArray = function toMultiLineStringArray (multiLineStrings) {
  6783. var multiLineStringArray = new Array(multiLineStrings.size()).fill(null);
  6784. return multiLineStrings.toArray(multiLineStringArray)
  6785. };
  6786. GeometryFactory.toLineStringArray = function toLineStringArray (lineStrings) {
  6787. var lineStringArray = new Array(lineStrings.size()).fill(null);
  6788. return lineStrings.toArray(lineStringArray)
  6789. };
  6790. GeometryFactory.toMultiPointArray = function toMultiPointArray (multiPoints) {
  6791. var multiPointArray = new Array(multiPoints.size()).fill(null);
  6792. return multiPoints.toArray(multiPointArray)
  6793. };
  6794. GeometryFactory.toLinearRingArray = function toLinearRingArray (linearRings) {
  6795. var linearRingArray = new Array(linearRings.size()).fill(null);
  6796. return linearRings.toArray(linearRingArray)
  6797. };
  6798. GeometryFactory.toPointArray = function toPointArray (points) {
  6799. var pointArray = new Array(points.size()).fill(null);
  6800. return points.toArray(pointArray)
  6801. };
  6802. GeometryFactory.toPolygonArray = function toPolygonArray (polygons) {
  6803. var polygonArray = new Array(polygons.size()).fill(null);
  6804. return polygons.toArray(polygonArray)
  6805. };
  6806. GeometryFactory.createPointFromInternalCoord = function createPointFromInternalCoord (coord, exemplar) {
  6807. exemplar.getPrecisionModel().makePrecise(coord);
  6808. return exemplar.getFactory().createPoint(coord)
  6809. };
  6810. staticAccessors$2.serialVersionUID.get = function () { return -6820524753094095635 };
  6811. Object.defineProperties( GeometryFactory, staticAccessors$2 );
  6812. var geometryTypes = ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon'];
  6813. /**
  6814. * Class for reading and writing Well-Known Text.Create a new parser for GeoJSON
  6815. * NOTE: Adapted from OpenLayers 2.11 implementation.
  6816. */
  6817. /**
  6818. * Create a new parser for GeoJSON
  6819. *
  6820. * @param {GeometryFactory} geometryFactory
  6821. * @return An instance of GeoJsonParser.
  6822. * @constructor
  6823. * @private
  6824. */
  6825. var GeoJSONParser = function GeoJSONParser (geometryFactory) {
  6826. this.geometryFactory = geometryFactory || new GeometryFactory();
  6827. };
  6828. /**
  6829. * Deserialize a GeoJSON object and return the Geometry or Feature(Collection) with JSTS Geometries
  6830. *
  6831. * @param {}
  6832. * A GeoJSON object.
  6833. * @return {} A Geometry instance or object representing a Feature(Collection) with Geometry instances.
  6834. * @private
  6835. */
  6836. GeoJSONParser.prototype.read = function read (json) {
  6837. var obj;
  6838. if (typeof json === 'string') {
  6839. obj = JSON.parse(json);
  6840. } else {
  6841. obj = json;
  6842. }
  6843. var type = obj.type;
  6844. if (!parse[type]) {
  6845. throw new Error('Unknown GeoJSON type: ' + obj.type)
  6846. }
  6847. if (geometryTypes.indexOf(type) !== -1) {
  6848. return parse[type].apply(this, [obj.coordinates])
  6849. } else if (type === 'GeometryCollection') {
  6850. return parse[type].apply(this, [obj.geometries])
  6851. }
  6852. // feature or feature collection
  6853. return parse[type].apply(this, [obj])
  6854. };
  6855. /**
  6856. * Serialize a Geometry object into GeoJSON
  6857. *
  6858. * @param {Geometry}
  6859. * geometry A Geometry or array of Geometries.
  6860. * @return {Object} A GeoJSON object represting the input Geometry/Geometries.
  6861. * @private
  6862. */
  6863. GeoJSONParser.prototype.write = function write (geometry) {
  6864. var type = geometry.getGeometryType();
  6865. if (!extract[type]) {
  6866. throw new Error('Geometry is not supported')
  6867. }
  6868. return extract[type].apply(this, [geometry])
  6869. };
  6870. var parse = {
  6871. /**
  6872. * Parse a GeoJSON Feature object
  6873. *
  6874. * @param {Object}
  6875. * obj Object to parse.
  6876. *
  6877. * @return {Object} Feature with geometry/bbox converted to JSTS Geometries.
  6878. */
  6879. Feature: function (obj) {
  6880. var feature = {};
  6881. // copy features
  6882. for (var key in obj) {
  6883. feature[key] = obj[key];
  6884. }
  6885. // parse geometry
  6886. if (obj.geometry) {
  6887. var type = obj.geometry.type;
  6888. if (!parse[type]) {
  6889. throw new Error('Unknown GeoJSON type: ' + obj.type)
  6890. }
  6891. feature.geometry = this.read(obj.geometry);
  6892. }
  6893. // bbox
  6894. if (obj.bbox) {
  6895. feature.bbox = parse.bbox.apply(this, [obj.bbox]);
  6896. }
  6897. return feature
  6898. },
  6899. /**
  6900. * Parse a GeoJSON FeatureCollection object
  6901. *
  6902. * @param {Object}
  6903. * obj Object to parse.
  6904. *
  6905. * @return {Object} FeatureCollection with geometry/bbox converted to JSTS Geometries.
  6906. */
  6907. FeatureCollection: function (obj) {
  6908. var this$1 = this;
  6909. var featureCollection = {};
  6910. if (obj.features) {
  6911. featureCollection.features = [];
  6912. for (var i = 0; i < obj.features.length; ++i) {
  6913. featureCollection.features.push(this$1.read(obj.features[i]));
  6914. }
  6915. }
  6916. if (obj.bbox) {
  6917. featureCollection.bbox = this.parse.bbox.apply(this, [obj.bbox]);
  6918. }
  6919. return featureCollection
  6920. },
  6921. /**
  6922. * Convert the ordinates in an array to an array of Coordinates
  6923. *
  6924. * @param {Array}
  6925. * array Array with {Number}s.
  6926. *
  6927. * @return {Array} Array with Coordinates.
  6928. */
  6929. coordinates: function (array) {
  6930. var coordinates = [];
  6931. for (var i = 0; i < array.length; ++i) {
  6932. var sub = array[i];
  6933. coordinates.push(new Coordinate(sub[0], sub[1]));
  6934. }
  6935. return coordinates
  6936. },
  6937. /**
  6938. * Convert the bbox to a LinearRing
  6939. *
  6940. * @param {Array}
  6941. * array Array with [xMin, yMin, xMax, yMax].
  6942. *
  6943. * @return {Array} Array with Coordinates.
  6944. */
  6945. bbox: function (array) {
  6946. return this.geometryFactory.createLinearRing([
  6947. new Coordinate(array[0], array[1]),
  6948. new Coordinate(array[2], array[1]),
  6949. new Coordinate(array[2], array[3]),
  6950. new Coordinate(array[0], array[3]),
  6951. new Coordinate(array[0], array[1])
  6952. ])
  6953. },
  6954. /**
  6955. * Convert an Array with ordinates to a Point
  6956. *
  6957. * @param {Array}
  6958. * array Array with ordinates.
  6959. *
  6960. * @return {Point} Point.
  6961. */
  6962. Point: function (array) {
  6963. var coordinate = new Coordinate(array[0], array[1]);
  6964. return this.geometryFactory.createPoint(coordinate)
  6965. },
  6966. /**
  6967. * Convert an Array with coordinates to a MultiPoint
  6968. *
  6969. * @param {Array}
  6970. * array Array with coordinates.
  6971. *
  6972. * @return {MultiPoint} MultiPoint.
  6973. */
  6974. MultiPoint: function (array) {
  6975. var this$1 = this;
  6976. var points = [];
  6977. for (var i = 0; i < array.length; ++i) {
  6978. points.push(parse.Point.apply(this$1, [array[i]]));
  6979. }
  6980. return this.geometryFactory.createMultiPoint(points)
  6981. },
  6982. /**
  6983. * Convert an Array with coordinates to a LineString
  6984. *
  6985. * @param {Array}
  6986. * array Array with coordinates.
  6987. *
  6988. * @return {LineString} LineString.
  6989. */
  6990. LineString: function (array) {
  6991. var coordinates = parse.coordinates.apply(this, [array]);
  6992. return this.geometryFactory.createLineString(coordinates)
  6993. },
  6994. /**
  6995. * Convert an Array with coordinates to a MultiLineString
  6996. *
  6997. * @param {Array}
  6998. * array Array with coordinates.
  6999. *
  7000. * @return {MultiLineString} MultiLineString.
  7001. */
  7002. MultiLineString: function (array) {
  7003. var this$1 = this;
  7004. var lineStrings = [];
  7005. for (var i = 0; i < array.length; ++i) {
  7006. lineStrings.push(parse.LineString.apply(this$1, [array[i]]));
  7007. }
  7008. return this.geometryFactory.createMultiLineString(lineStrings)
  7009. },
  7010. /**
  7011. * Convert an Array to a Polygon
  7012. *
  7013. * @param {Array}
  7014. * array Array with shell and holes.
  7015. *
  7016. * @return {Polygon} Polygon.
  7017. */
  7018. Polygon: function (array) {
  7019. var this$1 = this;
  7020. var shellCoordinates = parse.coordinates.apply(this, [array[0]]);
  7021. var shell = this.geometryFactory.createLinearRing(shellCoordinates);
  7022. var holes = [];
  7023. for (var i = 1; i < array.length; ++i) {
  7024. var hole = array[i];
  7025. var coordinates = parse.coordinates.apply(this$1, [hole]);
  7026. var linearRing = this$1.geometryFactory.createLinearRing(coordinates);
  7027. holes.push(linearRing);
  7028. }
  7029. return this.geometryFactory.createPolygon(shell, holes)
  7030. },
  7031. /**
  7032. * Convert an Array to a MultiPolygon
  7033. *
  7034. * @param {Array}
  7035. * array Array of arrays with shell and rings.
  7036. *
  7037. * @return {MultiPolygon} MultiPolygon.
  7038. */
  7039. MultiPolygon: function (array) {
  7040. var this$1 = this;
  7041. var polygons = [];
  7042. for (var i = 0; i < array.length; ++i) {
  7043. var polygon = array[i];
  7044. polygons.push(parse.Polygon.apply(this$1, [polygon]));
  7045. }
  7046. return this.geometryFactory.createMultiPolygon(polygons)
  7047. },
  7048. /**
  7049. * Convert an Array to a GeometryCollection
  7050. *
  7051. * @param {Array}
  7052. * array Array of GeoJSON geometries.
  7053. *
  7054. * @return {GeometryCollection} GeometryCollection.
  7055. */
  7056. GeometryCollection: function (array) {
  7057. var this$1 = this;
  7058. var geometries = [];
  7059. for (var i = 0; i < array.length; ++i) {
  7060. var geometry = array[i];
  7061. geometries.push(this$1.read(geometry));
  7062. }
  7063. return this.geometryFactory.createGeometryCollection(geometries)
  7064. }
  7065. };
  7066. var extract = {
  7067. /**
  7068. * Convert a Coordinate to an Array
  7069. *
  7070. * @param {Coordinate}
  7071. * coordinate Coordinate to convert.
  7072. *
  7073. * @return {Array} Array of ordinates.
  7074. */
  7075. coordinate: function (coordinate) {
  7076. return [coordinate.x, coordinate.y]
  7077. },
  7078. /**
  7079. * Convert a Point to a GeoJSON object
  7080. *
  7081. * @param {Point}
  7082. * point Point to convert.
  7083. *
  7084. * @return {Array} Array of 2 ordinates (paired to a coordinate).
  7085. */
  7086. Point: function (point) {
  7087. var array = extract.coordinate.apply(this, [point.getCoordinate()]);
  7088. return {
  7089. type: 'Point',
  7090. coordinates: array
  7091. }
  7092. },
  7093. /**
  7094. * Convert a MultiPoint to a GeoJSON object
  7095. *
  7096. * @param {MultiPoint}
  7097. * multipoint MultiPoint to convert.
  7098. *
  7099. * @return {Array} Array of coordinates.
  7100. */
  7101. MultiPoint: function (multipoint) {
  7102. var this$1 = this;
  7103. var array = [];
  7104. for (var i = 0; i < multipoint._geometries.length; ++i) {
  7105. var point = multipoint._geometries[i];
  7106. var geoJson = extract.Point.apply(this$1, [point]);
  7107. array.push(geoJson.coordinates);
  7108. }
  7109. return {
  7110. type: 'MultiPoint',
  7111. coordinates: array
  7112. }
  7113. },
  7114. /**
  7115. * Convert a LineString to a GeoJSON object
  7116. *
  7117. * @param {LineString}
  7118. * linestring LineString to convert.
  7119. *
  7120. * @return {Array} Array of coordinates.
  7121. */
  7122. LineString: function (linestring) {
  7123. var this$1 = this;
  7124. var array = [];
  7125. var coordinates = linestring.getCoordinates();
  7126. for (var i = 0; i < coordinates.length; ++i) {
  7127. var coordinate = coordinates[i];
  7128. array.push(extract.coordinate.apply(this$1, [coordinate]));
  7129. }
  7130. return {
  7131. type: 'LineString',
  7132. coordinates: array
  7133. }
  7134. },
  7135. /**
  7136. * Convert a MultiLineString to a GeoJSON object
  7137. *
  7138. * @param {MultiLineString}
  7139. * multilinestring MultiLineString to convert.
  7140. *
  7141. * @return {Array} Array of Array of coordinates.
  7142. */
  7143. MultiLineString: function (multilinestring) {
  7144. var this$1 = this;
  7145. var array = [];
  7146. for (var i = 0; i < multilinestring._geometries.length; ++i) {
  7147. var linestring = multilinestring._geometries[i];
  7148. var geoJson = extract.LineString.apply(this$1, [linestring]);
  7149. array.push(geoJson.coordinates);
  7150. }
  7151. return {
  7152. type: 'MultiLineString',
  7153. coordinates: array
  7154. }
  7155. },
  7156. /**
  7157. * Convert a Polygon to a GeoJSON object
  7158. *
  7159. * @param {Polygon}
  7160. * polygon Polygon to convert.
  7161. *
  7162. * @return {Array} Array with shell, holes.
  7163. */
  7164. Polygon: function (polygon) {
  7165. var this$1 = this;
  7166. var array = [];
  7167. var shellGeoJson = extract.LineString.apply(this, [polygon._shell]);
  7168. array.push(shellGeoJson.coordinates);
  7169. for (var i = 0; i < polygon._holes.length; ++i) {
  7170. var hole = polygon._holes[i];
  7171. var holeGeoJson = extract.LineString.apply(this$1, [hole]);
  7172. array.push(holeGeoJson.coordinates);
  7173. }
  7174. return {
  7175. type: 'Polygon',
  7176. coordinates: array
  7177. }
  7178. },
  7179. /**
  7180. * Convert a MultiPolygon to a GeoJSON object
  7181. *
  7182. * @param {MultiPolygon}
  7183. * multipolygon MultiPolygon to convert.
  7184. *
  7185. * @return {Array} Array of polygons.
  7186. */
  7187. MultiPolygon: function (multipolygon) {
  7188. var this$1 = this;
  7189. var array = [];
  7190. for (var i = 0; i < multipolygon._geometries.length; ++i) {
  7191. var polygon = multipolygon._geometries[i];
  7192. var geoJson = extract.Polygon.apply(this$1, [polygon]);
  7193. array.push(geoJson.coordinates);
  7194. }
  7195. return {
  7196. type: 'MultiPolygon',
  7197. coordinates: array
  7198. }
  7199. },
  7200. /**
  7201. * Convert a GeometryCollection to a GeoJSON object
  7202. *
  7203. * @param {GeometryCollection}
  7204. * collection GeometryCollection to convert.
  7205. *
  7206. * @return {Array} Array of geometries.
  7207. */
  7208. GeometryCollection: function (collection) {
  7209. var this$1 = this;
  7210. var array = [];
  7211. for (var i = 0; i < collection._geometries.length; ++i) {
  7212. var geometry = collection._geometries[i];
  7213. var type = geometry.getGeometryType();
  7214. array.push(extract[type].apply(this$1, [geometry]));
  7215. }
  7216. return {
  7217. type: 'GeometryCollection',
  7218. geometries: array
  7219. }
  7220. }
  7221. };
  7222. /**
  7223. * Converts a geometry in GeoJSON to a {@link Geometry}.
  7224. */
  7225. /**
  7226. * A <code>GeoJSONReader</code> is parameterized by a <code>GeometryFactory</code>,
  7227. * to allow it to create <code>Geometry</code> objects of the appropriate
  7228. * implementation. In particular, the <code>GeometryFactory</code> determines
  7229. * the <code>PrecisionModel</code> and <code>SRID</code> that is used.
  7230. *
  7231. * @param {GeometryFactory} geometryFactory
  7232. * @constructor
  7233. */
  7234. var GeoJSONReader = function GeoJSONReader (geometryFactory) {
  7235. this.geometryFactory = geometryFactory || new GeometryFactory();
  7236. this.precisionModel = this.geometryFactory.getPrecisionModel();
  7237. this.parser = new GeoJSONParser(this.geometryFactory);
  7238. };
  7239. /**
  7240. * Reads a GeoJSON representation of a {@link Geometry}
  7241. *
  7242. * Will also parse GeoJSON Features/FeatureCollections as custom objects.
  7243. *
  7244. * @param {Object|String} geoJson a GeoJSON Object or String.
  7245. * @return {Geometry|Object} a <code>Geometry or Feature/FeatureCollection representation.</code>
  7246. * @memberof GeoJSONReader
  7247. */
  7248. GeoJSONReader.prototype.read = function read (geoJson) {
  7249. var geometry = this.parser.read(geoJson);
  7250. if (this.precisionModel.getType() === PrecisionModel.FIXED) {
  7251. this.reducePrecision(geometry);
  7252. }
  7253. return geometry
  7254. };
  7255. // NOTE: this is a hack
  7256. GeoJSONReader.prototype.reducePrecision = function reducePrecision (geometry) {
  7257. var this$1 = this;
  7258. var i, len;
  7259. if (geometry.coordinate) {
  7260. this.precisionModel.makePrecise(geometry.coordinate);
  7261. } else if (geometry.points) {
  7262. for (i = 0, len = geometry.points.length; i < len; i++) {
  7263. this$1.precisionModel.makePrecise(geometry.points[i]);
  7264. }
  7265. } else if (geometry.geometries) {
  7266. for (i = 0, len = geometry.geometries.length; i < len; i++) {
  7267. this$1.reducePrecision(geometry.geometries[i]);
  7268. }
  7269. }
  7270. };
  7271. /**
  7272. * @module GeoJSONWriter
  7273. */
  7274. /**
  7275. * Writes the GeoJSON representation of a {@link Geometry}. The
  7276. * The GeoJSON format is defined <A
  7277. * HREF="http://geojson.org/geojson-spec.html">here</A>.
  7278. */
  7279. /**
  7280. * The <code>GeoJSONWriter</code> outputs coordinates rounded to the precision
  7281. * model. Only the maximum number of decimal places necessary to represent the
  7282. * ordinates to the required precision will be output.
  7283. *
  7284. * @param {GeometryFactory} geometryFactory
  7285. * @constructor
  7286. */
  7287. var GeoJSONWriter = function GeoJSONWriter () {
  7288. this.parser = new GeoJSONParser(this.geometryFactory);
  7289. };
  7290. /**
  7291. * Converts a <code>Geometry</code> to its GeoJSON representation.
  7292. *
  7293. * @param {Geometry}
  7294. * geometry a <code>Geometry</code> to process.
  7295. * @return {Object} The GeoJSON representation of the Geometry.
  7296. * @memberof GeoJSONWriter
  7297. */
  7298. GeoJSONWriter.prototype.write = function write (geometry) {
  7299. return this.parser.write(geometry)
  7300. };
  7301. /* eslint-disable no-undef */
  7302. // io
  7303. var Position = function Position () {};
  7304. var staticAccessors$20 = { ON: { configurable: true },LEFT: { configurable: true },RIGHT: { configurable: true } };
  7305. Position.prototype.interfaces_ = function interfaces_ () {
  7306. return []
  7307. };
  7308. Position.prototype.getClass = function getClass () {
  7309. return Position
  7310. };
  7311. Position.opposite = function opposite (position) {
  7312. if (position === Position.LEFT) { return Position.RIGHT }
  7313. if (position === Position.RIGHT) { return Position.LEFT }
  7314. return position
  7315. };
  7316. staticAccessors$20.ON.get = function () { return 0 };
  7317. staticAccessors$20.LEFT.get = function () { return 1 };
  7318. staticAccessors$20.RIGHT.get = function () { return 2 };
  7319. Object.defineProperties( Position, staticAccessors$20 );
  7320. /**
  7321. * @param {string=} message Optional message
  7322. * @extends {Error}
  7323. * @constructor
  7324. * @private
  7325. */
  7326. function EmptyStackException (message) {
  7327. this.message = message || '';
  7328. }
  7329. EmptyStackException.prototype = new Error();
  7330. /**
  7331. * @type {string}
  7332. */
  7333. EmptyStackException.prototype.name = 'EmptyStackException';
  7334. /**
  7335. * @see http://download.oracle.com/javase/6/docs/api/java/util/Stack.html
  7336. *
  7337. * @extends {List}
  7338. * @constructor
  7339. * @private
  7340. */
  7341. function Stack () {
  7342. /**
  7343. * @type {Array}
  7344. * @private
  7345. */
  7346. this.array_ = [];
  7347. }
  7348. Stack.prototype = new List();
  7349. /**
  7350. * @override
  7351. */
  7352. Stack.prototype.add = function (e) {
  7353. this.array_.push(e);
  7354. return true
  7355. };
  7356. /**
  7357. * @override
  7358. */
  7359. Stack.prototype.get = function (index) {
  7360. if (index < 0 || index >= this.size()) {
  7361. throw new Error()
  7362. }
  7363. return this.array_[index]
  7364. };
  7365. /**
  7366. * Pushes an item onto the top of this stack.
  7367. * @param {Object} e
  7368. * @return {Object}
  7369. */
  7370. Stack.prototype.push = function (e) {
  7371. this.array_.push(e);
  7372. return e
  7373. };
  7374. /**
  7375. * Pushes an item onto the top of this stack.
  7376. * @param {Object} e
  7377. * @return {Object}
  7378. */
  7379. Stack.prototype.pop = function (e) {
  7380. if (this.array_.length === 0) {
  7381. throw new EmptyStackException()
  7382. }
  7383. return this.array_.pop()
  7384. };
  7385. /**
  7386. * Looks at the object at the top of this stack without removing it from the
  7387. * stack.
  7388. * @return {Object}
  7389. */
  7390. Stack.prototype.peek = function () {
  7391. if (this.array_.length === 0) {
  7392. throw new EmptyStackException()
  7393. }
  7394. return this.array_[this.array_.length - 1]
  7395. };
  7396. /**
  7397. * Tests if this stack is empty.
  7398. * @return {boolean} true if and only if this stack contains no items; false
  7399. * otherwise.
  7400. */
  7401. Stack.prototype.empty = function () {
  7402. if (this.array_.length === 0) {
  7403. return true
  7404. } else {
  7405. return false
  7406. }
  7407. };
  7408. /**
  7409. * @return {boolean}
  7410. */
  7411. Stack.prototype.isEmpty = function () {
  7412. return this.empty()
  7413. };
  7414. /**
  7415. * Returns the 1-based position where an object is on this stack. If the object
  7416. * o occurs as an item in this stack, this method returns the distance from the
  7417. * top of the stack of the occurrence nearest the top of the stack; the topmost
  7418. * item on the stack is considered to be at distance 1. The equals method is
  7419. * used to compare o to the items in this stack.
  7420. *
  7421. * NOTE: does not currently actually use equals. (=== is used)
  7422. *
  7423. * @param {Object} o
  7424. * @return {number} the 1-based position from the top of the stack where the
  7425. * object is located; the return value -1 indicates that the object is
  7426. * not on the stack.
  7427. */
  7428. Stack.prototype.search = function (o) {
  7429. return this.array_.indexOf(o)
  7430. };
  7431. /**
  7432. * @return {number}
  7433. * @export
  7434. */
  7435. Stack.prototype.size = function () {
  7436. return this.array_.length
  7437. };
  7438. /**
  7439. * @return {Array}
  7440. */
  7441. Stack.prototype.toArray = function () {
  7442. var this$1 = this;
  7443. var array = [];
  7444. for (var i = 0, len = this.array_.length; i < len; i++) {
  7445. array.push(this$1.array_[i]);
  7446. }
  7447. return array
  7448. };
  7449. var RightmostEdgeFinder = function RightmostEdgeFinder () {
  7450. this._minIndex = -1;
  7451. this._minCoord = null;
  7452. this._minDe = null;
  7453. this._orientedDe = null;
  7454. };
  7455. RightmostEdgeFinder.prototype.getCoordinate = function getCoordinate () {
  7456. return this._minCoord
  7457. };
  7458. RightmostEdgeFinder.prototype.getRightmostSide = function getRightmostSide (de, index) {
  7459. var side = this.getRightmostSideOfSegment(de, index);
  7460. if (side < 0) { side = this.getRightmostSideOfSegment(de, index - 1); }
  7461. if (side < 0) {
  7462. this._minCoord = null;
  7463. this.checkForRightmostCoordinate(de);
  7464. }
  7465. return side
  7466. };
  7467. RightmostEdgeFinder.prototype.findRightmostEdgeAtVertex = function findRightmostEdgeAtVertex () {
  7468. var pts = this._minDe.getEdge().getCoordinates();
  7469. Assert.isTrue(this._minIndex > 0 && this._minIndex < pts.length, 'rightmost point expected to be interior vertex of edge');
  7470. var pPrev = pts[this._minIndex - 1];
  7471. var pNext = pts[this._minIndex + 1];
  7472. var orientation = CGAlgorithms.computeOrientation(this._minCoord, pNext, pPrev);
  7473. var usePrev = false;
  7474. if (pPrev.y < this._minCoord.y && pNext.y < this._minCoord.y && orientation === CGAlgorithms.COUNTERCLOCKWISE) {
  7475. usePrev = true;
  7476. } else if (pPrev.y > this._minCoord.y && pNext.y > this._minCoord.y && orientation === CGAlgorithms.CLOCKWISE) {
  7477. usePrev = true;
  7478. }
  7479. if (usePrev) {
  7480. this._minIndex = this._minIndex - 1;
  7481. }
  7482. };
  7483. RightmostEdgeFinder.prototype.getRightmostSideOfSegment = function getRightmostSideOfSegment (de, i) {
  7484. var e = de.getEdge();
  7485. var coord = e.getCoordinates();
  7486. if (i < 0 || i + 1 >= coord.length) { return -1 }
  7487. if (coord[i].y === coord[i + 1].y) { return -1 }
  7488. var pos = Position.LEFT;
  7489. if (coord[i].y < coord[i + 1].y) { pos = Position.RIGHT; }
  7490. return pos
  7491. };
  7492. RightmostEdgeFinder.prototype.getEdge = function getEdge () {
  7493. return this._orientedDe
  7494. };
  7495. RightmostEdgeFinder.prototype.checkForRightmostCoordinate = function checkForRightmostCoordinate (de) {
  7496. var this$1 = this;
  7497. var coord = de.getEdge().getCoordinates();
  7498. for (var i = 0; i < coord.length - 1; i++) {
  7499. if (this$1._minCoord === null || coord[i].x > this$1._minCoord.x) {
  7500. this$1._minDe = de;
  7501. this$1._minIndex = i;
  7502. this$1._minCoord = coord[i];
  7503. }
  7504. }
  7505. };
  7506. RightmostEdgeFinder.prototype.findRightmostEdgeAtNode = function findRightmostEdgeAtNode () {
  7507. var node = this._minDe.getNode();
  7508. var star = node.getEdges();
  7509. this._minDe = star.getRightmostEdge();
  7510. if (!this._minDe.isForward()) {
  7511. this._minDe = this._minDe.getSym();
  7512. this._minIndex = this._minDe.getEdge().getCoordinates().length - 1;
  7513. }
  7514. };
  7515. RightmostEdgeFinder.prototype.findEdge = function findEdge (dirEdgeList) {
  7516. var this$1 = this;
  7517. for (var i = dirEdgeList.iterator(); i.hasNext();) {
  7518. var de = i.next();
  7519. if (!de.isForward()) { continue }
  7520. this$1.checkForRightmostCoordinate(de);
  7521. }
  7522. Assert.isTrue(this._minIndex !== 0 || this._minCoord.equals(this._minDe.getCoordinate()), 'inconsistency in rightmost processing');
  7523. if (this._minIndex === 0) {
  7524. this.findRightmostEdgeAtNode();
  7525. } else {
  7526. this.findRightmostEdgeAtVertex();
  7527. }
  7528. this._orientedDe = this._minDe;
  7529. var rightmostSide = this.getRightmostSide(this._minDe, this._minIndex);
  7530. if (rightmostSide === Position.LEFT) {
  7531. this._orientedDe = this._minDe.getSym();
  7532. }
  7533. };
  7534. RightmostEdgeFinder.prototype.interfaces_ = function interfaces_ () {
  7535. return []
  7536. };
  7537. RightmostEdgeFinder.prototype.getClass = function getClass () {
  7538. return RightmostEdgeFinder
  7539. };
  7540. var TopologyException = (function (RuntimeException$$1) {
  7541. function TopologyException (msg, pt) {
  7542. RuntimeException$$1.call(this, TopologyException.msgWithCoord(msg, pt));
  7543. this.pt = pt ? new Coordinate(pt) : null;
  7544. this.name = 'TopologyException';
  7545. }
  7546. if ( RuntimeException$$1 ) TopologyException.__proto__ = RuntimeException$$1;
  7547. TopologyException.prototype = Object.create( RuntimeException$$1 && RuntimeException$$1.prototype );
  7548. TopologyException.prototype.constructor = TopologyException;
  7549. TopologyException.prototype.getCoordinate = function getCoordinate () {
  7550. return this.pt
  7551. };
  7552. TopologyException.prototype.interfaces_ = function interfaces_ () {
  7553. return []
  7554. };
  7555. TopologyException.prototype.getClass = function getClass () {
  7556. return TopologyException
  7557. };
  7558. TopologyException.msgWithCoord = function msgWithCoord (msg, pt) {
  7559. if (!pt) { return msg + ' [ ' + pt + ' ]' }
  7560. return msg
  7561. };
  7562. return TopologyException;
  7563. }(RuntimeException));
  7564. var LinkedList = function LinkedList () {
  7565. this.array_ = [];
  7566. };
  7567. LinkedList.prototype.addLast = function addLast (e) {
  7568. this.array_.push(e);
  7569. };
  7570. LinkedList.prototype.removeFirst = function removeFirst () {
  7571. return this.array_.shift()
  7572. };
  7573. LinkedList.prototype.isEmpty = function isEmpty () {
  7574. return this.array_.length === 0
  7575. };
  7576. var BufferSubgraph = function BufferSubgraph () {
  7577. this._finder = null;
  7578. this._dirEdgeList = new ArrayList();
  7579. this._nodes = new ArrayList();
  7580. this._rightMostCoord = null;
  7581. this._env = null;
  7582. this._finder = new RightmostEdgeFinder();
  7583. };
  7584. BufferSubgraph.prototype.clearVisitedEdges = function clearVisitedEdges () {
  7585. for (var it = this._dirEdgeList.iterator(); it.hasNext();) {
  7586. var de = it.next();
  7587. de.setVisited(false);
  7588. }
  7589. };
  7590. BufferSubgraph.prototype.getRightmostCoordinate = function getRightmostCoordinate () {
  7591. return this._rightMostCoord
  7592. };
  7593. BufferSubgraph.prototype.computeNodeDepth = function computeNodeDepth (n) {
  7594. var this$1 = this;
  7595. var startEdge = null;
  7596. for (var i = n.getEdges().iterator(); i.hasNext();) {
  7597. var de = i.next();
  7598. if (de.isVisited() || de.getSym().isVisited()) {
  7599. startEdge = de;
  7600. break
  7601. }
  7602. }
  7603. if (startEdge === null) { throw new TopologyException('unable to find edge to compute depths at ' + n.getCoordinate()) }
  7604. n.getEdges().computeDepths(startEdge);
  7605. for (var i$1 = n.getEdges().iterator(); i$1.hasNext();) {
  7606. var de$1 = i$1.next();
  7607. de$1.setVisited(true);
  7608. this$1.copySymDepths(de$1);
  7609. }
  7610. };
  7611. BufferSubgraph.prototype.computeDepth = function computeDepth (outsideDepth) {
  7612. this.clearVisitedEdges();
  7613. var de = this._finder.getEdge();
  7614. // const n = de.getNode()
  7615. // const label = de.getLabel()
  7616. de.setEdgeDepths(Position.RIGHT, outsideDepth);
  7617. this.copySymDepths(de);
  7618. this.computeDepths(de);
  7619. };
  7620. BufferSubgraph.prototype.create = function create (node) {
  7621. this.addReachable(node);
  7622. this._finder.findEdge(this._dirEdgeList);
  7623. this._rightMostCoord = this._finder.getCoordinate();
  7624. };
  7625. BufferSubgraph.prototype.findResultEdges = function findResultEdges () {
  7626. for (var it = this._dirEdgeList.iterator(); it.hasNext();) {
  7627. var de = it.next();
  7628. if (de.getDepth(Position.RIGHT) >= 1 && de.getDepth(Position.LEFT) <= 0 && !de.isInteriorAreaEdge()) {
  7629. de.setInResult(true);
  7630. }
  7631. }
  7632. };
  7633. BufferSubgraph.prototype.computeDepths = function computeDepths (startEdge) {
  7634. var this$1 = this;
  7635. var nodesVisited = new HashSet();
  7636. var nodeQueue = new LinkedList();
  7637. var startNode = startEdge.getNode();
  7638. nodeQueue.addLast(startNode);
  7639. nodesVisited.add(startNode);
  7640. startEdge.setVisited(true);
  7641. while (!nodeQueue.isEmpty()) {
  7642. var n = nodeQueue.removeFirst();
  7643. nodesVisited.add(n);
  7644. this$1.computeNodeDepth(n);
  7645. for (var i = n.getEdges().iterator(); i.hasNext();) {
  7646. var de = i.next();
  7647. var sym = de.getSym();
  7648. if (sym.isVisited()) { continue }
  7649. var adjNode = sym.getNode();
  7650. if (!nodesVisited.contains(adjNode)) {
  7651. nodeQueue.addLast(adjNode);
  7652. nodesVisited.add(adjNode);
  7653. }
  7654. }
  7655. }
  7656. };
  7657. BufferSubgraph.prototype.compareTo = function compareTo (o) {
  7658. var graph = o;
  7659. if (this._rightMostCoord.x < graph._rightMostCoord.x) {
  7660. return -1
  7661. }
  7662. if (this._rightMostCoord.x > graph._rightMostCoord.x) {
  7663. return 1
  7664. }
  7665. return 0
  7666. };
  7667. BufferSubgraph.prototype.getEnvelope = function getEnvelope () {
  7668. if (this._env === null) {
  7669. var edgeEnv = new Envelope();
  7670. for (var it = this._dirEdgeList.iterator(); it.hasNext();) {
  7671. var dirEdge = it.next();
  7672. var pts = dirEdge.getEdge().getCoordinates();
  7673. for (var i = 0; i < pts.length - 1; i++) {
  7674. edgeEnv.expandToInclude(pts[i]);
  7675. }
  7676. }
  7677. this._env = edgeEnv;
  7678. }
  7679. return this._env
  7680. };
  7681. BufferSubgraph.prototype.addReachable = function addReachable (startNode) {
  7682. var this$1 = this;
  7683. var nodeStack = new Stack();
  7684. nodeStack.add(startNode);
  7685. while (!nodeStack.empty()) {
  7686. var node = nodeStack.pop();
  7687. this$1.add(node, nodeStack);
  7688. }
  7689. };
  7690. BufferSubgraph.prototype.copySymDepths = function copySymDepths (de) {
  7691. var sym = de.getSym();
  7692. sym.setDepth(Position.LEFT, de.getDepth(Position.RIGHT));
  7693. sym.setDepth(Position.RIGHT, de.getDepth(Position.LEFT));
  7694. };
  7695. BufferSubgraph.prototype.add = function add (node, nodeStack) {
  7696. var this$1 = this;
  7697. node.setVisited(true);
  7698. this._nodes.add(node);
  7699. for (var i = node.getEdges().iterator(); i.hasNext();) {
  7700. var de = i.next();
  7701. this$1._dirEdgeList.add(de);
  7702. var sym = de.getSym();
  7703. var symNode = sym.getNode();
  7704. if (!symNode.isVisited()) { nodeStack.push(symNode); }
  7705. }
  7706. };
  7707. BufferSubgraph.prototype.getNodes = function getNodes () {
  7708. return this._nodes
  7709. };
  7710. BufferSubgraph.prototype.getDirectedEdges = function getDirectedEdges () {
  7711. return this._dirEdgeList
  7712. };
  7713. BufferSubgraph.prototype.interfaces_ = function interfaces_ () {
  7714. return [Comparable]
  7715. };
  7716. BufferSubgraph.prototype.getClass = function getClass () {
  7717. return BufferSubgraph
  7718. };
  7719. var TopologyLocation = function TopologyLocation () {
  7720. var this$1 = this;
  7721. this.location = null;
  7722. if (arguments.length === 1) {
  7723. if (arguments[0] instanceof Array) {
  7724. var location = arguments[0];
  7725. this.init(location.length);
  7726. } else if (Number.isInteger(arguments[0])) {
  7727. var on = arguments[0];
  7728. this.init(1);
  7729. this.location[Position.ON] = on;
  7730. } else if (arguments[0] instanceof TopologyLocation) {
  7731. var gl = arguments[0];
  7732. this.init(gl.location.length);
  7733. if (gl !== null) {
  7734. for (var i = 0; i < this.location.length; i++) {
  7735. this$1.location[i] = gl.location[i];
  7736. }
  7737. }
  7738. }
  7739. } else if (arguments.length === 3) {
  7740. var on$1 = arguments[0];
  7741. var left = arguments[1];
  7742. var right = arguments[2];
  7743. this.init(3);
  7744. this.location[Position.ON] = on$1;
  7745. this.location[Position.LEFT] = left;
  7746. this.location[Position.RIGHT] = right;
  7747. }
  7748. };
  7749. TopologyLocation.prototype.setAllLocations = function setAllLocations (locValue) {
  7750. var this$1 = this;
  7751. for (var i = 0; i < this.location.length; i++) {
  7752. this$1.location[i] = locValue;
  7753. }
  7754. };
  7755. TopologyLocation.prototype.isNull = function isNull () {
  7756. var this$1 = this;
  7757. for (var i = 0; i < this.location.length; i++) {
  7758. if (this$1.location[i] !== Location.NONE) { return false }
  7759. }
  7760. return true
  7761. };
  7762. TopologyLocation.prototype.setAllLocationsIfNull = function setAllLocationsIfNull (locValue) {
  7763. var this$1 = this;
  7764. for (var i = 0; i < this.location.length; i++) {
  7765. if (this$1.location[i] === Location.NONE) { this$1.location[i] = locValue; }
  7766. }
  7767. };
  7768. TopologyLocation.prototype.isLine = function isLine () {
  7769. return this.location.length === 1
  7770. };
  7771. TopologyLocation.prototype.merge = function merge (gl) {
  7772. var this$1 = this;
  7773. if (gl.location.length > this.location.length) {
  7774. var newLoc = new Array(3).fill(null);
  7775. newLoc[Position.ON] = this.location[Position.ON];
  7776. newLoc[Position.LEFT] = Location.NONE;
  7777. newLoc[Position.RIGHT] = Location.NONE;
  7778. this.location = newLoc;
  7779. }
  7780. for (var i = 0; i < this.location.length; i++) {
  7781. if (this$1.location[i] === Location.NONE && i < gl.location.length) { this$1.location[i] = gl.location[i]; }
  7782. }
  7783. };
  7784. TopologyLocation.prototype.getLocations = function getLocations () {
  7785. return this.location
  7786. };
  7787. TopologyLocation.prototype.flip = function flip () {
  7788. if (this.location.length <= 1) { return null }
  7789. var temp = this.location[Position.LEFT];
  7790. this.location[Position.LEFT] = this.location[Position.RIGHT];
  7791. this.location[Position.RIGHT] = temp;
  7792. };
  7793. TopologyLocation.prototype.toString = function toString () {
  7794. var buf = new StringBuffer();
  7795. if (this.location.length > 1) { buf.append(Location.toLocationSymbol(this.location[Position.LEFT])); }
  7796. buf.append(Location.toLocationSymbol(this.location[Position.ON]));
  7797. if (this.location.length > 1) { buf.append(Location.toLocationSymbol(this.location[Position.RIGHT])); }
  7798. return buf.toString()
  7799. };
  7800. TopologyLocation.prototype.setLocations = function setLocations (on, left, right) {
  7801. this.location[Position.ON] = on;
  7802. this.location[Position.LEFT] = left;
  7803. this.location[Position.RIGHT] = right;
  7804. };
  7805. TopologyLocation.prototype.get = function get (posIndex) {
  7806. if (posIndex < this.location.length) { return this.location[posIndex] }
  7807. return Location.NONE
  7808. };
  7809. TopologyLocation.prototype.isArea = function isArea () {
  7810. return this.location.length > 1
  7811. };
  7812. TopologyLocation.prototype.isAnyNull = function isAnyNull () {
  7813. var this$1 = this;
  7814. for (var i = 0; i < this.location.length; i++) {
  7815. if (this$1.location[i] === Location.NONE) { return true }
  7816. }
  7817. return false
  7818. };
  7819. TopologyLocation.prototype.setLocation = function setLocation () {
  7820. if (arguments.length === 1) {
  7821. var locValue = arguments[0];
  7822. this.setLocation(Position.ON, locValue);
  7823. } else if (arguments.length === 2) {
  7824. var locIndex = arguments[0];
  7825. var locValue$1 = arguments[1];
  7826. this.location[locIndex] = locValue$1;
  7827. }
  7828. };
  7829. TopologyLocation.prototype.init = function init (size) {
  7830. this.location = new Array(size).fill(null);
  7831. this.setAllLocations(Location.NONE);
  7832. };
  7833. TopologyLocation.prototype.isEqualOnSide = function isEqualOnSide (le, locIndex) {
  7834. return this.location[locIndex] === le.location[locIndex]
  7835. };
  7836. TopologyLocation.prototype.allPositionsEqual = function allPositionsEqual (loc) {
  7837. var this$1 = this;
  7838. for (var i = 0; i < this.location.length; i++) {
  7839. if (this$1.location[i] !== loc) { return false }
  7840. }
  7841. return true
  7842. };
  7843. TopologyLocation.prototype.interfaces_ = function interfaces_ () {
  7844. return []
  7845. };
  7846. TopologyLocation.prototype.getClass = function getClass () {
  7847. return TopologyLocation
  7848. };
  7849. var Label = function Label () {
  7850. this.elt = new Array(2).fill(null);
  7851. if (arguments.length === 1) {
  7852. if (Number.isInteger(arguments[0])) {
  7853. var onLoc = arguments[0];
  7854. this.elt[0] = new TopologyLocation(onLoc);
  7855. this.elt[1] = new TopologyLocation(onLoc);
  7856. } else if (arguments[0] instanceof Label) {
  7857. var lbl = arguments[0];
  7858. this.elt[0] = new TopologyLocation(lbl.elt[0]);
  7859. this.elt[1] = new TopologyLocation(lbl.elt[1]);
  7860. }
  7861. } else if (arguments.length === 2) {
  7862. var geomIndex = arguments[0];
  7863. var onLoc$1 = arguments[1];
  7864. this.elt[0] = new TopologyLocation(Location.NONE);
  7865. this.elt[1] = new TopologyLocation(Location.NONE);
  7866. this.elt[geomIndex].setLocation(onLoc$1);
  7867. } else if (arguments.length === 3) {
  7868. var onLoc$2 = arguments[0];
  7869. var leftLoc = arguments[1];
  7870. var rightLoc = arguments[2];
  7871. this.elt[0] = new TopologyLocation(onLoc$2, leftLoc, rightLoc);
  7872. this.elt[1] = new TopologyLocation(onLoc$2, leftLoc, rightLoc);
  7873. } else if (arguments.length === 4) {
  7874. var geomIndex$1 = arguments[0];
  7875. var onLoc$3 = arguments[1];
  7876. var leftLoc$1 = arguments[2];
  7877. var rightLoc$1 = arguments[3];
  7878. this.elt[0] = new TopologyLocation(Location.NONE, Location.NONE, Location.NONE);
  7879. this.elt[1] = new TopologyLocation(Location.NONE, Location.NONE, Location.NONE);
  7880. this.elt[geomIndex$1].setLocations(onLoc$3, leftLoc$1, rightLoc$1);
  7881. }
  7882. };
  7883. Label.prototype.getGeometryCount = function getGeometryCount () {
  7884. var count = 0;
  7885. if (!this.elt[0].isNull()) { count++; }
  7886. if (!this.elt[1].isNull()) { count++; }
  7887. return count
  7888. };
  7889. Label.prototype.setAllLocations = function setAllLocations (geomIndex, location) {
  7890. this.elt[geomIndex].setAllLocations(location);
  7891. };
  7892. Label.prototype.isNull = function isNull (geomIndex) {
  7893. return this.elt[geomIndex].isNull()
  7894. };
  7895. Label.prototype.setAllLocationsIfNull = function setAllLocationsIfNull () {
  7896. if (arguments.length === 1) {
  7897. var location = arguments[0];
  7898. this.setAllLocationsIfNull(0, location);
  7899. this.setAllLocationsIfNull(1, location);
  7900. } else if (arguments.length === 2) {
  7901. var geomIndex = arguments[0];
  7902. var location$1 = arguments[1];
  7903. this.elt[geomIndex].setAllLocationsIfNull(location$1);
  7904. }
  7905. };
  7906. Label.prototype.isLine = function isLine (geomIndex) {
  7907. return this.elt[geomIndex].isLine()
  7908. };
  7909. Label.prototype.merge = function merge (lbl) {
  7910. var this$1 = this;
  7911. for (var i = 0; i < 2; i++) {
  7912. if (this$1.elt[i] === null && lbl.elt[i] !== null) {
  7913. this$1.elt[i] = new TopologyLocation(lbl.elt[i]);
  7914. } else {
  7915. this$1.elt[i].merge(lbl.elt[i]);
  7916. }
  7917. }
  7918. };
  7919. Label.prototype.flip = function flip () {
  7920. this.elt[0].flip();
  7921. this.elt[1].flip();
  7922. };
  7923. Label.prototype.getLocation = function getLocation () {
  7924. if (arguments.length === 1) {
  7925. var geomIndex = arguments[0];
  7926. return this.elt[geomIndex].get(Position.ON)
  7927. } else if (arguments.length === 2) {
  7928. var geomIndex$1 = arguments[0];
  7929. var posIndex = arguments[1];
  7930. return this.elt[geomIndex$1].get(posIndex)
  7931. }
  7932. };
  7933. Label.prototype.toString = function toString () {
  7934. var buf = new StringBuffer();
  7935. if (this.elt[0] !== null) {
  7936. buf.append('A:');
  7937. buf.append(this.elt[0].toString());
  7938. }
  7939. if (this.elt[1] !== null) {
  7940. buf.append(' B:');
  7941. buf.append(this.elt[1].toString());
  7942. }
  7943. return buf.toString()
  7944. };
  7945. Label.prototype.isArea = function isArea () {
  7946. if (arguments.length === 0) {
  7947. return this.elt[0].isArea() || this.elt[1].isArea()
  7948. } else if (arguments.length === 1) {
  7949. var geomIndex = arguments[0];
  7950. return this.elt[geomIndex].isArea()
  7951. }
  7952. };
  7953. Label.prototype.isAnyNull = function isAnyNull (geomIndex) {
  7954. return this.elt[geomIndex].isAnyNull()
  7955. };
  7956. Label.prototype.setLocation = function setLocation () {
  7957. if (arguments.length === 2) {
  7958. var geomIndex = arguments[0];
  7959. var location = arguments[1];
  7960. this.elt[geomIndex].setLocation(Position.ON, location);
  7961. } else if (arguments.length === 3) {
  7962. var geomIndex$1 = arguments[0];
  7963. var posIndex = arguments[1];
  7964. var location$1 = arguments[2];
  7965. this.elt[geomIndex$1].setLocation(posIndex, location$1);
  7966. }
  7967. };
  7968. Label.prototype.isEqualOnSide = function isEqualOnSide (lbl, side) {
  7969. return this.elt[0].isEqualOnSide(lbl.elt[0], side) && this.elt[1].isEqualOnSide(lbl.elt[1], side)
  7970. };
  7971. Label.prototype.allPositionsEqual = function allPositionsEqual (geomIndex, loc) {
  7972. return this.elt[geomIndex].allPositionsEqual(loc)
  7973. };
  7974. Label.prototype.toLine = function toLine (geomIndex) {
  7975. if (this.elt[geomIndex].isArea()) { this.elt[geomIndex] = new TopologyLocation(this.elt[geomIndex].location[0]); }
  7976. };
  7977. Label.prototype.interfaces_ = function interfaces_ () {
  7978. return []
  7979. };
  7980. Label.prototype.getClass = function getClass () {
  7981. return Label
  7982. };
  7983. Label.toLineLabel = function toLineLabel (label) {
  7984. var lineLabel = new Label(Location.NONE);
  7985. for (var i = 0; i < 2; i++) {
  7986. lineLabel.setLocation(i, label.getLocation(i));
  7987. }
  7988. return lineLabel
  7989. };
  7990. var EdgeRing = function EdgeRing () {
  7991. this._startDe = null;
  7992. this._maxNodeDegree = -1;
  7993. this._edges = new ArrayList();
  7994. this._pts = new ArrayList();
  7995. this._label = new Label(Location.NONE);
  7996. this._ring = null;
  7997. this._isHole = null;
  7998. this._shell = null;
  7999. this._holes = new ArrayList();
  8000. this._geometryFactory = null;
  8001. var start = arguments[0];
  8002. var geometryFactory = arguments[1];
  8003. this._geometryFactory = geometryFactory;
  8004. this.computePoints(start);
  8005. this.computeRing();
  8006. };
  8007. EdgeRing.prototype.computeRing = function computeRing () {
  8008. var this$1 = this;
  8009. if (this._ring !== null) { return null }
  8010. var coord = new Array(this._pts.size()).fill(null);
  8011. for (var i = 0; i < this._pts.size(); i++) {
  8012. coord[i] = this$1._pts.get(i);
  8013. }
  8014. this._ring = this._geometryFactory.createLinearRing(coord);
  8015. this._isHole = CGAlgorithms.isCCW(this._ring.getCoordinates());
  8016. };
  8017. EdgeRing.prototype.isIsolated = function isIsolated () {
  8018. return this._label.getGeometryCount() === 1
  8019. };
  8020. EdgeRing.prototype.computePoints = function computePoints (start) {
  8021. var this$1 = this;
  8022. this._startDe = start;
  8023. var de = start;
  8024. var isFirstEdge = true;
  8025. do {
  8026. if (de === null) { throw new TopologyException('Found null DirectedEdge') }
  8027. if (de.getEdgeRing() === this$1) { throw new TopologyException('Directed Edge visited twice during ring-building at ' + de.getCoordinate()) }
  8028. this$1._edges.add(de);
  8029. var label = de.getLabel();
  8030. Assert.isTrue(label.isArea());
  8031. this$1.mergeLabel(label);
  8032. this$1.addPoints(de.getEdge(), de.isForward(), isFirstEdge);
  8033. isFirstEdge = false;
  8034. this$1.setEdgeRing(de, this$1);
  8035. de = this$1.getNext(de);
  8036. } while (de !== this._startDe)
  8037. };
  8038. EdgeRing.prototype.getLinearRing = function getLinearRing () {
  8039. return this._ring
  8040. };
  8041. EdgeRing.prototype.getCoordinate = function getCoordinate (i) {
  8042. return this._pts.get(i)
  8043. };
  8044. EdgeRing.prototype.computeMaxNodeDegree = function computeMaxNodeDegree () {
  8045. var this$1 = this;
  8046. this._maxNodeDegree = 0;
  8047. var de = this._startDe;
  8048. do {
  8049. var node = de.getNode();
  8050. var degree = node.getEdges().getOutgoingDegree(this$1);
  8051. if (degree > this$1._maxNodeDegree) { this$1._maxNodeDegree = degree; }
  8052. de = this$1.getNext(de);
  8053. } while (de !== this._startDe)
  8054. this._maxNodeDegree *= 2;
  8055. };
  8056. EdgeRing.prototype.addPoints = function addPoints (edge, isForward, isFirstEdge) {
  8057. var this$1 = this;
  8058. var edgePts = edge.getCoordinates();
  8059. if (isForward) {
  8060. var startIndex = 1;
  8061. if (isFirstEdge) { startIndex = 0; }
  8062. for (var i = startIndex; i < edgePts.length; i++) {
  8063. this$1._pts.add(edgePts[i]);
  8064. }
  8065. } else {
  8066. var startIndex$1 = edgePts.length - 2;
  8067. if (isFirstEdge) { startIndex$1 = edgePts.length - 1; }
  8068. for (var i$1 = startIndex$1; i$1 >= 0; i$1--) {
  8069. this$1._pts.add(edgePts[i$1]);
  8070. }
  8071. }
  8072. };
  8073. EdgeRing.prototype.isHole = function isHole () {
  8074. return this._isHole
  8075. };
  8076. EdgeRing.prototype.setInResult = function setInResult () {
  8077. var de = this._startDe;
  8078. do {
  8079. de.getEdge().setInResult(true);
  8080. de = de.getNext();
  8081. } while (de !== this._startDe)
  8082. };
  8083. EdgeRing.prototype.containsPoint = function containsPoint (p) {
  8084. var shell = this.getLinearRing();
  8085. var env = shell.getEnvelopeInternal();
  8086. if (!env.contains(p)) { return false }
  8087. if (!CGAlgorithms.isPointInRing(p, shell.getCoordinates())) { return false }
  8088. for (var i = this._holes.iterator(); i.hasNext();) {
  8089. var hole = i.next();
  8090. if (hole.containsPoint(p)) { return false }
  8091. }
  8092. return true
  8093. };
  8094. EdgeRing.prototype.addHole = function addHole (ring) {
  8095. this._holes.add(ring);
  8096. };
  8097. EdgeRing.prototype.isShell = function isShell () {
  8098. return this._shell === null
  8099. };
  8100. EdgeRing.prototype.getLabel = function getLabel () {
  8101. return this._label
  8102. };
  8103. EdgeRing.prototype.getEdges = function getEdges () {
  8104. return this._edges
  8105. };
  8106. EdgeRing.prototype.getMaxNodeDegree = function getMaxNodeDegree () {
  8107. if (this._maxNodeDegree < 0) { this.computeMaxNodeDegree(); }
  8108. return this._maxNodeDegree
  8109. };
  8110. EdgeRing.prototype.getShell = function getShell () {
  8111. return this._shell
  8112. };
  8113. EdgeRing.prototype.mergeLabel = function mergeLabel () {
  8114. if (arguments.length === 1) {
  8115. var deLabel = arguments[0];
  8116. this.mergeLabel(deLabel, 0);
  8117. this.mergeLabel(deLabel, 1);
  8118. } else if (arguments.length === 2) {
  8119. var deLabel$1 = arguments[0];
  8120. var geomIndex = arguments[1];
  8121. var loc = deLabel$1.getLocation(geomIndex, Position.RIGHT);
  8122. if (loc === Location.NONE) { return null }
  8123. if (this._label.getLocation(geomIndex) === Location.NONE) {
  8124. this._label.setLocation(geomIndex, loc);
  8125. return null
  8126. }
  8127. }
  8128. };
  8129. EdgeRing.prototype.setShell = function setShell (shell) {
  8130. this._shell = shell;
  8131. if (shell !== null) { shell.addHole(this); }
  8132. };
  8133. EdgeRing.prototype.toPolygon = function toPolygon (geometryFactory) {
  8134. var this$1 = this;
  8135. var holeLR = new Array(this._holes.size()).fill(null);
  8136. for (var i = 0; i < this._holes.size(); i++) {
  8137. holeLR[i] = this$1._holes.get(i).getLinearRing();
  8138. }
  8139. var poly = geometryFactory.createPolygon(this.getLinearRing(), holeLR);
  8140. return poly
  8141. };
  8142. EdgeRing.prototype.interfaces_ = function interfaces_ () {
  8143. return []
  8144. };
  8145. EdgeRing.prototype.getClass = function getClass () {
  8146. return EdgeRing
  8147. };
  8148. var MinimalEdgeRing = (function (EdgeRing$$1) {
  8149. function MinimalEdgeRing () {
  8150. var start = arguments[0];
  8151. var geometryFactory = arguments[1];
  8152. EdgeRing$$1.call(this, start, geometryFactory);
  8153. }
  8154. if ( EdgeRing$$1 ) MinimalEdgeRing.__proto__ = EdgeRing$$1;
  8155. MinimalEdgeRing.prototype = Object.create( EdgeRing$$1 && EdgeRing$$1.prototype );
  8156. MinimalEdgeRing.prototype.constructor = MinimalEdgeRing;
  8157. MinimalEdgeRing.prototype.setEdgeRing = function setEdgeRing (de, er) {
  8158. de.setMinEdgeRing(er);
  8159. };
  8160. MinimalEdgeRing.prototype.getNext = function getNext (de) {
  8161. return de.getNextMin()
  8162. };
  8163. MinimalEdgeRing.prototype.interfaces_ = function interfaces_ () {
  8164. return []
  8165. };
  8166. MinimalEdgeRing.prototype.getClass = function getClass () {
  8167. return MinimalEdgeRing
  8168. };
  8169. return MinimalEdgeRing;
  8170. }(EdgeRing));
  8171. var MaximalEdgeRing = (function (EdgeRing$$1) {
  8172. function MaximalEdgeRing () {
  8173. var start = arguments[0];
  8174. var geometryFactory = arguments[1];
  8175. EdgeRing$$1.call(this, start, geometryFactory);
  8176. }
  8177. if ( EdgeRing$$1 ) MaximalEdgeRing.__proto__ = EdgeRing$$1;
  8178. MaximalEdgeRing.prototype = Object.create( EdgeRing$$1 && EdgeRing$$1.prototype );
  8179. MaximalEdgeRing.prototype.constructor = MaximalEdgeRing;
  8180. MaximalEdgeRing.prototype.buildMinimalRings = function buildMinimalRings () {
  8181. var this$1 = this;
  8182. var minEdgeRings = new ArrayList();
  8183. var de = this._startDe;
  8184. do {
  8185. if (de.getMinEdgeRing() === null) {
  8186. var minEr = new MinimalEdgeRing(de, this$1._geometryFactory);
  8187. minEdgeRings.add(minEr);
  8188. }
  8189. de = de.getNext();
  8190. } while (de !== this._startDe)
  8191. return minEdgeRings
  8192. };
  8193. MaximalEdgeRing.prototype.setEdgeRing = function setEdgeRing (de, er) {
  8194. de.setEdgeRing(er);
  8195. };
  8196. MaximalEdgeRing.prototype.linkDirectedEdgesForMinimalEdgeRings = function linkDirectedEdgesForMinimalEdgeRings () {
  8197. var this$1 = this;
  8198. var de = this._startDe;
  8199. do {
  8200. var node = de.getNode();
  8201. node.getEdges().linkMinimalDirectedEdges(this$1);
  8202. de = de.getNext();
  8203. } while (de !== this._startDe)
  8204. };
  8205. MaximalEdgeRing.prototype.getNext = function getNext (de) {
  8206. return de.getNext()
  8207. };
  8208. MaximalEdgeRing.prototype.interfaces_ = function interfaces_ () {
  8209. return []
  8210. };
  8211. MaximalEdgeRing.prototype.getClass = function getClass () {
  8212. return MaximalEdgeRing
  8213. };
  8214. return MaximalEdgeRing;
  8215. }(EdgeRing));
  8216. var GraphComponent = function GraphComponent () {
  8217. this._label = null;
  8218. this._isInResult = false;
  8219. this._isCovered = false;
  8220. this._isCoveredSet = false;
  8221. this._isVisited = false;
  8222. if (arguments.length === 0) {} else if (arguments.length === 1) {
  8223. var label = arguments[0];
  8224. this._label = label;
  8225. }
  8226. };
  8227. GraphComponent.prototype.setVisited = function setVisited (isVisited) {
  8228. this._isVisited = isVisited;
  8229. };
  8230. GraphComponent.prototype.setInResult = function setInResult (isInResult) {
  8231. this._isInResult = isInResult;
  8232. };
  8233. GraphComponent.prototype.isCovered = function isCovered () {
  8234. return this._isCovered
  8235. };
  8236. GraphComponent.prototype.isCoveredSet = function isCoveredSet () {
  8237. return this._isCoveredSet
  8238. };
  8239. GraphComponent.prototype.setLabel = function setLabel (label) {
  8240. this._label = label;
  8241. };
  8242. GraphComponent.prototype.getLabel = function getLabel () {
  8243. return this._label
  8244. };
  8245. GraphComponent.prototype.setCovered = function setCovered (isCovered) {
  8246. this._isCovered = isCovered;
  8247. this._isCoveredSet = true;
  8248. };
  8249. GraphComponent.prototype.updateIM = function updateIM (im) {
  8250. Assert.isTrue(this._label.getGeometryCount() >= 2, 'found partial label');
  8251. this.computeIM(im);
  8252. };
  8253. GraphComponent.prototype.isInResult = function isInResult () {
  8254. return this._isInResult
  8255. };
  8256. GraphComponent.prototype.isVisited = function isVisited () {
  8257. return this._isVisited
  8258. };
  8259. GraphComponent.prototype.interfaces_ = function interfaces_ () {
  8260. return []
  8261. };
  8262. GraphComponent.prototype.getClass = function getClass () {
  8263. return GraphComponent
  8264. };
  8265. var Node = (function (GraphComponent$$1) {
  8266. function Node () {
  8267. GraphComponent$$1.call(this);
  8268. this._coord = null;
  8269. this._edges = null;
  8270. var coord = arguments[0];
  8271. var edges = arguments[1];
  8272. this._coord = coord;
  8273. this._edges = edges;
  8274. this._label = new Label(0, Location.NONE);
  8275. }
  8276. if ( GraphComponent$$1 ) Node.__proto__ = GraphComponent$$1;
  8277. Node.prototype = Object.create( GraphComponent$$1 && GraphComponent$$1.prototype );
  8278. Node.prototype.constructor = Node;
  8279. Node.prototype.isIncidentEdgeInResult = function isIncidentEdgeInResult () {
  8280. for (var it = this.getEdges().getEdges().iterator(); it.hasNext();) {
  8281. var de = it.next();
  8282. if (de.getEdge().isInResult()) { return true }
  8283. }
  8284. return false
  8285. };
  8286. Node.prototype.isIsolated = function isIsolated () {
  8287. return this._label.getGeometryCount() === 1
  8288. };
  8289. Node.prototype.getCoordinate = function getCoordinate () {
  8290. return this._coord
  8291. };
  8292. Node.prototype.print = function print (out) {
  8293. out.println('node ' + this._coord + ' lbl: ' + this._label);
  8294. };
  8295. Node.prototype.computeIM = function computeIM (im) {};
  8296. Node.prototype.computeMergedLocation = function computeMergedLocation (label2, eltIndex) {
  8297. var loc = Location.NONE;
  8298. loc = this._label.getLocation(eltIndex);
  8299. if (!label2.isNull(eltIndex)) {
  8300. var nLoc = label2.getLocation(eltIndex);
  8301. if (loc !== Location.BOUNDARY) { loc = nLoc; }
  8302. }
  8303. return loc
  8304. };
  8305. Node.prototype.setLabel = function setLabel () {
  8306. if (arguments.length === 2) {
  8307. var argIndex = arguments[0];
  8308. var onLocation = arguments[1];
  8309. if (this._label === null) {
  8310. this._label = new Label(argIndex, onLocation);
  8311. } else { this._label.setLocation(argIndex, onLocation); }
  8312. } else { return GraphComponent$$1.prototype.setLabel.apply(this, arguments) }
  8313. };
  8314. Node.prototype.getEdges = function getEdges () {
  8315. return this._edges
  8316. };
  8317. Node.prototype.mergeLabel = function mergeLabel () {
  8318. var this$1 = this;
  8319. if (arguments[0] instanceof Node) {
  8320. var n = arguments[0];
  8321. this.mergeLabel(n._label);
  8322. } else if (arguments[0] instanceof Label) {
  8323. var label2 = arguments[0];
  8324. for (var i = 0; i < 2; i++) {
  8325. var loc = this$1.computeMergedLocation(label2, i);
  8326. var thisLoc = this$1._label.getLocation(i);
  8327. if (thisLoc === Location.NONE) { this$1._label.setLocation(i, loc); }
  8328. }
  8329. }
  8330. };
  8331. Node.prototype.add = function add (e) {
  8332. this._edges.insert(e);
  8333. e.setNode(this);
  8334. };
  8335. Node.prototype.setLabelBoundary = function setLabelBoundary (argIndex) {
  8336. if (this._label === null) { return null }
  8337. var loc = Location.NONE;
  8338. if (this._label !== null) { loc = this._label.getLocation(argIndex); }
  8339. var newLoc = null;
  8340. switch (loc) {
  8341. case Location.BOUNDARY:
  8342. newLoc = Location.INTERIOR;
  8343. break
  8344. case Location.INTERIOR:
  8345. newLoc = Location.BOUNDARY;
  8346. break
  8347. default:
  8348. newLoc = Location.BOUNDARY;
  8349. break
  8350. }
  8351. this._label.setLocation(argIndex, newLoc);
  8352. };
  8353. Node.prototype.interfaces_ = function interfaces_ () {
  8354. return []
  8355. };
  8356. Node.prototype.getClass = function getClass () {
  8357. return Node
  8358. };
  8359. return Node;
  8360. }(GraphComponent));
  8361. var NodeMap = function NodeMap () {
  8362. this.nodeMap = new TreeMap();
  8363. this.nodeFact = null;
  8364. var nodeFact = arguments[0];
  8365. this.nodeFact = nodeFact;
  8366. };
  8367. NodeMap.prototype.find = function find (coord) {
  8368. return this.nodeMap.get(coord)
  8369. };
  8370. NodeMap.prototype.addNode = function addNode () {
  8371. if (arguments[0] instanceof Coordinate) {
  8372. var coord = arguments[0];
  8373. var node = this.nodeMap.get(coord);
  8374. if (node === null) {
  8375. node = this.nodeFact.createNode(coord);
  8376. this.nodeMap.put(coord, node);
  8377. }
  8378. return node
  8379. } else if (arguments[0] instanceof Node) {
  8380. var n = arguments[0];
  8381. var node$1 = this.nodeMap.get(n.getCoordinate());
  8382. if (node$1 === null) {
  8383. this.nodeMap.put(n.getCoordinate(), n);
  8384. return n
  8385. }
  8386. node$1.mergeLabel(n);
  8387. return node$1
  8388. }
  8389. };
  8390. NodeMap.prototype.print = function print (out) {
  8391. for (var it = this.iterator(); it.hasNext();) {
  8392. var n = it.next();
  8393. n.print(out);
  8394. }
  8395. };
  8396. NodeMap.prototype.iterator = function iterator () {
  8397. return this.nodeMap.values().iterator()
  8398. };
  8399. NodeMap.prototype.values = function values () {
  8400. return this.nodeMap.values()
  8401. };
  8402. NodeMap.prototype.getBoundaryNodes = function getBoundaryNodes (geomIndex) {
  8403. var bdyNodes = new ArrayList();
  8404. for (var i = this.iterator(); i.hasNext();) {
  8405. var node = i.next();
  8406. if (node.getLabel().getLocation(geomIndex) === Location.BOUNDARY) { bdyNodes.add(node); }
  8407. }
  8408. return bdyNodes
  8409. };
  8410. NodeMap.prototype.add = function add (e) {
  8411. var p = e.getCoordinate();
  8412. var n = this.addNode(p);
  8413. n.add(e);
  8414. };
  8415. NodeMap.prototype.interfaces_ = function interfaces_ () {
  8416. return []
  8417. };
  8418. NodeMap.prototype.getClass = function getClass () {
  8419. return NodeMap
  8420. };
  8421. var Quadrant = function Quadrant () {};
  8422. var staticAccessors$21 = { NE: { configurable: true },NW: { configurable: true },SW: { configurable: true },SE: { configurable: true } };
  8423. Quadrant.prototype.interfaces_ = function interfaces_ () {
  8424. return []
  8425. };
  8426. Quadrant.prototype.getClass = function getClass () {
  8427. return Quadrant
  8428. };
  8429. Quadrant.isNorthern = function isNorthern (quad) {
  8430. return quad === Quadrant.NE || quad === Quadrant.NW
  8431. };
  8432. Quadrant.isOpposite = function isOpposite (quad1, quad2) {
  8433. if (quad1 === quad2) { return false }
  8434. var diff = (quad1 - quad2 + 4) % 4;
  8435. if (diff === 2) { return true }
  8436. return false
  8437. };
  8438. Quadrant.commonHalfPlane = function commonHalfPlane (quad1, quad2) {
  8439. if (quad1 === quad2) { return quad1 }
  8440. var diff = (quad1 - quad2 + 4) % 4;
  8441. if (diff === 2) { return -1 }
  8442. var min = quad1 < quad2 ? quad1 : quad2;
  8443. var max = quad1 > quad2 ? quad1 : quad2;
  8444. if (min === 0 && max === 3) { return 3 }
  8445. return min
  8446. };
  8447. Quadrant.isInHalfPlane = function isInHalfPlane (quad, halfPlane) {
  8448. if (halfPlane === Quadrant.SE) {
  8449. return quad === Quadrant.SE || quad === Quadrant.SW
  8450. }
  8451. return quad === halfPlane || quad === halfPlane + 1
  8452. };
  8453. Quadrant.quadrant = function quadrant () {
  8454. if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
  8455. var dx = arguments[0];
  8456. var dy = arguments[1];
  8457. if (dx === 0.0 && dy === 0.0) { throw new IllegalArgumentException('Cannot compute the quadrant for point ( ' + dx + ', ' + dy + ' )') }
  8458. if (dx >= 0.0) {
  8459. if (dy >= 0.0) { return Quadrant.NE; } else { return Quadrant.SE }
  8460. } else {
  8461. if (dy >= 0.0) { return Quadrant.NW; } else { return Quadrant.SW }
  8462. }
  8463. } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {
  8464. var p0 = arguments[0];
  8465. var p1 = arguments[1];
  8466. if (p1.x === p0.x && p1.y === p0.y) { throw new IllegalArgumentException('Cannot compute the quadrant for two identical points ' + p0) }
  8467. if (p1.x >= p0.x) {
  8468. if (p1.y >= p0.y) { return Quadrant.NE; } else { return Quadrant.SE }
  8469. } else {
  8470. if (p1.y >= p0.y) { return Quadrant.NW; } else { return Quadrant.SW }
  8471. }
  8472. }
  8473. };
  8474. staticAccessors$21.NE.get = function () { return 0 };
  8475. staticAccessors$21.NW.get = function () { return 1 };
  8476. staticAccessors$21.SW.get = function () { return 2 };
  8477. staticAccessors$21.SE.get = function () { return 3 };
  8478. Object.defineProperties( Quadrant, staticAccessors$21 );
  8479. var EdgeEnd = function EdgeEnd () {
  8480. this._edge = null;
  8481. this._label = null;
  8482. this._node = null;
  8483. this._p0 = null;
  8484. this._p1 = null;
  8485. this._dx = null;
  8486. this._dy = null;
  8487. this._quadrant = null;
  8488. if (arguments.length === 1) {
  8489. var edge = arguments[0];
  8490. this._edge = edge;
  8491. } else if (arguments.length === 3) {
  8492. var edge$1 = arguments[0];
  8493. var p0 = arguments[1];
  8494. var p1 = arguments[2];
  8495. var label = null;
  8496. this._edge = edge$1;
  8497. this.init(p0, p1);
  8498. this._label = label;
  8499. } else if (arguments.length === 4) {
  8500. var edge$2 = arguments[0];
  8501. var p0$1 = arguments[1];
  8502. var p1$1 = arguments[2];
  8503. var label$1 = arguments[3];
  8504. this._edge = edge$2;
  8505. this.init(p0$1, p1$1);
  8506. this._label = label$1;
  8507. }
  8508. };
  8509. EdgeEnd.prototype.compareDirection = function compareDirection (e) {
  8510. if (this._dx === e._dx && this._dy === e._dy) { return 0 }
  8511. if (this._quadrant > e._quadrant) { return 1 }
  8512. if (this._quadrant < e._quadrant) { return -1 }
  8513. return CGAlgorithms.computeOrientation(e._p0, e._p1, this._p1)
  8514. };
  8515. EdgeEnd.prototype.getDy = function getDy () {
  8516. return this._dy
  8517. };
  8518. EdgeEnd.prototype.getCoordinate = function getCoordinate () {
  8519. return this._p0
  8520. };
  8521. EdgeEnd.prototype.setNode = function setNode (node) {
  8522. this._node = node;
  8523. };
  8524. EdgeEnd.prototype.print = function print (out) {
  8525. var angle = Math.atan2(this._dy, this._dx);
  8526. var className = this.getClass().getName();
  8527. var lastDotPos = className.lastIndexOf('.');
  8528. var name = className.substring(lastDotPos + 1);
  8529. out.print(' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + angle + ' ' + this._label);
  8530. };
  8531. EdgeEnd.prototype.compareTo = function compareTo (obj) {
  8532. var e = obj;
  8533. return this.compareDirection(e)
  8534. };
  8535. EdgeEnd.prototype.getDirectedCoordinate = function getDirectedCoordinate () {
  8536. return this._p1
  8537. };
  8538. EdgeEnd.prototype.getDx = function getDx () {
  8539. return this._dx
  8540. };
  8541. EdgeEnd.prototype.getLabel = function getLabel () {
  8542. return this._label
  8543. };
  8544. EdgeEnd.prototype.getEdge = function getEdge () {
  8545. return this._edge
  8546. };
  8547. EdgeEnd.prototype.getQuadrant = function getQuadrant () {
  8548. return this._quadrant
  8549. };
  8550. EdgeEnd.prototype.getNode = function getNode () {
  8551. return this._node
  8552. };
  8553. EdgeEnd.prototype.toString = function toString () {
  8554. var angle = Math.atan2(this._dy, this._dx);
  8555. var className = this.getClass().getName();
  8556. var lastDotPos = className.lastIndexOf('.');
  8557. var name = className.substring(lastDotPos + 1);
  8558. return ' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + angle + ' ' + this._label
  8559. };
  8560. EdgeEnd.prototype.computeLabel = function computeLabel (boundaryNodeRule) {};
  8561. EdgeEnd.prototype.init = function init (p0, p1) {
  8562. this._p0 = p0;
  8563. this._p1 = p1;
  8564. this._dx = p1.x - p0.x;
  8565. this._dy = p1.y - p0.y;
  8566. this._quadrant = Quadrant.quadrant(this._dx, this._dy);
  8567. Assert.isTrue(!(this._dx === 0 && this._dy === 0), 'EdgeEnd with identical endpoints found');
  8568. };
  8569. EdgeEnd.prototype.interfaces_ = function interfaces_ () {
  8570. return [Comparable]
  8571. };
  8572. EdgeEnd.prototype.getClass = function getClass () {
  8573. return EdgeEnd
  8574. };
  8575. var DirectedEdge = (function (EdgeEnd$$1) {
  8576. function DirectedEdge () {
  8577. var edge = arguments[0];
  8578. var isForward = arguments[1];
  8579. EdgeEnd$$1.call(this, edge);
  8580. this._isForward = null;
  8581. this._isInResult = false;
  8582. this._isVisited = false;
  8583. this._sym = null;
  8584. this._next = null;
  8585. this._nextMin = null;
  8586. this._edgeRing = null;
  8587. this._minEdgeRing = null;
  8588. this._depth = [0, -999, -999];
  8589. this._isForward = isForward;
  8590. if (isForward) {
  8591. this.init(edge.getCoordinate(0), edge.getCoordinate(1));
  8592. } else {
  8593. var n = edge.getNumPoints() - 1;
  8594. this.init(edge.getCoordinate(n), edge.getCoordinate(n - 1));
  8595. }
  8596. this.computeDirectedLabel();
  8597. }
  8598. if ( EdgeEnd$$1 ) DirectedEdge.__proto__ = EdgeEnd$$1;
  8599. DirectedEdge.prototype = Object.create( EdgeEnd$$1 && EdgeEnd$$1.prototype );
  8600. DirectedEdge.prototype.constructor = DirectedEdge;
  8601. DirectedEdge.prototype.getNextMin = function getNextMin () {
  8602. return this._nextMin
  8603. };
  8604. DirectedEdge.prototype.getDepth = function getDepth (position) {
  8605. return this._depth[position]
  8606. };
  8607. DirectedEdge.prototype.setVisited = function setVisited (isVisited) {
  8608. this._isVisited = isVisited;
  8609. };
  8610. DirectedEdge.prototype.computeDirectedLabel = function computeDirectedLabel () {
  8611. this._label = new Label(this._edge.getLabel());
  8612. if (!this._isForward) { this._label.flip(); }
  8613. };
  8614. DirectedEdge.prototype.getNext = function getNext () {
  8615. return this._next
  8616. };
  8617. DirectedEdge.prototype.setDepth = function setDepth (position, depthVal) {
  8618. if (this._depth[position] !== -999) {
  8619. if (this._depth[position] !== depthVal) { throw new TopologyException('assigned depths do not match', this.getCoordinate()) }
  8620. }
  8621. this._depth[position] = depthVal;
  8622. };
  8623. DirectedEdge.prototype.isInteriorAreaEdge = function isInteriorAreaEdge () {
  8624. var this$1 = this;
  8625. var isInteriorAreaEdge = true;
  8626. for (var i = 0; i < 2; i++) {
  8627. if (!(this$1._label.isArea(i) && this$1._label.getLocation(i, Position.LEFT) === Location.INTERIOR && this$1._label.getLocation(i, Position.RIGHT) === Location.INTERIOR)) {
  8628. isInteriorAreaEdge = false;
  8629. }
  8630. }
  8631. return isInteriorAreaEdge
  8632. };
  8633. DirectedEdge.prototype.setNextMin = function setNextMin (nextMin) {
  8634. this._nextMin = nextMin;
  8635. };
  8636. DirectedEdge.prototype.print = function print (out) {
  8637. EdgeEnd$$1.prototype.print.call(this, out);
  8638. out.print(' ' + this._depth[Position.LEFT] + '/' + this._depth[Position.RIGHT]);
  8639. out.print(' (' + this.getDepthDelta() + ')');
  8640. if (this._isInResult) { out.print(' inResult'); }
  8641. };
  8642. DirectedEdge.prototype.setMinEdgeRing = function setMinEdgeRing (minEdgeRing) {
  8643. this._minEdgeRing = minEdgeRing;
  8644. };
  8645. DirectedEdge.prototype.isLineEdge = function isLineEdge () {
  8646. var isLine = this._label.isLine(0) || this._label.isLine(1);
  8647. var isExteriorIfArea0 = !this._label.isArea(0) || this._label.allPositionsEqual(0, Location.EXTERIOR);
  8648. var isExteriorIfArea1 = !this._label.isArea(1) || this._label.allPositionsEqual(1, Location.EXTERIOR);
  8649. return isLine && isExteriorIfArea0 && isExteriorIfArea1
  8650. };
  8651. DirectedEdge.prototype.setEdgeRing = function setEdgeRing (edgeRing) {
  8652. this._edgeRing = edgeRing;
  8653. };
  8654. DirectedEdge.prototype.getMinEdgeRing = function getMinEdgeRing () {
  8655. return this._minEdgeRing
  8656. };
  8657. DirectedEdge.prototype.getDepthDelta = function getDepthDelta () {
  8658. var depthDelta = this._edge.getDepthDelta();
  8659. if (!this._isForward) { depthDelta = -depthDelta; }
  8660. return depthDelta
  8661. };
  8662. DirectedEdge.prototype.setInResult = function setInResult (isInResult) {
  8663. this._isInResult = isInResult;
  8664. };
  8665. DirectedEdge.prototype.getSym = function getSym () {
  8666. return this._sym
  8667. };
  8668. DirectedEdge.prototype.isForward = function isForward () {
  8669. return this._isForward
  8670. };
  8671. DirectedEdge.prototype.getEdge = function getEdge () {
  8672. return this._edge
  8673. };
  8674. DirectedEdge.prototype.printEdge = function printEdge (out) {
  8675. this.print(out);
  8676. out.print(' ');
  8677. if (this._isForward) { this._edge.print(out); } else { this._edge.printReverse(out); }
  8678. };
  8679. DirectedEdge.prototype.setSym = function setSym (de) {
  8680. this._sym = de;
  8681. };
  8682. DirectedEdge.prototype.setVisitedEdge = function setVisitedEdge (isVisited) {
  8683. this.setVisited(isVisited);
  8684. this._sym.setVisited(isVisited);
  8685. };
  8686. DirectedEdge.prototype.setEdgeDepths = function setEdgeDepths (position, depth) {
  8687. var depthDelta = this.getEdge().getDepthDelta();
  8688. if (!this._isForward) { depthDelta = -depthDelta; }
  8689. var directionFactor = 1;
  8690. if (position === Position.LEFT) { directionFactor = -1; }
  8691. var oppositePos = Position.opposite(position);
  8692. var delta = depthDelta * directionFactor;
  8693. var oppositeDepth = depth + delta;
  8694. this.setDepth(position, depth);
  8695. this.setDepth(oppositePos, oppositeDepth);
  8696. };
  8697. DirectedEdge.prototype.getEdgeRing = function getEdgeRing () {
  8698. return this._edgeRing
  8699. };
  8700. DirectedEdge.prototype.isInResult = function isInResult () {
  8701. return this._isInResult
  8702. };
  8703. DirectedEdge.prototype.setNext = function setNext (next) {
  8704. this._next = next;
  8705. };
  8706. DirectedEdge.prototype.isVisited = function isVisited () {
  8707. return this._isVisited
  8708. };
  8709. DirectedEdge.prototype.interfaces_ = function interfaces_ () {
  8710. return []
  8711. };
  8712. DirectedEdge.prototype.getClass = function getClass () {
  8713. return DirectedEdge
  8714. };
  8715. DirectedEdge.depthFactor = function depthFactor (currLocation, nextLocation) {
  8716. if (currLocation === Location.EXTERIOR && nextLocation === Location.INTERIOR) { return 1; } else if (currLocation === Location.INTERIOR && nextLocation === Location.EXTERIOR) { return -1 }
  8717. return 0
  8718. };
  8719. return DirectedEdge;
  8720. }(EdgeEnd));
  8721. var NodeFactory = function NodeFactory () {};
  8722. NodeFactory.prototype.createNode = function createNode (coord) {
  8723. return new Node(coord, null)
  8724. };
  8725. NodeFactory.prototype.interfaces_ = function interfaces_ () {
  8726. return []
  8727. };
  8728. NodeFactory.prototype.getClass = function getClass () {
  8729. return NodeFactory
  8730. };
  8731. var PlanarGraph = function PlanarGraph () {
  8732. this._edges = new ArrayList();
  8733. this._nodes = null;
  8734. this._edgeEndList = new ArrayList();
  8735. if (arguments.length === 0) {
  8736. this._nodes = new NodeMap(new NodeFactory());
  8737. } else if (arguments.length === 1) {
  8738. var nodeFact = arguments[0];
  8739. this._nodes = new NodeMap(nodeFact);
  8740. }
  8741. };
  8742. PlanarGraph.prototype.printEdges = function printEdges (out) {
  8743. var this$1 = this;
  8744. out.println('Edges:');
  8745. for (var i = 0; i < this._edges.size(); i++) {
  8746. out.println('edge ' + i + ':');
  8747. var e = this$1._edges.get(i);
  8748. e.print(out);
  8749. e.eiList.print(out);
  8750. }
  8751. };
  8752. PlanarGraph.prototype.find = function find (coord) {
  8753. return this._nodes.find(coord)
  8754. };
  8755. PlanarGraph.prototype.addNode = function addNode () {
  8756. if (arguments[0] instanceof Node) {
  8757. var node = arguments[0];
  8758. return this._nodes.addNode(node)
  8759. } else if (arguments[0] instanceof Coordinate) {
  8760. var coord = arguments[0];
  8761. return this._nodes.addNode(coord)
  8762. }
  8763. };
  8764. PlanarGraph.prototype.getNodeIterator = function getNodeIterator () {
  8765. return this._nodes.iterator()
  8766. };
  8767. PlanarGraph.prototype.linkResultDirectedEdges = function linkResultDirectedEdges () {
  8768. for (var nodeit = this._nodes.iterator(); nodeit.hasNext();) {
  8769. var node = nodeit.next();
  8770. node.getEdges().linkResultDirectedEdges();
  8771. }
  8772. };
  8773. PlanarGraph.prototype.debugPrintln = function debugPrintln (o) {
  8774. System.out.println(o);
  8775. };
  8776. PlanarGraph.prototype.isBoundaryNode = function isBoundaryNode (geomIndex, coord) {
  8777. var node = this._nodes.find(coord);
  8778. if (node === null) { return false }
  8779. var label = node.getLabel();
  8780. if (label !== null && label.getLocation(geomIndex) === Location.BOUNDARY) { return true }
  8781. return false
  8782. };
  8783. PlanarGraph.prototype.linkAllDirectedEdges = function linkAllDirectedEdges () {
  8784. for (var nodeit = this._nodes.iterator(); nodeit.hasNext();) {
  8785. var node = nodeit.next();
  8786. node.getEdges().linkAllDirectedEdges();
  8787. }
  8788. };
  8789. PlanarGraph.prototype.matchInSameDirection = function matchInSameDirection (p0, p1, ep0, ep1) {
  8790. if (!p0.equals(ep0)) { return false }
  8791. if (CGAlgorithms.computeOrientation(p0, p1, ep1) === CGAlgorithms.COLLINEAR && Quadrant.quadrant(p0, p1) === Quadrant.quadrant(ep0, ep1)) { return true }
  8792. return false
  8793. };
  8794. PlanarGraph.prototype.getEdgeEnds = function getEdgeEnds () {
  8795. return this._edgeEndList
  8796. };
  8797. PlanarGraph.prototype.debugPrint = function debugPrint (o) {
  8798. System.out.print(o);
  8799. };
  8800. PlanarGraph.prototype.getEdgeIterator = function getEdgeIterator () {
  8801. return this._edges.iterator()
  8802. };
  8803. PlanarGraph.prototype.findEdgeInSameDirection = function findEdgeInSameDirection (p0, p1) {
  8804. var this$1 = this;
  8805. for (var i = 0; i < this._edges.size(); i++) {
  8806. var e = this$1._edges.get(i);
  8807. var eCoord = e.getCoordinates();
  8808. if (this$1.matchInSameDirection(p0, p1, eCoord[0], eCoord[1])) { return e }
  8809. if (this$1.matchInSameDirection(p0, p1, eCoord[eCoord.length - 1], eCoord[eCoord.length - 2])) { return e }
  8810. }
  8811. return null
  8812. };
  8813. PlanarGraph.prototype.insertEdge = function insertEdge (e) {
  8814. this._edges.add(e);
  8815. };
  8816. PlanarGraph.prototype.findEdgeEnd = function findEdgeEnd (e) {
  8817. for (var i = this.getEdgeEnds().iterator(); i.hasNext();) {
  8818. var ee = i.next();
  8819. if (ee.getEdge() === e) { return ee }
  8820. }
  8821. return null
  8822. };
  8823. PlanarGraph.prototype.addEdges = function addEdges (edgesToAdd) {
  8824. var this$1 = this;
  8825. for (var it = edgesToAdd.iterator(); it.hasNext();) {
  8826. var e = it.next();
  8827. this$1._edges.add(e);
  8828. var de1 = new DirectedEdge(e, true);
  8829. var de2 = new DirectedEdge(e, false);
  8830. de1.setSym(de2);
  8831. de2.setSym(de1);
  8832. this$1.add(de1);
  8833. this$1.add(de2);
  8834. }
  8835. };
  8836. PlanarGraph.prototype.add = function add (e) {
  8837. this._nodes.add(e);
  8838. this._edgeEndList.add(e);
  8839. };
  8840. PlanarGraph.prototype.getNodes = function getNodes () {
  8841. return this._nodes.values()
  8842. };
  8843. PlanarGraph.prototype.findEdge = function findEdge (p0, p1) {
  8844. var this$1 = this;
  8845. for (var i = 0; i < this._edges.size(); i++) {
  8846. var e = this$1._edges.get(i);
  8847. var eCoord = e.getCoordinates();
  8848. if (p0.equals(eCoord[0]) && p1.equals(eCoord[1])) { return e }
  8849. }
  8850. return null
  8851. };
  8852. PlanarGraph.prototype.interfaces_ = function interfaces_ () {
  8853. return []
  8854. };
  8855. PlanarGraph.prototype.getClass = function getClass () {
  8856. return PlanarGraph
  8857. };
  8858. PlanarGraph.linkResultDirectedEdges = function linkResultDirectedEdges (nodes) {
  8859. for (var nodeit = nodes.iterator(); nodeit.hasNext();) {
  8860. var node = nodeit.next();
  8861. node.getEdges().linkResultDirectedEdges();
  8862. }
  8863. };
  8864. var PolygonBuilder = function PolygonBuilder () {
  8865. this._geometryFactory = null;
  8866. this._shellList = new ArrayList();
  8867. var geometryFactory = arguments[0];
  8868. this._geometryFactory = geometryFactory;
  8869. };
  8870. PolygonBuilder.prototype.sortShellsAndHoles = function sortShellsAndHoles (edgeRings, shellList, freeHoleList) {
  8871. for (var it = edgeRings.iterator(); it.hasNext();) {
  8872. var er = it.next();
  8873. if (er.isHole()) {
  8874. freeHoleList.add(er);
  8875. } else {
  8876. shellList.add(er);
  8877. }
  8878. }
  8879. };
  8880. PolygonBuilder.prototype.computePolygons = function computePolygons (shellList) {
  8881. var this$1 = this;
  8882. var resultPolyList = new ArrayList();
  8883. for (var it = shellList.iterator(); it.hasNext();) {
  8884. var er = it.next();
  8885. var poly = er.toPolygon(this$1._geometryFactory);
  8886. resultPolyList.add(poly);
  8887. }
  8888. return resultPolyList
  8889. };
  8890. PolygonBuilder.prototype.placeFreeHoles = function placeFreeHoles (shellList, freeHoleList) {
  8891. var this$1 = this;
  8892. for (var it = freeHoleList.iterator(); it.hasNext();) {
  8893. var hole = it.next();
  8894. if (hole.getShell() === null) {
  8895. var shell = this$1.findEdgeRingContaining(hole, shellList);
  8896. if (shell === null) { throw new TopologyException('unable to assign hole to a shell', hole.getCoordinate(0)) }
  8897. hole.setShell(shell);
  8898. }
  8899. }
  8900. };
  8901. PolygonBuilder.prototype.buildMinimalEdgeRings = function buildMinimalEdgeRings (maxEdgeRings, shellList, freeHoleList) {
  8902. var this$1 = this;
  8903. var edgeRings = new ArrayList();
  8904. for (var it = maxEdgeRings.iterator(); it.hasNext();) {
  8905. var er = it.next();
  8906. if (er.getMaxNodeDegree() > 2) {
  8907. er.linkDirectedEdgesForMinimalEdgeRings();
  8908. var minEdgeRings = er.buildMinimalRings();
  8909. var shell = this$1.findShell(minEdgeRings);
  8910. if (shell !== null) {
  8911. this$1.placePolygonHoles(shell, minEdgeRings);
  8912. shellList.add(shell);
  8913. } else {
  8914. freeHoleList.addAll(minEdgeRings);
  8915. }
  8916. } else {
  8917. edgeRings.add(er);
  8918. }
  8919. }
  8920. return edgeRings
  8921. };
  8922. PolygonBuilder.prototype.containsPoint = function containsPoint (p) {
  8923. for (var it = this._shellList.iterator(); it.hasNext();) {
  8924. var er = it.next();
  8925. if (er.containsPoint(p)) { return true }
  8926. }
  8927. return false
  8928. };
  8929. PolygonBuilder.prototype.buildMaximalEdgeRings = function buildMaximalEdgeRings (dirEdges) {
  8930. var this$1 = this;
  8931. var maxEdgeRings = new ArrayList();
  8932. for (var it = dirEdges.iterator(); it.hasNext();) {
  8933. var de = it.next();
  8934. if (de.isInResult() && de.getLabel().isArea()) {
  8935. if (de.getEdgeRing() === null) {
  8936. var er = new MaximalEdgeRing(de, this$1._geometryFactory);
  8937. maxEdgeRings.add(er);
  8938. er.setInResult();
  8939. }
  8940. }
  8941. }
  8942. return maxEdgeRings
  8943. };
  8944. PolygonBuilder.prototype.placePolygonHoles = function placePolygonHoles (shell, minEdgeRings) {
  8945. for (var it = minEdgeRings.iterator(); it.hasNext();) {
  8946. var er = it.next();
  8947. if (er.isHole()) {
  8948. er.setShell(shell);
  8949. }
  8950. }
  8951. };
  8952. PolygonBuilder.prototype.getPolygons = function getPolygons () {
  8953. var resultPolyList = this.computePolygons(this._shellList);
  8954. return resultPolyList
  8955. };
  8956. PolygonBuilder.prototype.findEdgeRingContaining = function findEdgeRingContaining (testEr, shellList) {
  8957. var testRing = testEr.getLinearRing();
  8958. var testEnv = testRing.getEnvelopeInternal();
  8959. var testPt = testRing.getCoordinateN(0);
  8960. var minShell = null;
  8961. var minEnv = null;
  8962. for (var it = shellList.iterator(); it.hasNext();) {
  8963. var tryShell = it.next();
  8964. var tryRing = tryShell.getLinearRing();
  8965. var tryEnv = tryRing.getEnvelopeInternal();
  8966. if (minShell !== null) { minEnv = minShell.getLinearRing().getEnvelopeInternal(); }
  8967. var isContained = false;
  8968. if (tryEnv.contains(testEnv) && CGAlgorithms.isPointInRing(testPt, tryRing.getCoordinates())) { isContained = true; }
  8969. if (isContained) {
  8970. if (minShell === null || minEnv.contains(tryEnv)) {
  8971. minShell = tryShell;
  8972. }
  8973. }
  8974. }
  8975. return minShell
  8976. };
  8977. PolygonBuilder.prototype.findShell = function findShell (minEdgeRings) {
  8978. var shellCount = 0;
  8979. var shell = null;
  8980. for (var it = minEdgeRings.iterator(); it.hasNext();) {
  8981. var er = it.next();
  8982. if (!er.isHole()) {
  8983. shell = er;
  8984. shellCount++;
  8985. }
  8986. }
  8987. Assert.isTrue(shellCount <= 1, 'found two shells in MinimalEdgeRing list');
  8988. return shell
  8989. };
  8990. PolygonBuilder.prototype.add = function add () {
  8991. if (arguments.length === 1) {
  8992. var graph = arguments[0];
  8993. this.add(graph.getEdgeEnds(), graph.getNodes());
  8994. } else if (arguments.length === 2) {
  8995. var dirEdges = arguments[0];
  8996. var nodes = arguments[1];
  8997. PlanarGraph.linkResultDirectedEdges(nodes);
  8998. var maxEdgeRings = this.buildMaximalEdgeRings(dirEdges);
  8999. var freeHoleList = new ArrayList();
  9000. var edgeRings = this.buildMinimalEdgeRings(maxEdgeRings, this._shellList, freeHoleList);
  9001. this.sortShellsAndHoles(edgeRings, this._shellList, freeHoleList);
  9002. this.placeFreeHoles(this._shellList, freeHoleList);
  9003. }
  9004. };
  9005. PolygonBuilder.prototype.interfaces_ = function interfaces_ () {
  9006. return []
  9007. };
  9008. PolygonBuilder.prototype.getClass = function getClass () {
  9009. return PolygonBuilder
  9010. };
  9011. var Boundable = function Boundable () {};
  9012. Boundable.prototype.getBounds = function getBounds () {};
  9013. Boundable.prototype.interfaces_ = function interfaces_ () {
  9014. return []
  9015. };
  9016. Boundable.prototype.getClass = function getClass () {
  9017. return Boundable
  9018. };
  9019. var ItemBoundable = function ItemBoundable () {
  9020. this._bounds = null;
  9021. this._item = null;
  9022. var bounds = arguments[0];
  9023. var item = arguments[1];
  9024. this._bounds = bounds;
  9025. this._item = item;
  9026. };
  9027. ItemBoundable.prototype.getItem = function getItem () {
  9028. return this._item
  9029. };
  9030. ItemBoundable.prototype.getBounds = function getBounds () {
  9031. return this._bounds
  9032. };
  9033. ItemBoundable.prototype.interfaces_ = function interfaces_ () {
  9034. return [Boundable, Serializable]
  9035. };
  9036. ItemBoundable.prototype.getClass = function getClass () {
  9037. return ItemBoundable
  9038. };
  9039. var PriorityQueue = function PriorityQueue () {
  9040. this._size = null;
  9041. this._items = null;
  9042. this._size = 0;
  9043. this._items = new ArrayList();
  9044. this._items.add(null);
  9045. };
  9046. PriorityQueue.prototype.poll = function poll () {
  9047. if (this.isEmpty()) { return null }
  9048. var minItem = this._items.get(1);
  9049. this._items.set(1, this._items.get(this._size));
  9050. this._size -= 1;
  9051. this.reorder(1);
  9052. return minItem
  9053. };
  9054. PriorityQueue.prototype.size = function size () {
  9055. return this._size
  9056. };
  9057. PriorityQueue.prototype.reorder = function reorder (hole) {
  9058. var this$1 = this;
  9059. var child = null;
  9060. var tmp = this._items.get(hole);
  9061. for (; hole * 2 <= this._size; hole = child) {
  9062. child = hole * 2;
  9063. if (child !== this$1._size && this$1._items.get(child + 1).compareTo(this$1._items.get(child)) < 0) { child++; }
  9064. if (this$1._items.get(child).compareTo(tmp) < 0) { this$1._items.set(hole, this$1._items.get(child)); } else { break }
  9065. }
  9066. this._items.set(hole, tmp);
  9067. };
  9068. PriorityQueue.prototype.clear = function clear () {
  9069. this._size = 0;
  9070. this._items.clear();
  9071. };
  9072. PriorityQueue.prototype.isEmpty = function isEmpty () {
  9073. return this._size === 0
  9074. };
  9075. PriorityQueue.prototype.add = function add (x) {
  9076. var this$1 = this;
  9077. this._items.add(null);
  9078. this._size += 1;
  9079. var hole = this._size;
  9080. this._items.set(0, x);
  9081. for (; x.compareTo(this._items.get(Math.trunc(hole / 2))) < 0; hole /= 2) {
  9082. this$1._items.set(hole, this$1._items.get(Math.trunc(hole / 2)));
  9083. }
  9084. this._items.set(hole, x);
  9085. };
  9086. PriorityQueue.prototype.interfaces_ = function interfaces_ () {
  9087. return []
  9088. };
  9089. PriorityQueue.prototype.getClass = function getClass () {
  9090. return PriorityQueue
  9091. };
  9092. var ItemVisitor = function ItemVisitor () {};
  9093. ItemVisitor.prototype.visitItem = function visitItem (item) {};
  9094. ItemVisitor.prototype.interfaces_ = function interfaces_ () {
  9095. return []
  9096. };
  9097. ItemVisitor.prototype.getClass = function getClass () {
  9098. return ItemVisitor
  9099. };
  9100. var SpatialIndex = function SpatialIndex () {};
  9101. SpatialIndex.prototype.insert = function insert (itemEnv, item) {};
  9102. SpatialIndex.prototype.remove = function remove (itemEnv, item) {};
  9103. SpatialIndex.prototype.query = function query () {
  9104. // if (arguments.length === 1) {
  9105. // const searchEnv = arguments[0]
  9106. // } else if (arguments.length === 2) {
  9107. // const searchEnv = arguments[0]
  9108. // const visitor = arguments[1]
  9109. // }
  9110. };
  9111. SpatialIndex.prototype.interfaces_ = function interfaces_ () {
  9112. return []
  9113. };
  9114. SpatialIndex.prototype.getClass = function getClass () {
  9115. return SpatialIndex
  9116. };
  9117. var AbstractNode = function AbstractNode () {
  9118. this._childBoundables = new ArrayList();
  9119. this._bounds = null;
  9120. this._level = null;
  9121. if (arguments.length === 0) {} else if (arguments.length === 1) {
  9122. var level = arguments[0];
  9123. this._level = level;
  9124. }
  9125. };
  9126. var staticAccessors$22 = { serialVersionUID: { configurable: true } };
  9127. AbstractNode.prototype.getLevel = function getLevel () {
  9128. return this._level
  9129. };
  9130. AbstractNode.prototype.size = function size () {
  9131. return this._childBoundables.size()
  9132. };
  9133. AbstractNode.prototype.getChildBoundables = function getChildBoundables () {
  9134. return this._childBoundables
  9135. };
  9136. AbstractNode.prototype.addChildBoundable = function addChildBoundable (childBoundable) {
  9137. Assert.isTrue(this._bounds === null);
  9138. this._childBoundables.add(childBoundable);
  9139. };
  9140. AbstractNode.prototype.isEmpty = function isEmpty () {
  9141. return this._childBoundables.isEmpty()
  9142. };
  9143. AbstractNode.prototype.getBounds = function getBounds () {
  9144. if (this._bounds === null) {
  9145. this._bounds = this.computeBounds();
  9146. }
  9147. return this._bounds
  9148. };
  9149. AbstractNode.prototype.interfaces_ = function interfaces_ () {
  9150. return [Boundable, Serializable]
  9151. };
  9152. AbstractNode.prototype.getClass = function getClass () {
  9153. return AbstractNode
  9154. };
  9155. staticAccessors$22.serialVersionUID.get = function () { return 6493722185909573708 };
  9156. Object.defineProperties( AbstractNode, staticAccessors$22 );
  9157. var Collections = function Collections () {};
  9158. Collections.reverseOrder = function reverseOrder () {
  9159. return {
  9160. compare: function compare (a, b) {
  9161. return b.compareTo(a)
  9162. }
  9163. }
  9164. };
  9165. Collections.min = function min (l) {
  9166. Collections.sort(l);
  9167. return l.get(0)
  9168. };
  9169. Collections.sort = function sort (l, c) {
  9170. var a = l.toArray();
  9171. if (c) {
  9172. Arrays.sort(a, c);
  9173. } else {
  9174. Arrays.sort(a);
  9175. }
  9176. var i = l.iterator();
  9177. for (var pos = 0, alen = a.length; pos < alen; pos++) {
  9178. i.next();
  9179. i.set(a[pos]);
  9180. }
  9181. };
  9182. Collections.singletonList = function singletonList (o) {
  9183. var arrayList = new ArrayList();
  9184. arrayList.add(o);
  9185. return arrayList
  9186. };
  9187. var BoundablePair = function BoundablePair () {
  9188. this._boundable1 = null;
  9189. this._boundable2 = null;
  9190. this._distance = null;
  9191. this._itemDistance = null;
  9192. var boundable1 = arguments[0];
  9193. var boundable2 = arguments[1];
  9194. var itemDistance = arguments[2];
  9195. this._boundable1 = boundable1;
  9196. this._boundable2 = boundable2;
  9197. this._itemDistance = itemDistance;
  9198. this._distance = this.distance();
  9199. };
  9200. BoundablePair.prototype.expandToQueue = function expandToQueue (priQ, minDistance) {
  9201. var isComp1 = BoundablePair.isComposite(this._boundable1);
  9202. var isComp2 = BoundablePair.isComposite(this._boundable2);
  9203. if (isComp1 && isComp2) {
  9204. if (BoundablePair.area(this._boundable1) > BoundablePair.area(this._boundable2)) {
  9205. this.expand(this._boundable1, this._boundable2, priQ, minDistance);
  9206. return null
  9207. } else {
  9208. this.expand(this._boundable2, this._boundable1, priQ, minDistance);
  9209. return null
  9210. }
  9211. } else if (isComp1) {
  9212. this.expand(this._boundable1, this._boundable2, priQ, minDistance);
  9213. return null
  9214. } else if (isComp2) {
  9215. this.expand(this._boundable2, this._boundable1, priQ, minDistance);
  9216. return null
  9217. }
  9218. throw new IllegalArgumentException('neither boundable is composite')
  9219. };
  9220. BoundablePair.prototype.isLeaves = function isLeaves () {
  9221. return !(BoundablePair.isComposite(this._boundable1) || BoundablePair.isComposite(this._boundable2))
  9222. };
  9223. BoundablePair.prototype.compareTo = function compareTo (o) {
  9224. var nd = o;
  9225. if (this._distance < nd._distance) { return -1 }
  9226. if (this._distance > nd._distance) { return 1 }
  9227. return 0
  9228. };
  9229. BoundablePair.prototype.expand = function expand (bndComposite, bndOther, priQ, minDistance) {
  9230. var this$1 = this;
  9231. var children = bndComposite.getChildBoundables();
  9232. for (var i = children.iterator(); i.hasNext();) {
  9233. var child = i.next();
  9234. var bp = new BoundablePair(child, bndOther, this$1._itemDistance);
  9235. if (bp.getDistance() < minDistance) {
  9236. priQ.add(bp);
  9237. }
  9238. }
  9239. };
  9240. BoundablePair.prototype.getBoundable = function getBoundable (i) {
  9241. if (i === 0) { return this._boundable1 }
  9242. return this._boundable2
  9243. };
  9244. BoundablePair.prototype.getDistance = function getDistance () {
  9245. return this._distance
  9246. };
  9247. BoundablePair.prototype.distance = function distance () {
  9248. if (this.isLeaves()) {
  9249. return this._itemDistance.distance(this._boundable1, this._boundable2)
  9250. }
  9251. return this._boundable1.getBounds().distance(this._boundable2.getBounds())
  9252. };
  9253. BoundablePair.prototype.interfaces_ = function interfaces_ () {
  9254. return [Comparable]
  9255. };
  9256. BoundablePair.prototype.getClass = function getClass () {
  9257. return BoundablePair
  9258. };
  9259. BoundablePair.area = function area (b) {
  9260. return b.getBounds().getArea()
  9261. };
  9262. BoundablePair.isComposite = function isComposite (item) {
  9263. return item instanceof AbstractNode
  9264. };
  9265. var AbstractSTRtree = function AbstractSTRtree () {
  9266. this._root = null;
  9267. this._built = false;
  9268. this._itemBoundables = new ArrayList();
  9269. this._nodeCapacity = null;
  9270. if (arguments.length === 0) {
  9271. var nodeCapacity = AbstractSTRtree.DEFAULT_NODE_CAPACITY;
  9272. this._nodeCapacity = nodeCapacity;
  9273. } else if (arguments.length === 1) {
  9274. var nodeCapacity$1 = arguments[0];
  9275. Assert.isTrue(nodeCapacity$1 > 1, 'Node capacity must be greater than 1');
  9276. this._nodeCapacity = nodeCapacity$1;
  9277. }
  9278. };
  9279. var staticAccessors$23 = { IntersectsOp: { configurable: true },serialVersionUID: { configurable: true },DEFAULT_NODE_CAPACITY: { configurable: true } };
  9280. AbstractSTRtree.prototype.getNodeCapacity = function getNodeCapacity () {
  9281. return this._nodeCapacity
  9282. };
  9283. AbstractSTRtree.prototype.lastNode = function lastNode (nodes) {
  9284. return nodes.get(nodes.size() - 1)
  9285. };
  9286. AbstractSTRtree.prototype.size = function size () {
  9287. var this$1 = this;
  9288. if (arguments.length === 0) {
  9289. if (this.isEmpty()) {
  9290. return 0
  9291. }
  9292. this.build();
  9293. return this.size(this._root)
  9294. } else if (arguments.length === 1) {
  9295. var node = arguments[0];
  9296. var size = 0;
  9297. for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
  9298. var childBoundable = i.next();
  9299. if (childBoundable instanceof AbstractNode) {
  9300. size += this$1.size(childBoundable);
  9301. } else if (childBoundable instanceof ItemBoundable) {
  9302. size += 1;
  9303. }
  9304. }
  9305. return size
  9306. }
  9307. };
  9308. AbstractSTRtree.prototype.removeItem = function removeItem (node, item) {
  9309. var childToRemove = null;
  9310. for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
  9311. var childBoundable = i.next();
  9312. if (childBoundable instanceof ItemBoundable) {
  9313. if (childBoundable.getItem() === item) { childToRemove = childBoundable; }
  9314. }
  9315. }
  9316. if (childToRemove !== null) {
  9317. node.getChildBoundables().remove(childToRemove);
  9318. return true
  9319. }
  9320. return false
  9321. };
  9322. AbstractSTRtree.prototype.itemsTree = function itemsTree () {
  9323. var this$1 = this;
  9324. if (arguments.length === 0) {
  9325. this.build();
  9326. var valuesTree = this.itemsTree(this._root);
  9327. if (valuesTree === null) { return new ArrayList() }
  9328. return valuesTree
  9329. } else if (arguments.length === 1) {
  9330. var node = arguments[0];
  9331. var valuesTreeForNode = new ArrayList();
  9332. for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
  9333. var childBoundable = i.next();
  9334. if (childBoundable instanceof AbstractNode) {
  9335. var valuesTreeForChild = this$1.itemsTree(childBoundable);
  9336. if (valuesTreeForChild !== null) { valuesTreeForNode.add(valuesTreeForChild); }
  9337. } else if (childBoundable instanceof ItemBoundable) {
  9338. valuesTreeForNode.add(childBoundable.getItem());
  9339. } else {
  9340. Assert.shouldNeverReachHere();
  9341. }
  9342. }
  9343. if (valuesTreeForNode.size() <= 0) { return null }
  9344. return valuesTreeForNode
  9345. }
  9346. };
  9347. AbstractSTRtree.prototype.insert = function insert (bounds, item) {
  9348. Assert.isTrue(!this._built, 'Cannot insert items into an STR packed R-tree after it has been built.');
  9349. this._itemBoundables.add(new ItemBoundable(bounds, item));
  9350. };
  9351. AbstractSTRtree.prototype.boundablesAtLevel = function boundablesAtLevel () {
  9352. var this$1 = this;
  9353. if (arguments.length === 1) {
  9354. var level = arguments[0];
  9355. var boundables = new ArrayList();
  9356. this.boundablesAtLevel(level, this._root, boundables);
  9357. return boundables
  9358. } else if (arguments.length === 3) {
  9359. var level$1 = arguments[0];
  9360. var top = arguments[1];
  9361. var boundables$1 = arguments[2];
  9362. Assert.isTrue(level$1 > -2);
  9363. if (top.getLevel() === level$1) {
  9364. boundables$1.add(top);
  9365. return null
  9366. }
  9367. for (var i = top.getChildBoundables().iterator(); i.hasNext();) {
  9368. var boundable = i.next();
  9369. if (boundable instanceof AbstractNode) {
  9370. this$1.boundablesAtLevel(level$1, boundable, boundables$1);
  9371. } else {
  9372. Assert.isTrue(boundable instanceof ItemBoundable);
  9373. if (level$1 === -1) {
  9374. boundables$1.add(boundable);
  9375. }
  9376. }
  9377. }
  9378. return null
  9379. }
  9380. };
  9381. AbstractSTRtree.prototype.query = function query () {
  9382. var this$1 = this;
  9383. if (arguments.length === 1) {
  9384. var searchBounds = arguments[0];
  9385. this.build();
  9386. var matches = new ArrayList();
  9387. if (this.isEmpty()) {
  9388. return matches
  9389. }
  9390. if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds)) {
  9391. this.query(searchBounds, this._root, matches);
  9392. }
  9393. return matches
  9394. } else if (arguments.length === 2) {
  9395. var searchBounds$1 = arguments[0];
  9396. var visitor = arguments[1];
  9397. this.build();
  9398. if (this.isEmpty()) {
  9399. return null
  9400. }
  9401. if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds$1)) {
  9402. this.query(searchBounds$1, this._root, visitor);
  9403. }
  9404. } else if (arguments.length === 3) {
  9405. if (hasInterface(arguments[2], ItemVisitor) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
  9406. var searchBounds$2 = arguments[0];
  9407. var node = arguments[1];
  9408. var visitor$1 = arguments[2];
  9409. var childBoundables = node.getChildBoundables();
  9410. for (var i = 0; i < childBoundables.size(); i++) {
  9411. var childBoundable = childBoundables.get(i);
  9412. if (!this$1.getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds$2)) {
  9413. continue
  9414. }
  9415. if (childBoundable instanceof AbstractNode) {
  9416. this$1.query(searchBounds$2, childBoundable, visitor$1);
  9417. } else if (childBoundable instanceof ItemBoundable) {
  9418. visitor$1.visitItem(childBoundable.getItem());
  9419. } else {
  9420. Assert.shouldNeverReachHere();
  9421. }
  9422. }
  9423. } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
  9424. var searchBounds$3 = arguments[0];
  9425. var node$1 = arguments[1];
  9426. var matches$1 = arguments[2];
  9427. var childBoundables$1 = node$1.getChildBoundables();
  9428. for (var i$1 = 0; i$1 < childBoundables$1.size(); i$1++) {
  9429. var childBoundable$1 = childBoundables$1.get(i$1);
  9430. if (!this$1.getIntersectsOp().intersects(childBoundable$1.getBounds(), searchBounds$3)) {
  9431. continue
  9432. }
  9433. if (childBoundable$1 instanceof AbstractNode) {
  9434. this$1.query(searchBounds$3, childBoundable$1, matches$1);
  9435. } else if (childBoundable$1 instanceof ItemBoundable) {
  9436. matches$1.add(childBoundable$1.getItem());
  9437. } else {
  9438. Assert.shouldNeverReachHere();
  9439. }
  9440. }
  9441. }
  9442. }
  9443. };
  9444. AbstractSTRtree.prototype.build = function build () {
  9445. if (this._built) { return null }
  9446. this._root = this._itemBoundables.isEmpty() ? this.createNode(0) : this.createHigherLevels(this._itemBoundables, -1);
  9447. this._itemBoundables = null;
  9448. this._built = true;
  9449. };
  9450. AbstractSTRtree.prototype.getRoot = function getRoot () {
  9451. this.build();
  9452. return this._root
  9453. };
  9454. AbstractSTRtree.prototype.remove = function remove () {
  9455. var this$1 = this;
  9456. if (arguments.length === 2) {
  9457. var searchBounds = arguments[0];
  9458. var item = arguments[1];
  9459. this.build();
  9460. if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds)) {
  9461. return this.remove(searchBounds, this._root, item)
  9462. }
  9463. return false
  9464. } else if (arguments.length === 3) {
  9465. var searchBounds$1 = arguments[0];
  9466. var node = arguments[1];
  9467. var item$1 = arguments[2];
  9468. var found = this.removeItem(node, item$1);
  9469. if (found) { return true }
  9470. var childToPrune = null;
  9471. for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
  9472. var childBoundable = i.next();
  9473. if (!this$1.getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds$1)) {
  9474. continue
  9475. }
  9476. if (childBoundable instanceof AbstractNode) {
  9477. found = this$1.remove(searchBounds$1, childBoundable, item$1);
  9478. if (found) {
  9479. childToPrune = childBoundable;
  9480. break
  9481. }
  9482. }
  9483. }
  9484. if (childToPrune !== null) {
  9485. if (childToPrune.getChildBoundables().isEmpty()) {
  9486. node.getChildBoundables().remove(childToPrune);
  9487. }
  9488. }
  9489. return found
  9490. }
  9491. };
  9492. AbstractSTRtree.prototype.createHigherLevels = function createHigherLevels (boundablesOfALevel, level) {
  9493. Assert.isTrue(!boundablesOfALevel.isEmpty());
  9494. var parentBoundables = this.createParentBoundables(boundablesOfALevel, level + 1);
  9495. if (parentBoundables.size() === 1) {
  9496. return parentBoundables.get(0)
  9497. }
  9498. return this.createHigherLevels(parentBoundables, level + 1)
  9499. };
  9500. AbstractSTRtree.prototype.depth = function depth () {
  9501. var this$1 = this;
  9502. if (arguments.length === 0) {
  9503. if (this.isEmpty()) {
  9504. return 0
  9505. }
  9506. this.build();
  9507. return this.depth(this._root)
  9508. } else if (arguments.length === 1) {
  9509. var node = arguments[0];
  9510. var maxChildDepth = 0;
  9511. for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
  9512. var childBoundable = i.next();
  9513. if (childBoundable instanceof AbstractNode) {
  9514. var childDepth = this$1.depth(childBoundable);
  9515. if (childDepth > maxChildDepth) { maxChildDepth = childDepth; }
  9516. }
  9517. }
  9518. return maxChildDepth + 1
  9519. }
  9520. };
  9521. AbstractSTRtree.prototype.createParentBoundables = function createParentBoundables (childBoundables, newLevel) {
  9522. var this$1 = this;
  9523. Assert.isTrue(!childBoundables.isEmpty());
  9524. var parentBoundables = new ArrayList();
  9525. parentBoundables.add(this.createNode(newLevel));
  9526. var sortedChildBoundables = new ArrayList(childBoundables);
  9527. Collections.sort(sortedChildBoundables, this.getComparator());
  9528. for (var i = sortedChildBoundables.iterator(); i.hasNext();) {
  9529. var childBoundable = i.next();
  9530. if (this$1.lastNode(parentBoundables).getChildBoundables().size() === this$1.getNodeCapacity()) {
  9531. parentBoundables.add(this$1.createNode(newLevel));
  9532. }
  9533. this$1.lastNode(parentBoundables).addChildBoundable(childBoundable);
  9534. }
  9535. return parentBoundables
  9536. };
  9537. AbstractSTRtree.prototype.isEmpty = function isEmpty () {
  9538. if (!this._built) { return this._itemBoundables.isEmpty() }
  9539. return this._root.isEmpty()
  9540. };
  9541. AbstractSTRtree.prototype.interfaces_ = function interfaces_ () {
  9542. return [Serializable]
  9543. };
  9544. AbstractSTRtree.prototype.getClass = function getClass () {
  9545. return AbstractSTRtree
  9546. };
  9547. AbstractSTRtree.compareDoubles = function compareDoubles (a, b) {
  9548. return a > b ? 1 : a < b ? -1 : 0
  9549. };
  9550. staticAccessors$23.IntersectsOp.get = function () { return IntersectsOp };
  9551. staticAccessors$23.serialVersionUID.get = function () { return -3886435814360241337 };
  9552. staticAccessors$23.DEFAULT_NODE_CAPACITY.get = function () { return 10 };
  9553. Object.defineProperties( AbstractSTRtree, staticAccessors$23 );
  9554. var IntersectsOp = function IntersectsOp () {};
  9555. var ItemDistance = function ItemDistance () {};
  9556. ItemDistance.prototype.distance = function distance (item1, item2) {};
  9557. ItemDistance.prototype.interfaces_ = function interfaces_ () {
  9558. return []
  9559. };
  9560. ItemDistance.prototype.getClass = function getClass () {
  9561. return ItemDistance
  9562. };
  9563. var STRtree = (function (AbstractSTRtree$$1) {
  9564. function STRtree (nodeCapacity) {
  9565. nodeCapacity = nodeCapacity || STRtree.DEFAULT_NODE_CAPACITY;
  9566. AbstractSTRtree$$1.call(this, nodeCapacity);
  9567. }
  9568. if ( AbstractSTRtree$$1 ) STRtree.__proto__ = AbstractSTRtree$$1;
  9569. STRtree.prototype = Object.create( AbstractSTRtree$$1 && AbstractSTRtree$$1.prototype );
  9570. STRtree.prototype.constructor = STRtree;
  9571. var staticAccessors = { STRtreeNode: { configurable: true },serialVersionUID: { configurable: true },xComparator: { configurable: true },yComparator: { configurable: true },intersectsOp: { configurable: true },DEFAULT_NODE_CAPACITY: { configurable: true } };
  9572. STRtree.prototype.createParentBoundablesFromVerticalSlices = function createParentBoundablesFromVerticalSlices (verticalSlices, newLevel) {
  9573. var this$1 = this;
  9574. Assert.isTrue(verticalSlices.length > 0);
  9575. var parentBoundables = new ArrayList();
  9576. for (var i = 0; i < verticalSlices.length; i++) {
  9577. parentBoundables.addAll(this$1.createParentBoundablesFromVerticalSlice(verticalSlices[i], newLevel));
  9578. }
  9579. return parentBoundables
  9580. };
  9581. STRtree.prototype.createNode = function createNode (level) {
  9582. return new STRtreeNode(level)
  9583. };
  9584. STRtree.prototype.size = function size () {
  9585. if (arguments.length === 0) {
  9586. return AbstractSTRtree$$1.prototype.size.call(this)
  9587. } else { return AbstractSTRtree$$1.prototype.size.apply(this, arguments) }
  9588. };
  9589. STRtree.prototype.insert = function insert () {
  9590. if (arguments.length === 2) {
  9591. var itemEnv = arguments[0];
  9592. var item = arguments[1];
  9593. if (itemEnv.isNull()) {
  9594. return null
  9595. }
  9596. AbstractSTRtree$$1.prototype.insert.call(this, itemEnv, item);
  9597. } else { return AbstractSTRtree$$1.prototype.insert.apply(this, arguments) }
  9598. };
  9599. STRtree.prototype.getIntersectsOp = function getIntersectsOp () {
  9600. return STRtree.intersectsOp
  9601. };
  9602. STRtree.prototype.verticalSlices = function verticalSlices (childBoundables, sliceCount) {
  9603. var sliceCapacity = Math.trunc(Math.ceil(childBoundables.size() / sliceCount));
  9604. var slices = new Array(sliceCount).fill(null);
  9605. var i = childBoundables.iterator();
  9606. for (var j = 0; j < sliceCount; j++) {
  9607. slices[j] = new ArrayList();
  9608. var boundablesAddedToSlice = 0;
  9609. while (i.hasNext() && boundablesAddedToSlice < sliceCapacity) {
  9610. var childBoundable = i.next();
  9611. slices[j].add(childBoundable);
  9612. boundablesAddedToSlice++;
  9613. }
  9614. }
  9615. return slices
  9616. };
  9617. STRtree.prototype.query = function query () {
  9618. if (arguments.length === 1) {
  9619. var searchEnv = arguments[0];
  9620. return AbstractSTRtree$$1.prototype.query.call(this, searchEnv)
  9621. } else if (arguments.length === 2) {
  9622. var searchEnv$1 = arguments[0];
  9623. var visitor = arguments[1];
  9624. AbstractSTRtree$$1.prototype.query.call(this, searchEnv$1, visitor);
  9625. } else if (arguments.length === 3) {
  9626. if (hasInterface(arguments[2], ItemVisitor) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
  9627. var searchBounds = arguments[0];
  9628. var node = arguments[1];
  9629. var visitor$1 = arguments[2];
  9630. AbstractSTRtree$$1.prototype.query.call(this, searchBounds, node, visitor$1);
  9631. } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
  9632. var searchBounds$1 = arguments[0];
  9633. var node$1 = arguments[1];
  9634. var matches = arguments[2];
  9635. AbstractSTRtree$$1.prototype.query.call(this, searchBounds$1, node$1, matches);
  9636. }
  9637. }
  9638. };
  9639. STRtree.prototype.getComparator = function getComparator () {
  9640. return STRtree.yComparator
  9641. };
  9642. STRtree.prototype.createParentBoundablesFromVerticalSlice = function createParentBoundablesFromVerticalSlice (childBoundables, newLevel) {
  9643. return AbstractSTRtree$$1.prototype.createParentBoundables.call(this, childBoundables, newLevel)
  9644. };
  9645. STRtree.prototype.remove = function remove () {
  9646. if (arguments.length === 2) {
  9647. var itemEnv = arguments[0];
  9648. var item = arguments[1];
  9649. return AbstractSTRtree$$1.prototype.remove.call(this, itemEnv, item)
  9650. } else { return AbstractSTRtree$$1.prototype.remove.apply(this, arguments) }
  9651. };
  9652. STRtree.prototype.depth = function depth () {
  9653. if (arguments.length === 0) {
  9654. return AbstractSTRtree$$1.prototype.depth.call(this)
  9655. } else { return AbstractSTRtree$$1.prototype.depth.apply(this, arguments) }
  9656. };
  9657. STRtree.prototype.createParentBoundables = function createParentBoundables (childBoundables, newLevel) {
  9658. Assert.isTrue(!childBoundables.isEmpty());
  9659. var minLeafCount = Math.trunc(Math.ceil(childBoundables.size() / this.getNodeCapacity()));
  9660. var sortedChildBoundables = new ArrayList(childBoundables);
  9661. Collections.sort(sortedChildBoundables, STRtree.xComparator);
  9662. var verticalSlices = this.verticalSlices(sortedChildBoundables, Math.trunc(Math.ceil(Math.sqrt(minLeafCount))));
  9663. return this.createParentBoundablesFromVerticalSlices(verticalSlices, newLevel)
  9664. };
  9665. STRtree.prototype.nearestNeighbour = function nearestNeighbour () {
  9666. if (arguments.length === 1) {
  9667. if (hasInterface(arguments[0], ItemDistance)) {
  9668. var itemDist = arguments[0];
  9669. var bp = new BoundablePair(this.getRoot(), this.getRoot(), itemDist);
  9670. return this.nearestNeighbour(bp)
  9671. } else if (arguments[0] instanceof BoundablePair) {
  9672. var initBndPair = arguments[0];
  9673. return this.nearestNeighbour(initBndPair, Double.POSITIVE_INFINITY)
  9674. }
  9675. } else if (arguments.length === 2) {
  9676. if (arguments[0] instanceof STRtree && hasInterface(arguments[1], ItemDistance)) {
  9677. var tree = arguments[0];
  9678. var itemDist$1 = arguments[1];
  9679. var bp$1 = new BoundablePair(this.getRoot(), tree.getRoot(), itemDist$1);
  9680. return this.nearestNeighbour(bp$1)
  9681. } else if (arguments[0] instanceof BoundablePair && typeof arguments[1] === 'number') {
  9682. var initBndPair$1 = arguments[0];
  9683. var maxDistance = arguments[1];
  9684. var distanceLowerBound = maxDistance;
  9685. var minPair = null;
  9686. var priQ = new PriorityQueue();
  9687. priQ.add(initBndPair$1);
  9688. while (!priQ.isEmpty() && distanceLowerBound > 0.0) {
  9689. var bndPair = priQ.poll();
  9690. var currentDistance = bndPair.getDistance();
  9691. if (currentDistance >= distanceLowerBound) { break }
  9692. if (bndPair.isLeaves()) {
  9693. distanceLowerBound = currentDistance;
  9694. minPair = bndPair;
  9695. } else {
  9696. bndPair.expandToQueue(priQ, distanceLowerBound);
  9697. }
  9698. }
  9699. return [minPair.getBoundable(0).getItem(), minPair.getBoundable(1).getItem()]
  9700. }
  9701. } else if (arguments.length === 3) {
  9702. var env = arguments[0];
  9703. var item = arguments[1];
  9704. var itemDist$2 = arguments[2];
  9705. var bnd = new ItemBoundable(env, item);
  9706. var bp$2 = new BoundablePair(this.getRoot(), bnd, itemDist$2);
  9707. return this.nearestNeighbour(bp$2)[0]
  9708. }
  9709. };
  9710. STRtree.prototype.interfaces_ = function interfaces_ () {
  9711. return [SpatialIndex, Serializable]
  9712. };
  9713. STRtree.prototype.getClass = function getClass () {
  9714. return STRtree
  9715. };
  9716. STRtree.centreX = function centreX (e) {
  9717. return STRtree.avg(e.getMinX(), e.getMaxX())
  9718. };
  9719. STRtree.avg = function avg (a, b) {
  9720. return (a + b) / 2
  9721. };
  9722. STRtree.centreY = function centreY (e) {
  9723. return STRtree.avg(e.getMinY(), e.getMaxY())
  9724. };
  9725. staticAccessors.STRtreeNode.get = function () { return STRtreeNode };
  9726. staticAccessors.serialVersionUID.get = function () { return 259274702368956900 };
  9727. staticAccessors.xComparator.get = function () {
  9728. return {
  9729. interfaces_: function () {
  9730. return [Comparator]
  9731. },
  9732. compare: function (o1, o2) {
  9733. return AbstractSTRtree$$1.compareDoubles(STRtree.centreX(o1.getBounds()), STRtree.centreX(o2.getBounds()))
  9734. }
  9735. }
  9736. };
  9737. staticAccessors.yComparator.get = function () {
  9738. return {
  9739. interfaces_: function () {
  9740. return [Comparator]
  9741. },
  9742. compare: function (o1, o2) {
  9743. return AbstractSTRtree$$1.compareDoubles(STRtree.centreY(o1.getBounds()), STRtree.centreY(o2.getBounds()))
  9744. }
  9745. }
  9746. };
  9747. staticAccessors.intersectsOp.get = function () {
  9748. return {
  9749. interfaces_: function () {
  9750. return [AbstractSTRtree$$1.IntersectsOp]
  9751. },
  9752. intersects: function (aBounds, bBounds) {
  9753. return aBounds.intersects(bBounds)
  9754. }
  9755. }
  9756. };
  9757. staticAccessors.DEFAULT_NODE_CAPACITY.get = function () { return 10 };
  9758. Object.defineProperties( STRtree, staticAccessors );
  9759. return STRtree;
  9760. }(AbstractSTRtree));
  9761. var STRtreeNode = (function (AbstractNode$$1) {
  9762. function STRtreeNode () {
  9763. var level = arguments[0];
  9764. AbstractNode$$1.call(this, level);
  9765. }
  9766. if ( AbstractNode$$1 ) STRtreeNode.__proto__ = AbstractNode$$1;
  9767. STRtreeNode.prototype = Object.create( AbstractNode$$1 && AbstractNode$$1.prototype );
  9768. STRtreeNode.prototype.constructor = STRtreeNode;
  9769. STRtreeNode.prototype.computeBounds = function computeBounds () {
  9770. var bounds = null;
  9771. for (var i = this.getChildBoundables().iterator(); i.hasNext();) {
  9772. var childBoundable = i.next();
  9773. if (bounds === null) {
  9774. bounds = new Envelope(childBoundable.getBounds());
  9775. } else {
  9776. bounds.expandToInclude(childBoundable.getBounds());
  9777. }
  9778. }
  9779. return bounds
  9780. };
  9781. STRtreeNode.prototype.interfaces_ = function interfaces_ () {
  9782. return []
  9783. };
  9784. STRtreeNode.prototype.getClass = function getClass () {
  9785. return STRtreeNode
  9786. };
  9787. return STRtreeNode;
  9788. }(AbstractNode));
  9789. var SegmentPointComparator = function SegmentPointComparator () {};
  9790. SegmentPointComparator.prototype.interfaces_ = function interfaces_ () {
  9791. return []
  9792. };
  9793. SegmentPointComparator.prototype.getClass = function getClass () {
  9794. return SegmentPointComparator
  9795. };
  9796. SegmentPointComparator.relativeSign = function relativeSign (x0, x1) {
  9797. if (x0 < x1) { return -1 }
  9798. if (x0 > x1) { return 1 }
  9799. return 0
  9800. };
  9801. SegmentPointComparator.compare = function compare (octant, p0, p1) {
  9802. if (p0.equals2D(p1)) { return 0 }
  9803. var xSign = SegmentPointComparator.relativeSign(p0.x, p1.x);
  9804. var ySign = SegmentPointComparator.relativeSign(p0.y, p1.y);
  9805. switch (octant) {
  9806. case 0:
  9807. return SegmentPointComparator.compareValue(xSign, ySign)
  9808. case 1:
  9809. return SegmentPointComparator.compareValue(ySign, xSign)
  9810. case 2:
  9811. return SegmentPointComparator.compareValue(ySign, -xSign)
  9812. case 3:
  9813. return SegmentPointComparator.compareValue(-xSign, ySign)
  9814. case 4:
  9815. return SegmentPointComparator.compareValue(-xSign, -ySign)
  9816. case 5:
  9817. return SegmentPointComparator.compareValue(-ySign, -xSign)
  9818. case 6:
  9819. return SegmentPointComparator.compareValue(-ySign, xSign)
  9820. case 7:
  9821. return SegmentPointComparator.compareValue(xSign, -ySign)
  9822. default:
  9823. }
  9824. Assert.shouldNeverReachHere('invalid octant value');
  9825. return 0
  9826. };
  9827. SegmentPointComparator.compareValue = function compareValue (compareSign0, compareSign1) {
  9828. if (compareSign0 < 0) { return -1 }
  9829. if (compareSign0 > 0) { return 1 }
  9830. if (compareSign1 < 0) { return -1 }
  9831. if (compareSign1 > 0) { return 1 }
  9832. return 0
  9833. };
  9834. var SegmentNode = function SegmentNode () {
  9835. this._segString = null;
  9836. this.coord = null;
  9837. this.segmentIndex = null;
  9838. this._segmentOctant = null;
  9839. this._isInterior = null;
  9840. var segString = arguments[0];
  9841. var coord = arguments[1];
  9842. var segmentIndex = arguments[2];
  9843. var segmentOctant = arguments[3];
  9844. this._segString = segString;
  9845. this.coord = new Coordinate(coord);
  9846. this.segmentIndex = segmentIndex;
  9847. this._segmentOctant = segmentOctant;
  9848. this._isInterior = !coord.equals2D(segString.getCoordinate(segmentIndex));
  9849. };
  9850. SegmentNode.prototype.getCoordinate = function getCoordinate () {
  9851. return this.coord
  9852. };
  9853. SegmentNode.prototype.print = function print (out) {
  9854. out.print(this.coord);
  9855. out.print(' seg # = ' + this.segmentIndex);
  9856. };
  9857. SegmentNode.prototype.compareTo = function compareTo (obj) {
  9858. var other = obj;
  9859. if (this.segmentIndex < other.segmentIndex) { return -1 }
  9860. if (this.segmentIndex > other.segmentIndex) { return 1 }
  9861. if (this.coord.equals2D(other.coord)) { return 0 }
  9862. return SegmentPointComparator.compare(this._segmentOctant, this.coord, other.coord)
  9863. };
  9864. SegmentNode.prototype.isEndPoint = function isEndPoint (maxSegmentIndex) {
  9865. if (this.segmentIndex === 0 && !this._isInterior) { return true }
  9866. if (this.segmentIndex === maxSegmentIndex) { return true }
  9867. return false
  9868. };
  9869. SegmentNode.prototype.isInterior = function isInterior () {
  9870. return this._isInterior
  9871. };
  9872. SegmentNode.prototype.interfaces_ = function interfaces_ () {
  9873. return [Comparable]
  9874. };
  9875. SegmentNode.prototype.getClass = function getClass () {
  9876. return SegmentNode
  9877. };
  9878. // import Iterator from '../../../../java/util/Iterator'
  9879. var SegmentNodeList = function SegmentNodeList () {
  9880. this._nodeMap = new TreeMap();
  9881. this._edge = null;
  9882. var edge = arguments[0];
  9883. this._edge = edge;
  9884. };
  9885. SegmentNodeList.prototype.getSplitCoordinates = function getSplitCoordinates () {
  9886. var this$1 = this;
  9887. var coordList = new CoordinateList();
  9888. this.addEndpoints();
  9889. var it = this.iterator();
  9890. var eiPrev = it.next();
  9891. while (it.hasNext()) {
  9892. var ei = it.next();
  9893. this$1.addEdgeCoordinates(eiPrev, ei, coordList);
  9894. eiPrev = ei;
  9895. }
  9896. return coordList.toCoordinateArray()
  9897. };
  9898. SegmentNodeList.prototype.addCollapsedNodes = function addCollapsedNodes () {
  9899. var this$1 = this;
  9900. var collapsedVertexIndexes = new ArrayList();
  9901. this.findCollapsesFromInsertedNodes(collapsedVertexIndexes);
  9902. this.findCollapsesFromExistingVertices(collapsedVertexIndexes);
  9903. for (var it = collapsedVertexIndexes.iterator(); it.hasNext();) {
  9904. var vertexIndex = it.next().intValue();
  9905. this$1.add(this$1._edge.getCoordinate(vertexIndex), vertexIndex);
  9906. }
  9907. };
  9908. SegmentNodeList.prototype.print = function print (out) {
  9909. out.println('Intersections:');
  9910. for (var it = this.iterator(); it.hasNext();) {
  9911. var ei = it.next();
  9912. ei.print(out);
  9913. }
  9914. };
  9915. SegmentNodeList.prototype.findCollapsesFromExistingVertices = function findCollapsesFromExistingVertices (collapsedVertexIndexes) {
  9916. var this$1 = this;
  9917. for (var i = 0; i < this._edge.size() - 2; i++) {
  9918. var p0 = this$1._edge.getCoordinate(i);
  9919. // const p1 = this._edge.getCoordinate(i + 1)
  9920. var p2 = this$1._edge.getCoordinate(i + 2);
  9921. if (p0.equals2D(p2)) {
  9922. collapsedVertexIndexes.add(new Integer(i + 1));
  9923. }
  9924. }
  9925. };
  9926. SegmentNodeList.prototype.addEdgeCoordinates = function addEdgeCoordinates (ei0, ei1, coordList) {
  9927. var this$1 = this;
  9928. // let npts = ei1.segmentIndex - ei0.segmentIndex + 2
  9929. var lastSegStartPt = this._edge.getCoordinate(ei1.segmentIndex);
  9930. var useIntPt1 = ei1.isInterior() || !ei1.coord.equals2D(lastSegStartPt);
  9931. // if (!useIntPt1) {
  9932. // npts--
  9933. // }
  9934. // const ipt = 0
  9935. coordList.add(new Coordinate(ei0.coord), false);
  9936. for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
  9937. coordList.add(this$1._edge.getCoordinate(i));
  9938. }
  9939. if (useIntPt1) {
  9940. coordList.add(new Coordinate(ei1.coord));
  9941. }
  9942. };
  9943. SegmentNodeList.prototype.iterator = function iterator () {
  9944. return this._nodeMap.values().iterator()
  9945. };
  9946. SegmentNodeList.prototype.addSplitEdges = function addSplitEdges (edgeList) {
  9947. var this$1 = this;
  9948. this.addEndpoints();
  9949. this.addCollapsedNodes();
  9950. var it = this.iterator();
  9951. var eiPrev = it.next();
  9952. while (it.hasNext()) {
  9953. var ei = it.next();
  9954. var newEdge = this$1.createSplitEdge(eiPrev, ei);
  9955. edgeList.add(newEdge);
  9956. eiPrev = ei;
  9957. }
  9958. };
  9959. SegmentNodeList.prototype.findCollapseIndex = function findCollapseIndex (ei0, ei1, collapsedVertexIndex) {
  9960. if (!ei0.coord.equals2D(ei1.coord)) { return false }
  9961. var numVerticesBetween = ei1.segmentIndex - ei0.segmentIndex;
  9962. if (!ei1.isInterior()) {
  9963. numVerticesBetween--;
  9964. }
  9965. if (numVerticesBetween === 1) {
  9966. collapsedVertexIndex[0] = ei0.segmentIndex + 1;
  9967. return true
  9968. }
  9969. return false
  9970. };
  9971. SegmentNodeList.prototype.findCollapsesFromInsertedNodes = function findCollapsesFromInsertedNodes (collapsedVertexIndexes) {
  9972. var this$1 = this;
  9973. var collapsedVertexIndex = new Array(1).fill(null);
  9974. var it = this.iterator();
  9975. var eiPrev = it.next();
  9976. while (it.hasNext()) {
  9977. var ei = it.next();
  9978. var isCollapsed = this$1.findCollapseIndex(eiPrev, ei, collapsedVertexIndex);
  9979. if (isCollapsed) { collapsedVertexIndexes.add(new Integer(collapsedVertexIndex[0])); }
  9980. eiPrev = ei;
  9981. }
  9982. };
  9983. SegmentNodeList.prototype.getEdge = function getEdge () {
  9984. return this._edge
  9985. };
  9986. SegmentNodeList.prototype.addEndpoints = function addEndpoints () {
  9987. var maxSegIndex = this._edge.size() - 1;
  9988. this.add(this._edge.getCoordinate(0), 0);
  9989. this.add(this._edge.getCoordinate(maxSegIndex), maxSegIndex);
  9990. };
  9991. SegmentNodeList.prototype.createSplitEdge = function createSplitEdge (ei0, ei1) {
  9992. var this$1 = this;
  9993. var npts = ei1.segmentIndex - ei0.segmentIndex + 2;
  9994. var lastSegStartPt = this._edge.getCoordinate(ei1.segmentIndex);
  9995. var useIntPt1 = ei1.isInterior() || !ei1.coord.equals2D(lastSegStartPt);
  9996. if (!useIntPt1) {
  9997. npts--;
  9998. }
  9999. var pts = new Array(npts).fill(null);
  10000. var ipt = 0;
  10001. pts[ipt++] = new Coordinate(ei0.coord);
  10002. for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
  10003. pts[ipt++] = this$1._edge.getCoordinate(i);
  10004. }
  10005. if (useIntPt1) { pts[ipt] = new Coordinate(ei1.coord); }
  10006. return new NodedSegmentString(pts, this._edge.getData())
  10007. };
  10008. SegmentNodeList.prototype.add = function add (intPt, segmentIndex) {
  10009. var eiNew = new SegmentNode(this._edge, intPt, segmentIndex, this._edge.getSegmentOctant(segmentIndex));
  10010. var ei = this._nodeMap.get(eiNew);
  10011. if (ei !== null) {
  10012. Assert.isTrue(ei.coord.equals2D(intPt), 'Found equal nodes with different coordinates');
  10013. return ei
  10014. }
  10015. this._nodeMap.put(eiNew, eiNew);
  10016. return eiNew
  10017. };
  10018. SegmentNodeList.prototype.checkSplitEdgesCorrectness = function checkSplitEdgesCorrectness (splitEdges) {
  10019. var edgePts = this._edge.getCoordinates();
  10020. var split0 = splitEdges.get(0);
  10021. var pt0 = split0.getCoordinate(0);
  10022. if (!pt0.equals2D(edgePts[0])) { throw new RuntimeException('bad split edge start point at ' + pt0) }
  10023. var splitn = splitEdges.get(splitEdges.size() - 1);
  10024. var splitnPts = splitn.getCoordinates();
  10025. var ptn = splitnPts[splitnPts.length - 1];
  10026. if (!ptn.equals2D(edgePts[edgePts.length - 1])) { throw new RuntimeException('bad split edge end point at ' + ptn) }
  10027. };
  10028. SegmentNodeList.prototype.interfaces_ = function interfaces_ () {
  10029. return []
  10030. };
  10031. SegmentNodeList.prototype.getClass = function getClass () {
  10032. return SegmentNodeList
  10033. };
  10034. // class NodeVertexIterator {
  10035. // constructor () {
  10036. // this._nodeList = null
  10037. // this._edge = null
  10038. // this._nodeIt = null
  10039. // this._currNode = null
  10040. // this._nextNode = null
  10041. // this._currSegIndex = 0
  10042. // let nodeList = arguments[0]
  10043. // this._nodeList = nodeList
  10044. // this._edge = nodeList.getEdge()
  10045. // this._nodeIt = nodeList.iterator()
  10046. // this.readNextNode()
  10047. // }
  10048. // next () {
  10049. // if (this._currNode === null) {
  10050. // this._currNode = this._nextNode
  10051. // this._currSegIndex = this._currNode.segmentIndex
  10052. // this.readNextNode()
  10053. // return this._currNode
  10054. // }
  10055. // if (this._nextNode === null) return null
  10056. // if (this._nextNode.segmentIndex === this._currNode.segmentIndex) {
  10057. // this._currNode = this._nextNode
  10058. // this._currSegIndex = this._currNode.segmentIndex
  10059. // this.readNextNode()
  10060. // return this._currNode
  10061. // }
  10062. // if (this._nextNode.segmentIndex > this._currNode.segmentIndex) {}
  10063. // return null
  10064. // }
  10065. // remove () {
  10066. // // throw new UnsupportedOperationException(this.getClass().getName())
  10067. // }
  10068. // hasNext () {
  10069. // if (this._nextNode === null) return false
  10070. // return true
  10071. // }
  10072. // readNextNode () {
  10073. // if (this._nodeIt.hasNext()) this._nextNode = this._nodeIt.next(); else this._nextNode = null
  10074. // }
  10075. // interfaces_ () {
  10076. // return [Iterator]
  10077. // }
  10078. // getClass () {
  10079. // return NodeVertexIterator
  10080. // }
  10081. // }
  10082. var Octant = function Octant () {};
  10083. Octant.prototype.interfaces_ = function interfaces_ () {
  10084. return []
  10085. };
  10086. Octant.prototype.getClass = function getClass () {
  10087. return Octant
  10088. };
  10089. Octant.octant = function octant () {
  10090. if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
  10091. var dx = arguments[0];
  10092. var dy = arguments[1];
  10093. if (dx === 0.0 && dy === 0.0) { throw new IllegalArgumentException('Cannot compute the octant for point ( ' + dx + ', ' + dy + ' )') }
  10094. var adx = Math.abs(dx);
  10095. var ady = Math.abs(dy);
  10096. if (dx >= 0) {
  10097. if (dy >= 0) {
  10098. if (adx >= ady) { return 0; } else { return 1 }
  10099. } else {
  10100. if (adx >= ady) { return 7; } else { return 6 }
  10101. }
  10102. } else {
  10103. if (dy >= 0) {
  10104. if (adx >= ady) { return 3; } else { return 2 }
  10105. } else {
  10106. if (adx >= ady) { return 4; } else { return 5 }
  10107. }
  10108. }
  10109. } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {
  10110. var p0 = arguments[0];
  10111. var p1 = arguments[1];
  10112. var dx$1 = p1.x - p0.x;
  10113. var dy$1 = p1.y - p0.y;
  10114. if (dx$1 === 0.0 && dy$1 === 0.0) { throw new IllegalArgumentException('Cannot compute the octant for two identical points ' + p0) }
  10115. return Octant.octant(dx$1, dy$1)
  10116. }
  10117. };
  10118. var SegmentString = function SegmentString () {};
  10119. SegmentString.prototype.getCoordinates = function getCoordinates () {};
  10120. SegmentString.prototype.size = function size () {};
  10121. SegmentString.prototype.getCoordinate = function getCoordinate (i) {};
  10122. SegmentString.prototype.isClosed = function isClosed () {};
  10123. SegmentString.prototype.setData = function setData (data) {};
  10124. SegmentString.prototype.getData = function getData () {};
  10125. SegmentString.prototype.interfaces_ = function interfaces_ () {
  10126. return []
  10127. };
  10128. SegmentString.prototype.getClass = function getClass () {
  10129. return SegmentString
  10130. };
  10131. var NodableSegmentString = function NodableSegmentString () {};
  10132. NodableSegmentString.prototype.addIntersection = function addIntersection (intPt, segmentIndex) {};
  10133. NodableSegmentString.prototype.interfaces_ = function interfaces_ () {
  10134. return [SegmentString]
  10135. };
  10136. NodableSegmentString.prototype.getClass = function getClass () {
  10137. return NodableSegmentString
  10138. };
  10139. var NodedSegmentString = function NodedSegmentString () {
  10140. this._nodeList = new SegmentNodeList(this);
  10141. this._pts = null;
  10142. this._data = null;
  10143. var pts = arguments[0];
  10144. var data = arguments[1];
  10145. this._pts = pts;
  10146. this._data = data;
  10147. };
  10148. NodedSegmentString.prototype.getCoordinates = function getCoordinates () {
  10149. return this._pts
  10150. };
  10151. NodedSegmentString.prototype.size = function size () {
  10152. return this._pts.length
  10153. };
  10154. NodedSegmentString.prototype.getCoordinate = function getCoordinate (i) {
  10155. return this._pts[i]
  10156. };
  10157. NodedSegmentString.prototype.isClosed = function isClosed () {
  10158. return this._pts[0].equals(this._pts[this._pts.length - 1])
  10159. };
  10160. NodedSegmentString.prototype.getSegmentOctant = function getSegmentOctant (index) {
  10161. if (index === this._pts.length - 1) { return -1 }
  10162. return this.safeOctant(this.getCoordinate(index), this.getCoordinate(index + 1))
  10163. };
  10164. NodedSegmentString.prototype.setData = function setData (data) {
  10165. this._data = data;
  10166. };
  10167. NodedSegmentString.prototype.safeOctant = function safeOctant (p0, p1) {
  10168. if (p0.equals2D(p1)) { return 0 }
  10169. return Octant.octant(p0, p1)
  10170. };
  10171. NodedSegmentString.prototype.getData = function getData () {
  10172. return this._data
  10173. };
  10174. NodedSegmentString.prototype.addIntersection = function addIntersection () {
  10175. if (arguments.length === 2) {
  10176. var intPt$1 = arguments[0];
  10177. var segmentIndex = arguments[1];
  10178. this.addIntersectionNode(intPt$1, segmentIndex);
  10179. } else if (arguments.length === 4) {
  10180. var li = arguments[0];
  10181. var segmentIndex$1 = arguments[1];
  10182. // const geomIndex = arguments[2]
  10183. var intIndex = arguments[3];
  10184. var intPt = new Coordinate(li.getIntersection(intIndex));
  10185. this.addIntersection(intPt, segmentIndex$1);
  10186. }
  10187. };
  10188. NodedSegmentString.prototype.toString = function toString () {
  10189. return WKTWriter.toLineString(new CoordinateArraySequence(this._pts))
  10190. };
  10191. NodedSegmentString.prototype.getNodeList = function getNodeList () {
  10192. return this._nodeList
  10193. };
  10194. NodedSegmentString.prototype.addIntersectionNode = function addIntersectionNode (intPt, segmentIndex) {
  10195. var normalizedSegmentIndex = segmentIndex;
  10196. var nextSegIndex = normalizedSegmentIndex + 1;
  10197. if (nextSegIndex < this._pts.length) {
  10198. var nextPt = this._pts[nextSegIndex];
  10199. if (intPt.equals2D(nextPt)) {
  10200. normalizedSegmentIndex = nextSegIndex;
  10201. }
  10202. }
  10203. var ei = this._nodeList.add(intPt, normalizedSegmentIndex);
  10204. return ei
  10205. };
  10206. NodedSegmentString.prototype.addIntersections = function addIntersections (li, segmentIndex, geomIndex) {
  10207. var this$1 = this;
  10208. for (var i = 0; i < li.getIntersectionNum(); i++) {
  10209. this$1.addIntersection(li, segmentIndex, geomIndex, i);
  10210. }
  10211. };
  10212. NodedSegmentString.prototype.interfaces_ = function interfaces_ () {
  10213. return [NodableSegmentString]
  10214. };
  10215. NodedSegmentString.prototype.getClass = function getClass () {
  10216. return NodedSegmentString
  10217. };
  10218. NodedSegmentString.getNodedSubstrings = function getNodedSubstrings () {
  10219. if (arguments.length === 1) {
  10220. var segStrings = arguments[0];
  10221. var resultEdgelist = new ArrayList();
  10222. NodedSegmentString.getNodedSubstrings(segStrings, resultEdgelist);
  10223. return resultEdgelist
  10224. } else if (arguments.length === 2) {
  10225. var segStrings$1 = arguments[0];
  10226. var resultEdgelist$1 = arguments[1];
  10227. for (var i = segStrings$1.iterator(); i.hasNext();) {
  10228. var ss = i.next();
  10229. ss.getNodeList().addSplitEdges(resultEdgelist$1);
  10230. }
  10231. }
  10232. };
  10233. var LineSegment = function LineSegment () {
  10234. this.p0 = null;
  10235. this.p1 = null;
  10236. if (arguments.length === 0) {
  10237. this.p0 = new Coordinate();
  10238. this.p1 = new Coordinate();
  10239. } else if (arguments.length === 1) {
  10240. var ls = arguments[0];
  10241. this.p0 = new Coordinate(ls.p0);
  10242. this.p1 = new Coordinate(ls.p1);
  10243. } else if (arguments.length === 2) {
  10244. this.p0 = arguments[0];
  10245. this.p1 = arguments[1];
  10246. } else if (arguments.length === 4) {
  10247. var x0 = arguments[0];
  10248. var y0 = arguments[1];
  10249. var x1 = arguments[2];
  10250. var y1 = arguments[3];
  10251. this.p0 = new Coordinate(x0, y0);
  10252. this.p1 = new Coordinate(x1, y1);
  10253. }
  10254. };
  10255. var staticAccessors$24 = { serialVersionUID: { configurable: true } };
  10256. LineSegment.prototype.minX = function minX () {
  10257. return Math.min(this.p0.x, this.p1.x)
  10258. };
  10259. LineSegment.prototype.orientationIndex = function orientationIndex () {
  10260. if (arguments[0] instanceof LineSegment) {
  10261. var seg = arguments[0];
  10262. var orient0 = CGAlgorithms.orientationIndex(this.p0, this.p1, seg.p0);
  10263. var orient1 = CGAlgorithms.orientationIndex(this.p0, this.p1, seg.p1);
  10264. if (orient0 >= 0 && orient1 >= 0) { return Math.max(orient0, orient1) }
  10265. if (orient0 <= 0 && orient1 <= 0) { return Math.max(orient0, orient1) }
  10266. return 0
  10267. } else if (arguments[0] instanceof Coordinate) {
  10268. var p = arguments[0];
  10269. return CGAlgorithms.orientationIndex(this.p0, this.p1, p)
  10270. }
  10271. };
  10272. LineSegment.prototype.toGeometry = function toGeometry (geomFactory) {
  10273. return geomFactory.createLineString([this.p0, this.p1])
  10274. };
  10275. LineSegment.prototype.isVertical = function isVertical () {
  10276. return this.p0.x === this.p1.x
  10277. };
  10278. LineSegment.prototype.equals = function equals (o) {
  10279. if (!(o instanceof LineSegment)) {
  10280. return false
  10281. }
  10282. var other = o;
  10283. return this.p0.equals(other.p0) && this.p1.equals(other.p1)
  10284. };
  10285. LineSegment.prototype.intersection = function intersection (line) {
  10286. var li = new RobustLineIntersector();
  10287. li.computeIntersection(this.p0, this.p1, line.p0, line.p1);
  10288. if (li.hasIntersection()) { return li.getIntersection(0) }
  10289. return null
  10290. };
  10291. LineSegment.prototype.project = function project () {
  10292. if (arguments[0] instanceof Coordinate) {
  10293. var p = arguments[0];
  10294. if (p.equals(this.p0) || p.equals(this.p1)) { return new Coordinate(p) }
  10295. var r = this.projectionFactor(p);
  10296. var coord = new Coordinate();
  10297. coord.x = this.p0.x + r * (this.p1.x - this.p0.x);
  10298. coord.y = this.p0.y + r * (this.p1.y - this.p0.y);
  10299. return coord
  10300. } else if (arguments[0] instanceof LineSegment) {
  10301. var seg = arguments[0];
  10302. var pf0 = this.projectionFactor(seg.p0);
  10303. var pf1 = this.projectionFactor(seg.p1);
  10304. if (pf0 >= 1.0 && pf1 >= 1.0) { return null }
  10305. if (pf0 <= 0.0 && pf1 <= 0.0) { return null }
  10306. var newp0 = this.project(seg.p0);
  10307. if (pf0 < 0.0) { newp0 = this.p0; }
  10308. if (pf0 > 1.0) { newp0 = this.p1; }
  10309. var newp1 = this.project(seg.p1);
  10310. if (pf1 < 0.0) { newp1 = this.p0; }
  10311. if (pf1 > 1.0) { newp1 = this.p1; }
  10312. return new LineSegment(newp0, newp1)
  10313. }
  10314. };
  10315. LineSegment.prototype.normalize = function normalize () {
  10316. if (this.p1.compareTo(this.p0) < 0) { this.reverse(); }
  10317. };
  10318. LineSegment.prototype.angle = function angle () {
  10319. return Math.atan2(this.p1.y - this.p0.y, this.p1.x - this.p0.x)
  10320. };
  10321. LineSegment.prototype.getCoordinate = function getCoordinate (i) {
  10322. if (i === 0) { return this.p0 }
  10323. return this.p1
  10324. };
  10325. LineSegment.prototype.distancePerpendicular = function distancePerpendicular (p) {
  10326. return CGAlgorithms.distancePointLinePerpendicular(p, this.p0, this.p1)
  10327. };
  10328. LineSegment.prototype.minY = function minY () {
  10329. return Math.min(this.p0.y, this.p1.y)
  10330. };
  10331. LineSegment.prototype.midPoint = function midPoint () {
  10332. return LineSegment.midPoint(this.p0, this.p1)
  10333. };
  10334. LineSegment.prototype.projectionFactor = function projectionFactor (p) {
  10335. if (p.equals(this.p0)) { return 0.0 }
  10336. if (p.equals(this.p1)) { return 1.0 }
  10337. var dx = this.p1.x - this.p0.x;
  10338. var dy = this.p1.y - this.p0.y;
  10339. var len = dx * dx + dy * dy;
  10340. if (len <= 0.0) { return Double.NaN }
  10341. var r = ((p.x - this.p0.x) * dx + (p.y - this.p0.y) * dy) / len;
  10342. return r
  10343. };
  10344. LineSegment.prototype.closestPoints = function closestPoints (line) {
  10345. var intPt = this.intersection(line);
  10346. if (intPt !== null) {
  10347. return [intPt, intPt]
  10348. }
  10349. var closestPt = new Array(2).fill(null);
  10350. var minDistance = Double.MAX_VALUE;
  10351. var dist = null;
  10352. var close00 = this.closestPoint(line.p0);
  10353. minDistance = close00.distance(line.p0);
  10354. closestPt[0] = close00;
  10355. closestPt[1] = line.p0;
  10356. var close01 = this.closestPoint(line.p1);
  10357. dist = close01.distance(line.p1);
  10358. if (dist < minDistance) {
  10359. minDistance = dist;
  10360. closestPt[0] = close01;
  10361. closestPt[1] = line.p1;
  10362. }
  10363. var close10 = line.closestPoint(this.p0);
  10364. dist = close10.distance(this.p0);
  10365. if (dist < minDistance) {
  10366. minDistance = dist;
  10367. closestPt[0] = this.p0;
  10368. closestPt[1] = close10;
  10369. }
  10370. var close11 = line.closestPoint(this.p1);
  10371. dist = close11.distance(this.p1);
  10372. if (dist < minDistance) {
  10373. minDistance = dist;
  10374. closestPt[0] = this.p1;
  10375. closestPt[1] = close11;
  10376. }
  10377. return closestPt
  10378. };
  10379. LineSegment.prototype.closestPoint = function closestPoint (p) {
  10380. var factor = this.projectionFactor(p);
  10381. if (factor > 0 && factor < 1) {
  10382. return this.project(p)
  10383. }
  10384. var dist0 = this.p0.distance(p);
  10385. var dist1 = this.p1.distance(p);
  10386. if (dist0 < dist1) { return this.p0 }
  10387. return this.p1
  10388. };
  10389. LineSegment.prototype.maxX = function maxX () {
  10390. return Math.max(this.p0.x, this.p1.x)
  10391. };
  10392. LineSegment.prototype.getLength = function getLength () {
  10393. return this.p0.distance(this.p1)
  10394. };
  10395. LineSegment.prototype.compareTo = function compareTo (o) {
  10396. var other = o;
  10397. var comp0 = this.p0.compareTo(other.p0);
  10398. if (comp0 !== 0) { return comp0 }
  10399. return this.p1.compareTo(other.p1)
  10400. };
  10401. LineSegment.prototype.reverse = function reverse () {
  10402. var temp = this.p0;
  10403. this.p0 = this.p1;
  10404. this.p1 = temp;
  10405. };
  10406. LineSegment.prototype.equalsTopo = function equalsTopo (other) {
  10407. return this.p0.equals(other.p0) &&
  10408. (this.p1.equals(other.p1) || this.p0.equals(other.p1)) &&
  10409. this.p1.equals(other.p0)
  10410. };
  10411. LineSegment.prototype.lineIntersection = function lineIntersection (line) {
  10412. try {
  10413. var intPt = HCoordinate.intersection(this.p0, this.p1, line.p0, line.p1);
  10414. return intPt
  10415. } catch (ex) {
  10416. if (ex instanceof NotRepresentableException) {} else { throw ex }
  10417. } finally {}
  10418. return null
  10419. };
  10420. LineSegment.prototype.maxY = function maxY () {
  10421. return Math.max(this.p0.y, this.p1.y)
  10422. };
  10423. LineSegment.prototype.pointAlongOffset = function pointAlongOffset (segmentLengthFraction, offsetDistance) {
  10424. var segx = this.p0.x + segmentLengthFraction * (this.p1.x - this.p0.x);
  10425. var segy = this.p0.y + segmentLengthFraction * (this.p1.y - this.p0.y);
  10426. var dx = this.p1.x - this.p0.x;
  10427. var dy = this.p1.y - this.p0.y;
  10428. var len = Math.sqrt(dx * dx + dy * dy);
  10429. var ux = 0.0;
  10430. var uy = 0.0;
  10431. if (offsetDistance !== 0.0) {
  10432. if (len <= 0.0) { throw new Error('Cannot compute offset from zero-length line segment') }
  10433. ux = offsetDistance * dx / len;
  10434. uy = offsetDistance * dy / len;
  10435. }
  10436. var offsetx = segx - uy;
  10437. var offsety = segy + ux;
  10438. var coord = new Coordinate(offsetx, offsety);
  10439. return coord
  10440. };
  10441. LineSegment.prototype.setCoordinates = function setCoordinates () {
  10442. if (arguments.length === 1) {
  10443. var ls = arguments[0];
  10444. this.setCoordinates(ls.p0, ls.p1);
  10445. } else if (arguments.length === 2) {
  10446. var p0 = arguments[0];
  10447. var p1 = arguments[1];
  10448. this.p0.x = p0.x;
  10449. this.p0.y = p0.y;
  10450. this.p1.x = p1.x;
  10451. this.p1.y = p1.y;
  10452. }
  10453. };
  10454. LineSegment.prototype.segmentFraction = function segmentFraction (inputPt) {
  10455. var segFrac = this.projectionFactor(inputPt);
  10456. if (segFrac < 0.0) { segFrac = 0.0; } else if (segFrac > 1.0 || Double.isNaN(segFrac)) { segFrac = 1.0; }
  10457. return segFrac
  10458. };
  10459. LineSegment.prototype.toString = function toString () {
  10460. return 'LINESTRING( ' + this.p0.x + ' ' + this.p0.y + ', ' + this.p1.x + ' ' + this.p1.y + ')'
  10461. };
  10462. LineSegment.prototype.isHorizontal = function isHorizontal () {
  10463. return this.p0.y === this.p1.y
  10464. };
  10465. LineSegment.prototype.distance = function distance () {
  10466. if (arguments[0] instanceof LineSegment) {
  10467. var ls = arguments[0];
  10468. return CGAlgorithms.distanceLineLine(this.p0, this.p1, ls.p0, ls.p1)
  10469. } else if (arguments[0] instanceof Coordinate) {
  10470. var p = arguments[0];
  10471. return CGAlgorithms.distancePointLine(p, this.p0, this.p1)
  10472. }
  10473. };
  10474. LineSegment.prototype.pointAlong = function pointAlong (segmentLengthFraction) {
  10475. var coord = new Coordinate();
  10476. coord.x = this.p0.x + segmentLengthFraction * (this.p1.x - this.p0.x);
  10477. coord.y = this.p0.y + segmentLengthFraction * (this.p1.y - this.p0.y);
  10478. return coord
  10479. };
  10480. LineSegment.prototype.hashCode = function hashCode () {
  10481. var bits0 = Double.doubleToLongBits(this.p0.x);
  10482. bits0 ^= Double.doubleToLongBits(this.p0.y) * 31;
  10483. var hash0 = Math.trunc(bits0) ^ Math.trunc(bits0 >> 32);
  10484. var bits1 = Double.doubleToLongBits(this.p1.x);
  10485. bits1 ^= Double.doubleToLongBits(this.p1.y) * 31;
  10486. var hash1 = Math.trunc(bits1) ^ Math.trunc(bits1 >> 32);
  10487. return hash0 ^ hash1
  10488. };
  10489. LineSegment.prototype.interfaces_ = function interfaces_ () {
  10490. return [Comparable, Serializable]
  10491. };
  10492. LineSegment.prototype.getClass = function getClass () {
  10493. return LineSegment
  10494. };
  10495. LineSegment.midPoint = function midPoint (p0, p1) {
  10496. return new Coordinate((p0.x + p1.x) / 2, (p0.y + p1.y) / 2)
  10497. };
  10498. staticAccessors$24.serialVersionUID.get = function () { return 3252005833466256227 };
  10499. Object.defineProperties( LineSegment, staticAccessors$24 );
  10500. var MonotoneChainOverlapAction = function MonotoneChainOverlapAction () {
  10501. this.tempEnv1 = new Envelope();
  10502. this.tempEnv2 = new Envelope();
  10503. this._overlapSeg1 = new LineSegment();
  10504. this._overlapSeg2 = new LineSegment();
  10505. };
  10506. MonotoneChainOverlapAction.prototype.overlap = function overlap () {
  10507. if (arguments.length === 2) {
  10508. // const seg1 = arguments[0]
  10509. // const seg2 = arguments[1]
  10510. } else if (arguments.length === 4) {
  10511. var mc1 = arguments[0];
  10512. var start1 = arguments[1];
  10513. var mc2 = arguments[2];
  10514. var start2 = arguments[3];
  10515. mc1.getLineSegment(start1, this._overlapSeg1);
  10516. mc2.getLineSegment(start2, this._overlapSeg2);
  10517. this.overlap(this._overlapSeg1, this._overlapSeg2);
  10518. }
  10519. };
  10520. MonotoneChainOverlapAction.prototype.interfaces_ = function interfaces_ () {
  10521. return []
  10522. };
  10523. MonotoneChainOverlapAction.prototype.getClass = function getClass () {
  10524. return MonotoneChainOverlapAction
  10525. };
  10526. var MonotoneChain = function MonotoneChain () {
  10527. this._pts = null;
  10528. this._start = null;
  10529. this._end = null;
  10530. this._env = null;
  10531. this._context = null;
  10532. this._id = null;
  10533. var pts = arguments[0];
  10534. var start = arguments[1];
  10535. var end = arguments[2];
  10536. var context = arguments[3];
  10537. this._pts = pts;
  10538. this._start = start;
  10539. this._end = end;
  10540. this._context = context;
  10541. };
  10542. MonotoneChain.prototype.getLineSegment = function getLineSegment (index, ls) {
  10543. ls.p0 = this._pts[index];
  10544. ls.p1 = this._pts[index + 1];
  10545. };
  10546. MonotoneChain.prototype.computeSelect = function computeSelect (searchEnv, start0, end0, mcs) {
  10547. var p0 = this._pts[start0];
  10548. var p1 = this._pts[end0];
  10549. mcs.tempEnv1.init(p0, p1);
  10550. if (end0 - start0 === 1) {
  10551. mcs.select(this, start0);
  10552. return null
  10553. }
  10554. if (!searchEnv.intersects(mcs.tempEnv1)) { return null }
  10555. var mid = Math.trunc((start0 + end0) / 2);
  10556. if (start0 < mid) {
  10557. this.computeSelect(searchEnv, start0, mid, mcs);
  10558. }
  10559. if (mid < end0) {
  10560. this.computeSelect(searchEnv, mid, end0, mcs);
  10561. }
  10562. };
  10563. MonotoneChain.prototype.getCoordinates = function getCoordinates () {
  10564. var this$1 = this;
  10565. var coord = new Array(this._end - this._start + 1).fill(null);
  10566. var index = 0;
  10567. for (var i = this._start; i <= this._end; i++) {
  10568. coord[index++] = this$1._pts[i];
  10569. }
  10570. return coord
  10571. };
  10572. MonotoneChain.prototype.computeOverlaps = function computeOverlaps (mc, mco) {
  10573. this.computeOverlapsInternal(this._start, this._end, mc, mc._start, mc._end, mco);
  10574. };
  10575. MonotoneChain.prototype.setId = function setId (id) {
  10576. this._id = id;
  10577. };
  10578. MonotoneChain.prototype.select = function select (searchEnv, mcs) {
  10579. this.computeSelect(searchEnv, this._start, this._end, mcs);
  10580. };
  10581. MonotoneChain.prototype.getEnvelope = function getEnvelope () {
  10582. if (this._env === null) {
  10583. var p0 = this._pts[this._start];
  10584. var p1 = this._pts[this._end];
  10585. this._env = new Envelope(p0, p1);
  10586. }
  10587. return this._env
  10588. };
  10589. MonotoneChain.prototype.getEndIndex = function getEndIndex () {
  10590. return this._end
  10591. };
  10592. MonotoneChain.prototype.getStartIndex = function getStartIndex () {
  10593. return this._start
  10594. };
  10595. MonotoneChain.prototype.getContext = function getContext () {
  10596. return this._context
  10597. };
  10598. MonotoneChain.prototype.getId = function getId () {
  10599. return this._id
  10600. };
  10601. MonotoneChain.prototype.computeOverlapsInternal = function computeOverlapsInternal (start0, end0, mc, start1, end1, mco) {
  10602. var p00 = this._pts[start0];
  10603. var p01 = this._pts[end0];
  10604. var p10 = mc._pts[start1];
  10605. var p11 = mc._pts[end1];
  10606. if (end0 - start0 === 1 && end1 - start1 === 1) {
  10607. mco.overlap(this, start0, mc, start1);
  10608. return null
  10609. }
  10610. mco.tempEnv1.init(p00, p01);
  10611. mco.tempEnv2.init(p10, p11);
  10612. if (!mco.tempEnv1.intersects(mco.tempEnv2)) { return null }
  10613. var mid0 = Math.trunc((start0 + end0) / 2);
  10614. var mid1 = Math.trunc((start1 + end1) / 2);
  10615. if (start0 < mid0) {
  10616. if (start1 < mid1) { this.computeOverlapsInternal(start0, mid0, mc, start1, mid1, mco); }
  10617. if (mid1 < end1) { this.computeOverlapsInternal(start0, mid0, mc, mid1, end1, mco); }
  10618. }
  10619. if (mid0 < end0) {
  10620. if (start1 < mid1) { this.computeOverlapsInternal(mid0, end0, mc, start1, mid1, mco); }
  10621. if (mid1 < end1) { this.computeOverlapsInternal(mid0, end0, mc, mid1, end1, mco); }
  10622. }
  10623. };
  10624. MonotoneChain.prototype.interfaces_ = function interfaces_ () {
  10625. return []
  10626. };
  10627. MonotoneChain.prototype.getClass = function getClass () {
  10628. return MonotoneChain
  10629. };
  10630. var MonotoneChainBuilder = function MonotoneChainBuilder () {};
  10631. MonotoneChainBuilder.prototype.interfaces_ = function interfaces_ () {
  10632. return []
  10633. };
  10634. MonotoneChainBuilder.prototype.getClass = function getClass () {
  10635. return MonotoneChainBuilder
  10636. };
  10637. MonotoneChainBuilder.getChainStartIndices = function getChainStartIndices (pts) {
  10638. var start = 0;
  10639. var startIndexList = new ArrayList();
  10640. startIndexList.add(new Integer(start));
  10641. do {
  10642. var last = MonotoneChainBuilder.findChainEnd(pts, start);
  10643. startIndexList.add(new Integer(last));
  10644. start = last;
  10645. } while (start < pts.length - 1)
  10646. var startIndex = MonotoneChainBuilder.toIntArray(startIndexList);
  10647. return startIndex
  10648. };
  10649. MonotoneChainBuilder.findChainEnd = function findChainEnd (pts, start) {
  10650. var safeStart = start;
  10651. while (safeStart < pts.length - 1 && pts[safeStart].equals2D(pts[safeStart + 1])) {
  10652. safeStart++;
  10653. }
  10654. if (safeStart >= pts.length - 1) {
  10655. return pts.length - 1
  10656. }
  10657. var chainQuad = Quadrant.quadrant(pts[safeStart], pts[safeStart + 1]);
  10658. var last = start + 1;
  10659. while (last < pts.length) {
  10660. if (!pts[last - 1].equals2D(pts[last])) {
  10661. var quad = Quadrant.quadrant(pts[last - 1], pts[last]);
  10662. if (quad !== chainQuad) { break }
  10663. }
  10664. last++;
  10665. }
  10666. return last - 1
  10667. };
  10668. MonotoneChainBuilder.getChains = function getChains () {
  10669. if (arguments.length === 1) {
  10670. var pts = arguments[0];
  10671. return MonotoneChainBuilder.getChains(pts, null)
  10672. } else if (arguments.length === 2) {
  10673. var pts$1 = arguments[0];
  10674. var context = arguments[1];
  10675. var mcList = new ArrayList();
  10676. var startIndex = MonotoneChainBuilder.getChainStartIndices(pts$1);
  10677. for (var i = 0; i < startIndex.length - 1; i++) {
  10678. var mc = new MonotoneChain(pts$1, startIndex[i], startIndex[i + 1], context);
  10679. mcList.add(mc);
  10680. }
  10681. return mcList
  10682. }
  10683. };
  10684. MonotoneChainBuilder.toIntArray = function toIntArray (list) {
  10685. var array = new Array(list.size()).fill(null);
  10686. for (var i = 0; i < array.length; i++) {
  10687. array[i] = list.get(i).intValue();
  10688. }
  10689. return array
  10690. };
  10691. var Noder = function Noder () {};
  10692. Noder.prototype.computeNodes = function computeNodes (segStrings) {};
  10693. Noder.prototype.getNodedSubstrings = function getNodedSubstrings () {};
  10694. Noder.prototype.interfaces_ = function interfaces_ () {
  10695. return []
  10696. };
  10697. Noder.prototype.getClass = function getClass () {
  10698. return Noder
  10699. };
  10700. var SinglePassNoder = function SinglePassNoder () {
  10701. this._segInt = null;
  10702. if (arguments.length === 0) {} else if (arguments.length === 1) {
  10703. var segInt = arguments[0];
  10704. this.setSegmentIntersector(segInt);
  10705. }
  10706. };
  10707. SinglePassNoder.prototype.setSegmentIntersector = function setSegmentIntersector (segInt) {
  10708. this._segInt = segInt;
  10709. };
  10710. SinglePassNoder.prototype.interfaces_ = function interfaces_ () {
  10711. return [Noder]
  10712. };
  10713. SinglePassNoder.prototype.getClass = function getClass () {
  10714. return SinglePassNoder
  10715. };
  10716. var MCIndexNoder = (function (SinglePassNoder$$1) {
  10717. function MCIndexNoder (si) {
  10718. if (si) { SinglePassNoder$$1.call(this, si); }
  10719. else { SinglePassNoder$$1.call(this); }
  10720. this._monoChains = new ArrayList();
  10721. this._index = new STRtree();
  10722. this._idCounter = 0;
  10723. this._nodedSegStrings = null;
  10724. this._nOverlaps = 0;
  10725. }
  10726. if ( SinglePassNoder$$1 ) MCIndexNoder.__proto__ = SinglePassNoder$$1;
  10727. MCIndexNoder.prototype = Object.create( SinglePassNoder$$1 && SinglePassNoder$$1.prototype );
  10728. MCIndexNoder.prototype.constructor = MCIndexNoder;
  10729. var staticAccessors = { SegmentOverlapAction: { configurable: true } };
  10730. MCIndexNoder.prototype.getMonotoneChains = function getMonotoneChains () {
  10731. return this._monoChains
  10732. };
  10733. MCIndexNoder.prototype.getNodedSubstrings = function getNodedSubstrings () {
  10734. return NodedSegmentString.getNodedSubstrings(this._nodedSegStrings)
  10735. };
  10736. MCIndexNoder.prototype.getIndex = function getIndex () {
  10737. return this._index
  10738. };
  10739. MCIndexNoder.prototype.add = function add (segStr) {
  10740. var this$1 = this;
  10741. var segChains = MonotoneChainBuilder.getChains(segStr.getCoordinates(), segStr);
  10742. for (var i = segChains.iterator(); i.hasNext();) {
  10743. var mc = i.next();
  10744. mc.setId(this$1._idCounter++);
  10745. this$1._index.insert(mc.getEnvelope(), mc);
  10746. this$1._monoChains.add(mc);
  10747. }
  10748. };
  10749. MCIndexNoder.prototype.computeNodes = function computeNodes (inputSegStrings) {
  10750. var this$1 = this;
  10751. this._nodedSegStrings = inputSegStrings;
  10752. for (var i = inputSegStrings.iterator(); i.hasNext();) {
  10753. this$1.add(i.next());
  10754. }
  10755. this.intersectChains();
  10756. };
  10757. MCIndexNoder.prototype.intersectChains = function intersectChains () {
  10758. var this$1 = this;
  10759. var overlapAction = new SegmentOverlapAction(this._segInt);
  10760. for (var i = this._monoChains.iterator(); i.hasNext();) {
  10761. var queryChain = i.next();
  10762. var overlapChains = this$1._index.query(queryChain.getEnvelope());
  10763. for (var j = overlapChains.iterator(); j.hasNext();) {
  10764. var testChain = j.next();
  10765. if (testChain.getId() > queryChain.getId()) {
  10766. queryChain.computeOverlaps(testChain, overlapAction);
  10767. this$1._nOverlaps++;
  10768. }
  10769. if (this$1._segInt.isDone()) { return null }
  10770. }
  10771. }
  10772. };
  10773. MCIndexNoder.prototype.interfaces_ = function interfaces_ () {
  10774. return []
  10775. };
  10776. MCIndexNoder.prototype.getClass = function getClass () {
  10777. return MCIndexNoder
  10778. };
  10779. staticAccessors.SegmentOverlapAction.get = function () { return SegmentOverlapAction };
  10780. Object.defineProperties( MCIndexNoder, staticAccessors );
  10781. return MCIndexNoder;
  10782. }(SinglePassNoder));
  10783. var SegmentOverlapAction = (function (MonotoneChainOverlapAction$$1) {
  10784. function SegmentOverlapAction () {
  10785. MonotoneChainOverlapAction$$1.call(this);
  10786. this._si = null;
  10787. var si = arguments[0];
  10788. this._si = si;
  10789. }
  10790. if ( MonotoneChainOverlapAction$$1 ) SegmentOverlapAction.__proto__ = MonotoneChainOverlapAction$$1;
  10791. SegmentOverlapAction.prototype = Object.create( MonotoneChainOverlapAction$$1 && MonotoneChainOverlapAction$$1.prototype );
  10792. SegmentOverlapAction.prototype.constructor = SegmentOverlapAction;
  10793. SegmentOverlapAction.prototype.overlap = function overlap () {
  10794. if (arguments.length === 4) {
  10795. var mc1 = arguments[0];
  10796. var start1 = arguments[1];
  10797. var mc2 = arguments[2];
  10798. var start2 = arguments[3];
  10799. var ss1 = mc1.getContext();
  10800. var ss2 = mc2.getContext();
  10801. this._si.processIntersections(ss1, start1, ss2, start2);
  10802. } else { return MonotoneChainOverlapAction$$1.prototype.overlap.apply(this, arguments) }
  10803. };
  10804. SegmentOverlapAction.prototype.interfaces_ = function interfaces_ () {
  10805. return []
  10806. };
  10807. SegmentOverlapAction.prototype.getClass = function getClass () {
  10808. return SegmentOverlapAction
  10809. };
  10810. return SegmentOverlapAction;
  10811. }(MonotoneChainOverlapAction));
  10812. var BufferParameters = function BufferParameters () {
  10813. this._quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS;
  10814. this._endCapStyle = BufferParameters.CAP_ROUND;
  10815. this._joinStyle = BufferParameters.JOIN_ROUND;
  10816. this._mitreLimit = BufferParameters.DEFAULT_MITRE_LIMIT;
  10817. this._isSingleSided = false;
  10818. this._simplifyFactor = BufferParameters.DEFAULT_SIMPLIFY_FACTOR;
  10819. if (arguments.length === 0) {} else if (arguments.length === 1) {
  10820. var quadrantSegments = arguments[0];
  10821. this.setQuadrantSegments(quadrantSegments);
  10822. } else if (arguments.length === 2) {
  10823. var quadrantSegments$1 = arguments[0];
  10824. var endCapStyle = arguments[1];
  10825. this.setQuadrantSegments(quadrantSegments$1);
  10826. this.setEndCapStyle(endCapStyle);
  10827. } else if (arguments.length === 4) {
  10828. var quadrantSegments$2 = arguments[0];
  10829. var endCapStyle$1 = arguments[1];
  10830. var joinStyle = arguments[2];
  10831. var mitreLimit = arguments[3];
  10832. this.setQuadrantSegments(quadrantSegments$2);
  10833. this.setEndCapStyle(endCapStyle$1);
  10834. this.setJoinStyle(joinStyle);
  10835. this.setMitreLimit(mitreLimit);
  10836. }
  10837. };
  10838. 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 } };
  10839. BufferParameters.prototype.getEndCapStyle = function getEndCapStyle () {
  10840. return this._endCapStyle
  10841. };
  10842. BufferParameters.prototype.isSingleSided = function isSingleSided () {
  10843. return this._isSingleSided
  10844. };
  10845. BufferParameters.prototype.setQuadrantSegments = function setQuadrantSegments (quadSegs) {
  10846. this._quadrantSegments = quadSegs;
  10847. if (this._quadrantSegments === 0) { this._joinStyle = BufferParameters.JOIN_BEVEL; }
  10848. if (this._quadrantSegments < 0) {
  10849. this._joinStyle = BufferParameters.JOIN_MITRE;
  10850. this._mitreLimit = Math.abs(this._quadrantSegments);
  10851. }
  10852. if (quadSegs <= 0) {
  10853. this._quadrantSegments = 1;
  10854. }
  10855. if (this._joinStyle !== BufferParameters.JOIN_ROUND) {
  10856. this._quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS;
  10857. }
  10858. };
  10859. BufferParameters.prototype.getJoinStyle = function getJoinStyle () {
  10860. return this._joinStyle
  10861. };
  10862. BufferParameters.prototype.setJoinStyle = function setJoinStyle (joinStyle) {
  10863. this._joinStyle = joinStyle;
  10864. };
  10865. BufferParameters.prototype.setSimplifyFactor = function setSimplifyFactor (simplifyFactor) {
  10866. this._simplifyFactor = simplifyFactor < 0 ? 0 : simplifyFactor;
  10867. };
  10868. BufferParameters.prototype.getSimplifyFactor = function getSimplifyFactor () {
  10869. return this._simplifyFactor
  10870. };
  10871. BufferParameters.prototype.getQuadrantSegments = function getQuadrantSegments () {
  10872. return this._quadrantSegments
  10873. };
  10874. BufferParameters.prototype.setEndCapStyle = function setEndCapStyle (endCapStyle) {
  10875. this._endCapStyle = endCapStyle;
  10876. };
  10877. BufferParameters.prototype.getMitreLimit = function getMitreLimit () {
  10878. return this._mitreLimit
  10879. };
  10880. BufferParameters.prototype.setMitreLimit = function setMitreLimit (mitreLimit) {
  10881. this._mitreLimit = mitreLimit;
  10882. };
  10883. BufferParameters.prototype.setSingleSided = function setSingleSided (isSingleSided) {
  10884. this._isSingleSided = isSingleSided;
  10885. };
  10886. BufferParameters.prototype.interfaces_ = function interfaces_ () {
  10887. return []
  10888. };
  10889. BufferParameters.prototype.getClass = function getClass () {
  10890. return BufferParameters
  10891. };
  10892. BufferParameters.bufferDistanceError = function bufferDistanceError (quadSegs) {
  10893. var alpha = Math.PI / 2.0 / quadSegs;
  10894. return 1 - Math.cos(alpha / 2.0)
  10895. };
  10896. staticAccessors$25.CAP_ROUND.get = function () { return 1 };
  10897. staticAccessors$25.CAP_FLAT.get = function () { return 2 };
  10898. staticAccessors$25.CAP_SQUARE.get = function () { return 3 };
  10899. staticAccessors$25.JOIN_ROUND.get = function () { return 1 };
  10900. staticAccessors$25.JOIN_MITRE.get = function () { return 2 };
  10901. staticAccessors$25.JOIN_BEVEL.get = function () { return 3 };
  10902. staticAccessors$25.DEFAULT_QUADRANT_SEGMENTS.get = function () { return 8 };
  10903. staticAccessors$25.DEFAULT_MITRE_LIMIT.get = function () { return 5.0 };
  10904. staticAccessors$25.DEFAULT_SIMPLIFY_FACTOR.get = function () { return 0.01 };
  10905. Object.defineProperties( BufferParameters, staticAccessors$25 );
  10906. var BufferInputLineSimplifier = function BufferInputLineSimplifier (inputLine) {
  10907. this._distanceTol = null;
  10908. this._isDeleted = null;
  10909. this._angleOrientation = CGAlgorithms.COUNTERCLOCKWISE;
  10910. this._inputLine = inputLine || null;
  10911. };
  10912. var staticAccessors$26 = { INIT: { configurable: true },DELETE: { configurable: true },KEEP: { configurable: true },NUM_PTS_TO_CHECK: { configurable: true } };
  10913. BufferInputLineSimplifier.prototype.isDeletable = function isDeletable (i0, i1, i2, distanceTol) {
  10914. var p0 = this._inputLine[i0];
  10915. var p1 = this._inputLine[i1];
  10916. var p2 = this._inputLine[i2];
  10917. if (!this.isConcave(p0, p1, p2)) { return false }
  10918. if (!this.isShallow(p0, p1, p2, distanceTol)) { return false }
  10919. return this.isShallowSampled(p0, p1, i0, i2, distanceTol)
  10920. };
  10921. BufferInputLineSimplifier.prototype.deleteShallowConcavities = function deleteShallowConcavities () {
  10922. var this$1 = this;
  10923. var index = 1;
  10924. // const maxIndex = this._inputLine.length - 1
  10925. var midIndex = this.findNextNonDeletedIndex(index);
  10926. var lastIndex = this.findNextNonDeletedIndex(midIndex);
  10927. var isChanged = false;
  10928. while (lastIndex < this._inputLine.length) {
  10929. var isMiddleVertexDeleted = false;
  10930. if (this$1.isDeletable(index, midIndex, lastIndex, this$1._distanceTol)) {
  10931. this$1._isDeleted[midIndex] = BufferInputLineSimplifier.DELETE;
  10932. isMiddleVertexDeleted = true;
  10933. isChanged = true;
  10934. }
  10935. if (isMiddleVertexDeleted) { index = lastIndex; } else { index = midIndex; }
  10936. midIndex = this$1.findNextNonDeletedIndex(index);
  10937. lastIndex = this$1.findNextNonDeletedIndex(midIndex);
  10938. }
  10939. return isChanged
  10940. };
  10941. BufferInputLineSimplifier.prototype.isShallowConcavity = function isShallowConcavity (p0, p1, p2, distanceTol) {
  10942. var orientation = CGAlgorithms.computeOrientation(p0, p1, p2);
  10943. var isAngleToSimplify = orientation === this._angleOrientation;
  10944. if (!isAngleToSimplify) { return false }
  10945. var dist = CGAlgorithms.distancePointLine(p1, p0, p2);
  10946. return dist < distanceTol
  10947. };
  10948. BufferInputLineSimplifier.prototype.isShallowSampled = function isShallowSampled (p0, p2, i0, i2, distanceTol) {
  10949. var this$1 = this;
  10950. var inc = Math.trunc((i2 - i0) / BufferInputLineSimplifier.NUM_PTS_TO_CHECK);
  10951. if (inc <= 0) { inc = 1; }
  10952. for (var i = i0; i < i2; i += inc) {
  10953. if (!this$1.isShallow(p0, p2, this$1._inputLine[i], distanceTol)) { return false }
  10954. }
  10955. return true
  10956. };
  10957. BufferInputLineSimplifier.prototype.isConcave = function isConcave (p0, p1, p2) {
  10958. var orientation = CGAlgorithms.computeOrientation(p0, p1, p2);
  10959. var isConcave = orientation === this._angleOrientation;
  10960. return isConcave
  10961. };
  10962. BufferInputLineSimplifier.prototype.simplify = function simplify (distanceTol) {
  10963. var this$1 = this;
  10964. this._distanceTol = Math.abs(distanceTol);
  10965. if (distanceTol < 0) { this._angleOrientation = CGAlgorithms.CLOCKWISE; }
  10966. this._isDeleted = new Array(this._inputLine.length).fill(null);
  10967. var isChanged = false;
  10968. do {
  10969. isChanged = this$1.deleteShallowConcavities();
  10970. } while (isChanged)
  10971. return this.collapseLine()
  10972. };
  10973. BufferInputLineSimplifier.prototype.findNextNonDeletedIndex = function findNextNonDeletedIndex (index) {
  10974. var next = index + 1;
  10975. while (next < this._inputLine.length && this._isDeleted[next] === BufferInputLineSimplifier.DELETE) { next++; }
  10976. return next
  10977. };
  10978. BufferInputLineSimplifier.prototype.isShallow = function isShallow (p0, p1, p2, distanceTol) {
  10979. var dist = CGAlgorithms.distancePointLine(p1, p0, p2);
  10980. return dist < distanceTol
  10981. };
  10982. BufferInputLineSimplifier.prototype.collapseLine = function collapseLine () {
  10983. var this$1 = this;
  10984. var coordList = new CoordinateList();
  10985. for (var i = 0; i < this._inputLine.length; i++) {
  10986. if (this$1._isDeleted[i] !== BufferInputLineSimplifier.DELETE) { coordList.add(this$1._inputLine[i]); }
  10987. }
  10988. return coordList.toCoordinateArray()
  10989. };
  10990. BufferInputLineSimplifier.prototype.interfaces_ = function interfaces_ () {
  10991. return []
  10992. };
  10993. BufferInputLineSimplifier.prototype.getClass = function getClass () {
  10994. return BufferInputLineSimplifier
  10995. };
  10996. BufferInputLineSimplifier.simplify = function simplify (inputLine, distanceTol) {
  10997. var simp = new BufferInputLineSimplifier(inputLine);
  10998. return simp.simplify(distanceTol)
  10999. };
  11000. staticAccessors$26.INIT.get = function () { return 0 };
  11001. staticAccessors$26.DELETE.get = function () { return 1 };
  11002. staticAccessors$26.KEEP.get = function () { return 1 };
  11003. staticAccessors$26.NUM_PTS_TO_CHECK.get = function () { return 10 };
  11004. Object.defineProperties( BufferInputLineSimplifier, staticAccessors$26 );
  11005. var OffsetSegmentString = function OffsetSegmentString () {
  11006. this._ptList = null;
  11007. this._precisionModel = null;
  11008. this._minimimVertexDistance = 0.0;
  11009. this._ptList = new ArrayList();
  11010. };
  11011. var staticAccessors$28 = { COORDINATE_ARRAY_TYPE: { configurable: true } };
  11012. OffsetSegmentString.prototype.getCoordinates = function getCoordinates () {
  11013. var coord = this._ptList.toArray(OffsetSegmentString.COORDINATE_ARRAY_TYPE);
  11014. return coord
  11015. };
  11016. OffsetSegmentString.prototype.setPrecisionModel = function setPrecisionModel (precisionModel) {
  11017. this._precisionModel = precisionModel;
  11018. };
  11019. OffsetSegmentString.prototype.addPt = function addPt (pt) {
  11020. var bufPt = new Coordinate(pt);
  11021. this._precisionModel.makePrecise(bufPt);
  11022. if (this.isRedundant(bufPt)) { return null }
  11023. this._ptList.add(bufPt);
  11024. };
  11025. OffsetSegmentString.prototype.revere = function revere () {};
  11026. OffsetSegmentString.prototype.addPts = function addPts (pt, isForward) {
  11027. var this$1 = this;
  11028. if (isForward) {
  11029. for (var i = 0; i < pt.length; i++) {
  11030. this$1.addPt(pt[i]);
  11031. }
  11032. } else {
  11033. for (var i$1 = pt.length - 1; i$1 >= 0; i$1--) {
  11034. this$1.addPt(pt[i$1]);
  11035. }
  11036. }
  11037. };
  11038. OffsetSegmentString.prototype.isRedundant = function isRedundant (pt) {
  11039. if (this._ptList.size() < 1) { return false }
  11040. var lastPt = this._ptList.get(this._ptList.size() - 1);
  11041. var ptDist = pt.distance(lastPt);
  11042. if (ptDist < this._minimimVertexDistance) { return true }
  11043. return false
  11044. };
  11045. OffsetSegmentString.prototype.toString = function toString () {
  11046. var fact = new GeometryFactory();
  11047. var line = fact.createLineString(this.getCoordinates());
  11048. return line.toString()
  11049. };
  11050. OffsetSegmentString.prototype.closeRing = function closeRing () {
  11051. if (this._ptList.size() < 1) { return null }
  11052. var startPt = new Coordinate(this._ptList.get(0));
  11053. var lastPt = this._ptList.get(this._ptList.size() - 1);
  11054. // const last2Pt = null
  11055. // if (this._ptList.size() >= 2) last2Pt = this._ptList.get(this._ptList.size() - 2)
  11056. if (startPt.equals(lastPt)) { return null }
  11057. this._ptList.add(startPt);
  11058. };
  11059. OffsetSegmentString.prototype.setMinimumVertexDistance = function setMinimumVertexDistance (minimimVertexDistance) {
  11060. this._minimimVertexDistance = minimimVertexDistance;
  11061. };
  11062. OffsetSegmentString.prototype.interfaces_ = function interfaces_ () {
  11063. return []
  11064. };
  11065. OffsetSegmentString.prototype.getClass = function getClass () {
  11066. return OffsetSegmentString
  11067. };
  11068. staticAccessors$28.COORDINATE_ARRAY_TYPE.get = function () { return new Array(0).fill(null) };
  11069. Object.defineProperties( OffsetSegmentString, staticAccessors$28 );
  11070. var Angle = function Angle () {};
  11071. 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 } };
  11072. Angle.prototype.interfaces_ = function interfaces_ () {
  11073. return []
  11074. };
  11075. Angle.prototype.getClass = function getClass () {
  11076. return Angle
  11077. };
  11078. Angle.toDegrees = function toDegrees (radians) {
  11079. return radians * 180 / Math.PI
  11080. };
  11081. Angle.normalize = function normalize (angle) {
  11082. while (angle > Math.PI) { angle -= Angle.PI_TIMES_2; }
  11083. while (angle <= -Math.PI) { angle += Angle.PI_TIMES_2; }
  11084. return angle
  11085. };
  11086. Angle.angle = function angle () {
  11087. if (arguments.length === 1) {
  11088. var p = arguments[0];
  11089. return Math.atan2(p.y, p.x)
  11090. } else if (arguments.length === 2) {
  11091. var p0 = arguments[0];
  11092. var p1 = arguments[1];
  11093. var dx = p1.x - p0.x;
  11094. var dy = p1.y - p0.y;
  11095. return Math.atan2(dy, dx)
  11096. }
  11097. };
  11098. Angle.isAcute = function isAcute (p0, p1, p2) {
  11099. var dx0 = p0.x - p1.x;
  11100. var dy0 = p0.y - p1.y;
  11101. var dx1 = p2.x - p1.x;
  11102. var dy1 = p2.y - p1.y;
  11103. var dotprod = dx0 * dx1 + dy0 * dy1;
  11104. return dotprod > 0
  11105. };
  11106. Angle.isObtuse = function isObtuse (p0, p1, p2) {
  11107. var dx0 = p0.x - p1.x;
  11108. var dy0 = p0.y - p1.y;
  11109. var dx1 = p2.x - p1.x;
  11110. var dy1 = p2.y - p1.y;
  11111. var dotprod = dx0 * dx1 + dy0 * dy1;
  11112. return dotprod < 0
  11113. };
  11114. Angle.interiorAngle = function interiorAngle (p0, p1, p2) {
  11115. var anglePrev = Angle.angle(p1, p0);
  11116. var angleNext = Angle.angle(p1, p2);
  11117. return Math.abs(angleNext - anglePrev)
  11118. };
  11119. Angle.normalizePositive = function normalizePositive (angle) {
  11120. if (angle < 0.0) {
  11121. while (angle < 0.0) { angle += Angle.PI_TIMES_2; }
  11122. if (angle >= Angle.PI_TIMES_2) { angle = 0.0; }
  11123. } else {
  11124. while (angle >= Angle.PI_TIMES_2) { angle -= Angle.PI_TIMES_2; }
  11125. if (angle < 0.0) { angle = 0.0; }
  11126. }
  11127. return angle
  11128. };
  11129. Angle.angleBetween = function angleBetween (tip1, tail, tip2) {
  11130. var a1 = Angle.angle(tail, tip1);
  11131. var a2 = Angle.angle(tail, tip2);
  11132. return Angle.diff(a1, a2)
  11133. };
  11134. Angle.diff = function diff (ang1, ang2) {
  11135. var delAngle = null;
  11136. if (ang1 < ang2) {
  11137. delAngle = ang2 - ang1;
  11138. } else {
  11139. delAngle = ang1 - ang2;
  11140. }
  11141. if (delAngle > Math.PI) {
  11142. delAngle = 2 * Math.PI - delAngle;
  11143. }
  11144. return delAngle
  11145. };
  11146. Angle.toRadians = function toRadians (angleDegrees) {
  11147. return angleDegrees * Math.PI / 180.0
  11148. };
  11149. Angle.getTurn = function getTurn (ang1, ang2) {
  11150. var crossproduct = Math.sin(ang2 - ang1);
  11151. if (crossproduct > 0) {
  11152. return Angle.COUNTERCLOCKWISE
  11153. }
  11154. if (crossproduct < 0) {
  11155. return Angle.CLOCKWISE
  11156. }
  11157. return Angle.NONE
  11158. };
  11159. Angle.angleBetweenOriented = function angleBetweenOriented (tip1, tail, tip2) {
  11160. var a1 = Angle.angle(tail, tip1);
  11161. var a2 = Angle.angle(tail, tip2);
  11162. var angDel = a2 - a1;
  11163. if (angDel <= -Math.PI) { return angDel + Angle.PI_TIMES_2 }
  11164. if (angDel > Math.PI) { return angDel - Angle.PI_TIMES_2 }
  11165. return angDel
  11166. };
  11167. staticAccessors$29.PI_TIMES_2.get = function () { return 2.0 * Math.PI };
  11168. staticAccessors$29.PI_OVER_2.get = function () { return Math.PI / 2.0 };
  11169. staticAccessors$29.PI_OVER_4.get = function () { return Math.PI / 4.0 };
  11170. staticAccessors$29.COUNTERCLOCKWISE.get = function () { return CGAlgorithms.COUNTERCLOCKWISE };
  11171. staticAccessors$29.CLOCKWISE.get = function () { return CGAlgorithms.CLOCKWISE };
  11172. staticAccessors$29.NONE.get = function () { return CGAlgorithms.COLLINEAR };
  11173. Object.defineProperties( Angle, staticAccessors$29 );
  11174. var OffsetSegmentGenerator = function OffsetSegmentGenerator () {
  11175. this._maxCurveSegmentError = 0.0;
  11176. this._filletAngleQuantum = null;
  11177. this._closingSegLengthFactor = 1;
  11178. this._segList = null;
  11179. this._distance = 0.0;
  11180. this._precisionModel = null;
  11181. this._bufParams = null;
  11182. this._li = null;
  11183. this._s0 = null;
  11184. this._s1 = null;
  11185. this._s2 = null;
  11186. this._seg0 = new LineSegment();
  11187. this._seg1 = new LineSegment();
  11188. this._offset0 = new LineSegment();
  11189. this._offset1 = new LineSegment();
  11190. this._side = 0;
  11191. this._hasNarrowConcaveAngle = false;
  11192. var precisionModel = arguments[0];
  11193. var bufParams = arguments[1];
  11194. var distance = arguments[2];
  11195. this._precisionModel = precisionModel;
  11196. this._bufParams = bufParams;
  11197. this._li = new RobustLineIntersector();
  11198. this._filletAngleQuantum = Math.PI / 2.0 / bufParams.getQuadrantSegments();
  11199. if (bufParams.getQuadrantSegments() >= 8 && bufParams.getJoinStyle() === BufferParameters.JOIN_ROUND) { this._closingSegLengthFactor = OffsetSegmentGenerator.MAX_CLOSING_SEG_LEN_FACTOR; }
  11200. this.init(distance);
  11201. };
  11202. 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 } };
  11203. OffsetSegmentGenerator.prototype.addNextSegment = function addNextSegment (p, addStartPoint) {
  11204. this._s0 = this._s1;
  11205. this._s1 = this._s2;
  11206. this._s2 = p;
  11207. this._seg0.setCoordinates(this._s0, this._s1);
  11208. this.computeOffsetSegment(this._seg0, this._side, this._distance, this._offset0);
  11209. this._seg1.setCoordinates(this._s1, this._s2);
  11210. this.computeOffsetSegment(this._seg1, this._side, this._distance, this._offset1);
  11211. if (this._s1.equals(this._s2)) { return null }
  11212. var orientation = CGAlgorithms.computeOrientation(this._s0, this._s1, this._s2);
  11213. var outsideTurn = (orientation === CGAlgorithms.CLOCKWISE && this._side === Position.LEFT) || (orientation === CGAlgorithms.COUNTERCLOCKWISE && this._side === Position.RIGHT);
  11214. if (orientation === 0) {
  11215. this.addCollinear(addStartPoint);
  11216. } else if (outsideTurn) {
  11217. this.addOutsideTurn(orientation, addStartPoint);
  11218. } else {
  11219. this.addInsideTurn(orientation, addStartPoint);
  11220. }
  11221. };
  11222. OffsetSegmentGenerator.prototype.addLineEndCap = function addLineEndCap (p0, p1) {
  11223. var seg = new LineSegment(p0, p1);
  11224. var offsetL = new LineSegment();
  11225. this.computeOffsetSegment(seg, Position.LEFT, this._distance, offsetL);
  11226. var offsetR = new LineSegment();
  11227. this.computeOffsetSegment(seg, Position.RIGHT, this._distance, offsetR);
  11228. var dx = p1.x - p0.x;
  11229. var dy = p1.y - p0.y;
  11230. var angle = Math.atan2(dy, dx);
  11231. switch (this._bufParams.getEndCapStyle()) {
  11232. case BufferParameters.CAP_ROUND:
  11233. this._segList.addPt(offsetL.p1);
  11234. this.addFilletArc(p1, angle + Math.PI / 2, angle - Math.PI / 2, CGAlgorithms.CLOCKWISE, this._distance);
  11235. this._segList.addPt(offsetR.p1);
  11236. break
  11237. case BufferParameters.CAP_FLAT:
  11238. this._segList.addPt(offsetL.p1);
  11239. this._segList.addPt(offsetR.p1);
  11240. break
  11241. case BufferParameters.CAP_SQUARE:
  11242. var squareCapSideOffset = new Coordinate();
  11243. squareCapSideOffset.x = Math.abs(this._distance) * Math.cos(angle);
  11244. squareCapSideOffset.y = Math.abs(this._distance) * Math.sin(angle);
  11245. var squareCapLOffset = new Coordinate(offsetL.p1.x + squareCapSideOffset.x, offsetL.p1.y + squareCapSideOffset.y);
  11246. var squareCapROffset = new Coordinate(offsetR.p1.x + squareCapSideOffset.x, offsetR.p1.y + squareCapSideOffset.y);
  11247. this._segList.addPt(squareCapLOffset);
  11248. this._segList.addPt(squareCapROffset);
  11249. break
  11250. default:
  11251. }
  11252. };
  11253. OffsetSegmentGenerator.prototype.getCoordinates = function getCoordinates () {
  11254. var pts = this._segList.getCoordinates();
  11255. return pts
  11256. };
  11257. OffsetSegmentGenerator.prototype.addMitreJoin = function addMitreJoin (p, offset0, offset1, distance) {
  11258. var isMitreWithinLimit = true;
  11259. var intPt = null;
  11260. try {
  11261. intPt = HCoordinate.intersection(offset0.p0, offset0.p1, offset1.p0, offset1.p1);
  11262. var mitreRatio = distance <= 0.0 ? 1.0 : intPt.distance(p) / Math.abs(distance);
  11263. if (mitreRatio > this._bufParams.getMitreLimit()) { isMitreWithinLimit = false; }
  11264. } catch (ex) {
  11265. if (ex instanceof NotRepresentableException) {
  11266. intPt = new Coordinate(0, 0);
  11267. isMitreWithinLimit = false;
  11268. } else { throw ex }
  11269. } finally {}
  11270. if (isMitreWithinLimit) {
  11271. this._segList.addPt(intPt);
  11272. } else {
  11273. this.addLimitedMitreJoin(offset0, offset1, distance, this._bufParams.getMitreLimit());
  11274. }
  11275. };
  11276. OffsetSegmentGenerator.prototype.addFilletCorner = function addFilletCorner (p, p0, p1, direction, radius) {
  11277. var dx0 = p0.x - p.x;
  11278. var dy0 = p0.y - p.y;
  11279. var startAngle = Math.atan2(dy0, dx0);
  11280. var dx1 = p1.x - p.x;
  11281. var dy1 = p1.y - p.y;
  11282. var endAngle = Math.atan2(dy1, dx1);
  11283. if (direction === CGAlgorithms.CLOCKWISE) {
  11284. if (startAngle <= endAngle) { startAngle += 2.0 * Math.PI; }
  11285. } else {
  11286. if (startAngle >= endAngle) { startAngle -= 2.0 * Math.PI; }
  11287. }
  11288. this._segList.addPt(p0);
  11289. this.addFilletArc(p, startAngle, endAngle, direction, radius);
  11290. this._segList.addPt(p1);
  11291. };
  11292. OffsetSegmentGenerator.prototype.addOutsideTurn = function addOutsideTurn (orientation, addStartPoint) {
  11293. if (this._offset0.p1.distance(this._offset1.p0) < this._distance * OffsetSegmentGenerator.OFFSET_SEGMENT_SEPARATION_FACTOR) {
  11294. this._segList.addPt(this._offset0.p1);
  11295. return null
  11296. }
  11297. if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_MITRE) {
  11298. this.addMitreJoin(this._s1, this._offset0, this._offset1, this._distance);
  11299. } else if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_BEVEL) {
  11300. this.addBevelJoin(this._offset0, this._offset1);
  11301. } else {
  11302. if (addStartPoint) { this._segList.addPt(this._offset0.p1); }
  11303. this.addFilletCorner(this._s1, this._offset0.p1, this._offset1.p0, orientation, this._distance);
  11304. this._segList.addPt(this._offset1.p0);
  11305. }
  11306. };
  11307. OffsetSegmentGenerator.prototype.createSquare = function createSquare (p) {
  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.addPt(new Coordinate(p.x - this._distance, p.y - this._distance));
  11311. this._segList.addPt(new Coordinate(p.x - this._distance, p.y + this._distance));
  11312. this._segList.closeRing();
  11313. };
  11314. OffsetSegmentGenerator.prototype.addSegments = function addSegments (pt, isForward) {
  11315. this._segList.addPts(pt, isForward);
  11316. };
  11317. OffsetSegmentGenerator.prototype.addFirstSegment = function addFirstSegment () {
  11318. this._segList.addPt(this._offset1.p0);
  11319. };
  11320. OffsetSegmentGenerator.prototype.addLastSegment = function addLastSegment () {
  11321. this._segList.addPt(this._offset1.p1);
  11322. };
  11323. OffsetSegmentGenerator.prototype.initSideSegments = function initSideSegments (s1, s2, side) {
  11324. this._s1 = s1;
  11325. this._s2 = s2;
  11326. this._side = side;
  11327. this._seg1.setCoordinates(s1, s2);
  11328. this.computeOffsetSegment(this._seg1, side, this._distance, this._offset1);
  11329. };
  11330. OffsetSegmentGenerator.prototype.addLimitedMitreJoin = function addLimitedMitreJoin (offset0, offset1, distance, mitreLimit) {
  11331. var basePt = this._seg0.p1;
  11332. var ang0 = Angle.angle(basePt, this._seg0.p0);
  11333. // const ang1 = Angle.angle(basePt, this._seg1.p1)
  11334. var angDiff = Angle.angleBetweenOriented(this._seg0.p0, basePt, this._seg1.p1);
  11335. var angDiffHalf = angDiff / 2;
  11336. var midAng = Angle.normalize(ang0 + angDiffHalf);
  11337. var mitreMidAng = Angle.normalize(midAng + Math.PI);
  11338. var mitreDist = mitreLimit * distance;
  11339. var bevelDelta = mitreDist * Math.abs(Math.sin(angDiffHalf));
  11340. var bevelHalfLen = distance - bevelDelta;
  11341. var bevelMidX = basePt.x + mitreDist * Math.cos(mitreMidAng);
  11342. var bevelMidY = basePt.y + mitreDist * Math.sin(mitreMidAng);
  11343. var bevelMidPt = new Coordinate(bevelMidX, bevelMidY);
  11344. var mitreMidLine = new LineSegment(basePt, bevelMidPt);
  11345. var bevelEndLeft = mitreMidLine.pointAlongOffset(1.0, bevelHalfLen);
  11346. var bevelEndRight = mitreMidLine.pointAlongOffset(1.0, -bevelHalfLen);
  11347. if (this._side === Position.LEFT) {
  11348. this._segList.addPt(bevelEndLeft);
  11349. this._segList.addPt(bevelEndRight);
  11350. } else {
  11351. this._segList.addPt(bevelEndRight);
  11352. this._segList.addPt(bevelEndLeft);
  11353. }
  11354. };
  11355. OffsetSegmentGenerator.prototype.computeOffsetSegment = function computeOffsetSegment (seg, side, distance, offset) {
  11356. var sideSign = side === Position.LEFT ? 1 : -1;
  11357. var dx = seg.p1.x - seg.p0.x;
  11358. var dy = seg.p1.y - seg.p0.y;
  11359. var len = Math.sqrt(dx * dx + dy * dy);
  11360. var ux = sideSign * distance * dx / len;
  11361. var uy = sideSign * distance * dy / len;
  11362. offset.p0.x = seg.p0.x - uy;
  11363. offset.p0.y = seg.p0.y + ux;
  11364. offset.p1.x = seg.p1.x - uy;
  11365. offset.p1.y = seg.p1.y + ux;
  11366. };
  11367. OffsetSegmentGenerator.prototype.addFilletArc = function addFilletArc (p, startAngle, endAngle, direction, radius) {
  11368. var this$1 = this;
  11369. var directionFactor = direction === CGAlgorithms.CLOCKWISE ? -1 : 1;
  11370. var totalAngle = Math.abs(startAngle - endAngle);
  11371. var nSegs = Math.trunc(totalAngle / this._filletAngleQuantum + 0.5);
  11372. if (nSegs < 1) { return null }
  11373. var initAngle = 0.0;
  11374. var currAngleInc = totalAngle / nSegs;
  11375. var currAngle = initAngle;
  11376. var pt = new Coordinate();
  11377. while (currAngle < totalAngle) {
  11378. var angle = startAngle + directionFactor * currAngle;
  11379. pt.x = p.x + radius * Math.cos(angle);
  11380. pt.y = p.y + radius * Math.sin(angle);
  11381. this$1._segList.addPt(pt);
  11382. currAngle += currAngleInc;
  11383. }
  11384. };
  11385. OffsetSegmentGenerator.prototype.addInsideTurn = function addInsideTurn (orientation, addStartPoint) {
  11386. this._li.computeIntersection(this._offset0.p0, this._offset0.p1, this._offset1.p0, this._offset1.p1);
  11387. if (this._li.hasIntersection()) {
  11388. this._segList.addPt(this._li.getIntersection(0));
  11389. } else {
  11390. this._hasNarrowConcaveAngle = true;
  11391. if (this._offset0.p1.distance(this._offset1.p0) < this._distance * OffsetSegmentGenerator.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR) {
  11392. this._segList.addPt(this._offset0.p1);
  11393. } else {
  11394. this._segList.addPt(this._offset0.p1);
  11395. if (this._closingSegLengthFactor > 0) {
  11396. 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));
  11397. this._segList.addPt(mid0);
  11398. 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));
  11399. this._segList.addPt(mid1);
  11400. } else {
  11401. this._segList.addPt(this._s1);
  11402. }
  11403. this._segList.addPt(this._offset1.p0);
  11404. }
  11405. }
  11406. };
  11407. OffsetSegmentGenerator.prototype.createCircle = function createCircle (p) {
  11408. var pt = new Coordinate(p.x + this._distance, p.y);
  11409. this._segList.addPt(pt);
  11410. this.addFilletArc(p, 0.0, 2.0 * Math.PI, -1, this._distance);
  11411. this._segList.closeRing();
  11412. };
  11413. OffsetSegmentGenerator.prototype.addBevelJoin = function addBevelJoin (offset0, offset1) {
  11414. this._segList.addPt(offset0.p1);
  11415. this._segList.addPt(offset1.p0);
  11416. };
  11417. OffsetSegmentGenerator.prototype.init = function init (distance) {
  11418. this._distance = distance;
  11419. this._maxCurveSegmentError = distance * (1 - Math.cos(this._filletAngleQuantum / 2.0));
  11420. this._segList = new OffsetSegmentString();
  11421. this._segList.setPrecisionModel(this._precisionModel);
  11422. this._segList.setMinimumVertexDistance(distance * OffsetSegmentGenerator.CURVE_VERTEX_SNAP_DISTANCE_FACTOR);
  11423. };
  11424. OffsetSegmentGenerator.prototype.addCollinear = function addCollinear (addStartPoint) {
  11425. this._li.computeIntersection(this._s0, this._s1, this._s1, this._s2);
  11426. var numInt = this._li.getIntersectionNum();
  11427. if (numInt >= 2) {
  11428. if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_BEVEL || this._bufParams.getJoinStyle() === BufferParameters.JOIN_MITRE) {
  11429. if (addStartPoint) { this._segList.addPt(this._offset0.p1); }
  11430. this._segList.addPt(this._offset1.p0);
  11431. } else {
  11432. this.addFilletCorner(this._s1, this._offset0.p1, this._offset1.p0, CGAlgorithms.CLOCKWISE, this._distance);
  11433. }
  11434. }
  11435. };
  11436. OffsetSegmentGenerator.prototype.closeRing = function closeRing () {
  11437. this._segList.closeRing();
  11438. };
  11439. OffsetSegmentGenerator.prototype.hasNarrowConcaveAngle = function hasNarrowConcaveAngle () {
  11440. return this._hasNarrowConcaveAngle
  11441. };
  11442. OffsetSegmentGenerator.prototype.interfaces_ = function interfaces_ () {
  11443. return []
  11444. };
  11445. OffsetSegmentGenerator.prototype.getClass = function getClass () {
  11446. return OffsetSegmentGenerator
  11447. };
  11448. staticAccessors$27.OFFSET_SEGMENT_SEPARATION_FACTOR.get = function () { return 1.0E-3 };
  11449. staticAccessors$27.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR.get = function () { return 1.0E-3 };
  11450. staticAccessors$27.CURVE_VERTEX_SNAP_DISTANCE_FACTOR.get = function () { return 1.0E-6 };
  11451. staticAccessors$27.MAX_CLOSING_SEG_LEN_FACTOR.get = function () { return 80 };
  11452. Object.defineProperties( OffsetSegmentGenerator, staticAccessors$27 );
  11453. var OffsetCurveBuilder = function OffsetCurveBuilder () {
  11454. this._distance = 0.0;
  11455. this._precisionModel = null;
  11456. this._bufParams = null;
  11457. var precisionModel = arguments[0];
  11458. var bufParams = arguments[1];
  11459. this._precisionModel = precisionModel;
  11460. this._bufParams = bufParams;
  11461. };
  11462. OffsetCurveBuilder.prototype.getOffsetCurve = function getOffsetCurve (inputPts, distance) {
  11463. this._distance = distance;
  11464. if (distance === 0.0) { return null }
  11465. var isRightSide = distance < 0.0;
  11466. var posDistance = Math.abs(distance);
  11467. var segGen = this.getSegGen(posDistance);
  11468. if (inputPts.length <= 1) {
  11469. this.computePointCurve(inputPts[0], segGen);
  11470. } else {
  11471. this.computeOffsetCurve(inputPts, isRightSide, segGen);
  11472. }
  11473. var curvePts = segGen.getCoordinates();
  11474. if (isRightSide) { CoordinateArrays.reverse(curvePts); }
  11475. return curvePts
  11476. };
  11477. OffsetCurveBuilder.prototype.computeSingleSidedBufferCurve = function computeSingleSidedBufferCurve (inputPts, isRightSide, segGen) {
  11478. var distTol = this.simplifyTolerance(this._distance);
  11479. if (isRightSide) {
  11480. segGen.addSegments(inputPts, true);
  11481. var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);
  11482. var n2 = simp2.length - 1;
  11483. segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);
  11484. segGen.addFirstSegment();
  11485. for (var i = n2 - 2; i >= 0; i--) {
  11486. segGen.addNextSegment(simp2[i], true);
  11487. }
  11488. } else {
  11489. segGen.addSegments(inputPts, false);
  11490. var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);
  11491. var n1 = simp1.length - 1;
  11492. segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);
  11493. segGen.addFirstSegment();
  11494. for (var i$1 = 2; i$1 <= n1; i$1++) {
  11495. segGen.addNextSegment(simp1[i$1], true);
  11496. }
  11497. }
  11498. segGen.addLastSegment();
  11499. segGen.closeRing();
  11500. };
  11501. OffsetCurveBuilder.prototype.computeRingBufferCurve = function computeRingBufferCurve (inputPts, side, segGen) {
  11502. var distTol = this.simplifyTolerance(this._distance);
  11503. if (side === Position.RIGHT) { distTol = -distTol; }
  11504. var simp = BufferInputLineSimplifier.simplify(inputPts, distTol);
  11505. var n = simp.length - 1;
  11506. segGen.initSideSegments(simp[n - 1], simp[0], side);
  11507. for (var i = 1; i <= n; i++) {
  11508. var addStartPoint = i !== 1;
  11509. segGen.addNextSegment(simp[i], addStartPoint);
  11510. }
  11511. segGen.closeRing();
  11512. };
  11513. OffsetCurveBuilder.prototype.computeLineBufferCurve = function computeLineBufferCurve (inputPts, segGen) {
  11514. var distTol = this.simplifyTolerance(this._distance);
  11515. var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);
  11516. var n1 = simp1.length - 1;
  11517. segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);
  11518. for (var i = 2; i <= n1; i++) {
  11519. segGen.addNextSegment(simp1[i], true);
  11520. }
  11521. segGen.addLastSegment();
  11522. segGen.addLineEndCap(simp1[n1 - 1], simp1[n1]);
  11523. var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);
  11524. var n2 = simp2.length - 1;
  11525. segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);
  11526. for (var i$1 = n2 - 2; i$1 >= 0; i$1--) {
  11527. segGen.addNextSegment(simp2[i$1], true);
  11528. }
  11529. segGen.addLastSegment();
  11530. segGen.addLineEndCap(simp2[1], simp2[0]);
  11531. segGen.closeRing();
  11532. };
  11533. OffsetCurveBuilder.prototype.computePointCurve = function computePointCurve (pt, segGen) {
  11534. switch (this._bufParams.getEndCapStyle()) {
  11535. case BufferParameters.CAP_ROUND:
  11536. segGen.createCircle(pt);
  11537. break
  11538. case BufferParameters.CAP_SQUARE:
  11539. segGen.createSquare(pt);
  11540. break
  11541. default:
  11542. }
  11543. };
  11544. OffsetCurveBuilder.prototype.getLineCurve = function getLineCurve (inputPts, distance) {
  11545. this._distance = distance;
  11546. if (distance < 0.0 && !this._bufParams.isSingleSided()) { return null }
  11547. if (distance === 0.0) { return null }
  11548. var posDistance = Math.abs(distance);
  11549. var segGen = this.getSegGen(posDistance);
  11550. if (inputPts.length <= 1) {
  11551. this.computePointCurve(inputPts[0], segGen);
  11552. } else {
  11553. if (this._bufParams.isSingleSided()) {
  11554. var isRightSide = distance < 0.0;
  11555. this.computeSingleSidedBufferCurve(inputPts, isRightSide, segGen);
  11556. } else { this.computeLineBufferCurve(inputPts, segGen); }
  11557. }
  11558. var lineCoord = segGen.getCoordinates();
  11559. return lineCoord
  11560. };
  11561. OffsetCurveBuilder.prototype.getBufferParameters = function getBufferParameters () {
  11562. return this._bufParams
  11563. };
  11564. OffsetCurveBuilder.prototype.simplifyTolerance = function simplifyTolerance (bufDistance) {
  11565. return bufDistance * this._bufParams.getSimplifyFactor()
  11566. };
  11567. OffsetCurveBuilder.prototype.getRingCurve = function getRingCurve (inputPts, side, distance) {
  11568. this._distance = distance;
  11569. if (inputPts.length <= 2) { return this.getLineCurve(inputPts, distance) }
  11570. if (distance === 0.0) {
  11571. return OffsetCurveBuilder.copyCoordinates(inputPts)
  11572. }
  11573. var segGen = this.getSegGen(distance);
  11574. this.computeRingBufferCurve(inputPts, side, segGen);
  11575. return segGen.getCoordinates()
  11576. };
  11577. OffsetCurveBuilder.prototype.computeOffsetCurve = function computeOffsetCurve (inputPts, isRightSide, segGen) {
  11578. var distTol = this.simplifyTolerance(this._distance);
  11579. if (isRightSide) {
  11580. var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);
  11581. var n2 = simp2.length - 1;
  11582. segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);
  11583. segGen.addFirstSegment();
  11584. for (var i = n2 - 2; i >= 0; i--) {
  11585. segGen.addNextSegment(simp2[i], true);
  11586. }
  11587. } else {
  11588. var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);
  11589. var n1 = simp1.length - 1;
  11590. segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);
  11591. segGen.addFirstSegment();
  11592. for (var i$1 = 2; i$1 <= n1; i$1++) {
  11593. segGen.addNextSegment(simp1[i$1], true);
  11594. }
  11595. }
  11596. segGen.addLastSegment();
  11597. };
  11598. OffsetCurveBuilder.prototype.getSegGen = function getSegGen (distance) {
  11599. return new OffsetSegmentGenerator(this._precisionModel, this._bufParams, distance)
  11600. };
  11601. OffsetCurveBuilder.prototype.interfaces_ = function interfaces_ () {
  11602. return []
  11603. };
  11604. OffsetCurveBuilder.prototype.getClass = function getClass () {
  11605. return OffsetCurveBuilder
  11606. };
  11607. OffsetCurveBuilder.copyCoordinates = function copyCoordinates (pts) {
  11608. var copy = new Array(pts.length).fill(null);
  11609. for (var i = 0; i < copy.length; i++) {
  11610. copy[i] = new Coordinate(pts[i]);
  11611. }
  11612. return copy
  11613. };
  11614. var SubgraphDepthLocater = function SubgraphDepthLocater () {
  11615. this._subgraphs = null;
  11616. this._seg = new LineSegment();
  11617. this._cga = new CGAlgorithms();
  11618. var subgraphs = arguments[0];
  11619. this._subgraphs = subgraphs;
  11620. };
  11621. var staticAccessors$30 = { DepthSegment: { configurable: true } };
  11622. SubgraphDepthLocater.prototype.findStabbedSegments = function findStabbedSegments () {
  11623. var this$1 = this;
  11624. if (arguments.length === 1) {
  11625. var stabbingRayLeftPt = arguments[0];
  11626. var stabbedSegments = new ArrayList();
  11627. for (var i = this._subgraphs.iterator(); i.hasNext();) {
  11628. var bsg = i.next();
  11629. var env = bsg.getEnvelope();
  11630. if (stabbingRayLeftPt.y < env.getMinY() || stabbingRayLeftPt.y > env.getMaxY()) { continue }
  11631. this$1.findStabbedSegments(stabbingRayLeftPt, bsg.getDirectedEdges(), stabbedSegments);
  11632. }
  11633. return stabbedSegments
  11634. } else if (arguments.length === 3) {
  11635. if (hasInterface(arguments[2], List) && (arguments[0] instanceof Coordinate && arguments[1] instanceof DirectedEdge)) {
  11636. var stabbingRayLeftPt$1 = arguments[0];
  11637. var dirEdge = arguments[1];
  11638. var stabbedSegments$1 = arguments[2];
  11639. var pts = dirEdge.getEdge().getCoordinates();
  11640. for (var i$1 = 0; i$1 < pts.length - 1; i$1++) {
  11641. this$1._seg.p0 = pts[i$1];
  11642. this$1._seg.p1 = pts[i$1 + 1];
  11643. if (this$1._seg.p0.y > this$1._seg.p1.y) { this$1._seg.reverse(); }
  11644. var maxx = Math.max(this$1._seg.p0.x, this$1._seg.p1.x);
  11645. if (maxx < stabbingRayLeftPt$1.x) { continue }
  11646. if (this$1._seg.isHorizontal()) { continue }
  11647. if (stabbingRayLeftPt$1.y < this$1._seg.p0.y || stabbingRayLeftPt$1.y > this$1._seg.p1.y) { continue }
  11648. if (CGAlgorithms.computeOrientation(this$1._seg.p0, this$1._seg.p1, stabbingRayLeftPt$1) === CGAlgorithms.RIGHT) { continue }
  11649. var depth = dirEdge.getDepth(Position.LEFT);
  11650. if (!this$1._seg.p0.equals(pts[i$1])) { depth = dirEdge.getDepth(Position.RIGHT); }
  11651. var ds = new DepthSegment(this$1._seg, depth);
  11652. stabbedSegments$1.add(ds);
  11653. }
  11654. } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Coordinate && hasInterface(arguments[1], List))) {
  11655. var stabbingRayLeftPt$2 = arguments[0];
  11656. var dirEdges = arguments[1];
  11657. var stabbedSegments$2 = arguments[2];
  11658. for (var i$2 = dirEdges.iterator(); i$2.hasNext();) {
  11659. var de = i$2.next();
  11660. if (!de.isForward()) { continue }
  11661. this$1.findStabbedSegments(stabbingRayLeftPt$2, de, stabbedSegments$2);
  11662. }
  11663. }
  11664. }
  11665. };
  11666. SubgraphDepthLocater.prototype.getDepth = function getDepth (p) {
  11667. var stabbedSegments = this.findStabbedSegments(p);
  11668. if (stabbedSegments.size() === 0) { return 0 }
  11669. var ds = Collections.min(stabbedSegments);
  11670. return ds._leftDepth
  11671. };
  11672. SubgraphDepthLocater.prototype.interfaces_ = function interfaces_ () {
  11673. return []
  11674. };
  11675. SubgraphDepthLocater.prototype.getClass = function getClass () {
  11676. return SubgraphDepthLocater
  11677. };
  11678. staticAccessors$30.DepthSegment.get = function () { return DepthSegment };
  11679. Object.defineProperties( SubgraphDepthLocater, staticAccessors$30 );
  11680. var DepthSegment = function DepthSegment () {
  11681. this._upwardSeg = null;
  11682. this._leftDepth = null;
  11683. var seg = arguments[0];
  11684. var depth = arguments[1];
  11685. this._upwardSeg = new LineSegment(seg);
  11686. this._leftDepth = depth;
  11687. };
  11688. DepthSegment.prototype.compareTo = function compareTo (obj) {
  11689. var other = obj;
  11690. if (this._upwardSeg.minX() >= other._upwardSeg.maxX()) { return 1 }
  11691. if (this._upwardSeg.maxX() <= other._upwardSeg.minX()) { return -1 }
  11692. var orientIndex = this._upwardSeg.orientationIndex(other._upwardSeg);
  11693. if (orientIndex !== 0) { return orientIndex }
  11694. orientIndex = -1 * other._upwardSeg.orientationIndex(this._upwardSeg);
  11695. if (orientIndex !== 0) { return orientIndex }
  11696. return this._upwardSeg.compareTo(other._upwardSeg)
  11697. };
  11698. DepthSegment.prototype.compareX = function compareX (seg0, seg1) {
  11699. var compare0 = seg0.p0.compareTo(seg1.p0);
  11700. if (compare0 !== 0) { return compare0 }
  11701. return seg0.p1.compareTo(seg1.p1)
  11702. };
  11703. DepthSegment.prototype.toString = function toString () {
  11704. return this._upwardSeg.toString()
  11705. };
  11706. DepthSegment.prototype.interfaces_ = function interfaces_ () {
  11707. return [Comparable]
  11708. };
  11709. DepthSegment.prototype.getClass = function getClass () {
  11710. return DepthSegment
  11711. };
  11712. var Triangle = function Triangle (p0, p1, p2) {
  11713. this.p0 = p0 || null;
  11714. this.p1 = p1 || null;
  11715. this.p2 = p2 || null;
  11716. };
  11717. Triangle.prototype.area = function area () {
  11718. return Triangle.area(this.p0, this.p1, this.p2)
  11719. };
  11720. Triangle.prototype.signedArea = function signedArea () {
  11721. return Triangle.signedArea(this.p0, this.p1, this.p2)
  11722. };
  11723. Triangle.prototype.interpolateZ = function interpolateZ (p) {
  11724. if (p === null) { throw new IllegalArgumentException('Supplied point is null.') }
  11725. return Triangle.interpolateZ(p, this.p0, this.p1, this.p2)
  11726. };
  11727. Triangle.prototype.longestSideLength = function longestSideLength () {
  11728. return Triangle.longestSideLength(this.p0, this.p1, this.p2)
  11729. };
  11730. Triangle.prototype.isAcute = function isAcute () {
  11731. return Triangle.isAcute(this.p0, this.p1, this.p2)
  11732. };
  11733. Triangle.prototype.circumcentre = function circumcentre () {
  11734. return Triangle.circumcentre(this.p0, this.p1, this.p2)
  11735. };
  11736. Triangle.prototype.area3D = function area3D () {
  11737. return Triangle.area3D(this.p0, this.p1, this.p2)
  11738. };
  11739. Triangle.prototype.centroid = function centroid () {
  11740. return Triangle.centroid(this.p0, this.p1, this.p2)
  11741. };
  11742. Triangle.prototype.inCentre = function inCentre () {
  11743. return Triangle.inCentre(this.p0, this.p1, this.p2)
  11744. };
  11745. Triangle.prototype.interfaces_ = function interfaces_ () {
  11746. return []
  11747. };
  11748. Triangle.prototype.getClass = function getClass () {
  11749. return Triangle
  11750. };
  11751. Triangle.area = function area (a, b, c) {
  11752. return Math.abs(((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2)
  11753. };
  11754. Triangle.signedArea = function signedArea (a, b, c) {
  11755. return ((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2
  11756. };
  11757. Triangle.det = function det (m00, m01, m10, m11) {
  11758. return m00 * m11 - m01 * m10
  11759. };
  11760. Triangle.interpolateZ = function interpolateZ (p, v0, v1, v2) {
  11761. var x0 = v0.x;
  11762. var y0 = v0.y;
  11763. var a = v1.x - x0;
  11764. var b = v2.x - x0;
  11765. var c = v1.y - y0;
  11766. var d = v2.y - y0;
  11767. var det = a * d - b * c;
  11768. var dx = p.x - x0;
  11769. var dy = p.y - y0;
  11770. var t = (d * dx - b * dy) / det;
  11771. var u = (-c * dx + a * dy) / det;
  11772. var z = v0.z + t * (v1.z - v0.z) + u * (v2.z - v0.z);
  11773. return z
  11774. };
  11775. Triangle.longestSideLength = function longestSideLength (a, b, c) {
  11776. var lenAB = a.distance(b);
  11777. var lenBC = b.distance(c);
  11778. var lenCA = c.distance(a);
  11779. var maxLen = lenAB;
  11780. if (lenBC > maxLen) { maxLen = lenBC; }
  11781. if (lenCA > maxLen) { maxLen = lenCA; }
  11782. return maxLen
  11783. };
  11784. Triangle.isAcute = function isAcute (a, b, c) {
  11785. if (!Angle.isAcute(a, b, c)) { return false }
  11786. if (!Angle.isAcute(b, c, a)) { return false }
  11787. if (!Angle.isAcute(c, a, b)) { return false }
  11788. return true
  11789. };
  11790. Triangle.circumcentre = function circumcentre (a, b, c) {
  11791. var cx = c.x;
  11792. var cy = c.y;
  11793. var ax = a.x - cx;
  11794. var ay = a.y - cy;
  11795. var bx = b.x - cx;
  11796. var by = b.y - cy;
  11797. var denom = 2 * Triangle.det(ax, ay, bx, by);
  11798. var numx = Triangle.det(ay, ax * ax + ay * ay, by, bx * bx + by * by);
  11799. var numy = Triangle.det(ax, ax * ax + ay * ay, bx, bx * bx + by * by);
  11800. var ccx = cx - numx / denom;
  11801. var ccy = cy + numy / denom;
  11802. return new Coordinate(ccx, ccy)
  11803. };
  11804. Triangle.perpendicularBisector = function perpendicularBisector (a, b) {
  11805. var dx = b.x - a.x;
  11806. var dy = b.y - a.y;
  11807. var l1 = new HCoordinate(a.x + dx / 2.0, a.y + dy / 2.0, 1.0);
  11808. var l2 = new HCoordinate(a.x - dy + dx / 2.0, a.y + dx + dy / 2.0, 1.0);
  11809. return new HCoordinate(l1, l2)
  11810. };
  11811. Triangle.angleBisector = function angleBisector (a, b, c) {
  11812. var len0 = b.distance(a);
  11813. var len2 = b.distance(c);
  11814. var frac = len0 / (len0 + len2);
  11815. var dx = c.x - a.x;
  11816. var dy = c.y - a.y;
  11817. var splitPt = new Coordinate(a.x + frac * dx, a.y + frac * dy);
  11818. return splitPt
  11819. };
  11820. Triangle.area3D = function area3D (a, b, c) {
  11821. var ux = b.x - a.x;
  11822. var uy = b.y - a.y;
  11823. var uz = b.z - a.z;
  11824. var vx = c.x - a.x;
  11825. var vy = c.y - a.y;
  11826. var vz = c.z - a.z;
  11827. var crossx = uy * vz - uz * vy;
  11828. var crossy = uz * vx - ux * vz;
  11829. var crossz = ux * vy - uy * vx;
  11830. var absSq = crossx * crossx + crossy * crossy + crossz * crossz;
  11831. var area3D = Math.sqrt(absSq) / 2;
  11832. return area3D
  11833. };
  11834. Triangle.centroid = function centroid (a, b, c) {
  11835. var x = (a.x + b.x + c.x) / 3;
  11836. var y = (a.y + b.y + c.y) / 3;
  11837. return new Coordinate(x, y)
  11838. };
  11839. Triangle.inCentre = function inCentre (a, b, c) {
  11840. var len0 = b.distance(c);
  11841. var len1 = a.distance(c);
  11842. var len2 = a.distance(b);
  11843. var circum = len0 + len1 + len2;
  11844. var inCentreX = (len0 * a.x + len1 * b.x + len2 * c.x) / circum;
  11845. var inCentreY = (len0 * a.y + len1 * b.y + len2 * c.y) / circum;
  11846. return new Coordinate(inCentreX, inCentreY)
  11847. };
  11848. var OffsetCurveSetBuilder = function OffsetCurveSetBuilder () {
  11849. this._inputGeom = null;
  11850. this._distance = null;
  11851. this._curveBuilder = null;
  11852. this._curveList = new ArrayList();
  11853. var inputGeom = arguments[0];
  11854. var distance = arguments[1];
  11855. var curveBuilder = arguments[2];
  11856. this._inputGeom = inputGeom;
  11857. this._distance = distance;
  11858. this._curveBuilder = curveBuilder;
  11859. };
  11860. OffsetCurveSetBuilder.prototype.addPoint = function addPoint (p) {
  11861. if (this._distance <= 0.0) { return null }
  11862. var coord = p.getCoordinates();
  11863. var curve = this._curveBuilder.getLineCurve(coord, this._distance);
  11864. this.addCurve(curve, Location.EXTERIOR, Location.INTERIOR);
  11865. };
  11866. OffsetCurveSetBuilder.prototype.addPolygon = function addPolygon (p) {
  11867. var this$1 = this;
  11868. var offsetDistance = this._distance;
  11869. var offsetSide = Position.LEFT;
  11870. if (this._distance < 0.0) {
  11871. offsetDistance = -this._distance;
  11872. offsetSide = Position.RIGHT;
  11873. }
  11874. var shell = p.getExteriorRing();
  11875. var shellCoord = CoordinateArrays.removeRepeatedPoints(shell.getCoordinates());
  11876. if (this._distance < 0.0 && this.isErodedCompletely(shell, this._distance)) { return null }
  11877. if (this._distance <= 0.0 && shellCoord.length < 3) { return null }
  11878. this.addPolygonRing(shellCoord, offsetDistance, offsetSide, Location.EXTERIOR, Location.INTERIOR);
  11879. for (var i = 0; i < p.getNumInteriorRing(); i++) {
  11880. var hole = p.getInteriorRingN(i);
  11881. var holeCoord = CoordinateArrays.removeRepeatedPoints(hole.getCoordinates());
  11882. if (this$1._distance > 0.0 && this$1.isErodedCompletely(hole, -this$1._distance)) { continue }
  11883. this$1.addPolygonRing(holeCoord, offsetDistance, Position.opposite(offsetSide), Location.INTERIOR, Location.EXTERIOR);
  11884. }
  11885. };
  11886. OffsetCurveSetBuilder.prototype.isTriangleErodedCompletely = function isTriangleErodedCompletely (triangleCoord, bufferDistance) {
  11887. var tri = new Triangle(triangleCoord[0], triangleCoord[1], triangleCoord[2]);
  11888. var inCentre = tri.inCentre();
  11889. var distToCentre = CGAlgorithms.distancePointLine(inCentre, tri.p0, tri.p1);
  11890. return distToCentre < Math.abs(bufferDistance)
  11891. };
  11892. OffsetCurveSetBuilder.prototype.addLineString = function addLineString (line) {
  11893. if (this._distance <= 0.0 && !this._curveBuilder.getBufferParameters().isSingleSided()) { return null }
  11894. var coord = CoordinateArrays.removeRepeatedPoints(line.getCoordinates());
  11895. var curve = this._curveBuilder.getLineCurve(coord, this._distance);
  11896. this.addCurve(curve, Location.EXTERIOR, Location.INTERIOR);
  11897. };
  11898. OffsetCurveSetBuilder.prototype.addCurve = function addCurve (coord, leftLoc, rightLoc) {
  11899. if (coord === null || coord.length < 2) { return null }
  11900. var e = new NodedSegmentString(coord, new Label(0, Location.BOUNDARY, leftLoc, rightLoc));
  11901. this._curveList.add(e);
  11902. };
  11903. OffsetCurveSetBuilder.prototype.getCurves = function getCurves () {
  11904. this.add(this._inputGeom);
  11905. return this._curveList
  11906. };
  11907. OffsetCurveSetBuilder.prototype.addPolygonRing = function addPolygonRing (coord, offsetDistance, side, cwLeftLoc, cwRightLoc) {
  11908. if (offsetDistance === 0.0 && coord.length < LinearRing.MINIMUM_VALID_SIZE) { return null }
  11909. var leftLoc = cwLeftLoc;
  11910. var rightLoc = cwRightLoc;
  11911. if (coord.length >= LinearRing.MINIMUM_VALID_SIZE && CGAlgorithms.isCCW(coord)) {
  11912. leftLoc = cwRightLoc;
  11913. rightLoc = cwLeftLoc;
  11914. side = Position.opposite(side);
  11915. }
  11916. var curve = this._curveBuilder.getRingCurve(coord, side, offsetDistance);
  11917. this.addCurve(curve, leftLoc, rightLoc);
  11918. };
  11919. OffsetCurveSetBuilder.prototype.add = function add (g) {
  11920. if (g.isEmpty()) { return null }
  11921. if (g instanceof Polygon) { this.addPolygon(g); }
  11922. else if (g instanceof LineString) { this.addLineString(g); }
  11923. else if (g instanceof Point) { this.addPoint(g); }
  11924. else if (g instanceof MultiPoint) { this.addCollection(g); }
  11925. else if (g instanceof MultiLineString) { this.addCollection(g); }
  11926. else if (g instanceof MultiPolygon) { this.addCollection(g); }
  11927. else if (g instanceof GeometryCollection) { this.addCollection(g); }
  11928. // else throw new UnsupportedOperationException(g.getClass().getName())
  11929. };
  11930. OffsetCurveSetBuilder.prototype.isErodedCompletely = function isErodedCompletely (ring, bufferDistance) {
  11931. var ringCoord = ring.getCoordinates();
  11932. // const minDiam = 0.0
  11933. if (ringCoord.length < 4) { return bufferDistance < 0 }
  11934. if (ringCoord.length === 4) { return this.isTriangleErodedCompletely(ringCoord, bufferDistance) }
  11935. var env = ring.getEnvelopeInternal();
  11936. var envMinDimension = Math.min(env.getHeight(), env.getWidth());
  11937. if (bufferDistance < 0.0 && 2 * Math.abs(bufferDistance) > envMinDimension) { return true }
  11938. return false
  11939. };
  11940. OffsetCurveSetBuilder.prototype.addCollection = function addCollection (gc) {
  11941. var this$1 = this;
  11942. for (var i = 0; i < gc.getNumGeometries(); i++) {
  11943. var g = gc.getGeometryN(i);
  11944. this$1.add(g);
  11945. }
  11946. };
  11947. OffsetCurveSetBuilder.prototype.interfaces_ = function interfaces_ () {
  11948. return []
  11949. };
  11950. OffsetCurveSetBuilder.prototype.getClass = function getClass () {
  11951. return OffsetCurveSetBuilder
  11952. };
  11953. var PointOnGeometryLocator = function PointOnGeometryLocator () {};
  11954. PointOnGeometryLocator.prototype.locate = function locate (p) {};
  11955. PointOnGeometryLocator.prototype.interfaces_ = function interfaces_ () {
  11956. return []
  11957. };
  11958. PointOnGeometryLocator.prototype.getClass = function getClass () {
  11959. return PointOnGeometryLocator
  11960. };
  11961. var GeometryCollectionIterator = function GeometryCollectionIterator () {
  11962. this._parent = null;
  11963. this._atStart = null;
  11964. this._max = null;
  11965. this._index = null;
  11966. this._subcollectionIterator = null;
  11967. var parent = arguments[0];
  11968. this._parent = parent;
  11969. this._atStart = true;
  11970. this._index = 0;
  11971. this._max = parent.getNumGeometries();
  11972. };
  11973. GeometryCollectionIterator.prototype.next = function next () {
  11974. if (this._atStart) {
  11975. this._atStart = false;
  11976. if (GeometryCollectionIterator.isAtomic(this._parent)) { this._index++; }
  11977. return this._parent
  11978. }
  11979. if (this._subcollectionIterator !== null) {
  11980. if (this._subcollectionIterator.hasNext()) {
  11981. return this._subcollectionIterator.next()
  11982. } else {
  11983. this._subcollectionIterator = null;
  11984. }
  11985. }
  11986. if (this._index >= this._max) {
  11987. throw new NoSuchElementException()
  11988. }
  11989. var obj = this._parent.getGeometryN(this._index++);
  11990. if (obj instanceof GeometryCollection) {
  11991. this._subcollectionIterator = new GeometryCollectionIterator(obj);
  11992. return this._subcollectionIterator.next()
  11993. }
  11994. return obj
  11995. };
  11996. GeometryCollectionIterator.prototype.remove = function remove () {
  11997. throw new Error(this.getClass().getName())
  11998. };
  11999. GeometryCollectionIterator.prototype.hasNext = function hasNext () {
  12000. if (this._atStart) {
  12001. return true
  12002. }
  12003. if (this._subcollectionIterator !== null) {
  12004. if (this._subcollectionIterator.hasNext()) {
  12005. return true
  12006. }
  12007. this._subcollectionIterator = null;
  12008. }
  12009. if (this._index >= this._max) {
  12010. return false
  12011. }
  12012. return true
  12013. };
  12014. GeometryCollectionIterator.prototype.interfaces_ = function interfaces_ () {
  12015. return [Iterator]
  12016. };
  12017. GeometryCollectionIterator.prototype.getClass = function getClass () {
  12018. return GeometryCollectionIterator
  12019. };
  12020. GeometryCollectionIterator.isAtomic = function isAtomic (geom) {
  12021. return !(geom instanceof GeometryCollection)
  12022. };
  12023. var SimplePointInAreaLocator = function SimplePointInAreaLocator () {
  12024. this._geom = null;
  12025. var geom = arguments[0];
  12026. this._geom = geom;
  12027. };
  12028. SimplePointInAreaLocator.prototype.locate = function locate (p) {
  12029. return SimplePointInAreaLocator.locate(p, this._geom)
  12030. };
  12031. SimplePointInAreaLocator.prototype.interfaces_ = function interfaces_ () {
  12032. return [PointOnGeometryLocator]
  12033. };
  12034. SimplePointInAreaLocator.prototype.getClass = function getClass () {
  12035. return SimplePointInAreaLocator
  12036. };
  12037. SimplePointInAreaLocator.isPointInRing = function isPointInRing (p, ring) {
  12038. if (!ring.getEnvelopeInternal().intersects(p)) { return false }
  12039. return CGAlgorithms.isPointInRing(p, ring.getCoordinates())
  12040. };
  12041. SimplePointInAreaLocator.containsPointInPolygon = function containsPointInPolygon (p, poly) {
  12042. if (poly.isEmpty()) { return false }
  12043. var shell = poly.getExteriorRing();
  12044. if (!SimplePointInAreaLocator.isPointInRing(p, shell)) { return false }
  12045. for (var i = 0; i < poly.getNumInteriorRing(); i++) {
  12046. var hole = poly.getInteriorRingN(i);
  12047. if (SimplePointInAreaLocator.isPointInRing(p, hole)) { return false }
  12048. }
  12049. return true
  12050. };
  12051. SimplePointInAreaLocator.containsPoint = function containsPoint (p, geom) {
  12052. if (geom instanceof Polygon) {
  12053. return SimplePointInAreaLocator.containsPointInPolygon(p, geom)
  12054. } else if (geom instanceof GeometryCollection) {
  12055. var geomi = new GeometryCollectionIterator(geom);
  12056. while (geomi.hasNext()) {
  12057. var g2 = geomi.next();
  12058. if (g2 !== geom) { if (SimplePointInAreaLocator.containsPoint(p, g2)) { return true } }
  12059. }
  12060. }
  12061. return false
  12062. };
  12063. SimplePointInAreaLocator.locate = function locate (p, geom) {
  12064. if (geom.isEmpty()) { return Location.EXTERIOR }
  12065. if (SimplePointInAreaLocator.containsPoint(p, geom)) { return Location.INTERIOR }
  12066. return Location.EXTERIOR
  12067. };
  12068. var EdgeEndStar = function EdgeEndStar () {
  12069. this._edgeMap = new TreeMap();
  12070. this._edgeList = null;
  12071. this._ptInAreaLocation = [Location.NONE, Location.NONE];
  12072. };
  12073. EdgeEndStar.prototype.getNextCW = function getNextCW (ee) {
  12074. this.getEdges();
  12075. var i = this._edgeList.indexOf(ee);
  12076. var iNextCW = i - 1;
  12077. if (i === 0) { iNextCW = this._edgeList.size() - 1; }
  12078. return this._edgeList.get(iNextCW)
  12079. };
  12080. EdgeEndStar.prototype.propagateSideLabels = function propagateSideLabels (geomIndex) {
  12081. var startLoc = Location.NONE;
  12082. for (var it = this.iterator(); it.hasNext();) {
  12083. var e = it.next();
  12084. var label = e.getLabel();
  12085. if (label.isArea(geomIndex) && label.getLocation(geomIndex, Position.LEFT) !== Location.NONE) { startLoc = label.getLocation(geomIndex, Position.LEFT); }
  12086. }
  12087. if (startLoc === Location.NONE) { return null }
  12088. var currLoc = startLoc;
  12089. for (var it$1 = this.iterator(); it$1.hasNext();) {
  12090. var e$1 = it$1.next();
  12091. var label$1 = e$1.getLabel();
  12092. if (label$1.getLocation(geomIndex, Position.ON) === Location.NONE) { label$1.setLocation(geomIndex, Position.ON, currLoc); }
  12093. if (label$1.isArea(geomIndex)) {
  12094. var leftLoc = label$1.getLocation(geomIndex, Position.LEFT);
  12095. var rightLoc = label$1.getLocation(geomIndex, Position.RIGHT);
  12096. if (rightLoc !== Location.NONE) {
  12097. if (rightLoc !== currLoc) { throw new TopologyException('side location conflict', e$1.getCoordinate()) }
  12098. if (leftLoc === Location.NONE) {
  12099. Assert.shouldNeverReachHere('found single null side (at ' + e$1.getCoordinate() + ')');
  12100. }
  12101. currLoc = leftLoc;
  12102. } else {
  12103. Assert.isTrue(label$1.getLocation(geomIndex, Position.LEFT) === Location.NONE, 'found single null side');
  12104. label$1.setLocation(geomIndex, Position.RIGHT, currLoc);
  12105. label$1.setLocation(geomIndex, Position.LEFT, currLoc);
  12106. }
  12107. }
  12108. }
  12109. };
  12110. EdgeEndStar.prototype.getCoordinate = function getCoordinate () {
  12111. var it = this.iterator();
  12112. if (!it.hasNext()) { return null }
  12113. var e = it.next();
  12114. return e.getCoordinate()
  12115. };
  12116. EdgeEndStar.prototype.print = function print (out) {
  12117. System.out.println('EdgeEndStar: ' + this.getCoordinate());
  12118. for (var it = this.iterator(); it.hasNext();) {
  12119. var e = it.next();
  12120. e.print(out);
  12121. }
  12122. };
  12123. EdgeEndStar.prototype.isAreaLabelsConsistent = function isAreaLabelsConsistent (geomGraph) {
  12124. this.computeEdgeEndLabels(geomGraph.getBoundaryNodeRule());
  12125. return this.checkAreaLabelsConsistent(0)
  12126. };
  12127. EdgeEndStar.prototype.checkAreaLabelsConsistent = function checkAreaLabelsConsistent (geomIndex) {
  12128. var edges = this.getEdges();
  12129. if (edges.size() <= 0) { return true }
  12130. var lastEdgeIndex = edges.size() - 1;
  12131. var startLabel = edges.get(lastEdgeIndex).getLabel();
  12132. var startLoc = startLabel.getLocation(geomIndex, Position.LEFT);
  12133. Assert.isTrue(startLoc !== Location.NONE, 'Found unlabelled area edge');
  12134. var currLoc = startLoc;
  12135. for (var it = this.iterator(); it.hasNext();) {
  12136. var e = it.next();
  12137. var label = e.getLabel();
  12138. Assert.isTrue(label.isArea(geomIndex), 'Found non-area edge');
  12139. var leftLoc = label.getLocation(geomIndex, Position.LEFT);
  12140. var rightLoc = label.getLocation(geomIndex, Position.RIGHT);
  12141. if (leftLoc === rightLoc) {
  12142. return false
  12143. }
  12144. if (rightLoc !== currLoc) {
  12145. return false
  12146. }
  12147. currLoc = leftLoc;
  12148. }
  12149. return true
  12150. };
  12151. EdgeEndStar.prototype.findIndex = function findIndex (eSearch) {
  12152. var this$1 = this;
  12153. this.iterator();
  12154. for (var i = 0; i < this._edgeList.size(); i++) {
  12155. var e = this$1._edgeList.get(i);
  12156. if (e === eSearch) { return i }
  12157. }
  12158. return -1
  12159. };
  12160. EdgeEndStar.prototype.iterator = function iterator () {
  12161. return this.getEdges().iterator()
  12162. };
  12163. EdgeEndStar.prototype.getEdges = function getEdges () {
  12164. if (this._edgeList === null) {
  12165. this._edgeList = new ArrayList(this._edgeMap.values());
  12166. }
  12167. return this._edgeList
  12168. };
  12169. EdgeEndStar.prototype.getLocation = function getLocation (geomIndex, p, geom) {
  12170. if (this._ptInAreaLocation[geomIndex] === Location.NONE) {
  12171. this._ptInAreaLocation[geomIndex] = SimplePointInAreaLocator.locate(p, geom[geomIndex].getGeometry());
  12172. }
  12173. return this._ptInAreaLocation[geomIndex]
  12174. };
  12175. EdgeEndStar.prototype.toString = function toString () {
  12176. var buf = new StringBuffer();
  12177. buf.append('EdgeEndStar: ' + this.getCoordinate());
  12178. buf.append('\n');
  12179. for (var it = this.iterator(); it.hasNext();) {
  12180. var e = it.next();
  12181. buf.append(e);
  12182. buf.append('\n');
  12183. }
  12184. return buf.toString()
  12185. };
  12186. EdgeEndStar.prototype.computeEdgeEndLabels = function computeEdgeEndLabels (boundaryNodeRule) {
  12187. for (var it = this.iterator(); it.hasNext();) {
  12188. var ee = it.next();
  12189. ee.computeLabel(boundaryNodeRule);
  12190. }
  12191. };
  12192. EdgeEndStar.prototype.computeLabelling = function computeLabelling (geomGraph) {
  12193. var this$1 = this;
  12194. this.computeEdgeEndLabels(geomGraph[0].getBoundaryNodeRule());
  12195. this.propagateSideLabels(0);
  12196. this.propagateSideLabels(1);
  12197. var hasDimensionalCollapseEdge = [false, false];
  12198. for (var it = this.iterator(); it.hasNext();) {
  12199. var e = it.next();
  12200. var label = e.getLabel();
  12201. for (var geomi = 0; geomi < 2; geomi++) {
  12202. if (label.isLine(geomi) && label.getLocation(geomi) === Location.BOUNDARY) { hasDimensionalCollapseEdge[geomi] = true; }
  12203. }
  12204. }
  12205. for (var it$1 = this.iterator(); it$1.hasNext();) {
  12206. var e$1 = it$1.next();
  12207. var label$1 = e$1.getLabel();
  12208. for (var geomi$1 = 0; geomi$1 < 2; geomi$1++) {
  12209. if (label$1.isAnyNull(geomi$1)) {
  12210. var loc = Location.NONE;
  12211. if (hasDimensionalCollapseEdge[geomi$1]) {
  12212. loc = Location.EXTERIOR;
  12213. } else {
  12214. var p = e$1.getCoordinate();
  12215. loc = this$1.getLocation(geomi$1, p, geomGraph);
  12216. }
  12217. label$1.setAllLocationsIfNull(geomi$1, loc);
  12218. }
  12219. }
  12220. }
  12221. };
  12222. EdgeEndStar.prototype.getDegree = function getDegree () {
  12223. return this._edgeMap.size()
  12224. };
  12225. EdgeEndStar.prototype.insertEdgeEnd = function insertEdgeEnd (e, obj) {
  12226. this._edgeMap.put(e, obj);
  12227. this._edgeList = null;
  12228. };
  12229. EdgeEndStar.prototype.interfaces_ = function interfaces_ () {
  12230. return []
  12231. };
  12232. EdgeEndStar.prototype.getClass = function getClass () {
  12233. return EdgeEndStar
  12234. };
  12235. var DirectedEdgeStar = (function (EdgeEndStar$$1) {
  12236. function DirectedEdgeStar () {
  12237. EdgeEndStar$$1.call(this);
  12238. this._resultAreaEdgeList = null;
  12239. this._label = null;
  12240. this._SCANNING_FOR_INCOMING = 1;
  12241. this._LINKING_TO_OUTGOING = 2;
  12242. }
  12243. if ( EdgeEndStar$$1 ) DirectedEdgeStar.__proto__ = EdgeEndStar$$1;
  12244. DirectedEdgeStar.prototype = Object.create( EdgeEndStar$$1 && EdgeEndStar$$1.prototype );
  12245. DirectedEdgeStar.prototype.constructor = DirectedEdgeStar;
  12246. DirectedEdgeStar.prototype.linkResultDirectedEdges = function linkResultDirectedEdges () {
  12247. var this$1 = this;
  12248. this.getResultAreaEdges();
  12249. var firstOut = null;
  12250. var incoming = null;
  12251. var state = this._SCANNING_FOR_INCOMING;
  12252. for (var i = 0; i < this._resultAreaEdgeList.size(); i++) {
  12253. var nextOut = this$1._resultAreaEdgeList.get(i);
  12254. var nextIn = nextOut.getSym();
  12255. if (!nextOut.getLabel().isArea()) { continue }
  12256. if (firstOut === null && nextOut.isInResult()) { firstOut = nextOut; }
  12257. switch (state) {
  12258. case this$1._SCANNING_FOR_INCOMING:
  12259. if (!nextIn.isInResult()) { continue }
  12260. incoming = nextIn;
  12261. state = this$1._LINKING_TO_OUTGOING;
  12262. break
  12263. case this$1._LINKING_TO_OUTGOING:
  12264. if (!nextOut.isInResult()) { continue }
  12265. incoming.setNext(nextOut);
  12266. state = this$1._SCANNING_FOR_INCOMING;
  12267. break
  12268. default:
  12269. }
  12270. }
  12271. if (state === this._LINKING_TO_OUTGOING) {
  12272. if (firstOut === null) { throw new TopologyException('no outgoing dirEdge found', this.getCoordinate()) }
  12273. Assert.isTrue(firstOut.isInResult(), 'unable to link last incoming dirEdge');
  12274. incoming.setNext(firstOut);
  12275. }
  12276. };
  12277. DirectedEdgeStar.prototype.insert = function insert (ee) {
  12278. var de = ee;
  12279. this.insertEdgeEnd(de, de);
  12280. };
  12281. DirectedEdgeStar.prototype.getRightmostEdge = function getRightmostEdge () {
  12282. var edges = this.getEdges();
  12283. var size = edges.size();
  12284. if (size < 1) { return null }
  12285. var de0 = edges.get(0);
  12286. if (size === 1) { return de0 }
  12287. var deLast = edges.get(size - 1);
  12288. var quad0 = de0.getQuadrant();
  12289. var quad1 = deLast.getQuadrant();
  12290. if (Quadrant.isNorthern(quad0) && Quadrant.isNorthern(quad1)) { return de0; } else if (!Quadrant.isNorthern(quad0) && !Quadrant.isNorthern(quad1)) { return deLast; } else {
  12291. // const nonHorizontalEdge = null
  12292. if (de0.getDy() !== 0) { return de0; } else if (deLast.getDy() !== 0) { return deLast }
  12293. }
  12294. Assert.shouldNeverReachHere('found two horizontal edges incident on node');
  12295. return null
  12296. };
  12297. DirectedEdgeStar.prototype.print = function print (out) {
  12298. System.out.println('DirectedEdgeStar: ' + this.getCoordinate());
  12299. for (var it = this.iterator(); it.hasNext();) {
  12300. var de = it.next();
  12301. out.print('out ');
  12302. de.print(out);
  12303. out.println();
  12304. out.print('in ');
  12305. de.getSym().print(out);
  12306. out.println();
  12307. }
  12308. };
  12309. DirectedEdgeStar.prototype.getResultAreaEdges = function getResultAreaEdges () {
  12310. var this$1 = this;
  12311. if (this._resultAreaEdgeList !== null) { return this._resultAreaEdgeList }
  12312. this._resultAreaEdgeList = new ArrayList();
  12313. for (var it = this.iterator(); it.hasNext();) {
  12314. var de = it.next();
  12315. if (de.isInResult() || de.getSym().isInResult()) { this$1._resultAreaEdgeList.add(de); }
  12316. }
  12317. return this._resultAreaEdgeList
  12318. };
  12319. DirectedEdgeStar.prototype.updateLabelling = function updateLabelling (nodeLabel) {
  12320. for (var it = this.iterator(); it.hasNext();) {
  12321. var de = it.next();
  12322. var label = de.getLabel();
  12323. label.setAllLocationsIfNull(0, nodeLabel.getLocation(0));
  12324. label.setAllLocationsIfNull(1, nodeLabel.getLocation(1));
  12325. }
  12326. };
  12327. DirectedEdgeStar.prototype.linkAllDirectedEdges = function linkAllDirectedEdges () {
  12328. var this$1 = this;
  12329. this.getEdges();
  12330. var prevOut = null;
  12331. var firstIn = null;
  12332. for (var i = this._edgeList.size() - 1; i >= 0; i--) {
  12333. var nextOut = this$1._edgeList.get(i);
  12334. var nextIn = nextOut.getSym();
  12335. if (firstIn === null) { firstIn = nextIn; }
  12336. if (prevOut !== null) { nextIn.setNext(prevOut); }
  12337. prevOut = nextOut;
  12338. }
  12339. firstIn.setNext(prevOut);
  12340. };
  12341. DirectedEdgeStar.prototype.computeDepths = function computeDepths () {
  12342. var this$1 = this;
  12343. if (arguments.length === 1) {
  12344. var de = arguments[0];
  12345. var edgeIndex = this.findIndex(de);
  12346. // const label = de.getLabel()
  12347. var startDepth = de.getDepth(Position.LEFT);
  12348. var targetLastDepth = de.getDepth(Position.RIGHT);
  12349. var nextDepth = this.computeDepths(edgeIndex + 1, this._edgeList.size(), startDepth);
  12350. var lastDepth = this.computeDepths(0, edgeIndex, nextDepth);
  12351. if (lastDepth !== targetLastDepth) { throw new TopologyException('depth mismatch at ' + de.getCoordinate()) }
  12352. } else if (arguments.length === 3) {
  12353. var startIndex = arguments[0];
  12354. var endIndex = arguments[1];
  12355. var startDepth$1 = arguments[2];
  12356. var currDepth = startDepth$1;
  12357. for (var i = startIndex; i < endIndex; i++) {
  12358. var nextDe = this$1._edgeList.get(i);
  12359. // const label = nextDe.getLabel()
  12360. nextDe.setEdgeDepths(Position.RIGHT, currDepth);
  12361. currDepth = nextDe.getDepth(Position.LEFT);
  12362. }
  12363. return currDepth
  12364. }
  12365. };
  12366. DirectedEdgeStar.prototype.mergeSymLabels = function mergeSymLabels () {
  12367. for (var it = this.iterator(); it.hasNext();) {
  12368. var de = it.next();
  12369. var label = de.getLabel();
  12370. label.merge(de.getSym().getLabel());
  12371. }
  12372. };
  12373. DirectedEdgeStar.prototype.linkMinimalDirectedEdges = function linkMinimalDirectedEdges (er) {
  12374. var this$1 = this;
  12375. var firstOut = null;
  12376. var incoming = null;
  12377. var state = this._SCANNING_FOR_INCOMING;
  12378. for (var i = this._resultAreaEdgeList.size() - 1; i >= 0; i--) {
  12379. var nextOut = this$1._resultAreaEdgeList.get(i);
  12380. var nextIn = nextOut.getSym();
  12381. if (firstOut === null && nextOut.getEdgeRing() === er) { firstOut = nextOut; }
  12382. switch (state) {
  12383. case this$1._SCANNING_FOR_INCOMING:
  12384. if (nextIn.getEdgeRing() !== er) { continue }
  12385. incoming = nextIn;
  12386. state = this$1._LINKING_TO_OUTGOING;
  12387. break
  12388. case this$1._LINKING_TO_OUTGOING:
  12389. if (nextOut.getEdgeRing() !== er) { continue }
  12390. incoming.setNextMin(nextOut);
  12391. state = this$1._SCANNING_FOR_INCOMING;
  12392. break
  12393. default:
  12394. }
  12395. }
  12396. if (state === this._LINKING_TO_OUTGOING) {
  12397. Assert.isTrue(firstOut !== null, 'found null for first outgoing dirEdge');
  12398. Assert.isTrue(firstOut.getEdgeRing() === er, 'unable to link last incoming dirEdge');
  12399. incoming.setNextMin(firstOut);
  12400. }
  12401. };
  12402. DirectedEdgeStar.prototype.getOutgoingDegree = function getOutgoingDegree () {
  12403. if (arguments.length === 0) {
  12404. var degree = 0;
  12405. for (var it = this.iterator(); it.hasNext();) {
  12406. var de = it.next();
  12407. if (de.isInResult()) { degree++; }
  12408. }
  12409. return degree
  12410. } else if (arguments.length === 1) {
  12411. var er = arguments[0];
  12412. var degree$1 = 0;
  12413. for (var it$1 = this.iterator(); it$1.hasNext();) {
  12414. var de$1 = it$1.next();
  12415. if (de$1.getEdgeRing() === er) { degree$1++; }
  12416. }
  12417. return degree$1
  12418. }
  12419. };
  12420. DirectedEdgeStar.prototype.getLabel = function getLabel () {
  12421. return this._label
  12422. };
  12423. DirectedEdgeStar.prototype.findCoveredLineEdges = function findCoveredLineEdges () {
  12424. var startLoc = Location.NONE;
  12425. for (var it = this.iterator(); it.hasNext();) {
  12426. var nextOut = it.next();
  12427. var nextIn = nextOut.getSym();
  12428. if (!nextOut.isLineEdge()) {
  12429. if (nextOut.isInResult()) {
  12430. startLoc = Location.INTERIOR;
  12431. break
  12432. }
  12433. if (nextIn.isInResult()) {
  12434. startLoc = Location.EXTERIOR;
  12435. break
  12436. }
  12437. }
  12438. }
  12439. if (startLoc === Location.NONE) { return null }
  12440. var currLoc = startLoc;
  12441. for (var it$1 = this.iterator(); it$1.hasNext();) {
  12442. var nextOut$1 = it$1.next();
  12443. var nextIn$1 = nextOut$1.getSym();
  12444. if (nextOut$1.isLineEdge()) {
  12445. nextOut$1.getEdge().setCovered(currLoc === Location.INTERIOR);
  12446. } else {
  12447. if (nextOut$1.isInResult()) { currLoc = Location.EXTERIOR; }
  12448. if (nextIn$1.isInResult()) { currLoc = Location.INTERIOR; }
  12449. }
  12450. }
  12451. };
  12452. DirectedEdgeStar.prototype.computeLabelling = function computeLabelling (geom) {
  12453. var this$1 = this;
  12454. EdgeEndStar$$1.prototype.computeLabelling.call(this, geom);
  12455. this._label = new Label(Location.NONE);
  12456. for (var it = this.iterator(); it.hasNext();) {
  12457. var ee = it.next();
  12458. var e = ee.getEdge();
  12459. var eLabel = e.getLabel();
  12460. for (var i = 0; i < 2; i++) {
  12461. var eLoc = eLabel.getLocation(i);
  12462. if (eLoc === Location.INTERIOR || eLoc === Location.BOUNDARY) { this$1._label.setLocation(i, Location.INTERIOR); }
  12463. }
  12464. }
  12465. };
  12466. DirectedEdgeStar.prototype.interfaces_ = function interfaces_ () {
  12467. return []
  12468. };
  12469. DirectedEdgeStar.prototype.getClass = function getClass () {
  12470. return DirectedEdgeStar
  12471. };
  12472. return DirectedEdgeStar;
  12473. }(EdgeEndStar));
  12474. var OverlayNodeFactory = (function (NodeFactory$$1) {
  12475. function OverlayNodeFactory () {
  12476. NodeFactory$$1.apply(this, arguments);
  12477. }
  12478. if ( NodeFactory$$1 ) OverlayNodeFactory.__proto__ = NodeFactory$$1;
  12479. OverlayNodeFactory.prototype = Object.create( NodeFactory$$1 && NodeFactory$$1.prototype );
  12480. OverlayNodeFactory.prototype.constructor = OverlayNodeFactory;
  12481. OverlayNodeFactory.prototype.createNode = function createNode (coord) {
  12482. return new Node(coord, new DirectedEdgeStar())
  12483. };
  12484. OverlayNodeFactory.prototype.interfaces_ = function interfaces_ () {
  12485. return []
  12486. };
  12487. OverlayNodeFactory.prototype.getClass = function getClass () {
  12488. return OverlayNodeFactory
  12489. };
  12490. return OverlayNodeFactory;
  12491. }(NodeFactory));
  12492. var OrientedCoordinateArray = function OrientedCoordinateArray () {
  12493. this._pts = null;
  12494. this._orientation = null;
  12495. var pts = arguments[0];
  12496. this._pts = pts;
  12497. this._orientation = OrientedCoordinateArray.orientation(pts);
  12498. };
  12499. OrientedCoordinateArray.prototype.compareTo = function compareTo (o1) {
  12500. var oca = o1;
  12501. var comp = OrientedCoordinateArray.compareOriented(this._pts, this._orientation, oca._pts, oca._orientation);
  12502. return comp
  12503. };
  12504. OrientedCoordinateArray.prototype.interfaces_ = function interfaces_ () {
  12505. return [Comparable]
  12506. };
  12507. OrientedCoordinateArray.prototype.getClass = function getClass () {
  12508. return OrientedCoordinateArray
  12509. };
  12510. OrientedCoordinateArray.orientation = function orientation (pts) {
  12511. return CoordinateArrays.increasingDirection(pts) === 1
  12512. };
  12513. OrientedCoordinateArray.compareOriented = function compareOriented (pts1, orientation1, pts2, orientation2) {
  12514. var dir1 = orientation1 ? 1 : -1;
  12515. var dir2 = orientation2 ? 1 : -1;
  12516. var limit1 = orientation1 ? pts1.length : -1;
  12517. var limit2 = orientation2 ? pts2.length : -1;
  12518. var i1 = orientation1 ? 0 : pts1.length - 1;
  12519. var i2 = orientation2 ? 0 : pts2.length - 1;
  12520. // const comp = 0
  12521. while (true) {
  12522. var compPt = pts1[i1].compareTo(pts2[i2]);
  12523. if (compPt !== 0) { return compPt }
  12524. i1 += dir1;
  12525. i2 += dir2;
  12526. var done1 = i1 === limit1;
  12527. var done2 = i2 === limit2;
  12528. if (done1 && !done2) { return -1 }
  12529. if (!done1 && done2) { return 1 }
  12530. if (done1 && done2) { return 0 }
  12531. }
  12532. };
  12533. var EdgeList = function EdgeList () {
  12534. this._edges = new ArrayList();
  12535. this._ocaMap = new TreeMap();
  12536. };
  12537. EdgeList.prototype.print = function print (out) {
  12538. var this$1 = this;
  12539. out.print('MULTILINESTRING ( ');
  12540. for (var j = 0; j < this._edges.size(); j++) {
  12541. var e = this$1._edges.get(j);
  12542. if (j > 0) { out.print(','); }
  12543. out.print('(');
  12544. var pts = e.getCoordinates();
  12545. for (var i = 0; i < pts.length; i++) {
  12546. if (i > 0) { out.print(','); }
  12547. out.print(pts[i].x + ' ' + pts[i].y);
  12548. }
  12549. out.println(')');
  12550. }
  12551. out.print(') ');
  12552. };
  12553. EdgeList.prototype.addAll = function addAll (edgeColl) {
  12554. var this$1 = this;
  12555. for (var i = edgeColl.iterator(); i.hasNext();) {
  12556. this$1.add(i.next());
  12557. }
  12558. };
  12559. EdgeList.prototype.findEdgeIndex = function findEdgeIndex (e) {
  12560. var this$1 = this;
  12561. for (var i = 0; i < this._edges.size(); i++) {
  12562. if (this$1._edges.get(i).equals(e)) { return i }
  12563. }
  12564. return -1
  12565. };
  12566. EdgeList.prototype.iterator = function iterator () {
  12567. return this._edges.iterator()
  12568. };
  12569. EdgeList.prototype.getEdges = function getEdges () {
  12570. return this._edges
  12571. };
  12572. EdgeList.prototype.get = function get (i) {
  12573. return this._edges.get(i)
  12574. };
  12575. EdgeList.prototype.findEqualEdge = function findEqualEdge (e) {
  12576. var oca = new OrientedCoordinateArray(e.getCoordinates());
  12577. var matchEdge = this._ocaMap.get(oca);
  12578. return matchEdge
  12579. };
  12580. EdgeList.prototype.add = function add (e) {
  12581. this._edges.add(e);
  12582. var oca = new OrientedCoordinateArray(e.getCoordinates());
  12583. this._ocaMap.put(oca, e);
  12584. };
  12585. EdgeList.prototype.interfaces_ = function interfaces_ () {
  12586. return []
  12587. };
  12588. EdgeList.prototype.getClass = function getClass () {
  12589. return EdgeList
  12590. };
  12591. var SegmentIntersector = function SegmentIntersector () {};
  12592. SegmentIntersector.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {};
  12593. SegmentIntersector.prototype.isDone = function isDone () {};
  12594. SegmentIntersector.prototype.interfaces_ = function interfaces_ () {
  12595. return []
  12596. };
  12597. SegmentIntersector.prototype.getClass = function getClass () {
  12598. return SegmentIntersector
  12599. };
  12600. var IntersectionAdder = function IntersectionAdder () {
  12601. this._hasIntersection = false;
  12602. this._hasProper = false;
  12603. this._hasProperInterior = false;
  12604. this._hasInterior = false;
  12605. this._properIntersectionPoint = null;
  12606. this._li = null;
  12607. this._isSelfIntersection = null;
  12608. this.numIntersections = 0;
  12609. this.numInteriorIntersections = 0;
  12610. this.numProperIntersections = 0;
  12611. this.numTests = 0;
  12612. var li = arguments[0];
  12613. this._li = li;
  12614. };
  12615. IntersectionAdder.prototype.isTrivialIntersection = function isTrivialIntersection (e0, segIndex0, e1, segIndex1) {
  12616. if (e0 === e1) {
  12617. if (this._li.getIntersectionNum() === 1) {
  12618. if (IntersectionAdder.isAdjacentSegments(segIndex0, segIndex1)) { return true }
  12619. if (e0.isClosed()) {
  12620. var maxSegIndex = e0.size() - 1;
  12621. if ((segIndex0 === 0 && segIndex1 === maxSegIndex) ||
  12622. (segIndex1 === 0 && segIndex0 === maxSegIndex)) {
  12623. return true
  12624. }
  12625. }
  12626. }
  12627. }
  12628. return false
  12629. };
  12630. IntersectionAdder.prototype.getProperIntersectionPoint = function getProperIntersectionPoint () {
  12631. return this._properIntersectionPoint
  12632. };
  12633. IntersectionAdder.prototype.hasProperInteriorIntersection = function hasProperInteriorIntersection () {
  12634. return this._hasProperInterior
  12635. };
  12636. IntersectionAdder.prototype.getLineIntersector = function getLineIntersector () {
  12637. return this._li
  12638. };
  12639. IntersectionAdder.prototype.hasProperIntersection = function hasProperIntersection () {
  12640. return this._hasProper
  12641. };
  12642. IntersectionAdder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {
  12643. if (e0 === e1 && segIndex0 === segIndex1) { return null }
  12644. this.numTests++;
  12645. var p00 = e0.getCoordinates()[segIndex0];
  12646. var p01 = e0.getCoordinates()[segIndex0 + 1];
  12647. var p10 = e1.getCoordinates()[segIndex1];
  12648. var p11 = e1.getCoordinates()[segIndex1 + 1];
  12649. this._li.computeIntersection(p00, p01, p10, p11);
  12650. if (this._li.hasIntersection()) {
  12651. this.numIntersections++;
  12652. if (this._li.isInteriorIntersection()) {
  12653. this.numInteriorIntersections++;
  12654. this._hasInterior = true;
  12655. }
  12656. if (!this.isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {
  12657. this._hasIntersection = true;
  12658. e0.addIntersections(this._li, segIndex0, 0);
  12659. e1.addIntersections(this._li, segIndex1, 1);
  12660. if (this._li.isProper()) {
  12661. this.numProperIntersections++;
  12662. this._hasProper = true;
  12663. this._hasProperInterior = true;
  12664. }
  12665. }
  12666. }
  12667. };
  12668. IntersectionAdder.prototype.hasIntersection = function hasIntersection () {
  12669. return this._hasIntersection
  12670. };
  12671. IntersectionAdder.prototype.isDone = function isDone () {
  12672. return false
  12673. };
  12674. IntersectionAdder.prototype.hasInteriorIntersection = function hasInteriorIntersection () {
  12675. return this._hasInterior
  12676. };
  12677. IntersectionAdder.prototype.interfaces_ = function interfaces_ () {
  12678. return [SegmentIntersector]
  12679. };
  12680. IntersectionAdder.prototype.getClass = function getClass () {
  12681. return IntersectionAdder
  12682. };
  12683. IntersectionAdder.isAdjacentSegments = function isAdjacentSegments (i1, i2) {
  12684. return Math.abs(i1 - i2) === 1
  12685. };
  12686. var EdgeIntersection = function EdgeIntersection () {
  12687. this.coord = null;
  12688. this.segmentIndex = null;
  12689. this.dist = null;
  12690. var coord = arguments[0];
  12691. var segmentIndex = arguments[1];
  12692. var dist = arguments[2];
  12693. this.coord = new Coordinate(coord);
  12694. this.segmentIndex = segmentIndex;
  12695. this.dist = dist;
  12696. };
  12697. EdgeIntersection.prototype.getSegmentIndex = function getSegmentIndex () {
  12698. return this.segmentIndex
  12699. };
  12700. EdgeIntersection.prototype.getCoordinate = function getCoordinate () {
  12701. return this.coord
  12702. };
  12703. EdgeIntersection.prototype.print = function print (out) {
  12704. out.print(this.coord);
  12705. out.print(' seg # = ' + this.segmentIndex);
  12706. out.println(' dist = ' + this.dist);
  12707. };
  12708. EdgeIntersection.prototype.compareTo = function compareTo (obj) {
  12709. var other = obj;
  12710. return this.compare(other.segmentIndex, other.dist)
  12711. };
  12712. EdgeIntersection.prototype.isEndPoint = function isEndPoint (maxSegmentIndex) {
  12713. if (this.segmentIndex === 0 && this.dist === 0.0) { return true }
  12714. if (this.segmentIndex === maxSegmentIndex) { return true }
  12715. return false
  12716. };
  12717. EdgeIntersection.prototype.toString = function toString () {
  12718. return this.coord + ' seg # = ' + this.segmentIndex + ' dist = ' + this.dist
  12719. };
  12720. EdgeIntersection.prototype.getDistance = function getDistance () {
  12721. return this.dist
  12722. };
  12723. EdgeIntersection.prototype.compare = function compare (segmentIndex, dist) {
  12724. if (this.segmentIndex < segmentIndex) { return -1 }
  12725. if (this.segmentIndex > segmentIndex) { return 1 }
  12726. if (this.dist < dist) { return -1 }
  12727. if (this.dist > dist) { return 1 }
  12728. return 0
  12729. };
  12730. EdgeIntersection.prototype.interfaces_ = function interfaces_ () {
  12731. return [Comparable]
  12732. };
  12733. EdgeIntersection.prototype.getClass = function getClass () {
  12734. return EdgeIntersection
  12735. };
  12736. var EdgeIntersectionList = function EdgeIntersectionList () {
  12737. this._nodeMap = new TreeMap();
  12738. this.edge = null;
  12739. var edge = arguments[0];
  12740. this.edge = edge;
  12741. };
  12742. EdgeIntersectionList.prototype.print = function print (out) {
  12743. out.println('Intersections:');
  12744. for (var it = this.iterator(); it.hasNext();) {
  12745. var ei = it.next();
  12746. ei.print(out);
  12747. }
  12748. };
  12749. EdgeIntersectionList.prototype.iterator = function iterator () {
  12750. return this._nodeMap.values().iterator()
  12751. };
  12752. EdgeIntersectionList.prototype.addSplitEdges = function addSplitEdges (edgeList) {
  12753. var this$1 = this;
  12754. this.addEndpoints();
  12755. var it = this.iterator();
  12756. var eiPrev = it.next();
  12757. while (it.hasNext()) {
  12758. var ei = it.next();
  12759. var newEdge = this$1.createSplitEdge(eiPrev, ei);
  12760. edgeList.add(newEdge);
  12761. eiPrev = ei;
  12762. }
  12763. };
  12764. EdgeIntersectionList.prototype.addEndpoints = function addEndpoints () {
  12765. var maxSegIndex = this.edge.pts.length - 1;
  12766. this.add(this.edge.pts[0], 0, 0.0);
  12767. this.add(this.edge.pts[maxSegIndex], maxSegIndex, 0.0);
  12768. };
  12769. EdgeIntersectionList.prototype.createSplitEdge = function createSplitEdge (ei0, ei1) {
  12770. var this$1 = this;
  12771. var npts = ei1.segmentIndex - ei0.segmentIndex + 2;
  12772. var lastSegStartPt = this.edge.pts[ei1.segmentIndex];
  12773. var useIntPt1 = ei1.dist > 0.0 || !ei1.coord.equals2D(lastSegStartPt);
  12774. if (!useIntPt1) {
  12775. npts--;
  12776. }
  12777. var pts = new Array(npts).fill(null);
  12778. var ipt = 0;
  12779. pts[ipt++] = new Coordinate(ei0.coord);
  12780. for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
  12781. pts[ipt++] = this$1.edge.pts[i];
  12782. }
  12783. if (useIntPt1) { pts[ipt] = ei1.coord; }
  12784. return new Edge(pts, new Label(this.edge._label))
  12785. };
  12786. EdgeIntersectionList.prototype.add = function add (intPt, segmentIndex, dist) {
  12787. var eiNew = new EdgeIntersection(intPt, segmentIndex, dist);
  12788. var ei = this._nodeMap.get(eiNew);
  12789. if (ei !== null) {
  12790. return ei
  12791. }
  12792. this._nodeMap.put(eiNew, eiNew);
  12793. return eiNew
  12794. };
  12795. EdgeIntersectionList.prototype.isIntersection = function isIntersection (pt) {
  12796. for (var it = this.iterator(); it.hasNext();) {
  12797. var ei = it.next();
  12798. if (ei.coord.equals(pt)) { return true }
  12799. }
  12800. return false
  12801. };
  12802. EdgeIntersectionList.prototype.interfaces_ = function interfaces_ () {
  12803. return []
  12804. };
  12805. EdgeIntersectionList.prototype.getClass = function getClass () {
  12806. return EdgeIntersectionList
  12807. };
  12808. var MonotoneChainIndexer = function MonotoneChainIndexer () {};
  12809. MonotoneChainIndexer.prototype.getChainStartIndices = function getChainStartIndices (pts) {
  12810. var this$1 = this;
  12811. var start = 0;
  12812. var startIndexList = new ArrayList();
  12813. startIndexList.add(new Integer(start));
  12814. do {
  12815. var last = this$1.findChainEnd(pts, start);
  12816. startIndexList.add(new Integer(last));
  12817. start = last;
  12818. } while (start < pts.length - 1)
  12819. var startIndex = MonotoneChainIndexer.toIntArray(startIndexList);
  12820. return startIndex
  12821. };
  12822. MonotoneChainIndexer.prototype.findChainEnd = function findChainEnd (pts, start) {
  12823. var chainQuad = Quadrant.quadrant(pts[start], pts[start + 1]);
  12824. var last = start + 1;
  12825. while (last < pts.length) {
  12826. var quad = Quadrant.quadrant(pts[last - 1], pts[last]);
  12827. if (quad !== chainQuad) { break }
  12828. last++;
  12829. }
  12830. return last - 1
  12831. };
  12832. MonotoneChainIndexer.prototype.interfaces_ = function interfaces_ () {
  12833. return []
  12834. };
  12835. MonotoneChainIndexer.prototype.getClass = function getClass () {
  12836. return MonotoneChainIndexer
  12837. };
  12838. MonotoneChainIndexer.toIntArray = function toIntArray (list) {
  12839. var array = new Array(list.size()).fill(null);
  12840. for (var i = 0; i < array.length; i++) {
  12841. array[i] = list.get(i).intValue();
  12842. }
  12843. return array
  12844. };
  12845. var MonotoneChainEdge = function MonotoneChainEdge () {
  12846. this.e = null;
  12847. this.pts = null;
  12848. this.startIndex = null;
  12849. this.env1 = new Envelope();
  12850. this.env2 = new Envelope();
  12851. var e = arguments[0];
  12852. this.e = e;
  12853. this.pts = e.getCoordinates();
  12854. var mcb = new MonotoneChainIndexer();
  12855. this.startIndex = mcb.getChainStartIndices(this.pts);
  12856. };
  12857. MonotoneChainEdge.prototype.getCoordinates = function getCoordinates () {
  12858. return this.pts
  12859. };
  12860. MonotoneChainEdge.prototype.getMaxX = function getMaxX (chainIndex) {
  12861. var x1 = this.pts[this.startIndex[chainIndex]].x;
  12862. var x2 = this.pts[this.startIndex[chainIndex + 1]].x;
  12863. return x1 > x2 ? x1 : x2
  12864. };
  12865. MonotoneChainEdge.prototype.getMinX = function getMinX (chainIndex) {
  12866. var x1 = this.pts[this.startIndex[chainIndex]].x;
  12867. var x2 = this.pts[this.startIndex[chainIndex + 1]].x;
  12868. return x1 < x2 ? x1 : x2
  12869. };
  12870. MonotoneChainEdge.prototype.computeIntersectsForChain = function computeIntersectsForChain () {
  12871. if (arguments.length === 4) {
  12872. var chainIndex0 = arguments[0];
  12873. var mce = arguments[1];
  12874. var chainIndex1 = arguments[2];
  12875. var si = arguments[3];
  12876. this.computeIntersectsForChain(this.startIndex[chainIndex0], this.startIndex[chainIndex0 + 1], mce, mce.startIndex[chainIndex1], mce.startIndex[chainIndex1 + 1], si);
  12877. } else if (arguments.length === 6) {
  12878. var start0 = arguments[0];
  12879. var end0 = arguments[1];
  12880. var mce$1 = arguments[2];
  12881. var start1 = arguments[3];
  12882. var end1 = arguments[4];
  12883. var ei = arguments[5];
  12884. var p00 = this.pts[start0];
  12885. var p01 = this.pts[end0];
  12886. var p10 = mce$1.pts[start1];
  12887. var p11 = mce$1.pts[end1];
  12888. if (end0 - start0 === 1 && end1 - start1 === 1) {
  12889. ei.addIntersections(this.e, start0, mce$1.e, start1);
  12890. return null
  12891. }
  12892. this.env1.init(p00, p01);
  12893. this.env2.init(p10, p11);
  12894. if (!this.env1.intersects(this.env2)) { return null }
  12895. var mid0 = Math.trunc((start0 + end0) / 2);
  12896. var mid1 = Math.trunc((start1 + end1) / 2);
  12897. if (start0 < mid0) {
  12898. if (start1 < mid1) { this.computeIntersectsForChain(start0, mid0, mce$1, start1, mid1, ei); }
  12899. if (mid1 < end1) { this.computeIntersectsForChain(start0, mid0, mce$1, mid1, end1, ei); }
  12900. }
  12901. if (mid0 < end0) {
  12902. if (start1 < mid1) { this.computeIntersectsForChain(mid0, end0, mce$1, start1, mid1, ei); }
  12903. if (mid1 < end1) { this.computeIntersectsForChain(mid0, end0, mce$1, mid1, end1, ei); }
  12904. }
  12905. }
  12906. };
  12907. MonotoneChainEdge.prototype.getStartIndexes = function getStartIndexes () {
  12908. return this.startIndex
  12909. };
  12910. MonotoneChainEdge.prototype.computeIntersects = function computeIntersects (mce, si) {
  12911. var this$1 = this;
  12912. for (var i = 0; i < this.startIndex.length - 1; i++) {
  12913. for (var j = 0; j < mce.startIndex.length - 1; j++) {
  12914. this$1.computeIntersectsForChain(i, mce, j, si);
  12915. }
  12916. }
  12917. };
  12918. MonotoneChainEdge.prototype.interfaces_ = function interfaces_ () {
  12919. return []
  12920. };
  12921. MonotoneChainEdge.prototype.getClass = function getClass () {
  12922. return MonotoneChainEdge
  12923. };
  12924. var Depth = function Depth () {
  12925. var this$1 = this;
  12926. this._depth = Array(2).fill().map(function () { return Array(3); });
  12927. for (var i = 0; i < 2; i++) {
  12928. for (var j = 0; j < 3; j++) {
  12929. this$1._depth[i][j] = Depth.NULL_VALUE;
  12930. }
  12931. }
  12932. };
  12933. var staticAccessors$31 = { NULL_VALUE: { configurable: true } };
  12934. Depth.prototype.getDepth = function getDepth (geomIndex, posIndex) {
  12935. return this._depth[geomIndex][posIndex]
  12936. };
  12937. Depth.prototype.setDepth = function setDepth (geomIndex, posIndex, depthValue) {
  12938. this._depth[geomIndex][posIndex] = depthValue;
  12939. };
  12940. Depth.prototype.isNull = function isNull () {
  12941. var this$1 = this;
  12942. if (arguments.length === 0) {
  12943. for (var i = 0; i < 2; i++) {
  12944. for (var j = 0; j < 3; j++) {
  12945. if (this$1._depth[i][j] !== Depth.NULL_VALUE) { return false }
  12946. }
  12947. }
  12948. return true
  12949. } else if (arguments.length === 1) {
  12950. var geomIndex = arguments[0];
  12951. return this._depth[geomIndex][1] === Depth.NULL_VALUE
  12952. } else if (arguments.length === 2) {
  12953. var geomIndex$1 = arguments[0];
  12954. var posIndex = arguments[1];
  12955. return this._depth[geomIndex$1][posIndex] === Depth.NULL_VALUE
  12956. }
  12957. };
  12958. Depth.prototype.normalize = function normalize () {
  12959. var this$1 = this;
  12960. for (var i = 0; i < 2; i++) {
  12961. if (!this$1.isNull(i)) {
  12962. var minDepth = this$1._depth[i][1];
  12963. if (this$1._depth[i][2] < minDepth) { minDepth = this$1._depth[i][2]; }
  12964. if (minDepth < 0) { minDepth = 0; }
  12965. for (var j = 1; j < 3; j++) {
  12966. var newValue = 0;
  12967. if (this$1._depth[i][j] > minDepth) { newValue = 1; }
  12968. this$1._depth[i][j] = newValue;
  12969. }
  12970. }
  12971. }
  12972. };
  12973. Depth.prototype.getDelta = function getDelta (geomIndex) {
  12974. return this._depth[geomIndex][Position.RIGHT] - this._depth[geomIndex][Position.LEFT]
  12975. };
  12976. Depth.prototype.getLocation = function getLocation (geomIndex, posIndex) {
  12977. if (this._depth[geomIndex][posIndex] <= 0) { return Location.EXTERIOR }
  12978. return Location.INTERIOR
  12979. };
  12980. Depth.prototype.toString = function toString () {
  12981. return 'A: ' + this._depth[0][1] + ',' + this._depth[0][2] + ' B: ' + this._depth[1][1] + ',' + this._depth[1][2]
  12982. };
  12983. Depth.prototype.add = function add () {
  12984. var this$1 = this;
  12985. if (arguments.length === 1) {
  12986. var lbl = arguments[0];
  12987. for (var i = 0; i < 2; i++) {
  12988. for (var j = 1; j < 3; j++) {
  12989. var loc = lbl.getLocation(i, j);
  12990. if (loc === Location.EXTERIOR || loc === Location.INTERIOR) {
  12991. if (this$1.isNull(i, j)) {
  12992. this$1._depth[i][j] = Depth.depthAtLocation(loc);
  12993. } else { this$1._depth[i][j] += Depth.depthAtLocation(loc); }
  12994. }
  12995. }
  12996. }
  12997. } else if (arguments.length === 3) {
  12998. var geomIndex = arguments[0];
  12999. var posIndex = arguments[1];
  13000. var location = arguments[2];
  13001. if (location === Location.INTERIOR) { this._depth[geomIndex][posIndex]++; }
  13002. }
  13003. };
  13004. Depth.prototype.interfaces_ = function interfaces_ () {
  13005. return []
  13006. };
  13007. Depth.prototype.getClass = function getClass () {
  13008. return Depth
  13009. };
  13010. Depth.depthAtLocation = function depthAtLocation (location) {
  13011. if (location === Location.EXTERIOR) { return 0 }
  13012. if (location === Location.INTERIOR) { return 1 }
  13013. return Depth.NULL_VALUE
  13014. };
  13015. staticAccessors$31.NULL_VALUE.get = function () { return -1 };
  13016. Object.defineProperties( Depth, staticAccessors$31 );
  13017. var Edge = (function (GraphComponent$$1) {
  13018. function Edge () {
  13019. GraphComponent$$1.call(this);
  13020. this.pts = null;
  13021. this._env = null;
  13022. this.eiList = new EdgeIntersectionList(this);
  13023. this._name = null;
  13024. this._mce = null;
  13025. this._isIsolated = true;
  13026. this._depth = new Depth();
  13027. this._depthDelta = 0;
  13028. if (arguments.length === 1) {
  13029. var pts = arguments[0];
  13030. Edge.call(this, pts, null);
  13031. } else if (arguments.length === 2) {
  13032. var pts$1 = arguments[0];
  13033. var label = arguments[1];
  13034. this.pts = pts$1;
  13035. this._label = label;
  13036. }
  13037. }
  13038. if ( GraphComponent$$1 ) Edge.__proto__ = GraphComponent$$1;
  13039. Edge.prototype = Object.create( GraphComponent$$1 && GraphComponent$$1.prototype );
  13040. Edge.prototype.constructor = Edge;
  13041. Edge.prototype.getDepth = function getDepth () {
  13042. return this._depth
  13043. };
  13044. Edge.prototype.getCollapsedEdge = function getCollapsedEdge () {
  13045. var newPts = new Array(2).fill(null);
  13046. newPts[0] = this.pts[0];
  13047. newPts[1] = this.pts[1];
  13048. var newe = new Edge(newPts, Label.toLineLabel(this._label));
  13049. return newe
  13050. };
  13051. Edge.prototype.isIsolated = function isIsolated () {
  13052. return this._isIsolated
  13053. };
  13054. Edge.prototype.getCoordinates = function getCoordinates () {
  13055. return this.pts
  13056. };
  13057. Edge.prototype.setIsolated = function setIsolated (isIsolated) {
  13058. this._isIsolated = isIsolated;
  13059. };
  13060. Edge.prototype.setName = function setName (name) {
  13061. this._name = name;
  13062. };
  13063. Edge.prototype.equals = function equals (o) {
  13064. var this$1 = this;
  13065. if (!(o instanceof Edge)) { return false }
  13066. var e = o;
  13067. if (this.pts.length !== e.pts.length) { return false }
  13068. var isEqualForward = true;
  13069. var isEqualReverse = true;
  13070. var iRev = this.pts.length;
  13071. for (var i = 0; i < this.pts.length; i++) {
  13072. if (!this$1.pts[i].equals2D(e.pts[i])) {
  13073. isEqualForward = false;
  13074. }
  13075. if (!this$1.pts[i].equals2D(e.pts[--iRev])) {
  13076. isEqualReverse = false;
  13077. }
  13078. if (!isEqualForward && !isEqualReverse) { return false }
  13079. }
  13080. return true
  13081. };
  13082. Edge.prototype.getCoordinate = function getCoordinate () {
  13083. if (arguments.length === 0) {
  13084. if (this.pts.length > 0) { return this.pts[0] }
  13085. return null
  13086. } else if (arguments.length === 1) {
  13087. var i = arguments[0];
  13088. return this.pts[i]
  13089. }
  13090. };
  13091. Edge.prototype.print = function print (out) {
  13092. var this$1 = this;
  13093. out.print('edge ' + this._name + ': ');
  13094. out.print('LINESTRING (');
  13095. for (var i = 0; i < this.pts.length; i++) {
  13096. if (i > 0) { out.print(','); }
  13097. out.print(this$1.pts[i].x + ' ' + this$1.pts[i].y);
  13098. }
  13099. out.print(') ' + this._label + ' ' + this._depthDelta);
  13100. };
  13101. Edge.prototype.computeIM = function computeIM (im) {
  13102. Edge.updateIM(this._label, im);
  13103. };
  13104. Edge.prototype.isCollapsed = function isCollapsed () {
  13105. if (!this._label.isArea()) { return false }
  13106. if (this.pts.length !== 3) { return false }
  13107. if (this.pts[0].equals(this.pts[2])) { return true }
  13108. return false
  13109. };
  13110. Edge.prototype.isClosed = function isClosed () {
  13111. return this.pts[0].equals(this.pts[this.pts.length - 1])
  13112. };
  13113. Edge.prototype.getMaximumSegmentIndex = function getMaximumSegmentIndex () {
  13114. return this.pts.length - 1
  13115. };
  13116. Edge.prototype.getDepthDelta = function getDepthDelta () {
  13117. return this._depthDelta
  13118. };
  13119. Edge.prototype.getNumPoints = function getNumPoints () {
  13120. return this.pts.length
  13121. };
  13122. Edge.prototype.printReverse = function printReverse (out) {
  13123. var this$1 = this;
  13124. out.print('edge ' + this._name + ': ');
  13125. for (var i = this.pts.length - 1; i >= 0; i--) {
  13126. out.print(this$1.pts[i] + ' ');
  13127. }
  13128. out.println('');
  13129. };
  13130. Edge.prototype.getMonotoneChainEdge = function getMonotoneChainEdge () {
  13131. if (this._mce === null) { this._mce = new MonotoneChainEdge(this); }
  13132. return this._mce
  13133. };
  13134. Edge.prototype.getEnvelope = function getEnvelope () {
  13135. var this$1 = this;
  13136. if (this._env === null) {
  13137. this._env = new Envelope();
  13138. for (var i = 0; i < this.pts.length; i++) {
  13139. this$1._env.expandToInclude(this$1.pts[i]);
  13140. }
  13141. }
  13142. return this._env
  13143. };
  13144. Edge.prototype.addIntersection = function addIntersection (li, segmentIndex, geomIndex, intIndex) {
  13145. var intPt = new Coordinate(li.getIntersection(intIndex));
  13146. var normalizedSegmentIndex = segmentIndex;
  13147. var dist = li.getEdgeDistance(geomIndex, intIndex);
  13148. var nextSegIndex = normalizedSegmentIndex + 1;
  13149. if (nextSegIndex < this.pts.length) {
  13150. var nextPt = this.pts[nextSegIndex];
  13151. if (intPt.equals2D(nextPt)) {
  13152. normalizedSegmentIndex = nextSegIndex;
  13153. dist = 0.0;
  13154. }
  13155. }
  13156. this.eiList.add(intPt, normalizedSegmentIndex, dist);
  13157. };
  13158. Edge.prototype.toString = function toString () {
  13159. var this$1 = this;
  13160. var buf = new StringBuffer();
  13161. buf.append('edge ' + this._name + ': ');
  13162. buf.append('LINESTRING (');
  13163. for (var i = 0; i < this.pts.length; i++) {
  13164. if (i > 0) { buf.append(','); }
  13165. buf.append(this$1.pts[i].x + ' ' + this$1.pts[i].y);
  13166. }
  13167. buf.append(') ' + this._label + ' ' + this._depthDelta);
  13168. return buf.toString()
  13169. };
  13170. Edge.prototype.isPointwiseEqual = function isPointwiseEqual (e) {
  13171. var this$1 = this;
  13172. if (this.pts.length !== e.pts.length) { return false }
  13173. for (var i = 0; i < this.pts.length; i++) {
  13174. if (!this$1.pts[i].equals2D(e.pts[i])) {
  13175. return false
  13176. }
  13177. }
  13178. return true
  13179. };
  13180. Edge.prototype.setDepthDelta = function setDepthDelta (depthDelta) {
  13181. this._depthDelta = depthDelta;
  13182. };
  13183. Edge.prototype.getEdgeIntersectionList = function getEdgeIntersectionList () {
  13184. return this.eiList
  13185. };
  13186. Edge.prototype.addIntersections = function addIntersections (li, segmentIndex, geomIndex) {
  13187. var this$1 = this;
  13188. for (var i = 0; i < li.getIntersectionNum(); i++) {
  13189. this$1.addIntersection(li, segmentIndex, geomIndex, i);
  13190. }
  13191. };
  13192. Edge.prototype.interfaces_ = function interfaces_ () {
  13193. return []
  13194. };
  13195. Edge.prototype.getClass = function getClass () {
  13196. return Edge
  13197. };
  13198. Edge.updateIM = function updateIM () {
  13199. if (arguments.length === 2) {
  13200. var label = arguments[0];
  13201. var im = arguments[1];
  13202. im.setAtLeastIfValid(label.getLocation(0, Position.ON), label.getLocation(1, Position.ON), 1);
  13203. if (label.isArea()) {
  13204. im.setAtLeastIfValid(label.getLocation(0, Position.LEFT), label.getLocation(1, Position.LEFT), 2);
  13205. im.setAtLeastIfValid(label.getLocation(0, Position.RIGHT), label.getLocation(1, Position.RIGHT), 2);
  13206. }
  13207. } else { return GraphComponent$$1.prototype.updateIM.apply(this, arguments) }
  13208. };
  13209. return Edge;
  13210. }(GraphComponent));
  13211. var BufferBuilder = function BufferBuilder (bufParams) {
  13212. this._workingPrecisionModel = null;
  13213. this._workingNoder = null;
  13214. this._geomFact = null;
  13215. this._graph = null;
  13216. this._edgeList = new EdgeList();
  13217. this._bufParams = bufParams || null;
  13218. };
  13219. BufferBuilder.prototype.setWorkingPrecisionModel = function setWorkingPrecisionModel (pm) {
  13220. this._workingPrecisionModel = pm;
  13221. };
  13222. BufferBuilder.prototype.insertUniqueEdge = function insertUniqueEdge (e) {
  13223. var existingEdge = this._edgeList.findEqualEdge(e);
  13224. if (existingEdge !== null) {
  13225. var existingLabel = existingEdge.getLabel();
  13226. var labelToMerge = e.getLabel();
  13227. if (!existingEdge.isPointwiseEqual(e)) {
  13228. labelToMerge = new Label(e.getLabel());
  13229. labelToMerge.flip();
  13230. }
  13231. existingLabel.merge(labelToMerge);
  13232. var mergeDelta = BufferBuilder.depthDelta(labelToMerge);
  13233. var existingDelta = existingEdge.getDepthDelta();
  13234. var newDelta = existingDelta + mergeDelta;
  13235. existingEdge.setDepthDelta(newDelta);
  13236. } else {
  13237. this._edgeList.add(e);
  13238. e.setDepthDelta(BufferBuilder.depthDelta(e.getLabel()));
  13239. }
  13240. };
  13241. BufferBuilder.prototype.buildSubgraphs = function buildSubgraphs (subgraphList, polyBuilder) {
  13242. var processedGraphs = new ArrayList();
  13243. for (var i = subgraphList.iterator(); i.hasNext();) {
  13244. var subgraph = i.next();
  13245. var p = subgraph.getRightmostCoordinate();
  13246. var locater = new SubgraphDepthLocater(processedGraphs);
  13247. var outsideDepth = locater.getDepth(p);
  13248. subgraph.computeDepth(outsideDepth);
  13249. subgraph.findResultEdges();
  13250. processedGraphs.add(subgraph);
  13251. polyBuilder.add(subgraph.getDirectedEdges(), subgraph.getNodes());
  13252. }
  13253. };
  13254. BufferBuilder.prototype.createSubgraphs = function createSubgraphs (graph) {
  13255. var subgraphList = new ArrayList();
  13256. for (var i = graph.getNodes().iterator(); i.hasNext();) {
  13257. var node = i.next();
  13258. if (!node.isVisited()) {
  13259. var subgraph = new BufferSubgraph();
  13260. subgraph.create(node);
  13261. subgraphList.add(subgraph);
  13262. }
  13263. }
  13264. Collections.sort(subgraphList, Collections.reverseOrder());
  13265. return subgraphList
  13266. };
  13267. BufferBuilder.prototype.createEmptyResultGeometry = function createEmptyResultGeometry () {
  13268. var emptyGeom = this._geomFact.createPolygon();
  13269. return emptyGeom
  13270. };
  13271. BufferBuilder.prototype.getNoder = function getNoder (precisionModel) {
  13272. if (this._workingNoder !== null) { return this._workingNoder }
  13273. var noder = new MCIndexNoder();
  13274. var li = new RobustLineIntersector();
  13275. li.setPrecisionModel(precisionModel);
  13276. noder.setSegmentIntersector(new IntersectionAdder(li));
  13277. return noder
  13278. };
  13279. BufferBuilder.prototype.buffer = function buffer (g, distance) {
  13280. var precisionModel = this._workingPrecisionModel;
  13281. if (precisionModel === null) { precisionModel = g.getPrecisionModel(); }
  13282. this._geomFact = g.getFactory();
  13283. var curveBuilder = new OffsetCurveBuilder(precisionModel, this._bufParams);
  13284. var curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);
  13285. var bufferSegStrList = curveSetBuilder.getCurves();
  13286. if (bufferSegStrList.size() <= 0) {
  13287. return this.createEmptyResultGeometry()
  13288. }
  13289. this.computeNodedEdges(bufferSegStrList, precisionModel);
  13290. this._graph = new PlanarGraph(new OverlayNodeFactory());
  13291. this._graph.addEdges(this._edgeList.getEdges());
  13292. var subgraphList = this.createSubgraphs(this._graph);
  13293. var polyBuilder = new PolygonBuilder(this._geomFact);
  13294. this.buildSubgraphs(subgraphList, polyBuilder);
  13295. var resultPolyList = polyBuilder.getPolygons();
  13296. if (resultPolyList.size() <= 0) {
  13297. return this.createEmptyResultGeometry()
  13298. }
  13299. var resultGeom = this._geomFact.buildGeometry(resultPolyList);
  13300. return resultGeom
  13301. };
  13302. BufferBuilder.prototype.computeNodedEdges = function computeNodedEdges (bufferSegStrList, precisionModel) {
  13303. var this$1 = this;
  13304. var noder = this.getNoder(precisionModel);
  13305. noder.computeNodes(bufferSegStrList);
  13306. var nodedSegStrings = noder.getNodedSubstrings();
  13307. for (var i = nodedSegStrings.iterator(); i.hasNext();) {
  13308. var segStr = i.next();
  13309. var pts = segStr.getCoordinates();
  13310. if (pts.length === 2 && pts[0].equals2D(pts[1])) { continue }
  13311. var oldLabel = segStr.getData();
  13312. var edge = new Edge(segStr.getCoordinates(), new Label(oldLabel));
  13313. this$1.insertUniqueEdge(edge);
  13314. }
  13315. };
  13316. BufferBuilder.prototype.setNoder = function setNoder (noder) {
  13317. this._workingNoder = noder;
  13318. };
  13319. BufferBuilder.prototype.interfaces_ = function interfaces_ () {
  13320. return []
  13321. };
  13322. BufferBuilder.prototype.getClass = function getClass () {
  13323. return BufferBuilder
  13324. };
  13325. BufferBuilder.depthDelta = function depthDelta (label) {
  13326. var lLoc = label.getLocation(0, Position.LEFT);
  13327. var rLoc = label.getLocation(0, Position.RIGHT);
  13328. if (lLoc === Location.INTERIOR && rLoc === Location.EXTERIOR) { return 1; } else if (lLoc === Location.EXTERIOR && rLoc === Location.INTERIOR) { return -1 }
  13329. return 0
  13330. };
  13331. BufferBuilder.convertSegStrings = function convertSegStrings (it) {
  13332. var fact = new GeometryFactory();
  13333. var lines = new ArrayList();
  13334. while (it.hasNext()) {
  13335. var ss = it.next();
  13336. var line = fact.createLineString(ss.getCoordinates());
  13337. lines.add(line);
  13338. }
  13339. return fact.buildGeometry(lines)
  13340. };
  13341. var ScaledNoder = function ScaledNoder () {
  13342. this._noder = null;
  13343. this._scaleFactor = null;
  13344. this._offsetX = null;
  13345. this._offsetY = null;
  13346. this._isScaled = false;
  13347. if (arguments.length === 2) {
  13348. var noder = arguments[0];
  13349. var scaleFactor = arguments[1];
  13350. this._noder = noder;
  13351. this._scaleFactor = scaleFactor;
  13352. this._offsetX = 0.0;
  13353. this._offsetY = 0.0;
  13354. this._isScaled = !this.isIntegerPrecision();
  13355. } else if (arguments.length === 4) {
  13356. var noder$1 = arguments[0];
  13357. var scaleFactor$1 = arguments[1];
  13358. var offsetX = arguments[2];
  13359. var offsetY = arguments[3];
  13360. this._noder = noder$1;
  13361. this._scaleFactor = scaleFactor$1;
  13362. this._offsetX = offsetX;
  13363. this._offsetY = offsetY;
  13364. this._isScaled = !this.isIntegerPrecision();
  13365. }
  13366. };
  13367. ScaledNoder.prototype.rescale = function rescale () {
  13368. var this$1 = this;
  13369. if (hasInterface(arguments[0], Collection)) {
  13370. var segStrings = arguments[0];
  13371. for (var i = segStrings.iterator(); i.hasNext();) {
  13372. var ss = i.next();
  13373. this$1.rescale(ss.getCoordinates());
  13374. }
  13375. } else if (arguments[0] instanceof Array) {
  13376. var pts = arguments[0];
  13377. // let p0 = null
  13378. // let p1 = null
  13379. // if (pts.length === 2) {
  13380. // p0 = new Coordinate(pts[0])
  13381. // p1 = new Coordinate(pts[1])
  13382. // }
  13383. for (var i$1 = 0; i$1 < pts.length; i$1++) {
  13384. pts[i$1].x = pts[i$1].x / this$1._scaleFactor + this$1._offsetX;
  13385. pts[i$1].y = pts[i$1].y / this$1._scaleFactor + this$1._offsetY;
  13386. }
  13387. if (pts.length === 2 && pts[0].equals2D(pts[1])) {
  13388. System.out.println(pts);
  13389. }
  13390. }
  13391. };
  13392. ScaledNoder.prototype.scale = function scale () {
  13393. var this$1 = this;
  13394. if (hasInterface(arguments[0], Collection)) {
  13395. var segStrings = arguments[0];
  13396. var nodedSegmentStrings = new ArrayList();
  13397. for (var i = segStrings.iterator(); i.hasNext();) {
  13398. var ss = i.next();
  13399. nodedSegmentStrings.add(new NodedSegmentString(this$1.scale(ss.getCoordinates()), ss.getData()));
  13400. }
  13401. return nodedSegmentStrings
  13402. } else if (arguments[0] instanceof Array) {
  13403. var pts = arguments[0];
  13404. var roundPts = new Array(pts.length).fill(null);
  13405. for (var i$1 = 0; i$1 < pts.length; i$1++) {
  13406. 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);
  13407. }
  13408. var roundPtsNoDup = CoordinateArrays.removeRepeatedPoints(roundPts);
  13409. return roundPtsNoDup
  13410. }
  13411. };
  13412. ScaledNoder.prototype.isIntegerPrecision = function isIntegerPrecision () {
  13413. return this._scaleFactor === 1.0
  13414. };
  13415. ScaledNoder.prototype.getNodedSubstrings = function getNodedSubstrings () {
  13416. var splitSS = this._noder.getNodedSubstrings();
  13417. if (this._isScaled) { this.rescale(splitSS); }
  13418. return splitSS
  13419. };
  13420. ScaledNoder.prototype.computeNodes = function computeNodes (inputSegStrings) {
  13421. var intSegStrings = inputSegStrings;
  13422. if (this._isScaled) { intSegStrings = this.scale(inputSegStrings); }
  13423. this._noder.computeNodes(intSegStrings);
  13424. };
  13425. ScaledNoder.prototype.interfaces_ = function interfaces_ () {
  13426. return [Noder]
  13427. };
  13428. ScaledNoder.prototype.getClass = function getClass () {
  13429. return ScaledNoder
  13430. };
  13431. var NodingValidator = function NodingValidator () {
  13432. this._li = new RobustLineIntersector();
  13433. this._segStrings = null;
  13434. var segStrings = arguments[0];
  13435. this._segStrings = segStrings;
  13436. };
  13437. var staticAccessors$33 = { fact: { configurable: true } };
  13438. NodingValidator.prototype.checkEndPtVertexIntersections = function checkEndPtVertexIntersections () {
  13439. var this$1 = this;
  13440. if (arguments.length === 0) {
  13441. for (var i = this._segStrings.iterator(); i.hasNext();) {
  13442. var ss = i.next();
  13443. var pts = ss.getCoordinates();
  13444. this$1.checkEndPtVertexIntersections(pts[0], this$1._segStrings);
  13445. this$1.checkEndPtVertexIntersections(pts[pts.length - 1], this$1._segStrings);
  13446. }
  13447. } else if (arguments.length === 2) {
  13448. var testPt = arguments[0];
  13449. var segStrings = arguments[1];
  13450. for (var i$1 = segStrings.iterator(); i$1.hasNext();) {
  13451. var ss$1 = i$1.next();
  13452. var pts$1 = ss$1.getCoordinates();
  13453. for (var j = 1; j < pts$1.length - 1; j++) {
  13454. if (pts$1[j].equals(testPt)) { throw new RuntimeException('found endpt/interior pt intersection at index ' + j + ' :pt ' + testPt) }
  13455. }
  13456. }
  13457. }
  13458. };
  13459. NodingValidator.prototype.checkInteriorIntersections = function checkInteriorIntersections () {
  13460. var this$1 = this;
  13461. if (arguments.length === 0) {
  13462. for (var i = this._segStrings.iterator(); i.hasNext();) {
  13463. var ss0 = i.next();
  13464. for (var j = this._segStrings.iterator(); j.hasNext();) {
  13465. var ss1 = j.next();
  13466. this$1.checkInteriorIntersections(ss0, ss1);
  13467. }
  13468. }
  13469. } else if (arguments.length === 2) {
  13470. var ss0$1 = arguments[0];
  13471. var ss1$1 = arguments[1];
  13472. var pts0 = ss0$1.getCoordinates();
  13473. var pts1 = ss1$1.getCoordinates();
  13474. for (var i0 = 0; i0 < pts0.length - 1; i0++) {
  13475. for (var i1 = 0; i1 < pts1.length - 1; i1++) {
  13476. this$1.checkInteriorIntersections(ss0$1, i0, ss1$1, i1);
  13477. }
  13478. }
  13479. } else if (arguments.length === 4) {
  13480. var e0 = arguments[0];
  13481. var segIndex0 = arguments[1];
  13482. var e1 = arguments[2];
  13483. var segIndex1 = arguments[3];
  13484. if (e0 === e1 && segIndex0 === segIndex1) { return null }
  13485. var p00 = e0.getCoordinates()[segIndex0];
  13486. var p01 = e0.getCoordinates()[segIndex0 + 1];
  13487. var p10 = e1.getCoordinates()[segIndex1];
  13488. var p11 = e1.getCoordinates()[segIndex1 + 1];
  13489. this._li.computeIntersection(p00, p01, p10, p11);
  13490. if (this._li.hasIntersection()) {
  13491. if (this._li.isProper() || this.hasInteriorIntersection(this._li, p00, p01) || this.hasInteriorIntersection(this._li, p10, p11)) {
  13492. throw new RuntimeException('found non-noded intersection at ' + p00 + '-' + p01 + ' and ' + p10 + '-' + p11)
  13493. }
  13494. }
  13495. }
  13496. };
  13497. NodingValidator.prototype.checkValid = function checkValid () {
  13498. this.checkEndPtVertexIntersections();
  13499. this.checkInteriorIntersections();
  13500. this.checkCollapses();
  13501. };
  13502. NodingValidator.prototype.checkCollapses = function checkCollapses () {
  13503. var this$1 = this;
  13504. if (arguments.length === 0) {
  13505. for (var i = this._segStrings.iterator(); i.hasNext();) {
  13506. var ss = i.next();
  13507. this$1.checkCollapses(ss);
  13508. }
  13509. } else if (arguments.length === 1) {
  13510. var ss$1 = arguments[0];
  13511. var pts = ss$1.getCoordinates();
  13512. for (var i$1 = 0; i$1 < pts.length - 2; i$1++) {
  13513. this$1.checkCollapse(pts[i$1], pts[i$1 + 1], pts[i$1 + 2]);
  13514. }
  13515. }
  13516. };
  13517. NodingValidator.prototype.hasInteriorIntersection = function hasInteriorIntersection (li, p0, p1) {
  13518. for (var i = 0; i < li.getIntersectionNum(); i++) {
  13519. var intPt = li.getIntersection(i);
  13520. if (!(intPt.equals(p0) || intPt.equals(p1))) { return true }
  13521. }
  13522. return false
  13523. };
  13524. NodingValidator.prototype.checkCollapse = function checkCollapse (p0, p1, p2) {
  13525. if (p0.equals(p2)) { throw new RuntimeException('found non-noded collapse at ' + NodingValidator.fact.createLineString([p0, p1, p2])) }
  13526. };
  13527. NodingValidator.prototype.interfaces_ = function interfaces_ () {
  13528. return []
  13529. };
  13530. NodingValidator.prototype.getClass = function getClass () {
  13531. return NodingValidator
  13532. };
  13533. staticAccessors$33.fact.get = function () { return new GeometryFactory() };
  13534. Object.defineProperties( NodingValidator, staticAccessors$33 );
  13535. var HotPixel = function HotPixel () {
  13536. this._li = null;
  13537. this._pt = null;
  13538. this._originalPt = null;
  13539. this._ptScaled = null;
  13540. this._p0Scaled = null;
  13541. this._p1Scaled = null;
  13542. this._scaleFactor = null;
  13543. this._minx = null;
  13544. this._maxx = null;
  13545. this._miny = null;
  13546. this._maxy = null;
  13547. this._corner = new Array(4).fill(null);
  13548. this._safeEnv = null;
  13549. var pt = arguments[0];
  13550. var scaleFactor = arguments[1];
  13551. var li = arguments[2];
  13552. this._originalPt = pt;
  13553. this._pt = pt;
  13554. this._scaleFactor = scaleFactor;
  13555. this._li = li;
  13556. if (scaleFactor <= 0) { throw new IllegalArgumentException('Scale factor must be non-zero') }
  13557. if (scaleFactor !== 1.0) {
  13558. this._pt = new Coordinate(this.scale(pt.x), this.scale(pt.y));
  13559. this._p0Scaled = new Coordinate();
  13560. this._p1Scaled = new Coordinate();
  13561. }
  13562. this.initCorners(this._pt);
  13563. };
  13564. var staticAccessors$34 = { SAFE_ENV_EXPANSION_FACTOR: { configurable: true } };
  13565. HotPixel.prototype.intersectsScaled = function intersectsScaled (p0, p1) {
  13566. var segMinx = Math.min(p0.x, p1.x);
  13567. var segMaxx = Math.max(p0.x, p1.x);
  13568. var segMiny = Math.min(p0.y, p1.y);
  13569. var segMaxy = Math.max(p0.y, p1.y);
  13570. var isOutsidePixelEnv = this._maxx < segMinx || this._minx > segMaxx || this._maxy < segMiny || this._miny > segMaxy;
  13571. if (isOutsidePixelEnv) { return false }
  13572. var intersects = this.intersectsToleranceSquare(p0, p1);
  13573. Assert.isTrue(!(isOutsidePixelEnv && intersects), 'Found bad envelope test');
  13574. return intersects
  13575. };
  13576. HotPixel.prototype.initCorners = function initCorners (pt) {
  13577. var tolerance = 0.5;
  13578. this._minx = pt.x - tolerance;
  13579. this._maxx = pt.x + tolerance;
  13580. this._miny = pt.y - tolerance;
  13581. this._maxy = pt.y + tolerance;
  13582. this._corner[0] = new Coordinate(this._maxx, this._maxy);
  13583. this._corner[1] = new Coordinate(this._minx, this._maxy);
  13584. this._corner[2] = new Coordinate(this._minx, this._miny);
  13585. this._corner[3] = new Coordinate(this._maxx, this._miny);
  13586. };
  13587. HotPixel.prototype.intersects = function intersects (p0, p1) {
  13588. if (this._scaleFactor === 1.0) { return this.intersectsScaled(p0, p1) }
  13589. this.copyScaled(p0, this._p0Scaled);
  13590. this.copyScaled(p1, this._p1Scaled);
  13591. return this.intersectsScaled(this._p0Scaled, this._p1Scaled)
  13592. };
  13593. HotPixel.prototype.scale = function scale (val) {
  13594. return Math.round(val * this._scaleFactor)
  13595. };
  13596. HotPixel.prototype.getCoordinate = function getCoordinate () {
  13597. return this._originalPt
  13598. };
  13599. HotPixel.prototype.copyScaled = function copyScaled (p, pScaled) {
  13600. pScaled.x = this.scale(p.x);
  13601. pScaled.y = this.scale(p.y);
  13602. };
  13603. HotPixel.prototype.getSafeEnvelope = function getSafeEnvelope () {
  13604. if (this._safeEnv === null) {
  13605. var safeTolerance = HotPixel.SAFE_ENV_EXPANSION_FACTOR / this._scaleFactor;
  13606. this._safeEnv = new Envelope(this._originalPt.x - safeTolerance, this._originalPt.x + safeTolerance, this._originalPt.y - safeTolerance, this._originalPt.y + safeTolerance);
  13607. }
  13608. return this._safeEnv
  13609. };
  13610. HotPixel.prototype.intersectsPixelClosure = function intersectsPixelClosure (p0, p1) {
  13611. this._li.computeIntersection(p0, p1, this._corner[0], this._corner[1]);
  13612. if (this._li.hasIntersection()) { return true }
  13613. this._li.computeIntersection(p0, p1, this._corner[1], this._corner[2]);
  13614. if (this._li.hasIntersection()) { return true }
  13615. this._li.computeIntersection(p0, p1, this._corner[2], this._corner[3]);
  13616. if (this._li.hasIntersection()) { return true }
  13617. this._li.computeIntersection(p0, p1, this._corner[3], this._corner[0]);
  13618. if (this._li.hasIntersection()) { return true }
  13619. return false
  13620. };
  13621. HotPixel.prototype.intersectsToleranceSquare = function intersectsToleranceSquare (p0, p1) {
  13622. var intersectsLeft = false;
  13623. var intersectsBottom = false;
  13624. this._li.computeIntersection(p0, p1, this._corner[0], this._corner[1]);
  13625. if (this._li.isProper()) { return true }
  13626. this._li.computeIntersection(p0, p1, this._corner[1], this._corner[2]);
  13627. if (this._li.isProper()) { return true }
  13628. if (this._li.hasIntersection()) { intersectsLeft = true; }
  13629. this._li.computeIntersection(p0, p1, this._corner[2], this._corner[3]);
  13630. if (this._li.isProper()) { return true }
  13631. if (this._li.hasIntersection()) { intersectsBottom = true; }
  13632. this._li.computeIntersection(p0, p1, this._corner[3], this._corner[0]);
  13633. if (this._li.isProper()) { return true }
  13634. if (intersectsLeft && intersectsBottom) { return true }
  13635. if (p0.equals(this._pt)) { return true }
  13636. if (p1.equals(this._pt)) { return true }
  13637. return false
  13638. };
  13639. HotPixel.prototype.addSnappedNode = function addSnappedNode (segStr, segIndex) {
  13640. var p0 = segStr.getCoordinate(segIndex);
  13641. var p1 = segStr.getCoordinate(segIndex + 1);
  13642. if (this.intersects(p0, p1)) {
  13643. segStr.addIntersection(this.getCoordinate(), segIndex);
  13644. return true
  13645. }
  13646. return false
  13647. };
  13648. HotPixel.prototype.interfaces_ = function interfaces_ () {
  13649. return []
  13650. };
  13651. HotPixel.prototype.getClass = function getClass () {
  13652. return HotPixel
  13653. };
  13654. staticAccessors$34.SAFE_ENV_EXPANSION_FACTOR.get = function () { return 0.75 };
  13655. Object.defineProperties( HotPixel, staticAccessors$34 );
  13656. var MonotoneChainSelectAction = function MonotoneChainSelectAction () {
  13657. this.tempEnv1 = new Envelope();
  13658. this.selectedSegment = new LineSegment();
  13659. };
  13660. MonotoneChainSelectAction.prototype.select = function select () {
  13661. if (arguments.length === 1) {
  13662. // const seg = arguments[0]
  13663. } else if (arguments.length === 2) {
  13664. var mc = arguments[0];
  13665. var startIndex = arguments[1];
  13666. mc.getLineSegment(startIndex, this.selectedSegment);
  13667. this.select(this.selectedSegment);
  13668. }
  13669. };
  13670. MonotoneChainSelectAction.prototype.interfaces_ = function interfaces_ () {
  13671. return []
  13672. };
  13673. MonotoneChainSelectAction.prototype.getClass = function getClass () {
  13674. return MonotoneChainSelectAction
  13675. };
  13676. var MCIndexPointSnapper = function MCIndexPointSnapper () {
  13677. this._index = null;
  13678. var index = arguments[0];
  13679. this._index = index;
  13680. };
  13681. var staticAccessors$35 = { HotPixelSnapAction: { configurable: true } };
  13682. MCIndexPointSnapper.prototype.snap = function snap () {
  13683. if (arguments.length === 1) {
  13684. var hotPixel = arguments[0];
  13685. return this.snap(hotPixel, null, -1)
  13686. } else if (arguments.length === 3) {
  13687. var hotPixel$1 = arguments[0];
  13688. var parentEdge = arguments[1];
  13689. var hotPixelVertexIndex = arguments[2];
  13690. var pixelEnv = hotPixel$1.getSafeEnvelope();
  13691. var hotPixelSnapAction = new HotPixelSnapAction(hotPixel$1, parentEdge, hotPixelVertexIndex);
  13692. this._index.query(pixelEnv, {
  13693. interfaces_: function () {
  13694. return [ItemVisitor]
  13695. },
  13696. visitItem: function (item) {
  13697. var testChain = item;
  13698. testChain.select(pixelEnv, hotPixelSnapAction);
  13699. }
  13700. });
  13701. return hotPixelSnapAction.isNodeAdded()
  13702. }
  13703. };
  13704. MCIndexPointSnapper.prototype.interfaces_ = function interfaces_ () {
  13705. return []
  13706. };
  13707. MCIndexPointSnapper.prototype.getClass = function getClass () {
  13708. return MCIndexPointSnapper
  13709. };
  13710. staticAccessors$35.HotPixelSnapAction.get = function () { return HotPixelSnapAction };
  13711. Object.defineProperties( MCIndexPointSnapper, staticAccessors$35 );
  13712. var HotPixelSnapAction = (function (MonotoneChainSelectAction$$1) {
  13713. function HotPixelSnapAction () {
  13714. MonotoneChainSelectAction$$1.call(this);
  13715. this._hotPixel = null;
  13716. this._parentEdge = null;
  13717. this._hotPixelVertexIndex = null;
  13718. this._isNodeAdded = false;
  13719. var hotPixel = arguments[0];
  13720. var parentEdge = arguments[1];
  13721. var hotPixelVertexIndex = arguments[2];
  13722. this._hotPixel = hotPixel;
  13723. this._parentEdge = parentEdge;
  13724. this._hotPixelVertexIndex = hotPixelVertexIndex;
  13725. }
  13726. if ( MonotoneChainSelectAction$$1 ) HotPixelSnapAction.__proto__ = MonotoneChainSelectAction$$1;
  13727. HotPixelSnapAction.prototype = Object.create( MonotoneChainSelectAction$$1 && MonotoneChainSelectAction$$1.prototype );
  13728. HotPixelSnapAction.prototype.constructor = HotPixelSnapAction;
  13729. HotPixelSnapAction.prototype.isNodeAdded = function isNodeAdded () {
  13730. return this._isNodeAdded
  13731. };
  13732. HotPixelSnapAction.prototype.select = function select () {
  13733. if (arguments.length === 2) {
  13734. var mc = arguments[0];
  13735. var startIndex = arguments[1];
  13736. var ss = mc.getContext();
  13737. if (this._parentEdge !== null) {
  13738. if (ss === this._parentEdge && startIndex === this._hotPixelVertexIndex) { return null }
  13739. }
  13740. this._isNodeAdded = this._hotPixel.addSnappedNode(ss, startIndex);
  13741. } else { return MonotoneChainSelectAction$$1.prototype.select.apply(this, arguments) }
  13742. };
  13743. HotPixelSnapAction.prototype.interfaces_ = function interfaces_ () {
  13744. return []
  13745. };
  13746. HotPixelSnapAction.prototype.getClass = function getClass () {
  13747. return HotPixelSnapAction
  13748. };
  13749. return HotPixelSnapAction;
  13750. }(MonotoneChainSelectAction));
  13751. var InteriorIntersectionFinderAdder = function InteriorIntersectionFinderAdder () {
  13752. this._li = null;
  13753. this._interiorIntersections = null;
  13754. var li = arguments[0];
  13755. this._li = li;
  13756. this._interiorIntersections = new ArrayList();
  13757. };
  13758. InteriorIntersectionFinderAdder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {
  13759. var this$1 = this;
  13760. if (e0 === e1 && segIndex0 === segIndex1) { return null }
  13761. var p00 = e0.getCoordinates()[segIndex0];
  13762. var p01 = e0.getCoordinates()[segIndex0 + 1];
  13763. var p10 = e1.getCoordinates()[segIndex1];
  13764. var p11 = e1.getCoordinates()[segIndex1 + 1];
  13765. this._li.computeIntersection(p00, p01, p10, p11);
  13766. if (this._li.hasIntersection()) {
  13767. if (this._li.isInteriorIntersection()) {
  13768. for (var intIndex = 0; intIndex < this._li.getIntersectionNum(); intIndex++) {
  13769. this$1._interiorIntersections.add(this$1._li.getIntersection(intIndex));
  13770. }
  13771. e0.addIntersections(this._li, segIndex0, 0);
  13772. e1.addIntersections(this._li, segIndex1, 1);
  13773. }
  13774. }
  13775. };
  13776. InteriorIntersectionFinderAdder.prototype.isDone = function isDone () {
  13777. return false
  13778. };
  13779. InteriorIntersectionFinderAdder.prototype.getInteriorIntersections = function getInteriorIntersections () {
  13780. return this._interiorIntersections
  13781. };
  13782. InteriorIntersectionFinderAdder.prototype.interfaces_ = function interfaces_ () {
  13783. return [SegmentIntersector]
  13784. };
  13785. InteriorIntersectionFinderAdder.prototype.getClass = function getClass () {
  13786. return InteriorIntersectionFinderAdder
  13787. };
  13788. var MCIndexSnapRounder = function MCIndexSnapRounder () {
  13789. this._pm = null;
  13790. this._li = null;
  13791. this._scaleFactor = null;
  13792. this._noder = null;
  13793. this._pointSnapper = null;
  13794. this._nodedSegStrings = null;
  13795. var pm = arguments[0];
  13796. this._pm = pm;
  13797. this._li = new RobustLineIntersector();
  13798. this._li.setPrecisionModel(pm);
  13799. this._scaleFactor = pm.getScale();
  13800. };
  13801. MCIndexSnapRounder.prototype.checkCorrectness = function checkCorrectness (inputSegmentStrings) {
  13802. var resultSegStrings = NodedSegmentString.getNodedSubstrings(inputSegmentStrings);
  13803. var nv = new NodingValidator(resultSegStrings);
  13804. try {
  13805. nv.checkValid();
  13806. } catch (ex) {
  13807. if (ex instanceof Exception) {
  13808. ex.printStackTrace();
  13809. } else { throw ex }
  13810. } finally {}
  13811. };
  13812. MCIndexSnapRounder.prototype.getNodedSubstrings = function getNodedSubstrings () {
  13813. return NodedSegmentString.getNodedSubstrings(this._nodedSegStrings)
  13814. };
  13815. MCIndexSnapRounder.prototype.snapRound = function snapRound (segStrings, li) {
  13816. var intersections = this.findInteriorIntersections(segStrings, li);
  13817. this.computeIntersectionSnaps(intersections);
  13818. this.computeVertexSnaps(segStrings);
  13819. };
  13820. MCIndexSnapRounder.prototype.findInteriorIntersections = function findInteriorIntersections (segStrings, li) {
  13821. var intFinderAdder = new InteriorIntersectionFinderAdder(li);
  13822. this._noder.setSegmentIntersector(intFinderAdder);
  13823. this._noder.computeNodes(segStrings);
  13824. return intFinderAdder.getInteriorIntersections()
  13825. };
  13826. MCIndexSnapRounder.prototype.computeVertexSnaps = function computeVertexSnaps () {
  13827. var this$1 = this;
  13828. if (hasInterface(arguments[0], Collection)) {
  13829. var edges = arguments[0];
  13830. for (var i0 = edges.iterator(); i0.hasNext();) {
  13831. var edge0 = i0.next();
  13832. this$1.computeVertexSnaps(edge0);
  13833. }
  13834. } else if (arguments[0] instanceof NodedSegmentString) {
  13835. var e = arguments[0];
  13836. var pts0 = e.getCoordinates();
  13837. for (var i = 0; i < pts0.length; i++) {
  13838. var hotPixel = new HotPixel(pts0[i], this$1._scaleFactor, this$1._li);
  13839. var isNodeAdded = this$1._pointSnapper.snap(hotPixel, e, i);
  13840. if (isNodeAdded) {
  13841. e.addIntersection(pts0[i], i);
  13842. }
  13843. }
  13844. }
  13845. };
  13846. MCIndexSnapRounder.prototype.computeNodes = function computeNodes (inputSegmentStrings) {
  13847. this._nodedSegStrings = inputSegmentStrings;
  13848. this._noder = new MCIndexNoder();
  13849. this._pointSnapper = new MCIndexPointSnapper(this._noder.getIndex());
  13850. this.snapRound(inputSegmentStrings, this._li);
  13851. };
  13852. MCIndexSnapRounder.prototype.computeIntersectionSnaps = function computeIntersectionSnaps (snapPts) {
  13853. var this$1 = this;
  13854. for (var it = snapPts.iterator(); it.hasNext();) {
  13855. var snapPt = it.next();
  13856. var hotPixel = new HotPixel(snapPt, this$1._scaleFactor, this$1._li);
  13857. this$1._pointSnapper.snap(hotPixel);
  13858. }
  13859. };
  13860. MCIndexSnapRounder.prototype.interfaces_ = function interfaces_ () {
  13861. return [Noder]
  13862. };
  13863. MCIndexSnapRounder.prototype.getClass = function getClass () {
  13864. return MCIndexSnapRounder
  13865. };
  13866. var BufferOp = function BufferOp () {
  13867. this._argGeom = null;
  13868. this._distance = null;
  13869. this._bufParams = new BufferParameters();
  13870. this._resultGeometry = null;
  13871. this._saveException = null;
  13872. if (arguments.length === 1) {
  13873. var g = arguments[0];
  13874. this._argGeom = g;
  13875. } else if (arguments.length === 2) {
  13876. var g$1 = arguments[0];
  13877. var bufParams = arguments[1];
  13878. this._argGeom = g$1;
  13879. this._bufParams = bufParams;
  13880. }
  13881. };
  13882. var staticAccessors$32 = { CAP_ROUND: { configurable: true },CAP_BUTT: { configurable: true },CAP_FLAT: { configurable: true },CAP_SQUARE: { configurable: true },MAX_PRECISION_DIGITS: { configurable: true } };
  13883. BufferOp.prototype.bufferFixedPrecision = function bufferFixedPrecision (fixedPM) {
  13884. var noder = new ScaledNoder(new MCIndexSnapRounder(new PrecisionModel(1.0)), fixedPM.getScale());
  13885. var bufBuilder = new BufferBuilder(this._bufParams);
  13886. bufBuilder.setWorkingPrecisionModel(fixedPM);
  13887. bufBuilder.setNoder(noder);
  13888. this._resultGeometry = bufBuilder.buffer(this._argGeom, this._distance);
  13889. };
  13890. BufferOp.prototype.bufferReducedPrecision = function bufferReducedPrecision () {
  13891. var this$1 = this;
  13892. if (arguments.length === 0) {
  13893. for (var precDigits = BufferOp.MAX_PRECISION_DIGITS; precDigits >= 0; precDigits--) {
  13894. try {
  13895. this$1.bufferReducedPrecision(precDigits);
  13896. } catch (ex) {
  13897. if (ex instanceof TopologyException) {
  13898. this$1._saveException = ex;
  13899. } else { throw ex }
  13900. } finally {}
  13901. if (this$1._resultGeometry !== null) { return null }
  13902. }
  13903. throw this._saveException
  13904. } else if (arguments.length === 1) {
  13905. var precisionDigits = arguments[0];
  13906. var sizeBasedScaleFactor = BufferOp.precisionScaleFactor(this._argGeom, this._distance, precisionDigits);
  13907. var fixedPM = new PrecisionModel(sizeBasedScaleFactor);
  13908. this.bufferFixedPrecision(fixedPM);
  13909. }
  13910. };
  13911. BufferOp.prototype.computeGeometry = function computeGeometry () {
  13912. this.bufferOriginalPrecision();
  13913. if (this._resultGeometry !== null) { return null }
  13914. var argPM = this._argGeom.getFactory().getPrecisionModel();
  13915. if (argPM.getType() === PrecisionModel.FIXED) { this.bufferFixedPrecision(argPM); } else { this.bufferReducedPrecision(); }
  13916. };
  13917. BufferOp.prototype.setQuadrantSegments = function setQuadrantSegments (quadrantSegments) {
  13918. this._bufParams.setQuadrantSegments(quadrantSegments);
  13919. };
  13920. BufferOp.prototype.bufferOriginalPrecision = function bufferOriginalPrecision () {
  13921. try {
  13922. var bufBuilder = new BufferBuilder(this._bufParams);
  13923. this._resultGeometry = bufBuilder.buffer(this._argGeom, this._distance);
  13924. } catch (ex) {
  13925. if (ex instanceof RuntimeException) {
  13926. this._saveException = ex;
  13927. } else { throw ex }
  13928. } finally {}
  13929. };
  13930. BufferOp.prototype.getResultGeometry = function getResultGeometry (distance) {
  13931. this._distance = distance;
  13932. this.computeGeometry();
  13933. return this._resultGeometry
  13934. };
  13935. BufferOp.prototype.setEndCapStyle = function setEndCapStyle (endCapStyle) {
  13936. this._bufParams.setEndCapStyle(endCapStyle);
  13937. };
  13938. BufferOp.prototype.interfaces_ = function interfaces_ () {
  13939. return []
  13940. };
  13941. BufferOp.prototype.getClass = function getClass () {
  13942. return BufferOp
  13943. };
  13944. BufferOp.bufferOp = function bufferOp () {
  13945. if (arguments.length === 2) {
  13946. var g = arguments[0];
  13947. var distance = arguments[1];
  13948. var gBuf = new BufferOp(g);
  13949. var geomBuf = gBuf.getResultGeometry(distance);
  13950. return geomBuf
  13951. } else if (arguments.length === 3) {
  13952. if (Number.isInteger(arguments[2]) && (arguments[0] instanceof Geometry && typeof arguments[1] === 'number')) {
  13953. var g$1 = arguments[0];
  13954. var distance$1 = arguments[1];
  13955. var quadrantSegments = arguments[2];
  13956. var bufOp = new BufferOp(g$1);
  13957. bufOp.setQuadrantSegments(quadrantSegments);
  13958. var geomBuf$1 = bufOp.getResultGeometry(distance$1);
  13959. return geomBuf$1
  13960. } else if (arguments[2] instanceof BufferParameters && (arguments[0] instanceof Geometry && typeof arguments[1] === 'number')) {
  13961. var g$2 = arguments[0];
  13962. var distance$2 = arguments[1];
  13963. var params = arguments[2];
  13964. var bufOp$1 = new BufferOp(g$2, params);
  13965. var geomBuf$2 = bufOp$1.getResultGeometry(distance$2);
  13966. return geomBuf$2
  13967. }
  13968. } else if (arguments.length === 4) {
  13969. var g$3 = arguments[0];
  13970. var distance$3 = arguments[1];
  13971. var quadrantSegments$1 = arguments[2];
  13972. var endCapStyle = arguments[3];
  13973. var bufOp$2 = new BufferOp(g$3);
  13974. bufOp$2.setQuadrantSegments(quadrantSegments$1);
  13975. bufOp$2.setEndCapStyle(endCapStyle);
  13976. var geomBuf$3 = bufOp$2.getResultGeometry(distance$3);
  13977. return geomBuf$3
  13978. }
  13979. };
  13980. BufferOp.precisionScaleFactor = function precisionScaleFactor (g, distance, maxPrecisionDigits) {
  13981. var env = g.getEnvelopeInternal();
  13982. var envMax = MathUtil.max(Math.abs(env.getMaxX()), Math.abs(env.getMaxY()), Math.abs(env.getMinX()), Math.abs(env.getMinY()));
  13983. var expandByDistance = distance > 0.0 ? distance : 0.0;
  13984. var bufEnvMax = envMax + 2 * expandByDistance;
  13985. var bufEnvPrecisionDigits = Math.trunc(Math.log(bufEnvMax) / Math.log(10) + 1.0);
  13986. var minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;
  13987. var scaleFactor = Math.pow(10.0, minUnitLog10);
  13988. return scaleFactor
  13989. };
  13990. staticAccessors$32.CAP_ROUND.get = function () { return BufferParameters.CAP_ROUND };
  13991. staticAccessors$32.CAP_BUTT.get = function () { return BufferParameters.CAP_FLAT };
  13992. staticAccessors$32.CAP_FLAT.get = function () { return BufferParameters.CAP_FLAT };
  13993. staticAccessors$32.CAP_SQUARE.get = function () { return BufferParameters.CAP_SQUARE };
  13994. staticAccessors$32.MAX_PRECISION_DIGITS.get = function () { return 12 };
  13995. Object.defineProperties( BufferOp, staticAccessors$32 );
  13996. var PointPairDistance = function PointPairDistance () {
  13997. this._pt = [new Coordinate(), new Coordinate()];
  13998. this._distance = Double.NaN;
  13999. this._isNull = true;
  14000. };
  14001. PointPairDistance.prototype.getCoordinates = function getCoordinates () {
  14002. return this._pt
  14003. };
  14004. PointPairDistance.prototype.getCoordinate = function getCoordinate (i) {
  14005. return this._pt[i]
  14006. };
  14007. PointPairDistance.prototype.setMinimum = function setMinimum () {
  14008. if (arguments.length === 1) {
  14009. var ptDist = arguments[0];
  14010. this.setMinimum(ptDist._pt[0], ptDist._pt[1]);
  14011. } else if (arguments.length === 2) {
  14012. var p0 = arguments[0];
  14013. var p1 = arguments[1];
  14014. if (this._isNull) {
  14015. this.initialize(p0, p1);
  14016. return null
  14017. }
  14018. var dist = p0.distance(p1);
  14019. if (dist < this._distance) { this.initialize(p0, p1, dist); }
  14020. }
  14021. };
  14022. PointPairDistance.prototype.initialize = function initialize () {
  14023. if (arguments.length === 0) {
  14024. this._isNull = true;
  14025. } else if (arguments.length === 2) {
  14026. var p0 = arguments[0];
  14027. var p1 = arguments[1];
  14028. this._pt[0].setCoordinate(p0);
  14029. this._pt[1].setCoordinate(p1);
  14030. this._distance = p0.distance(p1);
  14031. this._isNull = false;
  14032. } else if (arguments.length === 3) {
  14033. var p0$1 = arguments[0];
  14034. var p1$1 = arguments[1];
  14035. var distance = arguments[2];
  14036. this._pt[0].setCoordinate(p0$1);
  14037. this._pt[1].setCoordinate(p1$1);
  14038. this._distance = distance;
  14039. this._isNull = false;
  14040. }
  14041. };
  14042. PointPairDistance.prototype.getDistance = function getDistance () {
  14043. return this._distance
  14044. };
  14045. PointPairDistance.prototype.setMaximum = function setMaximum () {
  14046. if (arguments.length === 1) {
  14047. var ptDist = arguments[0];
  14048. this.setMaximum(ptDist._pt[0], ptDist._pt[1]);
  14049. } else if (arguments.length === 2) {
  14050. var p0 = arguments[0];
  14051. var p1 = arguments[1];
  14052. if (this._isNull) {
  14053. this.initialize(p0, p1);
  14054. return null
  14055. }
  14056. var dist = p0.distance(p1);
  14057. if (dist > this._distance) { this.initialize(p0, p1, dist); }
  14058. }
  14059. };
  14060. PointPairDistance.prototype.interfaces_ = function interfaces_ () {
  14061. return []
  14062. };
  14063. PointPairDistance.prototype.getClass = function getClass () {
  14064. return PointPairDistance
  14065. };
  14066. var DistanceToPointFinder = function DistanceToPointFinder () {};
  14067. DistanceToPointFinder.prototype.interfaces_ = function interfaces_ () {
  14068. return []
  14069. };
  14070. DistanceToPointFinder.prototype.getClass = function getClass () {
  14071. return DistanceToPointFinder
  14072. };
  14073. DistanceToPointFinder.computeDistance = function computeDistance () {
  14074. if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof LineString && arguments[1] instanceof Coordinate)) {
  14075. var line = arguments[0];
  14076. var pt = arguments[1];
  14077. var ptDist = arguments[2];
  14078. var coords = line.getCoordinates();
  14079. var tempSegment = new LineSegment();
  14080. for (var i = 0; i < coords.length - 1; i++) {
  14081. tempSegment.setCoordinates(coords[i], coords[i + 1]);
  14082. var closestPt = tempSegment.closestPoint(pt);
  14083. ptDist.setMinimum(closestPt, pt);
  14084. }
  14085. } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof Polygon && arguments[1] instanceof Coordinate)) {
  14086. var poly = arguments[0];
  14087. var pt$1 = arguments[1];
  14088. var ptDist$1 = arguments[2];
  14089. DistanceToPointFinder.computeDistance(poly.getExteriorRing(), pt$1, ptDist$1);
  14090. for (var i$1 = 0; i$1 < poly.getNumInteriorRing(); i$1++) {
  14091. DistanceToPointFinder.computeDistance(poly.getInteriorRingN(i$1), pt$1, ptDist$1);
  14092. }
  14093. } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof Geometry && arguments[1] instanceof Coordinate)) {
  14094. var geom = arguments[0];
  14095. var pt$2 = arguments[1];
  14096. var ptDist$2 = arguments[2];
  14097. if (geom instanceof LineString) {
  14098. DistanceToPointFinder.computeDistance(geom, pt$2, ptDist$2);
  14099. } else if (geom instanceof Polygon) {
  14100. DistanceToPointFinder.computeDistance(geom, pt$2, ptDist$2);
  14101. } else if (geom instanceof GeometryCollection) {
  14102. var gc = geom;
  14103. for (var i$2 = 0; i$2 < gc.getNumGeometries(); i$2++) {
  14104. var g = gc.getGeometryN(i$2);
  14105. DistanceToPointFinder.computeDistance(g, pt$2, ptDist$2);
  14106. }
  14107. } else {
  14108. ptDist$2.setMinimum(geom.getCoordinate(), pt$2);
  14109. }
  14110. } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof LineSegment && arguments[1] instanceof Coordinate)) {
  14111. var segment = arguments[0];
  14112. var pt$3 = arguments[1];
  14113. var ptDist$3 = arguments[2];
  14114. var closestPt$1 = segment.closestPoint(pt$3);
  14115. ptDist$3.setMinimum(closestPt$1, pt$3);
  14116. }
  14117. };
  14118. var BufferCurveMaximumDistanceFinder = function BufferCurveMaximumDistanceFinder (inputGeom) {
  14119. this._maxPtDist = new PointPairDistance();
  14120. this._inputGeom = inputGeom || null;
  14121. };
  14122. var staticAccessors$36 = { MaxPointDistanceFilter: { configurable: true },MaxMidpointDistanceFilter: { configurable: true } };
  14123. BufferCurveMaximumDistanceFinder.prototype.computeMaxMidpointDistance = function computeMaxMidpointDistance (curve) {
  14124. var distFilter = new MaxMidpointDistanceFilter(this._inputGeom);
  14125. curve.apply(distFilter);
  14126. this._maxPtDist.setMaximum(distFilter.getMaxPointDistance());
  14127. };
  14128. BufferCurveMaximumDistanceFinder.prototype.computeMaxVertexDistance = function computeMaxVertexDistance (curve) {
  14129. var distFilter = new MaxPointDistanceFilter(this._inputGeom);
  14130. curve.apply(distFilter);
  14131. this._maxPtDist.setMaximum(distFilter.getMaxPointDistance());
  14132. };
  14133. BufferCurveMaximumDistanceFinder.prototype.findDistance = function findDistance (bufferCurve) {
  14134. this.computeMaxVertexDistance(bufferCurve);
  14135. this.computeMaxMidpointDistance(bufferCurve);
  14136. return this._maxPtDist.getDistance()
  14137. };
  14138. BufferCurveMaximumDistanceFinder.prototype.getDistancePoints = function getDistancePoints () {
  14139. return this._maxPtDist
  14140. };
  14141. BufferCurveMaximumDistanceFinder.prototype.interfaces_ = function interfaces_ () {
  14142. return []
  14143. };
  14144. BufferCurveMaximumDistanceFinder.prototype.getClass = function getClass () {
  14145. return BufferCurveMaximumDistanceFinder
  14146. };
  14147. staticAccessors$36.MaxPointDistanceFilter.get = function () { return MaxPointDistanceFilter };
  14148. staticAccessors$36.MaxMidpointDistanceFilter.get = function () { return MaxMidpointDistanceFilter };
  14149. Object.defineProperties( BufferCurveMaximumDistanceFinder, staticAccessors$36 );
  14150. var MaxPointDistanceFilter = function MaxPointDistanceFilter (geom) {
  14151. this._maxPtDist = new PointPairDistance();
  14152. this._minPtDist = new PointPairDistance();
  14153. this._geom = geom || null;
  14154. };
  14155. MaxPointDistanceFilter.prototype.filter = function filter (pt) {
  14156. this._minPtDist.initialize();
  14157. DistanceToPointFinder.computeDistance(this._geom, pt, this._minPtDist);
  14158. this._maxPtDist.setMaximum(this._minPtDist);
  14159. };
  14160. MaxPointDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {
  14161. return this._maxPtDist
  14162. };
  14163. MaxPointDistanceFilter.prototype.interfaces_ = function interfaces_ () {
  14164. return [CoordinateFilter]
  14165. };
  14166. MaxPointDistanceFilter.prototype.getClass = function getClass () {
  14167. return MaxPointDistanceFilter
  14168. };
  14169. var MaxMidpointDistanceFilter = function MaxMidpointDistanceFilter (geom) {
  14170. this._maxPtDist = new PointPairDistance();
  14171. this._minPtDist = new PointPairDistance();
  14172. this._geom = geom || null;
  14173. };
  14174. MaxMidpointDistanceFilter.prototype.filter = function filter (seq, index) {
  14175. if (index === 0) { return null }
  14176. var p0 = seq.getCoordinate(index - 1);
  14177. var p1 = seq.getCoordinate(index);
  14178. var midPt = new Coordinate((p0.x + p1.x) / 2, (p0.y + p1.y) / 2);
  14179. this._minPtDist.initialize();
  14180. DistanceToPointFinder.computeDistance(this._geom, midPt, this._minPtDist);
  14181. this._maxPtDist.setMaximum(this._minPtDist);
  14182. };
  14183. MaxMidpointDistanceFilter.prototype.isDone = function isDone () {
  14184. return false
  14185. };
  14186. MaxMidpointDistanceFilter.prototype.isGeometryChanged = function isGeometryChanged () {
  14187. return false
  14188. };
  14189. MaxMidpointDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {
  14190. return this._maxPtDist
  14191. };
  14192. MaxMidpointDistanceFilter.prototype.interfaces_ = function interfaces_ () {
  14193. return [CoordinateSequenceFilter]
  14194. };
  14195. MaxMidpointDistanceFilter.prototype.getClass = function getClass () {
  14196. return MaxMidpointDistanceFilter
  14197. };
  14198. var PolygonExtracter = function PolygonExtracter (comps) {
  14199. this._comps = comps || null;
  14200. };
  14201. PolygonExtracter.prototype.filter = function filter (geom) {
  14202. if (geom instanceof Polygon) { this._comps.add(geom); }
  14203. };
  14204. PolygonExtracter.prototype.interfaces_ = function interfaces_ () {
  14205. return [GeometryFilter]
  14206. };
  14207. PolygonExtracter.prototype.getClass = function getClass () {
  14208. return PolygonExtracter
  14209. };
  14210. PolygonExtracter.getPolygons = function getPolygons () {
  14211. if (arguments.length === 1) {
  14212. var geom = arguments[0];
  14213. return PolygonExtracter.getPolygons(geom, new ArrayList())
  14214. } else if (arguments.length === 2) {
  14215. var geom$1 = arguments[0];
  14216. var list = arguments[1];
  14217. if (geom$1 instanceof Polygon) {
  14218. list.add(geom$1);
  14219. } else if (geom$1 instanceof GeometryCollection) {
  14220. geom$1.apply(new PolygonExtracter(list));
  14221. }
  14222. return list
  14223. }
  14224. };
  14225. var LinearComponentExtracter = function LinearComponentExtracter () {
  14226. this._lines = null;
  14227. this._isForcedToLineString = false;
  14228. if (arguments.length === 1) {
  14229. var lines = arguments[0];
  14230. this._lines = lines;
  14231. } else if (arguments.length === 2) {
  14232. var lines$1 = arguments[0];
  14233. var isForcedToLineString = arguments[1];
  14234. this._lines = lines$1;
  14235. this._isForcedToLineString = isForcedToLineString;
  14236. }
  14237. };
  14238. LinearComponentExtracter.prototype.filter = function filter (geom) {
  14239. if (this._isForcedToLineString && geom instanceof LinearRing) {
  14240. var line = geom.getFactory().createLineString(geom.getCoordinateSequence());
  14241. this._lines.add(line);
  14242. return null
  14243. }
  14244. if (geom instanceof LineString) { this._lines.add(geom); }
  14245. };
  14246. LinearComponentExtracter.prototype.setForceToLineString = function setForceToLineString (isForcedToLineString) {
  14247. this._isForcedToLineString = isForcedToLineString;
  14248. };
  14249. LinearComponentExtracter.prototype.interfaces_ = function interfaces_ () {
  14250. return [GeometryComponentFilter]
  14251. };
  14252. LinearComponentExtracter.prototype.getClass = function getClass () {
  14253. return LinearComponentExtracter
  14254. };
  14255. LinearComponentExtracter.getGeometry = function getGeometry () {
  14256. if (arguments.length === 1) {
  14257. var geom = arguments[0];
  14258. return geom.getFactory().buildGeometry(LinearComponentExtracter.getLines(geom))
  14259. } else if (arguments.length === 2) {
  14260. var geom$1 = arguments[0];
  14261. var forceToLineString = arguments[1];
  14262. return geom$1.getFactory().buildGeometry(LinearComponentExtracter.getLines(geom$1, forceToLineString))
  14263. }
  14264. };
  14265. LinearComponentExtracter.getLines = function getLines () {
  14266. if (arguments.length === 1) {
  14267. var geom = arguments[0];
  14268. return LinearComponentExtracter.getLines(geom, false)
  14269. } else if (arguments.length === 2) {
  14270. if (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], Collection)) {
  14271. var geoms = arguments[0];
  14272. var lines$1 = arguments[1];
  14273. for (var i = geoms.iterator(); i.hasNext();) {
  14274. var g = i.next();
  14275. LinearComponentExtracter.getLines(g, lines$1);
  14276. }
  14277. return lines$1
  14278. } else if (arguments[0] instanceof Geometry && typeof arguments[1] === 'boolean') {
  14279. var geom$1 = arguments[0];
  14280. var forceToLineString = arguments[1];
  14281. var lines = new ArrayList();
  14282. geom$1.apply(new LinearComponentExtracter(lines, forceToLineString));
  14283. return lines
  14284. } else if (arguments[0] instanceof Geometry && hasInterface(arguments[1], Collection)) {
  14285. var geom$2 = arguments[0];
  14286. var lines$2 = arguments[1];
  14287. if (geom$2 instanceof LineString) {
  14288. lines$2.add(geom$2);
  14289. } else {
  14290. geom$2.apply(new LinearComponentExtracter(lines$2));
  14291. }
  14292. return lines$2
  14293. }
  14294. } else if (arguments.length === 3) {
  14295. if (typeof arguments[2] === 'boolean' && (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], Collection))) {
  14296. var geoms$1 = arguments[0];
  14297. var lines$3 = arguments[1];
  14298. var forceToLineString$1 = arguments[2];
  14299. for (var i$1 = geoms$1.iterator(); i$1.hasNext();) {
  14300. var g$1 = i$1.next();
  14301. LinearComponentExtracter.getLines(g$1, lines$3, forceToLineString$1);
  14302. }
  14303. return lines$3
  14304. } else if (typeof arguments[2] === 'boolean' && (arguments[0] instanceof Geometry && hasInterface(arguments[1], Collection))) {
  14305. var geom$3 = arguments[0];
  14306. var lines$4 = arguments[1];
  14307. var forceToLineString$2 = arguments[2];
  14308. geom$3.apply(new LinearComponentExtracter(lines$4, forceToLineString$2));
  14309. return lines$4
  14310. }
  14311. }
  14312. };
  14313. var PointLocator = function PointLocator () {
  14314. this._boundaryRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
  14315. this._isIn = null;
  14316. this._numBoundaries = null;
  14317. if (arguments.length === 0) {} else if (arguments.length === 1) {
  14318. var boundaryRule = arguments[0];
  14319. if (boundaryRule === null) { throw new IllegalArgumentException('Rule must be non-null') }
  14320. this._boundaryRule = boundaryRule;
  14321. }
  14322. };
  14323. PointLocator.prototype.locateInternal = function locateInternal () {
  14324. var this$1 = this;
  14325. if (arguments[0] instanceof Coordinate && arguments[1] instanceof Polygon) {
  14326. var p = arguments[0];
  14327. var poly = arguments[1];
  14328. if (poly.isEmpty()) { return Location.EXTERIOR }
  14329. var shell = poly.getExteriorRing();
  14330. var shellLoc = this.locateInPolygonRing(p, shell);
  14331. if (shellLoc === Location.EXTERIOR) { return Location.EXTERIOR }
  14332. if (shellLoc === Location.BOUNDARY) { return Location.BOUNDARY }
  14333. for (var i = 0; i < poly.getNumInteriorRing(); i++) {
  14334. var hole = poly.getInteriorRingN(i);
  14335. var holeLoc = this$1.locateInPolygonRing(p, hole);
  14336. if (holeLoc === Location.INTERIOR) { return Location.EXTERIOR }
  14337. if (holeLoc === Location.BOUNDARY) { return Location.BOUNDARY }
  14338. }
  14339. return Location.INTERIOR
  14340. } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof LineString) {
  14341. var p$1 = arguments[0];
  14342. var l = arguments[1];
  14343. if (!l.getEnvelopeInternal().intersects(p$1)) { return Location.EXTERIOR }
  14344. var pt = l.getCoordinates();
  14345. if (!l.isClosed()) {
  14346. if (p$1.equals(pt[0]) || p$1.equals(pt[pt.length - 1])) {
  14347. return Location.BOUNDARY
  14348. }
  14349. }
  14350. if (CGAlgorithms.isOnLine(p$1, pt)) { return Location.INTERIOR }
  14351. return Location.EXTERIOR
  14352. } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Point) {
  14353. var p$2 = arguments[0];
  14354. var pt$1 = arguments[1];
  14355. var ptCoord = pt$1.getCoordinate();
  14356. if (ptCoord.equals2D(p$2)) { return Location.INTERIOR }
  14357. return Location.EXTERIOR
  14358. }
  14359. };
  14360. PointLocator.prototype.locateInPolygonRing = function locateInPolygonRing (p, ring) {
  14361. if (!ring.getEnvelopeInternal().intersects(p)) { return Location.EXTERIOR }
  14362. return CGAlgorithms.locatePointInRing(p, ring.getCoordinates())
  14363. };
  14364. PointLocator.prototype.intersects = function intersects (p, geom) {
  14365. return this.locate(p, geom) !== Location.EXTERIOR
  14366. };
  14367. PointLocator.prototype.updateLocationInfo = function updateLocationInfo (loc) {
  14368. if (loc === Location.INTERIOR) { this._isIn = true; }
  14369. if (loc === Location.BOUNDARY) { this._numBoundaries++; }
  14370. };
  14371. PointLocator.prototype.computeLocation = function computeLocation (p, geom) {
  14372. var this$1 = this;
  14373. if (geom instanceof Point) {
  14374. this.updateLocationInfo(this.locateInternal(p, geom));
  14375. }
  14376. if (geom instanceof LineString) {
  14377. this.updateLocationInfo(this.locateInternal(p, geom));
  14378. } else if (geom instanceof Polygon) {
  14379. this.updateLocationInfo(this.locateInternal(p, geom));
  14380. } else if (geom instanceof MultiLineString) {
  14381. var ml = geom;
  14382. for (var i = 0; i < ml.getNumGeometries(); i++) {
  14383. var l = ml.getGeometryN(i);
  14384. this$1.updateLocationInfo(this$1.locateInternal(p, l));
  14385. }
  14386. } else if (geom instanceof MultiPolygon) {
  14387. var mpoly = geom;
  14388. for (var i$1 = 0; i$1 < mpoly.getNumGeometries(); i$1++) {
  14389. var poly = mpoly.getGeometryN(i$1);
  14390. this$1.updateLocationInfo(this$1.locateInternal(p, poly));
  14391. }
  14392. } else if (geom instanceof GeometryCollection) {
  14393. var geomi = new GeometryCollectionIterator(geom);
  14394. while (geomi.hasNext()) {
  14395. var g2 = geomi.next();
  14396. if (g2 !== geom) { this$1.computeLocation(p, g2); }
  14397. }
  14398. }
  14399. };
  14400. PointLocator.prototype.locate = function locate (p, geom) {
  14401. if (geom.isEmpty()) { return Location.EXTERIOR }
  14402. if (geom instanceof LineString) {
  14403. return this.locateInternal(p, geom)
  14404. } else if (geom instanceof Polygon) {
  14405. return this.locateInternal(p, geom)
  14406. }
  14407. this._isIn = false;
  14408. this._numBoundaries = 0;
  14409. this.computeLocation(p, geom);
  14410. if (this._boundaryRule.isInBoundary(this._numBoundaries)) { return Location.BOUNDARY }
  14411. if (this._numBoundaries > 0 || this._isIn) { return Location.INTERIOR }
  14412. return Location.EXTERIOR
  14413. };
  14414. PointLocator.prototype.interfaces_ = function interfaces_ () {
  14415. return []
  14416. };
  14417. PointLocator.prototype.getClass = function getClass () {
  14418. return PointLocator
  14419. };
  14420. var GeometryLocation = function GeometryLocation () {
  14421. this._component = null;
  14422. this._segIndex = null;
  14423. this._pt = null;
  14424. if (arguments.length === 2) {
  14425. var component = arguments[0];
  14426. var pt = arguments[1];
  14427. GeometryLocation.call(this, component, GeometryLocation.INSIDE_AREA, pt);
  14428. } else if (arguments.length === 3) {
  14429. var component$1 = arguments[0];
  14430. var segIndex = arguments[1];
  14431. var pt$1 = arguments[2];
  14432. this._component = component$1;
  14433. this._segIndex = segIndex;
  14434. this._pt = pt$1;
  14435. }
  14436. };
  14437. var staticAccessors$38 = { INSIDE_AREA: { configurable: true } };
  14438. GeometryLocation.prototype.isInsideArea = function isInsideArea () {
  14439. return this._segIndex === GeometryLocation.INSIDE_AREA
  14440. };
  14441. GeometryLocation.prototype.getCoordinate = function getCoordinate () {
  14442. return this._pt
  14443. };
  14444. GeometryLocation.prototype.getGeometryComponent = function getGeometryComponent () {
  14445. return this._component
  14446. };
  14447. GeometryLocation.prototype.getSegmentIndex = function getSegmentIndex () {
  14448. return this._segIndex
  14449. };
  14450. GeometryLocation.prototype.interfaces_ = function interfaces_ () {
  14451. return []
  14452. };
  14453. GeometryLocation.prototype.getClass = function getClass () {
  14454. return GeometryLocation
  14455. };
  14456. staticAccessors$38.INSIDE_AREA.get = function () { return -1 };
  14457. Object.defineProperties( GeometryLocation, staticAccessors$38 );
  14458. var PointExtracter = function PointExtracter (pts) {
  14459. this._pts = pts || null;
  14460. };
  14461. PointExtracter.prototype.filter = function filter (geom) {
  14462. if (geom instanceof Point) { this._pts.add(geom); }
  14463. };
  14464. PointExtracter.prototype.interfaces_ = function interfaces_ () {
  14465. return [GeometryFilter]
  14466. };
  14467. PointExtracter.prototype.getClass = function getClass () {
  14468. return PointExtracter
  14469. };
  14470. PointExtracter.getPoints = function getPoints () {
  14471. if (arguments.length === 1) {
  14472. var geom = arguments[0];
  14473. if (geom instanceof Point) {
  14474. return Collections.singletonList(geom)
  14475. }
  14476. return PointExtracter.getPoints(geom, new ArrayList())
  14477. } else if (arguments.length === 2) {
  14478. var geom$1 = arguments[0];
  14479. var list = arguments[1];
  14480. if (geom$1 instanceof Point) {
  14481. list.add(geom$1);
  14482. } else if (geom$1 instanceof GeometryCollection) {
  14483. geom$1.apply(new PointExtracter(list));
  14484. }
  14485. return list
  14486. }
  14487. };
  14488. var ConnectedElementLocationFilter = function ConnectedElementLocationFilter () {
  14489. this._locations = null;
  14490. var locations = arguments[0];
  14491. this._locations = locations;
  14492. };
  14493. ConnectedElementLocationFilter.prototype.filter = function filter (geom) {
  14494. if (geom instanceof Point || geom instanceof LineString || geom instanceof Polygon) { this._locations.add(new GeometryLocation(geom, 0, geom.getCoordinate())); }
  14495. };
  14496. ConnectedElementLocationFilter.prototype.interfaces_ = function interfaces_ () {
  14497. return [GeometryFilter]
  14498. };
  14499. ConnectedElementLocationFilter.prototype.getClass = function getClass () {
  14500. return ConnectedElementLocationFilter
  14501. };
  14502. ConnectedElementLocationFilter.getLocations = function getLocations (geom) {
  14503. var locations = new ArrayList();
  14504. geom.apply(new ConnectedElementLocationFilter(locations));
  14505. return locations
  14506. };
  14507. var DistanceOp = function DistanceOp () {
  14508. this._geom = null;
  14509. this._terminateDistance = 0.0;
  14510. this._ptLocator = new PointLocator();
  14511. this._minDistanceLocation = null;
  14512. this._minDistance = Double.MAX_VALUE;
  14513. if (arguments.length === 2) {
  14514. var g0 = arguments[0];
  14515. var g1 = arguments[1];
  14516. this._geom = [g0, g1];
  14517. this._terminateDistance = 0.0;
  14518. } else if (arguments.length === 3) {
  14519. var g0$1 = arguments[0];
  14520. var g1$1 = arguments[1];
  14521. var terminateDistance = arguments[2];
  14522. this._geom = new Array(2).fill(null);
  14523. this._geom[0] = g0$1;
  14524. this._geom[1] = g1$1;
  14525. this._terminateDistance = terminateDistance;
  14526. }
  14527. };
  14528. DistanceOp.prototype.computeContainmentDistance = function computeContainmentDistance () {
  14529. var this$1 = this;
  14530. if (arguments.length === 0) {
  14531. var locPtPoly = new Array(2).fill(null);
  14532. this.computeContainmentDistance(0, locPtPoly);
  14533. if (this._minDistance <= this._terminateDistance) { return null }
  14534. this.computeContainmentDistance(1, locPtPoly);
  14535. } else if (arguments.length === 2) {
  14536. var polyGeomIndex = arguments[0];
  14537. var locPtPoly$1 = arguments[1];
  14538. var locationsIndex = 1 - polyGeomIndex;
  14539. var polys = PolygonExtracter.getPolygons(this._geom[polyGeomIndex]);
  14540. if (polys.size() > 0) {
  14541. var insideLocs = ConnectedElementLocationFilter.getLocations(this._geom[locationsIndex]);
  14542. this.computeContainmentDistance(insideLocs, polys, locPtPoly$1);
  14543. if (this._minDistance <= this._terminateDistance) {
  14544. this._minDistanceLocation[locationsIndex] = locPtPoly$1[0];
  14545. this._minDistanceLocation[polyGeomIndex] = locPtPoly$1[1];
  14546. return null
  14547. }
  14548. }
  14549. } else if (arguments.length === 3) {
  14550. if (arguments[2] instanceof Array && (hasInterface(arguments[0], List) && hasInterface(arguments[1], List))) {
  14551. var locs = arguments[0];
  14552. var polys$1 = arguments[1];
  14553. var locPtPoly$2 = arguments[2];
  14554. for (var i = 0; i < locs.size(); i++) {
  14555. var loc = locs.get(i);
  14556. for (var j = 0; j < polys$1.size(); j++) {
  14557. this$1.computeContainmentDistance(loc, polys$1.get(j), locPtPoly$2);
  14558. if (this$1._minDistance <= this$1._terminateDistance) { return null }
  14559. }
  14560. }
  14561. } else if (arguments[2] instanceof Array && (arguments[0] instanceof GeometryLocation && arguments[1] instanceof Polygon)) {
  14562. var ptLoc = arguments[0];
  14563. var poly = arguments[1];
  14564. var locPtPoly$3 = arguments[2];
  14565. var pt = ptLoc.getCoordinate();
  14566. if (Location.EXTERIOR !== this._ptLocator.locate(pt, poly)) {
  14567. this._minDistance = 0.0;
  14568. locPtPoly$3[0] = ptLoc;
  14569. locPtPoly$3[1] = new GeometryLocation(poly, pt);
  14570. return null
  14571. }
  14572. }
  14573. }
  14574. };
  14575. DistanceOp.prototype.computeMinDistanceLinesPoints = function computeMinDistanceLinesPoints (lines, points, locGeom) {
  14576. var this$1 = this;
  14577. for (var i = 0; i < lines.size(); i++) {
  14578. var line = lines.get(i);
  14579. for (var j = 0; j < points.size(); j++) {
  14580. var pt = points.get(j);
  14581. this$1.computeMinDistance(line, pt, locGeom);
  14582. if (this$1._minDistance <= this$1._terminateDistance) { return null }
  14583. }
  14584. }
  14585. };
  14586. DistanceOp.prototype.computeFacetDistance = function computeFacetDistance () {
  14587. var locGeom = new Array(2).fill(null);
  14588. var lines0 = LinearComponentExtracter.getLines(this._geom[0]);
  14589. var lines1 = LinearComponentExtracter.getLines(this._geom[1]);
  14590. var pts0 = PointExtracter.getPoints(this._geom[0]);
  14591. var pts1 = PointExtracter.getPoints(this._geom[1]);
  14592. this.computeMinDistanceLines(lines0, lines1, locGeom);
  14593. this.updateMinDistance(locGeom, false);
  14594. if (this._minDistance <= this._terminateDistance) { return null }
  14595. locGeom[0] = null;
  14596. locGeom[1] = null;
  14597. this.computeMinDistanceLinesPoints(lines0, pts1, locGeom);
  14598. this.updateMinDistance(locGeom, false);
  14599. if (this._minDistance <= this._terminateDistance) { return null }
  14600. locGeom[0] = null;
  14601. locGeom[1] = null;
  14602. this.computeMinDistanceLinesPoints(lines1, pts0, locGeom);
  14603. this.updateMinDistance(locGeom, true);
  14604. if (this._minDistance <= this._terminateDistance) { return null }
  14605. locGeom[0] = null;
  14606. locGeom[1] = null;
  14607. this.computeMinDistancePoints(pts0, pts1, locGeom);
  14608. this.updateMinDistance(locGeom, false);
  14609. };
  14610. DistanceOp.prototype.nearestLocations = function nearestLocations () {
  14611. this.computeMinDistance();
  14612. return this._minDistanceLocation
  14613. };
  14614. DistanceOp.prototype.updateMinDistance = function updateMinDistance (locGeom, flip) {
  14615. if (locGeom[0] === null) { return null }
  14616. if (flip) {
  14617. this._minDistanceLocation[0] = locGeom[1];
  14618. this._minDistanceLocation[1] = locGeom[0];
  14619. } else {
  14620. this._minDistanceLocation[0] = locGeom[0];
  14621. this._minDistanceLocation[1] = locGeom[1];
  14622. }
  14623. };
  14624. DistanceOp.prototype.nearestPoints = function nearestPoints () {
  14625. this.computeMinDistance();
  14626. var nearestPts = [this._minDistanceLocation[0].getCoordinate(), this._minDistanceLocation[1].getCoordinate()];
  14627. return nearestPts
  14628. };
  14629. DistanceOp.prototype.computeMinDistance = function computeMinDistance () {
  14630. var this$1 = this;
  14631. if (arguments.length === 0) {
  14632. if (this._minDistanceLocation !== null) { return null }
  14633. this._minDistanceLocation = new Array(2).fill(null);
  14634. this.computeContainmentDistance();
  14635. if (this._minDistance <= this._terminateDistance) { return null }
  14636. this.computeFacetDistance();
  14637. } else if (arguments.length === 3) {
  14638. if (arguments[2] instanceof Array && (arguments[0] instanceof LineString && arguments[1] instanceof Point)) {
  14639. var line = arguments[0];
  14640. var pt = arguments[1];
  14641. var locGeom = arguments[2];
  14642. if (line.getEnvelopeInternal().distance(pt.getEnvelopeInternal()) > this._minDistance) { return null }
  14643. var coord0 = line.getCoordinates();
  14644. var coord = pt.getCoordinate();
  14645. for (var i = 0; i < coord0.length - 1; i++) {
  14646. var dist = CGAlgorithms.distancePointLine(coord, coord0[i], coord0[i + 1]);
  14647. if (dist < this$1._minDistance) {
  14648. this$1._minDistance = dist;
  14649. var seg = new LineSegment(coord0[i], coord0[i + 1]);
  14650. var segClosestPoint = seg.closestPoint(coord);
  14651. locGeom[0] = new GeometryLocation(line, i, segClosestPoint);
  14652. locGeom[1] = new GeometryLocation(pt, 0, coord);
  14653. }
  14654. if (this$1._minDistance <= this$1._terminateDistance) { return null }
  14655. }
  14656. } else if (arguments[2] instanceof Array && (arguments[0] instanceof LineString && arguments[1] instanceof LineString)) {
  14657. var line0 = arguments[0];
  14658. var line1 = arguments[1];
  14659. var locGeom$1 = arguments[2];
  14660. if (line0.getEnvelopeInternal().distance(line1.getEnvelopeInternal()) > this._minDistance) { return null }
  14661. var coord0$1 = line0.getCoordinates();
  14662. var coord1 = line1.getCoordinates();
  14663. for (var i$1 = 0; i$1 < coord0$1.length - 1; i$1++) {
  14664. for (var j = 0; j < coord1.length - 1; j++) {
  14665. var dist$1 = CGAlgorithms.distanceLineLine(coord0$1[i$1], coord0$1[i$1 + 1], coord1[j], coord1[j + 1]);
  14666. if (dist$1 < this$1._minDistance) {
  14667. this$1._minDistance = dist$1;
  14668. var seg0 = new LineSegment(coord0$1[i$1], coord0$1[i$1 + 1]);
  14669. var seg1 = new LineSegment(coord1[j], coord1[j + 1]);
  14670. var closestPt = seg0.closestPoints(seg1);
  14671. locGeom$1[0] = new GeometryLocation(line0, i$1, closestPt[0]);
  14672. locGeom$1[1] = new GeometryLocation(line1, j, closestPt[1]);
  14673. }
  14674. if (this$1._minDistance <= this$1._terminateDistance) { return null }
  14675. }
  14676. }
  14677. }
  14678. }
  14679. };
  14680. DistanceOp.prototype.computeMinDistancePoints = function computeMinDistancePoints (points0, points1, locGeom) {
  14681. var this$1 = this;
  14682. for (var i = 0; i < points0.size(); i++) {
  14683. var pt0 = points0.get(i);
  14684. for (var j = 0; j < points1.size(); j++) {
  14685. var pt1 = points1.get(j);
  14686. var dist = pt0.getCoordinate().distance(pt1.getCoordinate());
  14687. if (dist < this$1._minDistance) {
  14688. this$1._minDistance = dist;
  14689. locGeom[0] = new GeometryLocation(pt0, 0, pt0.getCoordinate());
  14690. locGeom[1] = new GeometryLocation(pt1, 0, pt1.getCoordinate());
  14691. }
  14692. if (this$1._minDistance <= this$1._terminateDistance) { return null }
  14693. }
  14694. }
  14695. };
  14696. DistanceOp.prototype.distance = function distance () {
  14697. if (this._geom[0] === null || this._geom[1] === null) { throw new IllegalArgumentException('null geometries are not supported') }
  14698. if (this._geom[0].isEmpty() || this._geom[1].isEmpty()) { return 0.0 }
  14699. this.computeMinDistance();
  14700. return this._minDistance
  14701. };
  14702. DistanceOp.prototype.computeMinDistanceLines = function computeMinDistanceLines (lines0, lines1, locGeom) {
  14703. var this$1 = this;
  14704. for (var i = 0; i < lines0.size(); i++) {
  14705. var line0 = lines0.get(i);
  14706. for (var j = 0; j < lines1.size(); j++) {
  14707. var line1 = lines1.get(j);
  14708. this$1.computeMinDistance(line0, line1, locGeom);
  14709. if (this$1._minDistance <= this$1._terminateDistance) { return null }
  14710. }
  14711. }
  14712. };
  14713. DistanceOp.prototype.interfaces_ = function interfaces_ () {
  14714. return []
  14715. };
  14716. DistanceOp.prototype.getClass = function getClass () {
  14717. return DistanceOp
  14718. };
  14719. DistanceOp.distance = function distance (g0, g1) {
  14720. var distOp = new DistanceOp(g0, g1);
  14721. return distOp.distance()
  14722. };
  14723. DistanceOp.isWithinDistance = function isWithinDistance (g0, g1, distance) {
  14724. var distOp = new DistanceOp(g0, g1, distance);
  14725. return distOp.distance() <= distance
  14726. };
  14727. DistanceOp.nearestPoints = function nearestPoints (g0, g1) {
  14728. var distOp = new DistanceOp(g0, g1);
  14729. return distOp.nearestPoints()
  14730. };
  14731. var PointPairDistance$2 = function PointPairDistance () {
  14732. this._pt = [new Coordinate(), new Coordinate()];
  14733. this._distance = Double.NaN;
  14734. this._isNull = true;
  14735. };
  14736. PointPairDistance$2.prototype.getCoordinates = function getCoordinates () {
  14737. return this._pt
  14738. };
  14739. PointPairDistance$2.prototype.getCoordinate = function getCoordinate (i) {
  14740. return this._pt[i]
  14741. };
  14742. PointPairDistance$2.prototype.setMinimum = function setMinimum () {
  14743. if (arguments.length === 1) {
  14744. var ptDist = arguments[0];
  14745. this.setMinimum(ptDist._pt[0], ptDist._pt[1]);
  14746. } else if (arguments.length === 2) {
  14747. var p0 = arguments[0];
  14748. var p1 = arguments[1];
  14749. if (this._isNull) {
  14750. this.initialize(p0, p1);
  14751. return null
  14752. }
  14753. var dist = p0.distance(p1);
  14754. if (dist < this._distance) { this.initialize(p0, p1, dist); }
  14755. }
  14756. };
  14757. PointPairDistance$2.prototype.initialize = function initialize () {
  14758. if (arguments.length === 0) {
  14759. this._isNull = true;
  14760. } else if (arguments.length === 2) {
  14761. var p0 = arguments[0];
  14762. var p1 = arguments[1];
  14763. this._pt[0].setCoordinate(p0);
  14764. this._pt[1].setCoordinate(p1);
  14765. this._distance = p0.distance(p1);
  14766. this._isNull = false;
  14767. } else if (arguments.length === 3) {
  14768. var p0$1 = arguments[0];
  14769. var p1$1 = arguments[1];
  14770. var distance = arguments[2];
  14771. this._pt[0].setCoordinate(p0$1);
  14772. this._pt[1].setCoordinate(p1$1);
  14773. this._distance = distance;
  14774. this._isNull = false;
  14775. }
  14776. };
  14777. PointPairDistance$2.prototype.toString = function toString () {
  14778. return WKTWriter.toLineString(this._pt[0], this._pt[1])
  14779. };
  14780. PointPairDistance$2.prototype.getDistance = function getDistance () {
  14781. return this._distance
  14782. };
  14783. PointPairDistance$2.prototype.setMaximum = function setMaximum () {
  14784. if (arguments.length === 1) {
  14785. var ptDist = arguments[0];
  14786. this.setMaximum(ptDist._pt[0], ptDist._pt[1]);
  14787. } else if (arguments.length === 2) {
  14788. var p0 = arguments[0];
  14789. var p1 = arguments[1];
  14790. if (this._isNull) {
  14791. this.initialize(p0, p1);
  14792. return null
  14793. }
  14794. var dist = p0.distance(p1);
  14795. if (dist > this._distance) { this.initialize(p0, p1, dist); }
  14796. }
  14797. };
  14798. PointPairDistance$2.prototype.interfaces_ = function interfaces_ () {
  14799. return []
  14800. };
  14801. PointPairDistance$2.prototype.getClass = function getClass () {
  14802. return PointPairDistance$2
  14803. };
  14804. var DistanceToPoint = function DistanceToPoint () {};
  14805. DistanceToPoint.prototype.interfaces_ = function interfaces_ () {
  14806. return []
  14807. };
  14808. DistanceToPoint.prototype.getClass = function getClass () {
  14809. return DistanceToPoint
  14810. };
  14811. DistanceToPoint.computeDistance = function computeDistance () {
  14812. if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof LineString && arguments[1] instanceof Coordinate)) {
  14813. var line = arguments[0];
  14814. var pt = arguments[1];
  14815. var ptDist = arguments[2];
  14816. var tempSegment = new LineSegment();
  14817. var coords = line.getCoordinates();
  14818. for (var i = 0; i < coords.length - 1; i++) {
  14819. tempSegment.setCoordinates(coords[i], coords[i + 1]);
  14820. var closestPt = tempSegment.closestPoint(pt);
  14821. ptDist.setMinimum(closestPt, pt);
  14822. }
  14823. } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof Polygon && arguments[1] instanceof Coordinate)) {
  14824. var poly = arguments[0];
  14825. var pt$1 = arguments[1];
  14826. var ptDist$1 = arguments[2];
  14827. DistanceToPoint.computeDistance(poly.getExteriorRing(), pt$1, ptDist$1);
  14828. for (var i$1 = 0; i$1 < poly.getNumInteriorRing(); i$1++) {
  14829. DistanceToPoint.computeDistance(poly.getInteriorRingN(i$1), pt$1, ptDist$1);
  14830. }
  14831. } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof Geometry && arguments[1] instanceof Coordinate)) {
  14832. var geom = arguments[0];
  14833. var pt$2 = arguments[1];
  14834. var ptDist$2 = arguments[2];
  14835. if (geom instanceof LineString) {
  14836. DistanceToPoint.computeDistance(geom, pt$2, ptDist$2);
  14837. } else if (geom instanceof Polygon) {
  14838. DistanceToPoint.computeDistance(geom, pt$2, ptDist$2);
  14839. } else if (geom instanceof GeometryCollection) {
  14840. var gc = geom;
  14841. for (var i$2 = 0; i$2 < gc.getNumGeometries(); i$2++) {
  14842. var g = gc.getGeometryN(i$2);
  14843. DistanceToPoint.computeDistance(g, pt$2, ptDist$2);
  14844. }
  14845. } else {
  14846. ptDist$2.setMinimum(geom.getCoordinate(), pt$2);
  14847. }
  14848. } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof LineSegment && arguments[1] instanceof Coordinate)) {
  14849. var segment = arguments[0];
  14850. var pt$3 = arguments[1];
  14851. var ptDist$3 = arguments[2];
  14852. var closestPt$1 = segment.closestPoint(pt$3);
  14853. ptDist$3.setMinimum(closestPt$1, pt$3);
  14854. }
  14855. };
  14856. var DiscreteHausdorffDistance = function DiscreteHausdorffDistance () {
  14857. this._g0 = null;
  14858. this._g1 = null;
  14859. this._ptDist = new PointPairDistance$2();
  14860. this._densifyFrac = 0.0;
  14861. var g0 = arguments[0];
  14862. var g1 = arguments[1];
  14863. this._g0 = g0;
  14864. this._g1 = g1;
  14865. };
  14866. var staticAccessors$39 = { MaxPointDistanceFilter: { configurable: true },MaxDensifiedByFractionDistanceFilter: { configurable: true } };
  14867. DiscreteHausdorffDistance.prototype.getCoordinates = function getCoordinates () {
  14868. return this._ptDist.getCoordinates()
  14869. };
  14870. DiscreteHausdorffDistance.prototype.setDensifyFraction = function setDensifyFraction (densifyFrac) {
  14871. if (densifyFrac > 1.0 || densifyFrac <= 0.0) { throw new IllegalArgumentException('Fraction is not in range (0.0 - 1.0]') }
  14872. this._densifyFrac = densifyFrac;
  14873. };
  14874. DiscreteHausdorffDistance.prototype.compute = function compute (g0, g1) {
  14875. this.computeOrientedDistance(g0, g1, this._ptDist);
  14876. this.computeOrientedDistance(g1, g0, this._ptDist);
  14877. };
  14878. DiscreteHausdorffDistance.prototype.distance = function distance () {
  14879. this.compute(this._g0, this._g1);
  14880. return this._ptDist.getDistance()
  14881. };
  14882. DiscreteHausdorffDistance.prototype.computeOrientedDistance = function computeOrientedDistance (discreteGeom, geom, ptDist) {
  14883. var distFilter = new MaxPointDistanceFilter$1(geom);
  14884. discreteGeom.apply(distFilter);
  14885. ptDist.setMaximum(distFilter.getMaxPointDistance());
  14886. if (this._densifyFrac > 0) {
  14887. var fracFilter = new MaxDensifiedByFractionDistanceFilter(geom, this._densifyFrac);
  14888. discreteGeom.apply(fracFilter);
  14889. ptDist.setMaximum(fracFilter.getMaxPointDistance());
  14890. }
  14891. };
  14892. DiscreteHausdorffDistance.prototype.orientedDistance = function orientedDistance () {
  14893. this.computeOrientedDistance(this._g0, this._g1, this._ptDist);
  14894. return this._ptDist.getDistance()
  14895. };
  14896. DiscreteHausdorffDistance.prototype.interfaces_ = function interfaces_ () {
  14897. return []
  14898. };
  14899. DiscreteHausdorffDistance.prototype.getClass = function getClass () {
  14900. return DiscreteHausdorffDistance
  14901. };
  14902. DiscreteHausdorffDistance.distance = function distance () {
  14903. if (arguments.length === 2) {
  14904. var g0 = arguments[0];
  14905. var g1 = arguments[1];
  14906. var dist = new DiscreteHausdorffDistance(g0, g1);
  14907. return dist.distance()
  14908. } else if (arguments.length === 3) {
  14909. var g0$1 = arguments[0];
  14910. var g1$1 = arguments[1];
  14911. var densifyFrac = arguments[2];
  14912. var dist$1 = new DiscreteHausdorffDistance(g0$1, g1$1);
  14913. dist$1.setDensifyFraction(densifyFrac);
  14914. return dist$1.distance()
  14915. }
  14916. };
  14917. staticAccessors$39.MaxPointDistanceFilter.get = function () { return MaxPointDistanceFilter$1 };
  14918. staticAccessors$39.MaxDensifiedByFractionDistanceFilter.get = function () { return MaxDensifiedByFractionDistanceFilter };
  14919. Object.defineProperties( DiscreteHausdorffDistance, staticAccessors$39 );
  14920. var MaxPointDistanceFilter$1 = function MaxPointDistanceFilter () {
  14921. this._maxPtDist = new PointPairDistance$2();
  14922. this._minPtDist = new PointPairDistance$2();
  14923. this._euclideanDist = new DistanceToPoint();
  14924. this._geom = null;
  14925. var geom = arguments[0];
  14926. this._geom = geom;
  14927. };
  14928. MaxPointDistanceFilter$1.prototype.filter = function filter (pt) {
  14929. this._minPtDist.initialize();
  14930. DistanceToPoint.computeDistance(this._geom, pt, this._minPtDist);
  14931. this._maxPtDist.setMaximum(this._minPtDist);
  14932. };
  14933. MaxPointDistanceFilter$1.prototype.getMaxPointDistance = function getMaxPointDistance () {
  14934. return this._maxPtDist
  14935. };
  14936. MaxPointDistanceFilter$1.prototype.interfaces_ = function interfaces_ () {
  14937. return [CoordinateFilter]
  14938. };
  14939. MaxPointDistanceFilter$1.prototype.getClass = function getClass () {
  14940. return MaxPointDistanceFilter$1
  14941. };
  14942. var MaxDensifiedByFractionDistanceFilter = function MaxDensifiedByFractionDistanceFilter () {
  14943. this._maxPtDist = new PointPairDistance$2();
  14944. this._minPtDist = new PointPairDistance$2();
  14945. this._geom = null;
  14946. this._numSubSegs = 0;
  14947. var geom = arguments[0];
  14948. var fraction = arguments[1];
  14949. this._geom = geom;
  14950. this._numSubSegs = Math.trunc(Math.round(1.0 / fraction));
  14951. };
  14952. MaxDensifiedByFractionDistanceFilter.prototype.filter = function filter (seq, index) {
  14953. var this$1 = this;
  14954. if (index === 0) { return null }
  14955. var p0 = seq.getCoordinate(index - 1);
  14956. var p1 = seq.getCoordinate(index);
  14957. var delx = (p1.x - p0.x) / this._numSubSegs;
  14958. var dely = (p1.y - p0.y) / this._numSubSegs;
  14959. for (var i = 0; i < this._numSubSegs; i++) {
  14960. var x = p0.x + i * delx;
  14961. var y = p0.y + i * dely;
  14962. var pt = new Coordinate(x, y);
  14963. this$1._minPtDist.initialize();
  14964. DistanceToPoint.computeDistance(this$1._geom, pt, this$1._minPtDist);
  14965. this$1._maxPtDist.setMaximum(this$1._minPtDist);
  14966. }
  14967. };
  14968. MaxDensifiedByFractionDistanceFilter.prototype.isDone = function isDone () {
  14969. return false
  14970. };
  14971. MaxDensifiedByFractionDistanceFilter.prototype.isGeometryChanged = function isGeometryChanged () {
  14972. return false
  14973. };
  14974. MaxDensifiedByFractionDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {
  14975. return this._maxPtDist
  14976. };
  14977. MaxDensifiedByFractionDistanceFilter.prototype.interfaces_ = function interfaces_ () {
  14978. return [CoordinateSequenceFilter]
  14979. };
  14980. MaxDensifiedByFractionDistanceFilter.prototype.getClass = function getClass () {
  14981. return MaxDensifiedByFractionDistanceFilter
  14982. };
  14983. var BufferDistanceValidator = function BufferDistanceValidator (input, bufDistance, result) {
  14984. this._minValidDistance = null;
  14985. this._maxValidDistance = null;
  14986. this._minDistanceFound = null;
  14987. this._maxDistanceFound = null;
  14988. this._isValid = true;
  14989. this._errMsg = null;
  14990. this._errorLocation = null;
  14991. this._errorIndicator = null;
  14992. this._input = input || null;
  14993. this._bufDistance = bufDistance || null;
  14994. this._result = result || null;
  14995. };
  14996. var staticAccessors$37 = { VERBOSE: { configurable: true },MAX_DISTANCE_DIFF_FRAC: { configurable: true } };
  14997. BufferDistanceValidator.prototype.checkMaximumDistance = function checkMaximumDistance (input, bufCurve, maxDist) {
  14998. var haus = new DiscreteHausdorffDistance(bufCurve, input);
  14999. haus.setDensifyFraction(0.25);
  15000. this._maxDistanceFound = haus.orientedDistance();
  15001. if (this._maxDistanceFound > maxDist) {
  15002. this._isValid = false;
  15003. var pts = haus.getCoordinates();
  15004. this._errorLocation = pts[1];
  15005. this._errorIndicator = input.getFactory().createLineString(pts);
  15006. this._errMsg = 'Distance between buffer curve and input is too large (' + this._maxDistanceFound + ' at ' + WKTWriter.toLineString(pts[0], pts[1]) + ')';
  15007. }
  15008. };
  15009. BufferDistanceValidator.prototype.isValid = function isValid () {
  15010. var posDistance = Math.abs(this._bufDistance);
  15011. var distDelta = BufferDistanceValidator.MAX_DISTANCE_DIFF_FRAC * posDistance;
  15012. this._minValidDistance = posDistance - distDelta;
  15013. this._maxValidDistance = posDistance + distDelta;
  15014. if (this._input.isEmpty() || this._result.isEmpty()) { return true }
  15015. if (this._bufDistance > 0.0) {
  15016. this.checkPositiveValid();
  15017. } else {
  15018. this.checkNegativeValid();
  15019. }
  15020. if (BufferDistanceValidator.VERBOSE) {
  15021. 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));
  15022. }
  15023. return this._isValid
  15024. };
  15025. BufferDistanceValidator.prototype.checkNegativeValid = function checkNegativeValid () {
  15026. if (!(this._input instanceof Polygon || this._input instanceof MultiPolygon || this._input instanceof GeometryCollection)) {
  15027. return null
  15028. }
  15029. var inputCurve = this.getPolygonLines(this._input);
  15030. this.checkMinimumDistance(inputCurve, this._result, this._minValidDistance);
  15031. if (!this._isValid) { return null }
  15032. this.checkMaximumDistance(inputCurve, this._result, this._maxValidDistance);
  15033. };
  15034. BufferDistanceValidator.prototype.getErrorIndicator = function getErrorIndicator () {
  15035. return this._errorIndicator
  15036. };
  15037. BufferDistanceValidator.prototype.checkMinimumDistance = function checkMinimumDistance (g1, g2, minDist) {
  15038. var distOp = new DistanceOp(g1, g2, minDist);
  15039. this._minDistanceFound = distOp.distance();
  15040. if (this._minDistanceFound < minDist) {
  15041. this._isValid = false;
  15042. var pts = distOp.nearestPoints();
  15043. this._errorLocation = distOp.nearestPoints()[1];
  15044. this._errorIndicator = g1.getFactory().createLineString(pts);
  15045. this._errMsg = 'Distance between buffer curve and input is too small (' + this._minDistanceFound + ' at ' + WKTWriter.toLineString(pts[0], pts[1]) + ' )';
  15046. }
  15047. };
  15048. BufferDistanceValidator.prototype.checkPositiveValid = function checkPositiveValid () {
  15049. var bufCurve = this._result.getBoundary();
  15050. this.checkMinimumDistance(this._input, bufCurve, this._minValidDistance);
  15051. if (!this._isValid) { return null }
  15052. this.checkMaximumDistance(this._input, bufCurve, this._maxValidDistance);
  15053. };
  15054. BufferDistanceValidator.prototype.getErrorLocation = function getErrorLocation () {
  15055. return this._errorLocation
  15056. };
  15057. BufferDistanceValidator.prototype.getPolygonLines = function getPolygonLines (g) {
  15058. var lines = new ArrayList();
  15059. var lineExtracter = new LinearComponentExtracter(lines);
  15060. var polys = PolygonExtracter.getPolygons(g);
  15061. for (var i = polys.iterator(); i.hasNext();) {
  15062. var poly = i.next();
  15063. poly.apply(lineExtracter);
  15064. }
  15065. return g.getFactory().buildGeometry(lines)
  15066. };
  15067. BufferDistanceValidator.prototype.getErrorMessage = function getErrorMessage () {
  15068. return this._errMsg
  15069. };
  15070. BufferDistanceValidator.prototype.interfaces_ = function interfaces_ () {
  15071. return []
  15072. };
  15073. BufferDistanceValidator.prototype.getClass = function getClass () {
  15074. return BufferDistanceValidator
  15075. };
  15076. staticAccessors$37.VERBOSE.get = function () { return false };
  15077. staticAccessors$37.MAX_DISTANCE_DIFF_FRAC.get = function () { return 0.012 };
  15078. Object.defineProperties( BufferDistanceValidator, staticAccessors$37 );
  15079. var BufferResultValidator = function BufferResultValidator (input, distance, result) {
  15080. this._isValid = true;
  15081. this._errorMsg = null;
  15082. this._errorLocation = null;
  15083. this._errorIndicator = null;
  15084. this._input = input || null;
  15085. this._distance = distance || null;
  15086. this._result = result || null;
  15087. };
  15088. var staticAccessors$40 = { VERBOSE: { configurable: true },MAX_ENV_DIFF_FRAC: { configurable: true } };
  15089. BufferResultValidator.prototype.isValid = function isValid () {
  15090. this.checkPolygonal();
  15091. if (!this._isValid) { return this._isValid }
  15092. this.checkExpectedEmpty();
  15093. if (!this._isValid) { return this._isValid }
  15094. this.checkEnvelope();
  15095. if (!this._isValid) { return this._isValid }
  15096. this.checkArea();
  15097. if (!this._isValid) { return this._isValid }
  15098. this.checkDistance();
  15099. return this._isValid
  15100. };
  15101. BufferResultValidator.prototype.checkEnvelope = function checkEnvelope () {
  15102. if (this._distance < 0.0) { return null }
  15103. var padding = this._distance * BufferResultValidator.MAX_ENV_DIFF_FRAC;
  15104. if (padding === 0.0) { padding = 0.001; }
  15105. var expectedEnv = new Envelope(this._input.getEnvelopeInternal());
  15106. expectedEnv.expandBy(this._distance);
  15107. var bufEnv = new Envelope(this._result.getEnvelopeInternal());
  15108. bufEnv.expandBy(padding);
  15109. if (!bufEnv.contains(expectedEnv)) {
  15110. this._isValid = false;
  15111. this._errorMsg = 'Buffer envelope is incorrect';
  15112. this._errorIndicator = this._input.getFactory().toGeometry(bufEnv);
  15113. }
  15114. this.report('Envelope');
  15115. };
  15116. BufferResultValidator.prototype.checkDistance = function checkDistance () {
  15117. var distValid = new BufferDistanceValidator(this._input, this._distance, this._result);
  15118. if (!distValid.isValid()) {
  15119. this._isValid = false;
  15120. this._errorMsg = distValid.getErrorMessage();
  15121. this._errorLocation = distValid.getErrorLocation();
  15122. this._errorIndicator = distValid.getErrorIndicator();
  15123. }
  15124. this.report('Distance');
  15125. };
  15126. BufferResultValidator.prototype.checkArea = function checkArea () {
  15127. var inputArea = this._input.getArea();
  15128. var resultArea = this._result.getArea();
  15129. if (this._distance > 0.0 && inputArea > resultArea) {
  15130. this._isValid = false;
  15131. this._errorMsg = 'Area of positive buffer is smaller than input';
  15132. this._errorIndicator = this._result;
  15133. }
  15134. if (this._distance < 0.0 && inputArea < resultArea) {
  15135. this._isValid = false;
  15136. this._errorMsg = 'Area of negative buffer is larger than input';
  15137. this._errorIndicator = this._result;
  15138. }
  15139. this.report('Area');
  15140. };
  15141. BufferResultValidator.prototype.checkPolygonal = function checkPolygonal () {
  15142. if (!(this._result instanceof Polygon || this._result instanceof MultiPolygon)) { this._isValid = false; }
  15143. this._errorMsg = 'Result is not polygonal';
  15144. this._errorIndicator = this._result;
  15145. this.report('Polygonal');
  15146. };
  15147. BufferResultValidator.prototype.getErrorIndicator = function getErrorIndicator () {
  15148. return this._errorIndicator
  15149. };
  15150. BufferResultValidator.prototype.getErrorLocation = function getErrorLocation () {
  15151. return this._errorLocation
  15152. };
  15153. BufferResultValidator.prototype.checkExpectedEmpty = function checkExpectedEmpty () {
  15154. if (this._input.getDimension() >= 2) { return null }
  15155. if (this._distance > 0.0) { return null }
  15156. if (!this._result.isEmpty()) {
  15157. this._isValid = false;
  15158. this._errorMsg = 'Result is non-empty';
  15159. this._errorIndicator = this._result;
  15160. }
  15161. this.report('ExpectedEmpty');
  15162. };
  15163. BufferResultValidator.prototype.report = function report (checkName) {
  15164. if (!BufferResultValidator.VERBOSE) { return null }
  15165. System.out.println('Check ' + checkName + ': ' + (this._isValid ? 'passed' : 'FAILED'));
  15166. };
  15167. BufferResultValidator.prototype.getErrorMessage = function getErrorMessage () {
  15168. return this._errorMsg
  15169. };
  15170. BufferResultValidator.prototype.interfaces_ = function interfaces_ () {
  15171. return []
  15172. };
  15173. BufferResultValidator.prototype.getClass = function getClass () {
  15174. return BufferResultValidator
  15175. };
  15176. BufferResultValidator.isValidMsg = function isValidMsg (g, distance, result) {
  15177. var validator = new BufferResultValidator(g, distance, result);
  15178. if (!validator.isValid()) { return validator.getErrorMessage() }
  15179. return null
  15180. };
  15181. BufferResultValidator.isValid = function isValid (g, distance, result) {
  15182. var validator = new BufferResultValidator(g, distance, result);
  15183. if (validator.isValid()) { return true }
  15184. return false
  15185. };
  15186. staticAccessors$40.VERBOSE.get = function () { return false };
  15187. staticAccessors$40.MAX_ENV_DIFF_FRAC.get = function () { return 0.012 };
  15188. Object.defineProperties( BufferResultValidator, staticAccessors$40 );
  15189. // operation.buffer
  15190. var BasicSegmentString = function BasicSegmentString () {
  15191. this._pts = null;
  15192. this._data = null;
  15193. var pts = arguments[0];
  15194. var data = arguments[1];
  15195. this._pts = pts;
  15196. this._data = data;
  15197. };
  15198. BasicSegmentString.prototype.getCoordinates = function getCoordinates () {
  15199. return this._pts
  15200. };
  15201. BasicSegmentString.prototype.size = function size () {
  15202. return this._pts.length
  15203. };
  15204. BasicSegmentString.prototype.getCoordinate = function getCoordinate (i) {
  15205. return this._pts[i]
  15206. };
  15207. BasicSegmentString.prototype.isClosed = function isClosed () {
  15208. return this._pts[0].equals(this._pts[this._pts.length - 1])
  15209. };
  15210. BasicSegmentString.prototype.getSegmentOctant = function getSegmentOctant (index) {
  15211. if (index === this._pts.length - 1) { return -1 }
  15212. return Octant.octant(this.getCoordinate(index), this.getCoordinate(index + 1))
  15213. };
  15214. BasicSegmentString.prototype.setData = function setData (data) {
  15215. this._data = data;
  15216. };
  15217. BasicSegmentString.prototype.getData = function getData () {
  15218. return this._data
  15219. };
  15220. BasicSegmentString.prototype.toString = function toString () {
  15221. return WKTWriter.toLineString(new CoordinateArraySequence(this._pts))
  15222. };
  15223. BasicSegmentString.prototype.interfaces_ = function interfaces_ () {
  15224. return [SegmentString]
  15225. };
  15226. BasicSegmentString.prototype.getClass = function getClass () {
  15227. return BasicSegmentString
  15228. };
  15229. var InteriorIntersectionFinder = function InteriorIntersectionFinder () {
  15230. this._findAllIntersections = false;
  15231. this._isCheckEndSegmentsOnly = false;
  15232. this._li = null;
  15233. this._interiorIntersection = null;
  15234. this._intSegments = null;
  15235. this._intersections = new ArrayList();
  15236. this._intersectionCount = 0;
  15237. this._keepIntersections = true;
  15238. var li = arguments[0];
  15239. this._li = li;
  15240. this._interiorIntersection = null;
  15241. };
  15242. InteriorIntersectionFinder.prototype.getInteriorIntersection = function getInteriorIntersection () {
  15243. return this._interiorIntersection
  15244. };
  15245. InteriorIntersectionFinder.prototype.setCheckEndSegmentsOnly = function setCheckEndSegmentsOnly (isCheckEndSegmentsOnly) {
  15246. this._isCheckEndSegmentsOnly = isCheckEndSegmentsOnly;
  15247. };
  15248. InteriorIntersectionFinder.prototype.getIntersectionSegments = function getIntersectionSegments () {
  15249. return this._intSegments
  15250. };
  15251. InteriorIntersectionFinder.prototype.count = function count () {
  15252. return this._intersectionCount
  15253. };
  15254. InteriorIntersectionFinder.prototype.getIntersections = function getIntersections () {
  15255. return this._intersections
  15256. };
  15257. InteriorIntersectionFinder.prototype.setFindAllIntersections = function setFindAllIntersections (findAllIntersections) {
  15258. this._findAllIntersections = findAllIntersections;
  15259. };
  15260. InteriorIntersectionFinder.prototype.setKeepIntersections = function setKeepIntersections (keepIntersections) {
  15261. this._keepIntersections = keepIntersections;
  15262. };
  15263. InteriorIntersectionFinder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {
  15264. if (!this._findAllIntersections && this.hasIntersection()) { return null }
  15265. if (e0 === e1 && segIndex0 === segIndex1) { return null }
  15266. if (this._isCheckEndSegmentsOnly) {
  15267. var isEndSegPresent = this.isEndSegment(e0, segIndex0) || this.isEndSegment(e1, segIndex1);
  15268. if (!isEndSegPresent) { return null }
  15269. }
  15270. var p00 = e0.getCoordinates()[segIndex0];
  15271. var p01 = e0.getCoordinates()[segIndex0 + 1];
  15272. var p10 = e1.getCoordinates()[segIndex1];
  15273. var p11 = e1.getCoordinates()[segIndex1 + 1];
  15274. this._li.computeIntersection(p00, p01, p10, p11);
  15275. if (this._li.hasIntersection()) {
  15276. if (this._li.isInteriorIntersection()) {
  15277. this._intSegments = new Array(4).fill(null);
  15278. this._intSegments[0] = p00;
  15279. this._intSegments[1] = p01;
  15280. this._intSegments[2] = p10;
  15281. this._intSegments[3] = p11;
  15282. this._interiorIntersection = this._li.getIntersection(0);
  15283. if (this._keepIntersections) { this._intersections.add(this._interiorIntersection); }
  15284. this._intersectionCount++;
  15285. }
  15286. }
  15287. };
  15288. InteriorIntersectionFinder.prototype.isEndSegment = function isEndSegment (segStr, index) {
  15289. if (index === 0) { return true }
  15290. if (index >= segStr.size() - 2) { return true }
  15291. return false
  15292. };
  15293. InteriorIntersectionFinder.prototype.hasIntersection = function hasIntersection () {
  15294. return this._interiorIntersection !== null
  15295. };
  15296. InteriorIntersectionFinder.prototype.isDone = function isDone () {
  15297. if (this._findAllIntersections) { return false }
  15298. return this._interiorIntersection !== null
  15299. };
  15300. InteriorIntersectionFinder.prototype.interfaces_ = function interfaces_ () {
  15301. return [SegmentIntersector]
  15302. };
  15303. InteriorIntersectionFinder.prototype.getClass = function getClass () {
  15304. return InteriorIntersectionFinder
  15305. };
  15306. InteriorIntersectionFinder.createAllIntersectionsFinder = function createAllIntersectionsFinder (li) {
  15307. var finder = new InteriorIntersectionFinder(li);
  15308. finder.setFindAllIntersections(true);
  15309. return finder
  15310. };
  15311. InteriorIntersectionFinder.createAnyIntersectionFinder = function createAnyIntersectionFinder (li) {
  15312. return new InteriorIntersectionFinder(li)
  15313. };
  15314. InteriorIntersectionFinder.createIntersectionCounter = function createIntersectionCounter (li) {
  15315. var finder = new InteriorIntersectionFinder(li);
  15316. finder.setFindAllIntersections(true);
  15317. finder.setKeepIntersections(false);
  15318. return finder
  15319. };
  15320. var FastNodingValidator = function FastNodingValidator () {
  15321. this._li = new RobustLineIntersector();
  15322. this._segStrings = null;
  15323. this._findAllIntersections = false;
  15324. this._segInt = null;
  15325. this._isValid = true;
  15326. var segStrings = arguments[0];
  15327. this._segStrings = segStrings;
  15328. };
  15329. FastNodingValidator.prototype.execute = function execute () {
  15330. if (this._segInt !== null) { return null }
  15331. this.checkInteriorIntersections();
  15332. };
  15333. FastNodingValidator.prototype.getIntersections = function getIntersections () {
  15334. return this._segInt.getIntersections()
  15335. };
  15336. FastNodingValidator.prototype.isValid = function isValid () {
  15337. this.execute();
  15338. return this._isValid
  15339. };
  15340. FastNodingValidator.prototype.setFindAllIntersections = function setFindAllIntersections (findAllIntersections) {
  15341. this._findAllIntersections = findAllIntersections;
  15342. };
  15343. FastNodingValidator.prototype.checkInteriorIntersections = function checkInteriorIntersections () {
  15344. this._isValid = true;
  15345. this._segInt = new InteriorIntersectionFinder(this._li);
  15346. this._segInt.setFindAllIntersections(this._findAllIntersections);
  15347. var noder = new MCIndexNoder();
  15348. noder.setSegmentIntersector(this._segInt);
  15349. noder.computeNodes(this._segStrings);
  15350. if (this._segInt.hasIntersection()) {
  15351. this._isValid = false;
  15352. return null
  15353. }
  15354. };
  15355. FastNodingValidator.prototype.checkValid = function checkValid () {
  15356. this.execute();
  15357. if (!this._isValid) { throw new TopologyException(this.getErrorMessage(), this._segInt.getInteriorIntersection()) }
  15358. };
  15359. FastNodingValidator.prototype.getErrorMessage = function getErrorMessage () {
  15360. if (this._isValid) { return 'no intersections found' }
  15361. var intSegs = this._segInt.getIntersectionSegments();
  15362. return 'found non-noded intersection between ' + WKTWriter.toLineString(intSegs[0], intSegs[1]) + ' and ' + WKTWriter.toLineString(intSegs[2], intSegs[3])
  15363. };
  15364. FastNodingValidator.prototype.interfaces_ = function interfaces_ () {
  15365. return []
  15366. };
  15367. FastNodingValidator.prototype.getClass = function getClass () {
  15368. return FastNodingValidator
  15369. };
  15370. FastNodingValidator.computeIntersections = function computeIntersections (segStrings) {
  15371. var nv = new FastNodingValidator(segStrings);
  15372. nv.setFindAllIntersections(true);
  15373. nv.isValid();
  15374. return nv.getIntersections()
  15375. };
  15376. var EdgeNodingValidator = function EdgeNodingValidator () {
  15377. this._nv = null;
  15378. var edges = arguments[0];
  15379. this._nv = new FastNodingValidator(EdgeNodingValidator.toSegmentStrings(edges));
  15380. };
  15381. EdgeNodingValidator.prototype.checkValid = function checkValid () {
  15382. this._nv.checkValid();
  15383. };
  15384. EdgeNodingValidator.prototype.interfaces_ = function interfaces_ () {
  15385. return []
  15386. };
  15387. EdgeNodingValidator.prototype.getClass = function getClass () {
  15388. return EdgeNodingValidator
  15389. };
  15390. EdgeNodingValidator.toSegmentStrings = function toSegmentStrings (edges) {
  15391. var segStrings = new ArrayList();
  15392. for (var i = edges.iterator(); i.hasNext();) {
  15393. var e = i.next();
  15394. segStrings.add(new BasicSegmentString(e.getCoordinates(), e));
  15395. }
  15396. return segStrings
  15397. };
  15398. EdgeNodingValidator.checkValid = function checkValid (edges) {
  15399. var validator = new EdgeNodingValidator(edges);
  15400. validator.checkValid();
  15401. };
  15402. var GeometryCollectionMapper = function GeometryCollectionMapper (mapOp) {
  15403. this._mapOp = mapOp;
  15404. };
  15405. GeometryCollectionMapper.prototype.map = function map (gc) {
  15406. var this$1 = this;
  15407. var mapped = new ArrayList();
  15408. for (var i = 0; i < gc.getNumGeometries(); i++) {
  15409. var g = this$1._mapOp.map(gc.getGeometryN(i));
  15410. if (!g.isEmpty()) { mapped.add(g); }
  15411. }
  15412. return gc.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(mapped))
  15413. };
  15414. GeometryCollectionMapper.prototype.interfaces_ = function interfaces_ () {
  15415. return []
  15416. };
  15417. GeometryCollectionMapper.prototype.getClass = function getClass () {
  15418. return GeometryCollectionMapper
  15419. };
  15420. GeometryCollectionMapper.map = function map (gc, op) {
  15421. var mapper = new GeometryCollectionMapper(op);
  15422. return mapper.map(gc)
  15423. };
  15424. var LineBuilder = function LineBuilder () {
  15425. this._op = null;
  15426. this._geometryFactory = null;
  15427. this._ptLocator = null;
  15428. this._lineEdgesList = new ArrayList();
  15429. this._resultLineList = new ArrayList();
  15430. var op = arguments[0];
  15431. var geometryFactory = arguments[1];
  15432. var ptLocator = arguments[2];
  15433. this._op = op;
  15434. this._geometryFactory = geometryFactory;
  15435. this._ptLocator = ptLocator;
  15436. };
  15437. LineBuilder.prototype.collectLines = function collectLines (opCode) {
  15438. var this$1 = this;
  15439. for (var it = this._op.getGraph().getEdgeEnds().iterator(); it.hasNext();) {
  15440. var de = it.next();
  15441. this$1.collectLineEdge(de, opCode, this$1._lineEdgesList);
  15442. this$1.collectBoundaryTouchEdge(de, opCode, this$1._lineEdgesList);
  15443. }
  15444. };
  15445. LineBuilder.prototype.labelIsolatedLine = function labelIsolatedLine (e, targetIndex) {
  15446. var loc = this._ptLocator.locate(e.getCoordinate(), this._op.getArgGeometry(targetIndex));
  15447. e.getLabel().setLocation(targetIndex, loc);
  15448. };
  15449. LineBuilder.prototype.build = function build (opCode) {
  15450. this.findCoveredLineEdges();
  15451. this.collectLines(opCode);
  15452. this.buildLines(opCode);
  15453. return this._resultLineList
  15454. };
  15455. LineBuilder.prototype.collectLineEdge = function collectLineEdge (de, opCode, edges) {
  15456. var label = de.getLabel();
  15457. var e = de.getEdge();
  15458. if (de.isLineEdge()) {
  15459. if (!de.isVisited() && OverlayOp.isResultOfOp(label, opCode) && !e.isCovered()) {
  15460. edges.add(e);
  15461. de.setVisitedEdge(true);
  15462. }
  15463. }
  15464. };
  15465. LineBuilder.prototype.findCoveredLineEdges = function findCoveredLineEdges () {
  15466. var this$1 = this;
  15467. for (var nodeit = this._op.getGraph().getNodes().iterator(); nodeit.hasNext();) {
  15468. var node = nodeit.next();
  15469. node.getEdges().findCoveredLineEdges();
  15470. }
  15471. for (var it = this._op.getGraph().getEdgeEnds().iterator(); it.hasNext();) {
  15472. var de = it.next();
  15473. var e = de.getEdge();
  15474. if (de.isLineEdge() && !e.isCoveredSet()) {
  15475. var isCovered = this$1._op.isCoveredByA(de.getCoordinate());
  15476. e.setCovered(isCovered);
  15477. }
  15478. }
  15479. };
  15480. LineBuilder.prototype.labelIsolatedLines = function labelIsolatedLines (edgesList) {
  15481. var this$1 = this;
  15482. for (var it = edgesList.iterator(); it.hasNext();) {
  15483. var e = it.next();
  15484. var label = e.getLabel();
  15485. if (e.isIsolated()) {
  15486. if (label.isNull(0)) { this$1.labelIsolatedLine(e, 0); } else { this$1.labelIsolatedLine(e, 1); }
  15487. }
  15488. }
  15489. };
  15490. LineBuilder.prototype.buildLines = function buildLines (opCode) {
  15491. var this$1 = this;
  15492. for (var it = this._lineEdgesList.iterator(); it.hasNext();) {
  15493. var e = it.next();
  15494. // const label = e.getLabel()
  15495. var line = this$1._geometryFactory.createLineString(e.getCoordinates());
  15496. this$1._resultLineList.add(line);
  15497. e.setInResult(true);
  15498. }
  15499. };
  15500. LineBuilder.prototype.collectBoundaryTouchEdge = function collectBoundaryTouchEdge (de, opCode, edges) {
  15501. var label = de.getLabel();
  15502. if (de.isLineEdge()) { return null }
  15503. if (de.isVisited()) { return null }
  15504. if (de.isInteriorAreaEdge()) { return null }
  15505. if (de.getEdge().isInResult()) { return null }
  15506. Assert.isTrue(!(de.isInResult() || de.getSym().isInResult()) || !de.getEdge().isInResult());
  15507. if (OverlayOp.isResultOfOp(label, opCode) && opCode === OverlayOp.INTERSECTION) {
  15508. edges.add(de.getEdge());
  15509. de.setVisitedEdge(true);
  15510. }
  15511. };
  15512. LineBuilder.prototype.interfaces_ = function interfaces_ () {
  15513. return []
  15514. };
  15515. LineBuilder.prototype.getClass = function getClass () {
  15516. return LineBuilder
  15517. };
  15518. var PointBuilder = function PointBuilder () {
  15519. this._op = null;
  15520. this._geometryFactory = null;
  15521. this._resultPointList = new ArrayList();
  15522. var op = arguments[0];
  15523. var geometryFactory = arguments[1];
  15524. // const ptLocator = arguments[2]
  15525. this._op = op;
  15526. this._geometryFactory = geometryFactory;
  15527. };
  15528. PointBuilder.prototype.filterCoveredNodeToPoint = function filterCoveredNodeToPoint (n) {
  15529. var coord = n.getCoordinate();
  15530. if (!this._op.isCoveredByLA(coord)) {
  15531. var pt = this._geometryFactory.createPoint(coord);
  15532. this._resultPointList.add(pt);
  15533. }
  15534. };
  15535. PointBuilder.prototype.extractNonCoveredResultNodes = function extractNonCoveredResultNodes (opCode) {
  15536. var this$1 = this;
  15537. for (var nodeit = this._op.getGraph().getNodes().iterator(); nodeit.hasNext();) {
  15538. var n = nodeit.next();
  15539. if (n.isInResult()) { continue }
  15540. if (n.isIncidentEdgeInResult()) { continue }
  15541. if (n.getEdges().getDegree() === 0 || opCode === OverlayOp.INTERSECTION) {
  15542. var label = n.getLabel();
  15543. if (OverlayOp.isResultOfOp(label, opCode)) {
  15544. this$1.filterCoveredNodeToPoint(n);
  15545. }
  15546. }
  15547. }
  15548. };
  15549. PointBuilder.prototype.build = function build (opCode) {
  15550. this.extractNonCoveredResultNodes(opCode);
  15551. return this._resultPointList
  15552. };
  15553. PointBuilder.prototype.interfaces_ = function interfaces_ () {
  15554. return []
  15555. };
  15556. PointBuilder.prototype.getClass = function getClass () {
  15557. return PointBuilder
  15558. };
  15559. var GeometryTransformer = function GeometryTransformer () {
  15560. this._inputGeom = null;
  15561. this._factory = null;
  15562. this._pruneEmptyGeometry = true;
  15563. this._preserveGeometryCollectionType = true;
  15564. this._preserveCollections = false;
  15565. this._preserveType = false;
  15566. };
  15567. GeometryTransformer.prototype.transformPoint = function transformPoint (geom, parent) {
  15568. return this._factory.createPoint(this.transformCoordinates(geom.getCoordinateSequence(), geom))
  15569. };
  15570. GeometryTransformer.prototype.transformPolygon = function transformPolygon (geom, parent) {
  15571. var this$1 = this;
  15572. var isAllValidLinearRings = true;
  15573. var shell = this.transformLinearRing(geom.getExteriorRing(), geom);
  15574. if (shell === null || !(shell instanceof LinearRing) || shell.isEmpty()) { isAllValidLinearRings = false; }
  15575. var holes = new ArrayList();
  15576. for (var i = 0; i < geom.getNumInteriorRing(); i++) {
  15577. var hole = this$1.transformLinearRing(geom.getInteriorRingN(i), geom);
  15578. if (hole === null || hole.isEmpty()) {
  15579. continue
  15580. }
  15581. if (!(hole instanceof LinearRing)) { isAllValidLinearRings = false; }
  15582. holes.add(hole);
  15583. }
  15584. if (isAllValidLinearRings) { return this._factory.createPolygon(shell, holes.toArray([])); } else {
  15585. var components = new ArrayList();
  15586. if (shell !== null) { components.add(shell); }
  15587. components.addAll(holes);
  15588. return this._factory.buildGeometry(components)
  15589. }
  15590. };
  15591. GeometryTransformer.prototype.createCoordinateSequence = function createCoordinateSequence (coords) {
  15592. return this._factory.getCoordinateSequenceFactory().create(coords)
  15593. };
  15594. GeometryTransformer.prototype.getInputGeometry = function getInputGeometry () {
  15595. return this._inputGeom
  15596. };
  15597. GeometryTransformer.prototype.transformMultiLineString = function transformMultiLineString (geom, parent) {
  15598. var this$1 = this;
  15599. var transGeomList = new ArrayList();
  15600. for (var i = 0; i < geom.getNumGeometries(); i++) {
  15601. var transformGeom = this$1.transformLineString(geom.getGeometryN(i), geom);
  15602. if (transformGeom === null) { continue }
  15603. if (transformGeom.isEmpty()) { continue }
  15604. transGeomList.add(transformGeom);
  15605. }
  15606. return this._factory.buildGeometry(transGeomList)
  15607. };
  15608. GeometryTransformer.prototype.transformCoordinates = function transformCoordinates (coords, parent) {
  15609. return this.copy(coords)
  15610. };
  15611. GeometryTransformer.prototype.transformLineString = function transformLineString (geom, parent) {
  15612. return this._factory.createLineString(this.transformCoordinates(geom.getCoordinateSequence(), geom))
  15613. };
  15614. GeometryTransformer.prototype.transformMultiPoint = function transformMultiPoint (geom, parent) {
  15615. var this$1 = this;
  15616. var transGeomList = new ArrayList();
  15617. for (var i = 0; i < geom.getNumGeometries(); i++) {
  15618. var transformGeom = this$1.transformPoint(geom.getGeometryN(i), geom);
  15619. if (transformGeom === null) { continue }
  15620. if (transformGeom.isEmpty()) { continue }
  15621. transGeomList.add(transformGeom);
  15622. }
  15623. return this._factory.buildGeometry(transGeomList)
  15624. };
  15625. GeometryTransformer.prototype.transformMultiPolygon = function transformMultiPolygon (geom, parent) {
  15626. var this$1 = this;
  15627. var transGeomList = new ArrayList();
  15628. for (var i = 0; i < geom.getNumGeometries(); i++) {
  15629. var transformGeom = this$1.transformPolygon(geom.getGeometryN(i), geom);
  15630. if (transformGeom === null) { continue }
  15631. if (transformGeom.isEmpty()) { continue }
  15632. transGeomList.add(transformGeom);
  15633. }
  15634. return this._factory.buildGeometry(transGeomList)
  15635. };
  15636. GeometryTransformer.prototype.copy = function copy (seq) {
  15637. return seq.copy()
  15638. };
  15639. GeometryTransformer.prototype.transformGeometryCollection = function transformGeometryCollection (geom, parent) {
  15640. var this$1 = this;
  15641. var transGeomList = new ArrayList();
  15642. for (var i = 0; i < geom.getNumGeometries(); i++) {
  15643. var transformGeom = this$1.transform(geom.getGeometryN(i));
  15644. if (transformGeom === null) { continue }
  15645. if (this$1._pruneEmptyGeometry && transformGeom.isEmpty()) { continue }
  15646. transGeomList.add(transformGeom);
  15647. }
  15648. if (this._preserveGeometryCollectionType) { return this._factory.createGeometryCollection(GeometryFactory.toGeometryArray(transGeomList)) }
  15649. return this._factory.buildGeometry(transGeomList)
  15650. };
  15651. GeometryTransformer.prototype.transform = function transform (inputGeom) {
  15652. this._inputGeom = inputGeom;
  15653. this._factory = inputGeom.getFactory();
  15654. if (inputGeom instanceof Point) { return this.transformPoint(inputGeom, null) }
  15655. if (inputGeom instanceof MultiPoint) { return this.transformMultiPoint(inputGeom, null) }
  15656. if (inputGeom instanceof LinearRing) { return this.transformLinearRing(inputGeom, null) }
  15657. if (inputGeom instanceof LineString) { return this.transformLineString(inputGeom, null) }
  15658. if (inputGeom instanceof MultiLineString) { return this.transformMultiLineString(inputGeom, null) }
  15659. if (inputGeom instanceof Polygon) { return this.transformPolygon(inputGeom, null) }
  15660. if (inputGeom instanceof MultiPolygon) { return this.transformMultiPolygon(inputGeom, null) }
  15661. if (inputGeom instanceof GeometryCollection) { return this.transformGeometryCollection(inputGeom, null) }
  15662. throw new IllegalArgumentException('Unknown Geometry subtype: ' + inputGeom.getClass().getName())
  15663. };
  15664. GeometryTransformer.prototype.transformLinearRing = function transformLinearRing (geom, parent) {
  15665. var seq = this.transformCoordinates(geom.getCoordinateSequence(), geom);
  15666. if (seq === null) { return this._factory.createLinearRing(null) }
  15667. var seqSize = seq.size();
  15668. if (seqSize > 0 && seqSize < 4 && !this._preserveType) { return this._factory.createLineString(seq) }
  15669. return this._factory.createLinearRing(seq)
  15670. };
  15671. GeometryTransformer.prototype.interfaces_ = function interfaces_ () {
  15672. return []
  15673. };
  15674. GeometryTransformer.prototype.getClass = function getClass () {
  15675. return GeometryTransformer
  15676. };
  15677. var LineStringSnapper = function LineStringSnapper () {
  15678. this._snapTolerance = 0.0;
  15679. this._srcPts = null;
  15680. this._seg = new LineSegment();
  15681. this._allowSnappingToSourceVertices = false;
  15682. this._isClosed = false;
  15683. if (arguments[0] instanceof LineString && typeof arguments[1] === 'number') {
  15684. var srcLine = arguments[0];
  15685. var snapTolerance = arguments[1];
  15686. LineStringSnapper.call(this, srcLine.getCoordinates(), snapTolerance);
  15687. } else if (arguments[0] instanceof Array && typeof arguments[1] === 'number') {
  15688. var srcPts = arguments[0];
  15689. var snapTolerance$1 = arguments[1];
  15690. this._srcPts = srcPts;
  15691. this._isClosed = LineStringSnapper.isClosed(srcPts);
  15692. this._snapTolerance = snapTolerance$1;
  15693. }
  15694. };
  15695. LineStringSnapper.prototype.snapVertices = function snapVertices (srcCoords, snapPts) {
  15696. var this$1 = this;
  15697. var end = this._isClosed ? srcCoords.size() - 1 : srcCoords.size();
  15698. for (var i = 0; i < end; i++) {
  15699. var srcPt = srcCoords.get(i);
  15700. var snapVert = this$1.findSnapForVertex(srcPt, snapPts);
  15701. if (snapVert !== null) {
  15702. srcCoords.set(i, new Coordinate(snapVert));
  15703. if (i === 0 && this$1._isClosed) { srcCoords.set(srcCoords.size() - 1, new Coordinate(snapVert)); }
  15704. }
  15705. }
  15706. };
  15707. LineStringSnapper.prototype.findSnapForVertex = function findSnapForVertex (pt, snapPts) {
  15708. var this$1 = this;
  15709. for (var i = 0; i < snapPts.length; i++) {
  15710. if (pt.equals2D(snapPts[i])) { return null }
  15711. if (pt.distance(snapPts[i]) < this$1._snapTolerance) { return snapPts[i] }
  15712. }
  15713. return null
  15714. };
  15715. LineStringSnapper.prototype.snapTo = function snapTo (snapPts) {
  15716. var coordList = new CoordinateList(this._srcPts);
  15717. this.snapVertices(coordList, snapPts);
  15718. this.snapSegments(coordList, snapPts);
  15719. var newPts = coordList.toCoordinateArray();
  15720. return newPts
  15721. };
  15722. LineStringSnapper.prototype.snapSegments = function snapSegments (srcCoords, snapPts) {
  15723. var this$1 = this;
  15724. if (snapPts.length === 0) { return null }
  15725. var distinctPtCount = snapPts.length;
  15726. if (snapPts[0].equals2D(snapPts[snapPts.length - 1])) { distinctPtCount = snapPts.length - 1; }
  15727. for (var i = 0; i < distinctPtCount; i++) {
  15728. var snapPt = snapPts[i];
  15729. var index = this$1.findSegmentIndexToSnap(snapPt, srcCoords);
  15730. if (index >= 0) {
  15731. srcCoords.add(index + 1, new Coordinate(snapPt), false);
  15732. }
  15733. }
  15734. };
  15735. LineStringSnapper.prototype.findSegmentIndexToSnap = function findSegmentIndexToSnap (snapPt, srcCoords) {
  15736. var this$1 = this;
  15737. var minDist = Double.MAX_VALUE;
  15738. var snapIndex = -1;
  15739. for (var i = 0; i < srcCoords.size() - 1; i++) {
  15740. this$1._seg.p0 = srcCoords.get(i);
  15741. this$1._seg.p1 = srcCoords.get(i + 1);
  15742. if (this$1._seg.p0.equals2D(snapPt) || this$1._seg.p1.equals2D(snapPt)) {
  15743. if (this$1._allowSnappingToSourceVertices) { continue; } else { return -1 }
  15744. }
  15745. var dist = this$1._seg.distance(snapPt);
  15746. if (dist < this$1._snapTolerance && dist < minDist) {
  15747. minDist = dist;
  15748. snapIndex = i;
  15749. }
  15750. }
  15751. return snapIndex
  15752. };
  15753. LineStringSnapper.prototype.setAllowSnappingToSourceVertices = function setAllowSnappingToSourceVertices (allowSnappingToSourceVertices) {
  15754. this._allowSnappingToSourceVertices = allowSnappingToSourceVertices;
  15755. };
  15756. LineStringSnapper.prototype.interfaces_ = function interfaces_ () {
  15757. return []
  15758. };
  15759. LineStringSnapper.prototype.getClass = function getClass () {
  15760. return LineStringSnapper
  15761. };
  15762. LineStringSnapper.isClosed = function isClosed (pts) {
  15763. if (pts.length <= 1) { return false }
  15764. return pts[0].equals2D(pts[pts.length - 1])
  15765. };
  15766. var GeometrySnapper = function GeometrySnapper (srcGeom) {
  15767. this._srcGeom = srcGeom || null;
  15768. };
  15769. var staticAccessors$41 = { SNAP_PRECISION_FACTOR: { configurable: true } };
  15770. GeometrySnapper.prototype.snapTo = function snapTo (snapGeom, snapTolerance) {
  15771. var snapPts = this.extractTargetCoordinates(snapGeom);
  15772. var snapTrans = new SnapTransformer(snapTolerance, snapPts);
  15773. return snapTrans.transform(this._srcGeom)
  15774. };
  15775. GeometrySnapper.prototype.snapToSelf = function snapToSelf (snapTolerance, cleanResult) {
  15776. var snapPts = this.extractTargetCoordinates(this._srcGeom);
  15777. var snapTrans = new SnapTransformer(snapTolerance, snapPts, true);
  15778. var snappedGeom = snapTrans.transform(this._srcGeom);
  15779. var result = snappedGeom;
  15780. if (cleanResult && hasInterface(result, Polygonal)) {
  15781. result = snappedGeom.buffer(0);
  15782. }
  15783. return result
  15784. };
  15785. GeometrySnapper.prototype.computeSnapTolerance = function computeSnapTolerance (ringPts) {
  15786. var minSegLen = this.computeMinimumSegmentLength(ringPts);
  15787. var snapTol = minSegLen / 10;
  15788. return snapTol
  15789. };
  15790. GeometrySnapper.prototype.extractTargetCoordinates = function extractTargetCoordinates (g) {
  15791. var ptSet = new TreeSet();
  15792. var pts = g.getCoordinates();
  15793. for (var i = 0; i < pts.length; i++) {
  15794. ptSet.add(pts[i]);
  15795. }
  15796. return ptSet.toArray(new Array(0).fill(null))
  15797. };
  15798. GeometrySnapper.prototype.computeMinimumSegmentLength = function computeMinimumSegmentLength (pts) {
  15799. var minSegLen = Double.MAX_VALUE;
  15800. for (var i = 0; i < pts.length - 1; i++) {
  15801. var segLen = pts[i].distance(pts[i + 1]);
  15802. if (segLen < minSegLen) { minSegLen = segLen; }
  15803. }
  15804. return minSegLen
  15805. };
  15806. GeometrySnapper.prototype.interfaces_ = function interfaces_ () {
  15807. return []
  15808. };
  15809. GeometrySnapper.prototype.getClass = function getClass () {
  15810. return GeometrySnapper
  15811. };
  15812. GeometrySnapper.snap = function snap (g0, g1, snapTolerance) {
  15813. var snapGeom = new Array(2).fill(null);
  15814. var snapper0 = new GeometrySnapper(g0);
  15815. snapGeom[0] = snapper0.snapTo(g1, snapTolerance);
  15816. var snapper1 = new GeometrySnapper(g1);
  15817. snapGeom[1] = snapper1.snapTo(snapGeom[0], snapTolerance);
  15818. return snapGeom
  15819. };
  15820. GeometrySnapper.computeOverlaySnapTolerance = function computeOverlaySnapTolerance () {
  15821. if (arguments.length === 1) {
  15822. var g = arguments[0];
  15823. var snapTolerance = GeometrySnapper.computeSizeBasedSnapTolerance(g);
  15824. var pm = g.getPrecisionModel();
  15825. if (pm.getType() === PrecisionModel.FIXED) {
  15826. var fixedSnapTol = 1 / pm.getScale() * 2 / 1.415;
  15827. if (fixedSnapTol > snapTolerance) { snapTolerance = fixedSnapTol; }
  15828. }
  15829. return snapTolerance
  15830. } else if (arguments.length === 2) {
  15831. var g0 = arguments[0];
  15832. var g1 = arguments[1];
  15833. return Math.min(GeometrySnapper.computeOverlaySnapTolerance(g0), GeometrySnapper.computeOverlaySnapTolerance(g1))
  15834. }
  15835. };
  15836. GeometrySnapper.computeSizeBasedSnapTolerance = function computeSizeBasedSnapTolerance (g) {
  15837. var env = g.getEnvelopeInternal();
  15838. var minDimension = Math.min(env.getHeight(), env.getWidth());
  15839. var snapTol = minDimension * GeometrySnapper.SNAP_PRECISION_FACTOR;
  15840. return snapTol
  15841. };
  15842. GeometrySnapper.snapToSelf = function snapToSelf (geom, snapTolerance, cleanResult) {
  15843. var snapper0 = new GeometrySnapper(geom);
  15844. return snapper0.snapToSelf(snapTolerance, cleanResult)
  15845. };
  15846. staticAccessors$41.SNAP_PRECISION_FACTOR.get = function () { return 1e-9 };
  15847. Object.defineProperties( GeometrySnapper, staticAccessors$41 );
  15848. var SnapTransformer = (function (GeometryTransformer$$1) {
  15849. function SnapTransformer (snapTolerance, snapPts, isSelfSnap) {
  15850. GeometryTransformer$$1.call(this);
  15851. this._snapTolerance = snapTolerance || null;
  15852. this._snapPts = snapPts || null;
  15853. this._isSelfSnap = (isSelfSnap !== undefined) ? isSelfSnap : false;
  15854. }
  15855. if ( GeometryTransformer$$1 ) SnapTransformer.__proto__ = GeometryTransformer$$1;
  15856. SnapTransformer.prototype = Object.create( GeometryTransformer$$1 && GeometryTransformer$$1.prototype );
  15857. SnapTransformer.prototype.constructor = SnapTransformer;
  15858. SnapTransformer.prototype.snapLine = function snapLine (srcPts, snapPts) {
  15859. var snapper = new LineStringSnapper(srcPts, this._snapTolerance);
  15860. snapper.setAllowSnappingToSourceVertices(this._isSelfSnap);
  15861. return snapper.snapTo(snapPts)
  15862. };
  15863. SnapTransformer.prototype.transformCoordinates = function transformCoordinates (coords, parent) {
  15864. var srcPts = coords.toCoordinateArray();
  15865. var newPts = this.snapLine(srcPts, this._snapPts);
  15866. return this._factory.getCoordinateSequenceFactory().create(newPts)
  15867. };
  15868. SnapTransformer.prototype.interfaces_ = function interfaces_ () {
  15869. return []
  15870. };
  15871. SnapTransformer.prototype.getClass = function getClass () {
  15872. return SnapTransformer
  15873. };
  15874. return SnapTransformer;
  15875. }(GeometryTransformer));
  15876. var CommonBits = function CommonBits () {
  15877. this._isFirst = true;
  15878. this._commonMantissaBitsCount = 53;
  15879. this._commonBits = 0;
  15880. this._commonSignExp = null;
  15881. };
  15882. CommonBits.prototype.getCommon = function getCommon () {
  15883. return Double.longBitsToDouble(this._commonBits)
  15884. };
  15885. CommonBits.prototype.add = function add (num) {
  15886. var numBits = Double.doubleToLongBits(num);
  15887. if (this._isFirst) {
  15888. this._commonBits = numBits;
  15889. this._commonSignExp = CommonBits.signExpBits(this._commonBits);
  15890. this._isFirst = false;
  15891. return null
  15892. }
  15893. var numSignExp = CommonBits.signExpBits(numBits);
  15894. if (numSignExp !== this._commonSignExp) {
  15895. this._commonBits = 0;
  15896. return null
  15897. }
  15898. this._commonMantissaBitsCount = CommonBits.numCommonMostSigMantissaBits(this._commonBits, numBits);
  15899. this._commonBits = CommonBits.zeroLowerBits(this._commonBits, 64 - (12 + this._commonMantissaBitsCount));
  15900. };
  15901. CommonBits.prototype.toString = function toString () {
  15902. if (arguments.length === 1) {
  15903. var bits = arguments[0];
  15904. var x = Double.longBitsToDouble(bits);
  15905. var numStr = Double.toBinaryString(bits);
  15906. var padStr = '0000000000000000000000000000000000000000000000000000000000000000' + numStr;
  15907. var bitStr = padStr.substring(padStr.length - 64);
  15908. var str = bitStr.substring(0, 1) + ' ' + bitStr.substring(1, 12) + '(exp) ' + bitStr.substring(12) + ' [ ' + x + ' ]';
  15909. return str
  15910. }
  15911. };
  15912. CommonBits.prototype.interfaces_ = function interfaces_ () {
  15913. return []
  15914. };
  15915. CommonBits.prototype.getClass = function getClass () {
  15916. return CommonBits
  15917. };
  15918. CommonBits.getBit = function getBit (bits, i) {
  15919. var mask = 1 << i;
  15920. return (bits & mask) !== 0 ? 1 : 0
  15921. };
  15922. CommonBits.signExpBits = function signExpBits (num) {
  15923. return num >> 52
  15924. };
  15925. CommonBits.zeroLowerBits = function zeroLowerBits (bits, nBits) {
  15926. var invMask = (1 << nBits) - 1;
  15927. var mask = ~invMask;
  15928. var zeroed = bits & mask;
  15929. return zeroed
  15930. };
  15931. CommonBits.numCommonMostSigMantissaBits = function numCommonMostSigMantissaBits (num1, num2) {
  15932. var count = 0;
  15933. for (var i = 52; i >= 0; i--) {
  15934. if (CommonBits.getBit(num1, i) !== CommonBits.getBit(num2, i)) { return count }
  15935. count++;
  15936. }
  15937. return 52
  15938. };
  15939. var CommonBitsRemover = function CommonBitsRemover () {
  15940. this._commonCoord = null;
  15941. this._ccFilter = new CommonCoordinateFilter();
  15942. };
  15943. var staticAccessors$42 = { CommonCoordinateFilter: { configurable: true },Translater: { configurable: true } };
  15944. CommonBitsRemover.prototype.addCommonBits = function addCommonBits (geom) {
  15945. var trans = new Translater(this._commonCoord);
  15946. geom.apply(trans);
  15947. geom.geometryChanged();
  15948. };
  15949. CommonBitsRemover.prototype.removeCommonBits = function removeCommonBits (geom) {
  15950. if (this._commonCoord.x === 0.0 && this._commonCoord.y === 0.0) { return geom }
  15951. var invCoord = new Coordinate(this._commonCoord);
  15952. invCoord.x = -invCoord.x;
  15953. invCoord.y = -invCoord.y;
  15954. var trans = new Translater(invCoord);
  15955. geom.apply(trans);
  15956. geom.geometryChanged();
  15957. return geom
  15958. };
  15959. CommonBitsRemover.prototype.getCommonCoordinate = function getCommonCoordinate () {
  15960. return this._commonCoord
  15961. };
  15962. CommonBitsRemover.prototype.add = function add (geom) {
  15963. geom.apply(this._ccFilter);
  15964. this._commonCoord = this._ccFilter.getCommonCoordinate();
  15965. };
  15966. CommonBitsRemover.prototype.interfaces_ = function interfaces_ () {
  15967. return []
  15968. };
  15969. CommonBitsRemover.prototype.getClass = function getClass () {
  15970. return CommonBitsRemover
  15971. };
  15972. staticAccessors$42.CommonCoordinateFilter.get = function () { return CommonCoordinateFilter };
  15973. staticAccessors$42.Translater.get = function () { return Translater };
  15974. Object.defineProperties( CommonBitsRemover, staticAccessors$42 );
  15975. var CommonCoordinateFilter = function CommonCoordinateFilter () {
  15976. this._commonBitsX = new CommonBits();
  15977. this._commonBitsY = new CommonBits();
  15978. };
  15979. CommonCoordinateFilter.prototype.filter = function filter (coord) {
  15980. this._commonBitsX.add(coord.x);
  15981. this._commonBitsY.add(coord.y);
  15982. };
  15983. CommonCoordinateFilter.prototype.getCommonCoordinate = function getCommonCoordinate () {
  15984. return new Coordinate(this._commonBitsX.getCommon(), this._commonBitsY.getCommon())
  15985. };
  15986. CommonCoordinateFilter.prototype.interfaces_ = function interfaces_ () {
  15987. return [CoordinateFilter]
  15988. };
  15989. CommonCoordinateFilter.prototype.getClass = function getClass () {
  15990. return CommonCoordinateFilter
  15991. };
  15992. var Translater = function Translater () {
  15993. this.trans = null;
  15994. var trans = arguments[0];
  15995. this.trans = trans;
  15996. };
  15997. Translater.prototype.filter = function filter (seq, i) {
  15998. var xp = seq.getOrdinate(i, 0) + this.trans.x;
  15999. var yp = seq.getOrdinate(i, 1) + this.trans.y;
  16000. seq.setOrdinate(i, 0, xp);
  16001. seq.setOrdinate(i, 1, yp);
  16002. };
  16003. Translater.prototype.isDone = function isDone () {
  16004. return false
  16005. };
  16006. Translater.prototype.isGeometryChanged = function isGeometryChanged () {
  16007. return true
  16008. };
  16009. Translater.prototype.interfaces_ = function interfaces_ () {
  16010. return [CoordinateSequenceFilter]
  16011. };
  16012. Translater.prototype.getClass = function getClass () {
  16013. return Translater
  16014. };
  16015. var SnapOverlayOp = function SnapOverlayOp (g1, g2) {
  16016. this._geom = new Array(2).fill(null);
  16017. this._snapTolerance = null;
  16018. this._cbr = null;
  16019. this._geom[0] = g1;
  16020. this._geom[1] = g2;
  16021. this.computeSnapTolerance();
  16022. };
  16023. SnapOverlayOp.prototype.selfSnap = function selfSnap (geom) {
  16024. var snapper0 = new GeometrySnapper(geom);
  16025. var snapGeom = snapper0.snapTo(geom, this._snapTolerance);
  16026. return snapGeom
  16027. };
  16028. SnapOverlayOp.prototype.removeCommonBits = function removeCommonBits (geom) {
  16029. this._cbr = new CommonBitsRemover();
  16030. this._cbr.add(geom[0]);
  16031. this._cbr.add(geom[1]);
  16032. var remGeom = new Array(2).fill(null);
  16033. remGeom[0] = this._cbr.removeCommonBits(geom[0].copy());
  16034. remGeom[1] = this._cbr.removeCommonBits(geom[1].copy());
  16035. return remGeom
  16036. };
  16037. SnapOverlayOp.prototype.prepareResult = function prepareResult (geom) {
  16038. this._cbr.addCommonBits(geom);
  16039. return geom
  16040. };
  16041. SnapOverlayOp.prototype.getResultGeometry = function getResultGeometry (opCode) {
  16042. var prepGeom = this.snap(this._geom);
  16043. var result = OverlayOp.overlayOp(prepGeom[0], prepGeom[1], opCode);
  16044. return this.prepareResult(result)
  16045. };
  16046. SnapOverlayOp.prototype.checkValid = function checkValid (g) {
  16047. if (!g.isValid()) {
  16048. System.out.println('Snapped geometry is invalid');
  16049. }
  16050. };
  16051. SnapOverlayOp.prototype.computeSnapTolerance = function computeSnapTolerance () {
  16052. this._snapTolerance = GeometrySnapper.computeOverlaySnapTolerance(this._geom[0], this._geom[1]);
  16053. };
  16054. SnapOverlayOp.prototype.snap = function snap (geom) {
  16055. var remGeom = this.removeCommonBits(geom);
  16056. var snapGeom = GeometrySnapper.snap(remGeom[0], remGeom[1], this._snapTolerance);
  16057. return snapGeom
  16058. };
  16059. SnapOverlayOp.prototype.interfaces_ = function interfaces_ () {
  16060. return []
  16061. };
  16062. SnapOverlayOp.prototype.getClass = function getClass () {
  16063. return SnapOverlayOp
  16064. };
  16065. SnapOverlayOp.overlayOp = function overlayOp (g0, g1, opCode) {
  16066. var op = new SnapOverlayOp(g0, g1);
  16067. return op.getResultGeometry(opCode)
  16068. };
  16069. SnapOverlayOp.union = function union (g0, g1) {
  16070. return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.UNION)
  16071. };
  16072. SnapOverlayOp.intersection = function intersection (g0, g1) {
  16073. return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.INTERSECTION)
  16074. };
  16075. SnapOverlayOp.symDifference = function symDifference (g0, g1) {
  16076. return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.SYMDIFFERENCE)
  16077. };
  16078. SnapOverlayOp.difference = function difference (g0, g1) {
  16079. return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.DIFFERENCE)
  16080. };
  16081. var SnapIfNeededOverlayOp = function SnapIfNeededOverlayOp (g1, g2) {
  16082. this._geom = new Array(2).fill(null);
  16083. this._geom[0] = g1;
  16084. this._geom[1] = g2;
  16085. };
  16086. SnapIfNeededOverlayOp.prototype.getResultGeometry = function getResultGeometry (opCode) {
  16087. var result = null;
  16088. var isSuccess = false;
  16089. var savedException = null;
  16090. try {
  16091. result = OverlayOp.overlayOp(this._geom[0], this._geom[1], opCode);
  16092. var isValid = true;
  16093. if (isValid) { isSuccess = true; }
  16094. } catch (ex) {
  16095. if (ex instanceof RuntimeException) {
  16096. savedException = ex;
  16097. } else { throw ex }
  16098. } finally {}
  16099. if (!isSuccess) {
  16100. try {
  16101. result = SnapOverlayOp.overlayOp(this._geom[0], this._geom[1], opCode);
  16102. } catch (ex) {
  16103. if (ex instanceof RuntimeException) {
  16104. throw savedException
  16105. } else { throw ex }
  16106. } finally {}
  16107. }
  16108. return result
  16109. };
  16110. SnapIfNeededOverlayOp.prototype.interfaces_ = function interfaces_ () {
  16111. return []
  16112. };
  16113. SnapIfNeededOverlayOp.prototype.getClass = function getClass () {
  16114. return SnapIfNeededOverlayOp
  16115. };
  16116. SnapIfNeededOverlayOp.overlayOp = function overlayOp (g0, g1, opCode) {
  16117. var op = new SnapIfNeededOverlayOp(g0, g1);
  16118. return op.getResultGeometry(opCode)
  16119. };
  16120. SnapIfNeededOverlayOp.union = function union (g0, g1) {
  16121. return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.UNION)
  16122. };
  16123. SnapIfNeededOverlayOp.intersection = function intersection (g0, g1) {
  16124. return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.INTERSECTION)
  16125. };
  16126. SnapIfNeededOverlayOp.symDifference = function symDifference (g0, g1) {
  16127. return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.SYMDIFFERENCE)
  16128. };
  16129. SnapIfNeededOverlayOp.difference = function difference (g0, g1) {
  16130. return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.DIFFERENCE)
  16131. };
  16132. var MonotoneChain$2 = function MonotoneChain () {
  16133. this.mce = null;
  16134. this.chainIndex = null;
  16135. var mce = arguments[0];
  16136. var chainIndex = arguments[1];
  16137. this.mce = mce;
  16138. this.chainIndex = chainIndex;
  16139. };
  16140. MonotoneChain$2.prototype.computeIntersections = function computeIntersections (mc, si) {
  16141. this.mce.computeIntersectsForChain(this.chainIndex, mc.mce, mc.chainIndex, si);
  16142. };
  16143. MonotoneChain$2.prototype.interfaces_ = function interfaces_ () {
  16144. return []
  16145. };
  16146. MonotoneChain$2.prototype.getClass = function getClass () {
  16147. return MonotoneChain$2
  16148. };
  16149. var SweepLineEvent = function SweepLineEvent () {
  16150. this._label = null;
  16151. this._xValue = null;
  16152. this._eventType = null;
  16153. this._insertEvent = null;
  16154. this._deleteEventIndex = null;
  16155. this._obj = null;
  16156. if (arguments.length === 2) {
  16157. var x = arguments[0];
  16158. var insertEvent = arguments[1];
  16159. this._eventType = SweepLineEvent.DELETE;
  16160. this._xValue = x;
  16161. this._insertEvent = insertEvent;
  16162. } else if (arguments.length === 3) {
  16163. var label = arguments[0];
  16164. var x$1 = arguments[1];
  16165. var obj = arguments[2];
  16166. this._eventType = SweepLineEvent.INSERT;
  16167. this._label = label;
  16168. this._xValue = x$1;
  16169. this._obj = obj;
  16170. }
  16171. };
  16172. var staticAccessors$43 = { INSERT: { configurable: true },DELETE: { configurable: true } };
  16173. SweepLineEvent.prototype.isDelete = function isDelete () {
  16174. return this._eventType === SweepLineEvent.DELETE
  16175. };
  16176. SweepLineEvent.prototype.setDeleteEventIndex = function setDeleteEventIndex (deleteEventIndex) {
  16177. this._deleteEventIndex = deleteEventIndex;
  16178. };
  16179. SweepLineEvent.prototype.getObject = function getObject () {
  16180. return this._obj
  16181. };
  16182. SweepLineEvent.prototype.compareTo = function compareTo (o) {
  16183. var pe = o;
  16184. if (this._xValue < pe._xValue) { return -1 }
  16185. if (this._xValue > pe._xValue) { return 1 }
  16186. if (this._eventType < pe._eventType) { return -1 }
  16187. if (this._eventType > pe._eventType) { return 1 }
  16188. return 0
  16189. };
  16190. SweepLineEvent.prototype.getInsertEvent = function getInsertEvent () {
  16191. return this._insertEvent
  16192. };
  16193. SweepLineEvent.prototype.isInsert = function isInsert () {
  16194. return this._eventType === SweepLineEvent.INSERT
  16195. };
  16196. SweepLineEvent.prototype.isSameLabel = function isSameLabel (ev) {
  16197. if (this._label === null) { return false }
  16198. return this._label === ev._label
  16199. };
  16200. SweepLineEvent.prototype.getDeleteEventIndex = function getDeleteEventIndex () {
  16201. return this._deleteEventIndex
  16202. };
  16203. SweepLineEvent.prototype.interfaces_ = function interfaces_ () {
  16204. return [Comparable]
  16205. };
  16206. SweepLineEvent.prototype.getClass = function getClass () {
  16207. return SweepLineEvent
  16208. };
  16209. staticAccessors$43.INSERT.get = function () { return 1 };
  16210. staticAccessors$43.DELETE.get = function () { return 2 };
  16211. Object.defineProperties( SweepLineEvent, staticAccessors$43 );
  16212. var EdgeSetIntersector = function EdgeSetIntersector () {};
  16213. EdgeSetIntersector.prototype.interfaces_ = function interfaces_ () {
  16214. return []
  16215. };
  16216. EdgeSetIntersector.prototype.getClass = function getClass () {
  16217. return EdgeSetIntersector
  16218. };
  16219. var SegmentIntersector$2 = function SegmentIntersector () {
  16220. this._hasIntersection = false;
  16221. this._hasProper = false;
  16222. this._hasProperInterior = false;
  16223. this._properIntersectionPoint = null;
  16224. this._li = null;
  16225. this._includeProper = null;
  16226. this._recordIsolated = null;
  16227. this._isSelfIntersection = null;
  16228. this._numIntersections = 0;
  16229. this.numTests = 0;
  16230. this._bdyNodes = null;
  16231. this._isDone = false;
  16232. this._isDoneWhenProperInt = false;
  16233. var li = arguments[0];
  16234. var includeProper = arguments[1];
  16235. var recordIsolated = arguments[2];
  16236. this._li = li;
  16237. this._includeProper = includeProper;
  16238. this._recordIsolated = recordIsolated;
  16239. };
  16240. SegmentIntersector$2.prototype.isTrivialIntersection = function isTrivialIntersection (e0, segIndex0, e1, segIndex1) {
  16241. if (e0 === e1) {
  16242. if (this._li.getIntersectionNum() === 1) {
  16243. if (SegmentIntersector$2.isAdjacentSegments(segIndex0, segIndex1)) { return true }
  16244. if (e0.isClosed()) {
  16245. var maxSegIndex = e0.getNumPoints() - 1;
  16246. if ((segIndex0 === 0 && segIndex1 === maxSegIndex) ||
  16247. (segIndex1 === 0 && segIndex0 === maxSegIndex)) {
  16248. return true
  16249. }
  16250. }
  16251. }
  16252. }
  16253. return false
  16254. };
  16255. SegmentIntersector$2.prototype.getProperIntersectionPoint = function getProperIntersectionPoint () {
  16256. return this._properIntersectionPoint
  16257. };
  16258. SegmentIntersector$2.prototype.setIsDoneIfProperInt = function setIsDoneIfProperInt (isDoneWhenProperInt) {
  16259. this._isDoneWhenProperInt = isDoneWhenProperInt;
  16260. };
  16261. SegmentIntersector$2.prototype.hasProperInteriorIntersection = function hasProperInteriorIntersection () {
  16262. return this._hasProperInterior
  16263. };
  16264. SegmentIntersector$2.prototype.isBoundaryPointInternal = function isBoundaryPointInternal (li, bdyNodes) {
  16265. for (var i = bdyNodes.iterator(); i.hasNext();) {
  16266. var node = i.next();
  16267. var pt = node.getCoordinate();
  16268. if (li.isIntersection(pt)) { return true }
  16269. }
  16270. return false
  16271. };
  16272. SegmentIntersector$2.prototype.hasProperIntersection = function hasProperIntersection () {
  16273. return this._hasProper
  16274. };
  16275. SegmentIntersector$2.prototype.hasIntersection = function hasIntersection () {
  16276. return this._hasIntersection
  16277. };
  16278. SegmentIntersector$2.prototype.isDone = function isDone () {
  16279. return this._isDone
  16280. };
  16281. SegmentIntersector$2.prototype.isBoundaryPoint = function isBoundaryPoint (li, bdyNodes) {
  16282. if (bdyNodes === null) { return false }
  16283. if (this.isBoundaryPointInternal(li, bdyNodes[0])) { return true }
  16284. if (this.isBoundaryPointInternal(li, bdyNodes[1])) { return true }
  16285. return false
  16286. };
  16287. SegmentIntersector$2.prototype.setBoundaryNodes = function setBoundaryNodes (bdyNodes0, bdyNodes1) {
  16288. this._bdyNodes = new Array(2).fill(null);
  16289. this._bdyNodes[0] = bdyNodes0;
  16290. this._bdyNodes[1] = bdyNodes1;
  16291. };
  16292. SegmentIntersector$2.prototype.addIntersections = function addIntersections (e0, segIndex0, e1, segIndex1) {
  16293. if (e0 === e1 && segIndex0 === segIndex1) { return null }
  16294. this.numTests++;
  16295. var p00 = e0.getCoordinates()[segIndex0];
  16296. var p01 = e0.getCoordinates()[segIndex0 + 1];
  16297. var p10 = e1.getCoordinates()[segIndex1];
  16298. var p11 = e1.getCoordinates()[segIndex1 + 1];
  16299. this._li.computeIntersection(p00, p01, p10, p11);
  16300. if (this._li.hasIntersection()) {
  16301. if (this._recordIsolated) {
  16302. e0.setIsolated(false);
  16303. e1.setIsolated(false);
  16304. }
  16305. this._numIntersections++;
  16306. if (!this.isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {
  16307. this._hasIntersection = true;
  16308. if (this._includeProper || !this._li.isProper()) {
  16309. e0.addIntersections(this._li, segIndex0, 0);
  16310. e1.addIntersections(this._li, segIndex1, 1);
  16311. }
  16312. if (this._li.isProper()) {
  16313. this._properIntersectionPoint = this._li.getIntersection(0).copy();
  16314. this._hasProper = true;
  16315. if (this._isDoneWhenProperInt) {
  16316. this._isDone = true;
  16317. }
  16318. if (!this.isBoundaryPoint(this._li, this._bdyNodes)) { this._hasProperInterior = true; }
  16319. }
  16320. }
  16321. }
  16322. };
  16323. SegmentIntersector$2.prototype.interfaces_ = function interfaces_ () {
  16324. return []
  16325. };
  16326. SegmentIntersector$2.prototype.getClass = function getClass () {
  16327. return SegmentIntersector$2
  16328. };
  16329. SegmentIntersector$2.isAdjacentSegments = function isAdjacentSegments (i1, i2) {
  16330. return Math.abs(i1 - i2) === 1
  16331. };
  16332. var SimpleMCSweepLineIntersector = (function (EdgeSetIntersector$$1) {
  16333. function SimpleMCSweepLineIntersector () {
  16334. EdgeSetIntersector$$1.call(this);
  16335. this.events = new ArrayList();
  16336. this.nOverlaps = null;
  16337. }
  16338. if ( EdgeSetIntersector$$1 ) SimpleMCSweepLineIntersector.__proto__ = EdgeSetIntersector$$1;
  16339. SimpleMCSweepLineIntersector.prototype = Object.create( EdgeSetIntersector$$1 && EdgeSetIntersector$$1.prototype );
  16340. SimpleMCSweepLineIntersector.prototype.constructor = SimpleMCSweepLineIntersector;
  16341. SimpleMCSweepLineIntersector.prototype.prepareEvents = function prepareEvents () {
  16342. var this$1 = this;
  16343. Collections.sort(this.events);
  16344. for (var i = 0; i < this.events.size(); i++) {
  16345. var ev = this$1.events.get(i);
  16346. if (ev.isDelete()) {
  16347. ev.getInsertEvent().setDeleteEventIndex(i);
  16348. }
  16349. }
  16350. };
  16351. SimpleMCSweepLineIntersector.prototype.computeIntersections = function computeIntersections () {
  16352. var this$1 = this;
  16353. if (arguments.length === 1) {
  16354. var si = arguments[0];
  16355. this.nOverlaps = 0;
  16356. this.prepareEvents();
  16357. for (var i = 0; i < this.events.size(); i++) {
  16358. var ev = this$1.events.get(i);
  16359. if (ev.isInsert()) {
  16360. this$1.processOverlaps(i, ev.getDeleteEventIndex(), ev, si);
  16361. }
  16362. if (si.isDone()) {
  16363. break
  16364. }
  16365. }
  16366. } else if (arguments.length === 3) {
  16367. if (arguments[2] instanceof SegmentIntersector$2 && (hasInterface(arguments[0], List) && hasInterface(arguments[1], List))) {
  16368. var edges0 = arguments[0];
  16369. var edges1 = arguments[1];
  16370. var si$1 = arguments[2];
  16371. this.addEdges(edges0, edges0);
  16372. this.addEdges(edges1, edges1);
  16373. this.computeIntersections(si$1);
  16374. } else if (typeof arguments[2] === 'boolean' && (hasInterface(arguments[0], List) && arguments[1] instanceof SegmentIntersector$2)) {
  16375. var edges = arguments[0];
  16376. var si$2 = arguments[1];
  16377. var testAllSegments = arguments[2];
  16378. if (testAllSegments) { this.addEdges(edges, null); } else { this.addEdges(edges); }
  16379. this.computeIntersections(si$2);
  16380. }
  16381. }
  16382. };
  16383. SimpleMCSweepLineIntersector.prototype.addEdge = function addEdge (edge, edgeSet) {
  16384. var this$1 = this;
  16385. var mce = edge.getMonotoneChainEdge();
  16386. var startIndex = mce.getStartIndexes();
  16387. for (var i = 0; i < startIndex.length - 1; i++) {
  16388. var mc = new MonotoneChain$2(mce, i);
  16389. var insertEvent = new SweepLineEvent(edgeSet, mce.getMinX(i), mc);
  16390. this$1.events.add(insertEvent);
  16391. this$1.events.add(new SweepLineEvent(mce.getMaxX(i), insertEvent));
  16392. }
  16393. };
  16394. SimpleMCSweepLineIntersector.prototype.processOverlaps = function processOverlaps (start, end, ev0, si) {
  16395. var this$1 = this;
  16396. var mc0 = ev0.getObject();
  16397. for (var i = start; i < end; i++) {
  16398. var ev1 = this$1.events.get(i);
  16399. if (ev1.isInsert()) {
  16400. var mc1 = ev1.getObject();
  16401. if (!ev0.isSameLabel(ev1)) {
  16402. mc0.computeIntersections(mc1, si);
  16403. this$1.nOverlaps++;
  16404. }
  16405. }
  16406. }
  16407. };
  16408. SimpleMCSweepLineIntersector.prototype.addEdges = function addEdges () {
  16409. var this$1 = this;
  16410. if (arguments.length === 1) {
  16411. var edges = arguments[0];
  16412. for (var i = edges.iterator(); i.hasNext();) {
  16413. var edge = i.next();
  16414. this$1.addEdge(edge, edge);
  16415. }
  16416. } else if (arguments.length === 2) {
  16417. var edges$1 = arguments[0];
  16418. var edgeSet = arguments[1];
  16419. for (var i$1 = edges$1.iterator(); i$1.hasNext();) {
  16420. var edge$1 = i$1.next();
  16421. this$1.addEdge(edge$1, edgeSet);
  16422. }
  16423. }
  16424. };
  16425. SimpleMCSweepLineIntersector.prototype.interfaces_ = function interfaces_ () {
  16426. return []
  16427. };
  16428. SimpleMCSweepLineIntersector.prototype.getClass = function getClass () {
  16429. return SimpleMCSweepLineIntersector
  16430. };
  16431. return SimpleMCSweepLineIntersector;
  16432. }(EdgeSetIntersector));
  16433. var IntervalRTreeNode = function IntervalRTreeNode () {
  16434. this._min = Double.POSITIVE_INFINITY;
  16435. this._max = Double.NEGATIVE_INFINITY;
  16436. };
  16437. var staticAccessors$45 = { NodeComparator: { configurable: true } };
  16438. IntervalRTreeNode.prototype.getMin = function getMin () {
  16439. return this._min
  16440. };
  16441. IntervalRTreeNode.prototype.intersects = function intersects (queryMin, queryMax) {
  16442. if (this._min > queryMax || this._max < queryMin) { return false }
  16443. return true
  16444. };
  16445. IntervalRTreeNode.prototype.getMax = function getMax () {
  16446. return this._max
  16447. };
  16448. IntervalRTreeNode.prototype.toString = function toString () {
  16449. return WKTWriter.toLineString(new Coordinate(this._min, 0), new Coordinate(this._max, 0))
  16450. };
  16451. IntervalRTreeNode.prototype.interfaces_ = function interfaces_ () {
  16452. return []
  16453. };
  16454. IntervalRTreeNode.prototype.getClass = function getClass () {
  16455. return IntervalRTreeNode
  16456. };
  16457. staticAccessors$45.NodeComparator.get = function () { return NodeComparator };
  16458. Object.defineProperties( IntervalRTreeNode, staticAccessors$45 );
  16459. var NodeComparator = function NodeComparator () {};
  16460. NodeComparator.prototype.compare = function compare (o1, o2) {
  16461. var n1 = o1;
  16462. var n2 = o2;
  16463. var mid1 = (n1._min + n1._max) / 2;
  16464. var mid2 = (n2._min + n2._max) / 2;
  16465. if (mid1 < mid2) { return -1 }
  16466. if (mid1 > mid2) { return 1 }
  16467. return 0
  16468. };
  16469. NodeComparator.prototype.interfaces_ = function interfaces_ () {
  16470. return [Comparator]
  16471. };
  16472. NodeComparator.prototype.getClass = function getClass () {
  16473. return NodeComparator
  16474. };
  16475. var IntervalRTreeLeafNode = (function (IntervalRTreeNode$$1) {
  16476. function IntervalRTreeLeafNode () {
  16477. IntervalRTreeNode$$1.call(this);
  16478. this._item = null;
  16479. var min = arguments[0];
  16480. var max = arguments[1];
  16481. var item = arguments[2];
  16482. this._min = min;
  16483. this._max = max;
  16484. this._item = item;
  16485. }
  16486. if ( IntervalRTreeNode$$1 ) IntervalRTreeLeafNode.__proto__ = IntervalRTreeNode$$1;
  16487. IntervalRTreeLeafNode.prototype = Object.create( IntervalRTreeNode$$1 && IntervalRTreeNode$$1.prototype );
  16488. IntervalRTreeLeafNode.prototype.constructor = IntervalRTreeLeafNode;
  16489. IntervalRTreeLeafNode.prototype.query = function query (queryMin, queryMax, visitor) {
  16490. if (!this.intersects(queryMin, queryMax)) { return null }
  16491. visitor.visitItem(this._item);
  16492. };
  16493. IntervalRTreeLeafNode.prototype.interfaces_ = function interfaces_ () {
  16494. return []
  16495. };
  16496. IntervalRTreeLeafNode.prototype.getClass = function getClass () {
  16497. return IntervalRTreeLeafNode
  16498. };
  16499. return IntervalRTreeLeafNode;
  16500. }(IntervalRTreeNode));
  16501. var IntervalRTreeBranchNode = (function (IntervalRTreeNode$$1) {
  16502. function IntervalRTreeBranchNode () {
  16503. IntervalRTreeNode$$1.call(this);
  16504. this._node1 = null;
  16505. this._node2 = null;
  16506. var n1 = arguments[0];
  16507. var n2 = arguments[1];
  16508. this._node1 = n1;
  16509. this._node2 = n2;
  16510. this.buildExtent(this._node1, this._node2);
  16511. }
  16512. if ( IntervalRTreeNode$$1 ) IntervalRTreeBranchNode.__proto__ = IntervalRTreeNode$$1;
  16513. IntervalRTreeBranchNode.prototype = Object.create( IntervalRTreeNode$$1 && IntervalRTreeNode$$1.prototype );
  16514. IntervalRTreeBranchNode.prototype.constructor = IntervalRTreeBranchNode;
  16515. IntervalRTreeBranchNode.prototype.buildExtent = function buildExtent (n1, n2) {
  16516. this._min = Math.min(n1._min, n2._min);
  16517. this._max = Math.max(n1._max, n2._max);
  16518. };
  16519. IntervalRTreeBranchNode.prototype.query = function query (queryMin, queryMax, visitor) {
  16520. if (!this.intersects(queryMin, queryMax)) {
  16521. return null
  16522. }
  16523. if (this._node1 !== null) { this._node1.query(queryMin, queryMax, visitor); }
  16524. if (this._node2 !== null) { this._node2.query(queryMin, queryMax, visitor); }
  16525. };
  16526. IntervalRTreeBranchNode.prototype.interfaces_ = function interfaces_ () {
  16527. return []
  16528. };
  16529. IntervalRTreeBranchNode.prototype.getClass = function getClass () {
  16530. return IntervalRTreeBranchNode
  16531. };
  16532. return IntervalRTreeBranchNode;
  16533. }(IntervalRTreeNode));
  16534. var SortedPackedIntervalRTree = function SortedPackedIntervalRTree () {
  16535. this._leaves = new ArrayList();
  16536. this._root = null;
  16537. this._level = 0;
  16538. };
  16539. SortedPackedIntervalRTree.prototype.buildTree = function buildTree () {
  16540. var this$1 = this;
  16541. Collections.sort(this._leaves, new IntervalRTreeNode.NodeComparator());
  16542. var src = this._leaves;
  16543. var temp = null;
  16544. var dest = new ArrayList();
  16545. while (true) {
  16546. this$1.buildLevel(src, dest);
  16547. if (dest.size() === 1) { return dest.get(0) }
  16548. temp = src;
  16549. src = dest;
  16550. dest = temp;
  16551. }
  16552. };
  16553. SortedPackedIntervalRTree.prototype.insert = function insert (min, max, item) {
  16554. if (this._root !== null) { throw new Error('Index cannot be added to once it has been queried') }
  16555. this._leaves.add(new IntervalRTreeLeafNode(min, max, item));
  16556. };
  16557. SortedPackedIntervalRTree.prototype.query = function query (min, max, visitor) {
  16558. this.init();
  16559. this._root.query(min, max, visitor);
  16560. };
  16561. SortedPackedIntervalRTree.prototype.buildRoot = function buildRoot () {
  16562. if (this._root !== null) { return null }
  16563. this._root = this.buildTree();
  16564. };
  16565. SortedPackedIntervalRTree.prototype.printNode = function printNode (node) {
  16566. System.out.println(WKTWriter.toLineString(new Coordinate(node._min, this._level), new Coordinate(node._max, this._level)));
  16567. };
  16568. SortedPackedIntervalRTree.prototype.init = function init () {
  16569. if (this._root !== null) { return null }
  16570. this.buildRoot();
  16571. };
  16572. SortedPackedIntervalRTree.prototype.buildLevel = function buildLevel (src, dest) {
  16573. this._level++;
  16574. dest.clear();
  16575. for (var i = 0; i < src.size(); i += 2) {
  16576. var n1 = src.get(i);
  16577. var n2 = i + 1 < src.size() ? src.get(i) : null;
  16578. if (n2 === null) {
  16579. dest.add(n1);
  16580. } else {
  16581. var node = new IntervalRTreeBranchNode(src.get(i), src.get(i + 1));
  16582. dest.add(node);
  16583. }
  16584. }
  16585. };
  16586. SortedPackedIntervalRTree.prototype.interfaces_ = function interfaces_ () {
  16587. return []
  16588. };
  16589. SortedPackedIntervalRTree.prototype.getClass = function getClass () {
  16590. return SortedPackedIntervalRTree
  16591. };
  16592. var ArrayListVisitor = function ArrayListVisitor () {
  16593. this._items = new ArrayList();
  16594. };
  16595. ArrayListVisitor.prototype.visitItem = function visitItem (item) {
  16596. this._items.add(item);
  16597. };
  16598. ArrayListVisitor.prototype.getItems = function getItems () {
  16599. return this._items
  16600. };
  16601. ArrayListVisitor.prototype.interfaces_ = function interfaces_ () {
  16602. return [ItemVisitor]
  16603. };
  16604. ArrayListVisitor.prototype.getClass = function getClass () {
  16605. return ArrayListVisitor
  16606. };
  16607. var IndexedPointInAreaLocator = function IndexedPointInAreaLocator () {
  16608. this._index = null;
  16609. var g = arguments[0];
  16610. if (!hasInterface(g, Polygonal)) { throw new IllegalArgumentException('Argument must be Polygonal') }
  16611. this._index = new IntervalIndexedGeometry(g);
  16612. };
  16613. var staticAccessors$44 = { SegmentVisitor: { configurable: true },IntervalIndexedGeometry: { configurable: true } };
  16614. IndexedPointInAreaLocator.prototype.locate = function locate (p) {
  16615. var rcc = new RayCrossingCounter(p);
  16616. var visitor = new SegmentVisitor(rcc);
  16617. this._index.query(p.y, p.y, visitor);
  16618. return rcc.getLocation()
  16619. };
  16620. IndexedPointInAreaLocator.prototype.interfaces_ = function interfaces_ () {
  16621. return [PointOnGeometryLocator]
  16622. };
  16623. IndexedPointInAreaLocator.prototype.getClass = function getClass () {
  16624. return IndexedPointInAreaLocator
  16625. };
  16626. staticAccessors$44.SegmentVisitor.get = function () { return SegmentVisitor };
  16627. staticAccessors$44.IntervalIndexedGeometry.get = function () { return IntervalIndexedGeometry };
  16628. Object.defineProperties( IndexedPointInAreaLocator, staticAccessors$44 );
  16629. var SegmentVisitor = function SegmentVisitor () {
  16630. this._counter = null;
  16631. var counter = arguments[0];
  16632. this._counter = counter;
  16633. };
  16634. SegmentVisitor.prototype.visitItem = function visitItem (item) {
  16635. var seg = item;
  16636. this._counter.countSegment(seg.getCoordinate(0), seg.getCoordinate(1));
  16637. };
  16638. SegmentVisitor.prototype.interfaces_ = function interfaces_ () {
  16639. return [ItemVisitor]
  16640. };
  16641. SegmentVisitor.prototype.getClass = function getClass () {
  16642. return SegmentVisitor
  16643. };
  16644. var IntervalIndexedGeometry = function IntervalIndexedGeometry () {
  16645. this._index = new SortedPackedIntervalRTree();
  16646. var geom = arguments[0];
  16647. this.init(geom);
  16648. };
  16649. IntervalIndexedGeometry.prototype.init = function init (geom) {
  16650. var this$1 = this;
  16651. var lines = LinearComponentExtracter.getLines(geom);
  16652. for (var i = lines.iterator(); i.hasNext();) {
  16653. var line = i.next();
  16654. var pts = line.getCoordinates();
  16655. this$1.addLine(pts);
  16656. }
  16657. };
  16658. IntervalIndexedGeometry.prototype.addLine = function addLine (pts) {
  16659. var this$1 = this;
  16660. for (var i = 1; i < pts.length; i++) {
  16661. var seg = new LineSegment(pts[i - 1], pts[i]);
  16662. var min = Math.min(seg.p0.y, seg.p1.y);
  16663. var max = Math.max(seg.p0.y, seg.p1.y);
  16664. this$1._index.insert(min, max, seg);
  16665. }
  16666. };
  16667. IntervalIndexedGeometry.prototype.query = function query () {
  16668. if (arguments.length === 2) {
  16669. var min = arguments[0];
  16670. var max = arguments[1];
  16671. var visitor = new ArrayListVisitor();
  16672. this._index.query(min, max, visitor);
  16673. return visitor.getItems()
  16674. } else if (arguments.length === 3) {
  16675. var min$1 = arguments[0];
  16676. var max$1 = arguments[1];
  16677. var visitor$1 = arguments[2];
  16678. this._index.query(min$1, max$1, visitor$1);
  16679. }
  16680. };
  16681. IntervalIndexedGeometry.prototype.interfaces_ = function interfaces_ () {
  16682. return []
  16683. };
  16684. IntervalIndexedGeometry.prototype.getClass = function getClass () {
  16685. return IntervalIndexedGeometry
  16686. };
  16687. var GeometryGraph = (function (PlanarGraph$$1) {
  16688. function GeometryGraph () {
  16689. PlanarGraph$$1.call(this);
  16690. this._parentGeom = null;
  16691. this._lineEdgeMap = new HashMap();
  16692. this._boundaryNodeRule = null;
  16693. this._useBoundaryDeterminationRule = true;
  16694. this._argIndex = null;
  16695. this._boundaryNodes = null;
  16696. this._hasTooFewPoints = false;
  16697. this._invalidPoint = null;
  16698. this._areaPtLocator = null;
  16699. this._ptLocator = new PointLocator();
  16700. if (arguments.length === 2) {
  16701. var argIndex = arguments[0];
  16702. var parentGeom = arguments[1];
  16703. var boundaryNodeRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
  16704. this._argIndex = argIndex;
  16705. this._parentGeom = parentGeom;
  16706. this._boundaryNodeRule = boundaryNodeRule;
  16707. if (parentGeom !== null) {
  16708. this.add(parentGeom);
  16709. }
  16710. } else if (arguments.length === 3) {
  16711. var argIndex$1 = arguments[0];
  16712. var parentGeom$1 = arguments[1];
  16713. var boundaryNodeRule$1 = arguments[2];
  16714. this._argIndex = argIndex$1;
  16715. this._parentGeom = parentGeom$1;
  16716. this._boundaryNodeRule = boundaryNodeRule$1;
  16717. if (parentGeom$1 !== null) {
  16718. this.add(parentGeom$1);
  16719. }
  16720. }
  16721. }
  16722. if ( PlanarGraph$$1 ) GeometryGraph.__proto__ = PlanarGraph$$1;
  16723. GeometryGraph.prototype = Object.create( PlanarGraph$$1 && PlanarGraph$$1.prototype );
  16724. GeometryGraph.prototype.constructor = GeometryGraph;
  16725. GeometryGraph.prototype.insertBoundaryPoint = function insertBoundaryPoint (argIndex, coord) {
  16726. var n = this._nodes.addNode(coord);
  16727. var lbl = n.getLabel();
  16728. var boundaryCount = 1;
  16729. var loc = Location.NONE;
  16730. loc = lbl.getLocation(argIndex, Position.ON);
  16731. if (loc === Location.BOUNDARY) { boundaryCount++; }
  16732. var newLoc = GeometryGraph.determineBoundary(this._boundaryNodeRule, boundaryCount);
  16733. lbl.setLocation(argIndex, newLoc);
  16734. };
  16735. GeometryGraph.prototype.computeSelfNodes = function computeSelfNodes () {
  16736. if (arguments.length === 2) {
  16737. var li = arguments[0];
  16738. var computeRingSelfNodes = arguments[1];
  16739. return this.computeSelfNodes(li, computeRingSelfNodes, false)
  16740. } else if (arguments.length === 3) {
  16741. var li$1 = arguments[0];
  16742. var computeRingSelfNodes$1 = arguments[1];
  16743. var isDoneIfProperInt = arguments[2];
  16744. var si = new SegmentIntersector$2(li$1, true, false);
  16745. si.setIsDoneIfProperInt(isDoneIfProperInt);
  16746. var esi = this.createEdgeSetIntersector();
  16747. var isRings = this._parentGeom instanceof LinearRing || this._parentGeom instanceof Polygon || this._parentGeom instanceof MultiPolygon;
  16748. var computeAllSegments = computeRingSelfNodes$1 || !isRings;
  16749. esi.computeIntersections(this._edges, si, computeAllSegments);
  16750. this.addSelfIntersectionNodes(this._argIndex);
  16751. return si
  16752. }
  16753. };
  16754. GeometryGraph.prototype.computeSplitEdges = function computeSplitEdges (edgelist) {
  16755. for (var i = this._edges.iterator(); i.hasNext();) {
  16756. var e = i.next();
  16757. e.eiList.addSplitEdges(edgelist);
  16758. }
  16759. };
  16760. GeometryGraph.prototype.computeEdgeIntersections = function computeEdgeIntersections (g, li, includeProper) {
  16761. var si = new SegmentIntersector$2(li, includeProper, true);
  16762. si.setBoundaryNodes(this.getBoundaryNodes(), g.getBoundaryNodes());
  16763. var esi = this.createEdgeSetIntersector();
  16764. esi.computeIntersections(this._edges, g._edges, si);
  16765. return si
  16766. };
  16767. GeometryGraph.prototype.getGeometry = function getGeometry () {
  16768. return this._parentGeom
  16769. };
  16770. GeometryGraph.prototype.getBoundaryNodeRule = function getBoundaryNodeRule () {
  16771. return this._boundaryNodeRule
  16772. };
  16773. GeometryGraph.prototype.hasTooFewPoints = function hasTooFewPoints () {
  16774. return this._hasTooFewPoints
  16775. };
  16776. GeometryGraph.prototype.addPoint = function addPoint () {
  16777. if (arguments[0] instanceof Point) {
  16778. var p = arguments[0];
  16779. var coord = p.getCoordinate();
  16780. this.insertPoint(this._argIndex, coord, Location.INTERIOR);
  16781. } else if (arguments[0] instanceof Coordinate) {
  16782. var pt = arguments[0];
  16783. this.insertPoint(this._argIndex, pt, Location.INTERIOR);
  16784. }
  16785. };
  16786. GeometryGraph.prototype.addPolygon = function addPolygon (p) {
  16787. var this$1 = this;
  16788. this.addPolygonRing(p.getExteriorRing(), Location.EXTERIOR, Location.INTERIOR);
  16789. for (var i = 0; i < p.getNumInteriorRing(); i++) {
  16790. var hole = p.getInteriorRingN(i);
  16791. this$1.addPolygonRing(hole, Location.INTERIOR, Location.EXTERIOR);
  16792. }
  16793. };
  16794. GeometryGraph.prototype.addEdge = function addEdge (e) {
  16795. this.insertEdge(e);
  16796. var coord = e.getCoordinates();
  16797. this.insertPoint(this._argIndex, coord[0], Location.BOUNDARY);
  16798. this.insertPoint(this._argIndex, coord[coord.length - 1], Location.BOUNDARY);
  16799. };
  16800. GeometryGraph.prototype.addLineString = function addLineString (line) {
  16801. var coord = CoordinateArrays.removeRepeatedPoints(line.getCoordinates());
  16802. if (coord.length < 2) {
  16803. this._hasTooFewPoints = true;
  16804. this._invalidPoint = coord[0];
  16805. return null
  16806. }
  16807. var e = new Edge(coord, new Label(this._argIndex, Location.INTERIOR));
  16808. this._lineEdgeMap.put(line, e);
  16809. this.insertEdge(e);
  16810. Assert.isTrue(coord.length >= 2, 'found LineString with single point');
  16811. this.insertBoundaryPoint(this._argIndex, coord[0]);
  16812. this.insertBoundaryPoint(this._argIndex, coord[coord.length - 1]);
  16813. };
  16814. GeometryGraph.prototype.getInvalidPoint = function getInvalidPoint () {
  16815. return this._invalidPoint
  16816. };
  16817. GeometryGraph.prototype.getBoundaryPoints = function getBoundaryPoints () {
  16818. var coll = this.getBoundaryNodes();
  16819. var pts = new Array(coll.size()).fill(null);
  16820. var i = 0;
  16821. for (var it = coll.iterator(); it.hasNext();) {
  16822. var node = it.next();
  16823. pts[i++] = node.getCoordinate().copy();
  16824. }
  16825. return pts
  16826. };
  16827. GeometryGraph.prototype.getBoundaryNodes = function getBoundaryNodes () {
  16828. if (this._boundaryNodes === null) { this._boundaryNodes = this._nodes.getBoundaryNodes(this._argIndex); }
  16829. return this._boundaryNodes
  16830. };
  16831. GeometryGraph.prototype.addSelfIntersectionNode = function addSelfIntersectionNode (argIndex, coord, loc) {
  16832. if (this.isBoundaryNode(argIndex, coord)) { return null }
  16833. if (loc === Location.BOUNDARY && this._useBoundaryDeterminationRule) { this.insertBoundaryPoint(argIndex, coord); } else { this.insertPoint(argIndex, coord, loc); }
  16834. };
  16835. GeometryGraph.prototype.addPolygonRing = function addPolygonRing (lr, cwLeft, cwRight) {
  16836. if (lr.isEmpty()) { return null }
  16837. var coord = CoordinateArrays.removeRepeatedPoints(lr.getCoordinates());
  16838. if (coord.length < 4) {
  16839. this._hasTooFewPoints = true;
  16840. this._invalidPoint = coord[0];
  16841. return null
  16842. }
  16843. var left = cwLeft;
  16844. var right = cwRight;
  16845. if (CGAlgorithms.isCCW(coord)) {
  16846. left = cwRight;
  16847. right = cwLeft;
  16848. }
  16849. var e = new Edge(coord, new Label(this._argIndex, Location.BOUNDARY, left, right));
  16850. this._lineEdgeMap.put(lr, e);
  16851. this.insertEdge(e);
  16852. this.insertPoint(this._argIndex, coord[0], Location.BOUNDARY);
  16853. };
  16854. GeometryGraph.prototype.insertPoint = function insertPoint (argIndex, coord, onLocation) {
  16855. var n = this._nodes.addNode(coord);
  16856. var lbl = n.getLabel();
  16857. if (lbl === null) {
  16858. n._label = new Label(argIndex, onLocation);
  16859. } else { lbl.setLocation(argIndex, onLocation); }
  16860. };
  16861. GeometryGraph.prototype.createEdgeSetIntersector = function createEdgeSetIntersector () {
  16862. return new SimpleMCSweepLineIntersector()
  16863. };
  16864. GeometryGraph.prototype.addSelfIntersectionNodes = function addSelfIntersectionNodes (argIndex) {
  16865. var this$1 = this;
  16866. for (var i = this._edges.iterator(); i.hasNext();) {
  16867. var e = i.next();
  16868. var eLoc = e.getLabel().getLocation(argIndex);
  16869. for (var eiIt = e.eiList.iterator(); eiIt.hasNext();) {
  16870. var ei = eiIt.next();
  16871. this$1.addSelfIntersectionNode(argIndex, ei.coord, eLoc);
  16872. }
  16873. }
  16874. };
  16875. GeometryGraph.prototype.add = function add () {
  16876. if (arguments.length === 1) {
  16877. var g = arguments[0];
  16878. if (g.isEmpty()) { return null }
  16879. if (g instanceof MultiPolygon) { this._useBoundaryDeterminationRule = false; }
  16880. if (g instanceof Polygon) { this.addPolygon(g); }
  16881. else if (g instanceof LineString) { this.addLineString(g); }
  16882. else if (g instanceof Point) { this.addPoint(g); }
  16883. else if (g instanceof MultiPoint) { this.addCollection(g); }
  16884. else if (g instanceof MultiLineString) { this.addCollection(g); }
  16885. else if (g instanceof MultiPolygon) { this.addCollection(g); }
  16886. else if (g instanceof GeometryCollection) { this.addCollection(g); }
  16887. else { throw new Error(g.getClass().getName()) }
  16888. } else { return PlanarGraph$$1.prototype.add.apply(this, arguments) }
  16889. };
  16890. GeometryGraph.prototype.addCollection = function addCollection (gc) {
  16891. var this$1 = this;
  16892. for (var i = 0; i < gc.getNumGeometries(); i++) {
  16893. var g = gc.getGeometryN(i);
  16894. this$1.add(g);
  16895. }
  16896. };
  16897. GeometryGraph.prototype.locate = function locate (pt) {
  16898. if (hasInterface(this._parentGeom, Polygonal) && this._parentGeom.getNumGeometries() > 50) {
  16899. if (this._areaPtLocator === null) {
  16900. this._areaPtLocator = new IndexedPointInAreaLocator(this._parentGeom);
  16901. }
  16902. return this._areaPtLocator.locate(pt)
  16903. }
  16904. return this._ptLocator.locate(pt, this._parentGeom)
  16905. };
  16906. GeometryGraph.prototype.findEdge = function findEdge () {
  16907. if (arguments.length === 1) {
  16908. var line = arguments[0];
  16909. return this._lineEdgeMap.get(line)
  16910. } else { return PlanarGraph$$1.prototype.findEdge.apply(this, arguments) }
  16911. };
  16912. GeometryGraph.prototype.interfaces_ = function interfaces_ () {
  16913. return []
  16914. };
  16915. GeometryGraph.prototype.getClass = function getClass () {
  16916. return GeometryGraph
  16917. };
  16918. GeometryGraph.determineBoundary = function determineBoundary (boundaryNodeRule, boundaryCount) {
  16919. return boundaryNodeRule.isInBoundary(boundaryCount) ? Location.BOUNDARY : Location.INTERIOR
  16920. };
  16921. return GeometryGraph;
  16922. }(PlanarGraph));
  16923. var GeometryGraphOp = function GeometryGraphOp () {
  16924. this._li = new RobustLineIntersector();
  16925. this._resultPrecisionModel = null;
  16926. this._arg = null;
  16927. if (arguments.length === 1) {
  16928. var g0 = arguments[0];
  16929. this.setComputationPrecision(g0.getPrecisionModel());
  16930. this._arg = new Array(1).fill(null);
  16931. this._arg[0] = new GeometryGraph(0, g0);
  16932. } else if (arguments.length === 2) {
  16933. var g0$1 = arguments[0];
  16934. var g1 = arguments[1];
  16935. var boundaryNodeRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
  16936. if (g0$1.getPrecisionModel().compareTo(g1.getPrecisionModel()) >= 0) { this.setComputationPrecision(g0$1.getPrecisionModel()); } else { this.setComputationPrecision(g1.getPrecisionModel()); }
  16937. this._arg = new Array(2).fill(null);
  16938. this._arg[0] = new GeometryGraph(0, g0$1, boundaryNodeRule);
  16939. this._arg[1] = new GeometryGraph(1, g1, boundaryNodeRule);
  16940. } else if (arguments.length === 3) {
  16941. var g0$2 = arguments[0];
  16942. var g1$1 = arguments[1];
  16943. var boundaryNodeRule$1 = arguments[2];
  16944. if (g0$2.getPrecisionModel().compareTo(g1$1.getPrecisionModel()) >= 0) { this.setComputationPrecision(g0$2.getPrecisionModel()); } else { this.setComputationPrecision(g1$1.getPrecisionModel()); }
  16945. this._arg = new Array(2).fill(null);
  16946. this._arg[0] = new GeometryGraph(0, g0$2, boundaryNodeRule$1);
  16947. this._arg[1] = new GeometryGraph(1, g1$1, boundaryNodeRule$1);
  16948. }
  16949. };
  16950. GeometryGraphOp.prototype.getArgGeometry = function getArgGeometry (i) {
  16951. return this._arg[i].getGeometry()
  16952. };
  16953. GeometryGraphOp.prototype.setComputationPrecision = function setComputationPrecision (pm) {
  16954. this._resultPrecisionModel = pm;
  16955. this._li.setPrecisionModel(this._resultPrecisionModel);
  16956. };
  16957. GeometryGraphOp.prototype.interfaces_ = function interfaces_ () {
  16958. return []
  16959. };
  16960. GeometryGraphOp.prototype.getClass = function getClass () {
  16961. return GeometryGraphOp
  16962. };
  16963. // operation.geometrygraph
  16964. var GeometryMapper = function GeometryMapper () {};
  16965. GeometryMapper.prototype.interfaces_ = function interfaces_ () {
  16966. return []
  16967. };
  16968. GeometryMapper.prototype.getClass = function getClass () {
  16969. return GeometryMapper
  16970. };
  16971. GeometryMapper.map = function map () {
  16972. if (arguments[0] instanceof Geometry && hasInterface(arguments[1], GeometryMapper.MapOp)) {
  16973. var geom = arguments[0];
  16974. var op = arguments[1];
  16975. var mapped = new ArrayList();
  16976. for (var i = 0; i < geom.getNumGeometries(); i++) {
  16977. var g = op.map(geom.getGeometryN(i));
  16978. if (g !== null) { mapped.add(g); }
  16979. }
  16980. return geom.getFactory().buildGeometry(mapped)
  16981. } else if (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], GeometryMapper.MapOp)) {
  16982. var geoms = arguments[0];
  16983. var op$1 = arguments[1];
  16984. var mapped$1 = new ArrayList();
  16985. for (var i$1 = geoms.iterator(); i$1.hasNext();) {
  16986. var g$1 = i$1.next();
  16987. var gr = op$1.map(g$1);
  16988. if (gr !== null) { mapped$1.add(gr); }
  16989. }
  16990. return mapped$1
  16991. }
  16992. };
  16993. GeometryMapper.MapOp = function MapOp () {};
  16994. var OverlayOp = (function (GeometryGraphOp) {
  16995. function OverlayOp () {
  16996. var g0 = arguments[0];
  16997. var g1 = arguments[1];
  16998. GeometryGraphOp.call(this, g0, g1);
  16999. this._ptLocator = new PointLocator();
  17000. this._geomFact = null;
  17001. this._resultGeom = null;
  17002. this._graph = null;
  17003. this._edgeList = new EdgeList();
  17004. this._resultPolyList = new ArrayList();
  17005. this._resultLineList = new ArrayList();
  17006. this._resultPointList = new ArrayList();
  17007. this._graph = new PlanarGraph(new OverlayNodeFactory());
  17008. this._geomFact = g0.getFactory();
  17009. }
  17010. if ( GeometryGraphOp ) OverlayOp.__proto__ = GeometryGraphOp;
  17011. OverlayOp.prototype = Object.create( GeometryGraphOp && GeometryGraphOp.prototype );
  17012. OverlayOp.prototype.constructor = OverlayOp;
  17013. OverlayOp.prototype.insertUniqueEdge = function insertUniqueEdge (e) {
  17014. var existingEdge = this._edgeList.findEqualEdge(e);
  17015. if (existingEdge !== null) {
  17016. var existingLabel = existingEdge.getLabel();
  17017. var labelToMerge = e.getLabel();
  17018. if (!existingEdge.isPointwiseEqual(e)) {
  17019. labelToMerge = new Label(e.getLabel());
  17020. labelToMerge.flip();
  17021. }
  17022. var depth = existingEdge.getDepth();
  17023. if (depth.isNull()) {
  17024. depth.add(existingLabel);
  17025. }
  17026. depth.add(labelToMerge);
  17027. existingLabel.merge(labelToMerge);
  17028. } else {
  17029. this._edgeList.add(e);
  17030. }
  17031. };
  17032. OverlayOp.prototype.getGraph = function getGraph () {
  17033. return this._graph
  17034. };
  17035. OverlayOp.prototype.cancelDuplicateResultEdges = function cancelDuplicateResultEdges () {
  17036. for (var it = this._graph.getEdgeEnds().iterator(); it.hasNext();) {
  17037. var de = it.next();
  17038. var sym = de.getSym();
  17039. if (de.isInResult() && sym.isInResult()) {
  17040. de.setInResult(false);
  17041. sym.setInResult(false);
  17042. }
  17043. }
  17044. };
  17045. OverlayOp.prototype.isCoveredByLA = function isCoveredByLA (coord) {
  17046. if (this.isCovered(coord, this._resultLineList)) { return true }
  17047. if (this.isCovered(coord, this._resultPolyList)) { return true }
  17048. return false
  17049. };
  17050. OverlayOp.prototype.computeGeometry = function computeGeometry (resultPointList, resultLineList, resultPolyList, opcode) {
  17051. var geomList = new ArrayList();
  17052. geomList.addAll(resultPointList);
  17053. geomList.addAll(resultLineList);
  17054. geomList.addAll(resultPolyList);
  17055. if (geomList.isEmpty()) { return OverlayOp.createEmptyResult(opcode, this._arg[0].getGeometry(), this._arg[1].getGeometry(), this._geomFact) }
  17056. return this._geomFact.buildGeometry(geomList)
  17057. };
  17058. OverlayOp.prototype.mergeSymLabels = function mergeSymLabels () {
  17059. for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {
  17060. var node = nodeit.next();
  17061. node.getEdges().mergeSymLabels();
  17062. }
  17063. };
  17064. OverlayOp.prototype.isCovered = function isCovered (coord, geomList) {
  17065. var this$1 = this;
  17066. for (var it = geomList.iterator(); it.hasNext();) {
  17067. var geom = it.next();
  17068. var loc = this$1._ptLocator.locate(coord, geom);
  17069. if (loc !== Location.EXTERIOR) { return true }
  17070. }
  17071. return false
  17072. };
  17073. OverlayOp.prototype.replaceCollapsedEdges = function replaceCollapsedEdges () {
  17074. var newEdges = new ArrayList();
  17075. for (var it = this._edgeList.iterator(); it.hasNext();) {
  17076. var e = it.next();
  17077. if (e.isCollapsed()) {
  17078. it.remove();
  17079. newEdges.add(e.getCollapsedEdge());
  17080. }
  17081. }
  17082. this._edgeList.addAll(newEdges);
  17083. };
  17084. OverlayOp.prototype.updateNodeLabelling = function updateNodeLabelling () {
  17085. for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {
  17086. var node = nodeit.next();
  17087. var lbl = node.getEdges().getLabel();
  17088. node.getLabel().merge(lbl);
  17089. }
  17090. };
  17091. OverlayOp.prototype.getResultGeometry = function getResultGeometry (overlayOpCode) {
  17092. this.computeOverlay(overlayOpCode);
  17093. return this._resultGeom
  17094. };
  17095. OverlayOp.prototype.insertUniqueEdges = function insertUniqueEdges (edges) {
  17096. var this$1 = this;
  17097. for (var i = edges.iterator(); i.hasNext();) {
  17098. var e = i.next();
  17099. this$1.insertUniqueEdge(e);
  17100. }
  17101. };
  17102. OverlayOp.prototype.computeOverlay = function computeOverlay (opCode) {
  17103. this.copyPoints(0);
  17104. this.copyPoints(1);
  17105. this._arg[0].computeSelfNodes(this._li, false);
  17106. this._arg[1].computeSelfNodes(this._li, false);
  17107. this._arg[0].computeEdgeIntersections(this._arg[1], this._li, true);
  17108. var baseSplitEdges = new ArrayList();
  17109. this._arg[0].computeSplitEdges(baseSplitEdges);
  17110. this._arg[1].computeSplitEdges(baseSplitEdges);
  17111. // const splitEdges = baseSplitEdges
  17112. this.insertUniqueEdges(baseSplitEdges);
  17113. this.computeLabelsFromDepths();
  17114. this.replaceCollapsedEdges();
  17115. EdgeNodingValidator.checkValid(this._edgeList.getEdges());
  17116. this._graph.addEdges(this._edgeList.getEdges());
  17117. this.computeLabelling();
  17118. this.labelIncompleteNodes();
  17119. this.findResultAreaEdges(opCode);
  17120. this.cancelDuplicateResultEdges();
  17121. var polyBuilder = new PolygonBuilder(this._geomFact);
  17122. polyBuilder.add(this._graph);
  17123. this._resultPolyList = polyBuilder.getPolygons();
  17124. var lineBuilder = new LineBuilder(this, this._geomFact, this._ptLocator);
  17125. this._resultLineList = lineBuilder.build(opCode);
  17126. var pointBuilder = new PointBuilder(this, this._geomFact, this._ptLocator);
  17127. this._resultPointList = pointBuilder.build(opCode);
  17128. this._resultGeom = this.computeGeometry(this._resultPointList, this._resultLineList, this._resultPolyList, opCode);
  17129. };
  17130. OverlayOp.prototype.labelIncompleteNode = function labelIncompleteNode (n, targetIndex) {
  17131. var loc = this._ptLocator.locate(n.getCoordinate(), this._arg[targetIndex].getGeometry());
  17132. n.getLabel().setLocation(targetIndex, loc);
  17133. };
  17134. OverlayOp.prototype.copyPoints = function copyPoints (argIndex) {
  17135. var this$1 = this;
  17136. for (var i = this._arg[argIndex].getNodeIterator(); i.hasNext();) {
  17137. var graphNode = i.next();
  17138. var newNode = this$1._graph.addNode(graphNode.getCoordinate());
  17139. newNode.setLabel(argIndex, graphNode.getLabel().getLocation(argIndex));
  17140. }
  17141. };
  17142. OverlayOp.prototype.findResultAreaEdges = function findResultAreaEdges (opCode) {
  17143. for (var it = this._graph.getEdgeEnds().iterator(); it.hasNext();) {
  17144. var de = it.next();
  17145. var label = de.getLabel();
  17146. if (label.isArea() && !de.isInteriorAreaEdge() && OverlayOp.isResultOfOp(label.getLocation(0, Position.RIGHT), label.getLocation(1, Position.RIGHT), opCode)) {
  17147. de.setInResult(true);
  17148. }
  17149. }
  17150. };
  17151. OverlayOp.prototype.computeLabelsFromDepths = function computeLabelsFromDepths () {
  17152. for (var it = this._edgeList.iterator(); it.hasNext();) {
  17153. var e = it.next();
  17154. var lbl = e.getLabel();
  17155. var depth = e.getDepth();
  17156. if (!depth.isNull()) {
  17157. depth.normalize();
  17158. for (var i = 0; i < 2; i++) {
  17159. if (!lbl.isNull(i) && lbl.isArea() && !depth.isNull(i)) {
  17160. if (depth.getDelta(i) === 0) {
  17161. lbl.toLine(i);
  17162. } else {
  17163. Assert.isTrue(!depth.isNull(i, Position.LEFT), 'depth of LEFT side has not been initialized');
  17164. lbl.setLocation(i, Position.LEFT, depth.getLocation(i, Position.LEFT));
  17165. Assert.isTrue(!depth.isNull(i, Position.RIGHT), 'depth of RIGHT side has not been initialized');
  17166. lbl.setLocation(i, Position.RIGHT, depth.getLocation(i, Position.RIGHT));
  17167. }
  17168. }
  17169. }
  17170. }
  17171. }
  17172. };
  17173. OverlayOp.prototype.computeLabelling = function computeLabelling () {
  17174. var this$1 = this;
  17175. for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {
  17176. var node = nodeit.next();
  17177. node.getEdges().computeLabelling(this$1._arg);
  17178. }
  17179. this.mergeSymLabels();
  17180. this.updateNodeLabelling();
  17181. };
  17182. OverlayOp.prototype.labelIncompleteNodes = function labelIncompleteNodes () {
  17183. var this$1 = this;
  17184. // let nodeCount = 0
  17185. for (var ni = this._graph.getNodes().iterator(); ni.hasNext();) {
  17186. var n = ni.next();
  17187. var label = n.getLabel();
  17188. if (n.isIsolated()) {
  17189. // nodeCount++
  17190. if (label.isNull(0)) { this$1.labelIncompleteNode(n, 0); } else { this$1.labelIncompleteNode(n, 1); }
  17191. }
  17192. n.getEdges().updateLabelling(label);
  17193. }
  17194. };
  17195. OverlayOp.prototype.isCoveredByA = function isCoveredByA (coord) {
  17196. if (this.isCovered(coord, this._resultPolyList)) { return true }
  17197. return false
  17198. };
  17199. OverlayOp.prototype.interfaces_ = function interfaces_ () {
  17200. return []
  17201. };
  17202. OverlayOp.prototype.getClass = function getClass () {
  17203. return OverlayOp
  17204. };
  17205. return OverlayOp;
  17206. }(GeometryGraphOp));
  17207. OverlayOp.overlayOp = function (geom0, geom1, opCode) {
  17208. var gov = new OverlayOp(geom0, geom1);
  17209. var geomOv = gov.getResultGeometry(opCode);
  17210. return geomOv
  17211. };
  17212. OverlayOp.intersection = function (g, other) {
  17213. if (g.isEmpty() || other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.INTERSECTION, g, other, g.getFactory()) }
  17214. if (g.isGeometryCollection()) {
  17215. var g2 = other;
  17216. return GeometryCollectionMapper.map(g, {
  17217. interfaces_: function () {
  17218. return [GeometryMapper.MapOp]
  17219. },
  17220. map: function (g) {
  17221. return g.intersection(g2)
  17222. }
  17223. })
  17224. }
  17225. g.checkNotGeometryCollection(g);
  17226. g.checkNotGeometryCollection(other);
  17227. return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.INTERSECTION)
  17228. };
  17229. OverlayOp.symDifference = function (g, other) {
  17230. if (g.isEmpty() || other.isEmpty()) {
  17231. if (g.isEmpty() && other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.SYMDIFFERENCE, g, other, g.getFactory()) }
  17232. if (g.isEmpty()) { return other.copy() }
  17233. if (other.isEmpty()) { return g.copy() }
  17234. }
  17235. g.checkNotGeometryCollection(g);
  17236. g.checkNotGeometryCollection(other);
  17237. return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.SYMDIFFERENCE)
  17238. };
  17239. OverlayOp.resultDimension = function (opCode, g0, g1) {
  17240. var dim0 = g0.getDimension();
  17241. var dim1 = g1.getDimension();
  17242. var resultDimension = -1;
  17243. switch (opCode) {
  17244. case OverlayOp.INTERSECTION:
  17245. resultDimension = Math.min(dim0, dim1);
  17246. break
  17247. case OverlayOp.UNION:
  17248. resultDimension = Math.max(dim0, dim1);
  17249. break
  17250. case OverlayOp.DIFFERENCE:
  17251. resultDimension = dim0;
  17252. break
  17253. case OverlayOp.SYMDIFFERENCE:
  17254. resultDimension = Math.max(dim0, dim1);
  17255. break
  17256. default:
  17257. }
  17258. return resultDimension
  17259. };
  17260. OverlayOp.createEmptyResult = function (overlayOpCode, a, b, geomFact) {
  17261. var result = null;
  17262. switch (OverlayOp.resultDimension(overlayOpCode, a, b)) {
  17263. case -1:
  17264. result = geomFact.createGeometryCollection(new Array(0).fill(null));
  17265. break
  17266. case 0:
  17267. result = geomFact.createPoint();
  17268. break
  17269. case 1:
  17270. result = geomFact.createLineString();
  17271. break
  17272. case 2:
  17273. result = geomFact.createPolygon();
  17274. break
  17275. default:
  17276. }
  17277. return result
  17278. };
  17279. OverlayOp.difference = function (g, other) {
  17280. if (g.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.DIFFERENCE, g, other, g.getFactory()) }
  17281. if (other.isEmpty()) { return g.copy() }
  17282. g.checkNotGeometryCollection(g);
  17283. g.checkNotGeometryCollection(other);
  17284. return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.DIFFERENCE)
  17285. };
  17286. OverlayOp.isResultOfOp = function () {
  17287. if (arguments.length === 2) {
  17288. var label = arguments[0];
  17289. var opCode = arguments[1];
  17290. var loc0 = label.getLocation(0);
  17291. var loc1 = label.getLocation(1);
  17292. return OverlayOp.isResultOfOp(loc0, loc1, opCode)
  17293. } else if (arguments.length === 3) {
  17294. var loc0$1 = arguments[0];
  17295. var loc1$1 = arguments[1];
  17296. var overlayOpCode = arguments[2];
  17297. if (loc0$1 === Location.BOUNDARY) { loc0$1 = Location.INTERIOR; }
  17298. if (loc1$1 === Location.BOUNDARY) { loc1$1 = Location.INTERIOR; }
  17299. switch (overlayOpCode) {
  17300. case OverlayOp.INTERSECTION:
  17301. return loc0$1 === Location.INTERIOR && loc1$1 === Location.INTERIOR
  17302. case OverlayOp.UNION:
  17303. return loc0$1 === Location.INTERIOR || loc1$1 === Location.INTERIOR
  17304. case OverlayOp.DIFFERENCE:
  17305. return loc0$1 === Location.INTERIOR && loc1$1 !== Location.INTERIOR
  17306. case OverlayOp.SYMDIFFERENCE:
  17307. return (loc0$1 === Location.INTERIOR && loc1$1 !== Location.INTERIOR) || (loc0$1 !== Location.INTERIOR && loc1$1 === Location.INTERIOR)
  17308. default:
  17309. }
  17310. return false
  17311. }
  17312. };
  17313. OverlayOp.INTERSECTION = 1;
  17314. OverlayOp.UNION = 2;
  17315. OverlayOp.DIFFERENCE = 3;
  17316. OverlayOp.SYMDIFFERENCE = 4;
  17317. var FuzzyPointLocator = function FuzzyPointLocator () {
  17318. this._g = null;
  17319. this._boundaryDistanceTolerance = null;
  17320. this._linework = null;
  17321. this._ptLocator = new PointLocator();
  17322. this._seg = new LineSegment();
  17323. var g = arguments[0];
  17324. var boundaryDistanceTolerance = arguments[1];
  17325. this._g = g;
  17326. this._boundaryDistanceTolerance = boundaryDistanceTolerance;
  17327. this._linework = this.extractLinework(g);
  17328. };
  17329. FuzzyPointLocator.prototype.isWithinToleranceOfBoundary = function isWithinToleranceOfBoundary (pt) {
  17330. var this$1 = this;
  17331. for (var i = 0; i < this._linework.getNumGeometries(); i++) {
  17332. var line = this$1._linework.getGeometryN(i);
  17333. var seq = line.getCoordinateSequence();
  17334. for (var j = 0; j < seq.size() - 1; j++) {
  17335. seq.getCoordinate(j, this$1._seg.p0);
  17336. seq.getCoordinate(j + 1, this$1._seg.p1);
  17337. var dist = this$1._seg.distance(pt);
  17338. if (dist <= this$1._boundaryDistanceTolerance) { return true }
  17339. }
  17340. }
  17341. return false
  17342. };
  17343. FuzzyPointLocator.prototype.getLocation = function getLocation (pt) {
  17344. if (this.isWithinToleranceOfBoundary(pt)) { return Location.BOUNDARY }
  17345. return this._ptLocator.locate(pt, this._g)
  17346. };
  17347. FuzzyPointLocator.prototype.extractLinework = function extractLinework (g) {
  17348. var extracter = new PolygonalLineworkExtracter();
  17349. g.apply(extracter);
  17350. var linework = extracter.getLinework();
  17351. var lines = GeometryFactory.toLineStringArray(linework);
  17352. return g.getFactory().createMultiLineString(lines)
  17353. };
  17354. FuzzyPointLocator.prototype.interfaces_ = function interfaces_ () {
  17355. return []
  17356. };
  17357. FuzzyPointLocator.prototype.getClass = function getClass () {
  17358. return FuzzyPointLocator
  17359. };
  17360. var PolygonalLineworkExtracter = function PolygonalLineworkExtracter () {
  17361. this._linework = null;
  17362. this._linework = new ArrayList();
  17363. };
  17364. PolygonalLineworkExtracter.prototype.getLinework = function getLinework () {
  17365. return this._linework
  17366. };
  17367. PolygonalLineworkExtracter.prototype.filter = function filter (g) {
  17368. var this$1 = this;
  17369. if (g instanceof Polygon) {
  17370. var poly = g;
  17371. this._linework.add(poly.getExteriorRing());
  17372. for (var i = 0; i < poly.getNumInteriorRing(); i++) {
  17373. this$1._linework.add(poly.getInteriorRingN(i));
  17374. }
  17375. }
  17376. };
  17377. PolygonalLineworkExtracter.prototype.interfaces_ = function interfaces_ () {
  17378. return [GeometryFilter]
  17379. };
  17380. PolygonalLineworkExtracter.prototype.getClass = function getClass () {
  17381. return PolygonalLineworkExtracter
  17382. };
  17383. var OffsetPointGenerator = function OffsetPointGenerator () {
  17384. this._g = null;
  17385. this._doLeft = true;
  17386. this._doRight = true;
  17387. var g = arguments[0];
  17388. this._g = g;
  17389. };
  17390. OffsetPointGenerator.prototype.extractPoints = function extractPoints (line, offsetDistance, offsetPts) {
  17391. var this$1 = this;
  17392. var pts = line.getCoordinates();
  17393. for (var i = 0; i < pts.length - 1; i++) {
  17394. this$1.computeOffsetPoints(pts[i], pts[i + 1], offsetDistance, offsetPts);
  17395. }
  17396. };
  17397. OffsetPointGenerator.prototype.setSidesToGenerate = function setSidesToGenerate (doLeft, doRight) {
  17398. this._doLeft = doLeft;
  17399. this._doRight = doRight;
  17400. };
  17401. OffsetPointGenerator.prototype.getPoints = function getPoints (offsetDistance) {
  17402. var this$1 = this;
  17403. var offsetPts = new ArrayList();
  17404. var lines = LinearComponentExtracter.getLines(this._g);
  17405. for (var i = lines.iterator(); i.hasNext();) {
  17406. var line = i.next();
  17407. this$1.extractPoints(line, offsetDistance, offsetPts);
  17408. }
  17409. return offsetPts
  17410. };
  17411. OffsetPointGenerator.prototype.computeOffsetPoints = function computeOffsetPoints (p0, p1, offsetDistance, offsetPts) {
  17412. var dx = p1.x - p0.x;
  17413. var dy = p1.y - p0.y;
  17414. var len = Math.sqrt(dx * dx + dy * dy);
  17415. var ux = offsetDistance * dx / len;
  17416. var uy = offsetDistance * dy / len;
  17417. var midX = (p1.x + p0.x) / 2;
  17418. var midY = (p1.y + p0.y) / 2;
  17419. if (this._doLeft) {
  17420. var offsetLeft = new Coordinate(midX - uy, midY + ux);
  17421. offsetPts.add(offsetLeft);
  17422. }
  17423. if (this._doRight) {
  17424. var offsetRight = new Coordinate(midX + uy, midY - ux);
  17425. offsetPts.add(offsetRight);
  17426. }
  17427. };
  17428. OffsetPointGenerator.prototype.interfaces_ = function interfaces_ () {
  17429. return []
  17430. };
  17431. OffsetPointGenerator.prototype.getClass = function getClass () {
  17432. return OffsetPointGenerator
  17433. };
  17434. var OverlayResultValidator = function OverlayResultValidator () {
  17435. this._geom = null;
  17436. this._locFinder = null;
  17437. this._location = new Array(3).fill(null);
  17438. this._invalidLocation = null;
  17439. this._boundaryDistanceTolerance = OverlayResultValidator.TOLERANCE;
  17440. this._testCoords = new ArrayList();
  17441. var a = arguments[0];
  17442. var b = arguments[1];
  17443. var result = arguments[2];
  17444. this._boundaryDistanceTolerance = OverlayResultValidator.computeBoundaryDistanceTolerance(a, b);
  17445. this._geom = [a, b, result];
  17446. this._locFinder = [new FuzzyPointLocator(this._geom[0], this._boundaryDistanceTolerance), new FuzzyPointLocator(this._geom[1], this._boundaryDistanceTolerance), new FuzzyPointLocator(this._geom[2], this._boundaryDistanceTolerance)];
  17447. };
  17448. var staticAccessors$46 = { TOLERANCE: { configurable: true } };
  17449. OverlayResultValidator.prototype.reportResult = function reportResult (overlayOp, location, expectedInterior) {
  17450. 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]));
  17451. };
  17452. OverlayResultValidator.prototype.isValid = function isValid (overlayOp) {
  17453. this.addTestPts(this._geom[0]);
  17454. this.addTestPts(this._geom[1]);
  17455. var isValid = this.checkValid(overlayOp);
  17456. return isValid
  17457. };
  17458. OverlayResultValidator.prototype.checkValid = function checkValid () {
  17459. var this$1 = this;
  17460. if (arguments.length === 1) {
  17461. var overlayOp = arguments[0];
  17462. for (var i = 0; i < this._testCoords.size(); i++) {
  17463. var pt = this$1._testCoords.get(i);
  17464. if (!this$1.checkValid(overlayOp, pt)) {
  17465. this$1._invalidLocation = pt;
  17466. return false
  17467. }
  17468. }
  17469. return true
  17470. } else if (arguments.length === 2) {
  17471. var overlayOp$1 = arguments[0];
  17472. var pt$1 = arguments[1];
  17473. this._location[0] = this._locFinder[0].getLocation(pt$1);
  17474. this._location[1] = this._locFinder[1].getLocation(pt$1);
  17475. this._location[2] = this._locFinder[2].getLocation(pt$1);
  17476. if (OverlayResultValidator.hasLocation(this._location, Location.BOUNDARY)) { return true }
  17477. return this.isValidResult(overlayOp$1, this._location)
  17478. }
  17479. };
  17480. OverlayResultValidator.prototype.addTestPts = function addTestPts (g) {
  17481. var ptGen = new OffsetPointGenerator(g);
  17482. this._testCoords.addAll(ptGen.getPoints(5 * this._boundaryDistanceTolerance));
  17483. };
  17484. OverlayResultValidator.prototype.isValidResult = function isValidResult (overlayOp, location) {
  17485. var expectedInterior = OverlayOp.isResultOfOp(location[0], location[1], overlayOp);
  17486. var resultInInterior = location[2] === Location.INTERIOR;
  17487. var isValid = !(expectedInterior ^ resultInInterior);
  17488. if (!isValid) { this.reportResult(overlayOp, location, expectedInterior); }
  17489. return isValid
  17490. };
  17491. OverlayResultValidator.prototype.getInvalidLocation = function getInvalidLocation () {
  17492. return this._invalidLocation
  17493. };
  17494. OverlayResultValidator.prototype.interfaces_ = function interfaces_ () {
  17495. return []
  17496. };
  17497. OverlayResultValidator.prototype.getClass = function getClass () {
  17498. return OverlayResultValidator
  17499. };
  17500. OverlayResultValidator.hasLocation = function hasLocation (location, loc) {
  17501. for (var i = 0; i < 3; i++) {
  17502. if (location[i] === loc) { return true }
  17503. }
  17504. return false
  17505. };
  17506. OverlayResultValidator.computeBoundaryDistanceTolerance = function computeBoundaryDistanceTolerance (g0, g1) {
  17507. return Math.min(GeometrySnapper.computeSizeBasedSnapTolerance(g0), GeometrySnapper.computeSizeBasedSnapTolerance(g1))
  17508. };
  17509. OverlayResultValidator.isValid = function isValid (a, b, overlayOp, result) {
  17510. var validator = new OverlayResultValidator(a, b, result);
  17511. return validator.isValid(overlayOp)
  17512. };
  17513. staticAccessors$46.TOLERANCE.get = function () { return 0.000001 };
  17514. Object.defineProperties( OverlayResultValidator, staticAccessors$46 );
  17515. // operation.overlay
  17516. var GeometryCombiner = function GeometryCombiner (geoms) {
  17517. this._geomFactory = null;
  17518. this._skipEmpty = false;
  17519. this._inputGeoms = null;
  17520. this._geomFactory = GeometryCombiner.extractFactory(geoms);
  17521. this._inputGeoms = geoms;
  17522. };
  17523. GeometryCombiner.prototype.extractElements = function extractElements (geom, elems) {
  17524. var this$1 = this;
  17525. if (geom === null) { return null }
  17526. for (var i = 0; i < geom.getNumGeometries(); i++) {
  17527. var elemGeom = geom.getGeometryN(i);
  17528. if (this$1._skipEmpty && elemGeom.isEmpty()) { continue }
  17529. elems.add(elemGeom);
  17530. }
  17531. };
  17532. GeometryCombiner.prototype.combine = function combine () {
  17533. var this$1 = this;
  17534. var elems = new ArrayList();
  17535. for (var i = this._inputGeoms.iterator(); i.hasNext();) {
  17536. var g = i.next();
  17537. this$1.extractElements(g, elems);
  17538. }
  17539. if (elems.size() === 0) {
  17540. if (this._geomFactory !== null) {
  17541. return this._geomFactory.createGeometryCollection(null)
  17542. }
  17543. return null
  17544. }
  17545. return this._geomFactory.buildGeometry(elems)
  17546. };
  17547. GeometryCombiner.prototype.interfaces_ = function interfaces_ () {
  17548. return []
  17549. };
  17550. GeometryCombiner.prototype.getClass = function getClass () {
  17551. return GeometryCombiner
  17552. };
  17553. GeometryCombiner.combine = function combine () {
  17554. if (arguments.length === 1) {
  17555. var geoms = arguments[0];
  17556. var combiner = new GeometryCombiner(geoms);
  17557. return combiner.combine()
  17558. } else if (arguments.length === 2) {
  17559. var g0 = arguments[0];
  17560. var g1 = arguments[1];
  17561. var combiner$1 = new GeometryCombiner(GeometryCombiner.createList(g0, g1));
  17562. return combiner$1.combine()
  17563. } else if (arguments.length === 3) {
  17564. var g0$1 = arguments[0];
  17565. var g1$1 = arguments[1];
  17566. var g2 = arguments[2];
  17567. var combiner$2 = new GeometryCombiner(GeometryCombiner.createList(g0$1, g1$1, g2));
  17568. return combiner$2.combine()
  17569. }
  17570. };
  17571. GeometryCombiner.extractFactory = function extractFactory (geoms) {
  17572. if (geoms.isEmpty()) { return null }
  17573. return geoms.iterator().next().getFactory()
  17574. };
  17575. GeometryCombiner.createList = function createList () {
  17576. if (arguments.length === 2) {
  17577. var obj0 = arguments[0];
  17578. var obj1 = arguments[1];
  17579. var list = new ArrayList();
  17580. list.add(obj0);
  17581. list.add(obj1);
  17582. return list
  17583. } else if (arguments.length === 3) {
  17584. var obj0$1 = arguments[0];
  17585. var obj1$1 = arguments[1];
  17586. var obj2 = arguments[2];
  17587. var list$1 = new ArrayList();
  17588. list$1.add(obj0$1);
  17589. list$1.add(obj1$1);
  17590. list$1.add(obj2);
  17591. return list$1
  17592. }
  17593. };
  17594. var CascadedPolygonUnion = function CascadedPolygonUnion () {
  17595. this._inputPolys = null;
  17596. this._geomFactory = null;
  17597. var polys = arguments[0];
  17598. this._inputPolys = polys;
  17599. if (this._inputPolys === null) { this._inputPolys = new ArrayList(); }
  17600. };
  17601. var staticAccessors$47 = { STRTREE_NODE_CAPACITY: { configurable: true } };
  17602. CascadedPolygonUnion.prototype.reduceToGeometries = function reduceToGeometries (geomTree) {
  17603. var this$1 = this;
  17604. var geoms = new ArrayList();
  17605. for (var i = geomTree.iterator(); i.hasNext();) {
  17606. var o = i.next();
  17607. var geom = null;
  17608. if (hasInterface(o, List)) {
  17609. geom = this$1.unionTree(o);
  17610. } else if (o instanceof Geometry) {
  17611. geom = o;
  17612. }
  17613. geoms.add(geom);
  17614. }
  17615. return geoms
  17616. };
  17617. CascadedPolygonUnion.prototype.extractByEnvelope = function extractByEnvelope (env, geom, disjointGeoms) {
  17618. var intersectingGeoms = new ArrayList();
  17619. for (var i = 0; i < geom.getNumGeometries(); i++) {
  17620. var elem = geom.getGeometryN(i);
  17621. if (elem.getEnvelopeInternal().intersects(env)) { intersectingGeoms.add(elem); } else { disjointGeoms.add(elem); }
  17622. }
  17623. return this._geomFactory.buildGeometry(intersectingGeoms)
  17624. };
  17625. CascadedPolygonUnion.prototype.unionOptimized = function unionOptimized (g0, g1) {
  17626. var g0Env = g0.getEnvelopeInternal();
  17627. var g1Env = g1.getEnvelopeInternal();
  17628. if (!g0Env.intersects(g1Env)) {
  17629. var combo = GeometryCombiner.combine(g0, g1);
  17630. return combo
  17631. }
  17632. if (g0.getNumGeometries() <= 1 && g1.getNumGeometries() <= 1) { return this.unionActual(g0, g1) }
  17633. var commonEnv = g0Env.intersection(g1Env);
  17634. return this.unionUsingEnvelopeIntersection(g0, g1, commonEnv)
  17635. };
  17636. CascadedPolygonUnion.prototype.union = function union () {
  17637. if (this._inputPolys === null) { throw new Error('union() method cannot be called twice') }
  17638. if (this._inputPolys.isEmpty()) { return null }
  17639. this._geomFactory = this._inputPolys.iterator().next().getFactory();
  17640. var index = new STRtree(CascadedPolygonUnion.STRTREE_NODE_CAPACITY);
  17641. for (var i = this._inputPolys.iterator(); i.hasNext();) {
  17642. var item = i.next();
  17643. index.insert(item.getEnvelopeInternal(), item);
  17644. }
  17645. this._inputPolys = null;
  17646. var itemTree = index.itemsTree();
  17647. var unionAll = this.unionTree(itemTree);
  17648. return unionAll
  17649. };
  17650. CascadedPolygonUnion.prototype.binaryUnion = function binaryUnion () {
  17651. if (arguments.length === 1) {
  17652. var geoms = arguments[0];
  17653. return this.binaryUnion(geoms, 0, geoms.size())
  17654. } else if (arguments.length === 3) {
  17655. var geoms$1 = arguments[0];
  17656. var start = arguments[1];
  17657. var end = arguments[2];
  17658. if (end - start <= 1) {
  17659. var g0 = CascadedPolygonUnion.getGeometry(geoms$1, start);
  17660. return this.unionSafe(g0, null)
  17661. } else if (end - start === 2) {
  17662. return this.unionSafe(CascadedPolygonUnion.getGeometry(geoms$1, start), CascadedPolygonUnion.getGeometry(geoms$1, start + 1))
  17663. } else {
  17664. var mid = Math.trunc((end + start) / 2);
  17665. var g0$1 = this.binaryUnion(geoms$1, start, mid);
  17666. var g1 = this.binaryUnion(geoms$1, mid, end);
  17667. return this.unionSafe(g0$1, g1)
  17668. }
  17669. }
  17670. };
  17671. CascadedPolygonUnion.prototype.repeatedUnion = function repeatedUnion (geoms) {
  17672. var union = null;
  17673. for (var i = geoms.iterator(); i.hasNext();) {
  17674. var g = i.next();
  17675. if (union === null) { union = g.copy(); } else { union = union.union(g); }
  17676. }
  17677. return union
  17678. };
  17679. CascadedPolygonUnion.prototype.unionSafe = function unionSafe (g0, g1) {
  17680. if (g0 === null && g1 === null) { return null }
  17681. if (g0 === null) { return g1.copy() }
  17682. if (g1 === null) { return g0.copy() }
  17683. return this.unionOptimized(g0, g1)
  17684. };
  17685. CascadedPolygonUnion.prototype.unionActual = function unionActual (g0, g1) {
  17686. return CascadedPolygonUnion.restrictToPolygons(g0.union(g1))
  17687. };
  17688. CascadedPolygonUnion.prototype.unionTree = function unionTree (geomTree) {
  17689. var geoms = this.reduceToGeometries(geomTree);
  17690. var union = this.binaryUnion(geoms);
  17691. return union
  17692. };
  17693. CascadedPolygonUnion.prototype.unionUsingEnvelopeIntersection = function unionUsingEnvelopeIntersection (g0, g1, common) {
  17694. var disjointPolys = new ArrayList();
  17695. var g0Int = this.extractByEnvelope(common, g0, disjointPolys);
  17696. var g1Int = this.extractByEnvelope(common, g1, disjointPolys);
  17697. var union = this.unionActual(g0Int, g1Int);
  17698. disjointPolys.add(union);
  17699. var overallUnion = GeometryCombiner.combine(disjointPolys);
  17700. return overallUnion
  17701. };
  17702. CascadedPolygonUnion.prototype.bufferUnion = function bufferUnion () {
  17703. if (arguments.length === 1) {
  17704. var geoms = arguments[0];
  17705. var factory = geoms.get(0).getFactory();
  17706. var gColl = factory.buildGeometry(geoms);
  17707. var unionAll = gColl.buffer(0.0);
  17708. return unionAll
  17709. } else if (arguments.length === 2) {
  17710. var g0 = arguments[0];
  17711. var g1 = arguments[1];
  17712. var factory$1 = g0.getFactory();
  17713. var gColl$1 = factory$1.createGeometryCollection([g0, g1]);
  17714. var unionAll$1 = gColl$1.buffer(0.0);
  17715. return unionAll$1
  17716. }
  17717. };
  17718. CascadedPolygonUnion.prototype.interfaces_ = function interfaces_ () {
  17719. return []
  17720. };
  17721. CascadedPolygonUnion.prototype.getClass = function getClass () {
  17722. return CascadedPolygonUnion
  17723. };
  17724. CascadedPolygonUnion.restrictToPolygons = function restrictToPolygons (g) {
  17725. if (hasInterface(g, Polygonal)) {
  17726. return g
  17727. }
  17728. var polygons = PolygonExtracter.getPolygons(g);
  17729. if (polygons.size() === 1) { return polygons.get(0) }
  17730. return g.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons))
  17731. };
  17732. CascadedPolygonUnion.getGeometry = function getGeometry (list, index) {
  17733. if (index >= list.size()) { return null }
  17734. return list.get(index)
  17735. };
  17736. CascadedPolygonUnion.union = function union (polys) {
  17737. var op = new CascadedPolygonUnion(polys);
  17738. return op.union()
  17739. };
  17740. staticAccessors$47.STRTREE_NODE_CAPACITY.get = function () { return 4 };
  17741. Object.defineProperties( CascadedPolygonUnion, staticAccessors$47 );
  17742. var UnionOp = function UnionOp () {};
  17743. UnionOp.prototype.interfaces_ = function interfaces_ () {
  17744. return []
  17745. };
  17746. UnionOp.prototype.getClass = function getClass () {
  17747. return UnionOp
  17748. };
  17749. UnionOp.union = function union (g, other) {
  17750. if (g.isEmpty() || other.isEmpty()) {
  17751. if (g.isEmpty() && other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.UNION, g, other, g.getFactory()) }
  17752. if (g.isEmpty()) { return other.copy() }
  17753. if (other.isEmpty()) { return g.copy() }
  17754. }
  17755. g.checkNotGeometryCollection(g);
  17756. g.checkNotGeometryCollection(other);
  17757. return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.UNION)
  17758. };
  17759. // operation.union
  17760. // operation
  17761. /**
  17762. * Polyfill for IE support
  17763. */
  17764. exports.GeoJSONReader = GeoJSONReader;
  17765. exports.GeoJSONWriter = GeoJSONWriter;
  17766. exports.OverlayOp = OverlayOp;
  17767. exports.UnionOp = UnionOp;
  17768. exports.BufferOp = BufferOp;