createPolylineGeometry.js 685 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961
  1. /**
  2. * Cesium - https://github.com/AnalyticalGraphicsInc/cesium
  3. *
  4. * Copyright 2011-2016 Cesium Contributors
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Columbus View (Pat. Pend.)
  19. *
  20. * Portions licensed separately.
  21. * See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md for full licensing details.
  22. */
  23. (function () {
  24. /*global define*/
  25. define('Core/defined',[],function() {
  26. 'use strict';
  27. /**
  28. * @exports defined
  29. *
  30. * @param {Object} value The object.
  31. * @returns {Boolean} Returns true if the object is defined, returns false otherwise.
  32. *
  33. * @example
  34. * if (Cesium.defined(positions)) {
  35. * doSomething();
  36. * } else {
  37. * doSomethingElse();
  38. * }
  39. */
  40. function defined(value) {
  41. return value !== undefined && value !== null;
  42. }
  43. return defined;
  44. });
  45. /*global define*/
  46. define('Core/freezeObject',[
  47. './defined'
  48. ], function(
  49. defined) {
  50. 'use strict';
  51. /**
  52. * Freezes an object, using Object.freeze if available, otherwise returns
  53. * the object unchanged. This function should be used in setup code to prevent
  54. * errors from completely halting JavaScript execution in legacy browsers.
  55. *
  56. * @private
  57. *
  58. * @exports freezeObject
  59. */
  60. var freezeObject = Object.freeze;
  61. if (!defined(freezeObject)) {
  62. freezeObject = function(o) {
  63. return o;
  64. };
  65. }
  66. return freezeObject;
  67. });
  68. /*global define*/
  69. define('Core/defaultValue',[
  70. './freezeObject'
  71. ], function(
  72. freezeObject) {
  73. 'use strict';
  74. /**
  75. * Returns the first parameter if not undefined, otherwise the second parameter.
  76. * Useful for setting a default value for a parameter.
  77. *
  78. * @exports defaultValue
  79. *
  80. * @param {*} a
  81. * @param {*} b
  82. * @returns {*} Returns the first parameter if not undefined, otherwise the second parameter.
  83. *
  84. * @example
  85. * param = Cesium.defaultValue(param, 'default');
  86. */
  87. function defaultValue(a, b) {
  88. if (a !== undefined) {
  89. return a;
  90. }
  91. return b;
  92. }
  93. /**
  94. * A frozen empty object that can be used as the default value for options passed as
  95. * an object literal.
  96. */
  97. defaultValue.EMPTY_OBJECT = freezeObject({});
  98. return defaultValue;
  99. });
  100. /*global define*/
  101. define('Core/DeveloperError',[
  102. './defined'
  103. ], function(
  104. defined) {
  105. 'use strict';
  106. /**
  107. * Constructs an exception object that is thrown due to a developer error, e.g., invalid argument,
  108. * argument out of range, etc. This exception should only be thrown during development;
  109. * it usually indicates a bug in the calling code. This exception should never be
  110. * caught; instead the calling code should strive not to generate it.
  111. * <br /><br />
  112. * On the other hand, a {@link RuntimeError} indicates an exception that may
  113. * be thrown at runtime, e.g., out of memory, that the calling code should be prepared
  114. * to catch.
  115. *
  116. * @alias DeveloperError
  117. * @constructor
  118. * @extends Error
  119. *
  120. * @param {String} [message] The error message for this exception.
  121. *
  122. * @see RuntimeError
  123. */
  124. function DeveloperError(message) {
  125. /**
  126. * 'DeveloperError' indicating that this exception was thrown due to a developer error.
  127. * @type {String}
  128. * @readonly
  129. */
  130. this.name = 'DeveloperError';
  131. /**
  132. * The explanation for why this exception was thrown.
  133. * @type {String}
  134. * @readonly
  135. */
  136. this.message = message;
  137. //Browsers such as IE don't have a stack property until you actually throw the error.
  138. var stack;
  139. try {
  140. throw new Error();
  141. } catch (e) {
  142. stack = e.stack;
  143. }
  144. /**
  145. * The stack trace of this exception, if available.
  146. * @type {String}
  147. * @readonly
  148. */
  149. this.stack = stack;
  150. }
  151. if (defined(Object.create)) {
  152. DeveloperError.prototype = Object.create(Error.prototype);
  153. DeveloperError.prototype.constructor = DeveloperError;
  154. }
  155. DeveloperError.prototype.toString = function() {
  156. var str = this.name + ': ' + this.message;
  157. if (defined(this.stack)) {
  158. str += '\n' + this.stack.toString();
  159. }
  160. return str;
  161. };
  162. /**
  163. * @private
  164. */
  165. DeveloperError.throwInstantiationError = function() {
  166. throw new DeveloperError('This function defines an interface and should not be called directly.');
  167. };
  168. return DeveloperError;
  169. });
  170. /*global define*/
  171. define('Core/isArray',[
  172. './defined'
  173. ], function(
  174. defined) {
  175. 'use strict';
  176. /**
  177. * Tests an object to see if it is an array.
  178. * @exports isArray
  179. *
  180. * @param {Object} value The value to test.
  181. * @returns {Boolean} true if the value is an array, false otherwise.
  182. */
  183. var isArray = Array.isArray;
  184. if (!defined(isArray)) {
  185. isArray = function(value) {
  186. return Object.prototype.toString.call(value) === '[object Array]';
  187. };
  188. }
  189. return isArray;
  190. });
  191. /*global define*/
  192. define('Core/Check',[
  193. './defaultValue',
  194. './defined',
  195. './DeveloperError',
  196. './isArray'
  197. ], function(
  198. defaultValue,
  199. defined,
  200. DeveloperError,
  201. isArray) {
  202. 'use strict';
  203. /**
  204. * Contains functions for checking that supplied arguments are of a specified type
  205. * or meet specified conditions
  206. * @private
  207. */
  208. var Check = {};
  209. /**
  210. * Contains type checking functions, all using the typeof operator
  211. */
  212. Check.typeOf = {};
  213. /**
  214. * Contains functions for checking numeric conditions such as minimum and maximum values
  215. */
  216. Check.numeric = {};
  217. function getUndefinedErrorMessage(name) {
  218. return name + ' was required but undefined.';
  219. }
  220. function getFailedTypeErrorMessage(actual, expected, name) {
  221. return 'Expected ' + name + ' to be typeof ' + expected + ', got ' + actual;
  222. }
  223. /**
  224. * Throws if test is not defined
  225. *
  226. * @param {*} test The value that is to be checked
  227. * @param {String} name The name of the variable being tested
  228. * @exception {DeveloperError} test must be defined
  229. */
  230. Check.defined = function (test, name) {
  231. if (!defined(test)) {
  232. throw new DeveloperError(getUndefinedErrorMessage(name));
  233. }
  234. };
  235. /**
  236. * Throws if test is greater than maximum
  237. *
  238. * @param {Number} test The value to test
  239. * @param {Number} maximum The maximum allowed value
  240. * @exception {DeveloperError} test must not be greater than maximum
  241. * @exception {DeveloperError} Both test and maximum must be typeof 'number'
  242. */
  243. Check.numeric.maximum = function (test, maximum) {
  244. Check.typeOf.number(test);
  245. Check.typeOf.number(maximum);
  246. if (test > maximum) {
  247. throw new DeveloperError('Expected ' + test + ' to be at most ' + maximum);
  248. }
  249. };
  250. /**
  251. * Throws if test is less than minimum
  252. *
  253. * @param {Number} test The value to test
  254. * @param {Number} minimum The minimum allowed value
  255. * @exception {DeveloperError} test must not be less than mininum
  256. * @exception {DeveloperError} Both test and maximum must be typeof 'number'
  257. */
  258. Check.numeric.minimum = function (test, minimum) {
  259. Check.typeOf.number(test);
  260. Check.typeOf.number(minimum);
  261. if (test < minimum) {
  262. throw new DeveloperError('Expected ' + test + ' to be at least ' + minimum);
  263. }
  264. };
  265. /**
  266. * Throws if test is not typeof 'function'
  267. *
  268. * @param {*} test The value to test
  269. * @param {String} name The name of the variable being tested
  270. * @exception {DeveloperError} test must be typeof 'function'
  271. */
  272. Check.typeOf.function = function (test, name) {
  273. if (typeof test !== 'function') {
  274. throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'function', name));
  275. }
  276. };
  277. /**
  278. * Throws if test is not typeof 'string'
  279. *
  280. * @param {*} test The value to test
  281. * @param {String} name The name of the variable being tested
  282. * @exception {DeveloperError} test must be typeof 'string'
  283. */
  284. Check.typeOf.string = function (test, name) {
  285. if (typeof test !== 'string') {
  286. throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'string', name));
  287. }
  288. };
  289. /**
  290. * Throws if test is not typeof 'number'
  291. *
  292. * @param {*} test The value to test
  293. * @param {String} name The name of the variable being tested
  294. * @exception {DeveloperError} test must be typeof 'number'
  295. */
  296. Check.typeOf.number = function (test, name) {
  297. if (typeof test !== 'number') {
  298. throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'number', name));
  299. }
  300. };
  301. /**
  302. * Throws if test is not typeof 'object'
  303. *
  304. * @param {*} test The value to test
  305. * @param {String} name The name of the variable being tested
  306. * @exception {DeveloperError} test must be typeof 'object'
  307. */
  308. Check.typeOf.object = function (test, name) {
  309. if (typeof test !== 'object') {
  310. throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'object', name));
  311. }
  312. };
  313. /**
  314. * Throws if test is not typeof 'boolean'
  315. *
  316. * @param {*} test The value to test
  317. * @param {String} name The name of the variable being tested
  318. * @exception {DeveloperError} test must be typeof 'boolean'
  319. */
  320. Check.typeOf.boolean = function (test, name) {
  321. if (typeof test !== 'boolean') {
  322. throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'boolean', name));
  323. }
  324. };
  325. return Check;
  326. });
  327. /*
  328. I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
  329. so it's better encapsulated. Now you can have multiple random number generators
  330. and they won't stomp all over eachother's state.
  331. If you want to use this as a substitute for Math.random(), use the random()
  332. method like so:
  333. var m = new MersenneTwister();
  334. var randomNumber = m.random();
  335. You can also call the other genrand_{foo}() methods on the instance.
  336. If you want to use a specific seed in order to get a repeatable random
  337. sequence, pass an integer into the constructor:
  338. var m = new MersenneTwister(123);
  339. and that will always produce the same random sequence.
  340. Sean McCullough (banksean@gmail.com)
  341. */
  342. /*
  343. A C-program for MT19937, with initialization improved 2002/1/26.
  344. Coded by Takuji Nishimura and Makoto Matsumoto.
  345. Before using, initialize the state by using init_genrand(seed)
  346. or init_by_array(init_key, key_length).
  347. */
  348. /**
  349. @license
  350. mersenne-twister.js - https://gist.github.com/banksean/300494
  351. Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
  352. All rights reserved.
  353. Redistribution and use in source and binary forms, with or without
  354. modification, are permitted provided that the following conditions
  355. are met:
  356. 1. Redistributions of source code must retain the above copyright
  357. notice, this list of conditions and the following disclaimer.
  358. 2. Redistributions in binary form must reproduce the above copyright
  359. notice, this list of conditions and the following disclaimer in the
  360. documentation and/or other materials provided with the distribution.
  361. 3. The names of its contributors may not be used to endorse or promote
  362. products derived from this software without specific prior written
  363. permission.
  364. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  365. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  366. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  367. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  368. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  369. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  370. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  371. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  372. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  373. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  374. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  375. */
  376. /*
  377. Any feedback is very welcome.
  378. http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
  379. email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
  380. */
  381. define('ThirdParty/mersenne-twister',[],function() {
  382. var MersenneTwister = function(seed) {
  383. if (seed == undefined) {
  384. seed = new Date().getTime();
  385. }
  386. /* Period parameters */
  387. this.N = 624;
  388. this.M = 397;
  389. this.MATRIX_A = 0x9908b0df; /* constant vector a */
  390. this.UPPER_MASK = 0x80000000; /* most significant w-r bits */
  391. this.LOWER_MASK = 0x7fffffff; /* least significant r bits */
  392. this.mt = new Array(this.N); /* the array for the state vector */
  393. this.mti=this.N+1; /* mti==N+1 means mt[N] is not initialized */
  394. this.init_genrand(seed);
  395. }
  396. /* initializes mt[N] with a seed */
  397. MersenneTwister.prototype.init_genrand = function(s) {
  398. this.mt[0] = s >>> 0;
  399. for (this.mti=1; this.mti<this.N; this.mti++) {
  400. var s = this.mt[this.mti-1] ^ (this.mt[this.mti-1] >>> 30);
  401. this.mt[this.mti] = (((((s & 0xffff0000) >>> 16) * 1812433253) << 16) + (s & 0x0000ffff) * 1812433253)
  402. + this.mti;
  403. /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
  404. /* In the previous versions, MSBs of the seed affect */
  405. /* only MSBs of the array mt[]. */
  406. /* 2002/01/09 modified by Makoto Matsumoto */
  407. this.mt[this.mti] >>>= 0;
  408. /* for >32 bit machines */
  409. }
  410. }
  411. /* initialize by an array with array-length */
  412. /* init_key is the array for initializing keys */
  413. /* key_length is its length */
  414. /* slight change for C++, 2004/2/26 */
  415. //MersenneTwister.prototype.init_by_array = function(init_key, key_length) {
  416. // var i, j, k;
  417. // this.init_genrand(19650218);
  418. // i=1; j=0;
  419. // k = (this.N>key_length ? this.N : key_length);
  420. // for (; k; k--) {
  421. // var s = this.mt[i-1] ^ (this.mt[i-1] >>> 30)
  422. // this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1664525) << 16) + ((s & 0x0000ffff) * 1664525)))
  423. // + init_key[j] + j; /* non linear */
  424. // this.mt[i] >>>= 0; /* for WORDSIZE > 32 machines */
  425. // i++; j++;
  426. // if (i>=this.N) { this.mt[0] = this.mt[this.N-1]; i=1; }
  427. // if (j>=key_length) j=0;
  428. // }
  429. // for (k=this.N-1; k; k--) {
  430. // var s = this.mt[i-1] ^ (this.mt[i-1] >>> 30);
  431. // this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1566083941) << 16) + (s & 0x0000ffff) * 1566083941))
  432. // - i; /* non linear */
  433. // this.mt[i] >>>= 0; /* for WORDSIZE > 32 machines */
  434. // i++;
  435. // if (i>=this.N) { this.mt[0] = this.mt[this.N-1]; i=1; }
  436. // }
  437. //
  438. // this.mt[0] = 0x80000000; /* MSB is 1; assuring non-zero initial array */
  439. //}
  440. /* generates a random number on [0,0xffffffff]-interval */
  441. MersenneTwister.prototype.genrand_int32 = function() {
  442. var y;
  443. var mag01 = new Array(0x0, this.MATRIX_A);
  444. /* mag01[x] = x * MATRIX_A for x=0,1 */
  445. if (this.mti >= this.N) { /* generate N words at one time */
  446. var kk;
  447. if (this.mti == this.N+1) /* if init_genrand() has not been called, */
  448. this.init_genrand(5489); /* a default initial seed is used */
  449. for (kk=0;kk<this.N-this.M;kk++) {
  450. y = (this.mt[kk]&this.UPPER_MASK)|(this.mt[kk+1]&this.LOWER_MASK);
  451. this.mt[kk] = this.mt[kk+this.M] ^ (y >>> 1) ^ mag01[y & 0x1];
  452. }
  453. for (;kk<this.N-1;kk++) {
  454. y = (this.mt[kk]&this.UPPER_MASK)|(this.mt[kk+1]&this.LOWER_MASK);
  455. this.mt[kk] = this.mt[kk+(this.M-this.N)] ^ (y >>> 1) ^ mag01[y & 0x1];
  456. }
  457. y = (this.mt[this.N-1]&this.UPPER_MASK)|(this.mt[0]&this.LOWER_MASK);
  458. this.mt[this.N-1] = this.mt[this.M-1] ^ (y >>> 1) ^ mag01[y & 0x1];
  459. this.mti = 0;
  460. }
  461. y = this.mt[this.mti++];
  462. /* Tempering */
  463. y ^= (y >>> 11);
  464. y ^= (y << 7) & 0x9d2c5680;
  465. y ^= (y << 15) & 0xefc60000;
  466. y ^= (y >>> 18);
  467. return y >>> 0;
  468. }
  469. /* generates a random number on [0,0x7fffffff]-interval */
  470. //MersenneTwister.prototype.genrand_int31 = function() {
  471. // return (this.genrand_int32()>>>1);
  472. //}
  473. /* generates a random number on [0,1]-real-interval */
  474. //MersenneTwister.prototype.genrand_real1 = function() {
  475. // return this.genrand_int32()*(1.0/4294967295.0);
  476. // /* divided by 2^32-1 */
  477. //}
  478. /* generates a random number on [0,1)-real-interval */
  479. MersenneTwister.prototype.random = function() {
  480. return this.genrand_int32()*(1.0/4294967296.0);
  481. /* divided by 2^32 */
  482. }
  483. /* generates a random number on (0,1)-real-interval */
  484. //MersenneTwister.prototype.genrand_real3 = function() {
  485. // return (this.genrand_int32() + 0.5)*(1.0/4294967296.0);
  486. // /* divided by 2^32 */
  487. //}
  488. /* generates a random number on [0,1) with 53-bit resolution*/
  489. //MersenneTwister.prototype.genrand_res53 = function() {
  490. // var a=this.genrand_int32()>>>5, b=this.genrand_int32()>>>6;
  491. // return(a*67108864.0+b)*(1.0/9007199254740992.0);
  492. //}
  493. /* These real versions are due to Isaku Wada, 2002/01/09 added */
  494. return MersenneTwister;
  495. });
  496. /*global define*/
  497. define('Core/Math',[
  498. '../ThirdParty/mersenne-twister',
  499. './defaultValue',
  500. './defined',
  501. './DeveloperError'
  502. ], function(
  503. MersenneTwister,
  504. defaultValue,
  505. defined,
  506. DeveloperError) {
  507. 'use strict';
  508. /**
  509. * Math functions.
  510. *
  511. * @exports CesiumMath
  512. */
  513. var CesiumMath = {};
  514. /**
  515. * 0.1
  516. * @type {Number}
  517. * @constant
  518. */
  519. CesiumMath.EPSILON1 = 0.1;
  520. /**
  521. * 0.01
  522. * @type {Number}
  523. * @constant
  524. */
  525. CesiumMath.EPSILON2 = 0.01;
  526. /**
  527. * 0.001
  528. * @type {Number}
  529. * @constant
  530. */
  531. CesiumMath.EPSILON3 = 0.001;
  532. /**
  533. * 0.0001
  534. * @type {Number}
  535. * @constant
  536. */
  537. CesiumMath.EPSILON4 = 0.0001;
  538. /**
  539. * 0.00001
  540. * @type {Number}
  541. * @constant
  542. */
  543. CesiumMath.EPSILON5 = 0.00001;
  544. /**
  545. * 0.000001
  546. * @type {Number}
  547. * @constant
  548. */
  549. CesiumMath.EPSILON6 = 0.000001;
  550. /**
  551. * 0.0000001
  552. * @type {Number}
  553. * @constant
  554. */
  555. CesiumMath.EPSILON7 = 0.0000001;
  556. /**
  557. * 0.00000001
  558. * @type {Number}
  559. * @constant
  560. */
  561. CesiumMath.EPSILON8 = 0.00000001;
  562. /**
  563. * 0.000000001
  564. * @type {Number}
  565. * @constant
  566. */
  567. CesiumMath.EPSILON9 = 0.000000001;
  568. /**
  569. * 0.0000000001
  570. * @type {Number}
  571. * @constant
  572. */
  573. CesiumMath.EPSILON10 = 0.0000000001;
  574. /**
  575. * 0.00000000001
  576. * @type {Number}
  577. * @constant
  578. */
  579. CesiumMath.EPSILON11 = 0.00000000001;
  580. /**
  581. * 0.000000000001
  582. * @type {Number}
  583. * @constant
  584. */
  585. CesiumMath.EPSILON12 = 0.000000000001;
  586. /**
  587. * 0.0000000000001
  588. * @type {Number}
  589. * @constant
  590. */
  591. CesiumMath.EPSILON13 = 0.0000000000001;
  592. /**
  593. * 0.00000000000001
  594. * @type {Number}
  595. * @constant
  596. */
  597. CesiumMath.EPSILON14 = 0.00000000000001;
  598. /**
  599. * 0.000000000000001
  600. * @type {Number}
  601. * @constant
  602. */
  603. CesiumMath.EPSILON15 = 0.000000000000001;
  604. /**
  605. * 0.0000000000000001
  606. * @type {Number}
  607. * @constant
  608. */
  609. CesiumMath.EPSILON16 = 0.0000000000000001;
  610. /**
  611. * 0.00000000000000001
  612. * @type {Number}
  613. * @constant
  614. */
  615. CesiumMath.EPSILON17 = 0.00000000000000001;
  616. /**
  617. * 0.000000000000000001
  618. * @type {Number}
  619. * @constant
  620. */
  621. CesiumMath.EPSILON18 = 0.000000000000000001;
  622. /**
  623. * 0.0000000000000000001
  624. * @type {Number}
  625. * @constant
  626. */
  627. CesiumMath.EPSILON19 = 0.0000000000000000001;
  628. /**
  629. * 0.00000000000000000001
  630. * @type {Number}
  631. * @constant
  632. */
  633. CesiumMath.EPSILON20 = 0.00000000000000000001;
  634. /**
  635. * 3.986004418e14
  636. * @type {Number}
  637. * @constant
  638. */
  639. CesiumMath.GRAVITATIONALPARAMETER = 3.986004418e14;
  640. /**
  641. * Radius of the sun in meters: 6.955e8
  642. * @type {Number}
  643. * @constant
  644. */
  645. CesiumMath.SOLAR_RADIUS = 6.955e8;
  646. /**
  647. * The mean radius of the moon, according to the "Report of the IAU/IAG Working Group on
  648. * Cartographic Coordinates and Rotational Elements of the Planets and satellites: 2000",
  649. * Celestial Mechanics 82: 83-110, 2002.
  650. * @type {Number}
  651. * @constant
  652. */
  653. CesiumMath.LUNAR_RADIUS = 1737400.0;
  654. /**
  655. * 64 * 1024
  656. * @type {Number}
  657. * @constant
  658. */
  659. CesiumMath.SIXTY_FOUR_KILOBYTES = 64 * 1024;
  660. /**
  661. * Returns the sign of the value; 1 if the value is positive, -1 if the value is
  662. * negative, or 0 if the value is 0.
  663. *
  664. * @param {Number} value The value to return the sign of.
  665. * @returns {Number} The sign of value.
  666. */
  667. CesiumMath.sign = function(value) {
  668. if (value > 0) {
  669. return 1;
  670. }
  671. if (value < 0) {
  672. return -1;
  673. }
  674. return 0;
  675. };
  676. /**
  677. * Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative.
  678. * This is similar to {@link CesiumMath#sign} except that returns 1.0 instead of
  679. * 0.0 when the input value is 0.0.
  680. * @param {Number} value The value to return the sign of.
  681. * @returns {Number} The sign of value.
  682. */
  683. CesiumMath.signNotZero = function(value) {
  684. return value < 0.0 ? -1.0 : 1.0;
  685. };
  686. /**
  687. * Converts a scalar value in the range [-1.0, 1.0] to a SNORM in the range [0, rangeMax]
  688. * @param {Number} value The scalar value in the range [-1.0, 1.0]
  689. * @param {Number} [rangeMax=255] The maximum value in the mapped range, 255 by default.
  690. * @returns {Number} A SNORM value, where 0 maps to -1.0 and rangeMax maps to 1.0.
  691. *
  692. * @see CesiumMath.fromSNorm
  693. */
  694. CesiumMath.toSNorm = function(value, rangeMax) {
  695. rangeMax = defaultValue(rangeMax, 255);
  696. return Math.round((CesiumMath.clamp(value, -1.0, 1.0) * 0.5 + 0.5) * rangeMax);
  697. };
  698. /**
  699. * Converts a SNORM value in the range [0, rangeMax] to a scalar in the range [-1.0, 1.0].
  700. * @param {Number} value SNORM value in the range [0, 255]
  701. * @param {Number} [rangeMax=255] The maximum value in the SNORM range, 255 by default.
  702. * @returns {Number} Scalar in the range [-1.0, 1.0].
  703. *
  704. * @see CesiumMath.toSNorm
  705. */
  706. CesiumMath.fromSNorm = function(value, rangeMax) {
  707. rangeMax = defaultValue(rangeMax, 255);
  708. return CesiumMath.clamp(value, 0.0, rangeMax) / rangeMax * 2.0 - 1.0;
  709. };
  710. /**
  711. * Returns the hyperbolic sine of a number.
  712. * The hyperbolic sine of <em>value</em> is defined to be
  713. * (<em>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></em>)/2.0
  714. * where <i>e</i> is Euler's number, approximately 2.71828183.
  715. *
  716. * <p>Special cases:
  717. * <ul>
  718. * <li>If the argument is NaN, then the result is NaN.</li>
  719. *
  720. * <li>If the argument is infinite, then the result is an infinity
  721. * with the same sign as the argument.</li>
  722. *
  723. * <li>If the argument is zero, then the result is a zero with the
  724. * same sign as the argument.</li>
  725. * </ul>
  726. *</p>
  727. *
  728. * @param {Number} value The number whose hyperbolic sine is to be returned.
  729. * @returns {Number} The hyperbolic sine of <code>value</code>.
  730. */
  731. CesiumMath.sinh = function(value) {
  732. var part1 = Math.pow(Math.E, value);
  733. var part2 = Math.pow(Math.E, -1.0 * value);
  734. return (part1 - part2) * 0.5;
  735. };
  736. /**
  737. * Returns the hyperbolic cosine of a number.
  738. * The hyperbolic cosine of <strong>value</strong> is defined to be
  739. * (<em>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></em>)/2.0
  740. * where <i>e</i> is Euler's number, approximately 2.71828183.
  741. *
  742. * <p>Special cases:
  743. * <ul>
  744. * <li>If the argument is NaN, then the result is NaN.</li>
  745. *
  746. * <li>If the argument is infinite, then the result is positive infinity.</li>
  747. *
  748. * <li>If the argument is zero, then the result is 1.0.</li>
  749. * </ul>
  750. *</p>
  751. *
  752. * @param {Number} value The number whose hyperbolic cosine is to be returned.
  753. * @returns {Number} The hyperbolic cosine of <code>value</code>.
  754. */
  755. CesiumMath.cosh = function(value) {
  756. var part1 = Math.pow(Math.E, value);
  757. var part2 = Math.pow(Math.E, -1.0 * value);
  758. return (part1 + part2) * 0.5;
  759. };
  760. /**
  761. * Computes the linear interpolation of two values.
  762. *
  763. * @param {Number} p The start value to interpolate.
  764. * @param {Number} q The end value to interpolate.
  765. * @param {Number} time The time of interpolation generally in the range <code>[0.0, 1.0]</code>.
  766. * @returns {Number} The linearly interpolated value.
  767. *
  768. * @example
  769. * var n = Cesium.Math.lerp(0.0, 2.0, 0.5); // returns 1.0
  770. */
  771. CesiumMath.lerp = function(p, q, time) {
  772. return ((1.0 - time) * p) + (time * q);
  773. };
  774. /**
  775. * pi
  776. *
  777. * @type {Number}
  778. * @constant
  779. */
  780. CesiumMath.PI = Math.PI;
  781. /**
  782. * 1/pi
  783. *
  784. * @type {Number}
  785. * @constant
  786. */
  787. CesiumMath.ONE_OVER_PI = 1.0 / Math.PI;
  788. /**
  789. * pi/2
  790. *
  791. * @type {Number}
  792. * @constant
  793. */
  794. CesiumMath.PI_OVER_TWO = Math.PI * 0.5;
  795. /**
  796. * pi/3
  797. *
  798. * @type {Number}
  799. * @constant
  800. */
  801. CesiumMath.PI_OVER_THREE = Math.PI / 3.0;
  802. /**
  803. * pi/4
  804. *
  805. * @type {Number}
  806. * @constant
  807. */
  808. CesiumMath.PI_OVER_FOUR = Math.PI / 4.0;
  809. /**
  810. * pi/6
  811. *
  812. * @type {Number}
  813. * @constant
  814. */
  815. CesiumMath.PI_OVER_SIX = Math.PI / 6.0;
  816. /**
  817. * 3pi/2
  818. *
  819. * @type {Number}
  820. * @constant
  821. */
  822. CesiumMath.THREE_PI_OVER_TWO = (3.0 * Math.PI) * 0.5;
  823. /**
  824. * 2pi
  825. *
  826. * @type {Number}
  827. * @constant
  828. */
  829. CesiumMath.TWO_PI = 2.0 * Math.PI;
  830. /**
  831. * 1/2pi
  832. *
  833. * @type {Number}
  834. * @constant
  835. */
  836. CesiumMath.ONE_OVER_TWO_PI = 1.0 / (2.0 * Math.PI);
  837. /**
  838. * The number of radians in a degree.
  839. *
  840. * @type {Number}
  841. * @constant
  842. * @default Math.PI / 180.0
  843. */
  844. CesiumMath.RADIANS_PER_DEGREE = Math.PI / 180.0;
  845. /**
  846. * The number of degrees in a radian.
  847. *
  848. * @type {Number}
  849. * @constant
  850. * @default 180.0 / Math.PI
  851. */
  852. CesiumMath.DEGREES_PER_RADIAN = 180.0 / Math.PI;
  853. /**
  854. * The number of radians in an arc second.
  855. *
  856. * @type {Number}
  857. * @constant
  858. * @default {@link CesiumMath.RADIANS_PER_DEGREE} / 3600.0
  859. */
  860. CesiumMath.RADIANS_PER_ARCSECOND = CesiumMath.RADIANS_PER_DEGREE / 3600.0;
  861. /**
  862. * Converts degrees to radians.
  863. * @param {Number} degrees The angle to convert in degrees.
  864. * @returns {Number} The corresponding angle in radians.
  865. */
  866. CesiumMath.toRadians = function(degrees) {
  867. if (!defined(degrees)) {
  868. throw new DeveloperError('degrees is required.');
  869. }
  870. return degrees * CesiumMath.RADIANS_PER_DEGREE;
  871. };
  872. /**
  873. * Converts radians to degrees.
  874. * @param {Number} radians The angle to convert in radians.
  875. * @returns {Number} The corresponding angle in degrees.
  876. */
  877. CesiumMath.toDegrees = function(radians) {
  878. if (!defined(radians)) {
  879. throw new DeveloperError('radians is required.');
  880. }
  881. return radians * CesiumMath.DEGREES_PER_RADIAN;
  882. };
  883. /**
  884. * Converts a longitude value, in radians, to the range [<code>-Math.PI</code>, <code>Math.PI</code>).
  885. *
  886. * @param {Number} angle The longitude value, in radians, to convert to the range [<code>-Math.PI</code>, <code>Math.PI</code>).
  887. * @returns {Number} The equivalent longitude value in the range [<code>-Math.PI</code>, <code>Math.PI</code>).
  888. *
  889. * @example
  890. * // Convert 270 degrees to -90 degrees longitude
  891. * var longitude = Cesium.Math.convertLongitudeRange(Cesium.Math.toRadians(270.0));
  892. */
  893. CesiumMath.convertLongitudeRange = function(angle) {
  894. if (!defined(angle)) {
  895. throw new DeveloperError('angle is required.');
  896. }
  897. var twoPi = CesiumMath.TWO_PI;
  898. var simplified = angle - Math.floor(angle / twoPi) * twoPi;
  899. if (simplified < -Math.PI) {
  900. return simplified + twoPi;
  901. }
  902. if (simplified >= Math.PI) {
  903. return simplified - twoPi;
  904. }
  905. return simplified;
  906. };
  907. /**
  908. * Convenience function that clamps a latitude value, in radians, to the range [<code>-Math.PI/2</code>, <code>Math.PI/2</code>).
  909. * Useful for sanitizing data before use in objects requiring correct range.
  910. *
  911. * @param {Number} angle The latitude value, in radians, to clamp to the range [<code>-Math.PI/2</code>, <code>Math.PI/2</code>).
  912. * @returns {Number} The latitude value clamped to the range [<code>-Math.PI/2</code>, <code>Math.PI/2</code>).
  913. *
  914. * @example
  915. * // Clamp 108 degrees latitude to 90 degrees latitude
  916. * var latitude = Cesium.Math.clampToLatitudeRange(Cesium.Math.toRadians(108.0));
  917. */
  918. CesiumMath.clampToLatitudeRange = function(angle) {
  919. if (!defined(angle)) {
  920. throw new DeveloperError('angle is required.');
  921. }
  922. return CesiumMath.clamp(angle, -1*CesiumMath.PI_OVER_TWO, CesiumMath.PI_OVER_TWO);
  923. };
  924. /**
  925. * Produces an angle in the range -Pi <= angle <= Pi which is equivalent to the provided angle.
  926. *
  927. * @param {Number} angle in radians
  928. * @returns {Number} The angle in the range [<code>-CesiumMath.PI</code>, <code>CesiumMath.PI</code>].
  929. */
  930. CesiumMath.negativePiToPi = function(x) {
  931. if (!defined(x)) {
  932. throw new DeveloperError('x is required.');
  933. }
  934. return CesiumMath.zeroToTwoPi(x + CesiumMath.PI) - CesiumMath.PI;
  935. };
  936. /**
  937. * Produces an angle in the range 0 <= angle <= 2Pi which is equivalent to the provided angle.
  938. *
  939. * @param {Number} angle in radians
  940. * @returns {Number} The angle in the range [0, <code>CesiumMath.TWO_PI</code>].
  941. */
  942. CesiumMath.zeroToTwoPi = function(x) {
  943. if (!defined(x)) {
  944. throw new DeveloperError('x is required.');
  945. }
  946. var mod = CesiumMath.mod(x, CesiumMath.TWO_PI);
  947. if (Math.abs(mod) < CesiumMath.EPSILON14 && Math.abs(x) > CesiumMath.EPSILON14) {
  948. return CesiumMath.TWO_PI;
  949. }
  950. return mod;
  951. };
  952. /**
  953. * The modulo operation that also works for negative dividends.
  954. *
  955. * @param {Number} m The dividend.
  956. * @param {Number} n The divisor.
  957. * @returns {Number} The remainder.
  958. */
  959. CesiumMath.mod = function(m, n) {
  960. if (!defined(m)) {
  961. throw new DeveloperError('m is required.');
  962. }
  963. if (!defined(n)) {
  964. throw new DeveloperError('n is required.');
  965. }
  966. return ((m % n) + n) % n;
  967. };
  968. /**
  969. * Determines if two values are equal using an absolute or relative tolerance test. This is useful
  970. * to avoid problems due to roundoff error when comparing floating-point values directly. The values are
  971. * first compared using an absolute tolerance test. If that fails, a relative tolerance test is performed.
  972. * Use this test if you are unsure of the magnitudes of left and right.
  973. *
  974. * @param {Number} left The first value to compare.
  975. * @param {Number} right The other value to compare.
  976. * @param {Number} relativeEpsilon The maximum inclusive delta between <code>left</code> and <code>right</code> for the relative tolerance test.
  977. * @param {Number} [absoluteEpsilon=relativeEpsilon] The maximum inclusive delta between <code>left</code> and <code>right</code> for the absolute tolerance test.
  978. * @returns {Boolean} <code>true</code> if the values are equal within the epsilon; otherwise, <code>false</code>.
  979. *
  980. * @example
  981. * var a = Cesium.Math.equalsEpsilon(0.0, 0.01, Cesium.Math.EPSILON2); // true
  982. * var b = Cesium.Math.equalsEpsilon(0.0, 0.1, Cesium.Math.EPSILON2); // false
  983. * var c = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON7); // true
  984. * var d = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON9); // false
  985. */
  986. CesiumMath.equalsEpsilon = function(left, right, relativeEpsilon, absoluteEpsilon) {
  987. if (!defined(left)) {
  988. throw new DeveloperError('left is required.');
  989. }
  990. if (!defined(right)) {
  991. throw new DeveloperError('right is required.');
  992. }
  993. if (!defined(relativeEpsilon)) {
  994. throw new DeveloperError('relativeEpsilon is required.');
  995. }
  996. absoluteEpsilon = defaultValue(absoluteEpsilon, relativeEpsilon);
  997. var absDiff = Math.abs(left - right);
  998. return absDiff <= absoluteEpsilon || absDiff <= relativeEpsilon * Math.max(Math.abs(left), Math.abs(right));
  999. };
  1000. var factorials = [1];
  1001. /**
  1002. * Computes the factorial of the provided number.
  1003. *
  1004. * @param {Number} n The number whose factorial is to be computed.
  1005. * @returns {Number} The factorial of the provided number or undefined if the number is less than 0.
  1006. *
  1007. * @exception {DeveloperError} A number greater than or equal to 0 is required.
  1008. *
  1009. *
  1010. * @example
  1011. * //Compute 7!, which is equal to 5040
  1012. * var computedFactorial = Cesium.Math.factorial(7);
  1013. *
  1014. * @see {@link http://en.wikipedia.org/wiki/Factorial|Factorial on Wikipedia}
  1015. */
  1016. CesiumMath.factorial = function(n) {
  1017. if (typeof n !== 'number' || n < 0) {
  1018. throw new DeveloperError('A number greater than or equal to 0 is required.');
  1019. }
  1020. var length = factorials.length;
  1021. if (n >= length) {
  1022. var sum = factorials[length - 1];
  1023. for (var i = length; i <= n; i++) {
  1024. factorials.push(sum * i);
  1025. }
  1026. }
  1027. return factorials[n];
  1028. };
  1029. /**
  1030. * Increments a number with a wrapping to a minimum value if the number exceeds the maximum value.
  1031. *
  1032. * @param {Number} [n] The number to be incremented.
  1033. * @param {Number} [maximumValue] The maximum incremented value before rolling over to the minimum value.
  1034. * @param {Number} [minimumValue=0.0] The number reset to after the maximum value has been exceeded.
  1035. * @returns {Number} The incremented number.
  1036. *
  1037. * @exception {DeveloperError} Maximum value must be greater than minimum value.
  1038. *
  1039. * @example
  1040. * var n = Cesium.Math.incrementWrap(5, 10, 0); // returns 6
  1041. * var n = Cesium.Math.incrementWrap(10, 10, 0); // returns 0
  1042. */
  1043. CesiumMath.incrementWrap = function(n, maximumValue, minimumValue) {
  1044. minimumValue = defaultValue(minimumValue, 0.0);
  1045. if (!defined(n)) {
  1046. throw new DeveloperError('n is required.');
  1047. }
  1048. if (maximumValue <= minimumValue) {
  1049. throw new DeveloperError('maximumValue must be greater than minimumValue.');
  1050. }
  1051. ++n;
  1052. if (n > maximumValue) {
  1053. n = minimumValue;
  1054. }
  1055. return n;
  1056. };
  1057. /**
  1058. * Determines if a positive integer is a power of two.
  1059. *
  1060. * @param {Number} n The positive integer to test.
  1061. * @returns {Boolean} <code>true</code> if the number if a power of two; otherwise, <code>false</code>.
  1062. *
  1063. * @exception {DeveloperError} A number greater than or equal to 0 is required.
  1064. *
  1065. * @example
  1066. * var t = Cesium.Math.isPowerOfTwo(16); // true
  1067. * var f = Cesium.Math.isPowerOfTwo(20); // false
  1068. */
  1069. CesiumMath.isPowerOfTwo = function(n) {
  1070. if (typeof n !== 'number' || n < 0) {
  1071. throw new DeveloperError('A number greater than or equal to 0 is required.');
  1072. }
  1073. return (n !== 0) && ((n & (n - 1)) === 0);
  1074. };
  1075. /**
  1076. * Computes the next power-of-two integer greater than or equal to the provided positive integer.
  1077. *
  1078. * @param {Number} n The positive integer to test.
  1079. * @returns {Number} The next power-of-two integer.
  1080. *
  1081. * @exception {DeveloperError} A number greater than or equal to 0 is required.
  1082. *
  1083. * @example
  1084. * var n = Cesium.Math.nextPowerOfTwo(29); // 32
  1085. * var m = Cesium.Math.nextPowerOfTwo(32); // 32
  1086. */
  1087. CesiumMath.nextPowerOfTwo = function(n) {
  1088. if (typeof n !== 'number' || n < 0) {
  1089. throw new DeveloperError('A number greater than or equal to 0 is required.');
  1090. }
  1091. // From http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
  1092. --n;
  1093. n |= n >> 1;
  1094. n |= n >> 2;
  1095. n |= n >> 4;
  1096. n |= n >> 8;
  1097. n |= n >> 16;
  1098. ++n;
  1099. return n;
  1100. };
  1101. /**
  1102. * Constraint a value to lie between two values.
  1103. *
  1104. * @param {Number} value The value to constrain.
  1105. * @param {Number} min The minimum value.
  1106. * @param {Number} max The maximum value.
  1107. * @returns {Number} The value clamped so that min <= value <= max.
  1108. */
  1109. CesiumMath.clamp = function(value, min, max) {
  1110. if (!defined(value)) {
  1111. throw new DeveloperError('value is required');
  1112. }
  1113. if (!defined(min)) {
  1114. throw new DeveloperError('min is required.');
  1115. }
  1116. if (!defined(max)) {
  1117. throw new DeveloperError('max is required.');
  1118. }
  1119. return value < min ? min : value > max ? max : value;
  1120. };
  1121. var randomNumberGenerator = new MersenneTwister();
  1122. /**
  1123. * Sets the seed used by the random number generator
  1124. * in {@link CesiumMath#nextRandomNumber}.
  1125. *
  1126. * @param {Number} seed An integer used as the seed.
  1127. */
  1128. CesiumMath.setRandomNumberSeed = function(seed) {
  1129. if (!defined(seed)) {
  1130. throw new DeveloperError('seed is required.');
  1131. }
  1132. randomNumberGenerator = new MersenneTwister(seed);
  1133. };
  1134. /**
  1135. * Generates a random number in the range of [0.0, 1.0)
  1136. * using a Mersenne twister.
  1137. *
  1138. * @returns {Number} A random number in the range of [0.0, 1.0).
  1139. *
  1140. * @see CesiumMath.setRandomNumberSeed
  1141. * @see {@link http://en.wikipedia.org/wiki/Mersenne_twister|Mersenne twister on Wikipedia}
  1142. */
  1143. CesiumMath.nextRandomNumber = function() {
  1144. return randomNumberGenerator.random();
  1145. };
  1146. /**
  1147. * Computes <code>Math.acos(value)</acode>, but first clamps <code>value</code> to the range [-1.0, 1.0]
  1148. * so that the function will never return NaN.
  1149. *
  1150. * @param {Number} value The value for which to compute acos.
  1151. * @returns {Number} The acos of the value if the value is in the range [-1.0, 1.0], or the acos of -1.0 or 1.0,
  1152. * whichever is closer, if the value is outside the range.
  1153. */
  1154. CesiumMath.acosClamped = function(value) {
  1155. if (!defined(value)) {
  1156. throw new DeveloperError('value is required.');
  1157. }
  1158. return Math.acos(CesiumMath.clamp(value, -1.0, 1.0));
  1159. };
  1160. /**
  1161. * Computes <code>Math.asin(value)</acode>, but first clamps <code>value</code> to the range [-1.0, 1.0]
  1162. * so that the function will never return NaN.
  1163. *
  1164. * @param {Number} value The value for which to compute asin.
  1165. * @returns {Number} The asin of the value if the value is in the range [-1.0, 1.0], or the asin of -1.0 or 1.0,
  1166. * whichever is closer, if the value is outside the range.
  1167. */
  1168. CesiumMath.asinClamped = function(value) {
  1169. if (!defined(value)) {
  1170. throw new DeveloperError('value is required.');
  1171. }
  1172. return Math.asin(CesiumMath.clamp(value, -1.0, 1.0));
  1173. };
  1174. /**
  1175. * Finds the chord length between two points given the circle's radius and the angle between the points.
  1176. *
  1177. * @param {Number} angle The angle between the two points.
  1178. * @param {Number} radius The radius of the circle.
  1179. * @returns {Number} The chord length.
  1180. */
  1181. CesiumMath.chordLength = function(angle, radius) {
  1182. if (!defined(angle)) {
  1183. throw new DeveloperError('angle is required.');
  1184. }
  1185. if (!defined(radius)) {
  1186. throw new DeveloperError('radius is required.');
  1187. }
  1188. return 2.0 * radius * Math.sin(angle * 0.5);
  1189. };
  1190. /**
  1191. * Finds the logarithm of a number to a base.
  1192. *
  1193. * @param {Number} number The number.
  1194. * @param {Number} base The base.
  1195. * @returns {Number} The result.
  1196. */
  1197. CesiumMath.logBase = function(number, base) {
  1198. if (!defined(number)) {
  1199. throw new DeveloperError('number is required.');
  1200. }
  1201. if (!defined(base)) {
  1202. throw new DeveloperError('base is required.');
  1203. }
  1204. return Math.log(number) / Math.log(base);
  1205. };
  1206. /**
  1207. * @private
  1208. */
  1209. CesiumMath.fog = function(distanceToCamera, density) {
  1210. var scalar = distanceToCamera * density;
  1211. return 1.0 - Math.exp(-(scalar * scalar));
  1212. };
  1213. return CesiumMath;
  1214. });
  1215. /*global define*/
  1216. define('Core/Cartesian3',[
  1217. './Check',
  1218. './defaultValue',
  1219. './defined',
  1220. './DeveloperError',
  1221. './freezeObject',
  1222. './Math'
  1223. ], function(
  1224. Check,
  1225. defaultValue,
  1226. defined,
  1227. DeveloperError,
  1228. freezeObject,
  1229. CesiumMath) {
  1230. 'use strict';
  1231. /**
  1232. * A 3D Cartesian point.
  1233. * @alias Cartesian3
  1234. * @constructor
  1235. *
  1236. * @param {Number} [x=0.0] The X component.
  1237. * @param {Number} [y=0.0] The Y component.
  1238. * @param {Number} [z=0.0] The Z component.
  1239. *
  1240. * @see Cartesian2
  1241. * @see Cartesian4
  1242. * @see Packable
  1243. */
  1244. function Cartesian3(x, y, z) {
  1245. /**
  1246. * The X component.
  1247. * @type {Number}
  1248. * @default 0.0
  1249. */
  1250. this.x = defaultValue(x, 0.0);
  1251. /**
  1252. * The Y component.
  1253. * @type {Number}
  1254. * @default 0.0
  1255. */
  1256. this.y = defaultValue(y, 0.0);
  1257. /**
  1258. * The Z component.
  1259. * @type {Number}
  1260. * @default 0.0
  1261. */
  1262. this.z = defaultValue(z, 0.0);
  1263. }
  1264. /**
  1265. * Converts the provided Spherical into Cartesian3 coordinates.
  1266. *
  1267. * @param {Spherical} spherical The Spherical to be converted to Cartesian3.
  1268. * @param {Cartesian3} [result] The object onto which to store the result.
  1269. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  1270. */
  1271. Cartesian3.fromSpherical = function(spherical, result) {
  1272. Check.typeOf.object(spherical, 'spherical');
  1273. if (!defined(result)) {
  1274. result = new Cartesian3();
  1275. }
  1276. var clock = spherical.clock;
  1277. var cone = spherical.cone;
  1278. var magnitude = defaultValue(spherical.magnitude, 1.0);
  1279. var radial = magnitude * Math.sin(cone);
  1280. result.x = radial * Math.cos(clock);
  1281. result.y = radial * Math.sin(clock);
  1282. result.z = magnitude * Math.cos(cone);
  1283. return result;
  1284. };
  1285. /**
  1286. * Creates a Cartesian3 instance from x, y and z coordinates.
  1287. *
  1288. * @param {Number} x The x coordinate.
  1289. * @param {Number} y The y coordinate.
  1290. * @param {Number} z The z coordinate.
  1291. * @param {Cartesian3} [result] The object onto which to store the result.
  1292. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  1293. */
  1294. Cartesian3.fromElements = function(x, y, z, result) {
  1295. if (!defined(result)) {
  1296. return new Cartesian3(x, y, z);
  1297. }
  1298. result.x = x;
  1299. result.y = y;
  1300. result.z = z;
  1301. return result;
  1302. };
  1303. /**
  1304. * Duplicates a Cartesian3 instance.
  1305. *
  1306. * @param {Cartesian3} cartesian The Cartesian to duplicate.
  1307. * @param {Cartesian3} [result] The object onto which to store the result.
  1308. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided. (Returns undefined if cartesian is undefined)
  1309. */
  1310. Cartesian3.clone = function(cartesian, result) {
  1311. if (!defined(cartesian)) {
  1312. return undefined;
  1313. }
  1314. if (!defined(result)) {
  1315. return new Cartesian3(cartesian.x, cartesian.y, cartesian.z);
  1316. }
  1317. result.x = cartesian.x;
  1318. result.y = cartesian.y;
  1319. result.z = cartesian.z;
  1320. return result;
  1321. };
  1322. /**
  1323. * Creates a Cartesian3 instance from an existing Cartesian4. This simply takes the
  1324. * x, y, and z properties of the Cartesian4 and drops w.
  1325. * @function
  1326. *
  1327. * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian3 instance from.
  1328. * @param {Cartesian3} [result] The object onto which to store the result.
  1329. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  1330. */
  1331. Cartesian3.fromCartesian4 = Cartesian3.clone;
  1332. /**
  1333. * The number of elements used to pack the object into an array.
  1334. * @type {Number}
  1335. */
  1336. Cartesian3.packedLength = 3;
  1337. /**
  1338. * Stores the provided instance into the provided array.
  1339. *
  1340. * @param {Cartesian3} value The value to pack.
  1341. * @param {Number[]} array The array to pack into.
  1342. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  1343. *
  1344. * @returns {Number[]} The array that was packed into
  1345. */
  1346. Cartesian3.pack = function(value, array, startingIndex) {
  1347. Check.typeOf.object(value, 'value');
  1348. Check.defined(array, 'array');
  1349. startingIndex = defaultValue(startingIndex, 0);
  1350. array[startingIndex++] = value.x;
  1351. array[startingIndex++] = value.y;
  1352. array[startingIndex] = value.z;
  1353. return array;
  1354. };
  1355. /**
  1356. * Retrieves an instance from a packed array.
  1357. *
  1358. * @param {Number[]} array The packed array.
  1359. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  1360. * @param {Cartesian3} [result] The object into which to store the result.
  1361. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  1362. */
  1363. Cartesian3.unpack = function(array, startingIndex, result) {
  1364. Check.defined(array, 'array');
  1365. startingIndex = defaultValue(startingIndex, 0);
  1366. if (!defined(result)) {
  1367. result = new Cartesian3();
  1368. }
  1369. result.x = array[startingIndex++];
  1370. result.y = array[startingIndex++];
  1371. result.z = array[startingIndex];
  1372. return result;
  1373. };
  1374. /**
  1375. * Flattens an array of Cartesian3s into an array of components.
  1376. *
  1377. * @param {Cartesian3[]} array The array of cartesians to pack.
  1378. * @param {Number[]} result The array onto which to store the result.
  1379. * @returns {Number[]} The packed array.
  1380. */
  1381. Cartesian3.packArray = function(array, result) {
  1382. Check.defined(array, 'array');
  1383. var length = array.length;
  1384. if (!defined(result)) {
  1385. result = new Array(length * 3);
  1386. } else {
  1387. result.length = length * 3;
  1388. }
  1389. for (var i = 0; i < length; ++i) {
  1390. Cartesian3.pack(array[i], result, i * 3);
  1391. }
  1392. return result;
  1393. };
  1394. /**
  1395. * Unpacks an array of cartesian components into an array of Cartesian3s.
  1396. *
  1397. * @param {Number[]} array The array of components to unpack.
  1398. * @param {Cartesian3[]} result The array onto which to store the result.
  1399. * @returns {Cartesian3[]} The unpacked array.
  1400. */
  1401. Cartesian3.unpackArray = function(array, result) {
  1402. Check.defined(array, 'array');
  1403. Check.numeric.minimum(array.length, 3);
  1404. if (array.length % 3 !== 0) {
  1405. throw new DeveloperError('array length must be a multiple of 3.');
  1406. }
  1407. var length = array.length;
  1408. if (!defined(result)) {
  1409. result = new Array(length / 3);
  1410. } else {
  1411. result.length = length / 3;
  1412. }
  1413. for (var i = 0; i < length; i += 3) {
  1414. var index = i / 3;
  1415. result[index] = Cartesian3.unpack(array, i, result[index]);
  1416. }
  1417. return result;
  1418. };
  1419. /**
  1420. * Creates a Cartesian3 from three consecutive elements in an array.
  1421. * @function
  1422. *
  1423. * @param {Number[]} array The array whose three consecutive elements correspond to the x, y, and z components, respectively.
  1424. * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.
  1425. * @param {Cartesian3} [result] The object onto which to store the result.
  1426. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  1427. *
  1428. * @example
  1429. * // Create a Cartesian3 with (1.0, 2.0, 3.0)
  1430. * var v = [1.0, 2.0, 3.0];
  1431. * var p = Cesium.Cartesian3.fromArray(v);
  1432. *
  1433. * // Create a Cartesian3 with (1.0, 2.0, 3.0) using an offset into an array
  1434. * var v2 = [0.0, 0.0, 1.0, 2.0, 3.0];
  1435. * var p2 = Cesium.Cartesian3.fromArray(v2, 2);
  1436. */
  1437. Cartesian3.fromArray = Cartesian3.unpack;
  1438. /**
  1439. * Computes the value of the maximum component for the supplied Cartesian.
  1440. *
  1441. * @param {Cartesian3} cartesian The cartesian to use.
  1442. * @returns {Number} The value of the maximum component.
  1443. */
  1444. Cartesian3.maximumComponent = function(cartesian) {
  1445. Check.typeOf.object(cartesian, 'cartesian');
  1446. return Math.max(cartesian.x, cartesian.y, cartesian.z);
  1447. };
  1448. /**
  1449. * Computes the value of the minimum component for the supplied Cartesian.
  1450. *
  1451. * @param {Cartesian3} cartesian The cartesian to use.
  1452. * @returns {Number} The value of the minimum component.
  1453. */
  1454. Cartesian3.minimumComponent = function(cartesian) {
  1455. Check.typeOf.object(cartesian, 'cartesian');
  1456. return Math.min(cartesian.x, cartesian.y, cartesian.z);
  1457. };
  1458. /**
  1459. * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
  1460. *
  1461. * @param {Cartesian3} first A cartesian to compare.
  1462. * @param {Cartesian3} second A cartesian to compare.
  1463. * @param {Cartesian3} result The object into which to store the result.
  1464. * @returns {Cartesian3} A cartesian with the minimum components.
  1465. */
  1466. Cartesian3.minimumByComponent = function(first, second, result) {
  1467. Check.typeOf.object(first, 'first');
  1468. Check.typeOf.object(second, 'second');
  1469. Check.typeOf.object(result, 'result');
  1470. result.x = Math.min(first.x, second.x);
  1471. result.y = Math.min(first.y, second.y);
  1472. result.z = Math.min(first.z, second.z);
  1473. return result;
  1474. };
  1475. /**
  1476. * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
  1477. *
  1478. * @param {Cartesian3} first A cartesian to compare.
  1479. * @param {Cartesian3} second A cartesian to compare.
  1480. * @param {Cartesian3} result The object into which to store the result.
  1481. * @returns {Cartesian3} A cartesian with the maximum components.
  1482. */
  1483. Cartesian3.maximumByComponent = function(first, second, result) {
  1484. Check.typeOf.object(first, 'first');
  1485. Check.typeOf.object(second, 'second');
  1486. Check.typeOf.object(result, 'result');
  1487. result.x = Math.max(first.x, second.x);
  1488. result.y = Math.max(first.y, second.y);
  1489. result.z = Math.max(first.z, second.z);
  1490. return result;
  1491. };
  1492. /**
  1493. * Computes the provided Cartesian's squared magnitude.
  1494. *
  1495. * @param {Cartesian3} cartesian The Cartesian instance whose squared magnitude is to be computed.
  1496. * @returns {Number} The squared magnitude.
  1497. */
  1498. Cartesian3.magnitudeSquared = function(cartesian) {
  1499. Check.typeOf.object(cartesian, 'cartesian');
  1500. return cartesian.x * cartesian.x + cartesian.y * cartesian.y + cartesian.z * cartesian.z;
  1501. };
  1502. /**
  1503. * Computes the Cartesian's magnitude (length).
  1504. *
  1505. * @param {Cartesian3} cartesian The Cartesian instance whose magnitude is to be computed.
  1506. * @returns {Number} The magnitude.
  1507. */
  1508. Cartesian3.magnitude = function(cartesian) {
  1509. return Math.sqrt(Cartesian3.magnitudeSquared(cartesian));
  1510. };
  1511. var distanceScratch = new Cartesian3();
  1512. /**
  1513. * Computes the distance between two points.
  1514. *
  1515. * @param {Cartesian3} left The first point to compute the distance from.
  1516. * @param {Cartesian3} right The second point to compute the distance to.
  1517. * @returns {Number} The distance between two points.
  1518. *
  1519. * @example
  1520. * // Returns 1.0
  1521. * var d = Cesium.Cartesian3.distance(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(2.0, 0.0, 0.0));
  1522. */
  1523. Cartesian3.distance = function(left, right) {
  1524. Check.typeOf.object(left, 'left');
  1525. Check.typeOf.object(right, 'right');
  1526. Cartesian3.subtract(left, right, distanceScratch);
  1527. return Cartesian3.magnitude(distanceScratch);
  1528. };
  1529. /**
  1530. * Computes the squared distance between two points. Comparing squared distances
  1531. * using this function is more efficient than comparing distances using {@link Cartesian3#distance}.
  1532. *
  1533. * @param {Cartesian3} left The first point to compute the distance from.
  1534. * @param {Cartesian3} right The second point to compute the distance to.
  1535. * @returns {Number} The distance between two points.
  1536. *
  1537. * @example
  1538. * // Returns 4.0, not 2.0
  1539. * var d = Cesium.Cartesian3.distanceSquared(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(3.0, 0.0, 0.0));
  1540. */
  1541. Cartesian3.distanceSquared = function(left, right) {
  1542. Check.typeOf.object(left, 'left');
  1543. Check.typeOf.object(right, 'right');
  1544. Cartesian3.subtract(left, right, distanceScratch);
  1545. return Cartesian3.magnitudeSquared(distanceScratch);
  1546. };
  1547. /**
  1548. * Computes the normalized form of the supplied Cartesian.
  1549. *
  1550. * @param {Cartesian3} cartesian The Cartesian to be normalized.
  1551. * @param {Cartesian3} result The object onto which to store the result.
  1552. * @returns {Cartesian3} The modified result parameter.
  1553. */
  1554. Cartesian3.normalize = function(cartesian, result) {
  1555. Check.typeOf.object(cartesian, 'cartesian');
  1556. Check.typeOf.object(result, 'result');
  1557. var magnitude = Cartesian3.magnitude(cartesian);
  1558. result.x = cartesian.x / magnitude;
  1559. result.y = cartesian.y / magnitude;
  1560. result.z = cartesian.z / magnitude;
  1561. if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z)) {
  1562. throw new DeveloperError('normalized result is not a number');
  1563. }
  1564. return result;
  1565. };
  1566. /**
  1567. * Computes the dot (scalar) product of two Cartesians.
  1568. *
  1569. * @param {Cartesian3} left The first Cartesian.
  1570. * @param {Cartesian3} right The second Cartesian.
  1571. * @returns {Number} The dot product.
  1572. */
  1573. Cartesian3.dot = function(left, right) {
  1574. Check.typeOf.object(left, 'left');
  1575. Check.typeOf.object(right, 'right');
  1576. return left.x * right.x + left.y * right.y + left.z * right.z;
  1577. };
  1578. /**
  1579. * Computes the componentwise product of two Cartesians.
  1580. *
  1581. * @param {Cartesian3} left The first Cartesian.
  1582. * @param {Cartesian3} right The second Cartesian.
  1583. * @param {Cartesian3} result The object onto which to store the result.
  1584. * @returns {Cartesian3} The modified result parameter.
  1585. */
  1586. Cartesian3.multiplyComponents = function(left, right, result) {
  1587. Check.typeOf.object(left, 'left');
  1588. Check.typeOf.object(right, 'right');
  1589. Check.typeOf.object(result, 'result');
  1590. result.x = left.x * right.x;
  1591. result.y = left.y * right.y;
  1592. result.z = left.z * right.z;
  1593. return result;
  1594. };
  1595. /**
  1596. * Computes the componentwise quotient of two Cartesians.
  1597. *
  1598. * @param {Cartesian3} left The first Cartesian.
  1599. * @param {Cartesian3} right The second Cartesian.
  1600. * @param {Cartesian3} result The object onto which to store the result.
  1601. * @returns {Cartesian3} The modified result parameter.
  1602. */
  1603. Cartesian3.divideComponents = function(left, right, result) {
  1604. if (!defined(left)) {
  1605. throw new DeveloperError('left is required');
  1606. }
  1607. if (!defined(right)) {
  1608. throw new DeveloperError('right is required');
  1609. }
  1610. if (!defined(result)) {
  1611. throw new DeveloperError('result is required');
  1612. }
  1613. result.x = left.x / right.x;
  1614. result.y = left.y / right.y;
  1615. result.z = left.z / right.z;
  1616. return result;
  1617. };
  1618. /**
  1619. * Computes the componentwise sum of two Cartesians.
  1620. *
  1621. * @param {Cartesian3} left The first Cartesian.
  1622. * @param {Cartesian3} right The second Cartesian.
  1623. * @param {Cartesian3} result The object onto which to store the result.
  1624. * @returns {Cartesian3} The modified result parameter.
  1625. */
  1626. Cartesian3.add = function(left, right, result) {
  1627. Check.typeOf.object(left, 'left');
  1628. Check.typeOf.object(right, 'right');
  1629. Check.typeOf.object(result, 'result');
  1630. result.x = left.x + right.x;
  1631. result.y = left.y + right.y;
  1632. result.z = left.z + right.z;
  1633. return result;
  1634. };
  1635. /**
  1636. * Computes the componentwise difference of two Cartesians.
  1637. *
  1638. * @param {Cartesian3} left The first Cartesian.
  1639. * @param {Cartesian3} right The second Cartesian.
  1640. * @param {Cartesian3} result The object onto which to store the result.
  1641. * @returns {Cartesian3} The modified result parameter.
  1642. */
  1643. Cartesian3.subtract = function(left, right, result) {
  1644. Check.typeOf.object(left, 'left');
  1645. Check.typeOf.object(right, 'right');
  1646. Check.typeOf.object(result, 'result');
  1647. result.x = left.x - right.x;
  1648. result.y = left.y - right.y;
  1649. result.z = left.z - right.z;
  1650. return result;
  1651. };
  1652. /**
  1653. * Multiplies the provided Cartesian componentwise by the provided scalar.
  1654. *
  1655. * @param {Cartesian3} cartesian The Cartesian to be scaled.
  1656. * @param {Number} scalar The scalar to multiply with.
  1657. * @param {Cartesian3} result The object onto which to store the result.
  1658. * @returns {Cartesian3} The modified result parameter.
  1659. */
  1660. Cartesian3.multiplyByScalar = function(cartesian, scalar, result) {
  1661. Check.typeOf.object(cartesian, 'cartesian');
  1662. Check.typeOf.number(scalar, 'scalar');
  1663. Check.typeOf.object(result, 'result');
  1664. result.x = cartesian.x * scalar;
  1665. result.y = cartesian.y * scalar;
  1666. result.z = cartesian.z * scalar;
  1667. return result;
  1668. };
  1669. /**
  1670. * Divides the provided Cartesian componentwise by the provided scalar.
  1671. *
  1672. * @param {Cartesian3} cartesian The Cartesian to be divided.
  1673. * @param {Number} scalar The scalar to divide by.
  1674. * @param {Cartesian3} result The object onto which to store the result.
  1675. * @returns {Cartesian3} The modified result parameter.
  1676. */
  1677. Cartesian3.divideByScalar = function(cartesian, scalar, result) {
  1678. Check.typeOf.object(cartesian, 'cartesian');
  1679. Check.typeOf.number(scalar, 'scalar');
  1680. Check.typeOf.object(result, 'result');
  1681. result.x = cartesian.x / scalar;
  1682. result.y = cartesian.y / scalar;
  1683. result.z = cartesian.z / scalar;
  1684. return result;
  1685. };
  1686. /**
  1687. * Negates the provided Cartesian.
  1688. *
  1689. * @param {Cartesian3} cartesian The Cartesian to be negated.
  1690. * @param {Cartesian3} result The object onto which to store the result.
  1691. * @returns {Cartesian3} The modified result parameter.
  1692. */
  1693. Cartesian3.negate = function(cartesian, result) {
  1694. Check.typeOf.object(cartesian, 'cartesian');
  1695. Check.typeOf.object(result, 'result');
  1696. result.x = -cartesian.x;
  1697. result.y = -cartesian.y;
  1698. result.z = -cartesian.z;
  1699. return result;
  1700. };
  1701. /**
  1702. * Computes the absolute value of the provided Cartesian.
  1703. *
  1704. * @param {Cartesian3} cartesian The Cartesian whose absolute value is to be computed.
  1705. * @param {Cartesian3} result The object onto which to store the result.
  1706. * @returns {Cartesian3} The modified result parameter.
  1707. */
  1708. Cartesian3.abs = function(cartesian, result) {
  1709. Check.typeOf.object(cartesian, 'cartesian');
  1710. Check.typeOf.object(result, 'result');
  1711. result.x = Math.abs(cartesian.x);
  1712. result.y = Math.abs(cartesian.y);
  1713. result.z = Math.abs(cartesian.z);
  1714. return result;
  1715. };
  1716. var lerpScratch = new Cartesian3();
  1717. /**
  1718. * Computes the linear interpolation or extrapolation at t using the provided cartesians.
  1719. *
  1720. * @param {Cartesian3} start The value corresponding to t at 0.0.
  1721. * @param {Cartesian3} end The value corresponding to t at 1.0.
  1722. * @param {Number} t The point along t at which to interpolate.
  1723. * @param {Cartesian3} result The object onto which to store the result.
  1724. * @returns {Cartesian3} The modified result parameter.
  1725. */
  1726. Cartesian3.lerp = function(start, end, t, result) {
  1727. Check.typeOf.object(start, 'start');
  1728. Check.typeOf.object(end, 'end');
  1729. Check.typeOf.number(t, 't');
  1730. Check.typeOf.object(result, 'result');
  1731. Cartesian3.multiplyByScalar(end, t, lerpScratch);
  1732. result = Cartesian3.multiplyByScalar(start, 1.0 - t, result);
  1733. return Cartesian3.add(lerpScratch, result, result);
  1734. };
  1735. var angleBetweenScratch = new Cartesian3();
  1736. var angleBetweenScratch2 = new Cartesian3();
  1737. /**
  1738. * Returns the angle, in radians, between the provided Cartesians.
  1739. *
  1740. * @param {Cartesian3} left The first Cartesian.
  1741. * @param {Cartesian3} right The second Cartesian.
  1742. * @returns {Number} The angle between the Cartesians.
  1743. */
  1744. Cartesian3.angleBetween = function(left, right) {
  1745. Check.typeOf.object(left, 'left');
  1746. Check.typeOf.object(right, 'right');
  1747. Cartesian3.normalize(left, angleBetweenScratch);
  1748. Cartesian3.normalize(right, angleBetweenScratch2);
  1749. var cosine = Cartesian3.dot(angleBetweenScratch, angleBetweenScratch2);
  1750. var sine = Cartesian3.magnitude(Cartesian3.cross(angleBetweenScratch, angleBetweenScratch2, angleBetweenScratch));
  1751. return Math.atan2(sine, cosine);
  1752. };
  1753. var mostOrthogonalAxisScratch = new Cartesian3();
  1754. /**
  1755. * Returns the axis that is most orthogonal to the provided Cartesian.
  1756. *
  1757. * @param {Cartesian3} cartesian The Cartesian on which to find the most orthogonal axis.
  1758. * @param {Cartesian3} result The object onto which to store the result.
  1759. * @returns {Cartesian3} The most orthogonal axis.
  1760. */
  1761. Cartesian3.mostOrthogonalAxis = function(cartesian, result) {
  1762. Check.typeOf.object(cartesian, 'cartesian');
  1763. Check.typeOf.object(result, 'result');
  1764. var f = Cartesian3.normalize(cartesian, mostOrthogonalAxisScratch);
  1765. Cartesian3.abs(f, f);
  1766. if (f.x <= f.y) {
  1767. if (f.x <= f.z) {
  1768. result = Cartesian3.clone(Cartesian3.UNIT_X, result);
  1769. } else {
  1770. result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
  1771. }
  1772. } else {
  1773. if (f.y <= f.z) {
  1774. result = Cartesian3.clone(Cartesian3.UNIT_Y, result);
  1775. } else {
  1776. result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
  1777. }
  1778. }
  1779. return result;
  1780. };
  1781. /**
  1782. * Compares the provided Cartesians componentwise and returns
  1783. * <code>true</code> if they are equal, <code>false</code> otherwise.
  1784. *
  1785. * @param {Cartesian3} [left] The first Cartesian.
  1786. * @param {Cartesian3} [right] The second Cartesian.
  1787. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  1788. */
  1789. Cartesian3.equals = function(left, right) {
  1790. return (left === right) ||
  1791. ((defined(left)) &&
  1792. (defined(right)) &&
  1793. (left.x === right.x) &&
  1794. (left.y === right.y) &&
  1795. (left.z === right.z));
  1796. };
  1797. /**
  1798. * @private
  1799. */
  1800. Cartesian3.equalsArray = function(cartesian, array, offset) {
  1801. return cartesian.x === array[offset] &&
  1802. cartesian.y === array[offset + 1] &&
  1803. cartesian.z === array[offset + 2];
  1804. };
  1805. /**
  1806. * Compares the provided Cartesians componentwise and returns
  1807. * <code>true</code> if they pass an absolute or relative tolerance test,
  1808. * <code>false</code> otherwise.
  1809. *
  1810. * @param {Cartesian3} [left] The first Cartesian.
  1811. * @param {Cartesian3} [right] The second Cartesian.
  1812. * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
  1813. * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  1814. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  1815. */
  1816. Cartesian3.equalsEpsilon = function(left, right, relativeEpsilon, absoluteEpsilon) {
  1817. return (left === right) ||
  1818. (defined(left) &&
  1819. defined(right) &&
  1820. CesiumMath.equalsEpsilon(left.x, right.x, relativeEpsilon, absoluteEpsilon) &&
  1821. CesiumMath.equalsEpsilon(left.y, right.y, relativeEpsilon, absoluteEpsilon) &&
  1822. CesiumMath.equalsEpsilon(left.z, right.z, relativeEpsilon, absoluteEpsilon));
  1823. };
  1824. /**
  1825. * Computes the cross (outer) product of two Cartesians.
  1826. *
  1827. * @param {Cartesian3} left The first Cartesian.
  1828. * @param {Cartesian3} right The second Cartesian.
  1829. * @param {Cartesian3} result The object onto which to store the result.
  1830. * @returns {Cartesian3} The cross product.
  1831. */
  1832. Cartesian3.cross = function(left, right, result) {
  1833. Check.typeOf.object(left, 'left');
  1834. Check.typeOf.object(right, 'right');
  1835. Check.typeOf.object(result, 'result');
  1836. var leftX = left.x;
  1837. var leftY = left.y;
  1838. var leftZ = left.z;
  1839. var rightX = right.x;
  1840. var rightY = right.y;
  1841. var rightZ = right.z;
  1842. var x = leftY * rightZ - leftZ * rightY;
  1843. var y = leftZ * rightX - leftX * rightZ;
  1844. var z = leftX * rightY - leftY * rightX;
  1845. result.x = x;
  1846. result.y = y;
  1847. result.z = z;
  1848. return result;
  1849. };
  1850. /**
  1851. * Returns a Cartesian3 position from longitude and latitude values given in degrees.
  1852. *
  1853. * @param {Number} longitude The longitude, in degrees
  1854. * @param {Number} latitude The latitude, in degrees
  1855. * @param {Number} [height=0.0] The height, in meters, above the ellipsoid.
  1856. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
  1857. * @param {Cartesian3} [result] The object onto which to store the result.
  1858. * @returns {Cartesian3} The position
  1859. *
  1860. * @example
  1861. * var position = Cesium.Cartesian3.fromDegrees(-115.0, 37.0);
  1862. */
  1863. Cartesian3.fromDegrees = function(longitude, latitude, height, ellipsoid, result) {
  1864. Check.typeOf.number(longitude, 'longitude');
  1865. Check.typeOf.number(latitude, 'latitude');
  1866. longitude = CesiumMath.toRadians(longitude);
  1867. latitude = CesiumMath.toRadians(latitude);
  1868. return Cartesian3.fromRadians(longitude, latitude, height, ellipsoid, result);
  1869. };
  1870. var scratchN = new Cartesian3();
  1871. var scratchK = new Cartesian3();
  1872. var wgs84RadiiSquared = new Cartesian3(6378137.0 * 6378137.0, 6378137.0 * 6378137.0, 6356752.3142451793 * 6356752.3142451793);
  1873. /**
  1874. * Returns a Cartesian3 position from longitude and latitude values given in radians.
  1875. *
  1876. * @param {Number} longitude The longitude, in radians
  1877. * @param {Number} latitude The latitude, in radians
  1878. * @param {Number} [height=0.0] The height, in meters, above the ellipsoid.
  1879. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
  1880. * @param {Cartesian3} [result] The object onto which to store the result.
  1881. * @returns {Cartesian3} The position
  1882. *
  1883. * @example
  1884. * var position = Cesium.Cartesian3.fromRadians(-2.007, 0.645);
  1885. */
  1886. Cartesian3.fromRadians = function(longitude, latitude, height, ellipsoid, result) {
  1887. Check.typeOf.number(longitude, 'longitude');
  1888. Check.typeOf.number(latitude, 'latitude');
  1889. height = defaultValue(height, 0.0);
  1890. var radiiSquared = defined(ellipsoid) ? ellipsoid.radiiSquared : wgs84RadiiSquared;
  1891. var cosLatitude = Math.cos(latitude);
  1892. scratchN.x = cosLatitude * Math.cos(longitude);
  1893. scratchN.y = cosLatitude * Math.sin(longitude);
  1894. scratchN.z = Math.sin(latitude);
  1895. scratchN = Cartesian3.normalize(scratchN, scratchN);
  1896. Cartesian3.multiplyComponents(radiiSquared, scratchN, scratchK);
  1897. var gamma = Math.sqrt(Cartesian3.dot(scratchN, scratchK));
  1898. scratchK = Cartesian3.divideByScalar(scratchK, gamma, scratchK);
  1899. scratchN = Cartesian3.multiplyByScalar(scratchN, height, scratchN);
  1900. if (!defined(result)) {
  1901. result = new Cartesian3();
  1902. }
  1903. return Cartesian3.add(scratchK, scratchN, result);
  1904. };
  1905. /**
  1906. * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in degrees.
  1907. *
  1908. * @param {Number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].
  1909. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the coordinates lie.
  1910. * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
  1911. * @returns {Cartesian3[]} The array of positions.
  1912. *
  1913. * @example
  1914. * var positions = Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0, -107.0, 33.0]);
  1915. */
  1916. Cartesian3.fromDegreesArray = function(coordinates, ellipsoid, result) {
  1917. Check.defined(coordinates, 'coordinates');
  1918. if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
  1919. throw new DeveloperError('the number of coordinates must be a multiple of 2 and at least 2');
  1920. }
  1921. var length = coordinates.length;
  1922. if (!defined(result)) {
  1923. result = new Array(length / 2);
  1924. } else {
  1925. result.length = length / 2;
  1926. }
  1927. for (var i = 0; i < length; i += 2) {
  1928. var longitude = coordinates[i];
  1929. var latitude = coordinates[i + 1];
  1930. var index = i / 2;
  1931. result[index] = Cartesian3.fromDegrees(longitude, latitude, 0, ellipsoid, result[index]);
  1932. }
  1933. return result;
  1934. };
  1935. /**
  1936. * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in radians.
  1937. *
  1938. * @param {Number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].
  1939. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the coordinates lie.
  1940. * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
  1941. * @returns {Cartesian3[]} The array of positions.
  1942. *
  1943. * @example
  1944. * var positions = Cesium.Cartesian3.fromRadiansArray([-2.007, 0.645, -1.867, .575]);
  1945. */
  1946. Cartesian3.fromRadiansArray = function(coordinates, ellipsoid, result) {
  1947. Check.defined(coordinates, 'coordinates');
  1948. if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
  1949. throw new DeveloperError('the number of coordinates must be a multiple of 2 and at least 2');
  1950. }
  1951. var length = coordinates.length;
  1952. if (!defined(result)) {
  1953. result = new Array(length / 2);
  1954. } else {
  1955. result.length = length / 2;
  1956. }
  1957. for (var i = 0; i < length; i += 2) {
  1958. var longitude = coordinates[i];
  1959. var latitude = coordinates[i + 1];
  1960. var index = i / 2;
  1961. result[index] = Cartesian3.fromRadians(longitude, latitude, 0, ellipsoid, result[index]);
  1962. }
  1963. return result;
  1964. };
  1965. /**
  1966. * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in degrees.
  1967. *
  1968. * @param {Number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].
  1969. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
  1970. * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
  1971. * @returns {Cartesian3[]} The array of positions.
  1972. *
  1973. * @example
  1974. * var positions = Cesium.Cartesian3.fromDegreesArrayHeights([-115.0, 37.0, 100000.0, -107.0, 33.0, 150000.0]);
  1975. */
  1976. Cartesian3.fromDegreesArrayHeights = function(coordinates, ellipsoid, result) {
  1977. Check.defined(coordinates, 'coordinates');
  1978. if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
  1979. throw new DeveloperError('the number of coordinates must be a multiple of 3 and at least 3');
  1980. }
  1981. var length = coordinates.length;
  1982. if (!defined(result)) {
  1983. result = new Array(length / 3);
  1984. } else {
  1985. result.length = length / 3;
  1986. }
  1987. for (var i = 0; i < length; i += 3) {
  1988. var longitude = coordinates[i];
  1989. var latitude = coordinates[i + 1];
  1990. var height = coordinates[i + 2];
  1991. var index = i / 3;
  1992. result[index] = Cartesian3.fromDegrees(longitude, latitude, height, ellipsoid, result[index]);
  1993. }
  1994. return result;
  1995. };
  1996. /**
  1997. * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in radians.
  1998. *
  1999. * @param {Number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].
  2000. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
  2001. * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
  2002. * @returns {Cartesian3[]} The array of positions.
  2003. *
  2004. * @example
  2005. * var positions = Cesium.Cartesian3.fromRadiansArrayHeights([-2.007, 0.645, 100000.0, -1.867, .575, 150000.0]);
  2006. */
  2007. Cartesian3.fromRadiansArrayHeights = function(coordinates, ellipsoid, result) {
  2008. Check.defined(coordinates, 'coordinates');
  2009. if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
  2010. throw new DeveloperError('the number of coordinates must be a multiple of 3 and at least 3');
  2011. }
  2012. var length = coordinates.length;
  2013. if (!defined(result)) {
  2014. result = new Array(length / 3);
  2015. } else {
  2016. result.length = length / 3;
  2017. }
  2018. for (var i = 0; i < length; i += 3) {
  2019. var longitude = coordinates[i];
  2020. var latitude = coordinates[i + 1];
  2021. var height = coordinates[i + 2];
  2022. var index = i / 3;
  2023. result[index] = Cartesian3.fromRadians(longitude, latitude, height, ellipsoid, result[index]);
  2024. }
  2025. return result;
  2026. };
  2027. /**
  2028. * An immutable Cartesian3 instance initialized to (0.0, 0.0, 0.0).
  2029. *
  2030. * @type {Cartesian3}
  2031. * @constant
  2032. */
  2033. Cartesian3.ZERO = freezeObject(new Cartesian3(0.0, 0.0, 0.0));
  2034. /**
  2035. * An immutable Cartesian3 instance initialized to (1.0, 0.0, 0.0).
  2036. *
  2037. * @type {Cartesian3}
  2038. * @constant
  2039. */
  2040. Cartesian3.UNIT_X = freezeObject(new Cartesian3(1.0, 0.0, 0.0));
  2041. /**
  2042. * An immutable Cartesian3 instance initialized to (0.0, 1.0, 0.0).
  2043. *
  2044. * @type {Cartesian3}
  2045. * @constant
  2046. */
  2047. Cartesian3.UNIT_Y = freezeObject(new Cartesian3(0.0, 1.0, 0.0));
  2048. /**
  2049. * An immutable Cartesian3 instance initialized to (0.0, 0.0, 1.0).
  2050. *
  2051. * @type {Cartesian3}
  2052. * @constant
  2053. */
  2054. Cartesian3.UNIT_Z = freezeObject(new Cartesian3(0.0, 0.0, 1.0));
  2055. /**
  2056. * Duplicates this Cartesian3 instance.
  2057. *
  2058. * @param {Cartesian3} [result] The object onto which to store the result.
  2059. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
  2060. */
  2061. Cartesian3.prototype.clone = function(result) {
  2062. return Cartesian3.clone(this, result);
  2063. };
  2064. /**
  2065. * Compares this Cartesian against the provided Cartesian componentwise and returns
  2066. * <code>true</code> if they are equal, <code>false</code> otherwise.
  2067. *
  2068. * @param {Cartesian3} [right] The right hand side Cartesian.
  2069. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  2070. */
  2071. Cartesian3.prototype.equals = function(right) {
  2072. return Cartesian3.equals(this, right);
  2073. };
  2074. /**
  2075. * Compares this Cartesian against the provided Cartesian componentwise and returns
  2076. * <code>true</code> if they pass an absolute or relative tolerance test,
  2077. * <code>false</code> otherwise.
  2078. *
  2079. * @param {Cartesian3} [right] The right hand side Cartesian.
  2080. * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
  2081. * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  2082. * @returns {Boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
  2083. */
  2084. Cartesian3.prototype.equalsEpsilon = function(right, relativeEpsilon, absoluteEpsilon) {
  2085. return Cartesian3.equalsEpsilon(this, right, relativeEpsilon, absoluteEpsilon);
  2086. };
  2087. /**
  2088. * Creates a string representing this Cartesian in the format '(x, y, z)'.
  2089. *
  2090. * @returns {String} A string representing this Cartesian in the format '(x, y, z)'.
  2091. */
  2092. Cartesian3.prototype.toString = function() {
  2093. return '(' + this.x + ', ' + this.y + ', ' + this.z + ')';
  2094. };
  2095. return Cartesian3;
  2096. });
  2097. /*global define*/
  2098. define('Core/scaleToGeodeticSurface',[
  2099. './Cartesian3',
  2100. './defined',
  2101. './DeveloperError',
  2102. './Math'
  2103. ], function(
  2104. Cartesian3,
  2105. defined,
  2106. DeveloperError,
  2107. CesiumMath) {
  2108. 'use strict';
  2109. var scaleToGeodeticSurfaceIntersection = new Cartesian3();
  2110. var scaleToGeodeticSurfaceGradient = new Cartesian3();
  2111. /**
  2112. * Scales the provided Cartesian position along the geodetic surface normal
  2113. * so that it is on the surface of this ellipsoid. If the position is
  2114. * at the center of the ellipsoid, this function returns undefined.
  2115. *
  2116. * @param {Cartesian3} cartesian The Cartesian position to scale.
  2117. * @param {Cartesian3} oneOverRadii One over radii of the ellipsoid.
  2118. * @param {Cartesian3} oneOverRadiiSquared One over radii squared of the ellipsoid.
  2119. * @param {Number} centerToleranceSquared Tolerance for closeness to the center.
  2120. * @param {Cartesian3} [result] The object onto which to store the result.
  2121. * @returns {Cartesian3} The modified result parameter, a new Cartesian3 instance if none was provided, or undefined if the position is at the center.
  2122. *
  2123. * @exports scaleToGeodeticSurface
  2124. *
  2125. * @private
  2126. */
  2127. function scaleToGeodeticSurface(cartesian, oneOverRadii, oneOverRadiiSquared, centerToleranceSquared, result) {
  2128. if (!defined(cartesian)) {
  2129. throw new DeveloperError('cartesian is required.');
  2130. }
  2131. if (!defined(oneOverRadii)) {
  2132. throw new DeveloperError('oneOverRadii is required.');
  2133. }
  2134. if (!defined(oneOverRadiiSquared)) {
  2135. throw new DeveloperError('oneOverRadiiSquared is required.');
  2136. }
  2137. if (!defined(centerToleranceSquared)) {
  2138. throw new DeveloperError('centerToleranceSquared is required.');
  2139. }
  2140. var positionX = cartesian.x;
  2141. var positionY = cartesian.y;
  2142. var positionZ = cartesian.z;
  2143. var oneOverRadiiX = oneOverRadii.x;
  2144. var oneOverRadiiY = oneOverRadii.y;
  2145. var oneOverRadiiZ = oneOverRadii.z;
  2146. var x2 = positionX * positionX * oneOverRadiiX * oneOverRadiiX;
  2147. var y2 = positionY * positionY * oneOverRadiiY * oneOverRadiiY;
  2148. var z2 = positionZ * positionZ * oneOverRadiiZ * oneOverRadiiZ;
  2149. // Compute the squared ellipsoid norm.
  2150. var squaredNorm = x2 + y2 + z2;
  2151. var ratio = Math.sqrt(1.0 / squaredNorm);
  2152. // As an initial approximation, assume that the radial intersection is the projection point.
  2153. var intersection = Cartesian3.multiplyByScalar(cartesian, ratio, scaleToGeodeticSurfaceIntersection);
  2154. // If the position is near the center, the iteration will not converge.
  2155. if (squaredNorm < centerToleranceSquared) {
  2156. return !isFinite(ratio) ? undefined : Cartesian3.clone(intersection, result);
  2157. }
  2158. var oneOverRadiiSquaredX = oneOverRadiiSquared.x;
  2159. var oneOverRadiiSquaredY = oneOverRadiiSquared.y;
  2160. var oneOverRadiiSquaredZ = oneOverRadiiSquared.z;
  2161. // Use the gradient at the intersection point in place of the true unit normal.
  2162. // The difference in magnitude will be absorbed in the multiplier.
  2163. var gradient = scaleToGeodeticSurfaceGradient;
  2164. gradient.x = intersection.x * oneOverRadiiSquaredX * 2.0;
  2165. gradient.y = intersection.y * oneOverRadiiSquaredY * 2.0;
  2166. gradient.z = intersection.z * oneOverRadiiSquaredZ * 2.0;
  2167. // Compute the initial guess at the normal vector multiplier, lambda.
  2168. var lambda = (1.0 - ratio) * Cartesian3.magnitude(cartesian) / (0.5 * Cartesian3.magnitude(gradient));
  2169. var correction = 0.0;
  2170. var func;
  2171. var denominator;
  2172. var xMultiplier;
  2173. var yMultiplier;
  2174. var zMultiplier;
  2175. var xMultiplier2;
  2176. var yMultiplier2;
  2177. var zMultiplier2;
  2178. var xMultiplier3;
  2179. var yMultiplier3;
  2180. var zMultiplier3;
  2181. do {
  2182. lambda -= correction;
  2183. xMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredX);
  2184. yMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredY);
  2185. zMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredZ);
  2186. xMultiplier2 = xMultiplier * xMultiplier;
  2187. yMultiplier2 = yMultiplier * yMultiplier;
  2188. zMultiplier2 = zMultiplier * zMultiplier;
  2189. xMultiplier3 = xMultiplier2 * xMultiplier;
  2190. yMultiplier3 = yMultiplier2 * yMultiplier;
  2191. zMultiplier3 = zMultiplier2 * zMultiplier;
  2192. func = x2 * xMultiplier2 + y2 * yMultiplier2 + z2 * zMultiplier2 - 1.0;
  2193. // "denominator" here refers to the use of this expression in the velocity and acceleration
  2194. // computations in the sections to follow.
  2195. denominator = x2 * xMultiplier3 * oneOverRadiiSquaredX + y2 * yMultiplier3 * oneOverRadiiSquaredY + z2 * zMultiplier3 * oneOverRadiiSquaredZ;
  2196. var derivative = -2.0 * denominator;
  2197. correction = func / derivative;
  2198. } while (Math.abs(func) > CesiumMath.EPSILON12);
  2199. if (!defined(result)) {
  2200. return new Cartesian3(positionX * xMultiplier, positionY * yMultiplier, positionZ * zMultiplier);
  2201. }
  2202. result.x = positionX * xMultiplier;
  2203. result.y = positionY * yMultiplier;
  2204. result.z = positionZ * zMultiplier;
  2205. return result;
  2206. }
  2207. return scaleToGeodeticSurface;
  2208. });
  2209. /*global define*/
  2210. define('Core/Cartographic',[
  2211. './Cartesian3',
  2212. './defaultValue',
  2213. './defined',
  2214. './DeveloperError',
  2215. './freezeObject',
  2216. './Math',
  2217. './scaleToGeodeticSurface'
  2218. ], function(
  2219. Cartesian3,
  2220. defaultValue,
  2221. defined,
  2222. DeveloperError,
  2223. freezeObject,
  2224. CesiumMath,
  2225. scaleToGeodeticSurface) {
  2226. 'use strict';
  2227. /**
  2228. * A position defined by longitude, latitude, and height.
  2229. * @alias Cartographic
  2230. * @constructor
  2231. *
  2232. * @param {Number} [longitude=0.0] The longitude, in radians.
  2233. * @param {Number} [latitude=0.0] The latitude, in radians.
  2234. * @param {Number} [height=0.0] The height, in meters, above the ellipsoid.
  2235. *
  2236. * @see Ellipsoid
  2237. */
  2238. function Cartographic(longitude, latitude, height) {
  2239. /**
  2240. * The longitude, in radians.
  2241. * @type {Number}
  2242. * @default 0.0
  2243. */
  2244. this.longitude = defaultValue(longitude, 0.0);
  2245. /**
  2246. * The latitude, in radians.
  2247. * @type {Number}
  2248. * @default 0.0
  2249. */
  2250. this.latitude = defaultValue(latitude, 0.0);
  2251. /**
  2252. * The height, in meters, above the ellipsoid.
  2253. * @type {Number}
  2254. * @default 0.0
  2255. */
  2256. this.height = defaultValue(height, 0.0);
  2257. }
  2258. /**
  2259. * Creates a new Cartographic instance from longitude and latitude
  2260. * specified in radians.
  2261. *
  2262. * @param {Number} longitude The longitude, in radians.
  2263. * @param {Number} latitude The latitude, in radians.
  2264. * @param {Number} [height=0.0] The height, in meters, above the ellipsoid.
  2265. * @param {Cartographic} [result] The object onto which to store the result.
  2266. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.
  2267. */
  2268. Cartographic.fromRadians = function(longitude, latitude, height, result) {
  2269. if (!defined(longitude)) {
  2270. throw new DeveloperError('longitude is required.');
  2271. }
  2272. if (!defined(latitude)) {
  2273. throw new DeveloperError('latitude is required.');
  2274. }
  2275. height = defaultValue(height, 0.0);
  2276. if (!defined(result)) {
  2277. return new Cartographic(longitude, latitude, height);
  2278. }
  2279. result.longitude = longitude;
  2280. result.latitude = latitude;
  2281. result.height = height;
  2282. return result;
  2283. };
  2284. /**
  2285. * Creates a new Cartographic instance from longitude and latitude
  2286. * specified in degrees. The values in the resulting object will
  2287. * be in radians.
  2288. *
  2289. * @param {Number} longitude The longitude, in degrees.
  2290. * @param {Number} latitude The latitude, in degrees.
  2291. * @param {Number} [height=0.0] The height, in meters, above the ellipsoid.
  2292. * @param {Cartographic} [result] The object onto which to store the result.
  2293. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.
  2294. */
  2295. Cartographic.fromDegrees = function(longitude, latitude, height, result) {
  2296. if (!defined(longitude)) {
  2297. throw new DeveloperError('longitude is required.');
  2298. }
  2299. if (!defined(latitude)) {
  2300. throw new DeveloperError('latitude is required.');
  2301. }
  2302. longitude = CesiumMath.toRadians(longitude);
  2303. latitude = CesiumMath.toRadians(latitude);
  2304. return Cartographic.fromRadians(longitude, latitude, height, result);
  2305. };
  2306. var cartesianToCartographicN = new Cartesian3();
  2307. var cartesianToCartographicP = new Cartesian3();
  2308. var cartesianToCartographicH = new Cartesian3();
  2309. var wgs84OneOverRadii = new Cartesian3(1.0 / 6378137.0, 1.0 / 6378137.0, 1.0 / 6356752.3142451793);
  2310. var wgs84OneOverRadiiSquared = new Cartesian3(1.0 / (6378137.0 * 6378137.0), 1.0 / (6378137.0 * 6378137.0), 1.0 / (6356752.3142451793 * 6356752.3142451793));
  2311. var wgs84CenterToleranceSquared = CesiumMath.EPSILON1;
  2312. /**
  2313. * Creates a new Cartographic instance from a Cartesian position. The values in the
  2314. * resulting object will be in radians.
  2315. *
  2316. * @param {Cartesian3} cartesian The Cartesian position to convert to cartographic representation.
  2317. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
  2318. * @param {Cartographic} [result] The object onto which to store the result.
  2319. * @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.
  2320. */
  2321. Cartographic.fromCartesian = function(cartesian, ellipsoid, result) {
  2322. var oneOverRadii = defined(ellipsoid) ? ellipsoid.oneOverRadii : wgs84OneOverRadii;
  2323. var oneOverRadiiSquared = defined(ellipsoid) ? ellipsoid.oneOverRadiiSquared : wgs84OneOverRadiiSquared;
  2324. var centerToleranceSquared = defined(ellipsoid) ? ellipsoid._centerToleranceSquared : wgs84CenterToleranceSquared;
  2325. //`cartesian is required.` is thrown from scaleToGeodeticSurface
  2326. var p = scaleToGeodeticSurface(cartesian, oneOverRadii, oneOverRadiiSquared, centerToleranceSquared, cartesianToCartographicP);
  2327. if (!defined(p)) {
  2328. return undefined;
  2329. }
  2330. var n = Cartesian3.multiplyComponents(p, oneOverRadiiSquared, cartesianToCartographicN);
  2331. n = Cartesian3.normalize(n, n);
  2332. var h = Cartesian3.subtract(cartesian, p, cartesianToCartographicH);
  2333. var longitude = Math.atan2(n.y, n.x);
  2334. var latitude = Math.asin(n.z);
  2335. var height = CesiumMath.sign(Cartesian3.dot(h, cartesian)) * Cartesian3.magnitude(h);
  2336. if (!defined(result)) {
  2337. return new Cartographic(longitude, latitude, height);
  2338. }
  2339. result.longitude = longitude;
  2340. result.latitude = latitude;
  2341. result.height = height;
  2342. return result;
  2343. };
  2344. /**
  2345. * Duplicates a Cartographic instance.
  2346. *
  2347. * @param {Cartographic} cartographic The cartographic to duplicate.
  2348. * @param {Cartographic} [result] The object onto which to store the result.
  2349. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided. (Returns undefined if cartographic is undefined)
  2350. */
  2351. Cartographic.clone = function(cartographic, result) {
  2352. if (!defined(cartographic)) {
  2353. return undefined;
  2354. }
  2355. if (!defined(result)) {
  2356. return new Cartographic(cartographic.longitude, cartographic.latitude, cartographic.height);
  2357. }
  2358. result.longitude = cartographic.longitude;
  2359. result.latitude = cartographic.latitude;
  2360. result.height = cartographic.height;
  2361. return result;
  2362. };
  2363. /**
  2364. * Compares the provided cartographics componentwise and returns
  2365. * <code>true</code> if they are equal, <code>false</code> otherwise.
  2366. *
  2367. * @param {Cartographic} [left] The first cartographic.
  2368. * @param {Cartographic} [right] The second cartographic.
  2369. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  2370. */
  2371. Cartographic.equals = function(left, right) {
  2372. return (left === right) ||
  2373. ((defined(left)) &&
  2374. (defined(right)) &&
  2375. (left.longitude === right.longitude) &&
  2376. (left.latitude === right.latitude) &&
  2377. (left.height === right.height));
  2378. };
  2379. /**
  2380. * Compares the provided cartographics componentwise and returns
  2381. * <code>true</code> if they are within the provided epsilon,
  2382. * <code>false</code> otherwise.
  2383. *
  2384. * @param {Cartographic} [left] The first cartographic.
  2385. * @param {Cartographic} [right] The second cartographic.
  2386. * @param {Number} epsilon The epsilon to use for equality testing.
  2387. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  2388. */
  2389. Cartographic.equalsEpsilon = function(left, right, epsilon) {
  2390. if (typeof epsilon !== 'number') {
  2391. throw new DeveloperError('epsilon is required and must be a number.');
  2392. }
  2393. return (left === right) ||
  2394. ((defined(left)) &&
  2395. (defined(right)) &&
  2396. (Math.abs(left.longitude - right.longitude) <= epsilon) &&
  2397. (Math.abs(left.latitude - right.latitude) <= epsilon) &&
  2398. (Math.abs(left.height - right.height) <= epsilon));
  2399. };
  2400. /**
  2401. * An immutable Cartographic instance initialized to (0.0, 0.0, 0.0).
  2402. *
  2403. * @type {Cartographic}
  2404. * @constant
  2405. */
  2406. Cartographic.ZERO = freezeObject(new Cartographic(0.0, 0.0, 0.0));
  2407. /**
  2408. * Duplicates this instance.
  2409. *
  2410. * @param {Cartographic} [result] The object onto which to store the result.
  2411. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if one was not provided.
  2412. */
  2413. Cartographic.prototype.clone = function(result) {
  2414. return Cartographic.clone(this, result);
  2415. };
  2416. /**
  2417. * Compares the provided against this cartographic componentwise and returns
  2418. * <code>true</code> if they are equal, <code>false</code> otherwise.
  2419. *
  2420. * @param {Cartographic} [right] The second cartographic.
  2421. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  2422. */
  2423. Cartographic.prototype.equals = function(right) {
  2424. return Cartographic.equals(this, right);
  2425. };
  2426. /**
  2427. * Compares the provided against this cartographic componentwise and returns
  2428. * <code>true</code> if they are within the provided epsilon,
  2429. * <code>false</code> otherwise.
  2430. *
  2431. * @param {Cartographic} [right] The second cartographic.
  2432. * @param {Number} epsilon The epsilon to use for equality testing.
  2433. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  2434. */
  2435. Cartographic.prototype.equalsEpsilon = function(right, epsilon) {
  2436. return Cartographic.equalsEpsilon(this, right, epsilon);
  2437. };
  2438. /**
  2439. * Creates a string representing this cartographic in the format '(longitude, latitude, height)'.
  2440. *
  2441. * @returns {String} A string representing the provided cartographic in the format '(longitude, latitude, height)'.
  2442. */
  2443. Cartographic.prototype.toString = function() {
  2444. return '(' + this.longitude + ', ' + this.latitude + ', ' + this.height + ')';
  2445. };
  2446. return Cartographic;
  2447. });
  2448. /*global define*/
  2449. define('Core/defineProperties',[
  2450. './defined'
  2451. ], function(
  2452. defined) {
  2453. 'use strict';
  2454. var definePropertyWorks = (function() {
  2455. try {
  2456. return 'x' in Object.defineProperty({}, 'x', {});
  2457. } catch (e) {
  2458. return false;
  2459. }
  2460. })();
  2461. /**
  2462. * Defines properties on an object, using Object.defineProperties if available,
  2463. * otherwise returns the object unchanged. This function should be used in
  2464. * setup code to prevent errors from completely halting JavaScript execution
  2465. * in legacy browsers.
  2466. *
  2467. * @private
  2468. *
  2469. * @exports defineProperties
  2470. */
  2471. var defineProperties = Object.defineProperties;
  2472. if (!definePropertyWorks || !defined(defineProperties)) {
  2473. defineProperties = function(o) {
  2474. return o;
  2475. };
  2476. }
  2477. return defineProperties;
  2478. });
  2479. /*global define*/
  2480. define('Core/Ellipsoid',[
  2481. './Cartesian3',
  2482. './Cartographic',
  2483. './defaultValue',
  2484. './defined',
  2485. './defineProperties',
  2486. './DeveloperError',
  2487. './freezeObject',
  2488. './Math',
  2489. './scaleToGeodeticSurface'
  2490. ], function(
  2491. Cartesian3,
  2492. Cartographic,
  2493. defaultValue,
  2494. defined,
  2495. defineProperties,
  2496. DeveloperError,
  2497. freezeObject,
  2498. CesiumMath,
  2499. scaleToGeodeticSurface) {
  2500. 'use strict';
  2501. function initialize(ellipsoid, x, y, z) {
  2502. x = defaultValue(x, 0.0);
  2503. y = defaultValue(y, 0.0);
  2504. z = defaultValue(z, 0.0);
  2505. if (x < 0.0 || y < 0.0 || z < 0.0) {
  2506. throw new DeveloperError('All radii components must be greater than or equal to zero.');
  2507. }
  2508. ellipsoid._radii = new Cartesian3(x, y, z);
  2509. ellipsoid._radiiSquared = new Cartesian3(x * x,
  2510. y * y,
  2511. z * z);
  2512. ellipsoid._radiiToTheFourth = new Cartesian3(x * x * x * x,
  2513. y * y * y * y,
  2514. z * z * z * z);
  2515. ellipsoid._oneOverRadii = new Cartesian3(x === 0.0 ? 0.0 : 1.0 / x,
  2516. y === 0.0 ? 0.0 : 1.0 / y,
  2517. z === 0.0 ? 0.0 : 1.0 / z);
  2518. ellipsoid._oneOverRadiiSquared = new Cartesian3(x === 0.0 ? 0.0 : 1.0 / (x * x),
  2519. y === 0.0 ? 0.0 : 1.0 / (y * y),
  2520. z === 0.0 ? 0.0 : 1.0 / (z * z));
  2521. ellipsoid._minimumRadius = Math.min(x, y, z);
  2522. ellipsoid._maximumRadius = Math.max(x, y, z);
  2523. ellipsoid._centerToleranceSquared = CesiumMath.EPSILON1;
  2524. if (ellipsoid._radiiSquared.z !== 0) {
  2525. ellipsoid._sqauredXOverSquaredZ = ellipsoid._radiiSquared.x / ellipsoid._radiiSquared.z;
  2526. }
  2527. }
  2528. /**
  2529. * A quadratic surface defined in Cartesian coordinates by the equation
  2530. * <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used
  2531. * by Cesium to represent the shape of planetary bodies.
  2532. *
  2533. * Rather than constructing this object directly, one of the provided
  2534. * constants is normally used.
  2535. * @alias Ellipsoid
  2536. * @constructor
  2537. *
  2538. * @param {Number} [x=0] The radius in the x direction.
  2539. * @param {Number} [y=0] The radius in the y direction.
  2540. * @param {Number} [z=0] The radius in the z direction.
  2541. *
  2542. * @exception {DeveloperError} All radii components must be greater than or equal to zero.
  2543. *
  2544. * @see Ellipsoid.fromCartesian3
  2545. * @see Ellipsoid.WGS84
  2546. * @see Ellipsoid.UNIT_SPHERE
  2547. */
  2548. function Ellipsoid(x, y, z) {
  2549. this._radii = undefined;
  2550. this._radiiSquared = undefined;
  2551. this._radiiToTheFourth = undefined;
  2552. this._oneOverRadii = undefined;
  2553. this._oneOverRadiiSquared = undefined;
  2554. this._minimumRadius = undefined;
  2555. this._maximumRadius = undefined;
  2556. this._centerToleranceSquared = undefined;
  2557. this._sqauredXOverSquaredZ = undefined;
  2558. initialize(this, x, y, z);
  2559. }
  2560. defineProperties(Ellipsoid.prototype, {
  2561. /**
  2562. * Gets the radii of the ellipsoid.
  2563. * @memberof Ellipsoid.prototype
  2564. * @type {Cartesian3}
  2565. * @readonly
  2566. */
  2567. radii : {
  2568. get: function() {
  2569. return this._radii;
  2570. }
  2571. },
  2572. /**
  2573. * Gets the squared radii of the ellipsoid.
  2574. * @memberof Ellipsoid.prototype
  2575. * @type {Cartesian3}
  2576. * @readonly
  2577. */
  2578. radiiSquared : {
  2579. get : function() {
  2580. return this._radiiSquared;
  2581. }
  2582. },
  2583. /**
  2584. * Gets the radii of the ellipsoid raise to the fourth power.
  2585. * @memberof Ellipsoid.prototype
  2586. * @type {Cartesian3}
  2587. * @readonly
  2588. */
  2589. radiiToTheFourth : {
  2590. get : function() {
  2591. return this._radiiToTheFourth;
  2592. }
  2593. },
  2594. /**
  2595. * Gets one over the radii of the ellipsoid.
  2596. * @memberof Ellipsoid.prototype
  2597. * @type {Cartesian3}
  2598. * @readonly
  2599. */
  2600. oneOverRadii : {
  2601. get : function() {
  2602. return this._oneOverRadii;
  2603. }
  2604. },
  2605. /**
  2606. * Gets one over the squared radii of the ellipsoid.
  2607. * @memberof Ellipsoid.prototype
  2608. * @type {Cartesian3}
  2609. * @readonly
  2610. */
  2611. oneOverRadiiSquared : {
  2612. get : function() {
  2613. return this._oneOverRadiiSquared;
  2614. }
  2615. },
  2616. /**
  2617. * Gets the minimum radius of the ellipsoid.
  2618. * @memberof Ellipsoid.prototype
  2619. * @type {Number}
  2620. * @readonly
  2621. */
  2622. minimumRadius : {
  2623. get : function() {
  2624. return this._minimumRadius;
  2625. }
  2626. },
  2627. /**
  2628. * Gets the maximum radius of the ellipsoid.
  2629. * @memberof Ellipsoid.prototype
  2630. * @type {Number}
  2631. * @readonly
  2632. */
  2633. maximumRadius : {
  2634. get : function() {
  2635. return this._maximumRadius;
  2636. }
  2637. }
  2638. });
  2639. /**
  2640. * Duplicates an Ellipsoid instance.
  2641. *
  2642. * @param {Ellipsoid} ellipsoid The ellipsoid to duplicate.
  2643. * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new
  2644. * instance should be created.
  2645. * @returns {Ellipsoid} The cloned Ellipsoid. (Returns undefined if ellipsoid is undefined)
  2646. */
  2647. Ellipsoid.clone = function(ellipsoid, result) {
  2648. if (!defined(ellipsoid)) {
  2649. return undefined;
  2650. }
  2651. var radii = ellipsoid._radii;
  2652. if (!defined(result)) {
  2653. return new Ellipsoid(radii.x, radii.y, radii.z);
  2654. }
  2655. Cartesian3.clone(radii, result._radii);
  2656. Cartesian3.clone(ellipsoid._radiiSquared, result._radiiSquared);
  2657. Cartesian3.clone(ellipsoid._radiiToTheFourth, result._radiiToTheFourth);
  2658. Cartesian3.clone(ellipsoid._oneOverRadii, result._oneOverRadii);
  2659. Cartesian3.clone(ellipsoid._oneOverRadiiSquared, result._oneOverRadiiSquared);
  2660. result._minimumRadius = ellipsoid._minimumRadius;
  2661. result._maximumRadius = ellipsoid._maximumRadius;
  2662. result._centerToleranceSquared = ellipsoid._centerToleranceSquared;
  2663. return result;
  2664. };
  2665. /**
  2666. * Computes an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.
  2667. *
  2668. * @param {Cartesian3} [radii=Cartesian3.ZERO] The ellipsoid's radius in the x, y, and z directions.
  2669. * @returns {Ellipsoid} A new Ellipsoid instance.
  2670. *
  2671. * @exception {DeveloperError} All radii components must be greater than or equal to zero.
  2672. *
  2673. * @see Ellipsoid.WGS84
  2674. * @see Ellipsoid.UNIT_SPHERE
  2675. */
  2676. Ellipsoid.fromCartesian3 = function(cartesian, result) {
  2677. if (!defined(result)) {
  2678. result = new Ellipsoid();
  2679. }
  2680. if (!defined(cartesian)) {
  2681. return result;
  2682. }
  2683. initialize(result, cartesian.x, cartesian.y, cartesian.z);
  2684. return result;
  2685. };
  2686. /**
  2687. * An Ellipsoid instance initialized to the WGS84 standard.
  2688. *
  2689. * @type {Ellipsoid}
  2690. * @constant
  2691. */
  2692. Ellipsoid.WGS84 = freezeObject(new Ellipsoid(6378137.0, 6378137.0, 6356752.3142451793));
  2693. /**
  2694. * An Ellipsoid instance initialized to radii of (1.0, 1.0, 1.0).
  2695. *
  2696. * @type {Ellipsoid}
  2697. * @constant
  2698. */
  2699. Ellipsoid.UNIT_SPHERE = freezeObject(new Ellipsoid(1.0, 1.0, 1.0));
  2700. /**
  2701. * An Ellipsoid instance initialized to a sphere with the lunar radius.
  2702. *
  2703. * @type {Ellipsoid}
  2704. * @constant
  2705. */
  2706. Ellipsoid.MOON = freezeObject(new Ellipsoid(CesiumMath.LUNAR_RADIUS, CesiumMath.LUNAR_RADIUS, CesiumMath.LUNAR_RADIUS));
  2707. /**
  2708. * Duplicates an Ellipsoid instance.
  2709. *
  2710. * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new
  2711. * instance should be created.
  2712. * @returns {Ellipsoid} The cloned Ellipsoid.
  2713. */
  2714. Ellipsoid.prototype.clone = function(result) {
  2715. return Ellipsoid.clone(this, result);
  2716. };
  2717. /**
  2718. * The number of elements used to pack the object into an array.
  2719. * @type {Number}
  2720. */
  2721. Ellipsoid.packedLength = Cartesian3.packedLength;
  2722. /**
  2723. * Stores the provided instance into the provided array.
  2724. *
  2725. * @param {Ellipsoid} value The value to pack.
  2726. * @param {Number[]} array The array to pack into.
  2727. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  2728. *
  2729. * @returns {Number[]} The array that was packed into
  2730. */
  2731. Ellipsoid.pack = function(value, array, startingIndex) {
  2732. if (!defined(value)) {
  2733. throw new DeveloperError('value is required');
  2734. }
  2735. if (!defined(array)) {
  2736. throw new DeveloperError('array is required');
  2737. }
  2738. startingIndex = defaultValue(startingIndex, 0);
  2739. Cartesian3.pack(value._radii, array, startingIndex);
  2740. return array;
  2741. };
  2742. /**
  2743. * Retrieves an instance from a packed array.
  2744. *
  2745. * @param {Number[]} array The packed array.
  2746. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  2747. * @param {Ellipsoid} [result] The object into which to store the result.
  2748. * @returns {Ellipsoid} The modified result parameter or a new Ellipsoid instance if one was not provided.
  2749. */
  2750. Ellipsoid.unpack = function(array, startingIndex, result) {
  2751. if (!defined(array)) {
  2752. throw new DeveloperError('array is required');
  2753. }
  2754. startingIndex = defaultValue(startingIndex, 0);
  2755. var radii = Cartesian3.unpack(array, startingIndex);
  2756. return Ellipsoid.fromCartesian3(radii, result);
  2757. };
  2758. /**
  2759. * Computes the unit vector directed from the center of this ellipsoid toward the provided Cartesian position.
  2760. * @function
  2761. *
  2762. * @param {Cartesian3} cartesian The Cartesian for which to to determine the geocentric normal.
  2763. * @param {Cartesian3} [result] The object onto which to store the result.
  2764. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
  2765. */
  2766. Ellipsoid.prototype.geocentricSurfaceNormal = Cartesian3.normalize;
  2767. /**
  2768. * Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
  2769. *
  2770. * @param {Cartographic} cartographic The cartographic position for which to to determine the geodetic normal.
  2771. * @param {Cartesian3} [result] The object onto which to store the result.
  2772. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
  2773. */
  2774. Ellipsoid.prototype.geodeticSurfaceNormalCartographic = function(cartographic, result) {
  2775. if (!defined(cartographic)) {
  2776. throw new DeveloperError('cartographic is required.');
  2777. }
  2778. var longitude = cartographic.longitude;
  2779. var latitude = cartographic.latitude;
  2780. var cosLatitude = Math.cos(latitude);
  2781. var x = cosLatitude * Math.cos(longitude);
  2782. var y = cosLatitude * Math.sin(longitude);
  2783. var z = Math.sin(latitude);
  2784. if (!defined(result)) {
  2785. result = new Cartesian3();
  2786. }
  2787. result.x = x;
  2788. result.y = y;
  2789. result.z = z;
  2790. return Cartesian3.normalize(result, result);
  2791. };
  2792. /**
  2793. * Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
  2794. *
  2795. * @param {Cartesian3} cartesian The Cartesian position for which to to determine the surface normal.
  2796. * @param {Cartesian3} [result] The object onto which to store the result.
  2797. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
  2798. */
  2799. Ellipsoid.prototype.geodeticSurfaceNormal = function(cartesian, result) {
  2800. if (!defined(result)) {
  2801. result = new Cartesian3();
  2802. }
  2803. result = Cartesian3.multiplyComponents(cartesian, this._oneOverRadiiSquared, result);
  2804. return Cartesian3.normalize(result, result);
  2805. };
  2806. var cartographicToCartesianNormal = new Cartesian3();
  2807. var cartographicToCartesianK = new Cartesian3();
  2808. /**
  2809. * Converts the provided cartographic to Cartesian representation.
  2810. *
  2811. * @param {Cartographic} cartographic The cartographic position.
  2812. * @param {Cartesian3} [result] The object onto which to store the result.
  2813. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
  2814. *
  2815. * @example
  2816. * //Create a Cartographic and determine it's Cartesian representation on a WGS84 ellipsoid.
  2817. * var position = new Cesium.Cartographic(Cesium.Math.toRadians(21), Cesium.Math.toRadians(78), 5000);
  2818. * var cartesianPosition = Cesium.Ellipsoid.WGS84.cartographicToCartesian(position);
  2819. */
  2820. Ellipsoid.prototype.cartographicToCartesian = function(cartographic, result) {
  2821. //`cartographic is required` is thrown from geodeticSurfaceNormalCartographic.
  2822. var n = cartographicToCartesianNormal;
  2823. var k = cartographicToCartesianK;
  2824. this.geodeticSurfaceNormalCartographic(cartographic, n);
  2825. Cartesian3.multiplyComponents(this._radiiSquared, n, k);
  2826. var gamma = Math.sqrt(Cartesian3.dot(n, k));
  2827. Cartesian3.divideByScalar(k, gamma, k);
  2828. Cartesian3.multiplyByScalar(n, cartographic.height, n);
  2829. if (!defined(result)) {
  2830. result = new Cartesian3();
  2831. }
  2832. return Cartesian3.add(k, n, result);
  2833. };
  2834. /**
  2835. * Converts the provided array of cartographics to an array of Cartesians.
  2836. *
  2837. * @param {Cartographic[]} cartographics An array of cartographic positions.
  2838. * @param {Cartesian3[]} [result] The object onto which to store the result.
  2839. * @returns {Cartesian3[]} The modified result parameter or a new Array instance if none was provided.
  2840. *
  2841. * @example
  2842. * //Convert an array of Cartographics and determine their Cartesian representation on a WGS84 ellipsoid.
  2843. * var positions = [new Cesium.Cartographic(Cesium.Math.toRadians(21), Cesium.Math.toRadians(78), 0),
  2844. * new Cesium.Cartographic(Cesium.Math.toRadians(21.321), Cesium.Math.toRadians(78.123), 100),
  2845. * new Cesium.Cartographic(Cesium.Math.toRadians(21.645), Cesium.Math.toRadians(78.456), 250)];
  2846. * var cartesianPositions = Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray(positions);
  2847. */
  2848. Ellipsoid.prototype.cartographicArrayToCartesianArray = function(cartographics, result) {
  2849. if (!defined(cartographics)) {
  2850. throw new DeveloperError('cartographics is required.');
  2851. }
  2852. var length = cartographics.length;
  2853. if (!defined(result)) {
  2854. result = new Array(length);
  2855. } else {
  2856. result.length = length;
  2857. }
  2858. for ( var i = 0; i < length; i++) {
  2859. result[i] = this.cartographicToCartesian(cartographics[i], result[i]);
  2860. }
  2861. return result;
  2862. };
  2863. var cartesianToCartographicN = new Cartesian3();
  2864. var cartesianToCartographicP = new Cartesian3();
  2865. var cartesianToCartographicH = new Cartesian3();
  2866. /**
  2867. * Converts the provided cartesian to cartographic representation.
  2868. * The cartesian is undefined at the center of the ellipsoid.
  2869. *
  2870. * @param {Cartesian3} cartesian The Cartesian position to convert to cartographic representation.
  2871. * @param {Cartographic} [result] The object onto which to store the result.
  2872. * @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.
  2873. *
  2874. * @example
  2875. * //Create a Cartesian and determine it's Cartographic representation on a WGS84 ellipsoid.
  2876. * var position = new Cesium.Cartesian3(17832.12, 83234.52, 952313.73);
  2877. * var cartographicPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
  2878. */
  2879. Ellipsoid.prototype.cartesianToCartographic = function(cartesian, result) {
  2880. //`cartesian is required.` is thrown from scaleToGeodeticSurface
  2881. var p = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);
  2882. if (!defined(p)) {
  2883. return undefined;
  2884. }
  2885. var n = this.geodeticSurfaceNormal(p, cartesianToCartographicN);
  2886. var h = Cartesian3.subtract(cartesian, p, cartesianToCartographicH);
  2887. var longitude = Math.atan2(n.y, n.x);
  2888. var latitude = Math.asin(n.z);
  2889. var height = CesiumMath.sign(Cartesian3.dot(h, cartesian)) * Cartesian3.magnitude(h);
  2890. if (!defined(result)) {
  2891. return new Cartographic(longitude, latitude, height);
  2892. }
  2893. result.longitude = longitude;
  2894. result.latitude = latitude;
  2895. result.height = height;
  2896. return result;
  2897. };
  2898. /**
  2899. * Converts the provided array of cartesians to an array of cartographics.
  2900. *
  2901. * @param {Cartesian3[]} cartesians An array of Cartesian positions.
  2902. * @param {Cartographic[]} [result] The object onto which to store the result.
  2903. * @returns {Cartographic[]} The modified result parameter or a new Array instance if none was provided.
  2904. *
  2905. * @example
  2906. * //Create an array of Cartesians and determine their Cartographic representation on a WGS84 ellipsoid.
  2907. * var positions = [new Cesium.Cartesian3(17832.12, 83234.52, 952313.73),
  2908. * new Cesium.Cartesian3(17832.13, 83234.53, 952313.73),
  2909. * new Cesium.Cartesian3(17832.14, 83234.54, 952313.73)]
  2910. * var cartographicPositions = Cesium.Ellipsoid.WGS84.cartesianArrayToCartographicArray(positions);
  2911. */
  2912. Ellipsoid.prototype.cartesianArrayToCartographicArray = function(cartesians, result) {
  2913. if (!defined(cartesians)) {
  2914. throw new DeveloperError('cartesians is required.');
  2915. }
  2916. var length = cartesians.length;
  2917. if (!defined(result)) {
  2918. result = new Array(length);
  2919. } else {
  2920. result.length = length;
  2921. }
  2922. for ( var i = 0; i < length; ++i) {
  2923. result[i] = this.cartesianToCartographic(cartesians[i], result[i]);
  2924. }
  2925. return result;
  2926. };
  2927. /**
  2928. * Scales the provided Cartesian position along the geodetic surface normal
  2929. * so that it is on the surface of this ellipsoid. If the position is
  2930. * at the center of the ellipsoid, this function returns undefined.
  2931. *
  2932. * @param {Cartesian3} cartesian The Cartesian position to scale.
  2933. * @param {Cartesian3} [result] The object onto which to store the result.
  2934. * @returns {Cartesian3} The modified result parameter, a new Cartesian3 instance if none was provided, or undefined if the position is at the center.
  2935. */
  2936. Ellipsoid.prototype.scaleToGeodeticSurface = function(cartesian, result) {
  2937. return scaleToGeodeticSurface(cartesian, this._oneOverRadii, this._oneOverRadiiSquared, this._centerToleranceSquared, result);
  2938. };
  2939. /**
  2940. * Scales the provided Cartesian position along the geocentric surface normal
  2941. * so that it is on the surface of this ellipsoid.
  2942. *
  2943. * @param {Cartesian3} cartesian The Cartesian position to scale.
  2944. * @param {Cartesian3} [result] The object onto which to store the result.
  2945. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
  2946. */
  2947. Ellipsoid.prototype.scaleToGeocentricSurface = function(cartesian, result) {
  2948. if (!defined(cartesian)) {
  2949. throw new DeveloperError('cartesian is required.');
  2950. }
  2951. if (!defined(result)) {
  2952. result = new Cartesian3();
  2953. }
  2954. var positionX = cartesian.x;
  2955. var positionY = cartesian.y;
  2956. var positionZ = cartesian.z;
  2957. var oneOverRadiiSquared = this._oneOverRadiiSquared;
  2958. var beta = 1.0 / Math.sqrt((positionX * positionX) * oneOverRadiiSquared.x +
  2959. (positionY * positionY) * oneOverRadiiSquared.y +
  2960. (positionZ * positionZ) * oneOverRadiiSquared.z);
  2961. return Cartesian3.multiplyByScalar(cartesian, beta, result);
  2962. };
  2963. /**
  2964. * Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
  2965. * its components by the result of {@link Ellipsoid#oneOverRadii}.
  2966. *
  2967. * @param {Cartesian3} position The position to transform.
  2968. * @param {Cartesian3} [result] The position to which to copy the result, or undefined to create and
  2969. * return a new instance.
  2970. * @returns {Cartesian3} The position expressed in the scaled space. The returned instance is the
  2971. * one passed as the result parameter if it is not undefined, or a new instance of it is.
  2972. */
  2973. Ellipsoid.prototype.transformPositionToScaledSpace = function(position, result) {
  2974. if (!defined(result)) {
  2975. result = new Cartesian3();
  2976. }
  2977. return Cartesian3.multiplyComponents(position, this._oneOverRadii, result);
  2978. };
  2979. /**
  2980. * Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
  2981. * its components by the result of {@link Ellipsoid#radii}.
  2982. *
  2983. * @param {Cartesian3} position The position to transform.
  2984. * @param {Cartesian3} [result] The position to which to copy the result, or undefined to create and
  2985. * return a new instance.
  2986. * @returns {Cartesian3} The position expressed in the unscaled space. The returned instance is the
  2987. * one passed as the result parameter if it is not undefined, or a new instance of it is.
  2988. */
  2989. Ellipsoid.prototype.transformPositionFromScaledSpace = function(position, result) {
  2990. if (!defined(result)) {
  2991. result = new Cartesian3();
  2992. }
  2993. return Cartesian3.multiplyComponents(position, this._radii, result);
  2994. };
  2995. /**
  2996. * Compares this Ellipsoid against the provided Ellipsoid componentwise and returns
  2997. * <code>true</code> if they are equal, <code>false</code> otherwise.
  2998. *
  2999. * @param {Ellipsoid} [right] The other Ellipsoid.
  3000. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  3001. */
  3002. Ellipsoid.prototype.equals = function(right) {
  3003. return (this === right) ||
  3004. (defined(right) &&
  3005. Cartesian3.equals(this._radii, right._radii));
  3006. };
  3007. /**
  3008. * Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.
  3009. *
  3010. * @returns {String} A string representing this ellipsoid in the format '(radii.x, radii.y, radii.z)'.
  3011. */
  3012. Ellipsoid.prototype.toString = function() {
  3013. return this._radii.toString();
  3014. };
  3015. /**
  3016. * Computes a point which is the intersection of the surface normal with the z-axis.
  3017. *
  3018. * @param {Cartesian3} position the position. must be on the surface of the ellipsoid.
  3019. * @param {Number} [buffer = 0.0] A buffer to subtract from the ellipsoid size when checking if the point is inside the ellipsoid.
  3020. * In earth case, with common earth datums, there is no need for this buffer since the intersection point is always (relatively) very close to the center.
  3021. * In WGS84 datum, intersection point is at max z = +-42841.31151331382 (0.673% of z-axis).
  3022. * Intersection point could be outside the ellipsoid if the ratio of MajorAxis / AxisOfRotation is bigger than the square root of 2
  3023. * @param {Cartesian} [result] The cartesian to which to copy the result, or undefined to create and
  3024. * return a new instance.
  3025. * @returns {Cartesian | undefined} the intersection point if it's inside the ellipsoid, undefined otherwise
  3026. *
  3027. * @exception {DeveloperError} position is required.
  3028. * @exception {DeveloperError} Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y).
  3029. * @exception {DeveloperError} Ellipsoid.radii.z must be greater than 0.
  3030. */
  3031. Ellipsoid.prototype.getSurfaceNormalIntersectionWithZAxis = function(position, buffer, result) {
  3032. if (!defined(position)) {
  3033. throw new DeveloperError('position is required.');
  3034. }
  3035. if (!CesiumMath.equalsEpsilon(this._radii.x, this._radii.y, CesiumMath.EPSILON15)) {
  3036. throw new DeveloperError('Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)');
  3037. }
  3038. if (this._radii.z === 0) {
  3039. throw new DeveloperError('Ellipsoid.radii.z must be greater than 0');
  3040. }
  3041. buffer = defaultValue(buffer, 0.0);
  3042. var sqauredXOverSquaredZ = this._sqauredXOverSquaredZ;
  3043. if (!defined(result)) {
  3044. result = new Cartesian3();
  3045. }
  3046. result.x = 0.0;
  3047. result.y = 0.0;
  3048. result.z = position.z * (1 - sqauredXOverSquaredZ);
  3049. if (Math.abs(result.z) >= this._radii.z - buffer) {
  3050. return undefined;
  3051. }
  3052. return result;
  3053. };
  3054. return Ellipsoid;
  3055. });
  3056. /*global define*/
  3057. define('Core/arrayRemoveDuplicates',[
  3058. './defaultValue',
  3059. './defined',
  3060. './DeveloperError',
  3061. './Math'
  3062. ], function(
  3063. defaultValue,
  3064. defined,
  3065. DeveloperError,
  3066. CesiumMath) {
  3067. 'use strict';
  3068. var removeDuplicatesEpsilon = CesiumMath.EPSILON10;
  3069. /**
  3070. * Removes adjacent duplicate values in an array of values.
  3071. *
  3072. * @param {Object[]} [values] The array of values.
  3073. * @param {Function} equalsEpsilon Function to compare values with an epsilon. Boolean equalsEpsilon(left, right, epsilon).
  3074. * @param {Boolean} [wrapAround=false] Compare the last value in the array against the first value.
  3075. * @returns {Object[]|undefined} A new array of values with no adjacent duplicate values or the input array if no duplicates were found.
  3076. *
  3077. * @example
  3078. * // Returns [(1.0, 1.0, 1.0), (2.0, 2.0, 2.0), (3.0, 3.0, 3.0), (1.0, 1.0, 1.0)]
  3079. * var values = [
  3080. * new Cesium.Cartesian3(1.0, 1.0, 1.0),
  3081. * new Cesium.Cartesian3(1.0, 1.0, 1.0),
  3082. * new Cesium.Cartesian3(2.0, 2.0, 2.0),
  3083. * new Cesium.Cartesian3(3.0, 3.0, 3.0),
  3084. * new Cesium.Cartesian3(1.0, 1.0, 1.0)];
  3085. * var nonDuplicatevalues = Cesium.PolylinePipeline.removeDuplicates(values, Cartesian3.equalsEpsilon);
  3086. *
  3087. * @example
  3088. * // Returns [(1.0, 1.0, 1.0), (2.0, 2.0, 2.0), (3.0, 3.0, 3.0)]
  3089. * var values = [
  3090. * new Cesium.Cartesian3(1.0, 1.0, 1.0),
  3091. * new Cesium.Cartesian3(1.0, 1.0, 1.0),
  3092. * new Cesium.Cartesian3(2.0, 2.0, 2.0),
  3093. * new Cesium.Cartesian3(3.0, 3.0, 3.0),
  3094. * new Cesium.Cartesian3(1.0, 1.0, 1.0)];
  3095. * var nonDuplicatevalues = Cesium.PolylinePipeline.removeDuplicates(values, Cartesian3.equalsEpsilon, true);
  3096. *
  3097. * @private
  3098. */
  3099. function arrayRemoveDuplicates(values, equalsEpsilon, wrapAround) {
  3100. if (!defined(equalsEpsilon)) {
  3101. throw new DeveloperError('equalsEpsilon is required.');
  3102. }
  3103. if (!defined(values)) {
  3104. return undefined;
  3105. }
  3106. wrapAround = defaultValue(wrapAround, false);
  3107. var length = values.length;
  3108. if (length < 2) {
  3109. return values;
  3110. }
  3111. var i;
  3112. var v0;
  3113. var v1;
  3114. for (i = 1; i < length; ++i) {
  3115. v0 = values[i - 1];
  3116. v1 = values[i];
  3117. if (equalsEpsilon(v0, v1, removeDuplicatesEpsilon)) {
  3118. break;
  3119. }
  3120. }
  3121. if (i === length) {
  3122. if (wrapAround && equalsEpsilon(values[0], values[values.length - 1], removeDuplicatesEpsilon)) {
  3123. return values.slice(1);
  3124. }
  3125. return values;
  3126. }
  3127. var cleanedvalues = values.slice(0, i);
  3128. for (; i < length; ++i) {
  3129. // v0 is set by either the previous loop, or the previous clean point.
  3130. v1 = values[i];
  3131. if (!equalsEpsilon(v0, v1, removeDuplicatesEpsilon)) {
  3132. cleanedvalues.push(v1);
  3133. v0 = v1;
  3134. }
  3135. }
  3136. if (wrapAround && cleanedvalues.length > 1 && equalsEpsilon(cleanedvalues[0], cleanedvalues[cleanedvalues.length - 1], removeDuplicatesEpsilon)) {
  3137. cleanedvalues.shift();
  3138. }
  3139. return cleanedvalues;
  3140. }
  3141. return arrayRemoveDuplicates;
  3142. });
  3143. /*global define*/
  3144. define('Core/GeographicProjection',[
  3145. './Cartesian3',
  3146. './Cartographic',
  3147. './defaultValue',
  3148. './defined',
  3149. './defineProperties',
  3150. './DeveloperError',
  3151. './Ellipsoid'
  3152. ], function(
  3153. Cartesian3,
  3154. Cartographic,
  3155. defaultValue,
  3156. defined,
  3157. defineProperties,
  3158. DeveloperError,
  3159. Ellipsoid) {
  3160. 'use strict';
  3161. /**
  3162. * A simple map projection where longitude and latitude are linearly mapped to X and Y by multiplying
  3163. * them by the {@link Ellipsoid#maximumRadius}. This projection
  3164. * is commonly known as geographic, equirectangular, equidistant cylindrical, or plate carrée. It
  3165. * is also known as EPSG:4326.
  3166. *
  3167. * @alias GeographicProjection
  3168. * @constructor
  3169. *
  3170. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid.
  3171. *
  3172. * @see WebMercatorProjection
  3173. */
  3174. function GeographicProjection(ellipsoid) {
  3175. this._ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
  3176. this._semimajorAxis = this._ellipsoid.maximumRadius;
  3177. this._oneOverSemimajorAxis = 1.0 / this._semimajorAxis;
  3178. }
  3179. defineProperties(GeographicProjection.prototype, {
  3180. /**
  3181. * Gets the {@link Ellipsoid}.
  3182. *
  3183. * @memberof GeographicProjection.prototype
  3184. *
  3185. * @type {Ellipsoid}
  3186. * @readonly
  3187. */
  3188. ellipsoid : {
  3189. get : function() {
  3190. return this._ellipsoid;
  3191. }
  3192. }
  3193. });
  3194. /**
  3195. * Projects a set of {@link Cartographic} coordinates, in radians, to map coordinates, in meters.
  3196. * X and Y are the longitude and latitude, respectively, multiplied by the maximum radius of the
  3197. * ellipsoid. Z is the unmodified height.
  3198. *
  3199. * @param {Cartographic} cartographic The coordinates to project.
  3200. * @param {Cartesian3} [result] An instance into which to copy the result. If this parameter is
  3201. * undefined, a new instance is created and returned.
  3202. * @returns {Cartesian3} The projected coordinates. If the result parameter is not undefined, the
  3203. * coordinates are copied there and that instance is returned. Otherwise, a new instance is
  3204. * created and returned.
  3205. */
  3206. GeographicProjection.prototype.project = function(cartographic, result) {
  3207. // Actually this is the special case of equidistant cylindrical called the plate carree
  3208. var semimajorAxis = this._semimajorAxis;
  3209. var x = cartographic.longitude * semimajorAxis;
  3210. var y = cartographic.latitude * semimajorAxis;
  3211. var z = cartographic.height;
  3212. if (!defined(result)) {
  3213. return new Cartesian3(x, y, z);
  3214. }
  3215. result.x = x;
  3216. result.y = y;
  3217. result.z = z;
  3218. return result;
  3219. };
  3220. /**
  3221. * Unprojects a set of projected {@link Cartesian3} coordinates, in meters, to {@link Cartographic}
  3222. * coordinates, in radians. Longitude and Latitude are the X and Y coordinates, respectively,
  3223. * divided by the maximum radius of the ellipsoid. Height is the unmodified Z coordinate.
  3224. *
  3225. * @param {Cartesian3} cartesian The Cartesian position to unproject with height (z) in meters.
  3226. * @param {Cartographic} [result] An instance into which to copy the result. If this parameter is
  3227. * undefined, a new instance is created and returned.
  3228. * @returns {Cartographic} The unprojected coordinates. If the result parameter is not undefined, the
  3229. * coordinates are copied there and that instance is returned. Otherwise, a new instance is
  3230. * created and returned.
  3231. */
  3232. GeographicProjection.prototype.unproject = function(cartesian, result) {
  3233. if (!defined(cartesian)) {
  3234. throw new DeveloperError('cartesian is required');
  3235. }
  3236. var oneOverEarthSemimajorAxis = this._oneOverSemimajorAxis;
  3237. var longitude = cartesian.x * oneOverEarthSemimajorAxis;
  3238. var latitude = cartesian.y * oneOverEarthSemimajorAxis;
  3239. var height = cartesian.z;
  3240. if (!defined(result)) {
  3241. return new Cartographic(longitude, latitude, height);
  3242. }
  3243. result.longitude = longitude;
  3244. result.latitude = latitude;
  3245. result.height = height;
  3246. return result;
  3247. };
  3248. return GeographicProjection;
  3249. });
  3250. /*global define*/
  3251. define('Core/Intersect',[
  3252. './freezeObject'
  3253. ], function(
  3254. freezeObject) {
  3255. 'use strict';
  3256. /**
  3257. * This enumerated type is used in determining where, relative to the frustum, an
  3258. * object is located. The object can either be fully contained within the frustum (INSIDE),
  3259. * partially inside the frustum and partially outside (INTERSECTING), or somwhere entirely
  3260. * outside of the frustum's 6 planes (OUTSIDE).
  3261. *
  3262. * @exports Intersect
  3263. */
  3264. var Intersect = {
  3265. /**
  3266. * Represents that an object is not contained within the frustum.
  3267. *
  3268. * @type {Number}
  3269. * @constant
  3270. */
  3271. OUTSIDE : -1,
  3272. /**
  3273. * Represents that an object intersects one of the frustum's planes.
  3274. *
  3275. * @type {Number}
  3276. * @constant
  3277. */
  3278. INTERSECTING : 0,
  3279. /**
  3280. * Represents that an object is fully within the frustum.
  3281. *
  3282. * @type {Number}
  3283. * @constant
  3284. */
  3285. INSIDE : 1
  3286. };
  3287. return freezeObject(Intersect);
  3288. });
  3289. /*global define*/
  3290. define('Core/Interval',[
  3291. './defaultValue'
  3292. ], function(
  3293. defaultValue) {
  3294. 'use strict';
  3295. /**
  3296. * Represents the closed interval [start, stop].
  3297. * @alias Interval
  3298. * @constructor
  3299. *
  3300. * @param {Number} [start=0.0] The beginning of the interval.
  3301. * @param {Number} [stop=0.0] The end of the interval.
  3302. */
  3303. function Interval(start, stop) {
  3304. /**
  3305. * The beginning of the interval.
  3306. * @type {Number}
  3307. * @default 0.0
  3308. */
  3309. this.start = defaultValue(start, 0.0);
  3310. /**
  3311. * The end of the interval.
  3312. * @type {Number}
  3313. * @default 0.0
  3314. */
  3315. this.stop = defaultValue(stop, 0.0);
  3316. }
  3317. return Interval;
  3318. });
  3319. /*global define*/
  3320. define('Core/Matrix3',[
  3321. './Cartesian3',
  3322. './defaultValue',
  3323. './defined',
  3324. './defineProperties',
  3325. './DeveloperError',
  3326. './freezeObject',
  3327. './Math'
  3328. ], function(
  3329. Cartesian3,
  3330. defaultValue,
  3331. defined,
  3332. defineProperties,
  3333. DeveloperError,
  3334. freezeObject,
  3335. CesiumMath) {
  3336. 'use strict';
  3337. /**
  3338. * A 3x3 matrix, indexable as a column-major order array.
  3339. * Constructor parameters are in row-major order for code readability.
  3340. * @alias Matrix3
  3341. * @constructor
  3342. *
  3343. * @param {Number} [column0Row0=0.0] The value for column 0, row 0.
  3344. * @param {Number} [column1Row0=0.0] The value for column 1, row 0.
  3345. * @param {Number} [column2Row0=0.0] The value for column 2, row 0.
  3346. * @param {Number} [column0Row1=0.0] The value for column 0, row 1.
  3347. * @param {Number} [column1Row1=0.0] The value for column 1, row 1.
  3348. * @param {Number} [column2Row1=0.0] The value for column 2, row 1.
  3349. * @param {Number} [column0Row2=0.0] The value for column 0, row 2.
  3350. * @param {Number} [column1Row2=0.0] The value for column 1, row 2.
  3351. * @param {Number} [column2Row2=0.0] The value for column 2, row 2.
  3352. *
  3353. * @see Matrix3.fromColumnMajorArray
  3354. * @see Matrix3.fromRowMajorArray
  3355. * @see Matrix3.fromQuaternion
  3356. * @see Matrix3.fromScale
  3357. * @see Matrix3.fromUniformScale
  3358. * @see Matrix2
  3359. * @see Matrix4
  3360. */
  3361. function Matrix3(column0Row0, column1Row0, column2Row0,
  3362. column0Row1, column1Row1, column2Row1,
  3363. column0Row2, column1Row2, column2Row2) {
  3364. this[0] = defaultValue(column0Row0, 0.0);
  3365. this[1] = defaultValue(column0Row1, 0.0);
  3366. this[2] = defaultValue(column0Row2, 0.0);
  3367. this[3] = defaultValue(column1Row0, 0.0);
  3368. this[4] = defaultValue(column1Row1, 0.0);
  3369. this[5] = defaultValue(column1Row2, 0.0);
  3370. this[6] = defaultValue(column2Row0, 0.0);
  3371. this[7] = defaultValue(column2Row1, 0.0);
  3372. this[8] = defaultValue(column2Row2, 0.0);
  3373. }
  3374. /**
  3375. * The number of elements used to pack the object into an array.
  3376. * @type {Number}
  3377. */
  3378. Matrix3.packedLength = 9;
  3379. /**
  3380. * Stores the provided instance into the provided array.
  3381. *
  3382. * @param {Matrix3} value The value to pack.
  3383. * @param {Number[]} array The array to pack into.
  3384. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  3385. *
  3386. * @returns {Number[]} The array that was packed into
  3387. */
  3388. Matrix3.pack = function(value, array, startingIndex) {
  3389. if (!defined(value)) {
  3390. throw new DeveloperError('value is required');
  3391. }
  3392. if (!defined(array)) {
  3393. throw new DeveloperError('array is required');
  3394. }
  3395. startingIndex = defaultValue(startingIndex, 0);
  3396. array[startingIndex++] = value[0];
  3397. array[startingIndex++] = value[1];
  3398. array[startingIndex++] = value[2];
  3399. array[startingIndex++] = value[3];
  3400. array[startingIndex++] = value[4];
  3401. array[startingIndex++] = value[5];
  3402. array[startingIndex++] = value[6];
  3403. array[startingIndex++] = value[7];
  3404. array[startingIndex++] = value[8];
  3405. return array;
  3406. };
  3407. /**
  3408. * Retrieves an instance from a packed array.
  3409. *
  3410. * @param {Number[]} array The packed array.
  3411. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  3412. * @param {Matrix3} [result] The object into which to store the result.
  3413. * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
  3414. */
  3415. Matrix3.unpack = function(array, startingIndex, result) {
  3416. if (!defined(array)) {
  3417. throw new DeveloperError('array is required');
  3418. }
  3419. startingIndex = defaultValue(startingIndex, 0);
  3420. if (!defined(result)) {
  3421. result = new Matrix3();
  3422. }
  3423. result[0] = array[startingIndex++];
  3424. result[1] = array[startingIndex++];
  3425. result[2] = array[startingIndex++];
  3426. result[3] = array[startingIndex++];
  3427. result[4] = array[startingIndex++];
  3428. result[5] = array[startingIndex++];
  3429. result[6] = array[startingIndex++];
  3430. result[7] = array[startingIndex++];
  3431. result[8] = array[startingIndex++];
  3432. return result;
  3433. };
  3434. /**
  3435. * Duplicates a Matrix3 instance.
  3436. *
  3437. * @param {Matrix3} matrix The matrix to duplicate.
  3438. * @param {Matrix3} [result] The object onto which to store the result.
  3439. * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided. (Returns undefined if matrix is undefined)
  3440. */
  3441. Matrix3.clone = function(values, result) {
  3442. if (!defined(values)) {
  3443. return undefined;
  3444. }
  3445. if (!defined(result)) {
  3446. return new Matrix3(values[0], values[3], values[6],
  3447. values[1], values[4], values[7],
  3448. values[2], values[5], values[8]);
  3449. }
  3450. result[0] = values[0];
  3451. result[1] = values[1];
  3452. result[2] = values[2];
  3453. result[3] = values[3];
  3454. result[4] = values[4];
  3455. result[5] = values[5];
  3456. result[6] = values[6];
  3457. result[7] = values[7];
  3458. result[8] = values[8];
  3459. return result;
  3460. };
  3461. /**
  3462. * Creates a Matrix3 from 9 consecutive elements in an array.
  3463. *
  3464. * @param {Number[]} array The array whose 9 consecutive elements correspond to the positions of the matrix. Assumes column-major order.
  3465. * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.
  3466. * @param {Matrix3} [result] The object onto which to store the result.
  3467. * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
  3468. *
  3469. * @example
  3470. * // Create the Matrix3:
  3471. * // [1.0, 2.0, 3.0]
  3472. * // [1.0, 2.0, 3.0]
  3473. * // [1.0, 2.0, 3.0]
  3474. *
  3475. * var v = [1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];
  3476. * var m = Cesium.Matrix3.fromArray(v);
  3477. *
  3478. * // Create same Matrix3 with using an offset into an array
  3479. * var v2 = [0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];
  3480. * var m2 = Cesium.Matrix3.fromArray(v2, 2);
  3481. */
  3482. Matrix3.fromArray = function(array, startingIndex, result) {
  3483. if (!defined(array)) {
  3484. throw new DeveloperError('array is required');
  3485. }
  3486. startingIndex = defaultValue(startingIndex, 0);
  3487. if (!defined(result)) {
  3488. result = new Matrix3();
  3489. }
  3490. result[0] = array[startingIndex];
  3491. result[1] = array[startingIndex + 1];
  3492. result[2] = array[startingIndex + 2];
  3493. result[3] = array[startingIndex + 3];
  3494. result[4] = array[startingIndex + 4];
  3495. result[5] = array[startingIndex + 5];
  3496. result[6] = array[startingIndex + 6];
  3497. result[7] = array[startingIndex + 7];
  3498. result[8] = array[startingIndex + 8];
  3499. return result;
  3500. };
  3501. /**
  3502. * Creates a Matrix3 instance from a column-major order array.
  3503. *
  3504. * @param {Number[]} values The column-major order array.
  3505. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3506. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3507. */
  3508. Matrix3.fromColumnMajorArray = function(values, result) {
  3509. if (!defined(values)) {
  3510. throw new DeveloperError('values parameter is required');
  3511. }
  3512. return Matrix3.clone(values, result);
  3513. };
  3514. /**
  3515. * Creates a Matrix3 instance from a row-major order array.
  3516. * The resulting matrix will be in column-major order.
  3517. *
  3518. * @param {Number[]} values The row-major order array.
  3519. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3520. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3521. */
  3522. Matrix3.fromRowMajorArray = function(values, result) {
  3523. if (!defined(values)) {
  3524. throw new DeveloperError('values is required.');
  3525. }
  3526. if (!defined(result)) {
  3527. return new Matrix3(values[0], values[1], values[2],
  3528. values[3], values[4], values[5],
  3529. values[6], values[7], values[8]);
  3530. }
  3531. result[0] = values[0];
  3532. result[1] = values[3];
  3533. result[2] = values[6];
  3534. result[3] = values[1];
  3535. result[4] = values[4];
  3536. result[5] = values[7];
  3537. result[6] = values[2];
  3538. result[7] = values[5];
  3539. result[8] = values[8];
  3540. return result;
  3541. };
  3542. /**
  3543. * Computes a 3x3 rotation matrix from the provided quaternion.
  3544. *
  3545. * @param {Quaternion} quaternion the quaternion to use.
  3546. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3547. * @returns {Matrix3} The 3x3 rotation matrix from this quaternion.
  3548. */
  3549. Matrix3.fromQuaternion = function(quaternion, result) {
  3550. if (!defined(quaternion)) {
  3551. throw new DeveloperError('quaternion is required');
  3552. }
  3553. var x2 = quaternion.x * quaternion.x;
  3554. var xy = quaternion.x * quaternion.y;
  3555. var xz = quaternion.x * quaternion.z;
  3556. var xw = quaternion.x * quaternion.w;
  3557. var y2 = quaternion.y * quaternion.y;
  3558. var yz = quaternion.y * quaternion.z;
  3559. var yw = quaternion.y * quaternion.w;
  3560. var z2 = quaternion.z * quaternion.z;
  3561. var zw = quaternion.z * quaternion.w;
  3562. var w2 = quaternion.w * quaternion.w;
  3563. var m00 = x2 - y2 - z2 + w2;
  3564. var m01 = 2.0 * (xy - zw);
  3565. var m02 = 2.0 * (xz + yw);
  3566. var m10 = 2.0 * (xy + zw);
  3567. var m11 = -x2 + y2 - z2 + w2;
  3568. var m12 = 2.0 * (yz - xw);
  3569. var m20 = 2.0 * (xz - yw);
  3570. var m21 = 2.0 * (yz + xw);
  3571. var m22 = -x2 - y2 + z2 + w2;
  3572. if (!defined(result)) {
  3573. return new Matrix3(m00, m01, m02,
  3574. m10, m11, m12,
  3575. m20, m21, m22);
  3576. }
  3577. result[0] = m00;
  3578. result[1] = m10;
  3579. result[2] = m20;
  3580. result[3] = m01;
  3581. result[4] = m11;
  3582. result[5] = m21;
  3583. result[6] = m02;
  3584. result[7] = m12;
  3585. result[8] = m22;
  3586. return result;
  3587. };
  3588. /**
  3589. * Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )
  3590. *
  3591. * @param {HeadingPitchRoll} headingPitchRoll the headingPitchRoll to use.
  3592. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3593. * @returns {Matrix3} The 3x3 rotation matrix from this headingPitchRoll.
  3594. */
  3595. Matrix3.fromHeadingPitchRoll = function(headingPitchRoll, result) {
  3596. if (!defined(headingPitchRoll)) {
  3597. throw new DeveloperError('headingPitchRoll is required');
  3598. }
  3599. var cosTheta = Math.cos(-headingPitchRoll.pitch);
  3600. var cosPsi = Math.cos(-headingPitchRoll.heading);
  3601. var cosPhi = Math.cos(headingPitchRoll.roll);
  3602. var sinTheta = Math.sin(-headingPitchRoll.pitch);
  3603. var sinPsi = Math.sin(-headingPitchRoll.heading);
  3604. var sinPhi = Math.sin(headingPitchRoll.roll);
  3605. var m00 = cosTheta * cosPsi;
  3606. var m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi;
  3607. var m02 = sinPhi * sinPsi + cosPhi * sinTheta * cosPsi;
  3608. var m10 = cosTheta * sinPsi;
  3609. var m11 = cosPhi * cosPsi + sinPhi * sinTheta * sinPsi;
  3610. var m12 = -sinTheta * cosPhi + cosPhi * sinTheta * sinPsi;
  3611. var m20 = -sinTheta;
  3612. var m21 = sinPhi * cosTheta;
  3613. var m22 = cosPhi * cosTheta;
  3614. if (!defined(result)) {
  3615. return new Matrix3(m00, m01, m02,
  3616. m10, m11, m12,
  3617. m20, m21, m22);
  3618. }
  3619. result[0] = m00;
  3620. result[1] = m10;
  3621. result[2] = m20;
  3622. result[3] = m01;
  3623. result[4] = m11;
  3624. result[5] = m21;
  3625. result[6] = m02;
  3626. result[7] = m12;
  3627. result[8] = m22;
  3628. return result;
  3629. };
  3630. /**
  3631. * Computes a Matrix3 instance representing a non-uniform scale.
  3632. *
  3633. * @param {Cartesian3} scale The x, y, and z scale factors.
  3634. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3635. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3636. *
  3637. * @example
  3638. * // Creates
  3639. * // [7.0, 0.0, 0.0]
  3640. * // [0.0, 8.0, 0.0]
  3641. * // [0.0, 0.0, 9.0]
  3642. * var m = Cesium.Matrix3.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));
  3643. */
  3644. Matrix3.fromScale = function(scale, result) {
  3645. if (!defined(scale)) {
  3646. throw new DeveloperError('scale is required.');
  3647. }
  3648. if (!defined(result)) {
  3649. return new Matrix3(
  3650. scale.x, 0.0, 0.0,
  3651. 0.0, scale.y, 0.0,
  3652. 0.0, 0.0, scale.z);
  3653. }
  3654. result[0] = scale.x;
  3655. result[1] = 0.0;
  3656. result[2] = 0.0;
  3657. result[3] = 0.0;
  3658. result[4] = scale.y;
  3659. result[5] = 0.0;
  3660. result[6] = 0.0;
  3661. result[7] = 0.0;
  3662. result[8] = scale.z;
  3663. return result;
  3664. };
  3665. /**
  3666. * Computes a Matrix3 instance representing a uniform scale.
  3667. *
  3668. * @param {Number} scale The uniform scale factor.
  3669. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3670. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3671. *
  3672. * @example
  3673. * // Creates
  3674. * // [2.0, 0.0, 0.0]
  3675. * // [0.0, 2.0, 0.0]
  3676. * // [0.0, 0.0, 2.0]
  3677. * var m = Cesium.Matrix3.fromUniformScale(2.0);
  3678. */
  3679. Matrix3.fromUniformScale = function(scale, result) {
  3680. if (typeof scale !== 'number') {
  3681. throw new DeveloperError('scale is required.');
  3682. }
  3683. if (!defined(result)) {
  3684. return new Matrix3(
  3685. scale, 0.0, 0.0,
  3686. 0.0, scale, 0.0,
  3687. 0.0, 0.0, scale);
  3688. }
  3689. result[0] = scale;
  3690. result[1] = 0.0;
  3691. result[2] = 0.0;
  3692. result[3] = 0.0;
  3693. result[4] = scale;
  3694. result[5] = 0.0;
  3695. result[6] = 0.0;
  3696. result[7] = 0.0;
  3697. result[8] = scale;
  3698. return result;
  3699. };
  3700. /**
  3701. * Computes a Matrix3 instance representing the cross product equivalent matrix of a Cartesian3 vector.
  3702. *
  3703. * @param {Cartesian3} the vector on the left hand side of the cross product operation.
  3704. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3705. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3706. *
  3707. * @example
  3708. * // Creates
  3709. * // [0.0, -9.0, 8.0]
  3710. * // [9.0, 0.0, -7.0]
  3711. * // [-8.0, 7.0, 0.0]
  3712. * var m = Cesium.Matrix3.fromCrossProduct(new Cesium.Cartesian3(7.0, 8.0, 9.0));
  3713. */
  3714. Matrix3.fromCrossProduct = function(vector, result) {
  3715. if (!defined(vector)) {
  3716. throw new DeveloperError('vector is required.');
  3717. }
  3718. if (!defined(result)) {
  3719. return new Matrix3(
  3720. 0.0, -vector.z, vector.y,
  3721. vector.z, 0.0, -vector.x,
  3722. -vector.y, vector.x, 0.0);
  3723. }
  3724. result[0] = 0.0;
  3725. result[1] = vector.z;
  3726. result[2] = -vector.y;
  3727. result[3] = -vector.z;
  3728. result[4] = 0.0;
  3729. result[5] = vector.x;
  3730. result[6] = vector.y;
  3731. result[7] = -vector.x;
  3732. result[8] = 0.0;
  3733. return result;
  3734. };
  3735. /**
  3736. * Creates a rotation matrix around the x-axis.
  3737. *
  3738. * @param {Number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
  3739. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3740. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3741. *
  3742. * @example
  3743. * // Rotate a point 45 degrees counterclockwise around the x-axis.
  3744. * var p = new Cesium.Cartesian3(5, 6, 7);
  3745. * var m = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(45.0));
  3746. * var rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
  3747. */
  3748. Matrix3.fromRotationX = function(angle, result) {
  3749. if (!defined(angle)) {
  3750. throw new DeveloperError('angle is required.');
  3751. }
  3752. var cosAngle = Math.cos(angle);
  3753. var sinAngle = Math.sin(angle);
  3754. if (!defined(result)) {
  3755. return new Matrix3(
  3756. 1.0, 0.0, 0.0,
  3757. 0.0, cosAngle, -sinAngle,
  3758. 0.0, sinAngle, cosAngle);
  3759. }
  3760. result[0] = 1.0;
  3761. result[1] = 0.0;
  3762. result[2] = 0.0;
  3763. result[3] = 0.0;
  3764. result[4] = cosAngle;
  3765. result[5] = sinAngle;
  3766. result[6] = 0.0;
  3767. result[7] = -sinAngle;
  3768. result[8] = cosAngle;
  3769. return result;
  3770. };
  3771. /**
  3772. * Creates a rotation matrix around the y-axis.
  3773. *
  3774. * @param {Number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
  3775. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3776. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3777. *
  3778. * @example
  3779. * // Rotate a point 45 degrees counterclockwise around the y-axis.
  3780. * var p = new Cesium.Cartesian3(5, 6, 7);
  3781. * var m = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(45.0));
  3782. * var rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
  3783. */
  3784. Matrix3.fromRotationY = function(angle, result) {
  3785. if (!defined(angle)) {
  3786. throw new DeveloperError('angle is required.');
  3787. }
  3788. var cosAngle = Math.cos(angle);
  3789. var sinAngle = Math.sin(angle);
  3790. if (!defined(result)) {
  3791. return new Matrix3(
  3792. cosAngle, 0.0, sinAngle,
  3793. 0.0, 1.0, 0.0,
  3794. -sinAngle, 0.0, cosAngle);
  3795. }
  3796. result[0] = cosAngle;
  3797. result[1] = 0.0;
  3798. result[2] = -sinAngle;
  3799. result[3] = 0.0;
  3800. result[4] = 1.0;
  3801. result[5] = 0.0;
  3802. result[6] = sinAngle;
  3803. result[7] = 0.0;
  3804. result[8] = cosAngle;
  3805. return result;
  3806. };
  3807. /**
  3808. * Creates a rotation matrix around the z-axis.
  3809. *
  3810. * @param {Number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
  3811. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3812. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3813. *
  3814. * @example
  3815. * // Rotate a point 45 degrees counterclockwise around the z-axis.
  3816. * var p = new Cesium.Cartesian3(5, 6, 7);
  3817. * var m = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(45.0));
  3818. * var rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
  3819. */
  3820. Matrix3.fromRotationZ = function(angle, result) {
  3821. if (!defined(angle)) {
  3822. throw new DeveloperError('angle is required.');
  3823. }
  3824. var cosAngle = Math.cos(angle);
  3825. var sinAngle = Math.sin(angle);
  3826. if (!defined(result)) {
  3827. return new Matrix3(
  3828. cosAngle, -sinAngle, 0.0,
  3829. sinAngle, cosAngle, 0.0,
  3830. 0.0, 0.0, 1.0);
  3831. }
  3832. result[0] = cosAngle;
  3833. result[1] = sinAngle;
  3834. result[2] = 0.0;
  3835. result[3] = -sinAngle;
  3836. result[4] = cosAngle;
  3837. result[5] = 0.0;
  3838. result[6] = 0.0;
  3839. result[7] = 0.0;
  3840. result[8] = 1.0;
  3841. return result;
  3842. };
  3843. /**
  3844. * Creates an Array from the provided Matrix3 instance.
  3845. * The array will be in column-major order.
  3846. *
  3847. * @param {Matrix3} matrix The matrix to use..
  3848. * @param {Number[]} [result] The Array onto which to store the result.
  3849. * @returns {Number[]} The modified Array parameter or a new Array instance if one was not provided.
  3850. */
  3851. Matrix3.toArray = function(matrix, result) {
  3852. if (!defined(matrix)) {
  3853. throw new DeveloperError('matrix is required');
  3854. }
  3855. if (!defined(result)) {
  3856. return [matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5], matrix[6], matrix[7], matrix[8]];
  3857. }
  3858. result[0] = matrix[0];
  3859. result[1] = matrix[1];
  3860. result[2] = matrix[2];
  3861. result[3] = matrix[3];
  3862. result[4] = matrix[4];
  3863. result[5] = matrix[5];
  3864. result[6] = matrix[6];
  3865. result[7] = matrix[7];
  3866. result[8] = matrix[8];
  3867. return result;
  3868. };
  3869. /**
  3870. * Computes the array index of the element at the provided row and column.
  3871. *
  3872. * @param {Number} row The zero-based index of the row.
  3873. * @param {Number} column The zero-based index of the column.
  3874. * @returns {Number} The index of the element at the provided row and column.
  3875. *
  3876. * @exception {DeveloperError} row must be 0, 1, or 2.
  3877. * @exception {DeveloperError} column must be 0, 1, or 2.
  3878. *
  3879. * @example
  3880. * var myMatrix = new Cesium.Matrix3();
  3881. * var column1Row0Index = Cesium.Matrix3.getElementIndex(1, 0);
  3882. * var column1Row0 = myMatrix[column1Row0Index]
  3883. * myMatrix[column1Row0Index] = 10.0;
  3884. */
  3885. Matrix3.getElementIndex = function(column, row) {
  3886. if (typeof row !== 'number' || row < 0 || row > 2) {
  3887. throw new DeveloperError('row must be 0, 1, or 2.');
  3888. }
  3889. if (typeof column !== 'number' || column < 0 || column > 2) {
  3890. throw new DeveloperError('column must be 0, 1, or 2.');
  3891. }
  3892. return column * 3 + row;
  3893. };
  3894. /**
  3895. * Retrieves a copy of the matrix column at the provided index as a Cartesian3 instance.
  3896. *
  3897. * @param {Matrix3} matrix The matrix to use.
  3898. * @param {Number} index The zero-based index of the column to retrieve.
  3899. * @param {Cartesian3} result The object onto which to store the result.
  3900. * @returns {Cartesian3} The modified result parameter.
  3901. *
  3902. * @exception {DeveloperError} index must be 0, 1, or 2.
  3903. */
  3904. Matrix3.getColumn = function(matrix, index, result) {
  3905. if (!defined(matrix)) {
  3906. throw new DeveloperError('matrix is required.');
  3907. }
  3908. if (typeof index !== 'number' || index < 0 || index > 2) {
  3909. throw new DeveloperError('index must be 0, 1, or 2.');
  3910. }
  3911. if (!defined(result)) {
  3912. throw new DeveloperError('result is required');
  3913. }
  3914. var startIndex = index * 3;
  3915. var x = matrix[startIndex];
  3916. var y = matrix[startIndex + 1];
  3917. var z = matrix[startIndex + 2];
  3918. result.x = x;
  3919. result.y = y;
  3920. result.z = z;
  3921. return result;
  3922. };
  3923. /**
  3924. * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian3 instance.
  3925. *
  3926. * @param {Matrix3} matrix The matrix to use.
  3927. * @param {Number} index The zero-based index of the column to set.
  3928. * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified column.
  3929. * @param {Matrix3} result The object onto which to store the result.
  3930. * @returns {Matrix3} The modified result parameter.
  3931. *
  3932. * @exception {DeveloperError} index must be 0, 1, or 2.
  3933. */
  3934. Matrix3.setColumn = function(matrix, index, cartesian, result) {
  3935. if (!defined(matrix)) {
  3936. throw new DeveloperError('matrix is required');
  3937. }
  3938. if (!defined(cartesian)) {
  3939. throw new DeveloperError('cartesian is required');
  3940. }
  3941. if (typeof index !== 'number' || index < 0 || index > 2) {
  3942. throw new DeveloperError('index must be 0, 1, or 2.');
  3943. }
  3944. if (!defined(result)) {
  3945. throw new DeveloperError('result is required');
  3946. }
  3947. result = Matrix3.clone(matrix, result);
  3948. var startIndex = index * 3;
  3949. result[startIndex] = cartesian.x;
  3950. result[startIndex + 1] = cartesian.y;
  3951. result[startIndex + 2] = cartesian.z;
  3952. return result;
  3953. };
  3954. /**
  3955. * Retrieves a copy of the matrix row at the provided index as a Cartesian3 instance.
  3956. *
  3957. * @param {Matrix3} matrix The matrix to use.
  3958. * @param {Number} index The zero-based index of the row to retrieve.
  3959. * @param {Cartesian3} result The object onto which to store the result.
  3960. * @returns {Cartesian3} The modified result parameter.
  3961. *
  3962. * @exception {DeveloperError} index must be 0, 1, or 2.
  3963. */
  3964. Matrix3.getRow = function(matrix, index, result) {
  3965. if (!defined(matrix)) {
  3966. throw new DeveloperError('matrix is required.');
  3967. }
  3968. if (typeof index !== 'number' || index < 0 || index > 2) {
  3969. throw new DeveloperError('index must be 0, 1, or 2.');
  3970. }
  3971. if (!defined(result)) {
  3972. throw new DeveloperError('result is required');
  3973. }
  3974. var x = matrix[index];
  3975. var y = matrix[index + 3];
  3976. var z = matrix[index + 6];
  3977. result.x = x;
  3978. result.y = y;
  3979. result.z = z;
  3980. return result;
  3981. };
  3982. /**
  3983. * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian3 instance.
  3984. *
  3985. * @param {Matrix3} matrix The matrix to use.
  3986. * @param {Number} index The zero-based index of the row to set.
  3987. * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified row.
  3988. * @param {Matrix3} result The object onto which to store the result.
  3989. * @returns {Matrix3} The modified result parameter.
  3990. *
  3991. * @exception {DeveloperError} index must be 0, 1, or 2.
  3992. */
  3993. Matrix3.setRow = function(matrix, index, cartesian, result) {
  3994. if (!defined(matrix)) {
  3995. throw new DeveloperError('matrix is required');
  3996. }
  3997. if (!defined(cartesian)) {
  3998. throw new DeveloperError('cartesian is required');
  3999. }
  4000. if (typeof index !== 'number' || index < 0 || index > 2) {
  4001. throw new DeveloperError('index must be 0, 1, or 2.');
  4002. }
  4003. if (!defined(result)) {
  4004. throw new DeveloperError('result is required');
  4005. }
  4006. result = Matrix3.clone(matrix, result);
  4007. result[index] = cartesian.x;
  4008. result[index + 3] = cartesian.y;
  4009. result[index + 6] = cartesian.z;
  4010. return result;
  4011. };
  4012. var scratchColumn = new Cartesian3();
  4013. /**
  4014. * Extracts the non-uniform scale assuming the matrix is an affine transformation.
  4015. *
  4016. * @param {Matrix3} matrix The matrix.
  4017. * @param {Cartesian3} result The object onto which to store the result.
  4018. * @returns {Cartesian3} The modified result parameter.
  4019. */
  4020. Matrix3.getScale = function(matrix, result) {
  4021. if (!defined(matrix)) {
  4022. throw new DeveloperError('matrix is required.');
  4023. }
  4024. if (!defined(result)) {
  4025. throw new DeveloperError('result is required');
  4026. }
  4027. result.x = Cartesian3.magnitude(Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn));
  4028. result.y = Cartesian3.magnitude(Cartesian3.fromElements(matrix[3], matrix[4], matrix[5], scratchColumn));
  4029. result.z = Cartesian3.magnitude(Cartesian3.fromElements(matrix[6], matrix[7], matrix[8], scratchColumn));
  4030. return result;
  4031. };
  4032. var scratchScale = new Cartesian3();
  4033. /**
  4034. * Computes the maximum scale assuming the matrix is an affine transformation.
  4035. * The maximum scale is the maximum length of the column vectors.
  4036. *
  4037. * @param {Matrix3} matrix The matrix.
  4038. * @returns {Number} The maximum scale.
  4039. */
  4040. Matrix3.getMaximumScale = function(matrix) {
  4041. Matrix3.getScale(matrix, scratchScale);
  4042. return Cartesian3.maximumComponent(scratchScale);
  4043. };
  4044. /**
  4045. * Computes the product of two matrices.
  4046. *
  4047. * @param {Matrix3} left The first matrix.
  4048. * @param {Matrix3} right The second matrix.
  4049. * @param {Matrix3} result The object onto which to store the result.
  4050. * @returns {Matrix3} The modified result parameter.
  4051. */
  4052. Matrix3.multiply = function(left, right, result) {
  4053. if (!defined(left)) {
  4054. throw new DeveloperError('left is required');
  4055. }
  4056. if (!defined(right)) {
  4057. throw new DeveloperError('right is required');
  4058. }
  4059. if (!defined(result)) {
  4060. throw new DeveloperError('result is required');
  4061. }
  4062. var column0Row0 = left[0] * right[0] + left[3] * right[1] + left[6] * right[2];
  4063. var column0Row1 = left[1] * right[0] + left[4] * right[1] + left[7] * right[2];
  4064. var column0Row2 = left[2] * right[0] + left[5] * right[1] + left[8] * right[2];
  4065. var column1Row0 = left[0] * right[3] + left[3] * right[4] + left[6] * right[5];
  4066. var column1Row1 = left[1] * right[3] + left[4] * right[4] + left[7] * right[5];
  4067. var column1Row2 = left[2] * right[3] + left[5] * right[4] + left[8] * right[5];
  4068. var column2Row0 = left[0] * right[6] + left[3] * right[7] + left[6] * right[8];
  4069. var column2Row1 = left[1] * right[6] + left[4] * right[7] + left[7] * right[8];
  4070. var column2Row2 = left[2] * right[6] + left[5] * right[7] + left[8] * right[8];
  4071. result[0] = column0Row0;
  4072. result[1] = column0Row1;
  4073. result[2] = column0Row2;
  4074. result[3] = column1Row0;
  4075. result[4] = column1Row1;
  4076. result[5] = column1Row2;
  4077. result[6] = column2Row0;
  4078. result[7] = column2Row1;
  4079. result[8] = column2Row2;
  4080. return result;
  4081. };
  4082. /**
  4083. * Computes the sum of two matrices.
  4084. *
  4085. * @param {Matrix3} left The first matrix.
  4086. * @param {Matrix3} right The second matrix.
  4087. * @param {Matrix3} result The object onto which to store the result.
  4088. * @returns {Matrix3} The modified result parameter.
  4089. */
  4090. Matrix3.add = function(left, right, result) {
  4091. if (!defined(left)) {
  4092. throw new DeveloperError('left is required');
  4093. }
  4094. if (!defined(right)) {
  4095. throw new DeveloperError('right is required');
  4096. }
  4097. if (!defined(result)) {
  4098. throw new DeveloperError('result is required');
  4099. }
  4100. result[0] = left[0] + right[0];
  4101. result[1] = left[1] + right[1];
  4102. result[2] = left[2] + right[2];
  4103. result[3] = left[3] + right[3];
  4104. result[4] = left[4] + right[4];
  4105. result[5] = left[5] + right[5];
  4106. result[6] = left[6] + right[6];
  4107. result[7] = left[7] + right[7];
  4108. result[8] = left[8] + right[8];
  4109. return result;
  4110. };
  4111. /**
  4112. * Computes the difference of two matrices.
  4113. *
  4114. * @param {Matrix3} left The first matrix.
  4115. * @param {Matrix3} right The second matrix.
  4116. * @param {Matrix3} result The object onto which to store the result.
  4117. * @returns {Matrix3} The modified result parameter.
  4118. */
  4119. Matrix3.subtract = function(left, right, result) {
  4120. if (!defined(left)) {
  4121. throw new DeveloperError('left is required');
  4122. }
  4123. if (!defined(right)) {
  4124. throw new DeveloperError('right is required');
  4125. }
  4126. if (!defined(result)) {
  4127. throw new DeveloperError('result is required');
  4128. }
  4129. result[0] = left[0] - right[0];
  4130. result[1] = left[1] - right[1];
  4131. result[2] = left[2] - right[2];
  4132. result[3] = left[3] - right[3];
  4133. result[4] = left[4] - right[4];
  4134. result[5] = left[5] - right[5];
  4135. result[6] = left[6] - right[6];
  4136. result[7] = left[7] - right[7];
  4137. result[8] = left[8] - right[8];
  4138. return result;
  4139. };
  4140. /**
  4141. * Computes the product of a matrix and a column vector.
  4142. *
  4143. * @param {Matrix3} matrix The matrix.
  4144. * @param {Cartesian3} cartesian The column.
  4145. * @param {Cartesian3} result The object onto which to store the result.
  4146. * @returns {Cartesian3} The modified result parameter.
  4147. */
  4148. Matrix3.multiplyByVector = function(matrix, cartesian, result) {
  4149. if (!defined(matrix)) {
  4150. throw new DeveloperError('matrix is required');
  4151. }
  4152. if (!defined(cartesian)) {
  4153. throw new DeveloperError('cartesian is required');
  4154. }
  4155. if (!defined(result)) {
  4156. throw new DeveloperError('result is required');
  4157. }
  4158. var vX = cartesian.x;
  4159. var vY = cartesian.y;
  4160. var vZ = cartesian.z;
  4161. var x = matrix[0] * vX + matrix[3] * vY + matrix[6] * vZ;
  4162. var y = matrix[1] * vX + matrix[4] * vY + matrix[7] * vZ;
  4163. var z = matrix[2] * vX + matrix[5] * vY + matrix[8] * vZ;
  4164. result.x = x;
  4165. result.y = y;
  4166. result.z = z;
  4167. return result;
  4168. };
  4169. /**
  4170. * Computes the product of a matrix and a scalar.
  4171. *
  4172. * @param {Matrix3} matrix The matrix.
  4173. * @param {Number} scalar The number to multiply by.
  4174. * @param {Matrix3} result The object onto which to store the result.
  4175. * @returns {Matrix3} The modified result parameter.
  4176. */
  4177. Matrix3.multiplyByScalar = function(matrix, scalar, result) {
  4178. if (!defined(matrix)) {
  4179. throw new DeveloperError('matrix is required');
  4180. }
  4181. if (typeof scalar !== 'number') {
  4182. throw new DeveloperError('scalar must be a number');
  4183. }
  4184. if (!defined(result)) {
  4185. throw new DeveloperError('result is required');
  4186. }
  4187. result[0] = matrix[0] * scalar;
  4188. result[1] = matrix[1] * scalar;
  4189. result[2] = matrix[2] * scalar;
  4190. result[3] = matrix[3] * scalar;
  4191. result[4] = matrix[4] * scalar;
  4192. result[5] = matrix[5] * scalar;
  4193. result[6] = matrix[6] * scalar;
  4194. result[7] = matrix[7] * scalar;
  4195. result[8] = matrix[8] * scalar;
  4196. return result;
  4197. };
  4198. /**
  4199. * Computes the product of a matrix times a (non-uniform) scale, as if the scale were a scale matrix.
  4200. *
  4201. * @param {Matrix3} matrix The matrix on the left-hand side.
  4202. * @param {Cartesian3} scale The non-uniform scale on the right-hand side.
  4203. * @param {Matrix3} result The object onto which to store the result.
  4204. * @returns {Matrix3} The modified result parameter.
  4205. *
  4206. *
  4207. * @example
  4208. * // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromScale(scale), m);
  4209. * Cesium.Matrix3.multiplyByScale(m, scale, m);
  4210. *
  4211. * @see Matrix3.fromScale
  4212. * @see Matrix3.multiplyByUniformScale
  4213. */
  4214. Matrix3.multiplyByScale = function(matrix, scale, result) {
  4215. if (!defined(matrix)) {
  4216. throw new DeveloperError('matrix is required');
  4217. }
  4218. if (!defined(scale)) {
  4219. throw new DeveloperError('scale is required');
  4220. }
  4221. if (!defined(result)) {
  4222. throw new DeveloperError('result is required');
  4223. }
  4224. result[0] = matrix[0] * scale.x;
  4225. result[1] = matrix[1] * scale.x;
  4226. result[2] = matrix[2] * scale.x;
  4227. result[3] = matrix[3] * scale.y;
  4228. result[4] = matrix[4] * scale.y;
  4229. result[5] = matrix[5] * scale.y;
  4230. result[6] = matrix[6] * scale.z;
  4231. result[7] = matrix[7] * scale.z;
  4232. result[8] = matrix[8] * scale.z;
  4233. return result;
  4234. };
  4235. /**
  4236. * Creates a negated copy of the provided matrix.
  4237. *
  4238. * @param {Matrix3} matrix The matrix to negate.
  4239. * @param {Matrix3} result The object onto which to store the result.
  4240. * @returns {Matrix3} The modified result parameter.
  4241. */
  4242. Matrix3.negate = function(matrix, result) {
  4243. if (!defined(matrix)) {
  4244. throw new DeveloperError('matrix is required');
  4245. }
  4246. if (!defined(result)) {
  4247. throw new DeveloperError('result is required');
  4248. }
  4249. result[0] = -matrix[0];
  4250. result[1] = -matrix[1];
  4251. result[2] = -matrix[2];
  4252. result[3] = -matrix[3];
  4253. result[4] = -matrix[4];
  4254. result[5] = -matrix[5];
  4255. result[6] = -matrix[6];
  4256. result[7] = -matrix[7];
  4257. result[8] = -matrix[8];
  4258. return result;
  4259. };
  4260. /**
  4261. * Computes the transpose of the provided matrix.
  4262. *
  4263. * @param {Matrix3} matrix The matrix to transpose.
  4264. * @param {Matrix3} result The object onto which to store the result.
  4265. * @returns {Matrix3} The modified result parameter.
  4266. */
  4267. Matrix3.transpose = function(matrix, result) {
  4268. if (!defined(matrix)) {
  4269. throw new DeveloperError('matrix is required');
  4270. }
  4271. if (!defined(result)) {
  4272. throw new DeveloperError('result is required');
  4273. }
  4274. var column0Row0 = matrix[0];
  4275. var column0Row1 = matrix[3];
  4276. var column0Row2 = matrix[6];
  4277. var column1Row0 = matrix[1];
  4278. var column1Row1 = matrix[4];
  4279. var column1Row2 = matrix[7];
  4280. var column2Row0 = matrix[2];
  4281. var column2Row1 = matrix[5];
  4282. var column2Row2 = matrix[8];
  4283. result[0] = column0Row0;
  4284. result[1] = column0Row1;
  4285. result[2] = column0Row2;
  4286. result[3] = column1Row0;
  4287. result[4] = column1Row1;
  4288. result[5] = column1Row2;
  4289. result[6] = column2Row0;
  4290. result[7] = column2Row1;
  4291. result[8] = column2Row2;
  4292. return result;
  4293. };
  4294. function computeFrobeniusNorm(matrix) {
  4295. var norm = 0.0;
  4296. for (var i = 0; i < 9; ++i) {
  4297. var temp = matrix[i];
  4298. norm += temp * temp;
  4299. }
  4300. return Math.sqrt(norm);
  4301. }
  4302. var rowVal = [1, 0, 0];
  4303. var colVal = [2, 2, 1];
  4304. function offDiagonalFrobeniusNorm(matrix) {
  4305. // Computes the "off-diagonal" Frobenius norm.
  4306. // Assumes matrix is symmetric.
  4307. var norm = 0.0;
  4308. for (var i = 0; i < 3; ++i) {
  4309. var temp = matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])];
  4310. norm += 2.0 * temp * temp;
  4311. }
  4312. return Math.sqrt(norm);
  4313. }
  4314. function shurDecomposition(matrix, result) {
  4315. // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,
  4316. // section 8.4.2 The 2by2 Symmetric Schur Decomposition.
  4317. //
  4318. // The routine takes a matrix, which is assumed to be symmetric, and
  4319. // finds the largest off-diagonal term, and then creates
  4320. // a matrix (result) which can be used to help reduce it
  4321. var tolerance = CesiumMath.EPSILON15;
  4322. var maxDiagonal = 0.0;
  4323. var rotAxis = 1;
  4324. // find pivot (rotAxis) based on max diagonal of matrix
  4325. for (var i = 0; i < 3; ++i) {
  4326. var temp = Math.abs(matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])]);
  4327. if (temp > maxDiagonal) {
  4328. rotAxis = i;
  4329. maxDiagonal = temp;
  4330. }
  4331. }
  4332. var c = 1.0;
  4333. var s = 0.0;
  4334. var p = rowVal[rotAxis];
  4335. var q = colVal[rotAxis];
  4336. if (Math.abs(matrix[Matrix3.getElementIndex(q, p)]) > tolerance) {
  4337. var qq = matrix[Matrix3.getElementIndex(q, q)];
  4338. var pp = matrix[Matrix3.getElementIndex(p, p)];
  4339. var qp = matrix[Matrix3.getElementIndex(q, p)];
  4340. var tau = (qq - pp) / 2.0 / qp;
  4341. var t;
  4342. if (tau < 0.0) {
  4343. t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));
  4344. } else {
  4345. t = 1.0 / (tau + Math.sqrt(1.0 + tau * tau));
  4346. }
  4347. c = 1.0 / Math.sqrt(1.0 + t * t);
  4348. s = t * c;
  4349. }
  4350. result = Matrix3.clone(Matrix3.IDENTITY, result);
  4351. result[Matrix3.getElementIndex(p, p)] = result[Matrix3.getElementIndex(q, q)] = c;
  4352. result[Matrix3.getElementIndex(q, p)] = s;
  4353. result[Matrix3.getElementIndex(p, q)] = -s;
  4354. return result;
  4355. }
  4356. var jMatrix = new Matrix3();
  4357. var jMatrixTranspose = new Matrix3();
  4358. /**
  4359. * Computes the eigenvectors and eigenvalues of a symmetric matrix.
  4360. * <p>
  4361. * Returns a diagonal matrix and unitary matrix such that:
  4362. * <code>matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)</code>
  4363. * </p>
  4364. * <p>
  4365. * The values along the diagonal of the diagonal matrix are the eigenvalues. The columns
  4366. * of the unitary matrix are the corresponding eigenvectors.
  4367. * </p>
  4368. *
  4369. * @param {Matrix3} matrix The matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.
  4370. * @param {Object} [result] An object with unitary and diagonal properties which are matrices onto which to store the result.
  4371. * @returns {Object} An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.
  4372. *
  4373. * @example
  4374. * var a = //... symetric matrix
  4375. * var result = {
  4376. * unitary : new Cesium.Matrix3(),
  4377. * diagonal : new Cesium.Matrix3()
  4378. * };
  4379. * Cesium.Matrix3.computeEigenDecomposition(a, result);
  4380. *
  4381. * var unitaryTranspose = Cesium.Matrix3.transpose(result.unitary, new Cesium.Matrix3());
  4382. * var b = Cesium.Matrix3.multiply(result.unitary, result.diagonal, new Cesium.Matrix3());
  4383. * Cesium.Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a
  4384. *
  4385. * var lambda = Cesium.Matrix3.getColumn(result.diagonal, 0, new Cesium.Cartesian3()).x; // first eigenvalue
  4386. * var v = Cesium.Matrix3.getColumn(result.unitary, 0, new Cesium.Cartesian3()); // first eigenvector
  4387. * var c = Cesium.Cartesian3.multiplyByScalar(v, lambda, new Cesium.Cartesian3()); // equal to Cesium.Matrix3.multiplyByVector(a, v)
  4388. */
  4389. Matrix3.computeEigenDecomposition = function(matrix, result) {
  4390. if (!defined(matrix)) {
  4391. throw new DeveloperError('matrix is required.');
  4392. }
  4393. // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,
  4394. // section 8.4.3 The Classical Jacobi Algorithm
  4395. var tolerance = CesiumMath.EPSILON20;
  4396. var maxSweeps = 10;
  4397. var count = 0;
  4398. var sweep = 0;
  4399. if (!defined(result)) {
  4400. result = {};
  4401. }
  4402. var unitaryMatrix = result.unitary = Matrix3.clone(Matrix3.IDENTITY, result.unitary);
  4403. var diagMatrix = result.diagonal = Matrix3.clone(matrix, result.diagonal);
  4404. var epsilon = tolerance * computeFrobeniusNorm(diagMatrix);
  4405. while (sweep < maxSweeps && offDiagonalFrobeniusNorm(diagMatrix) > epsilon) {
  4406. shurDecomposition(diagMatrix, jMatrix);
  4407. Matrix3.transpose(jMatrix, jMatrixTranspose);
  4408. Matrix3.multiply(diagMatrix, jMatrix, diagMatrix);
  4409. Matrix3.multiply(jMatrixTranspose, diagMatrix, diagMatrix);
  4410. Matrix3.multiply(unitaryMatrix, jMatrix, unitaryMatrix);
  4411. if (++count > 2) {
  4412. ++sweep;
  4413. count = 0;
  4414. }
  4415. }
  4416. return result;
  4417. };
  4418. /**
  4419. * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.
  4420. *
  4421. * @param {Matrix3} matrix The matrix with signed elements.
  4422. * @param {Matrix3} result The object onto which to store the result.
  4423. * @returns {Matrix3} The modified result parameter.
  4424. */
  4425. Matrix3.abs = function(matrix, result) {
  4426. if (!defined(matrix)) {
  4427. throw new DeveloperError('matrix is required');
  4428. }
  4429. if (!defined(result)) {
  4430. throw new DeveloperError('result is required');
  4431. }
  4432. result[0] = Math.abs(matrix[0]);
  4433. result[1] = Math.abs(matrix[1]);
  4434. result[2] = Math.abs(matrix[2]);
  4435. result[3] = Math.abs(matrix[3]);
  4436. result[4] = Math.abs(matrix[4]);
  4437. result[5] = Math.abs(matrix[5]);
  4438. result[6] = Math.abs(matrix[6]);
  4439. result[7] = Math.abs(matrix[7]);
  4440. result[8] = Math.abs(matrix[8]);
  4441. return result;
  4442. };
  4443. /**
  4444. * Computes the determinant of the provided matrix.
  4445. *
  4446. * @param {Matrix3} matrix The matrix to use.
  4447. * @returns {Number} The value of the determinant of the matrix.
  4448. */
  4449. Matrix3.determinant = function(matrix) {
  4450. if (!defined(matrix)) {
  4451. throw new DeveloperError('matrix is required');
  4452. }
  4453. var m11 = matrix[0];
  4454. var m21 = matrix[3];
  4455. var m31 = matrix[6];
  4456. var m12 = matrix[1];
  4457. var m22 = matrix[4];
  4458. var m32 = matrix[7];
  4459. var m13 = matrix[2];
  4460. var m23 = matrix[5];
  4461. var m33 = matrix[8];
  4462. return m11 * (m22 * m33 - m23 * m32) + m12 * (m23 * m31 - m21 * m33) + m13 * (m21 * m32 - m22 * m31);
  4463. };
  4464. /**
  4465. * Computes the inverse of the provided matrix.
  4466. *
  4467. * @param {Matrix3} matrix The matrix to invert.
  4468. * @param {Matrix3} result The object onto which to store the result.
  4469. * @returns {Matrix3} The modified result parameter.
  4470. *
  4471. * @exception {DeveloperError} matrix is not invertible.
  4472. */
  4473. Matrix3.inverse = function(matrix, result) {
  4474. if (!defined(matrix)) {
  4475. throw new DeveloperError('matrix is required');
  4476. }
  4477. if (!defined(result)) {
  4478. throw new DeveloperError('result is required');
  4479. }
  4480. var m11 = matrix[0];
  4481. var m21 = matrix[1];
  4482. var m31 = matrix[2];
  4483. var m12 = matrix[3];
  4484. var m22 = matrix[4];
  4485. var m32 = matrix[5];
  4486. var m13 = matrix[6];
  4487. var m23 = matrix[7];
  4488. var m33 = matrix[8];
  4489. var determinant = Matrix3.determinant(matrix);
  4490. if (Math.abs(determinant) <= CesiumMath.EPSILON15) {
  4491. throw new DeveloperError('matrix is not invertible');
  4492. }
  4493. result[0] = m22 * m33 - m23 * m32;
  4494. result[1] = m23 * m31 - m21 * m33;
  4495. result[2] = m21 * m32 - m22 * m31;
  4496. result[3] = m13 * m32 - m12 * m33;
  4497. result[4] = m11 * m33 - m13 * m31;
  4498. result[5] = m12 * m31 - m11 * m32;
  4499. result[6] = m12 * m23 - m13 * m22;
  4500. result[7] = m13 * m21 - m11 * m23;
  4501. result[8] = m11 * m22 - m12 * m21;
  4502. var scale = 1.0 / determinant;
  4503. return Matrix3.multiplyByScalar(result, scale, result);
  4504. };
  4505. /**
  4506. * Compares the provided matrices componentwise and returns
  4507. * <code>true</code> if they are equal, <code>false</code> otherwise.
  4508. *
  4509. * @param {Matrix3} [left] The first matrix.
  4510. * @param {Matrix3} [right] The second matrix.
  4511. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  4512. */
  4513. Matrix3.equals = function(left, right) {
  4514. return (left === right) ||
  4515. (defined(left) &&
  4516. defined(right) &&
  4517. left[0] === right[0] &&
  4518. left[1] === right[1] &&
  4519. left[2] === right[2] &&
  4520. left[3] === right[3] &&
  4521. left[4] === right[4] &&
  4522. left[5] === right[5] &&
  4523. left[6] === right[6] &&
  4524. left[7] === right[7] &&
  4525. left[8] === right[8]);
  4526. };
  4527. /**
  4528. * Compares the provided matrices componentwise and returns
  4529. * <code>true</code> if they are within the provided epsilon,
  4530. * <code>false</code> otherwise.
  4531. *
  4532. * @param {Matrix3} [left] The first matrix.
  4533. * @param {Matrix3} [right] The second matrix.
  4534. * @param {Number} epsilon The epsilon to use for equality testing.
  4535. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  4536. */
  4537. Matrix3.equalsEpsilon = function(left, right, epsilon) {
  4538. if (typeof epsilon !== 'number') {
  4539. throw new DeveloperError('epsilon must be a number');
  4540. }
  4541. return (left === right) ||
  4542. (defined(left) &&
  4543. defined(right) &&
  4544. Math.abs(left[0] - right[0]) <= epsilon &&
  4545. Math.abs(left[1] - right[1]) <= epsilon &&
  4546. Math.abs(left[2] - right[2]) <= epsilon &&
  4547. Math.abs(left[3] - right[3]) <= epsilon &&
  4548. Math.abs(left[4] - right[4]) <= epsilon &&
  4549. Math.abs(left[5] - right[5]) <= epsilon &&
  4550. Math.abs(left[6] - right[6]) <= epsilon &&
  4551. Math.abs(left[7] - right[7]) <= epsilon &&
  4552. Math.abs(left[8] - right[8]) <= epsilon);
  4553. };
  4554. /**
  4555. * An immutable Matrix3 instance initialized to the identity matrix.
  4556. *
  4557. * @type {Matrix3}
  4558. * @constant
  4559. */
  4560. Matrix3.IDENTITY = freezeObject(new Matrix3(1.0, 0.0, 0.0,
  4561. 0.0, 1.0, 0.0,
  4562. 0.0, 0.0, 1.0));
  4563. /**
  4564. * An immutable Matrix3 instance initialized to the zero matrix.
  4565. *
  4566. * @type {Matrix3}
  4567. * @constant
  4568. */
  4569. Matrix3.ZERO = freezeObject(new Matrix3(0.0, 0.0, 0.0,
  4570. 0.0, 0.0, 0.0,
  4571. 0.0, 0.0, 0.0));
  4572. /**
  4573. * The index into Matrix3 for column 0, row 0.
  4574. *
  4575. * @type {Number}
  4576. * @constant
  4577. */
  4578. Matrix3.COLUMN0ROW0 = 0;
  4579. /**
  4580. * The index into Matrix3 for column 0, row 1.
  4581. *
  4582. * @type {Number}
  4583. * @constant
  4584. */
  4585. Matrix3.COLUMN0ROW1 = 1;
  4586. /**
  4587. * The index into Matrix3 for column 0, row 2.
  4588. *
  4589. * @type {Number}
  4590. * @constant
  4591. */
  4592. Matrix3.COLUMN0ROW2 = 2;
  4593. /**
  4594. * The index into Matrix3 for column 1, row 0.
  4595. *
  4596. * @type {Number}
  4597. * @constant
  4598. */
  4599. Matrix3.COLUMN1ROW0 = 3;
  4600. /**
  4601. * The index into Matrix3 for column 1, row 1.
  4602. *
  4603. * @type {Number}
  4604. * @constant
  4605. */
  4606. Matrix3.COLUMN1ROW1 = 4;
  4607. /**
  4608. * The index into Matrix3 for column 1, row 2.
  4609. *
  4610. * @type {Number}
  4611. * @constant
  4612. */
  4613. Matrix3.COLUMN1ROW2 = 5;
  4614. /**
  4615. * The index into Matrix3 for column 2, row 0.
  4616. *
  4617. * @type {Number}
  4618. * @constant
  4619. */
  4620. Matrix3.COLUMN2ROW0 = 6;
  4621. /**
  4622. * The index into Matrix3 for column 2, row 1.
  4623. *
  4624. * @type {Number}
  4625. * @constant
  4626. */
  4627. Matrix3.COLUMN2ROW1 = 7;
  4628. /**
  4629. * The index into Matrix3 for column 2, row 2.
  4630. *
  4631. * @type {Number}
  4632. * @constant
  4633. */
  4634. Matrix3.COLUMN2ROW2 = 8;
  4635. defineProperties(Matrix3.prototype, {
  4636. /**
  4637. * Gets the number of items in the collection.
  4638. * @memberof Matrix3.prototype
  4639. *
  4640. * @type {Number}
  4641. */
  4642. length : {
  4643. get : function() {
  4644. return Matrix3.packedLength;
  4645. }
  4646. }
  4647. });
  4648. /**
  4649. * Duplicates the provided Matrix3 instance.
  4650. *
  4651. * @param {Matrix3} [result] The object onto which to store the result.
  4652. * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
  4653. */
  4654. Matrix3.prototype.clone = function(result) {
  4655. return Matrix3.clone(this, result);
  4656. };
  4657. /**
  4658. * Compares this matrix to the provided matrix componentwise and returns
  4659. * <code>true</code> if they are equal, <code>false</code> otherwise.
  4660. *
  4661. * @param {Matrix3} [right] The right hand side matrix.
  4662. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  4663. */
  4664. Matrix3.prototype.equals = function(right) {
  4665. return Matrix3.equals(this, right);
  4666. };
  4667. /**
  4668. * @private
  4669. */
  4670. Matrix3.equalsArray = function(matrix, array, offset) {
  4671. return matrix[0] === array[offset] &&
  4672. matrix[1] === array[offset + 1] &&
  4673. matrix[2] === array[offset + 2] &&
  4674. matrix[3] === array[offset + 3] &&
  4675. matrix[4] === array[offset + 4] &&
  4676. matrix[5] === array[offset + 5] &&
  4677. matrix[6] === array[offset + 6] &&
  4678. matrix[7] === array[offset + 7] &&
  4679. matrix[8] === array[offset + 8];
  4680. };
  4681. /**
  4682. * Compares this matrix to the provided matrix componentwise and returns
  4683. * <code>true</code> if they are within the provided epsilon,
  4684. * <code>false</code> otherwise.
  4685. *
  4686. * @param {Matrix3} [right] The right hand side matrix.
  4687. * @param {Number} epsilon The epsilon to use for equality testing.
  4688. * @returns {Boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
  4689. */
  4690. Matrix3.prototype.equalsEpsilon = function(right, epsilon) {
  4691. return Matrix3.equalsEpsilon(this, right, epsilon);
  4692. };
  4693. /**
  4694. * Creates a string representing this Matrix with each row being
  4695. * on a separate line and in the format '(column0, column1, column2)'.
  4696. *
  4697. * @returns {String} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2)'.
  4698. */
  4699. Matrix3.prototype.toString = function() {
  4700. return '(' + this[0] + ', ' + this[3] + ', ' + this[6] + ')\n' +
  4701. '(' + this[1] + ', ' + this[4] + ', ' + this[7] + ')\n' +
  4702. '(' + this[2] + ', ' + this[5] + ', ' + this[8] + ')';
  4703. };
  4704. return Matrix3;
  4705. });
  4706. /*global define*/
  4707. define('Core/Cartesian4',[
  4708. './defaultValue',
  4709. './defined',
  4710. './DeveloperError',
  4711. './freezeObject',
  4712. './Math'
  4713. ], function(
  4714. defaultValue,
  4715. defined,
  4716. DeveloperError,
  4717. freezeObject,
  4718. CesiumMath) {
  4719. 'use strict';
  4720. /**
  4721. * A 4D Cartesian point.
  4722. * @alias Cartesian4
  4723. * @constructor
  4724. *
  4725. * @param {Number} [x=0.0] The X component.
  4726. * @param {Number} [y=0.0] The Y component.
  4727. * @param {Number} [z=0.0] The Z component.
  4728. * @param {Number} [w=0.0] The W component.
  4729. *
  4730. * @see Cartesian2
  4731. * @see Cartesian3
  4732. * @see Packable
  4733. */
  4734. function Cartesian4(x, y, z, w) {
  4735. /**
  4736. * The X component.
  4737. * @type {Number}
  4738. * @default 0.0
  4739. */
  4740. this.x = defaultValue(x, 0.0);
  4741. /**
  4742. * The Y component.
  4743. * @type {Number}
  4744. * @default 0.0
  4745. */
  4746. this.y = defaultValue(y, 0.0);
  4747. /**
  4748. * The Z component.
  4749. * @type {Number}
  4750. * @default 0.0
  4751. */
  4752. this.z = defaultValue(z, 0.0);
  4753. /**
  4754. * The W component.
  4755. * @type {Number}
  4756. * @default 0.0
  4757. */
  4758. this.w = defaultValue(w, 0.0);
  4759. }
  4760. /**
  4761. * Creates a Cartesian4 instance from x, y, z and w coordinates.
  4762. *
  4763. * @param {Number} x The x coordinate.
  4764. * @param {Number} y The y coordinate.
  4765. * @param {Number} z The z coordinate.
  4766. * @param {Number} w The w coordinate.
  4767. * @param {Cartesian4} [result] The object onto which to store the result.
  4768. * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
  4769. */
  4770. Cartesian4.fromElements = function(x, y, z, w, result) {
  4771. if (!defined(result)) {
  4772. return new Cartesian4(x, y, z, w);
  4773. }
  4774. result.x = x;
  4775. result.y = y;
  4776. result.z = z;
  4777. result.w = w;
  4778. return result;
  4779. };
  4780. /**
  4781. * Creates a Cartesian4 instance from a {@link Color}. <code>red</code>, <code>green</code>, <code>blue</code>,
  4782. * and <code>alpha</code> map to <code>x</code>, <code>y</code>, <code>z</code>, and <code>w</code>, respectively.
  4783. *
  4784. * @param {Color} color The source color.
  4785. * @param {Cartesian4} [result] The object onto which to store the result.
  4786. * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
  4787. */
  4788. Cartesian4.fromColor = function(color, result) {
  4789. if (!defined(color)) {
  4790. throw new DeveloperError('color is required');
  4791. }
  4792. if (!defined(result)) {
  4793. return new Cartesian4(color.red, color.green, color.blue, color.alpha);
  4794. }
  4795. result.x = color.red;
  4796. result.y = color.green;
  4797. result.z = color.blue;
  4798. result.w = color.alpha;
  4799. return result;
  4800. };
  4801. /**
  4802. * Duplicates a Cartesian4 instance.
  4803. *
  4804. * @param {Cartesian4} cartesian The Cartesian to duplicate.
  4805. * @param {Cartesian4} [result] The object onto which to store the result.
  4806. * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided. (Returns undefined if cartesian is undefined)
  4807. */
  4808. Cartesian4.clone = function(cartesian, result) {
  4809. if (!defined(cartesian)) {
  4810. return undefined;
  4811. }
  4812. if (!defined(result)) {
  4813. return new Cartesian4(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
  4814. }
  4815. result.x = cartesian.x;
  4816. result.y = cartesian.y;
  4817. result.z = cartesian.z;
  4818. result.w = cartesian.w;
  4819. return result;
  4820. };
  4821. /**
  4822. * The number of elements used to pack the object into an array.
  4823. * @type {Number}
  4824. */
  4825. Cartesian4.packedLength = 4;
  4826. /**
  4827. * Stores the provided instance into the provided array.
  4828. *
  4829. * @param {Cartesian4} value The value to pack.
  4830. * @param {Number[]} array The array to pack into.
  4831. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  4832. *
  4833. * @returns {Number[]} The array that was packed into
  4834. */
  4835. Cartesian4.pack = function(value, array, startingIndex) {
  4836. if (!defined(value)) {
  4837. throw new DeveloperError('value is required');
  4838. }
  4839. if (!defined(array)) {
  4840. throw new DeveloperError('array is required');
  4841. }
  4842. startingIndex = defaultValue(startingIndex, 0);
  4843. array[startingIndex++] = value.x;
  4844. array[startingIndex++] = value.y;
  4845. array[startingIndex++] = value.z;
  4846. array[startingIndex] = value.w;
  4847. return array;
  4848. };
  4849. /**
  4850. * Retrieves an instance from a packed array.
  4851. *
  4852. * @param {Number[]} array The packed array.
  4853. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  4854. * @param {Cartesian4} [result] The object into which to store the result.
  4855. * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
  4856. */
  4857. Cartesian4.unpack = function(array, startingIndex, result) {
  4858. if (!defined(array)) {
  4859. throw new DeveloperError('array is required');
  4860. }
  4861. startingIndex = defaultValue(startingIndex, 0);
  4862. if (!defined(result)) {
  4863. result = new Cartesian4();
  4864. }
  4865. result.x = array[startingIndex++];
  4866. result.y = array[startingIndex++];
  4867. result.z = array[startingIndex++];
  4868. result.w = array[startingIndex];
  4869. return result;
  4870. };
  4871. /**
  4872. * Flattens an array of Cartesian4s into and array of components.
  4873. *
  4874. * @param {Cartesian4[]} array The array of cartesians to pack.
  4875. * @param {Number[]} result The array onto which to store the result.
  4876. * @returns {Number[]} The packed array.
  4877. */
  4878. Cartesian4.packArray = function(array, result) {
  4879. if (!defined(array)) {
  4880. throw new DeveloperError('array is required');
  4881. }
  4882. var length = array.length;
  4883. if (!defined(result)) {
  4884. result = new Array(length * 4);
  4885. } else {
  4886. result.length = length * 4;
  4887. }
  4888. for (var i = 0; i < length; ++i) {
  4889. Cartesian4.pack(array[i], result, i * 4);
  4890. }
  4891. return result;
  4892. };
  4893. /**
  4894. * Unpacks an array of cartesian components into and array of Cartesian4s.
  4895. *
  4896. * @param {Number[]} array The array of components to unpack.
  4897. * @param {Cartesian4[]} result The array onto which to store the result.
  4898. * @returns {Cartesian4[]} The unpacked array.
  4899. */
  4900. Cartesian4.unpackArray = function(array, result) {
  4901. if (!defined(array)) {
  4902. throw new DeveloperError('array is required');
  4903. }
  4904. var length = array.length;
  4905. if (!defined(result)) {
  4906. result = new Array(length / 4);
  4907. } else {
  4908. result.length = length / 4;
  4909. }
  4910. for (var i = 0; i < length; i += 4) {
  4911. var index = i / 4;
  4912. result[index] = Cartesian4.unpack(array, i, result[index]);
  4913. }
  4914. return result;
  4915. };
  4916. /**
  4917. * Creates a Cartesian4 from four consecutive elements in an array.
  4918. * @function
  4919. *
  4920. * @param {Number[]} array The array whose four consecutive elements correspond to the x, y, z, and w components, respectively.
  4921. * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.
  4922. * @param {Cartesian4} [result] The object onto which to store the result.
  4923. * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
  4924. *
  4925. * @example
  4926. * // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0)
  4927. * var v = [1.0, 2.0, 3.0, 4.0];
  4928. * var p = Cesium.Cartesian4.fromArray(v);
  4929. *
  4930. * // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0) using an offset into an array
  4931. * var v2 = [0.0, 0.0, 1.0, 2.0, 3.0, 4.0];
  4932. * var p2 = Cesium.Cartesian4.fromArray(v2, 2);
  4933. */
  4934. Cartesian4.fromArray = Cartesian4.unpack;
  4935. /**
  4936. * Computes the value of the maximum component for the supplied Cartesian.
  4937. *
  4938. * @param {Cartesian4} cartesian The cartesian to use.
  4939. * @returns {Number} The value of the maximum component.
  4940. */
  4941. Cartesian4.maximumComponent = function(cartesian) {
  4942. if (!defined(cartesian)) {
  4943. throw new DeveloperError('cartesian is required');
  4944. }
  4945. return Math.max(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
  4946. };
  4947. /**
  4948. * Computes the value of the minimum component for the supplied Cartesian.
  4949. *
  4950. * @param {Cartesian4} cartesian The cartesian to use.
  4951. * @returns {Number} The value of the minimum component.
  4952. */
  4953. Cartesian4.minimumComponent = function(cartesian) {
  4954. if (!defined(cartesian)) {
  4955. throw new DeveloperError('cartesian is required');
  4956. }
  4957. return Math.min(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
  4958. };
  4959. /**
  4960. * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
  4961. *
  4962. * @param {Cartesian4} first A cartesian to compare.
  4963. * @param {Cartesian4} second A cartesian to compare.
  4964. * @param {Cartesian4} result The object into which to store the result.
  4965. * @returns {Cartesian4} A cartesian with the minimum components.
  4966. */
  4967. Cartesian4.minimumByComponent = function(first, second, result) {
  4968. if (!defined(first)) {
  4969. throw new DeveloperError('first is required.');
  4970. }
  4971. if (!defined(second)) {
  4972. throw new DeveloperError('second is required.');
  4973. }
  4974. if (!defined(result)) {
  4975. throw new DeveloperError('result is required.');
  4976. }
  4977. result.x = Math.min(first.x, second.x);
  4978. result.y = Math.min(first.y, second.y);
  4979. result.z = Math.min(first.z, second.z);
  4980. result.w = Math.min(first.w, second.w);
  4981. return result;
  4982. };
  4983. /**
  4984. * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
  4985. *
  4986. * @param {Cartesian4} first A cartesian to compare.
  4987. * @param {Cartesian4} second A cartesian to compare.
  4988. * @param {Cartesian4} result The object into which to store the result.
  4989. * @returns {Cartesian4} A cartesian with the maximum components.
  4990. */
  4991. Cartesian4.maximumByComponent = function(first, second, result) {
  4992. if (!defined(first)) {
  4993. throw new DeveloperError('first is required.');
  4994. }
  4995. if (!defined(second)) {
  4996. throw new DeveloperError('second is required.');
  4997. }
  4998. if (!defined(result)) {
  4999. throw new DeveloperError('result is required.');
  5000. }
  5001. result.x = Math.max(first.x, second.x);
  5002. result.y = Math.max(first.y, second.y);
  5003. result.z = Math.max(first.z, second.z);
  5004. result.w = Math.max(first.w, second.w);
  5005. return result;
  5006. };
  5007. /**
  5008. * Computes the provided Cartesian's squared magnitude.
  5009. *
  5010. * @param {Cartesian4} cartesian The Cartesian instance whose squared magnitude is to be computed.
  5011. * @returns {Number} The squared magnitude.
  5012. */
  5013. Cartesian4.magnitudeSquared = function(cartesian) {
  5014. if (!defined(cartesian)) {
  5015. throw new DeveloperError('cartesian is required');
  5016. }
  5017. return cartesian.x * cartesian.x + cartesian.y * cartesian.y + cartesian.z * cartesian.z + cartesian.w * cartesian.w;
  5018. };
  5019. /**
  5020. * Computes the Cartesian's magnitude (length).
  5021. *
  5022. * @param {Cartesian4} cartesian The Cartesian instance whose magnitude is to be computed.
  5023. * @returns {Number} The magnitude.
  5024. */
  5025. Cartesian4.magnitude = function(cartesian) {
  5026. return Math.sqrt(Cartesian4.magnitudeSquared(cartesian));
  5027. };
  5028. var distanceScratch = new Cartesian4();
  5029. /**
  5030. * Computes the 4-space distance between two points.
  5031. *
  5032. * @param {Cartesian4} left The first point to compute the distance from.
  5033. * @param {Cartesian4} right The second point to compute the distance to.
  5034. * @returns {Number} The distance between two points.
  5035. *
  5036. * @example
  5037. * // Returns 1.0
  5038. * var d = Cesium.Cartesian4.distance(
  5039. * new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),
  5040. * new Cesium.Cartesian4(2.0, 0.0, 0.0, 0.0));
  5041. */
  5042. Cartesian4.distance = function(left, right) {
  5043. if (!defined(left) || !defined(right)) {
  5044. throw new DeveloperError('left and right are required.');
  5045. }
  5046. Cartesian4.subtract(left, right, distanceScratch);
  5047. return Cartesian4.magnitude(distanceScratch);
  5048. };
  5049. /**
  5050. * Computes the squared distance between two points. Comparing squared distances
  5051. * using this function is more efficient than comparing distances using {@link Cartesian4#distance}.
  5052. *
  5053. * @param {Cartesian4} left The first point to compute the distance from.
  5054. * @param {Cartesian4} right The second point to compute the distance to.
  5055. * @returns {Number} The distance between two points.
  5056. *
  5057. * @example
  5058. * // Returns 4.0, not 2.0
  5059. * var d = Cesium.Cartesian4.distance(
  5060. * new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),
  5061. * new Cesium.Cartesian4(3.0, 0.0, 0.0, 0.0));
  5062. */
  5063. Cartesian4.distanceSquared = function(left, right) {
  5064. if (!defined(left) || !defined(right)) {
  5065. throw new DeveloperError('left and right are required.');
  5066. }
  5067. Cartesian4.subtract(left, right, distanceScratch);
  5068. return Cartesian4.magnitudeSquared(distanceScratch);
  5069. };
  5070. /**
  5071. * Computes the normalized form of the supplied Cartesian.
  5072. *
  5073. * @param {Cartesian4} cartesian The Cartesian to be normalized.
  5074. * @param {Cartesian4} result The object onto which to store the result.
  5075. * @returns {Cartesian4} The modified result parameter.
  5076. */
  5077. Cartesian4.normalize = function(cartesian, result) {
  5078. if (!defined(cartesian)) {
  5079. throw new DeveloperError('cartesian is required');
  5080. }
  5081. if (!defined(result)) {
  5082. throw new DeveloperError('result is required');
  5083. }
  5084. var magnitude = Cartesian4.magnitude(cartesian);
  5085. result.x = cartesian.x / magnitude;
  5086. result.y = cartesian.y / magnitude;
  5087. result.z = cartesian.z / magnitude;
  5088. result.w = cartesian.w / magnitude;
  5089. if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z) || isNaN(result.w)) {
  5090. throw new DeveloperError('normalized result is not a number');
  5091. }
  5092. return result;
  5093. };
  5094. /**
  5095. * Computes the dot (scalar) product of two Cartesians.
  5096. *
  5097. * @param {Cartesian4} left The first Cartesian.
  5098. * @param {Cartesian4} right The second Cartesian.
  5099. * @returns {Number} The dot product.
  5100. */
  5101. Cartesian4.dot = function(left, right) {
  5102. if (!defined(left)) {
  5103. throw new DeveloperError('left is required');
  5104. }
  5105. if (!defined(right)) {
  5106. throw new DeveloperError('right is required');
  5107. }
  5108. return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
  5109. };
  5110. /**
  5111. * Computes the componentwise product of two Cartesians.
  5112. *
  5113. * @param {Cartesian4} left The first Cartesian.
  5114. * @param {Cartesian4} right The second Cartesian.
  5115. * @param {Cartesian4} result The object onto which to store the result.
  5116. * @returns {Cartesian4} The modified result parameter.
  5117. */
  5118. Cartesian4.multiplyComponents = function(left, right, result) {
  5119. if (!defined(left)) {
  5120. throw new DeveloperError('left is required');
  5121. }
  5122. if (!defined(right)) {
  5123. throw new DeveloperError('right is required');
  5124. }
  5125. if (!defined(result)) {
  5126. throw new DeveloperError('result is required');
  5127. }
  5128. result.x = left.x * right.x;
  5129. result.y = left.y * right.y;
  5130. result.z = left.z * right.z;
  5131. result.w = left.w * right.w;
  5132. return result;
  5133. };
  5134. /**
  5135. * Computes the componentwise quotient of two Cartesians.
  5136. *
  5137. * @param {Cartesian4} left The first Cartesian.
  5138. * @param {Cartesian4} right The second Cartesian.
  5139. * @param {Cartesian4} result The object onto which to store the result.
  5140. * @returns {Cartesian4} The modified result parameter.
  5141. */
  5142. Cartesian4.divideComponents = function(left, right, result) {
  5143. if (!defined(left)) {
  5144. throw new DeveloperError('left is required');
  5145. }
  5146. if (!defined(right)) {
  5147. throw new DeveloperError('right is required');
  5148. }
  5149. if (!defined(result)) {
  5150. throw new DeveloperError('result is required');
  5151. }
  5152. result.x = left.x / right.x;
  5153. result.y = left.y / right.y;
  5154. result.z = left.z / right.z;
  5155. result.w = left.w / right.w;
  5156. return result;
  5157. };
  5158. /**
  5159. * Computes the componentwise sum of two Cartesians.
  5160. *
  5161. * @param {Cartesian4} left The first Cartesian.
  5162. * @param {Cartesian4} right The second Cartesian.
  5163. * @param {Cartesian4} result The object onto which to store the result.
  5164. * @returns {Cartesian4} The modified result parameter.
  5165. */
  5166. Cartesian4.add = function(left, right, result) {
  5167. if (!defined(left)) {
  5168. throw new DeveloperError('left is required');
  5169. }
  5170. if (!defined(right)) {
  5171. throw new DeveloperError('right is required');
  5172. }
  5173. if (!defined(result)) {
  5174. throw new DeveloperError('result is required');
  5175. }
  5176. result.x = left.x + right.x;
  5177. result.y = left.y + right.y;
  5178. result.z = left.z + right.z;
  5179. result.w = left.w + right.w;
  5180. return result;
  5181. };
  5182. /**
  5183. * Computes the componentwise difference of two Cartesians.
  5184. *
  5185. * @param {Cartesian4} left The first Cartesian.
  5186. * @param {Cartesian4} right The second Cartesian.
  5187. * @param {Cartesian4} result The object onto which to store the result.
  5188. * @returns {Cartesian4} The modified result parameter.
  5189. */
  5190. Cartesian4.subtract = function(left, right, result) {
  5191. if (!defined(left)) {
  5192. throw new DeveloperError('left is required');
  5193. }
  5194. if (!defined(right)) {
  5195. throw new DeveloperError('right is required');
  5196. }
  5197. if (!defined(result)) {
  5198. throw new DeveloperError('result is required');
  5199. }
  5200. result.x = left.x - right.x;
  5201. result.y = left.y - right.y;
  5202. result.z = left.z - right.z;
  5203. result.w = left.w - right.w;
  5204. return result;
  5205. };
  5206. /**
  5207. * Multiplies the provided Cartesian componentwise by the provided scalar.
  5208. *
  5209. * @param {Cartesian4} cartesian The Cartesian to be scaled.
  5210. * @param {Number} scalar The scalar to multiply with.
  5211. * @param {Cartesian4} result The object onto which to store the result.
  5212. * @returns {Cartesian4} The modified result parameter.
  5213. */
  5214. Cartesian4.multiplyByScalar = function(cartesian, scalar, result) {
  5215. if (!defined(cartesian)) {
  5216. throw new DeveloperError('cartesian is required');
  5217. }
  5218. if (typeof scalar !== 'number') {
  5219. throw new DeveloperError('scalar is required and must be a number.');
  5220. }
  5221. if (!defined(result)) {
  5222. throw new DeveloperError('result is required');
  5223. }
  5224. result.x = cartesian.x * scalar;
  5225. result.y = cartesian.y * scalar;
  5226. result.z = cartesian.z * scalar;
  5227. result.w = cartesian.w * scalar;
  5228. return result;
  5229. };
  5230. /**
  5231. * Divides the provided Cartesian componentwise by the provided scalar.
  5232. *
  5233. * @param {Cartesian4} cartesian The Cartesian to be divided.
  5234. * @param {Number} scalar The scalar to divide by.
  5235. * @param {Cartesian4} result The object onto which to store the result.
  5236. * @returns {Cartesian4} The modified result parameter.
  5237. */
  5238. Cartesian4.divideByScalar = function(cartesian, scalar, result) {
  5239. if (!defined(cartesian)) {
  5240. throw new DeveloperError('cartesian is required');
  5241. }
  5242. if (typeof scalar !== 'number') {
  5243. throw new DeveloperError('scalar is required and must be a number.');
  5244. }
  5245. if (!defined(result)) {
  5246. throw new DeveloperError('result is required');
  5247. }
  5248. result.x = cartesian.x / scalar;
  5249. result.y = cartesian.y / scalar;
  5250. result.z = cartesian.z / scalar;
  5251. result.w = cartesian.w / scalar;
  5252. return result;
  5253. };
  5254. /**
  5255. * Negates the provided Cartesian.
  5256. *
  5257. * @param {Cartesian4} cartesian The Cartesian to be negated.
  5258. * @param {Cartesian4} result The object onto which to store the result.
  5259. * @returns {Cartesian4} The modified result parameter.
  5260. */
  5261. Cartesian4.negate = function(cartesian, result) {
  5262. if (!defined(cartesian)) {
  5263. throw new DeveloperError('cartesian is required');
  5264. }
  5265. if (!defined(result)) {
  5266. throw new DeveloperError('result is required');
  5267. }
  5268. result.x = -cartesian.x;
  5269. result.y = -cartesian.y;
  5270. result.z = -cartesian.z;
  5271. result.w = -cartesian.w;
  5272. return result;
  5273. };
  5274. /**
  5275. * Computes the absolute value of the provided Cartesian.
  5276. *
  5277. * @param {Cartesian4} cartesian The Cartesian whose absolute value is to be computed.
  5278. * @param {Cartesian4} result The object onto which to store the result.
  5279. * @returns {Cartesian4} The modified result parameter.
  5280. */
  5281. Cartesian4.abs = function(cartesian, result) {
  5282. if (!defined(cartesian)) {
  5283. throw new DeveloperError('cartesian is required');
  5284. }
  5285. if (!defined(result)) {
  5286. throw new DeveloperError('result is required');
  5287. }
  5288. result.x = Math.abs(cartesian.x);
  5289. result.y = Math.abs(cartesian.y);
  5290. result.z = Math.abs(cartesian.z);
  5291. result.w = Math.abs(cartesian.w);
  5292. return result;
  5293. };
  5294. var lerpScratch = new Cartesian4();
  5295. /**
  5296. * Computes the linear interpolation or extrapolation at t using the provided cartesians.
  5297. *
  5298. * @param {Cartesian4} start The value corresponding to t at 0.0.
  5299. * @param {Cartesian4}end The value corresponding to t at 1.0.
  5300. * @param {Number} t The point along t at which to interpolate.
  5301. * @param {Cartesian4} result The object onto which to store the result.
  5302. * @returns {Cartesian4} The modified result parameter.
  5303. */
  5304. Cartesian4.lerp = function(start, end, t, result) {
  5305. if (!defined(start)) {
  5306. throw new DeveloperError('start is required.');
  5307. }
  5308. if (!defined(end)) {
  5309. throw new DeveloperError('end is required.');
  5310. }
  5311. if (typeof t !== 'number') {
  5312. throw new DeveloperError('t is required and must be a number.');
  5313. }
  5314. if (!defined(result)) {
  5315. throw new DeveloperError('result is required.');
  5316. }
  5317. Cartesian4.multiplyByScalar(end, t, lerpScratch);
  5318. result = Cartesian4.multiplyByScalar(start, 1.0 - t, result);
  5319. return Cartesian4.add(lerpScratch, result, result);
  5320. };
  5321. var mostOrthogonalAxisScratch = new Cartesian4();
  5322. /**
  5323. * Returns the axis that is most orthogonal to the provided Cartesian.
  5324. *
  5325. * @param {Cartesian4} cartesian The Cartesian on which to find the most orthogonal axis.
  5326. * @param {Cartesian4} result The object onto which to store the result.
  5327. * @returns {Cartesian4} The most orthogonal axis.
  5328. */
  5329. Cartesian4.mostOrthogonalAxis = function(cartesian, result) {
  5330. if (!defined(cartesian)) {
  5331. throw new DeveloperError('cartesian is required.');
  5332. }
  5333. if (!defined(result)) {
  5334. throw new DeveloperError('result is required.');
  5335. }
  5336. var f = Cartesian4.normalize(cartesian, mostOrthogonalAxisScratch);
  5337. Cartesian4.abs(f, f);
  5338. if (f.x <= f.y) {
  5339. if (f.x <= f.z) {
  5340. if (f.x <= f.w) {
  5341. result = Cartesian4.clone(Cartesian4.UNIT_X, result);
  5342. } else {
  5343. result = Cartesian4.clone(Cartesian4.UNIT_W, result);
  5344. }
  5345. } else if (f.z <= f.w) {
  5346. result = Cartesian4.clone(Cartesian4.UNIT_Z, result);
  5347. } else {
  5348. result = Cartesian4.clone(Cartesian4.UNIT_W, result);
  5349. }
  5350. } else if (f.y <= f.z) {
  5351. if (f.y <= f.w) {
  5352. result = Cartesian4.clone(Cartesian4.UNIT_Y, result);
  5353. } else {
  5354. result = Cartesian4.clone(Cartesian4.UNIT_W, result);
  5355. }
  5356. } else if (f.z <= f.w) {
  5357. result = Cartesian4.clone(Cartesian4.UNIT_Z, result);
  5358. } else {
  5359. result = Cartesian4.clone(Cartesian4.UNIT_W, result);
  5360. }
  5361. return result;
  5362. };
  5363. /**
  5364. * Compares the provided Cartesians componentwise and returns
  5365. * <code>true</code> if they are equal, <code>false</code> otherwise.
  5366. *
  5367. * @param {Cartesian4} [left] The first Cartesian.
  5368. * @param {Cartesian4} [right] The second Cartesian.
  5369. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  5370. */
  5371. Cartesian4.equals = function(left, right) {
  5372. return (left === right) ||
  5373. ((defined(left)) &&
  5374. (defined(right)) &&
  5375. (left.x === right.x) &&
  5376. (left.y === right.y) &&
  5377. (left.z === right.z) &&
  5378. (left.w === right.w));
  5379. };
  5380. /**
  5381. * @private
  5382. */
  5383. Cartesian4.equalsArray = function(cartesian, array, offset) {
  5384. return cartesian.x === array[offset] &&
  5385. cartesian.y === array[offset + 1] &&
  5386. cartesian.z === array[offset + 2] &&
  5387. cartesian.w === array[offset + 3];
  5388. };
  5389. /**
  5390. * Compares the provided Cartesians componentwise and returns
  5391. * <code>true</code> if they pass an absolute or relative tolerance test,
  5392. * <code>false</code> otherwise.
  5393. *
  5394. * @param {Cartesian4} [left] The first Cartesian.
  5395. * @param {Cartesian4} [right] The second Cartesian.
  5396. * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
  5397. * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  5398. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  5399. */
  5400. Cartesian4.equalsEpsilon = function(left, right, relativeEpsilon, absoluteEpsilon) {
  5401. return (left === right) ||
  5402. (defined(left) &&
  5403. defined(right) &&
  5404. CesiumMath.equalsEpsilon(left.x, right.x, relativeEpsilon, absoluteEpsilon) &&
  5405. CesiumMath.equalsEpsilon(left.y, right.y, relativeEpsilon, absoluteEpsilon) &&
  5406. CesiumMath.equalsEpsilon(left.z, right.z, relativeEpsilon, absoluteEpsilon) &&
  5407. CesiumMath.equalsEpsilon(left.w, right.w, relativeEpsilon, absoluteEpsilon));
  5408. };
  5409. /**
  5410. * An immutable Cartesian4 instance initialized to (0.0, 0.0, 0.0, 0.0).
  5411. *
  5412. * @type {Cartesian4}
  5413. * @constant
  5414. */
  5415. Cartesian4.ZERO = freezeObject(new Cartesian4(0.0, 0.0, 0.0, 0.0));
  5416. /**
  5417. * An immutable Cartesian4 instance initialized to (1.0, 0.0, 0.0, 0.0).
  5418. *
  5419. * @type {Cartesian4}
  5420. * @constant
  5421. */
  5422. Cartesian4.UNIT_X = freezeObject(new Cartesian4(1.0, 0.0, 0.0, 0.0));
  5423. /**
  5424. * An immutable Cartesian4 instance initialized to (0.0, 1.0, 0.0, 0.0).
  5425. *
  5426. * @type {Cartesian4}
  5427. * @constant
  5428. */
  5429. Cartesian4.UNIT_Y = freezeObject(new Cartesian4(0.0, 1.0, 0.0, 0.0));
  5430. /**
  5431. * An immutable Cartesian4 instance initialized to (0.0, 0.0, 1.0, 0.0).
  5432. *
  5433. * @type {Cartesian4}
  5434. * @constant
  5435. */
  5436. Cartesian4.UNIT_Z = freezeObject(new Cartesian4(0.0, 0.0, 1.0, 0.0));
  5437. /**
  5438. * An immutable Cartesian4 instance initialized to (0.0, 0.0, 0.0, 1.0).
  5439. *
  5440. * @type {Cartesian4}
  5441. * @constant
  5442. */
  5443. Cartesian4.UNIT_W = freezeObject(new Cartesian4(0.0, 0.0, 0.0, 1.0));
  5444. /**
  5445. * Duplicates this Cartesian4 instance.
  5446. *
  5447. * @param {Cartesian4} [result] The object onto which to store the result.
  5448. * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
  5449. */
  5450. Cartesian4.prototype.clone = function(result) {
  5451. return Cartesian4.clone(this, result);
  5452. };
  5453. /**
  5454. * Compares this Cartesian against the provided Cartesian componentwise and returns
  5455. * <code>true</code> if they are equal, <code>false</code> otherwise.
  5456. *
  5457. * @param {Cartesian4} [right] The right hand side Cartesian.
  5458. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  5459. */
  5460. Cartesian4.prototype.equals = function(right) {
  5461. return Cartesian4.equals(this, right);
  5462. };
  5463. /**
  5464. * Compares this Cartesian against the provided Cartesian componentwise and returns
  5465. * <code>true</code> if they pass an absolute or relative tolerance test,
  5466. * <code>false</code> otherwise.
  5467. *
  5468. * @param {Cartesian4} [right] The right hand side Cartesian.
  5469. * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
  5470. * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  5471. * @returns {Boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
  5472. */
  5473. Cartesian4.prototype.equalsEpsilon = function(right, relativeEpsilon, absoluteEpsilon) {
  5474. return Cartesian4.equalsEpsilon(this, right, relativeEpsilon, absoluteEpsilon);
  5475. };
  5476. /**
  5477. * Creates a string representing this Cartesian in the format '(x, y)'.
  5478. *
  5479. * @returns {String} A string representing the provided Cartesian in the format '(x, y)'.
  5480. */
  5481. Cartesian4.prototype.toString = function() {
  5482. return '(' + this.x + ', ' + this.y + ', ' + this.z + ', ' + this.w + ')';
  5483. };
  5484. return Cartesian4;
  5485. });
  5486. /*global define*/
  5487. define('Core/RuntimeError',[
  5488. './defined'
  5489. ], function(
  5490. defined) {
  5491. 'use strict';
  5492. /**
  5493. * Constructs an exception object that is thrown due to an error that can occur at runtime, e.g.,
  5494. * out of memory, could not compile shader, etc. If a function may throw this
  5495. * exception, the calling code should be prepared to catch it.
  5496. * <br /><br />
  5497. * On the other hand, a {@link DeveloperError} indicates an exception due
  5498. * to a developer error, e.g., invalid argument, that usually indicates a bug in the
  5499. * calling code.
  5500. *
  5501. * @alias RuntimeError
  5502. * @constructor
  5503. * @extends Error
  5504. *
  5505. * @param {String} [message] The error message for this exception.
  5506. *
  5507. * @see DeveloperError
  5508. */
  5509. function RuntimeError(message) {
  5510. /**
  5511. * 'RuntimeError' indicating that this exception was thrown due to a runtime error.
  5512. * @type {String}
  5513. * @readonly
  5514. */
  5515. this.name = 'RuntimeError';
  5516. /**
  5517. * The explanation for why this exception was thrown.
  5518. * @type {String}
  5519. * @readonly
  5520. */
  5521. this.message = message;
  5522. //Browsers such as IE don't have a stack property until you actually throw the error.
  5523. var stack;
  5524. try {
  5525. throw new Error();
  5526. } catch (e) {
  5527. stack = e.stack;
  5528. }
  5529. /**
  5530. * The stack trace of this exception, if available.
  5531. * @type {String}
  5532. * @readonly
  5533. */
  5534. this.stack = stack;
  5535. }
  5536. if (defined(Object.create)) {
  5537. RuntimeError.prototype = Object.create(Error.prototype);
  5538. RuntimeError.prototype.constructor = RuntimeError;
  5539. }
  5540. RuntimeError.prototype.toString = function() {
  5541. var str = this.name + ': ' + this.message;
  5542. if (defined(this.stack)) {
  5543. str += '\n' + this.stack.toString();
  5544. }
  5545. return str;
  5546. };
  5547. return RuntimeError;
  5548. });
  5549. /*global define*/
  5550. define('Core/Matrix4',[
  5551. './Cartesian3',
  5552. './Cartesian4',
  5553. './defaultValue',
  5554. './defined',
  5555. './defineProperties',
  5556. './DeveloperError',
  5557. './freezeObject',
  5558. './Math',
  5559. './Matrix3',
  5560. './RuntimeError'
  5561. ], function(
  5562. Cartesian3,
  5563. Cartesian4,
  5564. defaultValue,
  5565. defined,
  5566. defineProperties,
  5567. DeveloperError,
  5568. freezeObject,
  5569. CesiumMath,
  5570. Matrix3,
  5571. RuntimeError) {
  5572. 'use strict';
  5573. /**
  5574. * A 4x4 matrix, indexable as a column-major order array.
  5575. * Constructor parameters are in row-major order for code readability.
  5576. * @alias Matrix4
  5577. * @constructor
  5578. *
  5579. * @param {Number} [column0Row0=0.0] The value for column 0, row 0.
  5580. * @param {Number} [column1Row0=0.0] The value for column 1, row 0.
  5581. * @param {Number} [column2Row0=0.0] The value for column 2, row 0.
  5582. * @param {Number} [column3Row0=0.0] The value for column 3, row 0.
  5583. * @param {Number} [column0Row1=0.0] The value for column 0, row 1.
  5584. * @param {Number} [column1Row1=0.0] The value for column 1, row 1.
  5585. * @param {Number} [column2Row1=0.0] The value for column 2, row 1.
  5586. * @param {Number} [column3Row1=0.0] The value for column 3, row 1.
  5587. * @param {Number} [column0Row2=0.0] The value for column 0, row 2.
  5588. * @param {Number} [column1Row2=0.0] The value for column 1, row 2.
  5589. * @param {Number} [column2Row2=0.0] The value for column 2, row 2.
  5590. * @param {Number} [column3Row2=0.0] The value for column 3, row 2.
  5591. * @param {Number} [column0Row3=0.0] The value for column 0, row 3.
  5592. * @param {Number} [column1Row3=0.0] The value for column 1, row 3.
  5593. * @param {Number} [column2Row3=0.0] The value for column 2, row 3.
  5594. * @param {Number} [column3Row3=0.0] The value for column 3, row 3.
  5595. *
  5596. * @see Matrix4.fromColumnMajorArray
  5597. * @see Matrix4.fromRowMajorArray
  5598. * @see Matrix4.fromRotationTranslation
  5599. * @see Matrix4.fromTranslationRotationScale
  5600. * @see Matrix4.fromTranslationQuaternionRotationScale
  5601. * @see Matrix4.fromTranslation
  5602. * @see Matrix4.fromScale
  5603. * @see Matrix4.fromUniformScale
  5604. * @see Matrix4.fromCamera
  5605. * @see Matrix4.computePerspectiveFieldOfView
  5606. * @see Matrix4.computeOrthographicOffCenter
  5607. * @see Matrix4.computePerspectiveOffCenter
  5608. * @see Matrix4.computeInfinitePerspectiveOffCenter
  5609. * @see Matrix4.computeViewportTransformation
  5610. * @see Matrix4.computeView
  5611. * @see Matrix2
  5612. * @see Matrix3
  5613. * @see Packable
  5614. */
  5615. function Matrix4(column0Row0, column1Row0, column2Row0, column3Row0,
  5616. column0Row1, column1Row1, column2Row1, column3Row1,
  5617. column0Row2, column1Row2, column2Row2, column3Row2,
  5618. column0Row3, column1Row3, column2Row3, column3Row3) {
  5619. this[0] = defaultValue(column0Row0, 0.0);
  5620. this[1] = defaultValue(column0Row1, 0.0);
  5621. this[2] = defaultValue(column0Row2, 0.0);
  5622. this[3] = defaultValue(column0Row3, 0.0);
  5623. this[4] = defaultValue(column1Row0, 0.0);
  5624. this[5] = defaultValue(column1Row1, 0.0);
  5625. this[6] = defaultValue(column1Row2, 0.0);
  5626. this[7] = defaultValue(column1Row3, 0.0);
  5627. this[8] = defaultValue(column2Row0, 0.0);
  5628. this[9] = defaultValue(column2Row1, 0.0);
  5629. this[10] = defaultValue(column2Row2, 0.0);
  5630. this[11] = defaultValue(column2Row3, 0.0);
  5631. this[12] = defaultValue(column3Row0, 0.0);
  5632. this[13] = defaultValue(column3Row1, 0.0);
  5633. this[14] = defaultValue(column3Row2, 0.0);
  5634. this[15] = defaultValue(column3Row3, 0.0);
  5635. }
  5636. /**
  5637. * The number of elements used to pack the object into an array.
  5638. * @type {Number}
  5639. */
  5640. Matrix4.packedLength = 16;
  5641. /**
  5642. * Stores the provided instance into the provided array.
  5643. *
  5644. * @param {Matrix4} value The value to pack.
  5645. * @param {Number[]} array The array to pack into.
  5646. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  5647. *
  5648. * @returns {Number[]} The array that was packed into
  5649. */
  5650. Matrix4.pack = function(value, array, startingIndex) {
  5651. if (!defined(value)) {
  5652. throw new DeveloperError('value is required');
  5653. }
  5654. if (!defined(array)) {
  5655. throw new DeveloperError('array is required');
  5656. }
  5657. startingIndex = defaultValue(startingIndex, 0);
  5658. array[startingIndex++] = value[0];
  5659. array[startingIndex++] = value[1];
  5660. array[startingIndex++] = value[2];
  5661. array[startingIndex++] = value[3];
  5662. array[startingIndex++] = value[4];
  5663. array[startingIndex++] = value[5];
  5664. array[startingIndex++] = value[6];
  5665. array[startingIndex++] = value[7];
  5666. array[startingIndex++] = value[8];
  5667. array[startingIndex++] = value[9];
  5668. array[startingIndex++] = value[10];
  5669. array[startingIndex++] = value[11];
  5670. array[startingIndex++] = value[12];
  5671. array[startingIndex++] = value[13];
  5672. array[startingIndex++] = value[14];
  5673. array[startingIndex] = value[15];
  5674. return array;
  5675. };
  5676. /**
  5677. * Retrieves an instance from a packed array.
  5678. *
  5679. * @param {Number[]} array The packed array.
  5680. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  5681. * @param {Matrix4} [result] The object into which to store the result.
  5682. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
  5683. */
  5684. Matrix4.unpack = function(array, startingIndex, result) {
  5685. if (!defined(array)) {
  5686. throw new DeveloperError('array is required');
  5687. }
  5688. startingIndex = defaultValue(startingIndex, 0);
  5689. if (!defined(result)) {
  5690. result = new Matrix4();
  5691. }
  5692. result[0] = array[startingIndex++];
  5693. result[1] = array[startingIndex++];
  5694. result[2] = array[startingIndex++];
  5695. result[3] = array[startingIndex++];
  5696. result[4] = array[startingIndex++];
  5697. result[5] = array[startingIndex++];
  5698. result[6] = array[startingIndex++];
  5699. result[7] = array[startingIndex++];
  5700. result[8] = array[startingIndex++];
  5701. result[9] = array[startingIndex++];
  5702. result[10] = array[startingIndex++];
  5703. result[11] = array[startingIndex++];
  5704. result[12] = array[startingIndex++];
  5705. result[13] = array[startingIndex++];
  5706. result[14] = array[startingIndex++];
  5707. result[15] = array[startingIndex];
  5708. return result;
  5709. };
  5710. /**
  5711. * Duplicates a Matrix4 instance.
  5712. *
  5713. * @param {Matrix4} matrix The matrix to duplicate.
  5714. * @param {Matrix4} [result] The object onto which to store the result.
  5715. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided. (Returns undefined if matrix is undefined)
  5716. */
  5717. Matrix4.clone = function(matrix, result) {
  5718. if (!defined(matrix)) {
  5719. return undefined;
  5720. }
  5721. if (!defined(result)) {
  5722. return new Matrix4(matrix[0], matrix[4], matrix[8], matrix[12],
  5723. matrix[1], matrix[5], matrix[9], matrix[13],
  5724. matrix[2], matrix[6], matrix[10], matrix[14],
  5725. matrix[3], matrix[7], matrix[11], matrix[15]);
  5726. }
  5727. result[0] = matrix[0];
  5728. result[1] = matrix[1];
  5729. result[2] = matrix[2];
  5730. result[3] = matrix[3];
  5731. result[4] = matrix[4];
  5732. result[5] = matrix[5];
  5733. result[6] = matrix[6];
  5734. result[7] = matrix[7];
  5735. result[8] = matrix[8];
  5736. result[9] = matrix[9];
  5737. result[10] = matrix[10];
  5738. result[11] = matrix[11];
  5739. result[12] = matrix[12];
  5740. result[13] = matrix[13];
  5741. result[14] = matrix[14];
  5742. result[15] = matrix[15];
  5743. return result;
  5744. };
  5745. /**
  5746. * Creates a Matrix4 from 16 consecutive elements in an array.
  5747. * @function
  5748. *
  5749. * @param {Number[]} array The array whose 16 consecutive elements correspond to the positions of the matrix. Assumes column-major order.
  5750. * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.
  5751. * @param {Matrix4} [result] The object onto which to store the result.
  5752. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
  5753. *
  5754. * @example
  5755. * // Create the Matrix4:
  5756. * // [1.0, 2.0, 3.0, 4.0]
  5757. * // [1.0, 2.0, 3.0, 4.0]
  5758. * // [1.0, 2.0, 3.0, 4.0]
  5759. * // [1.0, 2.0, 3.0, 4.0]
  5760. *
  5761. * var v = [1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0];
  5762. * var m = Cesium.Matrix4.fromArray(v);
  5763. *
  5764. * // Create same Matrix4 with using an offset into an array
  5765. * var v2 = [0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0];
  5766. * var m2 = Cesium.Matrix4.fromArray(v2, 2);
  5767. */
  5768. Matrix4.fromArray = Matrix4.unpack;
  5769. /**
  5770. * Computes a Matrix4 instance from a column-major order array.
  5771. *
  5772. * @param {Number[]} values The column-major order array.
  5773. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5774. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5775. */
  5776. Matrix4.fromColumnMajorArray = function(values, result) {
  5777. if (!defined(values)) {
  5778. throw new DeveloperError('values is required');
  5779. }
  5780. return Matrix4.clone(values, result);
  5781. };
  5782. /**
  5783. * Computes a Matrix4 instance from a row-major order array.
  5784. * The resulting matrix will be in column-major order.
  5785. *
  5786. * @param {Number[]} values The row-major order array.
  5787. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5788. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5789. */
  5790. Matrix4.fromRowMajorArray = function(values, result) {
  5791. if (!defined(values)) {
  5792. throw new DeveloperError('values is required.');
  5793. }
  5794. if (!defined(result)) {
  5795. return new Matrix4(values[0], values[1], values[2], values[3],
  5796. values[4], values[5], values[6], values[7],
  5797. values[8], values[9], values[10], values[11],
  5798. values[12], values[13], values[14], values[15]);
  5799. }
  5800. result[0] = values[0];
  5801. result[1] = values[4];
  5802. result[2] = values[8];
  5803. result[3] = values[12];
  5804. result[4] = values[1];
  5805. result[5] = values[5];
  5806. result[6] = values[9];
  5807. result[7] = values[13];
  5808. result[8] = values[2];
  5809. result[9] = values[6];
  5810. result[10] = values[10];
  5811. result[11] = values[14];
  5812. result[12] = values[3];
  5813. result[13] = values[7];
  5814. result[14] = values[11];
  5815. result[15] = values[15];
  5816. return result;
  5817. };
  5818. /**
  5819. * Computes a Matrix4 instance from a Matrix3 representing the rotation
  5820. * and a Cartesian3 representing the translation.
  5821. *
  5822. * @param {Matrix3} rotation The upper left portion of the matrix representing the rotation.
  5823. * @param {Cartesian3} [translation=Cartesian3.ZERO] The upper right portion of the matrix representing the translation.
  5824. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5825. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5826. */
  5827. Matrix4.fromRotationTranslation = function(rotation, translation, result) {
  5828. if (!defined(rotation)) {
  5829. throw new DeveloperError('rotation is required.');
  5830. }
  5831. translation = defaultValue(translation, Cartesian3.ZERO);
  5832. if (!defined(result)) {
  5833. return new Matrix4(rotation[0], rotation[3], rotation[6], translation.x,
  5834. rotation[1], rotation[4], rotation[7], translation.y,
  5835. rotation[2], rotation[5], rotation[8], translation.z,
  5836. 0.0, 0.0, 0.0, 1.0);
  5837. }
  5838. result[0] = rotation[0];
  5839. result[1] = rotation[1];
  5840. result[2] = rotation[2];
  5841. result[3] = 0.0;
  5842. result[4] = rotation[3];
  5843. result[5] = rotation[4];
  5844. result[6] = rotation[5];
  5845. result[7] = 0.0;
  5846. result[8] = rotation[6];
  5847. result[9] = rotation[7];
  5848. result[10] = rotation[8];
  5849. result[11] = 0.0;
  5850. result[12] = translation.x;
  5851. result[13] = translation.y;
  5852. result[14] = translation.z;
  5853. result[15] = 1.0;
  5854. return result;
  5855. };
  5856. /**
  5857. * Computes a Matrix4 instance from a translation, rotation, and scale (TRS)
  5858. * representation with the rotation represented as a quaternion.
  5859. *
  5860. * @param {Cartesian3} translation The translation transformation.
  5861. * @param {Quaternion} rotation The rotation transformation.
  5862. * @param {Cartesian3} scale The non-uniform scale transformation.
  5863. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5864. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5865. *
  5866. * @example
  5867. * var result = Cesium.Matrix4.fromTranslationQuaternionRotationScale(
  5868. * new Cesium.Cartesian3(1.0, 2.0, 3.0), // translation
  5869. * Cesium.Quaternion.IDENTITY, // rotation
  5870. * new Cesium.Cartesian3(7.0, 8.0, 9.0), // scale
  5871. * result);
  5872. */
  5873. Matrix4.fromTranslationQuaternionRotationScale = function(translation, rotation, scale, result) {
  5874. if (!defined(translation)) {
  5875. throw new DeveloperError('translation is required.');
  5876. }
  5877. if (!defined(rotation)) {
  5878. throw new DeveloperError('rotation is required.');
  5879. }
  5880. if (!defined(scale)) {
  5881. throw new DeveloperError('scale is required.');
  5882. }
  5883. if (!defined(result)) {
  5884. result = new Matrix4();
  5885. }
  5886. var scaleX = scale.x;
  5887. var scaleY = scale.y;
  5888. var scaleZ = scale.z;
  5889. var x2 = rotation.x * rotation.x;
  5890. var xy = rotation.x * rotation.y;
  5891. var xz = rotation.x * rotation.z;
  5892. var xw = rotation.x * rotation.w;
  5893. var y2 = rotation.y * rotation.y;
  5894. var yz = rotation.y * rotation.z;
  5895. var yw = rotation.y * rotation.w;
  5896. var z2 = rotation.z * rotation.z;
  5897. var zw = rotation.z * rotation.w;
  5898. var w2 = rotation.w * rotation.w;
  5899. var m00 = x2 - y2 - z2 + w2;
  5900. var m01 = 2.0 * (xy - zw);
  5901. var m02 = 2.0 * (xz + yw);
  5902. var m10 = 2.0 * (xy + zw);
  5903. var m11 = -x2 + y2 - z2 + w2;
  5904. var m12 = 2.0 * (yz - xw);
  5905. var m20 = 2.0 * (xz - yw);
  5906. var m21 = 2.0 * (yz + xw);
  5907. var m22 = -x2 - y2 + z2 + w2;
  5908. result[0] = m00 * scaleX;
  5909. result[1] = m10 * scaleX;
  5910. result[2] = m20 * scaleX;
  5911. result[3] = 0.0;
  5912. result[4] = m01 * scaleY;
  5913. result[5] = m11 * scaleY;
  5914. result[6] = m21 * scaleY;
  5915. result[7] = 0.0;
  5916. result[8] = m02 * scaleZ;
  5917. result[9] = m12 * scaleZ;
  5918. result[10] = m22 * scaleZ;
  5919. result[11] = 0.0;
  5920. result[12] = translation.x;
  5921. result[13] = translation.y;
  5922. result[14] = translation.z;
  5923. result[15] = 1.0;
  5924. return result;
  5925. };
  5926. /**
  5927. * Creates a Matrix4 instance from a {@link TranslationRotationScale} instance.
  5928. *
  5929. * @param {TranslationRotationScale} translationRotationScale The instance.
  5930. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5931. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5932. */
  5933. Matrix4.fromTranslationRotationScale = function(translationRotationScale, result) {
  5934. if (!defined(translationRotationScale)) {
  5935. throw new DeveloperError('translationRotationScale is required.');
  5936. }
  5937. return Matrix4.fromTranslationQuaternionRotationScale(translationRotationScale.translation, translationRotationScale.rotation, translationRotationScale.scale, result);
  5938. };
  5939. /**
  5940. * Creates a Matrix4 instance from a Cartesian3 representing the translation.
  5941. *
  5942. * @param {Cartesian3} translation The upper right portion of the matrix representing the translation.
  5943. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5944. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5945. *
  5946. * @see Matrix4.multiplyByTranslation
  5947. */
  5948. Matrix4.fromTranslation = function(translation, result) {
  5949. if (!defined(translation)) {
  5950. throw new DeveloperError('translation is required.');
  5951. }
  5952. return Matrix4.fromRotationTranslation(Matrix3.IDENTITY, translation, result);
  5953. };
  5954. /**
  5955. * Computes a Matrix4 instance representing a non-uniform scale.
  5956. *
  5957. * @param {Cartesian3} scale The x, y, and z scale factors.
  5958. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5959. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5960. *
  5961. * @example
  5962. * // Creates
  5963. * // [7.0, 0.0, 0.0, 0.0]
  5964. * // [0.0, 8.0, 0.0, 0.0]
  5965. * // [0.0, 0.0, 9.0, 0.0]
  5966. * // [0.0, 0.0, 0.0, 1.0]
  5967. * var m = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));
  5968. */
  5969. Matrix4.fromScale = function(scale, result) {
  5970. if (!defined(scale)) {
  5971. throw new DeveloperError('scale is required.');
  5972. }
  5973. if (!defined(result)) {
  5974. return new Matrix4(
  5975. scale.x, 0.0, 0.0, 0.0,
  5976. 0.0, scale.y, 0.0, 0.0,
  5977. 0.0, 0.0, scale.z, 0.0,
  5978. 0.0, 0.0, 0.0, 1.0);
  5979. }
  5980. result[0] = scale.x;
  5981. result[1] = 0.0;
  5982. result[2] = 0.0;
  5983. result[3] = 0.0;
  5984. result[4] = 0.0;
  5985. result[5] = scale.y;
  5986. result[6] = 0.0;
  5987. result[7] = 0.0;
  5988. result[8] = 0.0;
  5989. result[9] = 0.0;
  5990. result[10] = scale.z;
  5991. result[11] = 0.0;
  5992. result[12] = 0.0;
  5993. result[13] = 0.0;
  5994. result[14] = 0.0;
  5995. result[15] = 1.0;
  5996. return result;
  5997. };
  5998. /**
  5999. * Computes a Matrix4 instance representing a uniform scale.
  6000. *
  6001. * @param {Number} scale The uniform scale factor.
  6002. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  6003. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  6004. *
  6005. * @example
  6006. * // Creates
  6007. * // [2.0, 0.0, 0.0, 0.0]
  6008. * // [0.0, 2.0, 0.0, 0.0]
  6009. * // [0.0, 0.0, 2.0, 0.0]
  6010. * // [0.0, 0.0, 0.0, 1.0]
  6011. * var m = Cesium.Matrix4.fromUniformScale(2.0);
  6012. */
  6013. Matrix4.fromUniformScale = function(scale, result) {
  6014. if (typeof scale !== 'number') {
  6015. throw new DeveloperError('scale is required.');
  6016. }
  6017. if (!defined(result)) {
  6018. return new Matrix4(scale, 0.0, 0.0, 0.0,
  6019. 0.0, scale, 0.0, 0.0,
  6020. 0.0, 0.0, scale, 0.0,
  6021. 0.0, 0.0, 0.0, 1.0);
  6022. }
  6023. result[0] = scale;
  6024. result[1] = 0.0;
  6025. result[2] = 0.0;
  6026. result[3] = 0.0;
  6027. result[4] = 0.0;
  6028. result[5] = scale;
  6029. result[6] = 0.0;
  6030. result[7] = 0.0;
  6031. result[8] = 0.0;
  6032. result[9] = 0.0;
  6033. result[10] = scale;
  6034. result[11] = 0.0;
  6035. result[12] = 0.0;
  6036. result[13] = 0.0;
  6037. result[14] = 0.0;
  6038. result[15] = 1.0;
  6039. return result;
  6040. };
  6041. var fromCameraF = new Cartesian3();
  6042. var fromCameraR = new Cartesian3();
  6043. var fromCameraU = new Cartesian3();
  6044. /**
  6045. * Computes a Matrix4 instance from a Camera.
  6046. *
  6047. * @param {Camera} camera The camera to use.
  6048. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  6049. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  6050. */
  6051. Matrix4.fromCamera = function(camera, result) {
  6052. if (!defined(camera)) {
  6053. throw new DeveloperError('camera is required.');
  6054. }
  6055. var position = camera.position;
  6056. var direction = camera.direction;
  6057. var up = camera.up;
  6058. if (!defined(position)) {
  6059. throw new DeveloperError('camera.position is required.');
  6060. }
  6061. if (!defined(direction)) {
  6062. throw new DeveloperError('camera.direction is required.');
  6063. }
  6064. if (!defined(up)) {
  6065. throw new DeveloperError('camera.up is required.');
  6066. }
  6067. Cartesian3.normalize(direction, fromCameraF);
  6068. Cartesian3.normalize(Cartesian3.cross(fromCameraF, up, fromCameraR), fromCameraR);
  6069. Cartesian3.normalize(Cartesian3.cross(fromCameraR, fromCameraF, fromCameraU), fromCameraU);
  6070. var sX = fromCameraR.x;
  6071. var sY = fromCameraR.y;
  6072. var sZ = fromCameraR.z;
  6073. var fX = fromCameraF.x;
  6074. var fY = fromCameraF.y;
  6075. var fZ = fromCameraF.z;
  6076. var uX = fromCameraU.x;
  6077. var uY = fromCameraU.y;
  6078. var uZ = fromCameraU.z;
  6079. var positionX = position.x;
  6080. var positionY = position.y;
  6081. var positionZ = position.z;
  6082. var t0 = sX * -positionX + sY * -positionY+ sZ * -positionZ;
  6083. var t1 = uX * -positionX + uY * -positionY+ uZ * -positionZ;
  6084. var t2 = fX * positionX + fY * positionY + fZ * positionZ;
  6085. // The code below this comment is an optimized
  6086. // version of the commented lines.
  6087. // Rather that create two matrices and then multiply,
  6088. // we just bake in the multiplcation as part of creation.
  6089. // var rotation = new Matrix4(
  6090. // sX, sY, sZ, 0.0,
  6091. // uX, uY, uZ, 0.0,
  6092. // -fX, -fY, -fZ, 0.0,
  6093. // 0.0, 0.0, 0.0, 1.0);
  6094. // var translation = new Matrix4(
  6095. // 1.0, 0.0, 0.0, -position.x,
  6096. // 0.0, 1.0, 0.0, -position.y,
  6097. // 0.0, 0.0, 1.0, -position.z,
  6098. // 0.0, 0.0, 0.0, 1.0);
  6099. // return rotation.multiply(translation);
  6100. if (!defined(result)) {
  6101. return new Matrix4(
  6102. sX, sY, sZ, t0,
  6103. uX, uY, uZ, t1,
  6104. -fX, -fY, -fZ, t2,
  6105. 0.0, 0.0, 0.0, 1.0);
  6106. }
  6107. result[0] = sX;
  6108. result[1] = uX;
  6109. result[2] = -fX;
  6110. result[3] = 0.0;
  6111. result[4] = sY;
  6112. result[5] = uY;
  6113. result[6] = -fY;
  6114. result[7] = 0.0;
  6115. result[8] = sZ;
  6116. result[9] = uZ;
  6117. result[10] = -fZ;
  6118. result[11] = 0.0;
  6119. result[12] = t0;
  6120. result[13] = t1;
  6121. result[14] = t2;
  6122. result[15] = 1.0;
  6123. return result;
  6124. };
  6125. /**
  6126. * Computes a Matrix4 instance representing a perspective transformation matrix.
  6127. *
  6128. * @param {Number} fovY The field of view along the Y axis in radians.
  6129. * @param {Number} aspectRatio The aspect ratio.
  6130. * @param {Number} near The distance to the near plane in meters.
  6131. * @param {Number} far The distance to the far plane in meters.
  6132. * @param {Matrix4} result The object in which the result will be stored.
  6133. * @returns {Matrix4} The modified result parameter.
  6134. *
  6135. * @exception {DeveloperError} fovY must be in (0, PI].
  6136. * @exception {DeveloperError} aspectRatio must be greater than zero.
  6137. * @exception {DeveloperError} near must be greater than zero.
  6138. * @exception {DeveloperError} far must be greater than zero.
  6139. */
  6140. Matrix4.computePerspectiveFieldOfView = function(fovY, aspectRatio, near, far, result) {
  6141. if (fovY <= 0.0 || fovY > Math.PI) {
  6142. throw new DeveloperError('fovY must be in (0, PI].');
  6143. }
  6144. if (aspectRatio <= 0.0) {
  6145. throw new DeveloperError('aspectRatio must be greater than zero.');
  6146. }
  6147. if (near <= 0.0) {
  6148. throw new DeveloperError('near must be greater than zero.');
  6149. }
  6150. if (far <= 0.0) {
  6151. throw new DeveloperError('far must be greater than zero.');
  6152. }
  6153. if (!defined(result)) {
  6154. throw new DeveloperError('result is required');
  6155. }
  6156. var bottom = Math.tan(fovY * 0.5);
  6157. var column1Row1 = 1.0 / bottom;
  6158. var column0Row0 = column1Row1 / aspectRatio;
  6159. var column2Row2 = (far + near) / (near - far);
  6160. var column3Row2 = (2.0 * far * near) / (near - far);
  6161. result[0] = column0Row0;
  6162. result[1] = 0.0;
  6163. result[2] = 0.0;
  6164. result[3] = 0.0;
  6165. result[4] = 0.0;
  6166. result[5] = column1Row1;
  6167. result[6] = 0.0;
  6168. result[7] = 0.0;
  6169. result[8] = 0.0;
  6170. result[9] = 0.0;
  6171. result[10] = column2Row2;
  6172. result[11] = -1.0;
  6173. result[12] = 0.0;
  6174. result[13] = 0.0;
  6175. result[14] = column3Row2;
  6176. result[15] = 0.0;
  6177. return result;
  6178. };
  6179. /**
  6180. * Computes a Matrix4 instance representing an orthographic transformation matrix.
  6181. *
  6182. * @param {Number} left The number of meters to the left of the camera that will be in view.
  6183. * @param {Number} right The number of meters to the right of the camera that will be in view.
  6184. * @param {Number} bottom The number of meters below of the camera that will be in view.
  6185. * @param {Number} top The number of meters above of the camera that will be in view.
  6186. * @param {Number} near The distance to the near plane in meters.
  6187. * @param {Number} far The distance to the far plane in meters.
  6188. * @param {Matrix4} result The object in which the result will be stored.
  6189. * @returns {Matrix4} The modified result parameter.
  6190. */
  6191. Matrix4.computeOrthographicOffCenter = function(left, right, bottom, top, near, far, result) {
  6192. if (!defined(left)) {
  6193. throw new DeveloperError('left is required.');
  6194. }
  6195. if (!defined(right)) {
  6196. throw new DeveloperError('right is required.');
  6197. }
  6198. if (!defined(bottom)) {
  6199. throw new DeveloperError('bottom is required.');
  6200. }
  6201. if (!defined(top)) {
  6202. throw new DeveloperError('top is required.');
  6203. }
  6204. if (!defined(near)) {
  6205. throw new DeveloperError('near is required.');
  6206. }
  6207. if (!defined(far)) {
  6208. throw new DeveloperError('far is required.');
  6209. }
  6210. if (!defined(result)) {
  6211. throw new DeveloperError('result is required');
  6212. }
  6213. var a = 1.0 / (right - left);
  6214. var b = 1.0 / (top - bottom);
  6215. var c = 1.0 / (far - near);
  6216. var tx = -(right + left) * a;
  6217. var ty = -(top + bottom) * b;
  6218. var tz = -(far + near) * c;
  6219. a *= 2.0;
  6220. b *= 2.0;
  6221. c *= -2.0;
  6222. result[0] = a;
  6223. result[1] = 0.0;
  6224. result[2] = 0.0;
  6225. result[3] = 0.0;
  6226. result[4] = 0.0;
  6227. result[5] = b;
  6228. result[6] = 0.0;
  6229. result[7] = 0.0;
  6230. result[8] = 0.0;
  6231. result[9] = 0.0;
  6232. result[10] = c;
  6233. result[11] = 0.0;
  6234. result[12] = tx;
  6235. result[13] = ty;
  6236. result[14] = tz;
  6237. result[15] = 1.0;
  6238. return result;
  6239. };
  6240. /**
  6241. * Computes a Matrix4 instance representing an off center perspective transformation.
  6242. *
  6243. * @param {Number} left The number of meters to the left of the camera that will be in view.
  6244. * @param {Number} right The number of meters to the right of the camera that will be in view.
  6245. * @param {Number} bottom The number of meters below of the camera that will be in view.
  6246. * @param {Number} top The number of meters above of the camera that will be in view.
  6247. * @param {Number} near The distance to the near plane in meters.
  6248. * @param {Number} far The distance to the far plane in meters.
  6249. * @param {Matrix4} result The object in which the result will be stored.
  6250. * @returns {Matrix4} The modified result parameter.
  6251. */
  6252. Matrix4.computePerspectiveOffCenter = function(left, right, bottom, top, near, far, result) {
  6253. if (!defined(left)) {
  6254. throw new DeveloperError('left is required.');
  6255. }
  6256. if (!defined(right)) {
  6257. throw new DeveloperError('right is required.');
  6258. }
  6259. if (!defined(bottom)) {
  6260. throw new DeveloperError('bottom is required.');
  6261. }
  6262. if (!defined(top)) {
  6263. throw new DeveloperError('top is required.');
  6264. }
  6265. if (!defined(near)) {
  6266. throw new DeveloperError('near is required.');
  6267. }
  6268. if (!defined(far)) {
  6269. throw new DeveloperError('far is required.');
  6270. }
  6271. if (!defined(result)) {
  6272. throw new DeveloperError('result is required');
  6273. }
  6274. var column0Row0 = 2.0 * near / (right - left);
  6275. var column1Row1 = 2.0 * near / (top - bottom);
  6276. var column2Row0 = (right + left) / (right - left);
  6277. var column2Row1 = (top + bottom) / (top - bottom);
  6278. var column2Row2 = -(far + near) / (far - near);
  6279. var column2Row3 = -1.0;
  6280. var column3Row2 = -2.0 * far * near / (far - near);
  6281. result[0] = column0Row0;
  6282. result[1] = 0.0;
  6283. result[2] = 0.0;
  6284. result[3] = 0.0;
  6285. result[4] = 0.0;
  6286. result[5] = column1Row1;
  6287. result[6] = 0.0;
  6288. result[7] = 0.0;
  6289. result[8] = column2Row0;
  6290. result[9] = column2Row1;
  6291. result[10] = column2Row2;
  6292. result[11] = column2Row3;
  6293. result[12] = 0.0;
  6294. result[13] = 0.0;
  6295. result[14] = column3Row2;
  6296. result[15] = 0.0;
  6297. return result;
  6298. };
  6299. /**
  6300. * Computes a Matrix4 instance representing an infinite off center perspective transformation.
  6301. *
  6302. * @param {Number} left The number of meters to the left of the camera that will be in view.
  6303. * @param {Number} right The number of meters to the right of the camera that will be in view.
  6304. * @param {Number} bottom The number of meters below of the camera that will be in view.
  6305. * @param {Number} top The number of meters above of the camera that will be in view.
  6306. * @param {Number} near The distance to the near plane in meters.
  6307. * @param {Matrix4} result The object in which the result will be stored.
  6308. * @returns {Matrix4} The modified result parameter.
  6309. */
  6310. Matrix4.computeInfinitePerspectiveOffCenter = function(left, right, bottom, top, near, result) {
  6311. if (!defined(left)) {
  6312. throw new DeveloperError('left is required.');
  6313. }
  6314. if (!defined(right)) {
  6315. throw new DeveloperError('right is required.');
  6316. }
  6317. if (!defined(bottom)) {
  6318. throw new DeveloperError('bottom is required.');
  6319. }
  6320. if (!defined(top)) {
  6321. throw new DeveloperError('top is required.');
  6322. }
  6323. if (!defined(near)) {
  6324. throw new DeveloperError('near is required.');
  6325. }
  6326. if (!defined(result)) {
  6327. throw new DeveloperError('result is required');
  6328. }
  6329. var column0Row0 = 2.0 * near / (right - left);
  6330. var column1Row1 = 2.0 * near / (top - bottom);
  6331. var column2Row0 = (right + left) / (right - left);
  6332. var column2Row1 = (top + bottom) / (top - bottom);
  6333. var column2Row2 = -1.0;
  6334. var column2Row3 = -1.0;
  6335. var column3Row2 = -2.0 * near;
  6336. result[0] = column0Row0;
  6337. result[1] = 0.0;
  6338. result[2] = 0.0;
  6339. result[3] = 0.0;
  6340. result[4] = 0.0;
  6341. result[5] = column1Row1;
  6342. result[6] = 0.0;
  6343. result[7] = 0.0;
  6344. result[8] = column2Row0;
  6345. result[9] = column2Row1;
  6346. result[10] = column2Row2;
  6347. result[11] = column2Row3;
  6348. result[12] = 0.0;
  6349. result[13] = 0.0;
  6350. result[14] = column3Row2;
  6351. result[15] = 0.0;
  6352. return result;
  6353. };
  6354. /**
  6355. * Computes a Matrix4 instance that transforms from normalized device coordinates to window coordinates.
  6356. *
  6357. * @param {Object}[viewport = { x : 0.0, y : 0.0, width : 0.0, height : 0.0 }] The viewport's corners as shown in Example 1.
  6358. * @param {Number}[nearDepthRange=0.0] The near plane distance in window coordinates.
  6359. * @param {Number}[farDepthRange=1.0] The far plane distance in window coordinates.
  6360. * @param {Matrix4} result The object in which the result will be stored.
  6361. * @returns {Matrix4} The modified result parameter.
  6362. *
  6363. * @example
  6364. * // Create viewport transformation using an explicit viewport and depth range.
  6365. * var m = Cesium.Matrix4.computeViewportTransformation({
  6366. * x : 0.0,
  6367. * y : 0.0,
  6368. * width : 1024.0,
  6369. * height : 768.0
  6370. * }, 0.0, 1.0, new Cesium.Matrix4());
  6371. */
  6372. Matrix4.computeViewportTransformation = function(viewport, nearDepthRange, farDepthRange, result) {
  6373. if (!defined(result)) {
  6374. throw new DeveloperError('result is required');
  6375. }
  6376. viewport = defaultValue(viewport, defaultValue.EMPTY_OBJECT);
  6377. var x = defaultValue(viewport.x, 0.0);
  6378. var y = defaultValue(viewport.y, 0.0);
  6379. var width = defaultValue(viewport.width, 0.0);
  6380. var height = defaultValue(viewport.height, 0.0);
  6381. nearDepthRange = defaultValue(nearDepthRange, 0.0);
  6382. farDepthRange = defaultValue(farDepthRange, 1.0);
  6383. var halfWidth = width * 0.5;
  6384. var halfHeight = height * 0.5;
  6385. var halfDepth = (farDepthRange - nearDepthRange) * 0.5;
  6386. var column0Row0 = halfWidth;
  6387. var column1Row1 = halfHeight;
  6388. var column2Row2 = halfDepth;
  6389. var column3Row0 = x + halfWidth;
  6390. var column3Row1 = y + halfHeight;
  6391. var column3Row2 = nearDepthRange + halfDepth;
  6392. var column3Row3 = 1.0;
  6393. result[0] = column0Row0;
  6394. result[1] = 0.0;
  6395. result[2] = 0.0;
  6396. result[3] = 0.0;
  6397. result[4] = 0.0;
  6398. result[5] = column1Row1;
  6399. result[6] = 0.0;
  6400. result[7] = 0.0;
  6401. result[8] = 0.0;
  6402. result[9] = 0.0;
  6403. result[10] = column2Row2;
  6404. result[11] = 0.0;
  6405. result[12] = column3Row0;
  6406. result[13] = column3Row1;
  6407. result[14] = column3Row2;
  6408. result[15] = column3Row3;
  6409. return result;
  6410. };
  6411. /**
  6412. * Computes a Matrix4 instance that transforms from world space to view space.
  6413. *
  6414. * @param {Cartesian3} position The position of the camera.
  6415. * @param {Cartesian3} direction The forward direction.
  6416. * @param {Cartesian3} up The up direction.
  6417. * @param {Cartesian3} right The right direction.
  6418. * @param {Matrix4} result The object in which the result will be stored.
  6419. * @returns {Matrix4} The modified result parameter.
  6420. */
  6421. Matrix4.computeView = function(position, direction, up, right, result) {
  6422. if (!defined(position)) {
  6423. throw new DeveloperError('position is required');
  6424. }
  6425. if (!defined(direction)) {
  6426. throw new DeveloperError('direction is required');
  6427. }
  6428. if (!defined(up)) {
  6429. throw new DeveloperError('up is required');
  6430. }
  6431. if (!defined(right)) {
  6432. throw new DeveloperError('right is required');
  6433. }
  6434. if (!defined(result)) {
  6435. throw new DeveloperError('result is required');
  6436. }
  6437. result[0] = right.x;
  6438. result[1] = up.x;
  6439. result[2] = -direction.x;
  6440. result[3] = 0.0;
  6441. result[4] = right.y;
  6442. result[5] = up.y;
  6443. result[6] = -direction.y;
  6444. result[7] = 0.0;
  6445. result[8] = right.z;
  6446. result[9] = up.z;
  6447. result[10] = -direction.z;
  6448. result[11] = 0.0;
  6449. result[12] = -Cartesian3.dot(right, position);
  6450. result[13] = -Cartesian3.dot(up, position);
  6451. result[14] = Cartesian3.dot(direction, position);
  6452. result[15] = 1.0;
  6453. return result;
  6454. };
  6455. /**
  6456. * Computes an Array from the provided Matrix4 instance.
  6457. * The array will be in column-major order.
  6458. *
  6459. * @param {Matrix4} matrix The matrix to use..
  6460. * @param {Number[]} [result] The Array onto which to store the result.
  6461. * @returns {Number[]} The modified Array parameter or a new Array instance if one was not provided.
  6462. *
  6463. * @example
  6464. * //create an array from an instance of Matrix4
  6465. * // m = [10.0, 14.0, 18.0, 22.0]
  6466. * // [11.0, 15.0, 19.0, 23.0]
  6467. * // [12.0, 16.0, 20.0, 24.0]
  6468. * // [13.0, 17.0, 21.0, 25.0]
  6469. * var a = Cesium.Matrix4.toArray(m);
  6470. *
  6471. * // m remains the same
  6472. * //creates a = [10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0]
  6473. */
  6474. Matrix4.toArray = function(matrix, result) {
  6475. if (!defined(matrix)) {
  6476. throw new DeveloperError('matrix is required');
  6477. }
  6478. if (!defined(result)) {
  6479. return [matrix[0], matrix[1], matrix[2], matrix[3],
  6480. matrix[4], matrix[5], matrix[6], matrix[7],
  6481. matrix[8], matrix[9], matrix[10], matrix[11],
  6482. matrix[12], matrix[13], matrix[14], matrix[15]];
  6483. }
  6484. result[0] = matrix[0];
  6485. result[1] = matrix[1];
  6486. result[2] = matrix[2];
  6487. result[3] = matrix[3];
  6488. result[4] = matrix[4];
  6489. result[5] = matrix[5];
  6490. result[6] = matrix[6];
  6491. result[7] = matrix[7];
  6492. result[8] = matrix[8];
  6493. result[9] = matrix[9];
  6494. result[10] = matrix[10];
  6495. result[11] = matrix[11];
  6496. result[12] = matrix[12];
  6497. result[13] = matrix[13];
  6498. result[14] = matrix[14];
  6499. result[15] = matrix[15];
  6500. return result;
  6501. };
  6502. /**
  6503. * Computes the array index of the element at the provided row and column.
  6504. *
  6505. * @param {Number} row The zero-based index of the row.
  6506. * @param {Number} column The zero-based index of the column.
  6507. * @returns {Number} The index of the element at the provided row and column.
  6508. *
  6509. * @exception {DeveloperError} row must be 0, 1, 2, or 3.
  6510. * @exception {DeveloperError} column must be 0, 1, 2, or 3.
  6511. *
  6512. * @example
  6513. * var myMatrix = new Cesium.Matrix4();
  6514. * var column1Row0Index = Cesium.Matrix4.getElementIndex(1, 0);
  6515. * var column1Row0 = myMatrix[column1Row0Index];
  6516. * myMatrix[column1Row0Index] = 10.0;
  6517. */
  6518. Matrix4.getElementIndex = function(column, row) {
  6519. if (typeof row !== 'number' || row < 0 || row > 3) {
  6520. throw new DeveloperError('row must be 0, 1, 2, or 3.');
  6521. }
  6522. if (typeof column !== 'number' || column < 0 || column > 3) {
  6523. throw new DeveloperError('column must be 0, 1, 2, or 3.');
  6524. }
  6525. return column * 4 + row;
  6526. };
  6527. /**
  6528. * Retrieves a copy of the matrix column at the provided index as a Cartesian4 instance.
  6529. *
  6530. * @param {Matrix4} matrix The matrix to use.
  6531. * @param {Number} index The zero-based index of the column to retrieve.
  6532. * @param {Cartesian4} result The object onto which to store the result.
  6533. * @returns {Cartesian4} The modified result parameter.
  6534. *
  6535. * @exception {DeveloperError} index must be 0, 1, 2, or 3.
  6536. *
  6537. * @example
  6538. * //returns a Cartesian4 instance with values from the specified column
  6539. * // m = [10.0, 11.0, 12.0, 13.0]
  6540. * // [14.0, 15.0, 16.0, 17.0]
  6541. * // [18.0, 19.0, 20.0, 21.0]
  6542. * // [22.0, 23.0, 24.0, 25.0]
  6543. *
  6544. * //Example 1: Creates an instance of Cartesian
  6545. * var a = Cesium.Matrix4.getColumn(m, 2, new Cesium.Cartesian4());
  6546. *
  6547. * @example
  6548. * //Example 2: Sets values for Cartesian instance
  6549. * var a = new Cesium.Cartesian4();
  6550. * Cesium.Matrix4.getColumn(m, 2, a);
  6551. *
  6552. * // a.x = 12.0; a.y = 16.0; a.z = 20.0; a.w = 24.0;
  6553. */
  6554. Matrix4.getColumn = function(matrix, index, result) {
  6555. if (!defined(matrix)) {
  6556. throw new DeveloperError('matrix is required.');
  6557. }
  6558. if (typeof index !== 'number' || index < 0 || index > 3) {
  6559. throw new DeveloperError('index must be 0, 1, 2, or 3.');
  6560. }
  6561. if (!defined(result)) {
  6562. throw new DeveloperError('result is required');
  6563. }
  6564. var startIndex = index * 4;
  6565. var x = matrix[startIndex];
  6566. var y = matrix[startIndex + 1];
  6567. var z = matrix[startIndex + 2];
  6568. var w = matrix[startIndex + 3];
  6569. result.x = x;
  6570. result.y = y;
  6571. result.z = z;
  6572. result.w = w;
  6573. return result;
  6574. };
  6575. /**
  6576. * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian4 instance.
  6577. *
  6578. * @param {Matrix4} matrix The matrix to use.
  6579. * @param {Number} index The zero-based index of the column to set.
  6580. * @param {Cartesian4} cartesian The Cartesian whose values will be assigned to the specified column.
  6581. * @param {Matrix4} result The object onto which to store the result.
  6582. * @returns {Matrix4} The modified result parameter.
  6583. *
  6584. * @exception {DeveloperError} index must be 0, 1, 2, or 3.
  6585. *
  6586. * @example
  6587. * //creates a new Matrix4 instance with new column values from the Cartesian4 instance
  6588. * // m = [10.0, 11.0, 12.0, 13.0]
  6589. * // [14.0, 15.0, 16.0, 17.0]
  6590. * // [18.0, 19.0, 20.0, 21.0]
  6591. * // [22.0, 23.0, 24.0, 25.0]
  6592. *
  6593. * var a = Cesium.Matrix4.setColumn(m, 2, new Cesium.Cartesian4(99.0, 98.0, 97.0, 96.0), new Cesium.Matrix4());
  6594. *
  6595. * // m remains the same
  6596. * // a = [10.0, 11.0, 99.0, 13.0]
  6597. * // [14.0, 15.0, 98.0, 17.0]
  6598. * // [18.0, 19.0, 97.0, 21.0]
  6599. * // [22.0, 23.0, 96.0, 25.0]
  6600. */
  6601. Matrix4.setColumn = function(matrix, index, cartesian, result) {
  6602. if (!defined(matrix)) {
  6603. throw new DeveloperError('matrix is required');
  6604. }
  6605. if (!defined(cartesian)) {
  6606. throw new DeveloperError('cartesian is required');
  6607. }
  6608. if (typeof index !== 'number' || index < 0 || index > 3) {
  6609. throw new DeveloperError('index must be 0, 1, 2, or 3.');
  6610. }
  6611. if (!defined(result)) {
  6612. throw new DeveloperError('result is required');
  6613. }
  6614. result = Matrix4.clone(matrix, result);
  6615. var startIndex = index * 4;
  6616. result[startIndex] = cartesian.x;
  6617. result[startIndex + 1] = cartesian.y;
  6618. result[startIndex + 2] = cartesian.z;
  6619. result[startIndex + 3] = cartesian.w;
  6620. return result;
  6621. };
  6622. /**
  6623. * Computes a new matrix that replaces the translation in the rightmost column of the provided
  6624. * matrix with the provided translation. This assumes the matrix is an affine transformation
  6625. *
  6626. * @param {Matrix4} matrix The matrix to use.
  6627. * @param {Cartesian3} translation The translation that replaces the translation of the provided matrix.
  6628. * @param {Cartesian4} result The object onto which to store the result.
  6629. * @returns {Matrix4} The modified result parameter.
  6630. */
  6631. Matrix4.setTranslation = function(matrix, translation, result) {
  6632. if (!defined(matrix)) {
  6633. throw new DeveloperError('matrix is required');
  6634. }
  6635. if (!defined(translation)) {
  6636. throw new DeveloperError('translation is required');
  6637. }
  6638. if (!defined(result)) {
  6639. throw new DeveloperError('result is required');
  6640. }
  6641. result[0] = matrix[0];
  6642. result[1] = matrix[1];
  6643. result[2] = matrix[2];
  6644. result[3] = matrix[3];
  6645. result[4] = matrix[4];
  6646. result[5] = matrix[5];
  6647. result[6] = matrix[6];
  6648. result[7] = matrix[7];
  6649. result[8] = matrix[8];
  6650. result[9] = matrix[9];
  6651. result[10] = matrix[10];
  6652. result[11] = matrix[11];
  6653. result[12] = translation.x;
  6654. result[13] = translation.y;
  6655. result[14] = translation.z;
  6656. result[15] = matrix[15];
  6657. return result;
  6658. };
  6659. /**
  6660. * Retrieves a copy of the matrix row at the provided index as a Cartesian4 instance.
  6661. *
  6662. * @param {Matrix4} matrix The matrix to use.
  6663. * @param {Number} index The zero-based index of the row to retrieve.
  6664. * @param {Cartesian4} result The object onto which to store the result.
  6665. * @returns {Cartesian4} The modified result parameter.
  6666. *
  6667. * @exception {DeveloperError} index must be 0, 1, 2, or 3.
  6668. *
  6669. * @example
  6670. * //returns a Cartesian4 instance with values from the specified column
  6671. * // m = [10.0, 11.0, 12.0, 13.0]
  6672. * // [14.0, 15.0, 16.0, 17.0]
  6673. * // [18.0, 19.0, 20.0, 21.0]
  6674. * // [22.0, 23.0, 24.0, 25.0]
  6675. *
  6676. * //Example 1: Returns an instance of Cartesian
  6677. * var a = Cesium.Matrix4.getRow(m, 2, new Cesium.Cartesian4());
  6678. *
  6679. * @example
  6680. * //Example 2: Sets values for a Cartesian instance
  6681. * var a = new Cesium.Cartesian4();
  6682. * Cesium.Matrix4.getRow(m, 2, a);
  6683. *
  6684. * // a.x = 18.0; a.y = 19.0; a.z = 20.0; a.w = 21.0;
  6685. */
  6686. Matrix4.getRow = function(matrix, index, result) {
  6687. if (!defined(matrix)) {
  6688. throw new DeveloperError('matrix is required.');
  6689. }
  6690. if (typeof index !== 'number' || index < 0 || index > 3) {
  6691. throw new DeveloperError('index must be 0, 1, 2, or 3.');
  6692. }
  6693. if (!defined(result)) {
  6694. throw new DeveloperError('result is required');
  6695. }
  6696. var x = matrix[index];
  6697. var y = matrix[index + 4];
  6698. var z = matrix[index + 8];
  6699. var w = matrix[index + 12];
  6700. result.x = x;
  6701. result.y = y;
  6702. result.z = z;
  6703. result.w = w;
  6704. return result;
  6705. };
  6706. /**
  6707. * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian4 instance.
  6708. *
  6709. * @param {Matrix4} matrix The matrix to use.
  6710. * @param {Number} index The zero-based index of the row to set.
  6711. * @param {Cartesian4} cartesian The Cartesian whose values will be assigned to the specified row.
  6712. * @param {Matrix4} result The object onto which to store the result.
  6713. * @returns {Matrix4} The modified result parameter.
  6714. *
  6715. * @exception {DeveloperError} index must be 0, 1, 2, or 3.
  6716. *
  6717. * @example
  6718. * //create a new Matrix4 instance with new row values from the Cartesian4 instance
  6719. * // m = [10.0, 11.0, 12.0, 13.0]
  6720. * // [14.0, 15.0, 16.0, 17.0]
  6721. * // [18.0, 19.0, 20.0, 21.0]
  6722. * // [22.0, 23.0, 24.0, 25.0]
  6723. *
  6724. * var a = Cesium.Matrix4.setRow(m, 2, new Cesium.Cartesian4(99.0, 98.0, 97.0, 96.0), new Cesium.Matrix4());
  6725. *
  6726. * // m remains the same
  6727. * // a = [10.0, 11.0, 12.0, 13.0]
  6728. * // [14.0, 15.0, 16.0, 17.0]
  6729. * // [99.0, 98.0, 97.0, 96.0]
  6730. * // [22.0, 23.0, 24.0, 25.0]
  6731. */
  6732. Matrix4.setRow = function(matrix, index, cartesian, result) {
  6733. if (!defined(matrix)) {
  6734. throw new DeveloperError('matrix is required');
  6735. }
  6736. if (!defined(cartesian)) {
  6737. throw new DeveloperError('cartesian is required');
  6738. }
  6739. if (typeof index !== 'number' || index < 0 || index > 3) {
  6740. throw new DeveloperError('index must be 0, 1, 2, or 3.');
  6741. }
  6742. if (!defined(result)) {
  6743. throw new DeveloperError('result is required');
  6744. }
  6745. result = Matrix4.clone(matrix, result);
  6746. result[index] = cartesian.x;
  6747. result[index + 4] = cartesian.y;
  6748. result[index + 8] = cartesian.z;
  6749. result[index + 12] = cartesian.w;
  6750. return result;
  6751. };
  6752. var scratchColumn = new Cartesian3();
  6753. /**
  6754. * Extracts the non-uniform scale assuming the matrix is an affine transformation.
  6755. *
  6756. * @param {Matrix4} matrix The matrix.
  6757. * @param {Cartesian3} result The object onto which to store the result.
  6758. * @returns {Cartesian3} The modified result parameter
  6759. */
  6760. Matrix4.getScale = function(matrix, result) {
  6761. if (!defined(matrix)) {
  6762. throw new DeveloperError('matrix is required.');
  6763. }
  6764. if (!defined(result)) {
  6765. throw new DeveloperError('result is required');
  6766. }
  6767. result.x = Cartesian3.magnitude(Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn));
  6768. result.y = Cartesian3.magnitude(Cartesian3.fromElements(matrix[4], matrix[5], matrix[6], scratchColumn));
  6769. result.z = Cartesian3.magnitude(Cartesian3.fromElements(matrix[8], matrix[9], matrix[10], scratchColumn));
  6770. return result;
  6771. };
  6772. var scratchScale = new Cartesian3();
  6773. /**
  6774. * Computes the maximum scale assuming the matrix is an affine transformation.
  6775. * The maximum scale is the maximum length of the column vectors in the upper-left
  6776. * 3x3 matrix.
  6777. *
  6778. * @param {Matrix4} matrix The matrix.
  6779. * @returns {Number} The maximum scale.
  6780. */
  6781. Matrix4.getMaximumScale = function(matrix) {
  6782. Matrix4.getScale(matrix, scratchScale);
  6783. return Cartesian3.maximumComponent(scratchScale);
  6784. };
  6785. /**
  6786. * Computes the product of two matrices.
  6787. *
  6788. * @param {Matrix4} left The first matrix.
  6789. * @param {Matrix4} right The second matrix.
  6790. * @param {Matrix4} result The object onto which to store the result.
  6791. * @returns {Matrix4} The modified result parameter.
  6792. */
  6793. Matrix4.multiply = function(left, right, result) {
  6794. if (!defined(left)) {
  6795. throw new DeveloperError('left is required');
  6796. }
  6797. if (!defined(right)) {
  6798. throw new DeveloperError('right is required');
  6799. }
  6800. if (!defined(result)) {
  6801. throw new DeveloperError('result is required');
  6802. }
  6803. var left0 = left[0];
  6804. var left1 = left[1];
  6805. var left2 = left[2];
  6806. var left3 = left[3];
  6807. var left4 = left[4];
  6808. var left5 = left[5];
  6809. var left6 = left[6];
  6810. var left7 = left[7];
  6811. var left8 = left[8];
  6812. var left9 = left[9];
  6813. var left10 = left[10];
  6814. var left11 = left[11];
  6815. var left12 = left[12];
  6816. var left13 = left[13];
  6817. var left14 = left[14];
  6818. var left15 = left[15];
  6819. var right0 = right[0];
  6820. var right1 = right[1];
  6821. var right2 = right[2];
  6822. var right3 = right[3];
  6823. var right4 = right[4];
  6824. var right5 = right[5];
  6825. var right6 = right[6];
  6826. var right7 = right[7];
  6827. var right8 = right[8];
  6828. var right9 = right[9];
  6829. var right10 = right[10];
  6830. var right11 = right[11];
  6831. var right12 = right[12];
  6832. var right13 = right[13];
  6833. var right14 = right[14];
  6834. var right15 = right[15];
  6835. var column0Row0 = left0 * right0 + left4 * right1 + left8 * right2 + left12 * right3;
  6836. var column0Row1 = left1 * right0 + left5 * right1 + left9 * right2 + left13 * right3;
  6837. var column0Row2 = left2 * right0 + left6 * right1 + left10 * right2 + left14 * right3;
  6838. var column0Row3 = left3 * right0 + left7 * right1 + left11 * right2 + left15 * right3;
  6839. var column1Row0 = left0 * right4 + left4 * right5 + left8 * right6 + left12 * right7;
  6840. var column1Row1 = left1 * right4 + left5 * right5 + left9 * right6 + left13 * right7;
  6841. var column1Row2 = left2 * right4 + left6 * right5 + left10 * right6 + left14 * right7;
  6842. var column1Row3 = left3 * right4 + left7 * right5 + left11 * right6 + left15 * right7;
  6843. var column2Row0 = left0 * right8 + left4 * right9 + left8 * right10 + left12 * right11;
  6844. var column2Row1 = left1 * right8 + left5 * right9 + left9 * right10 + left13 * right11;
  6845. var column2Row2 = left2 * right8 + left6 * right9 + left10 * right10 + left14 * right11;
  6846. var column2Row3 = left3 * right8 + left7 * right9 + left11 * right10 + left15 * right11;
  6847. var column3Row0 = left0 * right12 + left4 * right13 + left8 * right14 + left12 * right15;
  6848. var column3Row1 = left1 * right12 + left5 * right13 + left9 * right14 + left13 * right15;
  6849. var column3Row2 = left2 * right12 + left6 * right13 + left10 * right14 + left14 * right15;
  6850. var column3Row3 = left3 * right12 + left7 * right13 + left11 * right14 + left15 * right15;
  6851. result[0] = column0Row0;
  6852. result[1] = column0Row1;
  6853. result[2] = column0Row2;
  6854. result[3] = column0Row3;
  6855. result[4] = column1Row0;
  6856. result[5] = column1Row1;
  6857. result[6] = column1Row2;
  6858. result[7] = column1Row3;
  6859. result[8] = column2Row0;
  6860. result[9] = column2Row1;
  6861. result[10] = column2Row2;
  6862. result[11] = column2Row3;
  6863. result[12] = column3Row0;
  6864. result[13] = column3Row1;
  6865. result[14] = column3Row2;
  6866. result[15] = column3Row3;
  6867. return result;
  6868. };
  6869. /**
  6870. * Computes the sum of two matrices.
  6871. *
  6872. * @param {Matrix4} left The first matrix.
  6873. * @param {Matrix4} right The second matrix.
  6874. * @param {Matrix4} result The object onto which to store the result.
  6875. * @returns {Matrix4} The modified result parameter.
  6876. */
  6877. Matrix4.add = function(left, right, result) {
  6878. if (!defined(left)) {
  6879. throw new DeveloperError('left is required');
  6880. }
  6881. if (!defined(right)) {
  6882. throw new DeveloperError('right is required');
  6883. }
  6884. if (!defined(result)) {
  6885. throw new DeveloperError('result is required');
  6886. }
  6887. result[0] = left[0] + right[0];
  6888. result[1] = left[1] + right[1];
  6889. result[2] = left[2] + right[2];
  6890. result[3] = left[3] + right[3];
  6891. result[4] = left[4] + right[4];
  6892. result[5] = left[5] + right[5];
  6893. result[6] = left[6] + right[6];
  6894. result[7] = left[7] + right[7];
  6895. result[8] = left[8] + right[8];
  6896. result[9] = left[9] + right[9];
  6897. result[10] = left[10] + right[10];
  6898. result[11] = left[11] + right[11];
  6899. result[12] = left[12] + right[12];
  6900. result[13] = left[13] + right[13];
  6901. result[14] = left[14] + right[14];
  6902. result[15] = left[15] + right[15];
  6903. return result;
  6904. };
  6905. /**
  6906. * Computes the difference of two matrices.
  6907. *
  6908. * @param {Matrix4} left The first matrix.
  6909. * @param {Matrix4} right The second matrix.
  6910. * @param {Matrix4} result The object onto which to store the result.
  6911. * @returns {Matrix4} The modified result parameter.
  6912. */
  6913. Matrix4.subtract = function(left, right, result) {
  6914. if (!defined(left)) {
  6915. throw new DeveloperError('left is required');
  6916. }
  6917. if (!defined(right)) {
  6918. throw new DeveloperError('right is required');
  6919. }
  6920. if (!defined(result)) {
  6921. throw new DeveloperError('result is required');
  6922. }
  6923. result[0] = left[0] - right[0];
  6924. result[1] = left[1] - right[1];
  6925. result[2] = left[2] - right[2];
  6926. result[3] = left[3] - right[3];
  6927. result[4] = left[4] - right[4];
  6928. result[5] = left[5] - right[5];
  6929. result[6] = left[6] - right[6];
  6930. result[7] = left[7] - right[7];
  6931. result[8] = left[8] - right[8];
  6932. result[9] = left[9] - right[9];
  6933. result[10] = left[10] - right[10];
  6934. result[11] = left[11] - right[11];
  6935. result[12] = left[12] - right[12];
  6936. result[13] = left[13] - right[13];
  6937. result[14] = left[14] - right[14];
  6938. result[15] = left[15] - right[15];
  6939. return result;
  6940. };
  6941. /**
  6942. * Computes the product of two matrices assuming the matrices are
  6943. * affine transformation matrices, where the upper left 3x3 elements
  6944. * are a rotation matrix, and the upper three elements in the fourth
  6945. * column are the translation. The bottom row is assumed to be [0, 0, 0, 1].
  6946. * The matrix is not verified to be in the proper form.
  6947. * This method is faster than computing the product for general 4x4
  6948. * matrices using {@link Matrix4.multiply}.
  6949. *
  6950. * @param {Matrix4} left The first matrix.
  6951. * @param {Matrix4} right The second matrix.
  6952. * @param {Matrix4} result The object onto which to store the result.
  6953. * @returns {Matrix4} The modified result parameter.
  6954. *
  6955. * @example
  6956. * var m1 = new Cesium.Matrix4(1.0, 6.0, 7.0, 0.0, 2.0, 5.0, 8.0, 0.0, 3.0, 4.0, 9.0, 0.0, 0.0, 0.0, 0.0, 1.0);
  6957. * var m2 = Cesium.Transforms.eastNorthUpToFixedFrame(new Cesium.Cartesian3(1.0, 1.0, 1.0));
  6958. * var m3 = Cesium.Matrix4.multiplyTransformation(m1, m2, new Cesium.Matrix4());
  6959. */
  6960. Matrix4.multiplyTransformation = function(left, right, result) {
  6961. if (!defined(left)) {
  6962. throw new DeveloperError('left is required');
  6963. }
  6964. if (!defined(right)) {
  6965. throw new DeveloperError('right is required');
  6966. }
  6967. if (!defined(result)) {
  6968. throw new DeveloperError('result is required');
  6969. }
  6970. var left0 = left[0];
  6971. var left1 = left[1];
  6972. var left2 = left[2];
  6973. var left4 = left[4];
  6974. var left5 = left[5];
  6975. var left6 = left[6];
  6976. var left8 = left[8];
  6977. var left9 = left[9];
  6978. var left10 = left[10];
  6979. var left12 = left[12];
  6980. var left13 = left[13];
  6981. var left14 = left[14];
  6982. var right0 = right[0];
  6983. var right1 = right[1];
  6984. var right2 = right[2];
  6985. var right4 = right[4];
  6986. var right5 = right[5];
  6987. var right6 = right[6];
  6988. var right8 = right[8];
  6989. var right9 = right[9];
  6990. var right10 = right[10];
  6991. var right12 = right[12];
  6992. var right13 = right[13];
  6993. var right14 = right[14];
  6994. var column0Row0 = left0 * right0 + left4 * right1 + left8 * right2;
  6995. var column0Row1 = left1 * right0 + left5 * right1 + left9 * right2;
  6996. var column0Row2 = left2 * right0 + left6 * right1 + left10 * right2;
  6997. var column1Row0 = left0 * right4 + left4 * right5 + left8 * right6;
  6998. var column1Row1 = left1 * right4 + left5 * right5 + left9 * right6;
  6999. var column1Row2 = left2 * right4 + left6 * right5 + left10 * right6;
  7000. var column2Row0 = left0 * right8 + left4 * right9 + left8 * right10;
  7001. var column2Row1 = left1 * right8 + left5 * right9 + left9 * right10;
  7002. var column2Row2 = left2 * right8 + left6 * right9 + left10 * right10;
  7003. var column3Row0 = left0 * right12 + left4 * right13 + left8 * right14 + left12;
  7004. var column3Row1 = left1 * right12 + left5 * right13 + left9 * right14 + left13;
  7005. var column3Row2 = left2 * right12 + left6 * right13 + left10 * right14 + left14;
  7006. result[0] = column0Row0;
  7007. result[1] = column0Row1;
  7008. result[2] = column0Row2;
  7009. result[3] = 0.0;
  7010. result[4] = column1Row0;
  7011. result[5] = column1Row1;
  7012. result[6] = column1Row2;
  7013. result[7] = 0.0;
  7014. result[8] = column2Row0;
  7015. result[9] = column2Row1;
  7016. result[10] = column2Row2;
  7017. result[11] = 0.0;
  7018. result[12] = column3Row0;
  7019. result[13] = column3Row1;
  7020. result[14] = column3Row2;
  7021. result[15] = 1.0;
  7022. return result;
  7023. };
  7024. /**
  7025. * Multiplies a transformation matrix (with a bottom row of <code>[0.0, 0.0, 0.0, 1.0]</code>)
  7026. * by a 3x3 rotation matrix. This is an optimization
  7027. * for <code>Matrix4.multiply(m, Matrix4.fromRotationTranslation(rotation), m);</code> with less allocations and arithmetic operations.
  7028. *
  7029. * @param {Matrix4} matrix The matrix on the left-hand side.
  7030. * @param {Matrix3} rotation The 3x3 rotation matrix on the right-hand side.
  7031. * @param {Matrix4} result The object onto which to store the result.
  7032. * @returns {Matrix4} The modified result parameter.
  7033. *
  7034. * @example
  7035. * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromRotationTranslation(rotation), m);
  7036. * Cesium.Matrix4.multiplyByMatrix3(m, rotation, m);
  7037. */
  7038. Matrix4.multiplyByMatrix3 = function(matrix, rotation, result) {
  7039. if (!defined(matrix)) {
  7040. throw new DeveloperError('matrix is required');
  7041. }
  7042. if (!defined(rotation)) {
  7043. throw new DeveloperError('rotation is required');
  7044. }
  7045. if (!defined(result)) {
  7046. throw new DeveloperError('result is required');
  7047. }
  7048. var left0 = matrix[0];
  7049. var left1 = matrix[1];
  7050. var left2 = matrix[2];
  7051. var left4 = matrix[4];
  7052. var left5 = matrix[5];
  7053. var left6 = matrix[6];
  7054. var left8 = matrix[8];
  7055. var left9 = matrix[9];
  7056. var left10 = matrix[10];
  7057. var right0 = rotation[0];
  7058. var right1 = rotation[1];
  7059. var right2 = rotation[2];
  7060. var right4 = rotation[3];
  7061. var right5 = rotation[4];
  7062. var right6 = rotation[5];
  7063. var right8 = rotation[6];
  7064. var right9 = rotation[7];
  7065. var right10 = rotation[8];
  7066. var column0Row0 = left0 * right0 + left4 * right1 + left8 * right2;
  7067. var column0Row1 = left1 * right0 + left5 * right1 + left9 * right2;
  7068. var column0Row2 = left2 * right0 + left6 * right1 + left10 * right2;
  7069. var column1Row0 = left0 * right4 + left4 * right5 + left8 * right6;
  7070. var column1Row1 = left1 * right4 + left5 * right5 + left9 * right6;
  7071. var column1Row2 = left2 * right4 + left6 * right5 + left10 * right6;
  7072. var column2Row0 = left0 * right8 + left4 * right9 + left8 * right10;
  7073. var column2Row1 = left1 * right8 + left5 * right9 + left9 * right10;
  7074. var column2Row2 = left2 * right8 + left6 * right9 + left10 * right10;
  7075. result[0] = column0Row0;
  7076. result[1] = column0Row1;
  7077. result[2] = column0Row2;
  7078. result[3] = 0.0;
  7079. result[4] = column1Row0;
  7080. result[5] = column1Row1;
  7081. result[6] = column1Row2;
  7082. result[7] = 0.0;
  7083. result[8] = column2Row0;
  7084. result[9] = column2Row1;
  7085. result[10] = column2Row2;
  7086. result[11] = 0.0;
  7087. result[12] = matrix[12];
  7088. result[13] = matrix[13];
  7089. result[14] = matrix[14];
  7090. result[15] = matrix[15];
  7091. return result;
  7092. };
  7093. /**
  7094. * Multiplies a transformation matrix (with a bottom row of <code>[0.0, 0.0, 0.0, 1.0]</code>)
  7095. * by an implicit translation matrix defined by a {@link Cartesian3}. This is an optimization
  7096. * for <code>Matrix4.multiply(m, Matrix4.fromTranslation(position), m);</code> with less allocations and arithmetic operations.
  7097. *
  7098. * @param {Matrix4} matrix The matrix on the left-hand side.
  7099. * @param {Cartesian3} translation The translation on the right-hand side.
  7100. * @param {Matrix4} result The object onto which to store the result.
  7101. * @returns {Matrix4} The modified result parameter.
  7102. *
  7103. * @example
  7104. * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromTranslation(position), m);
  7105. * Cesium.Matrix4.multiplyByTranslation(m, position, m);
  7106. */
  7107. Matrix4.multiplyByTranslation = function(matrix, translation, result) {
  7108. if (!defined(matrix)) {
  7109. throw new DeveloperError('matrix is required');
  7110. }
  7111. if (!defined(translation)) {
  7112. throw new DeveloperError('translation is required');
  7113. }
  7114. if (!defined(result)) {
  7115. throw new DeveloperError('result is required');
  7116. }
  7117. var x = translation.x;
  7118. var y = translation.y;
  7119. var z = translation.z;
  7120. var tx = (x * matrix[0]) + (y * matrix[4]) + (z * matrix[8]) + matrix[12];
  7121. var ty = (x * matrix[1]) + (y * matrix[5]) + (z * matrix[9]) + matrix[13];
  7122. var tz = (x * matrix[2]) + (y * matrix[6]) + (z * matrix[10]) + matrix[14];
  7123. result[0] = matrix[0];
  7124. result[1] = matrix[1];
  7125. result[2] = matrix[2];
  7126. result[3] = matrix[3];
  7127. result[4] = matrix[4];
  7128. result[5] = matrix[5];
  7129. result[6] = matrix[6];
  7130. result[7] = matrix[7];
  7131. result[8] = matrix[8];
  7132. result[9] = matrix[9];
  7133. result[10] = matrix[10];
  7134. result[11] = matrix[11];
  7135. result[12] = tx;
  7136. result[13] = ty;
  7137. result[14] = tz;
  7138. result[15] = matrix[15];
  7139. return result;
  7140. };
  7141. var uniformScaleScratch = new Cartesian3();
  7142. /**
  7143. * Multiplies an affine transformation matrix (with a bottom row of <code>[0.0, 0.0, 0.0, 1.0]</code>)
  7144. * by an implicit uniform scale matrix. This is an optimization
  7145. * for <code>Matrix4.multiply(m, Matrix4.fromUniformScale(scale), m);</code>, where
  7146. * <code>m</code> must be an affine matrix.
  7147. * This function performs fewer allocations and arithmetic operations.
  7148. *
  7149. * @param {Matrix4} matrix The affine matrix on the left-hand side.
  7150. * @param {Number} scale The uniform scale on the right-hand side.
  7151. * @param {Matrix4} result The object onto which to store the result.
  7152. * @returns {Matrix4} The modified result parameter.
  7153. *
  7154. *
  7155. * @example
  7156. * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromUniformScale(scale), m);
  7157. * Cesium.Matrix4.multiplyByUniformScale(m, scale, m);
  7158. *
  7159. * @see Matrix4.fromUniformScale
  7160. * @see Matrix4.multiplyByScale
  7161. */
  7162. Matrix4.multiplyByUniformScale = function(matrix, scale, result) {
  7163. if (!defined(matrix)) {
  7164. throw new DeveloperError('matrix is required');
  7165. }
  7166. if (typeof scale !== 'number') {
  7167. throw new DeveloperError('scale is required');
  7168. }
  7169. if (!defined(result)) {
  7170. throw new DeveloperError('result is required');
  7171. }
  7172. uniformScaleScratch.x = scale;
  7173. uniformScaleScratch.y = scale;
  7174. uniformScaleScratch.z = scale;
  7175. return Matrix4.multiplyByScale(matrix, uniformScaleScratch, result);
  7176. };
  7177. /**
  7178. * Multiplies an affine transformation matrix (with a bottom row of <code>[0.0, 0.0, 0.0, 1.0]</code>)
  7179. * by an implicit non-uniform scale matrix. This is an optimization
  7180. * for <code>Matrix4.multiply(m, Matrix4.fromUniformScale(scale), m);</code>, where
  7181. * <code>m</code> must be an affine matrix.
  7182. * This function performs fewer allocations and arithmetic operations.
  7183. *
  7184. * @param {Matrix4} matrix The affine matrix on the left-hand side.
  7185. * @param {Cartesian3} scale The non-uniform scale on the right-hand side.
  7186. * @param {Matrix4} result The object onto which to store the result.
  7187. * @returns {Matrix4} The modified result parameter.
  7188. *
  7189. *
  7190. * @example
  7191. * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromScale(scale), m);
  7192. * Cesium.Matrix4.multiplyByScale(m, scale, m);
  7193. *
  7194. * @see Matrix4.fromScale
  7195. * @see Matrix4.multiplyByUniformScale
  7196. */
  7197. Matrix4.multiplyByScale = function(matrix, scale, result) {
  7198. if (!defined(matrix)) {
  7199. throw new DeveloperError('matrix is required');
  7200. }
  7201. if (!defined(scale)) {
  7202. throw new DeveloperError('scale is required');
  7203. }
  7204. if (!defined(result)) {
  7205. throw new DeveloperError('result is required');
  7206. }
  7207. var scaleX = scale.x;
  7208. var scaleY = scale.y;
  7209. var scaleZ = scale.z;
  7210. // Faster than Cartesian3.equals
  7211. if ((scaleX === 1.0) && (scaleY === 1.0) && (scaleZ === 1.0)) {
  7212. return Matrix4.clone(matrix, result);
  7213. }
  7214. result[0] = scaleX * matrix[0];
  7215. result[1] = scaleX * matrix[1];
  7216. result[2] = scaleX * matrix[2];
  7217. result[3] = 0.0;
  7218. result[4] = scaleY * matrix[4];
  7219. result[5] = scaleY * matrix[5];
  7220. result[6] = scaleY * matrix[6];
  7221. result[7] = 0.0;
  7222. result[8] = scaleZ * matrix[8];
  7223. result[9] = scaleZ * matrix[9];
  7224. result[10] = scaleZ * matrix[10];
  7225. result[11] = 0.0;
  7226. result[12] = matrix[12];
  7227. result[13] = matrix[13];
  7228. result[14] = matrix[14];
  7229. result[15] = 1.0;
  7230. return result;
  7231. };
  7232. /**
  7233. * Computes the product of a matrix and a column vector.
  7234. *
  7235. * @param {Matrix4} matrix The matrix.
  7236. * @param {Cartesian4} cartesian The vector.
  7237. * @param {Cartesian4} result The object onto which to store the result.
  7238. * @returns {Cartesian4} The modified result parameter.
  7239. */
  7240. Matrix4.multiplyByVector = function(matrix, cartesian, result) {
  7241. if (!defined(matrix)) {
  7242. throw new DeveloperError('matrix is required');
  7243. }
  7244. if (!defined(cartesian)) {
  7245. throw new DeveloperError('cartesian is required');
  7246. }
  7247. if (!defined(result)) {
  7248. throw new DeveloperError('result is required');
  7249. }
  7250. var vX = cartesian.x;
  7251. var vY = cartesian.y;
  7252. var vZ = cartesian.z;
  7253. var vW = cartesian.w;
  7254. var x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ + matrix[12] * vW;
  7255. var y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ + matrix[13] * vW;
  7256. var z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ + matrix[14] * vW;
  7257. var w = matrix[3] * vX + matrix[7] * vY + matrix[11] * vZ + matrix[15] * vW;
  7258. result.x = x;
  7259. result.y = y;
  7260. result.z = z;
  7261. result.w = w;
  7262. return result;
  7263. };
  7264. /**
  7265. * Computes the product of a matrix and a {@link Cartesian3}. This is equivalent to calling {@link Matrix4.multiplyByVector}
  7266. * with a {@link Cartesian4} with a <code>w</code> component of zero.
  7267. *
  7268. * @param {Matrix4} matrix The matrix.
  7269. * @param {Cartesian3} cartesian The point.
  7270. * @param {Cartesian3} result The object onto which to store the result.
  7271. * @returns {Cartesian3} The modified result parameter.
  7272. *
  7273. * @example
  7274. * var p = new Cesium.Cartesian3(1.0, 2.0, 3.0);
  7275. * var result = Cesium.Matrix4.multiplyByPointAsVector(matrix, p, new Cesium.Cartesian3());
  7276. * // A shortcut for
  7277. * // Cartesian3 p = ...
  7278. * // Cesium.Matrix4.multiplyByVector(matrix, new Cesium.Cartesian4(p.x, p.y, p.z, 0.0), result);
  7279. */
  7280. Matrix4.multiplyByPointAsVector = function(matrix, cartesian, result) {
  7281. if (!defined(matrix)) {
  7282. throw new DeveloperError('matrix is required');
  7283. }
  7284. if (!defined(cartesian)) {
  7285. throw new DeveloperError('cartesian is required');
  7286. }
  7287. if (!defined(result)) {
  7288. throw new DeveloperError('result is required');
  7289. }
  7290. var vX = cartesian.x;
  7291. var vY = cartesian.y;
  7292. var vZ = cartesian.z;
  7293. var x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ;
  7294. var y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ;
  7295. var z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ;
  7296. result.x = x;
  7297. result.y = y;
  7298. result.z = z;
  7299. return result;
  7300. };
  7301. /**
  7302. * Computes the product of a matrix and a {@link Cartesian3}. This is equivalent to calling {@link Matrix4.multiplyByVector}
  7303. * with a {@link Cartesian4} with a <code>w</code> component of 1, but returns a {@link Cartesian3} instead of a {@link Cartesian4}.
  7304. *
  7305. * @param {Matrix4} matrix The matrix.
  7306. * @param {Cartesian3} cartesian The point.
  7307. * @param {Cartesian3} result The object onto which to store the result.
  7308. * @returns {Cartesian3} The modified result parameter.
  7309. *
  7310. * @example
  7311. * var p = new Cesium.Cartesian3(1.0, 2.0, 3.0);
  7312. * var result = Cesium.Matrix4.multiplyByPoint(matrix, p, new Cesium.Cartesian3());
  7313. */
  7314. Matrix4.multiplyByPoint = function(matrix, cartesian, result) {
  7315. if (!defined(matrix)) {
  7316. throw new DeveloperError('matrix is required');
  7317. }
  7318. if (!defined(cartesian)) {
  7319. throw new DeveloperError('cartesian is required');
  7320. }
  7321. if (!defined(result)) {
  7322. throw new DeveloperError('result is required');
  7323. }
  7324. var vX = cartesian.x;
  7325. var vY = cartesian.y;
  7326. var vZ = cartesian.z;
  7327. var x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ + matrix[12];
  7328. var y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ + matrix[13];
  7329. var z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ + matrix[14];
  7330. result.x = x;
  7331. result.y = y;
  7332. result.z = z;
  7333. return result;
  7334. };
  7335. /**
  7336. * Computes the product of a matrix and a scalar.
  7337. *
  7338. * @param {Matrix4} matrix The matrix.
  7339. * @param {Number} scalar The number to multiply by.
  7340. * @param {Matrix4} result The object onto which to store the result.
  7341. * @returns {Matrix4} The modified result parameter.
  7342. *
  7343. * @example
  7344. * //create a Matrix4 instance which is a scaled version of the supplied Matrix4
  7345. * // m = [10.0, 11.0, 12.0, 13.0]
  7346. * // [14.0, 15.0, 16.0, 17.0]
  7347. * // [18.0, 19.0, 20.0, 21.0]
  7348. * // [22.0, 23.0, 24.0, 25.0]
  7349. *
  7350. * var a = Cesium.Matrix4.multiplyByScalar(m, -2, new Cesium.Matrix4());
  7351. *
  7352. * // m remains the same
  7353. * // a = [-20.0, -22.0, -24.0, -26.0]
  7354. * // [-28.0, -30.0, -32.0, -34.0]
  7355. * // [-36.0, -38.0, -40.0, -42.0]
  7356. * // [-44.0, -46.0, -48.0, -50.0]
  7357. */
  7358. Matrix4.multiplyByScalar = function(matrix, scalar, result) {
  7359. if (!defined(matrix)) {
  7360. throw new DeveloperError('matrix is required');
  7361. }
  7362. if (typeof scalar !== 'number') {
  7363. throw new DeveloperError('scalar must be a number');
  7364. }
  7365. if (!defined(result)) {
  7366. throw new DeveloperError('result is required');
  7367. }
  7368. result[0] = matrix[0] * scalar;
  7369. result[1] = matrix[1] * scalar;
  7370. result[2] = matrix[2] * scalar;
  7371. result[3] = matrix[3] * scalar;
  7372. result[4] = matrix[4] * scalar;
  7373. result[5] = matrix[5] * scalar;
  7374. result[6] = matrix[6] * scalar;
  7375. result[7] = matrix[7] * scalar;
  7376. result[8] = matrix[8] * scalar;
  7377. result[9] = matrix[9] * scalar;
  7378. result[10] = matrix[10] * scalar;
  7379. result[11] = matrix[11] * scalar;
  7380. result[12] = matrix[12] * scalar;
  7381. result[13] = matrix[13] * scalar;
  7382. result[14] = matrix[14] * scalar;
  7383. result[15] = matrix[15] * scalar;
  7384. return result;
  7385. };
  7386. /**
  7387. * Computes a negated copy of the provided matrix.
  7388. *
  7389. * @param {Matrix4} matrix The matrix to negate.
  7390. * @param {Matrix4} result The object onto which to store the result.
  7391. * @returns {Matrix4} The modified result parameter.
  7392. *
  7393. * @example
  7394. * //create a new Matrix4 instance which is a negation of a Matrix4
  7395. * // m = [10.0, 11.0, 12.0, 13.0]
  7396. * // [14.0, 15.0, 16.0, 17.0]
  7397. * // [18.0, 19.0, 20.0, 21.0]
  7398. * // [22.0, 23.0, 24.0, 25.0]
  7399. *
  7400. * var a = Cesium.Matrix4.negate(m, new Cesium.Matrix4());
  7401. *
  7402. * // m remains the same
  7403. * // a = [-10.0, -11.0, -12.0, -13.0]
  7404. * // [-14.0, -15.0, -16.0, -17.0]
  7405. * // [-18.0, -19.0, -20.0, -21.0]
  7406. * // [-22.0, -23.0, -24.0, -25.0]
  7407. */
  7408. Matrix4.negate = function(matrix, result) {
  7409. if (!defined(matrix)) {
  7410. throw new DeveloperError('matrix is required');
  7411. }
  7412. if (!defined(result)) {
  7413. throw new DeveloperError('result is required');
  7414. }
  7415. result[0] = -matrix[0];
  7416. result[1] = -matrix[1];
  7417. result[2] = -matrix[2];
  7418. result[3] = -matrix[3];
  7419. result[4] = -matrix[4];
  7420. result[5] = -matrix[5];
  7421. result[6] = -matrix[6];
  7422. result[7] = -matrix[7];
  7423. result[8] = -matrix[8];
  7424. result[9] = -matrix[9];
  7425. result[10] = -matrix[10];
  7426. result[11] = -matrix[11];
  7427. result[12] = -matrix[12];
  7428. result[13] = -matrix[13];
  7429. result[14] = -matrix[14];
  7430. result[15] = -matrix[15];
  7431. return result;
  7432. };
  7433. /**
  7434. * Computes the transpose of the provided matrix.
  7435. *
  7436. * @param {Matrix4} matrix The matrix to transpose.
  7437. * @param {Matrix4} result The object onto which to store the result.
  7438. * @returns {Matrix4} The modified result parameter.
  7439. *
  7440. * @example
  7441. * //returns transpose of a Matrix4
  7442. * // m = [10.0, 11.0, 12.0, 13.0]
  7443. * // [14.0, 15.0, 16.0, 17.0]
  7444. * // [18.0, 19.0, 20.0, 21.0]
  7445. * // [22.0, 23.0, 24.0, 25.0]
  7446. *
  7447. * var a = Cesium.Matrix4.transpose(m, new Cesium.Matrix4());
  7448. *
  7449. * // m remains the same
  7450. * // a = [10.0, 14.0, 18.0, 22.0]
  7451. * // [11.0, 15.0, 19.0, 23.0]
  7452. * // [12.0, 16.0, 20.0, 24.0]
  7453. * // [13.0, 17.0, 21.0, 25.0]
  7454. */
  7455. Matrix4.transpose = function(matrix, result) {
  7456. if (!defined(matrix)) {
  7457. throw new DeveloperError('matrix is required');
  7458. }
  7459. if (!defined(result)) {
  7460. throw new DeveloperError('result is required');
  7461. }
  7462. var matrix1 = matrix[1];
  7463. var matrix2 = matrix[2];
  7464. var matrix3 = matrix[3];
  7465. var matrix6 = matrix[6];
  7466. var matrix7 = matrix[7];
  7467. var matrix11 = matrix[11];
  7468. result[0] = matrix[0];
  7469. result[1] = matrix[4];
  7470. result[2] = matrix[8];
  7471. result[3] = matrix[12];
  7472. result[4] = matrix1;
  7473. result[5] = matrix[5];
  7474. result[6] = matrix[9];
  7475. result[7] = matrix[13];
  7476. result[8] = matrix2;
  7477. result[9] = matrix6;
  7478. result[10] = matrix[10];
  7479. result[11] = matrix[14];
  7480. result[12] = matrix3;
  7481. result[13] = matrix7;
  7482. result[14] = matrix11;
  7483. result[15] = matrix[15];
  7484. return result;
  7485. };
  7486. /**
  7487. * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.
  7488. *
  7489. * @param {Matrix4} matrix The matrix with signed elements.
  7490. * @param {Matrix4} result The object onto which to store the result.
  7491. * @returns {Matrix4} The modified result parameter.
  7492. */
  7493. Matrix4.abs = function(matrix, result) {
  7494. if (!defined(matrix)) {
  7495. throw new DeveloperError('matrix is required');
  7496. }
  7497. if (!defined(result)) {
  7498. throw new DeveloperError('result is required');
  7499. }
  7500. result[0] = Math.abs(matrix[0]);
  7501. result[1] = Math.abs(matrix[1]);
  7502. result[2] = Math.abs(matrix[2]);
  7503. result[3] = Math.abs(matrix[3]);
  7504. result[4] = Math.abs(matrix[4]);
  7505. result[5] = Math.abs(matrix[5]);
  7506. result[6] = Math.abs(matrix[6]);
  7507. result[7] = Math.abs(matrix[7]);
  7508. result[8] = Math.abs(matrix[8]);
  7509. result[9] = Math.abs(matrix[9]);
  7510. result[10] = Math.abs(matrix[10]);
  7511. result[11] = Math.abs(matrix[11]);
  7512. result[12] = Math.abs(matrix[12]);
  7513. result[13] = Math.abs(matrix[13]);
  7514. result[14] = Math.abs(matrix[14]);
  7515. result[15] = Math.abs(matrix[15]);
  7516. return result;
  7517. };
  7518. /**
  7519. * Compares the provided matrices componentwise and returns
  7520. * <code>true</code> if they are equal, <code>false</code> otherwise.
  7521. *
  7522. * @param {Matrix4} [left] The first matrix.
  7523. * @param {Matrix4} [right] The second matrix.
  7524. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  7525. *
  7526. * @example
  7527. * //compares two Matrix4 instances
  7528. *
  7529. * // a = [10.0, 14.0, 18.0, 22.0]
  7530. * // [11.0, 15.0, 19.0, 23.0]
  7531. * // [12.0, 16.0, 20.0, 24.0]
  7532. * // [13.0, 17.0, 21.0, 25.0]
  7533. *
  7534. * // b = [10.0, 14.0, 18.0, 22.0]
  7535. * // [11.0, 15.0, 19.0, 23.0]
  7536. * // [12.0, 16.0, 20.0, 24.0]
  7537. * // [13.0, 17.0, 21.0, 25.0]
  7538. *
  7539. * if(Cesium.Matrix4.equals(a,b)) {
  7540. * console.log("Both matrices are equal");
  7541. * } else {
  7542. * console.log("They are not equal");
  7543. * }
  7544. *
  7545. * //Prints "Both matrices are equal" on the console
  7546. */
  7547. Matrix4.equals = function(left, right) {
  7548. // Given that most matrices will be transformation matrices, the elements
  7549. // are tested in order such that the test is likely to fail as early
  7550. // as possible. I _think_ this is just as friendly to the L1 cache
  7551. // as testing in index order. It is certainty faster in practice.
  7552. return (left === right) ||
  7553. (defined(left) &&
  7554. defined(right) &&
  7555. // Translation
  7556. left[12] === right[12] &&
  7557. left[13] === right[13] &&
  7558. left[14] === right[14] &&
  7559. // Rotation/scale
  7560. left[0] === right[0] &&
  7561. left[1] === right[1] &&
  7562. left[2] === right[2] &&
  7563. left[4] === right[4] &&
  7564. left[5] === right[5] &&
  7565. left[6] === right[6] &&
  7566. left[8] === right[8] &&
  7567. left[9] === right[9] &&
  7568. left[10] === right[10] &&
  7569. // Bottom row
  7570. left[3] === right[3] &&
  7571. left[7] === right[7] &&
  7572. left[11] === right[11] &&
  7573. left[15] === right[15]);
  7574. };
  7575. /**
  7576. * Compares the provided matrices componentwise and returns
  7577. * <code>true</code> if they are within the provided epsilon,
  7578. * <code>false</code> otherwise.
  7579. *
  7580. * @param {Matrix4} [left] The first matrix.
  7581. * @param {Matrix4} [right] The second matrix.
  7582. * @param {Number} epsilon The epsilon to use for equality testing.
  7583. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  7584. *
  7585. * @example
  7586. * //compares two Matrix4 instances
  7587. *
  7588. * // a = [10.5, 14.5, 18.5, 22.5]
  7589. * // [11.5, 15.5, 19.5, 23.5]
  7590. * // [12.5, 16.5, 20.5, 24.5]
  7591. * // [13.5, 17.5, 21.5, 25.5]
  7592. *
  7593. * // b = [10.0, 14.0, 18.0, 22.0]
  7594. * // [11.0, 15.0, 19.0, 23.0]
  7595. * // [12.0, 16.0, 20.0, 24.0]
  7596. * // [13.0, 17.0, 21.0, 25.0]
  7597. *
  7598. * if(Cesium.Matrix4.equalsEpsilon(a,b,0.1)){
  7599. * console.log("Difference between both the matrices is less than 0.1");
  7600. * } else {
  7601. * console.log("Difference between both the matrices is not less than 0.1");
  7602. * }
  7603. *
  7604. * //Prints "Difference between both the matrices is not less than 0.1" on the console
  7605. */
  7606. Matrix4.equalsEpsilon = function(left, right, epsilon) {
  7607. if (typeof epsilon !== 'number') {
  7608. throw new DeveloperError('epsilon must be a number');
  7609. }
  7610. return (left === right) ||
  7611. (defined(left) &&
  7612. defined(right) &&
  7613. Math.abs(left[0] - right[0]) <= epsilon &&
  7614. Math.abs(left[1] - right[1]) <= epsilon &&
  7615. Math.abs(left[2] - right[2]) <= epsilon &&
  7616. Math.abs(left[3] - right[3]) <= epsilon &&
  7617. Math.abs(left[4] - right[4]) <= epsilon &&
  7618. Math.abs(left[5] - right[5]) <= epsilon &&
  7619. Math.abs(left[6] - right[6]) <= epsilon &&
  7620. Math.abs(left[7] - right[7]) <= epsilon &&
  7621. Math.abs(left[8] - right[8]) <= epsilon &&
  7622. Math.abs(left[9] - right[9]) <= epsilon &&
  7623. Math.abs(left[10] - right[10]) <= epsilon &&
  7624. Math.abs(left[11] - right[11]) <= epsilon &&
  7625. Math.abs(left[12] - right[12]) <= epsilon &&
  7626. Math.abs(left[13] - right[13]) <= epsilon &&
  7627. Math.abs(left[14] - right[14]) <= epsilon &&
  7628. Math.abs(left[15] - right[15]) <= epsilon);
  7629. };
  7630. /**
  7631. * Gets the translation portion of the provided matrix, assuming the matrix is a affine transformation matrix.
  7632. *
  7633. * @param {Matrix4} matrix The matrix to use.
  7634. * @param {Cartesian3} result The object onto which to store the result.
  7635. * @returns {Cartesian3} The modified result parameter.
  7636. */
  7637. Matrix4.getTranslation = function(matrix, result) {
  7638. if (!defined(matrix)) {
  7639. throw new DeveloperError('matrix is required');
  7640. }
  7641. if (!defined(result)) {
  7642. throw new DeveloperError('result is required');
  7643. }
  7644. result.x = matrix[12];
  7645. result.y = matrix[13];
  7646. result.z = matrix[14];
  7647. return result;
  7648. };
  7649. /**
  7650. * Gets the upper left 3x3 rotation matrix of the provided matrix, assuming the matrix is a affine transformation matrix.
  7651. *
  7652. * @param {Matrix4} matrix The matrix to use.
  7653. * @param {Matrix3} result The object onto which to store the result.
  7654. * @returns {Matrix3} The modified result parameter.
  7655. *
  7656. * @example
  7657. * // returns a Matrix3 instance from a Matrix4 instance
  7658. *
  7659. * // m = [10.0, 14.0, 18.0, 22.0]
  7660. * // [11.0, 15.0, 19.0, 23.0]
  7661. * // [12.0, 16.0, 20.0, 24.0]
  7662. * // [13.0, 17.0, 21.0, 25.0]
  7663. *
  7664. * var b = new Cesium.Matrix3();
  7665. * Cesium.Matrix4.getRotation(m,b);
  7666. *
  7667. * // b = [10.0, 14.0, 18.0]
  7668. * // [11.0, 15.0, 19.0]
  7669. * // [12.0, 16.0, 20.0]
  7670. */
  7671. Matrix4.getRotation = function(matrix, result) {
  7672. if (!defined(matrix)) {
  7673. throw new DeveloperError('matrix is required');
  7674. }
  7675. if (!defined(result)) {
  7676. throw new DeveloperError('result is required');
  7677. }
  7678. result[0] = matrix[0];
  7679. result[1] = matrix[1];
  7680. result[2] = matrix[2];
  7681. result[3] = matrix[4];
  7682. result[4] = matrix[5];
  7683. result[5] = matrix[6];
  7684. result[6] = matrix[8];
  7685. result[7] = matrix[9];
  7686. result[8] = matrix[10];
  7687. return result;
  7688. };
  7689. var scratchInverseRotation = new Matrix3();
  7690. var scratchMatrix3Zero = new Matrix3();
  7691. var scratchBottomRow = new Cartesian4();
  7692. var scratchExpectedBottomRow = new Cartesian4(0.0, 0.0, 0.0, 1.0);
  7693. /**
  7694. * Computes the inverse of the provided matrix using Cramers Rule.
  7695. * If the determinant is zero, the matrix can not be inverted, and an exception is thrown.
  7696. * If the matrix is an affine transformation matrix, it is more efficient
  7697. * to invert it with {@link Matrix4.inverseTransformation}.
  7698. *
  7699. * @param {Matrix4} matrix The matrix to invert.
  7700. * @param {Matrix4} result The object onto which to store the result.
  7701. * @returns {Matrix4} The modified result parameter.
  7702. *
  7703. * @exception {RuntimeError} matrix is not invertible because its determinate is zero.
  7704. */
  7705. Matrix4.inverse = function(matrix, result) {
  7706. if (!defined(matrix)) {
  7707. throw new DeveloperError('matrix is required');
  7708. }
  7709. if (!defined(result)) {
  7710. throw new DeveloperError('result is required');
  7711. }
  7712. // Special case for a zero scale matrix that can occur, for example,
  7713. // when a model's node has a [0, 0, 0] scale.
  7714. if (Matrix3.equalsEpsilon(Matrix4.getRotation(matrix, scratchInverseRotation), scratchMatrix3Zero, CesiumMath.EPSILON7) &&
  7715. Cartesian4.equals(Matrix4.getRow(matrix, 3, scratchBottomRow), scratchExpectedBottomRow)) {
  7716. result[0] = 0.0;
  7717. result[1] = 0.0;
  7718. result[2] = 0.0;
  7719. result[3] = 0.0;
  7720. result[4] = 0.0;
  7721. result[5] = 0.0;
  7722. result[6] = 0.0;
  7723. result[7] = 0.0;
  7724. result[8] = 0.0;
  7725. result[9] = 0.0;
  7726. result[10] = 0.0;
  7727. result[11] = 0.0;
  7728. result[12] = -matrix[12];
  7729. result[13] = -matrix[13];
  7730. result[14] = -matrix[14];
  7731. result[15] = 1.0;
  7732. return result;
  7733. }
  7734. //
  7735. // Ported from:
  7736. // ftp://download.intel.com/design/PentiumIII/sml/24504301.pdf
  7737. //
  7738. var src0 = matrix[0];
  7739. var src1 = matrix[4];
  7740. var src2 = matrix[8];
  7741. var src3 = matrix[12];
  7742. var src4 = matrix[1];
  7743. var src5 = matrix[5];
  7744. var src6 = matrix[9];
  7745. var src7 = matrix[13];
  7746. var src8 = matrix[2];
  7747. var src9 = matrix[6];
  7748. var src10 = matrix[10];
  7749. var src11 = matrix[14];
  7750. var src12 = matrix[3];
  7751. var src13 = matrix[7];
  7752. var src14 = matrix[11];
  7753. var src15 = matrix[15];
  7754. // calculate pairs for first 8 elements (cofactors)
  7755. var tmp0 = src10 * src15;
  7756. var tmp1 = src11 * src14;
  7757. var tmp2 = src9 * src15;
  7758. var tmp3 = src11 * src13;
  7759. var tmp4 = src9 * src14;
  7760. var tmp5 = src10 * src13;
  7761. var tmp6 = src8 * src15;
  7762. var tmp7 = src11 * src12;
  7763. var tmp8 = src8 * src14;
  7764. var tmp9 = src10 * src12;
  7765. var tmp10 = src8 * src13;
  7766. var tmp11 = src9 * src12;
  7767. // calculate first 8 elements (cofactors)
  7768. var dst0 = (tmp0 * src5 + tmp3 * src6 + tmp4 * src7) - (tmp1 * src5 + tmp2 * src6 + tmp5 * src7);
  7769. var dst1 = (tmp1 * src4 + tmp6 * src6 + tmp9 * src7) - (tmp0 * src4 + tmp7 * src6 + tmp8 * src7);
  7770. var dst2 = (tmp2 * src4 + tmp7 * src5 + tmp10 * src7) - (tmp3 * src4 + tmp6 * src5 + tmp11 * src7);
  7771. var dst3 = (tmp5 * src4 + tmp8 * src5 + tmp11 * src6) - (tmp4 * src4 + tmp9 * src5 + tmp10 * src6);
  7772. var dst4 = (tmp1 * src1 + tmp2 * src2 + tmp5 * src3) - (tmp0 * src1 + tmp3 * src2 + tmp4 * src3);
  7773. var dst5 = (tmp0 * src0 + tmp7 * src2 + tmp8 * src3) - (tmp1 * src0 + tmp6 * src2 + tmp9 * src3);
  7774. var dst6 = (tmp3 * src0 + tmp6 * src1 + tmp11 * src3) - (tmp2 * src0 + tmp7 * src1 + tmp10 * src3);
  7775. var dst7 = (tmp4 * src0 + tmp9 * src1 + tmp10 * src2) - (tmp5 * src0 + tmp8 * src1 + tmp11 * src2);
  7776. // calculate pairs for second 8 elements (cofactors)
  7777. tmp0 = src2 * src7;
  7778. tmp1 = src3 * src6;
  7779. tmp2 = src1 * src7;
  7780. tmp3 = src3 * src5;
  7781. tmp4 = src1 * src6;
  7782. tmp5 = src2 * src5;
  7783. tmp6 = src0 * src7;
  7784. tmp7 = src3 * src4;
  7785. tmp8 = src0 * src6;
  7786. tmp9 = src2 * src4;
  7787. tmp10 = src0 * src5;
  7788. tmp11 = src1 * src4;
  7789. // calculate second 8 elements (cofactors)
  7790. var dst8 = (tmp0 * src13 + tmp3 * src14 + tmp4 * src15) - (tmp1 * src13 + tmp2 * src14 + tmp5 * src15);
  7791. var dst9 = (tmp1 * src12 + tmp6 * src14 + tmp9 * src15) - (tmp0 * src12 + tmp7 * src14 + tmp8 * src15);
  7792. var dst10 = (tmp2 * src12 + tmp7 * src13 + tmp10 * src15) - (tmp3 * src12 + tmp6 * src13 + tmp11 * src15);
  7793. var dst11 = (tmp5 * src12 + tmp8 * src13 + tmp11 * src14) - (tmp4 * src12 + tmp9 * src13 + tmp10 * src14);
  7794. var dst12 = (tmp2 * src10 + tmp5 * src11 + tmp1 * src9) - (tmp4 * src11 + tmp0 * src9 + tmp3 * src10);
  7795. var dst13 = (tmp8 * src11 + tmp0 * src8 + tmp7 * src10) - (tmp6 * src10 + tmp9 * src11 + tmp1 * src8);
  7796. var dst14 = (tmp6 * src9 + tmp11 * src11 + tmp3 * src8) - (tmp10 * src11 + tmp2 * src8 + tmp7 * src9);
  7797. var dst15 = (tmp10 * src10 + tmp4 * src8 + tmp9 * src9) - (tmp8 * src9 + tmp11 * src10 + tmp5 * src8);
  7798. // calculate determinant
  7799. var det = src0 * dst0 + src1 * dst1 + src2 * dst2 + src3 * dst3;
  7800. if (Math.abs(det) < CesiumMath.EPSILON20) {
  7801. throw new RuntimeError('matrix is not invertible because its determinate is zero.');
  7802. }
  7803. // calculate matrix inverse
  7804. det = 1.0 / det;
  7805. result[0] = dst0 * det;
  7806. result[1] = dst1 * det;
  7807. result[2] = dst2 * det;
  7808. result[3] = dst3 * det;
  7809. result[4] = dst4 * det;
  7810. result[5] = dst5 * det;
  7811. result[6] = dst6 * det;
  7812. result[7] = dst7 * det;
  7813. result[8] = dst8 * det;
  7814. result[9] = dst9 * det;
  7815. result[10] = dst10 * det;
  7816. result[11] = dst11 * det;
  7817. result[12] = dst12 * det;
  7818. result[13] = dst13 * det;
  7819. result[14] = dst14 * det;
  7820. result[15] = dst15 * det;
  7821. return result;
  7822. };
  7823. /**
  7824. * Computes the inverse of the provided matrix assuming it is
  7825. * an affine transformation matrix, where the upper left 3x3 elements
  7826. * are a rotation matrix, and the upper three elements in the fourth
  7827. * column are the translation. The bottom row is assumed to be [0, 0, 0, 1].
  7828. * The matrix is not verified to be in the proper form.
  7829. * This method is faster than computing the inverse for a general 4x4
  7830. * matrix using {@link Matrix4.inverse}.
  7831. *
  7832. * @param {Matrix4} matrix The matrix to invert.
  7833. * @param {Matrix4} result The object onto which to store the result.
  7834. * @returns {Matrix4} The modified result parameter.
  7835. */
  7836. Matrix4.inverseTransformation = function(matrix, result) {
  7837. if (!defined(matrix)) {
  7838. throw new DeveloperError('matrix is required');
  7839. }
  7840. if (!defined(result)) {
  7841. throw new DeveloperError('result is required');
  7842. }
  7843. //This function is an optimized version of the below 4 lines.
  7844. //var rT = Matrix3.transpose(Matrix4.getRotation(matrix));
  7845. //var rTN = Matrix3.negate(rT);
  7846. //var rTT = Matrix3.multiplyByVector(rTN, Matrix4.getTranslation(matrix));
  7847. //return Matrix4.fromRotationTranslation(rT, rTT, result);
  7848. var matrix0 = matrix[0];
  7849. var matrix1 = matrix[1];
  7850. var matrix2 = matrix[2];
  7851. var matrix4 = matrix[4];
  7852. var matrix5 = matrix[5];
  7853. var matrix6 = matrix[6];
  7854. var matrix8 = matrix[8];
  7855. var matrix9 = matrix[9];
  7856. var matrix10 = matrix[10];
  7857. var vX = matrix[12];
  7858. var vY = matrix[13];
  7859. var vZ = matrix[14];
  7860. var x = -matrix0 * vX - matrix1 * vY - matrix2 * vZ;
  7861. var y = -matrix4 * vX - matrix5 * vY - matrix6 * vZ;
  7862. var z = -matrix8 * vX - matrix9 * vY - matrix10 * vZ;
  7863. result[0] = matrix0;
  7864. result[1] = matrix4;
  7865. result[2] = matrix8;
  7866. result[3] = 0.0;
  7867. result[4] = matrix1;
  7868. result[5] = matrix5;
  7869. result[6] = matrix9;
  7870. result[7] = 0.0;
  7871. result[8] = matrix2;
  7872. result[9] = matrix6;
  7873. result[10] = matrix10;
  7874. result[11] = 0.0;
  7875. result[12] = x;
  7876. result[13] = y;
  7877. result[14] = z;
  7878. result[15] = 1.0;
  7879. return result;
  7880. };
  7881. /**
  7882. * An immutable Matrix4 instance initialized to the identity matrix.
  7883. *
  7884. * @type {Matrix4}
  7885. * @constant
  7886. */
  7887. Matrix4.IDENTITY = freezeObject(new Matrix4(1.0, 0.0, 0.0, 0.0,
  7888. 0.0, 1.0, 0.0, 0.0,
  7889. 0.0, 0.0, 1.0, 0.0,
  7890. 0.0, 0.0, 0.0, 1.0));
  7891. /**
  7892. * An immutable Matrix4 instance initialized to the zero matrix.
  7893. *
  7894. * @type {Matrix4}
  7895. * @constant
  7896. */
  7897. Matrix4.ZERO = freezeObject(new Matrix4(0.0, 0.0, 0.0, 0.0,
  7898. 0.0, 0.0, 0.0, 0.0,
  7899. 0.0, 0.0, 0.0, 0.0,
  7900. 0.0, 0.0, 0.0, 0.0));
  7901. /**
  7902. * The index into Matrix4 for column 0, row 0.
  7903. *
  7904. * @type {Number}
  7905. * @constant
  7906. */
  7907. Matrix4.COLUMN0ROW0 = 0;
  7908. /**
  7909. * The index into Matrix4 for column 0, row 1.
  7910. *
  7911. * @type {Number}
  7912. * @constant
  7913. */
  7914. Matrix4.COLUMN0ROW1 = 1;
  7915. /**
  7916. * The index into Matrix4 for column 0, row 2.
  7917. *
  7918. * @type {Number}
  7919. * @constant
  7920. */
  7921. Matrix4.COLUMN0ROW2 = 2;
  7922. /**
  7923. * The index into Matrix4 for column 0, row 3.
  7924. *
  7925. * @type {Number}
  7926. * @constant
  7927. */
  7928. Matrix4.COLUMN0ROW3 = 3;
  7929. /**
  7930. * The index into Matrix4 for column 1, row 0.
  7931. *
  7932. * @type {Number}
  7933. * @constant
  7934. */
  7935. Matrix4.COLUMN1ROW0 = 4;
  7936. /**
  7937. * The index into Matrix4 for column 1, row 1.
  7938. *
  7939. * @type {Number}
  7940. * @constant
  7941. */
  7942. Matrix4.COLUMN1ROW1 = 5;
  7943. /**
  7944. * The index into Matrix4 for column 1, row 2.
  7945. *
  7946. * @type {Number}
  7947. * @constant
  7948. */
  7949. Matrix4.COLUMN1ROW2 = 6;
  7950. /**
  7951. * The index into Matrix4 for column 1, row 3.
  7952. *
  7953. * @type {Number}
  7954. * @constant
  7955. */
  7956. Matrix4.COLUMN1ROW3 = 7;
  7957. /**
  7958. * The index into Matrix4 for column 2, row 0.
  7959. *
  7960. * @type {Number}
  7961. * @constant
  7962. */
  7963. Matrix4.COLUMN2ROW0 = 8;
  7964. /**
  7965. * The index into Matrix4 for column 2, row 1.
  7966. *
  7967. * @type {Number}
  7968. * @constant
  7969. */
  7970. Matrix4.COLUMN2ROW1 = 9;
  7971. /**
  7972. * The index into Matrix4 for column 2, row 2.
  7973. *
  7974. * @type {Number}
  7975. * @constant
  7976. */
  7977. Matrix4.COLUMN2ROW2 = 10;
  7978. /**
  7979. * The index into Matrix4 for column 2, row 3.
  7980. *
  7981. * @type {Number}
  7982. * @constant
  7983. */
  7984. Matrix4.COLUMN2ROW3 = 11;
  7985. /**
  7986. * The index into Matrix4 for column 3, row 0.
  7987. *
  7988. * @type {Number}
  7989. * @constant
  7990. */
  7991. Matrix4.COLUMN3ROW0 = 12;
  7992. /**
  7993. * The index into Matrix4 for column 3, row 1.
  7994. *
  7995. * @type {Number}
  7996. * @constant
  7997. */
  7998. Matrix4.COLUMN3ROW1 = 13;
  7999. /**
  8000. * The index into Matrix4 for column 3, row 2.
  8001. *
  8002. * @type {Number}
  8003. * @constant
  8004. */
  8005. Matrix4.COLUMN3ROW2 = 14;
  8006. /**
  8007. * The index into Matrix4 for column 3, row 3.
  8008. *
  8009. * @type {Number}
  8010. * @constant
  8011. */
  8012. Matrix4.COLUMN3ROW3 = 15;
  8013. defineProperties(Matrix4.prototype, {
  8014. /**
  8015. * Gets the number of items in the collection.
  8016. * @memberof Matrix4.prototype
  8017. *
  8018. * @type {Number}
  8019. */
  8020. length : {
  8021. get : function() {
  8022. return Matrix4.packedLength;
  8023. }
  8024. }
  8025. });
  8026. /**
  8027. * Duplicates the provided Matrix4 instance.
  8028. *
  8029. * @param {Matrix4} [result] The object onto which to store the result.
  8030. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
  8031. */
  8032. Matrix4.prototype.clone = function(result) {
  8033. return Matrix4.clone(this, result);
  8034. };
  8035. /**
  8036. * Compares this matrix to the provided matrix componentwise and returns
  8037. * <code>true</code> if they are equal, <code>false</code> otherwise.
  8038. *
  8039. * @param {Matrix4} [right] The right hand side matrix.
  8040. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  8041. */
  8042. Matrix4.prototype.equals = function(right) {
  8043. return Matrix4.equals(this, right);
  8044. };
  8045. /**
  8046. * @private
  8047. */
  8048. Matrix4.equalsArray = function(matrix, array, offset) {
  8049. return matrix[0] === array[offset] &&
  8050. matrix[1] === array[offset + 1] &&
  8051. matrix[2] === array[offset + 2] &&
  8052. matrix[3] === array[offset + 3] &&
  8053. matrix[4] === array[offset + 4] &&
  8054. matrix[5] === array[offset + 5] &&
  8055. matrix[6] === array[offset + 6] &&
  8056. matrix[7] === array[offset + 7] &&
  8057. matrix[8] === array[offset + 8] &&
  8058. matrix[9] === array[offset + 9] &&
  8059. matrix[10] === array[offset + 10] &&
  8060. matrix[11] === array[offset + 11] &&
  8061. matrix[12] === array[offset + 12] &&
  8062. matrix[13] === array[offset + 13] &&
  8063. matrix[14] === array[offset + 14] &&
  8064. matrix[15] === array[offset + 15];
  8065. };
  8066. /**
  8067. * Compares this matrix to the provided matrix componentwise and returns
  8068. * <code>true</code> if they are within the provided epsilon,
  8069. * <code>false</code> otherwise.
  8070. *
  8071. * @param {Matrix4} [right] The right hand side matrix.
  8072. * @param {Number} epsilon The epsilon to use for equality testing.
  8073. * @returns {Boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
  8074. */
  8075. Matrix4.prototype.equalsEpsilon = function(right, epsilon) {
  8076. return Matrix4.equalsEpsilon(this, right, epsilon);
  8077. };
  8078. /**
  8079. * Computes a string representing this Matrix with each row being
  8080. * on a separate line and in the format '(column0, column1, column2, column3)'.
  8081. *
  8082. * @returns {String} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2, column3)'.
  8083. */
  8084. Matrix4.prototype.toString = function() {
  8085. return '(' + this[0] + ', ' + this[4] + ', ' + this[8] + ', ' + this[12] +')\n' +
  8086. '(' + this[1] + ', ' + this[5] + ', ' + this[9] + ', ' + this[13] +')\n' +
  8087. '(' + this[2] + ', ' + this[6] + ', ' + this[10] + ', ' + this[14] +')\n' +
  8088. '(' + this[3] + ', ' + this[7] + ', ' + this[11] + ', ' + this[15] +')';
  8089. };
  8090. return Matrix4;
  8091. });
  8092. /*global define*/
  8093. define('Core/Rectangle',[
  8094. './Cartographic',
  8095. './defaultValue',
  8096. './defined',
  8097. './defineProperties',
  8098. './DeveloperError',
  8099. './Ellipsoid',
  8100. './freezeObject',
  8101. './Math'
  8102. ], function(
  8103. Cartographic,
  8104. defaultValue,
  8105. defined,
  8106. defineProperties,
  8107. DeveloperError,
  8108. Ellipsoid,
  8109. freezeObject,
  8110. CesiumMath) {
  8111. 'use strict';
  8112. /**
  8113. * A two dimensional region specified as longitude and latitude coordinates.
  8114. *
  8115. * @alias Rectangle
  8116. * @constructor
  8117. *
  8118. * @param {Number} [west=0.0] The westernmost longitude, in radians, in the range [-Pi, Pi].
  8119. * @param {Number} [south=0.0] The southernmost latitude, in radians, in the range [-Pi/2, Pi/2].
  8120. * @param {Number} [east=0.0] The easternmost longitude, in radians, in the range [-Pi, Pi].
  8121. * @param {Number} [north=0.0] The northernmost latitude, in radians, in the range [-Pi/2, Pi/2].
  8122. *
  8123. * @see Packable
  8124. */
  8125. function Rectangle(west, south, east, north) {
  8126. /**
  8127. * The westernmost longitude in radians in the range [-Pi, Pi].
  8128. *
  8129. * @type {Number}
  8130. * @default 0.0
  8131. */
  8132. this.west = defaultValue(west, 0.0);
  8133. /**
  8134. * The southernmost latitude in radians in the range [-Pi/2, Pi/2].
  8135. *
  8136. * @type {Number}
  8137. * @default 0.0
  8138. */
  8139. this.south = defaultValue(south, 0.0);
  8140. /**
  8141. * The easternmost longitude in radians in the range [-Pi, Pi].
  8142. *
  8143. * @type {Number}
  8144. * @default 0.0
  8145. */
  8146. this.east = defaultValue(east, 0.0);
  8147. /**
  8148. * The northernmost latitude in radians in the range [-Pi/2, Pi/2].
  8149. *
  8150. * @type {Number}
  8151. * @default 0.0
  8152. */
  8153. this.north = defaultValue(north, 0.0);
  8154. }
  8155. defineProperties(Rectangle.prototype, {
  8156. /**
  8157. * Gets the width of the rectangle in radians.
  8158. * @memberof Rectangle.prototype
  8159. * @type {Number}
  8160. */
  8161. width : {
  8162. get : function() {
  8163. return Rectangle.computeWidth(this);
  8164. }
  8165. },
  8166. /**
  8167. * Gets the height of the rectangle in radians.
  8168. * @memberof Rectangle.prototype
  8169. * @type {Number}
  8170. */
  8171. height : {
  8172. get : function() {
  8173. return Rectangle.computeHeight(this);
  8174. }
  8175. }
  8176. });
  8177. /**
  8178. * The number of elements used to pack the object into an array.
  8179. * @type {Number}
  8180. */
  8181. Rectangle.packedLength = 4;
  8182. /**
  8183. * Stores the provided instance into the provided array.
  8184. *
  8185. * @param {Rectangle} value The value to pack.
  8186. * @param {Number[]} array The array to pack into.
  8187. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  8188. *
  8189. * @returns {Number[]} The array that was packed into
  8190. */
  8191. Rectangle.pack = function(value, array, startingIndex) {
  8192. if (!defined(value)) {
  8193. throw new DeveloperError('value is required');
  8194. }
  8195. if (!defined(array)) {
  8196. throw new DeveloperError('array is required');
  8197. }
  8198. startingIndex = defaultValue(startingIndex, 0);
  8199. array[startingIndex++] = value.west;
  8200. array[startingIndex++] = value.south;
  8201. array[startingIndex++] = value.east;
  8202. array[startingIndex] = value.north;
  8203. return array;
  8204. };
  8205. /**
  8206. * Retrieves an instance from a packed array.
  8207. *
  8208. * @param {Number[]} array The packed array.
  8209. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  8210. * @param {Rectangle} [result] The object into which to store the result.
  8211. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if one was not provided.
  8212. */
  8213. Rectangle.unpack = function(array, startingIndex, result) {
  8214. if (!defined(array)) {
  8215. throw new DeveloperError('array is required');
  8216. }
  8217. startingIndex = defaultValue(startingIndex, 0);
  8218. if (!defined(result)) {
  8219. result = new Rectangle();
  8220. }
  8221. result.west = array[startingIndex++];
  8222. result.south = array[startingIndex++];
  8223. result.east = array[startingIndex++];
  8224. result.north = array[startingIndex];
  8225. return result;
  8226. };
  8227. /**
  8228. * Computes the width of a rectangle in radians.
  8229. * @param {Rectangle} rectangle The rectangle to compute the width of.
  8230. * @returns {Number} The width.
  8231. */
  8232. Rectangle.computeWidth = function(rectangle) {
  8233. if (!defined(rectangle)) {
  8234. throw new DeveloperError('rectangle is required.');
  8235. }
  8236. var east = rectangle.east;
  8237. var west = rectangle.west;
  8238. if (east < west) {
  8239. east += CesiumMath.TWO_PI;
  8240. }
  8241. return east - west;
  8242. };
  8243. /**
  8244. * Computes the height of a rectangle in radians.
  8245. * @param {Rectangle} rectangle The rectangle to compute the height of.
  8246. * @returns {Number} The height.
  8247. */
  8248. Rectangle.computeHeight = function(rectangle) {
  8249. if (!defined(rectangle)) {
  8250. throw new DeveloperError('rectangle is required.');
  8251. }
  8252. return rectangle.north - rectangle.south;
  8253. };
  8254. /**
  8255. * Creates an rectangle given the boundary longitude and latitude in degrees.
  8256. *
  8257. * @param {Number} [west=0.0] The westernmost longitude in degrees in the range [-180.0, 180.0].
  8258. * @param {Number} [south=0.0] The southernmost latitude in degrees in the range [-90.0, 90.0].
  8259. * @param {Number} [east=0.0] The easternmost longitude in degrees in the range [-180.0, 180.0].
  8260. * @param {Number} [north=0.0] The northernmost latitude in degrees in the range [-90.0, 90.0].
  8261. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  8262. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  8263. *
  8264. * @example
  8265. * var rectangle = Cesium.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0);
  8266. */
  8267. Rectangle.fromDegrees = function(west, south, east, north, result) {
  8268. west = CesiumMath.toRadians(defaultValue(west, 0.0));
  8269. south = CesiumMath.toRadians(defaultValue(south, 0.0));
  8270. east = CesiumMath.toRadians(defaultValue(east, 0.0));
  8271. north = CesiumMath.toRadians(defaultValue(north, 0.0));
  8272. if (!defined(result)) {
  8273. return new Rectangle(west, south, east, north);
  8274. }
  8275. result.west = west;
  8276. result.south = south;
  8277. result.east = east;
  8278. result.north = north;
  8279. return result;
  8280. };
  8281. /**
  8282. * Creates the smallest possible Rectangle that encloses all positions in the provided array.
  8283. *
  8284. * @param {Cartographic[]} cartographics The list of Cartographic instances.
  8285. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  8286. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  8287. */
  8288. Rectangle.fromCartographicArray = function(cartographics, result) {
  8289. if (!defined(cartographics)) {
  8290. throw new DeveloperError('cartographics is required.');
  8291. }
  8292. var west = Number.MAX_VALUE;
  8293. var east = -Number.MAX_VALUE;
  8294. var westOverIDL = Number.MAX_VALUE;
  8295. var eastOverIDL = -Number.MAX_VALUE;
  8296. var south = Number.MAX_VALUE;
  8297. var north = -Number.MAX_VALUE;
  8298. for ( var i = 0, len = cartographics.length; i < len; i++) {
  8299. var position = cartographics[i];
  8300. west = Math.min(west, position.longitude);
  8301. east = Math.max(east, position.longitude);
  8302. south = Math.min(south, position.latitude);
  8303. north = Math.max(north, position.latitude);
  8304. var lonAdjusted = position.longitude >= 0 ? position.longitude : position.longitude + CesiumMath.TWO_PI;
  8305. westOverIDL = Math.min(westOverIDL, lonAdjusted);
  8306. eastOverIDL = Math.max(eastOverIDL, lonAdjusted);
  8307. }
  8308. if(east - west > eastOverIDL - westOverIDL) {
  8309. west = westOverIDL;
  8310. east = eastOverIDL;
  8311. if (east > CesiumMath.PI) {
  8312. east = east - CesiumMath.TWO_PI;
  8313. }
  8314. if (west > CesiumMath.PI) {
  8315. west = west - CesiumMath.TWO_PI;
  8316. }
  8317. }
  8318. if (!defined(result)) {
  8319. return new Rectangle(west, south, east, north);
  8320. }
  8321. result.west = west;
  8322. result.south = south;
  8323. result.east = east;
  8324. result.north = north;
  8325. return result;
  8326. };
  8327. /**
  8328. * Creates the smallest possible Rectangle that encloses all positions in the provided array.
  8329. *
  8330. * @param {Cartesian[]} cartesians The list of Cartesian instances.
  8331. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid the cartesians are on.
  8332. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  8333. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  8334. */
  8335. Rectangle.fromCartesianArray = function(cartesians, ellipsoid, result) {
  8336. if (!defined(cartesians)) {
  8337. throw new DeveloperError('cartesians is required.');
  8338. }
  8339. var west = Number.MAX_VALUE;
  8340. var east = -Number.MAX_VALUE;
  8341. var westOverIDL = Number.MAX_VALUE;
  8342. var eastOverIDL = -Number.MAX_VALUE;
  8343. var south = Number.MAX_VALUE;
  8344. var north = -Number.MAX_VALUE;
  8345. for ( var i = 0, len = cartesians.length; i < len; i++) {
  8346. var position = ellipsoid.cartesianToCartographic(cartesians[i]);
  8347. west = Math.min(west, position.longitude);
  8348. east = Math.max(east, position.longitude);
  8349. south = Math.min(south, position.latitude);
  8350. north = Math.max(north, position.latitude);
  8351. var lonAdjusted = position.longitude >= 0 ? position.longitude : position.longitude + CesiumMath.TWO_PI;
  8352. westOverIDL = Math.min(westOverIDL, lonAdjusted);
  8353. eastOverIDL = Math.max(eastOverIDL, lonAdjusted);
  8354. }
  8355. if(east - west > eastOverIDL - westOverIDL) {
  8356. west = westOverIDL;
  8357. east = eastOverIDL;
  8358. if (east > CesiumMath.PI) {
  8359. east = east - CesiumMath.TWO_PI;
  8360. }
  8361. if (west > CesiumMath.PI) {
  8362. west = west - CesiumMath.TWO_PI;
  8363. }
  8364. }
  8365. if (!defined(result)) {
  8366. return new Rectangle(west, south, east, north);
  8367. }
  8368. result.west = west;
  8369. result.south = south;
  8370. result.east = east;
  8371. result.north = north;
  8372. return result;
  8373. };
  8374. /**
  8375. * Duplicates an Rectangle.
  8376. *
  8377. * @param {Rectangle} rectangle The rectangle to clone.
  8378. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  8379. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided. (Returns undefined if rectangle is undefined)
  8380. */
  8381. Rectangle.clone = function(rectangle, result) {
  8382. if (!defined(rectangle)) {
  8383. return undefined;
  8384. }
  8385. if (!defined(result)) {
  8386. return new Rectangle(rectangle.west, rectangle.south, rectangle.east, rectangle.north);
  8387. }
  8388. result.west = rectangle.west;
  8389. result.south = rectangle.south;
  8390. result.east = rectangle.east;
  8391. result.north = rectangle.north;
  8392. return result;
  8393. };
  8394. /**
  8395. * Duplicates this Rectangle.
  8396. *
  8397. * @param {Rectangle} [result] The object onto which to store the result.
  8398. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  8399. */
  8400. Rectangle.prototype.clone = function(result) {
  8401. return Rectangle.clone(this, result);
  8402. };
  8403. /**
  8404. * Compares the provided Rectangle with this Rectangle componentwise and returns
  8405. * <code>true</code> if they are equal, <code>false</code> otherwise.
  8406. *
  8407. * @param {Rectangle} [other] The Rectangle to compare.
  8408. * @returns {Boolean} <code>true</code> if the Rectangles are equal, <code>false</code> otherwise.
  8409. */
  8410. Rectangle.prototype.equals = function(other) {
  8411. return Rectangle.equals(this, other);
  8412. };
  8413. /**
  8414. * Compares the provided rectangles and returns <code>true</code> if they are equal,
  8415. * <code>false</code> otherwise.
  8416. *
  8417. * @param {Rectangle} [left] The first Rectangle.
  8418. * @param {Rectangle} [right] The second Rectangle.
  8419. * @returns {Boolean} <code>true</code> if left and right are equal; otherwise <code>false</code>.
  8420. */
  8421. Rectangle.equals = function(left, right) {
  8422. return (left === right) ||
  8423. ((defined(left)) &&
  8424. (defined(right)) &&
  8425. (left.west === right.west) &&
  8426. (left.south === right.south) &&
  8427. (left.east === right.east) &&
  8428. (left.north === right.north));
  8429. };
  8430. /**
  8431. * Compares the provided Rectangle with this Rectangle componentwise and returns
  8432. * <code>true</code> if they are within the provided epsilon,
  8433. * <code>false</code> otherwise.
  8434. *
  8435. * @param {Rectangle} [other] The Rectangle to compare.
  8436. * @param {Number} epsilon The epsilon to use for equality testing.
  8437. * @returns {Boolean} <code>true</code> if the Rectangles are within the provided epsilon, <code>false</code> otherwise.
  8438. */
  8439. Rectangle.prototype.equalsEpsilon = function(other, epsilon) {
  8440. if (typeof epsilon !== 'number') {
  8441. throw new DeveloperError('epsilon is required and must be a number.');
  8442. }
  8443. return defined(other) &&
  8444. (Math.abs(this.west - other.west) <= epsilon) &&
  8445. (Math.abs(this.south - other.south) <= epsilon) &&
  8446. (Math.abs(this.east - other.east) <= epsilon) &&
  8447. (Math.abs(this.north - other.north) <= epsilon);
  8448. };
  8449. /**
  8450. * Checks an Rectangle's properties and throws if they are not in valid ranges.
  8451. *
  8452. * @param {Rectangle} rectangle The rectangle to validate
  8453. *
  8454. * @exception {DeveloperError} <code>north</code> must be in the interval [<code>-Pi/2</code>, <code>Pi/2</code>].
  8455. * @exception {DeveloperError} <code>south</code> must be in the interval [<code>-Pi/2</code>, <code>Pi/2</code>].
  8456. * @exception {DeveloperError} <code>east</code> must be in the interval [<code>-Pi</code>, <code>Pi</code>].
  8457. * @exception {DeveloperError} <code>west</code> must be in the interval [<code>-Pi</code>, <code>Pi</code>].
  8458. */
  8459. Rectangle.validate = function(rectangle) {
  8460. if (!defined(rectangle)) {
  8461. throw new DeveloperError('rectangle is required');
  8462. }
  8463. var north = rectangle.north;
  8464. if (typeof north !== 'number') {
  8465. throw new DeveloperError('north is required to be a number.');
  8466. }
  8467. if (north < -CesiumMath.PI_OVER_TWO || north > CesiumMath.PI_OVER_TWO) {
  8468. throw new DeveloperError('north must be in the interval [-Pi/2, Pi/2].');
  8469. }
  8470. var south = rectangle.south;
  8471. if (typeof south !== 'number') {
  8472. throw new DeveloperError('south is required to be a number.');
  8473. }
  8474. if (south < -CesiumMath.PI_OVER_TWO || south > CesiumMath.PI_OVER_TWO) {
  8475. throw new DeveloperError('south must be in the interval [-Pi/2, Pi/2].');
  8476. }
  8477. var west = rectangle.west;
  8478. if (typeof west !== 'number') {
  8479. throw new DeveloperError('west is required to be a number.');
  8480. }
  8481. if (west < -Math.PI || west > Math.PI) {
  8482. throw new DeveloperError('west must be in the interval [-Pi, Pi].');
  8483. }
  8484. var east = rectangle.east;
  8485. if (typeof east !== 'number') {
  8486. throw new DeveloperError('east is required to be a number.');
  8487. }
  8488. if (east < -Math.PI || east > Math.PI) {
  8489. throw new DeveloperError('east must be in the interval [-Pi, Pi].');
  8490. }
  8491. };
  8492. /**
  8493. * Computes the southwest corner of an rectangle.
  8494. *
  8495. * @param {Rectangle} rectangle The rectangle for which to find the corner
  8496. * @param {Cartographic} [result] The object onto which to store the result.
  8497. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  8498. */
  8499. Rectangle.southwest = function(rectangle, result) {
  8500. if (!defined(rectangle)) {
  8501. throw new DeveloperError('rectangle is required');
  8502. }
  8503. if (!defined(result)) {
  8504. return new Cartographic(rectangle.west, rectangle.south);
  8505. }
  8506. result.longitude = rectangle.west;
  8507. result.latitude = rectangle.south;
  8508. result.height = 0.0;
  8509. return result;
  8510. };
  8511. /**
  8512. * Computes the northwest corner of an rectangle.
  8513. *
  8514. * @param {Rectangle} rectangle The rectangle for which to find the corner
  8515. * @param {Cartographic} [result] The object onto which to store the result.
  8516. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  8517. */
  8518. Rectangle.northwest = function(rectangle, result) {
  8519. if (!defined(rectangle)) {
  8520. throw new DeveloperError('rectangle is required');
  8521. }
  8522. if (!defined(result)) {
  8523. return new Cartographic(rectangle.west, rectangle.north);
  8524. }
  8525. result.longitude = rectangle.west;
  8526. result.latitude = rectangle.north;
  8527. result.height = 0.0;
  8528. return result;
  8529. };
  8530. /**
  8531. * Computes the northeast corner of an rectangle.
  8532. *
  8533. * @param {Rectangle} rectangle The rectangle for which to find the corner
  8534. * @param {Cartographic} [result] The object onto which to store the result.
  8535. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  8536. */
  8537. Rectangle.northeast = function(rectangle, result) {
  8538. if (!defined(rectangle)) {
  8539. throw new DeveloperError('rectangle is required');
  8540. }
  8541. if (!defined(result)) {
  8542. return new Cartographic(rectangle.east, rectangle.north);
  8543. }
  8544. result.longitude = rectangle.east;
  8545. result.latitude = rectangle.north;
  8546. result.height = 0.0;
  8547. return result;
  8548. };
  8549. /**
  8550. * Computes the southeast corner of an rectangle.
  8551. *
  8552. * @param {Rectangle} rectangle The rectangle for which to find the corner
  8553. * @param {Cartographic} [result] The object onto which to store the result.
  8554. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  8555. */
  8556. Rectangle.southeast = function(rectangle, result) {
  8557. if (!defined(rectangle)) {
  8558. throw new DeveloperError('rectangle is required');
  8559. }
  8560. if (!defined(result)) {
  8561. return new Cartographic(rectangle.east, rectangle.south);
  8562. }
  8563. result.longitude = rectangle.east;
  8564. result.latitude = rectangle.south;
  8565. result.height = 0.0;
  8566. return result;
  8567. };
  8568. /**
  8569. * Computes the center of an rectangle.
  8570. *
  8571. * @param {Rectangle} rectangle The rectangle for which to find the center
  8572. * @param {Cartographic} [result] The object onto which to store the result.
  8573. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  8574. */
  8575. Rectangle.center = function(rectangle, result) {
  8576. if (!defined(rectangle)) {
  8577. throw new DeveloperError('rectangle is required');
  8578. }
  8579. var east = rectangle.east;
  8580. var west = rectangle.west;
  8581. if (east < west) {
  8582. east += CesiumMath.TWO_PI;
  8583. }
  8584. var longitude = CesiumMath.negativePiToPi((west + east) * 0.5);
  8585. var latitude = (rectangle.south + rectangle.north) * 0.5;
  8586. if (!defined(result)) {
  8587. return new Cartographic(longitude, latitude);
  8588. }
  8589. result.longitude = longitude;
  8590. result.latitude = latitude;
  8591. result.height = 0.0;
  8592. return result;
  8593. };
  8594. /**
  8595. * Computes the intersection of two rectangles. This function assumes that the rectangle's coordinates are
  8596. * latitude and longitude in radians and produces a correct intersection, taking into account the fact that
  8597. * the same angle can be represented with multiple values as well as the wrapping of longitude at the
  8598. * anti-meridian. For a simple intersection that ignores these factors and can be used with projected
  8599. * coordinates, see {@link Rectangle.simpleIntersection}.
  8600. *
  8601. * @param {Rectangle} rectangle On rectangle to find an intersection
  8602. * @param {Rectangle} otherRectangle Another rectangle to find an intersection
  8603. * @param {Rectangle} [result] The object onto which to store the result.
  8604. * @returns {Rectangle|undefined} The modified result parameter, a new Rectangle instance if none was provided or undefined if there is no intersection.
  8605. */
  8606. Rectangle.intersection = function(rectangle, otherRectangle, result) {
  8607. if (!defined(rectangle)) {
  8608. throw new DeveloperError('rectangle is required');
  8609. }
  8610. if (!defined(otherRectangle)) {
  8611. throw new DeveloperError('otherRectangle is required.');
  8612. }
  8613. var rectangleEast = rectangle.east;
  8614. var rectangleWest = rectangle.west;
  8615. var otherRectangleEast = otherRectangle.east;
  8616. var otherRectangleWest = otherRectangle.west;
  8617. if (rectangleEast < rectangleWest && otherRectangleEast > 0.0) {
  8618. rectangleEast += CesiumMath.TWO_PI;
  8619. } else if (otherRectangleEast < otherRectangleWest && rectangleEast > 0.0) {
  8620. otherRectangleEast += CesiumMath.TWO_PI;
  8621. }
  8622. if (rectangleEast < rectangleWest && otherRectangleWest < 0.0) {
  8623. otherRectangleWest += CesiumMath.TWO_PI;
  8624. } else if (otherRectangleEast < otherRectangleWest && rectangleWest < 0.0) {
  8625. rectangleWest += CesiumMath.TWO_PI;
  8626. }
  8627. var west = CesiumMath.negativePiToPi(Math.max(rectangleWest, otherRectangleWest));
  8628. var east = CesiumMath.negativePiToPi(Math.min(rectangleEast, otherRectangleEast));
  8629. if ((rectangle.west < rectangle.east || otherRectangle.west < otherRectangle.east) && east <= west) {
  8630. return undefined;
  8631. }
  8632. var south = Math.max(rectangle.south, otherRectangle.south);
  8633. var north = Math.min(rectangle.north, otherRectangle.north);
  8634. if (south >= north) {
  8635. return undefined;
  8636. }
  8637. if (!defined(result)) {
  8638. return new Rectangle(west, south, east, north);
  8639. }
  8640. result.west = west;
  8641. result.south = south;
  8642. result.east = east;
  8643. result.north = north;
  8644. return result;
  8645. };
  8646. /**
  8647. * Computes a simple intersection of two rectangles. Unlike {@link Rectangle.intersection}, this function
  8648. * does not attempt to put the angular coordinates into a consistent range or to account for crossing the
  8649. * anti-meridian. As such, it can be used for rectangles where the coordinates are not simply latitude
  8650. * and longitude (i.e. projected coordinates).
  8651. *
  8652. * @param {Rectangle} rectangle On rectangle to find an intersection
  8653. * @param {Rectangle} otherRectangle Another rectangle to find an intersection
  8654. * @param {Rectangle} [result] The object onto which to store the result.
  8655. * @returns {Rectangle|undefined} The modified result parameter, a new Rectangle instance if none was provided or undefined if there is no intersection.
  8656. */
  8657. Rectangle.simpleIntersection = function(rectangle, otherRectangle, result) {
  8658. if (!defined(rectangle)) {
  8659. throw new DeveloperError('rectangle is required');
  8660. }
  8661. if (!defined(otherRectangle)) {
  8662. throw new DeveloperError('otherRectangle is required.');
  8663. }
  8664. var west = Math.max(rectangle.west, otherRectangle.west);
  8665. var south = Math.max(rectangle.south, otherRectangle.south);
  8666. var east = Math.min(rectangle.east, otherRectangle.east);
  8667. var north = Math.min(rectangle.north, otherRectangle.north);
  8668. if (south >= north || west >= east) {
  8669. return undefined;
  8670. }
  8671. if (!defined(result)) {
  8672. return new Rectangle(west, south, east, north);
  8673. }
  8674. result.west = west;
  8675. result.south = south;
  8676. result.east = east;
  8677. result.north = north;
  8678. return result;
  8679. };
  8680. /**
  8681. * Computes a rectangle that is the union of two rectangles.
  8682. *
  8683. * @param {Rectangle} rectangle A rectangle to enclose in rectangle.
  8684. * @param {Rectangle} otherRectangle A rectangle to enclose in a rectangle.
  8685. * @param {Rectangle} [result] The object onto which to store the result.
  8686. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  8687. */
  8688. Rectangle.union = function(rectangle, otherRectangle, result) {
  8689. if (!defined(rectangle)) {
  8690. throw new DeveloperError('rectangle is required');
  8691. }
  8692. if (!defined(otherRectangle)) {
  8693. throw new DeveloperError('otherRectangle is required.');
  8694. }
  8695. if (!defined(result)) {
  8696. result = new Rectangle();
  8697. }
  8698. var rectangleEast = rectangle.east;
  8699. var rectangleWest = rectangle.west;
  8700. var otherRectangleEast = otherRectangle.east;
  8701. var otherRectangleWest = otherRectangle.west;
  8702. if (rectangleEast < rectangleWest && otherRectangleEast > 0.0) {
  8703. rectangleEast += CesiumMath.TWO_PI;
  8704. } else if (otherRectangleEast < otherRectangleWest && rectangleEast > 0.0) {
  8705. otherRectangleEast += CesiumMath.TWO_PI;
  8706. }
  8707. if (rectangleEast < rectangleWest && otherRectangleWest < 0.0) {
  8708. otherRectangleWest += CesiumMath.TWO_PI;
  8709. } else if (otherRectangleEast < otherRectangleWest && rectangleWest < 0.0) {
  8710. rectangleWest += CesiumMath.TWO_PI;
  8711. }
  8712. var west = CesiumMath.convertLongitudeRange(Math.min(rectangleWest, otherRectangleWest));
  8713. var east = CesiumMath.convertLongitudeRange(Math.max(rectangleEast, otherRectangleEast));
  8714. result.west = west;
  8715. result.south = Math.min(rectangle.south, otherRectangle.south);
  8716. result.east = east;
  8717. result.north = Math.max(rectangle.north, otherRectangle.north);
  8718. return result;
  8719. };
  8720. /**
  8721. * Computes a rectangle by enlarging the provided rectangle until it contains the provided cartographic.
  8722. *
  8723. * @param {Rectangle} rectangle A rectangle to expand.
  8724. * @param {Cartographic} cartographic A cartographic to enclose in a rectangle.
  8725. * @param {Rectangle} [result] The object onto which to store the result.
  8726. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if one was not provided.
  8727. */
  8728. Rectangle.expand = function(rectangle, cartographic, result) {
  8729. if (!defined(rectangle)) {
  8730. throw new DeveloperError('rectangle is required.');
  8731. }
  8732. if (!defined(cartographic)) {
  8733. throw new DeveloperError('cartographic is required.');
  8734. }
  8735. if (!defined(result)) {
  8736. result = new Rectangle();
  8737. }
  8738. result.west = Math.min(rectangle.west, cartographic.longitude);
  8739. result.south = Math.min(rectangle.south, cartographic.latitude);
  8740. result.east = Math.max(rectangle.east, cartographic.longitude);
  8741. result.north = Math.max(rectangle.north, cartographic.latitude);
  8742. return result;
  8743. };
  8744. /**
  8745. * Returns true if the cartographic is on or inside the rectangle, false otherwise.
  8746. *
  8747. * @param {Rectangle} rectangle The rectangle
  8748. * @param {Cartographic} cartographic The cartographic to test.
  8749. * @returns {Boolean} true if the provided cartographic is inside the rectangle, false otherwise.
  8750. */
  8751. Rectangle.contains = function(rectangle, cartographic) {
  8752. if (!defined(rectangle)) {
  8753. throw new DeveloperError('rectangle is required');
  8754. }
  8755. if (!defined(cartographic)) {
  8756. throw new DeveloperError('cartographic is required.');
  8757. }
  8758. var longitude = cartographic.longitude;
  8759. var latitude = cartographic.latitude;
  8760. var west = rectangle.west;
  8761. var east = rectangle.east;
  8762. if (east < west) {
  8763. east += CesiumMath.TWO_PI;
  8764. if (longitude < 0.0) {
  8765. longitude += CesiumMath.TWO_PI;
  8766. }
  8767. }
  8768. return (longitude > west || CesiumMath.equalsEpsilon(longitude, west, CesiumMath.EPSILON14)) &&
  8769. (longitude < east || CesiumMath.equalsEpsilon(longitude, east, CesiumMath.EPSILON14)) &&
  8770. latitude >= rectangle.south &&
  8771. latitude <= rectangle.north;
  8772. };
  8773. var subsampleLlaScratch = new Cartographic();
  8774. /**
  8775. * Samples an rectangle so that it includes a list of Cartesian points suitable for passing to
  8776. * {@link BoundingSphere#fromPoints}. Sampling is necessary to account
  8777. * for rectangles that cover the poles or cross the equator.
  8778. *
  8779. * @param {Rectangle} rectangle The rectangle to subsample.
  8780. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use.
  8781. * @param {Number} [surfaceHeight=0.0] The height of the rectangle above the ellipsoid.
  8782. * @param {Cartesian3[]} [result] The array of Cartesians onto which to store the result.
  8783. * @returns {Cartesian3[]} The modified result parameter or a new Array of Cartesians instances if none was provided.
  8784. */
  8785. Rectangle.subsample = function(rectangle, ellipsoid, surfaceHeight, result) {
  8786. if (!defined(rectangle)) {
  8787. throw new DeveloperError('rectangle is required');
  8788. }
  8789. ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
  8790. surfaceHeight = defaultValue(surfaceHeight, 0.0);
  8791. if (!defined(result)) {
  8792. result = [];
  8793. }
  8794. var length = 0;
  8795. var north = rectangle.north;
  8796. var south = rectangle.south;
  8797. var east = rectangle.east;
  8798. var west = rectangle.west;
  8799. var lla = subsampleLlaScratch;
  8800. lla.height = surfaceHeight;
  8801. lla.longitude = west;
  8802. lla.latitude = north;
  8803. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8804. length++;
  8805. lla.longitude = east;
  8806. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8807. length++;
  8808. lla.latitude = south;
  8809. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8810. length++;
  8811. lla.longitude = west;
  8812. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8813. length++;
  8814. if (north < 0.0) {
  8815. lla.latitude = north;
  8816. } else if (south > 0.0) {
  8817. lla.latitude = south;
  8818. } else {
  8819. lla.latitude = 0.0;
  8820. }
  8821. for ( var i = 1; i < 8; ++i) {
  8822. lla.longitude = -Math.PI + i * CesiumMath.PI_OVER_TWO;
  8823. if (Rectangle.contains(rectangle, lla)) {
  8824. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8825. length++;
  8826. }
  8827. }
  8828. if (lla.latitude === 0.0) {
  8829. lla.longitude = west;
  8830. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8831. length++;
  8832. lla.longitude = east;
  8833. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8834. length++;
  8835. }
  8836. result.length = length;
  8837. return result;
  8838. };
  8839. /**
  8840. * The largest possible rectangle.
  8841. *
  8842. * @type {Rectangle}
  8843. * @constant
  8844. */
  8845. Rectangle.MAX_VALUE = freezeObject(new Rectangle(-Math.PI, -CesiumMath.PI_OVER_TWO, Math.PI, CesiumMath.PI_OVER_TWO));
  8846. return Rectangle;
  8847. });
  8848. /*global define*/
  8849. define('Core/BoundingSphere',[
  8850. './Cartesian3',
  8851. './Cartographic',
  8852. './defaultValue',
  8853. './defined',
  8854. './DeveloperError',
  8855. './Ellipsoid',
  8856. './GeographicProjection',
  8857. './Intersect',
  8858. './Interval',
  8859. './Matrix3',
  8860. './Matrix4',
  8861. './Rectangle'
  8862. ], function(
  8863. Cartesian3,
  8864. Cartographic,
  8865. defaultValue,
  8866. defined,
  8867. DeveloperError,
  8868. Ellipsoid,
  8869. GeographicProjection,
  8870. Intersect,
  8871. Interval,
  8872. Matrix3,
  8873. Matrix4,
  8874. Rectangle) {
  8875. 'use strict';
  8876. /**
  8877. * A bounding sphere with a center and a radius.
  8878. * @alias BoundingSphere
  8879. * @constructor
  8880. *
  8881. * @param {Cartesian3} [center=Cartesian3.ZERO] The center of the bounding sphere.
  8882. * @param {Number} [radius=0.0] The radius of the bounding sphere.
  8883. *
  8884. * @see AxisAlignedBoundingBox
  8885. * @see BoundingRectangle
  8886. * @see Packable
  8887. */
  8888. function BoundingSphere(center, radius) {
  8889. /**
  8890. * The center point of the sphere.
  8891. * @type {Cartesian3}
  8892. * @default {@link Cartesian3.ZERO}
  8893. */
  8894. this.center = Cartesian3.clone(defaultValue(center, Cartesian3.ZERO));
  8895. /**
  8896. * The radius of the sphere.
  8897. * @type {Number}
  8898. * @default 0.0
  8899. */
  8900. this.radius = defaultValue(radius, 0.0);
  8901. }
  8902. var fromPointsXMin = new Cartesian3();
  8903. var fromPointsYMin = new Cartesian3();
  8904. var fromPointsZMin = new Cartesian3();
  8905. var fromPointsXMax = new Cartesian3();
  8906. var fromPointsYMax = new Cartesian3();
  8907. var fromPointsZMax = new Cartesian3();
  8908. var fromPointsCurrentPos = new Cartesian3();
  8909. var fromPointsScratch = new Cartesian3();
  8910. var fromPointsRitterCenter = new Cartesian3();
  8911. var fromPointsMinBoxPt = new Cartesian3();
  8912. var fromPointsMaxBoxPt = new Cartesian3();
  8913. var fromPointsNaiveCenterScratch = new Cartesian3();
  8914. /**
  8915. * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.
  8916. * The bounding sphere is computed by running two algorithms, a naive algorithm and
  8917. * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.
  8918. *
  8919. * @param {Cartesian3[]} positions An array of points that the bounding sphere will enclose. Each point must have <code>x</code>, <code>y</code>, and <code>z</code> properties.
  8920. * @param {BoundingSphere} [result] The object onto which to store the result.
  8921. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.
  8922. *
  8923. * @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}
  8924. */
  8925. BoundingSphere.fromPoints = function(positions, result) {
  8926. if (!defined(result)) {
  8927. result = new BoundingSphere();
  8928. }
  8929. if (!defined(positions) || positions.length === 0) {
  8930. result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);
  8931. result.radius = 0.0;
  8932. return result;
  8933. }
  8934. var currentPos = Cartesian3.clone(positions[0], fromPointsCurrentPos);
  8935. var xMin = Cartesian3.clone(currentPos, fromPointsXMin);
  8936. var yMin = Cartesian3.clone(currentPos, fromPointsYMin);
  8937. var zMin = Cartesian3.clone(currentPos, fromPointsZMin);
  8938. var xMax = Cartesian3.clone(currentPos, fromPointsXMax);
  8939. var yMax = Cartesian3.clone(currentPos, fromPointsYMax);
  8940. var zMax = Cartesian3.clone(currentPos, fromPointsZMax);
  8941. var numPositions = positions.length;
  8942. for (var i = 1; i < numPositions; i++) {
  8943. Cartesian3.clone(positions[i], currentPos);
  8944. var x = currentPos.x;
  8945. var y = currentPos.y;
  8946. var z = currentPos.z;
  8947. // Store points containing the the smallest and largest components
  8948. if (x < xMin.x) {
  8949. Cartesian3.clone(currentPos, xMin);
  8950. }
  8951. if (x > xMax.x) {
  8952. Cartesian3.clone(currentPos, xMax);
  8953. }
  8954. if (y < yMin.y) {
  8955. Cartesian3.clone(currentPos, yMin);
  8956. }
  8957. if (y > yMax.y) {
  8958. Cartesian3.clone(currentPos, yMax);
  8959. }
  8960. if (z < zMin.z) {
  8961. Cartesian3.clone(currentPos, zMin);
  8962. }
  8963. if (z > zMax.z) {
  8964. Cartesian3.clone(currentPos, zMax);
  8965. }
  8966. }
  8967. // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).
  8968. var xSpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(xMax, xMin, fromPointsScratch));
  8969. var ySpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(yMax, yMin, fromPointsScratch));
  8970. var zSpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(zMax, zMin, fromPointsScratch));
  8971. // Set the diameter endpoints to the largest span.
  8972. var diameter1 = xMin;
  8973. var diameter2 = xMax;
  8974. var maxSpan = xSpan;
  8975. if (ySpan > maxSpan) {
  8976. maxSpan = ySpan;
  8977. diameter1 = yMin;
  8978. diameter2 = yMax;
  8979. }
  8980. if (zSpan > maxSpan) {
  8981. maxSpan = zSpan;
  8982. diameter1 = zMin;
  8983. diameter2 = zMax;
  8984. }
  8985. // Calculate the center of the initial sphere found by Ritter's algorithm
  8986. var ritterCenter = fromPointsRitterCenter;
  8987. ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
  8988. ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
  8989. ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
  8990. // Calculate the radius of the initial sphere found by Ritter's algorithm
  8991. var radiusSquared = Cartesian3.magnitudeSquared(Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch));
  8992. var ritterRadius = Math.sqrt(radiusSquared);
  8993. // Find the center of the sphere found using the Naive method.
  8994. var minBoxPt = fromPointsMinBoxPt;
  8995. minBoxPt.x = xMin.x;
  8996. minBoxPt.y = yMin.y;
  8997. minBoxPt.z = zMin.z;
  8998. var maxBoxPt = fromPointsMaxBoxPt;
  8999. maxBoxPt.x = xMax.x;
  9000. maxBoxPt.y = yMax.y;
  9001. maxBoxPt.z = zMax.z;
  9002. var naiveCenter = Cartesian3.multiplyByScalar(Cartesian3.add(minBoxPt, maxBoxPt, fromPointsScratch), 0.5, fromPointsNaiveCenterScratch);
  9003. // Begin 2nd pass to find naive radius and modify the ritter sphere.
  9004. var naiveRadius = 0;
  9005. for (i = 0; i < numPositions; i++) {
  9006. Cartesian3.clone(positions[i], currentPos);
  9007. // Find the furthest point from the naive center to calculate the naive radius.
  9008. var r = Cartesian3.magnitude(Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch));
  9009. if (r > naiveRadius) {
  9010. naiveRadius = r;
  9011. }
  9012. // Make adjustments to the Ritter Sphere to include all points.
  9013. var oldCenterToPointSquared = Cartesian3.magnitudeSquared(Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch));
  9014. if (oldCenterToPointSquared > radiusSquared) {
  9015. var oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
  9016. // Calculate new radius to include the point that lies outside
  9017. ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
  9018. radiusSquared = ritterRadius * ritterRadius;
  9019. // Calculate center of new Ritter sphere
  9020. var oldToNew = oldCenterToPoint - ritterRadius;
  9021. ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
  9022. ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
  9023. ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
  9024. }
  9025. }
  9026. if (ritterRadius < naiveRadius) {
  9027. Cartesian3.clone(ritterCenter, result.center);
  9028. result.radius = ritterRadius;
  9029. } else {
  9030. Cartesian3.clone(naiveCenter, result.center);
  9031. result.radius = naiveRadius;
  9032. }
  9033. return result;
  9034. };
  9035. var defaultProjection = new GeographicProjection();
  9036. var fromRectangle2DLowerLeft = new Cartesian3();
  9037. var fromRectangle2DUpperRight = new Cartesian3();
  9038. var fromRectangle2DSouthwest = new Cartographic();
  9039. var fromRectangle2DNortheast = new Cartographic();
  9040. /**
  9041. * Computes a bounding sphere from an rectangle projected in 2D.
  9042. *
  9043. * @param {Rectangle} rectangle The rectangle around which to create a bounding sphere.
  9044. * @param {Object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.
  9045. * @param {BoundingSphere} [result] The object onto which to store the result.
  9046. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9047. */
  9048. BoundingSphere.fromRectangle2D = function(rectangle, projection, result) {
  9049. return BoundingSphere.fromRectangleWithHeights2D(rectangle, projection, 0.0, 0.0, result);
  9050. };
  9051. /**
  9052. * Computes a bounding sphere from an rectangle projected in 2D. The bounding sphere accounts for the
  9053. * object's minimum and maximum heights over the rectangle.
  9054. *
  9055. * @param {Rectangle} rectangle The rectangle around which to create a bounding sphere.
  9056. * @param {Object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.
  9057. * @param {Number} [minimumHeight=0.0] The minimum height over the rectangle.
  9058. * @param {Number} [maximumHeight=0.0] The maximum height over the rectangle.
  9059. * @param {BoundingSphere} [result] The object onto which to store the result.
  9060. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9061. */
  9062. BoundingSphere.fromRectangleWithHeights2D = function(rectangle, projection, minimumHeight, maximumHeight, result) {
  9063. if (!defined(result)) {
  9064. result = new BoundingSphere();
  9065. }
  9066. if (!defined(rectangle)) {
  9067. result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);
  9068. result.radius = 0.0;
  9069. return result;
  9070. }
  9071. projection = defaultValue(projection, defaultProjection);
  9072. Rectangle.southwest(rectangle, fromRectangle2DSouthwest);
  9073. fromRectangle2DSouthwest.height = minimumHeight;
  9074. Rectangle.northeast(rectangle, fromRectangle2DNortheast);
  9075. fromRectangle2DNortheast.height = maximumHeight;
  9076. var lowerLeft = projection.project(fromRectangle2DSouthwest, fromRectangle2DLowerLeft);
  9077. var upperRight = projection.project(fromRectangle2DNortheast, fromRectangle2DUpperRight);
  9078. var width = upperRight.x - lowerLeft.x;
  9079. var height = upperRight.y - lowerLeft.y;
  9080. var elevation = upperRight.z - lowerLeft.z;
  9081. result.radius = Math.sqrt(width * width + height * height + elevation * elevation) * 0.5;
  9082. var center = result.center;
  9083. center.x = lowerLeft.x + width * 0.5;
  9084. center.y = lowerLeft.y + height * 0.5;
  9085. center.z = lowerLeft.z + elevation * 0.5;
  9086. return result;
  9087. };
  9088. var fromRectangle3DScratch = [];
  9089. /**
  9090. * Computes a bounding sphere from an rectangle in 3D. The bounding sphere is created using a subsample of points
  9091. * on the ellipsoid and contained in the rectangle. It may not be accurate for all rectangles on all types of ellipsoids.
  9092. *
  9093. * @param {Rectangle} rectangle The valid rectangle used to create a bounding sphere.
  9094. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid used to determine positions of the rectangle.
  9095. * @param {Number} [surfaceHeight=0.0] The height above the surface of the ellipsoid.
  9096. * @param {BoundingSphere} [result] The object onto which to store the result.
  9097. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9098. */
  9099. BoundingSphere.fromRectangle3D = function(rectangle, ellipsoid, surfaceHeight, result) {
  9100. ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
  9101. surfaceHeight = defaultValue(surfaceHeight, 0.0);
  9102. var positions;
  9103. if (defined(rectangle)) {
  9104. positions = Rectangle.subsample(rectangle, ellipsoid, surfaceHeight, fromRectangle3DScratch);
  9105. }
  9106. return BoundingSphere.fromPoints(positions, result);
  9107. };
  9108. /**
  9109. * Computes a tight-fitting bounding sphere enclosing a list of 3D points, where the points are
  9110. * stored in a flat array in X, Y, Z, order. The bounding sphere is computed by running two
  9111. * algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to
  9112. * ensure a tight fit.
  9113. *
  9114. * @param {Number[]} positions An array of points that the bounding sphere will enclose. Each point
  9115. * is formed from three elements in the array in the order X, Y, Z.
  9116. * @param {Cartesian3} [center=Cartesian3.ZERO] The position to which the positions are relative, which need not be the
  9117. * origin of the coordinate system. This is useful when the positions are to be used for
  9118. * relative-to-center (RTC) rendering.
  9119. * @param {Number} [stride=3] The number of array elements per vertex. It must be at least 3, but it may
  9120. * be higher. Regardless of the value of this parameter, the X coordinate of the first position
  9121. * is at array index 0, the Y coordinate is at array index 1, and the Z coordinate is at array index
  9122. * 2. When stride is 3, the X coordinate of the next position then begins at array index 3. If
  9123. * the stride is 5, however, two array elements are skipped and the next position begins at array
  9124. * index 5.
  9125. * @param {BoundingSphere} [result] The object onto which to store the result.
  9126. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.
  9127. *
  9128. * @example
  9129. * // Compute the bounding sphere from 3 positions, each specified relative to a center.
  9130. * // In addition to the X, Y, and Z coordinates, the points array contains two additional
  9131. * // elements per point which are ignored for the purpose of computing the bounding sphere.
  9132. * var center = new Cesium.Cartesian3(1.0, 2.0, 3.0);
  9133. * var points = [1.0, 2.0, 3.0, 0.1, 0.2,
  9134. * 4.0, 5.0, 6.0, 0.1, 0.2,
  9135. * 7.0, 8.0, 9.0, 0.1, 0.2];
  9136. * var sphere = Cesium.BoundingSphere.fromVertices(points, center, 5);
  9137. *
  9138. * @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}
  9139. */
  9140. BoundingSphere.fromVertices = function(positions, center, stride, result) {
  9141. if (!defined(result)) {
  9142. result = new BoundingSphere();
  9143. }
  9144. if (!defined(positions) || positions.length === 0) {
  9145. result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);
  9146. result.radius = 0.0;
  9147. return result;
  9148. }
  9149. center = defaultValue(center, Cartesian3.ZERO);
  9150. stride = defaultValue(stride, 3);
  9151. if (stride < 3) {
  9152. throw new DeveloperError('stride must be 3 or greater.');
  9153. }
  9154. var currentPos = fromPointsCurrentPos;
  9155. currentPos.x = positions[0] + center.x;
  9156. currentPos.y = positions[1] + center.y;
  9157. currentPos.z = positions[2] + center.z;
  9158. var xMin = Cartesian3.clone(currentPos, fromPointsXMin);
  9159. var yMin = Cartesian3.clone(currentPos, fromPointsYMin);
  9160. var zMin = Cartesian3.clone(currentPos, fromPointsZMin);
  9161. var xMax = Cartesian3.clone(currentPos, fromPointsXMax);
  9162. var yMax = Cartesian3.clone(currentPos, fromPointsYMax);
  9163. var zMax = Cartesian3.clone(currentPos, fromPointsZMax);
  9164. var numElements = positions.length;
  9165. for (var i = 0; i < numElements; i += stride) {
  9166. var x = positions[i] + center.x;
  9167. var y = positions[i + 1] + center.y;
  9168. var z = positions[i + 2] + center.z;
  9169. currentPos.x = x;
  9170. currentPos.y = y;
  9171. currentPos.z = z;
  9172. // Store points containing the the smallest and largest components
  9173. if (x < xMin.x) {
  9174. Cartesian3.clone(currentPos, xMin);
  9175. }
  9176. if (x > xMax.x) {
  9177. Cartesian3.clone(currentPos, xMax);
  9178. }
  9179. if (y < yMin.y) {
  9180. Cartesian3.clone(currentPos, yMin);
  9181. }
  9182. if (y > yMax.y) {
  9183. Cartesian3.clone(currentPos, yMax);
  9184. }
  9185. if (z < zMin.z) {
  9186. Cartesian3.clone(currentPos, zMin);
  9187. }
  9188. if (z > zMax.z) {
  9189. Cartesian3.clone(currentPos, zMax);
  9190. }
  9191. }
  9192. // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).
  9193. var xSpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(xMax, xMin, fromPointsScratch));
  9194. var ySpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(yMax, yMin, fromPointsScratch));
  9195. var zSpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(zMax, zMin, fromPointsScratch));
  9196. // Set the diameter endpoints to the largest span.
  9197. var diameter1 = xMin;
  9198. var diameter2 = xMax;
  9199. var maxSpan = xSpan;
  9200. if (ySpan > maxSpan) {
  9201. maxSpan = ySpan;
  9202. diameter1 = yMin;
  9203. diameter2 = yMax;
  9204. }
  9205. if (zSpan > maxSpan) {
  9206. maxSpan = zSpan;
  9207. diameter1 = zMin;
  9208. diameter2 = zMax;
  9209. }
  9210. // Calculate the center of the initial sphere found by Ritter's algorithm
  9211. var ritterCenter = fromPointsRitterCenter;
  9212. ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
  9213. ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
  9214. ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
  9215. // Calculate the radius of the initial sphere found by Ritter's algorithm
  9216. var radiusSquared = Cartesian3.magnitudeSquared(Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch));
  9217. var ritterRadius = Math.sqrt(radiusSquared);
  9218. // Find the center of the sphere found using the Naive method.
  9219. var minBoxPt = fromPointsMinBoxPt;
  9220. minBoxPt.x = xMin.x;
  9221. minBoxPt.y = yMin.y;
  9222. minBoxPt.z = zMin.z;
  9223. var maxBoxPt = fromPointsMaxBoxPt;
  9224. maxBoxPt.x = xMax.x;
  9225. maxBoxPt.y = yMax.y;
  9226. maxBoxPt.z = zMax.z;
  9227. var naiveCenter = Cartesian3.multiplyByScalar(Cartesian3.add(minBoxPt, maxBoxPt, fromPointsScratch), 0.5, fromPointsNaiveCenterScratch);
  9228. // Begin 2nd pass to find naive radius and modify the ritter sphere.
  9229. var naiveRadius = 0;
  9230. for (i = 0; i < numElements; i += stride) {
  9231. currentPos.x = positions[i] + center.x;
  9232. currentPos.y = positions[i + 1] + center.y;
  9233. currentPos.z = positions[i + 2] + center.z;
  9234. // Find the furthest point from the naive center to calculate the naive radius.
  9235. var r = Cartesian3.magnitude(Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch));
  9236. if (r > naiveRadius) {
  9237. naiveRadius = r;
  9238. }
  9239. // Make adjustments to the Ritter Sphere to include all points.
  9240. var oldCenterToPointSquared = Cartesian3.magnitudeSquared(Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch));
  9241. if (oldCenterToPointSquared > radiusSquared) {
  9242. var oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
  9243. // Calculate new radius to include the point that lies outside
  9244. ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
  9245. radiusSquared = ritterRadius * ritterRadius;
  9246. // Calculate center of new Ritter sphere
  9247. var oldToNew = oldCenterToPoint - ritterRadius;
  9248. ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
  9249. ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
  9250. ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
  9251. }
  9252. }
  9253. if (ritterRadius < naiveRadius) {
  9254. Cartesian3.clone(ritterCenter, result.center);
  9255. result.radius = ritterRadius;
  9256. } else {
  9257. Cartesian3.clone(naiveCenter, result.center);
  9258. result.radius = naiveRadius;
  9259. }
  9260. return result;
  9261. };
  9262. /**
  9263. * Computes a tight-fitting bounding sphere enclosing a list of {@link EncodedCartesian3}s, where the points are
  9264. * stored in parallel flat arrays in X, Y, Z, order. The bounding sphere is computed by running two
  9265. * algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to
  9266. * ensure a tight fit.
  9267. *
  9268. * @param {Number[]} positionsHigh An array of high bits of the encoded cartesians that the bounding sphere will enclose. Each point
  9269. * is formed from three elements in the array in the order X, Y, Z.
  9270. * @param {Number[]} positionsLow An array of low bits of the encoded cartesians that the bounding sphere will enclose. Each point
  9271. * is formed from three elements in the array in the order X, Y, Z.
  9272. * @param {BoundingSphere} [result] The object onto which to store the result.
  9273. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.
  9274. *
  9275. * @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}
  9276. */
  9277. BoundingSphere.fromEncodedCartesianVertices = function(positionsHigh, positionsLow, result) {
  9278. if (!defined(result)) {
  9279. result = new BoundingSphere();
  9280. }
  9281. if (!defined(positionsHigh) || !defined(positionsLow) || positionsHigh.length !== positionsLow.length || positionsHigh.length === 0) {
  9282. result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);
  9283. result.radius = 0.0;
  9284. return result;
  9285. }
  9286. var currentPos = fromPointsCurrentPos;
  9287. currentPos.x = positionsHigh[0] + positionsLow[0];
  9288. currentPos.y = positionsHigh[1] + positionsLow[1];
  9289. currentPos.z = positionsHigh[2] + positionsLow[2];
  9290. var xMin = Cartesian3.clone(currentPos, fromPointsXMin);
  9291. var yMin = Cartesian3.clone(currentPos, fromPointsYMin);
  9292. var zMin = Cartesian3.clone(currentPos, fromPointsZMin);
  9293. var xMax = Cartesian3.clone(currentPos, fromPointsXMax);
  9294. var yMax = Cartesian3.clone(currentPos, fromPointsYMax);
  9295. var zMax = Cartesian3.clone(currentPos, fromPointsZMax);
  9296. var numElements = positionsHigh.length;
  9297. for (var i = 0; i < numElements; i += 3) {
  9298. var x = positionsHigh[i] + positionsLow[i];
  9299. var y = positionsHigh[i + 1] + positionsLow[i + 1];
  9300. var z = positionsHigh[i + 2] + positionsLow[i + 2];
  9301. currentPos.x = x;
  9302. currentPos.y = y;
  9303. currentPos.z = z;
  9304. // Store points containing the the smallest and largest components
  9305. if (x < xMin.x) {
  9306. Cartesian3.clone(currentPos, xMin);
  9307. }
  9308. if (x > xMax.x) {
  9309. Cartesian3.clone(currentPos, xMax);
  9310. }
  9311. if (y < yMin.y) {
  9312. Cartesian3.clone(currentPos, yMin);
  9313. }
  9314. if (y > yMax.y) {
  9315. Cartesian3.clone(currentPos, yMax);
  9316. }
  9317. if (z < zMin.z) {
  9318. Cartesian3.clone(currentPos, zMin);
  9319. }
  9320. if (z > zMax.z) {
  9321. Cartesian3.clone(currentPos, zMax);
  9322. }
  9323. }
  9324. // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).
  9325. var xSpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(xMax, xMin, fromPointsScratch));
  9326. var ySpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(yMax, yMin, fromPointsScratch));
  9327. var zSpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(zMax, zMin, fromPointsScratch));
  9328. // Set the diameter endpoints to the largest span.
  9329. var diameter1 = xMin;
  9330. var diameter2 = xMax;
  9331. var maxSpan = xSpan;
  9332. if (ySpan > maxSpan) {
  9333. maxSpan = ySpan;
  9334. diameter1 = yMin;
  9335. diameter2 = yMax;
  9336. }
  9337. if (zSpan > maxSpan) {
  9338. maxSpan = zSpan;
  9339. diameter1 = zMin;
  9340. diameter2 = zMax;
  9341. }
  9342. // Calculate the center of the initial sphere found by Ritter's algorithm
  9343. var ritterCenter = fromPointsRitterCenter;
  9344. ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
  9345. ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
  9346. ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
  9347. // Calculate the radius of the initial sphere found by Ritter's algorithm
  9348. var radiusSquared = Cartesian3.magnitudeSquared(Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch));
  9349. var ritterRadius = Math.sqrt(radiusSquared);
  9350. // Find the center of the sphere found using the Naive method.
  9351. var minBoxPt = fromPointsMinBoxPt;
  9352. minBoxPt.x = xMin.x;
  9353. minBoxPt.y = yMin.y;
  9354. minBoxPt.z = zMin.z;
  9355. var maxBoxPt = fromPointsMaxBoxPt;
  9356. maxBoxPt.x = xMax.x;
  9357. maxBoxPt.y = yMax.y;
  9358. maxBoxPt.z = zMax.z;
  9359. var naiveCenter = Cartesian3.multiplyByScalar(Cartesian3.add(minBoxPt, maxBoxPt, fromPointsScratch), 0.5, fromPointsNaiveCenterScratch);
  9360. // Begin 2nd pass to find naive radius and modify the ritter sphere.
  9361. var naiveRadius = 0;
  9362. for (i = 0; i < numElements; i += 3) {
  9363. currentPos.x = positionsHigh[i] + positionsLow[i];
  9364. currentPos.y = positionsHigh[i + 1] + positionsLow[i + 1];
  9365. currentPos.z = positionsHigh[i + 2] + positionsLow[i + 2];
  9366. // Find the furthest point from the naive center to calculate the naive radius.
  9367. var r = Cartesian3.magnitude(Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch));
  9368. if (r > naiveRadius) {
  9369. naiveRadius = r;
  9370. }
  9371. // Make adjustments to the Ritter Sphere to include all points.
  9372. var oldCenterToPointSquared = Cartesian3.magnitudeSquared(Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch));
  9373. if (oldCenterToPointSquared > radiusSquared) {
  9374. var oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
  9375. // Calculate new radius to include the point that lies outside
  9376. ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
  9377. radiusSquared = ritterRadius * ritterRadius;
  9378. // Calculate center of new Ritter sphere
  9379. var oldToNew = oldCenterToPoint - ritterRadius;
  9380. ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
  9381. ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
  9382. ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
  9383. }
  9384. }
  9385. if (ritterRadius < naiveRadius) {
  9386. Cartesian3.clone(ritterCenter, result.center);
  9387. result.radius = ritterRadius;
  9388. } else {
  9389. Cartesian3.clone(naiveCenter, result.center);
  9390. result.radius = naiveRadius;
  9391. }
  9392. return result;
  9393. };
  9394. /**
  9395. * Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere
  9396. * tighly and fully encompases the box.
  9397. *
  9398. * @param {Cartesian3} [corner] The minimum height over the rectangle.
  9399. * @param {Cartesian3} [oppositeCorner] The maximum height over the rectangle.
  9400. * @param {BoundingSphere} [result] The object onto which to store the result.
  9401. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9402. *
  9403. * @example
  9404. * // Create a bounding sphere around the unit cube
  9405. * var sphere = Cesium.BoundingSphere.fromCornerPoints(new Cesium.Cartesian3(-0.5, -0.5, -0.5), new Cesium.Cartesian3(0.5, 0.5, 0.5));
  9406. */
  9407. BoundingSphere.fromCornerPoints = function(corner, oppositeCorner, result) {
  9408. if (!defined(corner) || !defined(oppositeCorner)) {
  9409. throw new DeveloperError('corner and oppositeCorner are required.');
  9410. }
  9411. if (!defined(result)) {
  9412. result = new BoundingSphere();
  9413. }
  9414. var center = result.center;
  9415. Cartesian3.add(corner, oppositeCorner, center);
  9416. Cartesian3.multiplyByScalar(center, 0.5, center);
  9417. result.radius = Cartesian3.distance(center, oppositeCorner);
  9418. return result;
  9419. };
  9420. /**
  9421. * Creates a bounding sphere encompassing an ellipsoid.
  9422. *
  9423. * @param {Ellipsoid} ellipsoid The ellipsoid around which to create a bounding sphere.
  9424. * @param {BoundingSphere} [result] The object onto which to store the result.
  9425. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9426. *
  9427. * @example
  9428. * var boundingSphere = Cesium.BoundingSphere.fromEllipsoid(ellipsoid);
  9429. */
  9430. BoundingSphere.fromEllipsoid = function(ellipsoid, result) {
  9431. if (!defined(ellipsoid)) {
  9432. throw new DeveloperError('ellipsoid is required.');
  9433. }
  9434. if (!defined(result)) {
  9435. result = new BoundingSphere();
  9436. }
  9437. Cartesian3.clone(Cartesian3.ZERO, result.center);
  9438. result.radius = ellipsoid.maximumRadius;
  9439. return result;
  9440. };
  9441. var fromBoundingSpheresScratch = new Cartesian3();
  9442. /**
  9443. * Computes a tight-fitting bounding sphere enclosing the provided array of bounding spheres.
  9444. *
  9445. * @param {BoundingSphere[]} boundingSpheres The array of bounding spheres.
  9446. * @param {BoundingSphere} [result] The object onto which to store the result.
  9447. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9448. */
  9449. BoundingSphere.fromBoundingSpheres = function(boundingSpheres, result) {
  9450. if (!defined(result)) {
  9451. result = new BoundingSphere();
  9452. }
  9453. if (!defined(boundingSpheres) || boundingSpheres.length === 0) {
  9454. result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);
  9455. result.radius = 0.0;
  9456. return result;
  9457. }
  9458. var length = boundingSpheres.length;
  9459. if (length === 1) {
  9460. return BoundingSphere.clone(boundingSpheres[0], result);
  9461. }
  9462. if (length === 2) {
  9463. return BoundingSphere.union(boundingSpheres[0], boundingSpheres[1], result);
  9464. }
  9465. var positions = [];
  9466. for (var i = 0; i < length; i++) {
  9467. positions.push(boundingSpheres[i].center);
  9468. }
  9469. result = BoundingSphere.fromPoints(positions, result);
  9470. var center = result.center;
  9471. var radius = result.radius;
  9472. for (i = 0; i < length; i++) {
  9473. var tmp = boundingSpheres[i];
  9474. radius = Math.max(radius, Cartesian3.distance(center, tmp.center, fromBoundingSpheresScratch) + tmp.radius);
  9475. }
  9476. result.radius = radius;
  9477. return result;
  9478. };
  9479. var fromOrientedBoundingBoxScratchU = new Cartesian3();
  9480. var fromOrientedBoundingBoxScratchV = new Cartesian3();
  9481. var fromOrientedBoundingBoxScratchW = new Cartesian3();
  9482. /**
  9483. * Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box.
  9484. *
  9485. * @param {OrientedBoundingBox} orientedBoundingBox The oriented bounding box.
  9486. * @param {BoundingSphere} [result] The object onto which to store the result.
  9487. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9488. */
  9489. BoundingSphere.fromOrientedBoundingBox = function(orientedBoundingBox, result) {
  9490. if (!defined(result)) {
  9491. result = new BoundingSphere();
  9492. }
  9493. var halfAxes = orientedBoundingBox.halfAxes;
  9494. var u = Matrix3.getColumn(halfAxes, 0, fromOrientedBoundingBoxScratchU);
  9495. var v = Matrix3.getColumn(halfAxes, 1, fromOrientedBoundingBoxScratchV);
  9496. var w = Matrix3.getColumn(halfAxes, 2, fromOrientedBoundingBoxScratchW);
  9497. var uHalf = Cartesian3.magnitude(u);
  9498. var vHalf = Cartesian3.magnitude(v);
  9499. var wHalf = Cartesian3.magnitude(w);
  9500. result.center = Cartesian3.clone(orientedBoundingBox.center, result.center);
  9501. result.radius = Math.max(uHalf, vHalf, wHalf);
  9502. return result;
  9503. };
  9504. /**
  9505. * Duplicates a BoundingSphere instance.
  9506. *
  9507. * @param {BoundingSphere} sphere The bounding sphere to duplicate.
  9508. * @param {BoundingSphere} [result] The object onto which to store the result.
  9509. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided. (Returns undefined if sphere is undefined)
  9510. */
  9511. BoundingSphere.clone = function(sphere, result) {
  9512. if (!defined(sphere)) {
  9513. return undefined;
  9514. }
  9515. if (!defined(result)) {
  9516. return new BoundingSphere(sphere.center, sphere.radius);
  9517. }
  9518. result.center = Cartesian3.clone(sphere.center, result.center);
  9519. result.radius = sphere.radius;
  9520. return result;
  9521. };
  9522. /**
  9523. * The number of elements used to pack the object into an array.
  9524. * @type {Number}
  9525. */
  9526. BoundingSphere.packedLength = 4;
  9527. /**
  9528. * Stores the provided instance into the provided array.
  9529. *
  9530. * @param {BoundingSphere} value The value to pack.
  9531. * @param {Number[]} array The array to pack into.
  9532. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  9533. *
  9534. * @returns {Number[]} The array that was packed into
  9535. */
  9536. BoundingSphere.pack = function(value, array, startingIndex) {
  9537. if (!defined(value)) {
  9538. throw new DeveloperError('value is required');
  9539. }
  9540. if (!defined(array)) {
  9541. throw new DeveloperError('array is required');
  9542. }
  9543. startingIndex = defaultValue(startingIndex, 0);
  9544. var center = value.center;
  9545. array[startingIndex++] = center.x;
  9546. array[startingIndex++] = center.y;
  9547. array[startingIndex++] = center.z;
  9548. array[startingIndex] = value.radius;
  9549. return array;
  9550. };
  9551. /**
  9552. * Retrieves an instance from a packed array.
  9553. *
  9554. * @param {Number[]} array The packed array.
  9555. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  9556. * @param {BoundingSphere} [result] The object into which to store the result.
  9557. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.
  9558. */
  9559. BoundingSphere.unpack = function(array, startingIndex, result) {
  9560. if (!defined(array)) {
  9561. throw new DeveloperError('array is required');
  9562. }
  9563. startingIndex = defaultValue(startingIndex, 0);
  9564. if (!defined(result)) {
  9565. result = new BoundingSphere();
  9566. }
  9567. var center = result.center;
  9568. center.x = array[startingIndex++];
  9569. center.y = array[startingIndex++];
  9570. center.z = array[startingIndex++];
  9571. result.radius = array[startingIndex];
  9572. return result;
  9573. };
  9574. var unionScratch = new Cartesian3();
  9575. var unionScratchCenter = new Cartesian3();
  9576. /**
  9577. * Computes a bounding sphere that contains both the left and right bounding spheres.
  9578. *
  9579. * @param {BoundingSphere} left A sphere to enclose in a bounding sphere.
  9580. * @param {BoundingSphere} right A sphere to enclose in a bounding sphere.
  9581. * @param {BoundingSphere} [result] The object onto which to store the result.
  9582. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9583. */
  9584. BoundingSphere.union = function(left, right, result) {
  9585. if (!defined(left)) {
  9586. throw new DeveloperError('left is required.');
  9587. }
  9588. if (!defined(right)) {
  9589. throw new DeveloperError('right is required.');
  9590. }
  9591. if (!defined(result)) {
  9592. result = new BoundingSphere();
  9593. }
  9594. var leftCenter = left.center;
  9595. var leftRadius = left.radius;
  9596. var rightCenter = right.center;
  9597. var rightRadius = right.radius;
  9598. var toRightCenter = Cartesian3.subtract(rightCenter, leftCenter, unionScratch);
  9599. var centerSeparation = Cartesian3.magnitude(toRightCenter);
  9600. if (leftRadius >= (centerSeparation + rightRadius)) {
  9601. // Left sphere wins.
  9602. left.clone(result);
  9603. return result;
  9604. }
  9605. if (rightRadius >= (centerSeparation + leftRadius)) {
  9606. // Right sphere wins.
  9607. right.clone(result);
  9608. return result;
  9609. }
  9610. // There are two tangent points, one on far side of each sphere.
  9611. var halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;
  9612. // Compute the center point halfway between the two tangent points.
  9613. var center = Cartesian3.multiplyByScalar(toRightCenter,
  9614. (-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation, unionScratchCenter);
  9615. Cartesian3.add(center, leftCenter, center);
  9616. Cartesian3.clone(center, result.center);
  9617. result.radius = halfDistanceBetweenTangentPoints;
  9618. return result;
  9619. };
  9620. var expandScratch = new Cartesian3();
  9621. /**
  9622. * Computes a bounding sphere by enlarging the provided sphere to contain the provided point.
  9623. *
  9624. * @param {BoundingSphere} sphere A sphere to expand.
  9625. * @param {Cartesian3} point A point to enclose in a bounding sphere.
  9626. * @param {BoundingSphere} [result] The object onto which to store the result.
  9627. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9628. */
  9629. BoundingSphere.expand = function(sphere, point, result) {
  9630. if (!defined(sphere)) {
  9631. throw new DeveloperError('sphere is required.');
  9632. }
  9633. if (!defined(point)) {
  9634. throw new DeveloperError('point is required.');
  9635. }
  9636. result = BoundingSphere.clone(sphere, result);
  9637. var radius = Cartesian3.magnitude(Cartesian3.subtract(point, result.center, expandScratch));
  9638. if (radius > result.radius) {
  9639. result.radius = radius;
  9640. }
  9641. return result;
  9642. };
  9643. /**
  9644. * Determines which side of a plane a sphere is located.
  9645. *
  9646. * @param {BoundingSphere} sphere The bounding sphere to test.
  9647. * @param {Plane} plane The plane to test against.
  9648. * @returns {Intersect} {@link Intersect.INSIDE} if the entire sphere is on the side of the plane
  9649. * the normal is pointing, {@link Intersect.OUTSIDE} if the entire sphere is
  9650. * on the opposite side, and {@link Intersect.INTERSECTING} if the sphere
  9651. * intersects the plane.
  9652. */
  9653. BoundingSphere.intersectPlane = function(sphere, plane) {
  9654. if (!defined(sphere)) {
  9655. throw new DeveloperError('sphere is required.');
  9656. }
  9657. if (!defined(plane)) {
  9658. throw new DeveloperError('plane is required.');
  9659. }
  9660. var center = sphere.center;
  9661. var radius = sphere.radius;
  9662. var normal = plane.normal;
  9663. var distanceToPlane = Cartesian3.dot(normal, center) + plane.distance;
  9664. if (distanceToPlane < -radius) {
  9665. // The center point is negative side of the plane normal
  9666. return Intersect.OUTSIDE;
  9667. } else if (distanceToPlane < radius) {
  9668. // The center point is positive side of the plane, but radius extends beyond it; partial overlap
  9669. return Intersect.INTERSECTING;
  9670. }
  9671. return Intersect.INSIDE;
  9672. };
  9673. /**
  9674. * Applies a 4x4 affine transformation matrix to a bounding sphere.
  9675. *
  9676. * @param {BoundingSphere} sphere The bounding sphere to apply the transformation to.
  9677. * @param {Matrix4} transform The transformation matrix to apply to the bounding sphere.
  9678. * @param {BoundingSphere} [result] The object onto which to store the result.
  9679. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9680. */
  9681. BoundingSphere.transform = function(sphere, transform, result) {
  9682. if (!defined(sphere)) {
  9683. throw new DeveloperError('sphere is required.');
  9684. }
  9685. if (!defined(transform)) {
  9686. throw new DeveloperError('transform is required.');
  9687. }
  9688. if (!defined(result)) {
  9689. result = new BoundingSphere();
  9690. }
  9691. result.center = Matrix4.multiplyByPoint(transform, sphere.center, result.center);
  9692. result.radius = Matrix4.getMaximumScale(transform) * sphere.radius;
  9693. return result;
  9694. };
  9695. var distanceSquaredToScratch = new Cartesian3();
  9696. /**
  9697. * Computes the estimated distance squared from the closest point on a bounding sphere to a point.
  9698. *
  9699. * @param {BoundingSphere} sphere The sphere.
  9700. * @param {Cartesian3} cartesian The point
  9701. * @returns {Number} The estimated distance squared from the bounding sphere to the point.
  9702. *
  9703. * @example
  9704. * // Sort bounding spheres from back to front
  9705. * spheres.sort(function(a, b) {
  9706. * return Cesium.BoundingSphere.distanceSquaredTo(b, camera.positionWC) - Cesium.BoundingSphere.distanceSquaredTo(a, camera.positionWC);
  9707. * });
  9708. */
  9709. BoundingSphere.distanceSquaredTo = function(sphere, cartesian) {
  9710. if (!defined(sphere)) {
  9711. throw new DeveloperError('sphere is required.');
  9712. }
  9713. if (!defined(cartesian)) {
  9714. throw new DeveloperError('cartesian is required.');
  9715. }
  9716. var diff = Cartesian3.subtract(sphere.center, cartesian, distanceSquaredToScratch);
  9717. return Cartesian3.magnitudeSquared(diff) - sphere.radius * sphere.radius;
  9718. };
  9719. /**
  9720. * Applies a 4x4 affine transformation matrix to a bounding sphere where there is no scale
  9721. * The transformation matrix is not verified to have a uniform scale of 1.
  9722. * This method is faster than computing the general bounding sphere transform using {@link BoundingSphere.transform}.
  9723. *
  9724. * @param {BoundingSphere} sphere The bounding sphere to apply the transformation to.
  9725. * @param {Matrix4} transform The transformation matrix to apply to the bounding sphere.
  9726. * @param {BoundingSphere} [result] The object onto which to store the result.
  9727. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9728. *
  9729. * @example
  9730. * var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid);
  9731. * var boundingSphere = new Cesium.BoundingSphere();
  9732. * var newBoundingSphere = Cesium.BoundingSphere.transformWithoutScale(boundingSphere, modelMatrix);
  9733. */
  9734. BoundingSphere.transformWithoutScale = function(sphere, transform, result) {
  9735. if (!defined(sphere)) {
  9736. throw new DeveloperError('sphere is required.');
  9737. }
  9738. if (!defined(transform)) {
  9739. throw new DeveloperError('transform is required.');
  9740. }
  9741. if (!defined(result)) {
  9742. result = new BoundingSphere();
  9743. }
  9744. result.center = Matrix4.multiplyByPoint(transform, sphere.center, result.center);
  9745. result.radius = sphere.radius;
  9746. return result;
  9747. };
  9748. var scratchCartesian3 = new Cartesian3();
  9749. /**
  9750. * The distances calculated by the vector from the center of the bounding sphere to position projected onto direction
  9751. * plus/minus the radius of the bounding sphere.
  9752. * <br>
  9753. * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the
  9754. * closest and farthest planes from position that intersect the bounding sphere.
  9755. *
  9756. * @param {BoundingSphere} sphere The bounding sphere to calculate the distance to.
  9757. * @param {Cartesian3} position The position to calculate the distance from.
  9758. * @param {Cartesian3} direction The direction from position.
  9759. * @param {Interval} [result] A Interval to store the nearest and farthest distances.
  9760. * @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.
  9761. */
  9762. BoundingSphere.computePlaneDistances = function(sphere, position, direction, result) {
  9763. if (!defined(sphere)) {
  9764. throw new DeveloperError('sphere is required.');
  9765. }
  9766. if (!defined(position)) {
  9767. throw new DeveloperError('position is required.');
  9768. }
  9769. if (!defined(direction)) {
  9770. throw new DeveloperError('direction is required.');
  9771. }
  9772. if (!defined(result)) {
  9773. result = new Interval();
  9774. }
  9775. var toCenter = Cartesian3.subtract(sphere.center, position, scratchCartesian3);
  9776. var mag = Cartesian3.dot(direction, toCenter);
  9777. result.start = mag - sphere.radius;
  9778. result.stop = mag + sphere.radius;
  9779. return result;
  9780. };
  9781. var projectTo2DNormalScratch = new Cartesian3();
  9782. var projectTo2DEastScratch = new Cartesian3();
  9783. var projectTo2DNorthScratch = new Cartesian3();
  9784. var projectTo2DWestScratch = new Cartesian3();
  9785. var projectTo2DSouthScratch = new Cartesian3();
  9786. var projectTo2DCartographicScratch = new Cartographic();
  9787. var projectTo2DPositionsScratch = new Array(8);
  9788. for (var n = 0; n < 8; ++n) {
  9789. projectTo2DPositionsScratch[n] = new Cartesian3();
  9790. }
  9791. var projectTo2DProjection = new GeographicProjection();
  9792. /**
  9793. * Creates a bounding sphere in 2D from a bounding sphere in 3D world coordinates.
  9794. *
  9795. * @param {BoundingSphere} sphere The bounding sphere to transform to 2D.
  9796. * @param {Object} [projection=GeographicProjection] The projection to 2D.
  9797. * @param {BoundingSphere} [result] The object onto which to store the result.
  9798. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9799. */
  9800. BoundingSphere.projectTo2D = function(sphere, projection, result) {
  9801. if (!defined(sphere)) {
  9802. throw new DeveloperError('sphere is required.');
  9803. }
  9804. projection = defaultValue(projection, projectTo2DProjection);
  9805. var ellipsoid = projection.ellipsoid;
  9806. var center = sphere.center;
  9807. var radius = sphere.radius;
  9808. var normal = ellipsoid.geodeticSurfaceNormal(center, projectTo2DNormalScratch);
  9809. var east = Cartesian3.cross(Cartesian3.UNIT_Z, normal, projectTo2DEastScratch);
  9810. Cartesian3.normalize(east, east);
  9811. var north = Cartesian3.cross(normal, east, projectTo2DNorthScratch);
  9812. Cartesian3.normalize(north, north);
  9813. Cartesian3.multiplyByScalar(normal, radius, normal);
  9814. Cartesian3.multiplyByScalar(north, radius, north);
  9815. Cartesian3.multiplyByScalar(east, radius, east);
  9816. var south = Cartesian3.negate(north, projectTo2DSouthScratch);
  9817. var west = Cartesian3.negate(east, projectTo2DWestScratch);
  9818. var positions = projectTo2DPositionsScratch;
  9819. // top NE corner
  9820. var corner = positions[0];
  9821. Cartesian3.add(normal, north, corner);
  9822. Cartesian3.add(corner, east, corner);
  9823. // top NW corner
  9824. corner = positions[1];
  9825. Cartesian3.add(normal, north, corner);
  9826. Cartesian3.add(corner, west, corner);
  9827. // top SW corner
  9828. corner = positions[2];
  9829. Cartesian3.add(normal, south, corner);
  9830. Cartesian3.add(corner, west, corner);
  9831. // top SE corner
  9832. corner = positions[3];
  9833. Cartesian3.add(normal, south, corner);
  9834. Cartesian3.add(corner, east, corner);
  9835. Cartesian3.negate(normal, normal);
  9836. // bottom NE corner
  9837. corner = positions[4];
  9838. Cartesian3.add(normal, north, corner);
  9839. Cartesian3.add(corner, east, corner);
  9840. // bottom NW corner
  9841. corner = positions[5];
  9842. Cartesian3.add(normal, north, corner);
  9843. Cartesian3.add(corner, west, corner);
  9844. // bottom SW corner
  9845. corner = positions[6];
  9846. Cartesian3.add(normal, south, corner);
  9847. Cartesian3.add(corner, west, corner);
  9848. // bottom SE corner
  9849. corner = positions[7];
  9850. Cartesian3.add(normal, south, corner);
  9851. Cartesian3.add(corner, east, corner);
  9852. var length = positions.length;
  9853. for (var i = 0; i < length; ++i) {
  9854. var position = positions[i];
  9855. Cartesian3.add(center, position, position);
  9856. var cartographic = ellipsoid.cartesianToCartographic(position, projectTo2DCartographicScratch);
  9857. projection.project(cartographic, position);
  9858. }
  9859. result = BoundingSphere.fromPoints(positions, result);
  9860. // swizzle center components
  9861. center = result.center;
  9862. var x = center.x;
  9863. var y = center.y;
  9864. var z = center.z;
  9865. center.x = z;
  9866. center.y = x;
  9867. center.z = y;
  9868. return result;
  9869. };
  9870. /**
  9871. * Determines whether or not a sphere is hidden from view by the occluder.
  9872. *
  9873. * @param {BoundingSphere} sphere The bounding sphere surrounding the occludee object.
  9874. * @param {Occluder} occluder The occluder.
  9875. * @returns {Boolean} <code>true</code> if the sphere is not visible; otherwise <code>false</code>.
  9876. */
  9877. BoundingSphere.isOccluded = function(sphere, occluder) {
  9878. if (!defined(sphere)) {
  9879. throw new DeveloperError('sphere is required.');
  9880. }
  9881. if (!defined(occluder)) {
  9882. throw new DeveloperError('occluder is required.');
  9883. }
  9884. return !occluder.isBoundingSphereVisible(sphere);
  9885. };
  9886. /**
  9887. * Compares the provided BoundingSphere componentwise and returns
  9888. * <code>true</code> if they are equal, <code>false</code> otherwise.
  9889. *
  9890. * @param {BoundingSphere} [left] The first BoundingSphere.
  9891. * @param {BoundingSphere} [right] The second BoundingSphere.
  9892. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  9893. */
  9894. BoundingSphere.equals = function(left, right) {
  9895. return (left === right) ||
  9896. ((defined(left)) &&
  9897. (defined(right)) &&
  9898. Cartesian3.equals(left.center, right.center) &&
  9899. left.radius === right.radius);
  9900. };
  9901. /**
  9902. * Determines which side of a plane the sphere is located.
  9903. *
  9904. * @param {Plane} plane The plane to test against.
  9905. * @returns {Intersect} {@link Intersect.INSIDE} if the entire sphere is on the side of the plane
  9906. * the normal is pointing, {@link Intersect.OUTSIDE} if the entire sphere is
  9907. * on the opposite side, and {@link Intersect.INTERSECTING} if the sphere
  9908. * intersects the plane.
  9909. */
  9910. BoundingSphere.prototype.intersectPlane = function(plane) {
  9911. return BoundingSphere.intersectPlane(this, plane);
  9912. };
  9913. /**
  9914. * Computes the estimated distance squared from the closest point on a bounding sphere to a point.
  9915. *
  9916. * @param {Cartesian3} cartesian The point
  9917. * @returns {Number} The estimated distance squared from the bounding sphere to the point.
  9918. *
  9919. * @example
  9920. * // Sort bounding spheres from back to front
  9921. * spheres.sort(function(a, b) {
  9922. * return b.distanceSquaredTo(camera.positionWC) - a.distanceSquaredTo(camera.positionWC);
  9923. * });
  9924. */
  9925. BoundingSphere.prototype.distanceSquaredTo = function(cartesian) {
  9926. return BoundingSphere.distanceSquaredTo(this, cartesian);
  9927. };
  9928. /**
  9929. * The distances calculated by the vector from the center of the bounding sphere to position projected onto direction
  9930. * plus/minus the radius of the bounding sphere.
  9931. * <br>
  9932. * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the
  9933. * closest and farthest planes from position that intersect the bounding sphere.
  9934. *
  9935. * @param {Cartesian3} position The position to calculate the distance from.
  9936. * @param {Cartesian3} direction The direction from position.
  9937. * @param {Interval} [result] A Interval to store the nearest and farthest distances.
  9938. * @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.
  9939. */
  9940. BoundingSphere.prototype.computePlaneDistances = function(position, direction, result) {
  9941. return BoundingSphere.computePlaneDistances(this, position, direction, result);
  9942. };
  9943. /**
  9944. * Determines whether or not a sphere is hidden from view by the occluder.
  9945. *
  9946. * @param {Occluder} occluder The occluder.
  9947. * @returns {Boolean} <code>true</code> if the sphere is not visible; otherwise <code>false</code>.
  9948. */
  9949. BoundingSphere.prototype.isOccluded = function(occluder) {
  9950. return BoundingSphere.isOccluded(this, occluder);
  9951. };
  9952. /**
  9953. * Compares this BoundingSphere against the provided BoundingSphere componentwise and returns
  9954. * <code>true</code> if they are equal, <code>false</code> otherwise.
  9955. *
  9956. * @param {BoundingSphere} [right] The right hand side BoundingSphere.
  9957. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  9958. */
  9959. BoundingSphere.prototype.equals = function(right) {
  9960. return BoundingSphere.equals(this, right);
  9961. };
  9962. /**
  9963. * Duplicates this BoundingSphere instance.
  9964. *
  9965. * @param {BoundingSphere} [result] The object onto which to store the result.
  9966. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9967. */
  9968. BoundingSphere.prototype.clone = function(result) {
  9969. return BoundingSphere.clone(this, result);
  9970. };
  9971. return BoundingSphere;
  9972. });
  9973. /*global define*/
  9974. define('Core/Fullscreen',[
  9975. './defined',
  9976. './defineProperties'
  9977. ], function(
  9978. defined,
  9979. defineProperties) {
  9980. 'use strict';
  9981. var _supportsFullscreen;
  9982. var _names = {
  9983. requestFullscreen : undefined,
  9984. exitFullscreen : undefined,
  9985. fullscreenEnabled : undefined,
  9986. fullscreenElement : undefined,
  9987. fullscreenchange : undefined,
  9988. fullscreenerror : undefined
  9989. };
  9990. /**
  9991. * Browser-independent functions for working with the standard fullscreen API.
  9992. *
  9993. * @exports Fullscreen
  9994. *
  9995. * @see {@link http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html|W3C Fullscreen Living Specification}
  9996. */
  9997. var Fullscreen = {};
  9998. defineProperties(Fullscreen, {
  9999. /**
  10000. * The element that is currently fullscreen, if any. To simply check if the
  10001. * browser is in fullscreen mode or not, use {@link Fullscreen#fullscreen}.
  10002. * @memberof Fullscreen
  10003. * @type {Object}
  10004. * @readonly
  10005. */
  10006. element : {
  10007. get : function() {
  10008. if (!Fullscreen.supportsFullscreen()) {
  10009. return undefined;
  10010. }
  10011. return document[_names.fullscreenElement];
  10012. }
  10013. },
  10014. /**
  10015. * The name of the event on the document that is fired when fullscreen is
  10016. * entered or exited. This event name is intended for use with addEventListener.
  10017. * In your event handler, to determine if the browser is in fullscreen mode or not,
  10018. * use {@link Fullscreen#fullscreen}.
  10019. * @memberof Fullscreen
  10020. * @type {String}
  10021. * @readonly
  10022. */
  10023. changeEventName : {
  10024. get : function() {
  10025. if (!Fullscreen.supportsFullscreen()) {
  10026. return undefined;
  10027. }
  10028. return _names.fullscreenchange;
  10029. }
  10030. },
  10031. /**
  10032. * The name of the event that is fired when a fullscreen error
  10033. * occurs. This event name is intended for use with addEventListener.
  10034. * @memberof Fullscreen
  10035. * @type {String}
  10036. * @readonly
  10037. */
  10038. errorEventName : {
  10039. get : function() {
  10040. if (!Fullscreen.supportsFullscreen()) {
  10041. return undefined;
  10042. }
  10043. return _names.fullscreenerror;
  10044. }
  10045. },
  10046. /**
  10047. * Determine whether the browser will allow an element to be made fullscreen, or not.
  10048. * For example, by default, iframes cannot go fullscreen unless the containing page
  10049. * adds an "allowfullscreen" attribute (or prefixed equivalent).
  10050. * @memberof Fullscreen
  10051. * @type {Boolean}
  10052. * @readonly
  10053. */
  10054. enabled : {
  10055. get : function() {
  10056. if (!Fullscreen.supportsFullscreen()) {
  10057. return undefined;
  10058. }
  10059. return document[_names.fullscreenEnabled];
  10060. }
  10061. },
  10062. /**
  10063. * Determines if the browser is currently in fullscreen mode.
  10064. * @memberof Fullscreen
  10065. * @type {Boolean}
  10066. * @readonly
  10067. */
  10068. fullscreen : {
  10069. get : function() {
  10070. if (!Fullscreen.supportsFullscreen()) {
  10071. return undefined;
  10072. }
  10073. return Fullscreen.element !== null;
  10074. }
  10075. }
  10076. });
  10077. /**
  10078. * Detects whether the browser supports the standard fullscreen API.
  10079. *
  10080. * @returns {Boolean} <code>true</code> if the browser supports the standard fullscreen API,
  10081. * <code>false</code> otherwise.
  10082. */
  10083. Fullscreen.supportsFullscreen = function() {
  10084. if (defined(_supportsFullscreen)) {
  10085. return _supportsFullscreen;
  10086. }
  10087. _supportsFullscreen = false;
  10088. var body = document.body;
  10089. if (typeof body.requestFullscreen === 'function') {
  10090. // go with the unprefixed, standard set of names
  10091. _names.requestFullscreen = 'requestFullscreen';
  10092. _names.exitFullscreen = 'exitFullscreen';
  10093. _names.fullscreenEnabled = 'fullscreenEnabled';
  10094. _names.fullscreenElement = 'fullscreenElement';
  10095. _names.fullscreenchange = 'fullscreenchange';
  10096. _names.fullscreenerror = 'fullscreenerror';
  10097. _supportsFullscreen = true;
  10098. return _supportsFullscreen;
  10099. }
  10100. //check for the correct combination of prefix plus the various names that browsers use
  10101. var prefixes = ['webkit', 'moz', 'o', 'ms', 'khtml'];
  10102. var name;
  10103. for (var i = 0, len = prefixes.length; i < len; ++i) {
  10104. var prefix = prefixes[i];
  10105. // casing of Fullscreen differs across browsers
  10106. name = prefix + 'RequestFullscreen';
  10107. if (typeof body[name] === 'function') {
  10108. _names.requestFullscreen = name;
  10109. _supportsFullscreen = true;
  10110. } else {
  10111. name = prefix + 'RequestFullScreen';
  10112. if (typeof body[name] === 'function') {
  10113. _names.requestFullscreen = name;
  10114. _supportsFullscreen = true;
  10115. }
  10116. }
  10117. // disagreement about whether it's "exit" as per spec, or "cancel"
  10118. name = prefix + 'ExitFullscreen';
  10119. if (typeof document[name] === 'function') {
  10120. _names.exitFullscreen = name;
  10121. } else {
  10122. name = prefix + 'CancelFullScreen';
  10123. if (typeof document[name] === 'function') {
  10124. _names.exitFullscreen = name;
  10125. }
  10126. }
  10127. // casing of Fullscreen differs across browsers
  10128. name = prefix + 'FullscreenEnabled';
  10129. if (document[name] !== undefined) {
  10130. _names.fullscreenEnabled = name;
  10131. } else {
  10132. name = prefix + 'FullScreenEnabled';
  10133. if (document[name] !== undefined) {
  10134. _names.fullscreenEnabled = name;
  10135. }
  10136. }
  10137. // casing of Fullscreen differs across browsers
  10138. name = prefix + 'FullscreenElement';
  10139. if (document[name] !== undefined) {
  10140. _names.fullscreenElement = name;
  10141. } else {
  10142. name = prefix + 'FullScreenElement';
  10143. if (document[name] !== undefined) {
  10144. _names.fullscreenElement = name;
  10145. }
  10146. }
  10147. // thankfully, event names are all lowercase per spec
  10148. name = prefix + 'fullscreenchange';
  10149. // event names do not have 'on' in the front, but the property on the document does
  10150. if (document['on' + name] !== undefined) {
  10151. //except on IE
  10152. if (prefix === 'ms') {
  10153. name = 'MSFullscreenChange';
  10154. }
  10155. _names.fullscreenchange = name;
  10156. }
  10157. name = prefix + 'fullscreenerror';
  10158. if (document['on' + name] !== undefined) {
  10159. //except on IE
  10160. if (prefix === 'ms') {
  10161. name = 'MSFullscreenError';
  10162. }
  10163. _names.fullscreenerror = name;
  10164. }
  10165. }
  10166. return _supportsFullscreen;
  10167. };
  10168. /**
  10169. * Asynchronously requests the browser to enter fullscreen mode on the given element.
  10170. * If fullscreen mode is not supported by the browser, does nothing.
  10171. *
  10172. * @param {Object} element The HTML element which will be placed into fullscreen mode.
  10173. * @param {HMDVRDevice} [vrDevice] The VR device.
  10174. *
  10175. * @example
  10176. * // Put the entire page into fullscreen.
  10177. * Cesium.Fullscreen.requestFullscreen(document.body)
  10178. *
  10179. * // Place only the Cesium canvas into fullscreen.
  10180. * Cesium.Fullscreen.requestFullscreen(scene.canvas)
  10181. */
  10182. Fullscreen.requestFullscreen = function(element, vrDevice) {
  10183. if (!Fullscreen.supportsFullscreen()) {
  10184. return;
  10185. }
  10186. element[_names.requestFullscreen]({ vrDisplay: vrDevice });
  10187. };
  10188. /**
  10189. * Asynchronously exits fullscreen mode. If the browser is not currently
  10190. * in fullscreen, or if fullscreen mode is not supported by the browser, does nothing.
  10191. */
  10192. Fullscreen.exitFullscreen = function() {
  10193. if (!Fullscreen.supportsFullscreen()) {
  10194. return;
  10195. }
  10196. document[_names.exitFullscreen]();
  10197. };
  10198. return Fullscreen;
  10199. });
  10200. /*global define*/
  10201. define('Core/FeatureDetection',[
  10202. './defaultValue',
  10203. './defined',
  10204. './Fullscreen'
  10205. ], function(
  10206. defaultValue,
  10207. defined,
  10208. Fullscreen) {
  10209. 'use strict';
  10210. var theNavigator;
  10211. if (typeof navigator !== 'undefined') {
  10212. theNavigator = navigator;
  10213. } else {
  10214. theNavigator = {};
  10215. }
  10216. function extractVersion(versionString) {
  10217. var parts = versionString.split('.');
  10218. for (var i = 0, len = parts.length; i < len; ++i) {
  10219. parts[i] = parseInt(parts[i], 10);
  10220. }
  10221. return parts;
  10222. }
  10223. var isChromeResult;
  10224. var chromeVersionResult;
  10225. function isChrome() {
  10226. if (!defined(isChromeResult)) {
  10227. isChromeResult = false;
  10228. // Edge contains Chrome in the user agent too
  10229. if (!isEdge()) {
  10230. var fields = (/ Chrome\/([\.0-9]+)/).exec(theNavigator.userAgent);
  10231. if (fields !== null) {
  10232. isChromeResult = true;
  10233. chromeVersionResult = extractVersion(fields[1]);
  10234. }
  10235. }
  10236. }
  10237. return isChromeResult;
  10238. }
  10239. function chromeVersion() {
  10240. return isChrome() && chromeVersionResult;
  10241. }
  10242. var isSafariResult;
  10243. var safariVersionResult;
  10244. function isSafari() {
  10245. if (!defined(isSafariResult)) {
  10246. isSafariResult = false;
  10247. // Chrome and Edge contain Safari in the user agent too
  10248. if (!isChrome() && !isEdge() && (/ Safari\/[\.0-9]+/).test(theNavigator.userAgent)) {
  10249. var fields = (/ Version\/([\.0-9]+)/).exec(theNavigator.userAgent);
  10250. if (fields !== null) {
  10251. isSafariResult = true;
  10252. safariVersionResult = extractVersion(fields[1]);
  10253. }
  10254. }
  10255. }
  10256. return isSafariResult;
  10257. }
  10258. function safariVersion() {
  10259. return isSafari() && safariVersionResult;
  10260. }
  10261. var isWebkitResult;
  10262. var webkitVersionResult;
  10263. function isWebkit() {
  10264. if (!defined(isWebkitResult)) {
  10265. isWebkitResult = false;
  10266. var fields = (/ AppleWebKit\/([\.0-9]+)(\+?)/).exec(theNavigator.userAgent);
  10267. if (fields !== null) {
  10268. isWebkitResult = true;
  10269. webkitVersionResult = extractVersion(fields[1]);
  10270. webkitVersionResult.isNightly = !!fields[2];
  10271. }
  10272. }
  10273. return isWebkitResult;
  10274. }
  10275. function webkitVersion() {
  10276. return isWebkit() && webkitVersionResult;
  10277. }
  10278. var isInternetExplorerResult;
  10279. var internetExplorerVersionResult;
  10280. function isInternetExplorer() {
  10281. if (!defined(isInternetExplorerResult)) {
  10282. isInternetExplorerResult = false;
  10283. var fields;
  10284. if (theNavigator.appName === 'Microsoft Internet Explorer') {
  10285. fields = /MSIE ([0-9]{1,}[\.0-9]{0,})/.exec(theNavigator.userAgent);
  10286. if (fields !== null) {
  10287. isInternetExplorerResult = true;
  10288. internetExplorerVersionResult = extractVersion(fields[1]);
  10289. }
  10290. } else if (theNavigator.appName === 'Netscape') {
  10291. fields = /Trident\/.*rv:([0-9]{1,}[\.0-9]{0,})/.exec(theNavigator.userAgent);
  10292. if (fields !== null) {
  10293. isInternetExplorerResult = true;
  10294. internetExplorerVersionResult = extractVersion(fields[1]);
  10295. }
  10296. }
  10297. }
  10298. return isInternetExplorerResult;
  10299. }
  10300. function internetExplorerVersion() {
  10301. return isInternetExplorer() && internetExplorerVersionResult;
  10302. }
  10303. var isEdgeResult;
  10304. var edgeVersionResult;
  10305. function isEdge() {
  10306. if (!defined(isEdgeResult)) {
  10307. isEdgeResult = false;
  10308. var fields = (/ Edge\/([\.0-9]+)/).exec(theNavigator.userAgent);
  10309. if (fields !== null) {
  10310. isEdgeResult = true;
  10311. edgeVersionResult = extractVersion(fields[1]);
  10312. }
  10313. }
  10314. return isEdgeResult;
  10315. }
  10316. function edgeVersion() {
  10317. return isEdge() && edgeVersionResult;
  10318. }
  10319. var isFirefoxResult;
  10320. var firefoxVersionResult;
  10321. function isFirefox() {
  10322. if (!defined(isFirefoxResult)) {
  10323. isFirefoxResult = false;
  10324. var fields = /Firefox\/([\.0-9]+)/.exec(theNavigator.userAgent);
  10325. if (fields !== null) {
  10326. isFirefoxResult = true;
  10327. firefoxVersionResult = extractVersion(fields[1]);
  10328. }
  10329. }
  10330. return isFirefoxResult;
  10331. }
  10332. var isWindowsResult;
  10333. function isWindows() {
  10334. if (!defined(isWindowsResult)) {
  10335. isWindowsResult = /Windows/i.test(theNavigator.appVersion);
  10336. }
  10337. return isWindowsResult;
  10338. }
  10339. function firefoxVersion() {
  10340. return isFirefox() && firefoxVersionResult;
  10341. }
  10342. var hasPointerEvents;
  10343. function supportsPointerEvents() {
  10344. if (!defined(hasPointerEvents)) {
  10345. //While navigator.pointerEnabled is deprecated in the W3C specification
  10346. //we still need to use it if it exists in order to support browsers
  10347. //that rely on it, such as the Windows WebBrowser control which defines
  10348. //PointerEvent but sets navigator.pointerEnabled to false.
  10349. hasPointerEvents = typeof PointerEvent !== 'undefined' && (!defined(theNavigator.pointerEnabled) || theNavigator.pointerEnabled);
  10350. }
  10351. return hasPointerEvents;
  10352. }
  10353. var imageRenderingValueResult;
  10354. var supportsImageRenderingPixelatedResult;
  10355. function supportsImageRenderingPixelated() {
  10356. if (!defined(supportsImageRenderingPixelatedResult)) {
  10357. var canvas = document.createElement('canvas');
  10358. canvas.setAttribute('style',
  10359. 'image-rendering: -moz-crisp-edges;' +
  10360. 'image-rendering: pixelated;');
  10361. //canvas.style.imageRendering will be undefined, null or an empty string on unsupported browsers.
  10362. var tmp = canvas.style.imageRendering;
  10363. supportsImageRenderingPixelatedResult = defined(tmp) && tmp !== '';
  10364. if (supportsImageRenderingPixelatedResult) {
  10365. imageRenderingValueResult = tmp;
  10366. }
  10367. }
  10368. return supportsImageRenderingPixelatedResult;
  10369. }
  10370. function imageRenderingValue() {
  10371. return supportsImageRenderingPixelated() ? imageRenderingValueResult : undefined;
  10372. }
  10373. /**
  10374. * A set of functions to detect whether the current browser supports
  10375. * various features.
  10376. *
  10377. * @exports FeatureDetection
  10378. */
  10379. var FeatureDetection = {
  10380. isChrome : isChrome,
  10381. chromeVersion : chromeVersion,
  10382. isSafari : isSafari,
  10383. safariVersion : safariVersion,
  10384. isWebkit : isWebkit,
  10385. webkitVersion : webkitVersion,
  10386. isInternetExplorer : isInternetExplorer,
  10387. internetExplorerVersion : internetExplorerVersion,
  10388. isEdge : isEdge,
  10389. edgeVersion : edgeVersion,
  10390. isFirefox : isFirefox,
  10391. firefoxVersion : firefoxVersion,
  10392. isWindows : isWindows,
  10393. hardwareConcurrency : defaultValue(theNavigator.hardwareConcurrency, 3),
  10394. supportsPointerEvents : supportsPointerEvents,
  10395. supportsImageRenderingPixelated: supportsImageRenderingPixelated,
  10396. imageRenderingValue: imageRenderingValue
  10397. };
  10398. /**
  10399. * Detects whether the current browser supports the full screen standard.
  10400. *
  10401. * @returns {Boolean} true if the browser supports the full screen standard, false if not.
  10402. *
  10403. * @see Fullscreen
  10404. * @see {@link http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html|W3C Fullscreen Living Specification}
  10405. */
  10406. FeatureDetection.supportsFullscreen = function() {
  10407. return Fullscreen.supportsFullscreen();
  10408. };
  10409. /**
  10410. * Detects whether the current browser supports typed arrays.
  10411. *
  10412. * @returns {Boolean} true if the browser supports typed arrays, false if not.
  10413. *
  10414. * @see {@link http://www.khronos.org/registry/typedarray/specs/latest/|Typed Array Specification}
  10415. */
  10416. FeatureDetection.supportsTypedArrays = function() {
  10417. return typeof ArrayBuffer !== 'undefined';
  10418. };
  10419. /**
  10420. * Detects whether the current browser supports Web Workers.
  10421. *
  10422. * @returns {Boolean} true if the browsers supports Web Workers, false if not.
  10423. *
  10424. * @see {@link http://www.w3.org/TR/workers/}
  10425. */
  10426. FeatureDetection.supportsWebWorkers = function() {
  10427. return typeof Worker !== 'undefined';
  10428. };
  10429. return FeatureDetection;
  10430. });
  10431. /*global define*/
  10432. define('Core/Color',[
  10433. './defaultValue',
  10434. './defined',
  10435. './DeveloperError',
  10436. './FeatureDetection',
  10437. './freezeObject',
  10438. './Math'
  10439. ], function(
  10440. defaultValue,
  10441. defined,
  10442. DeveloperError,
  10443. FeatureDetection,
  10444. freezeObject,
  10445. CesiumMath) {
  10446. 'use strict';
  10447. function hue2rgb(m1, m2, h) {
  10448. if (h < 0) {
  10449. h += 1;
  10450. }
  10451. if (h > 1) {
  10452. h -= 1;
  10453. }
  10454. if (h * 6 < 1) {
  10455. return m1 + (m2 - m1) * 6 * h;
  10456. }
  10457. if (h * 2 < 1) {
  10458. return m2;
  10459. }
  10460. if (h * 3 < 2) {
  10461. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  10462. }
  10463. return m1;
  10464. }
  10465. /**
  10466. * A color, specified using red, green, blue, and alpha values,
  10467. * which range from <code>0</code> (no intensity) to <code>1.0</code> (full intensity).
  10468. * @param {Number} [red=1.0] The red component.
  10469. * @param {Number} [green=1.0] The green component.
  10470. * @param {Number} [blue=1.0] The blue component.
  10471. * @param {Number} [alpha=1.0] The alpha component.
  10472. *
  10473. * @constructor
  10474. * @alias Color
  10475. *
  10476. * @see Packable
  10477. */
  10478. function Color(red, green, blue, alpha) {
  10479. /**
  10480. * The red component.
  10481. * @type {Number}
  10482. * @default 1.0
  10483. */
  10484. this.red = defaultValue(red, 1.0);
  10485. /**
  10486. * The green component.
  10487. * @type {Number}
  10488. * @default 1.0
  10489. */
  10490. this.green = defaultValue(green, 1.0);
  10491. /**
  10492. * The blue component.
  10493. * @type {Number}
  10494. * @default 1.0
  10495. */
  10496. this.blue = defaultValue(blue, 1.0);
  10497. /**
  10498. * The alpha component.
  10499. * @type {Number}
  10500. * @default 1.0
  10501. */
  10502. this.alpha = defaultValue(alpha, 1.0);
  10503. }
  10504. /**
  10505. * Creates a Color instance from a {@link Cartesian4}. <code>x</code>, <code>y</code>, <code>z</code>,
  10506. * and <code>w</code> map to <code>red</code>, <code>green</code>, <code>blue</code>, and <code>alpha</code>, respectively.
  10507. *
  10508. * @param {Cartesian4} cartesian The source cartesian.
  10509. * @param {Color} [result] The object onto which to store the result.
  10510. * @returns {Color} The modified result parameter or a new Color instance if one was not provided.
  10511. */
  10512. Color.fromCartesian4 = function(cartesian, result) {
  10513. if (!defined(cartesian)) {
  10514. throw new DeveloperError('cartesian is required');
  10515. }
  10516. if (!defined(result)) {
  10517. return new Color(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
  10518. }
  10519. result.red = cartesian.x;
  10520. result.green = cartesian.y;
  10521. result.blue = cartesian.z;
  10522. result.alpha = cartesian.w;
  10523. return result;
  10524. };
  10525. /**
  10526. * Creates a new Color specified using red, green, blue, and alpha values
  10527. * that are in the range of 0 to 255, converting them internally to a range of 0.0 to 1.0.
  10528. *
  10529. * @param {Number} [red=255] The red component.
  10530. * @param {Number} [green=255] The green component.
  10531. * @param {Number} [blue=255] The blue component.
  10532. * @param {Number} [alpha=255] The alpha component.
  10533. * @param {Color} [result] The object onto which to store the result.
  10534. * @returns {Color} The modified result parameter or a new Color instance if one was not provided.
  10535. */
  10536. Color.fromBytes = function(red, green, blue, alpha, result) {
  10537. red = Color.byteToFloat(defaultValue(red, 255.0));
  10538. green = Color.byteToFloat(defaultValue(green, 255.0));
  10539. blue = Color.byteToFloat(defaultValue(blue, 255.0));
  10540. alpha = Color.byteToFloat(defaultValue(alpha, 255.0));
  10541. if (!defined(result)) {
  10542. return new Color(red, green, blue, alpha);
  10543. }
  10544. result.red = red;
  10545. result.green = green;
  10546. result.blue = blue;
  10547. result.alpha = alpha;
  10548. return result;
  10549. };
  10550. /**
  10551. * Creates a new Color that has the same red, green, and blue components
  10552. * of the specified color, but with the specified alpha value.
  10553. *
  10554. * @param {Color} color The base color
  10555. * @param {Number} alpha The new alpha component.
  10556. * @param {Color} [result] The object onto which to store the result.
  10557. * @returns {Color} The modified result parameter or a new Color instance if one was not provided.
  10558. *
  10559. * @example var translucentRed = Cesium.Color.fromAlpha(Cesium.Color.RED, 0.9);
  10560. */
  10561. Color.fromAlpha = function(color, alpha, result) {
  10562. if (!defined(color)) {
  10563. throw new DeveloperError('color is required');
  10564. }
  10565. if (!defined(alpha)) {
  10566. throw new DeveloperError('alpha is required');
  10567. }
  10568. if (!defined(result)) {
  10569. return new Color(color.red, color.green, color.blue, alpha);
  10570. }
  10571. result.red = color.red;
  10572. result.green = color.green;
  10573. result.blue = color.blue;
  10574. result.alpha = alpha;
  10575. return result;
  10576. };
  10577. var scratchArrayBuffer;
  10578. var scratchUint32Array;
  10579. var scratchUint8Array;
  10580. if (FeatureDetection.supportsTypedArrays()) {
  10581. scratchArrayBuffer = new ArrayBuffer(4);
  10582. scratchUint32Array = new Uint32Array(scratchArrayBuffer);
  10583. scratchUint8Array = new Uint8Array(scratchArrayBuffer);
  10584. }
  10585. /**
  10586. * Creates a new Color from a single numeric unsigned 32-bit RGBA value, using the endianness
  10587. * of the system.
  10588. *
  10589. * @param {Number} rgba A single numeric unsigned 32-bit RGBA value.
  10590. * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.
  10591. * @returns {Color} The color object.
  10592. *
  10593. * @example
  10594. * var color = Cesium.Color.fromRgba(0x67ADDFFF);
  10595. *
  10596. * @see Color#toRgba
  10597. */
  10598. Color.fromRgba = function(rgba, result) {
  10599. // scratchUint32Array and scratchUint8Array share an underlying array buffer
  10600. scratchUint32Array[0] = rgba;
  10601. return Color.fromBytes(scratchUint8Array[0], scratchUint8Array[1], scratchUint8Array[2], scratchUint8Array[3], result);
  10602. };
  10603. /**
  10604. * Creates a Color instance from hue, saturation, and lightness.
  10605. *
  10606. * @param {Number} [hue=0] The hue angle 0...1
  10607. * @param {Number} [saturation=0] The saturation value 0...1
  10608. * @param {Number} [lightness=0] The lightness value 0...1
  10609. * @param {Number} [alpha=1.0] The alpha component 0...1
  10610. * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.
  10611. * @returns {Color} The color object.
  10612. *
  10613. * @see {@link http://www.w3.org/TR/css3-color/#hsl-color|CSS color values}
  10614. */
  10615. Color.fromHsl = function(hue, saturation, lightness, alpha, result) {
  10616. hue = defaultValue(hue, 0.0) % 1.0;
  10617. saturation = defaultValue(saturation, 0.0);
  10618. lightness = defaultValue(lightness, 0.0);
  10619. alpha = defaultValue(alpha, 1.0);
  10620. var red = lightness;
  10621. var green = lightness;
  10622. var blue = lightness;
  10623. if (saturation !== 0) {
  10624. var m2;
  10625. if (lightness < 0.5) {
  10626. m2 = lightness * (1 + saturation);
  10627. } else {
  10628. m2 = lightness + saturation - lightness * saturation;
  10629. }
  10630. var m1 = 2.0 * lightness - m2;
  10631. red = hue2rgb(m1, m2, hue + 1 / 3);
  10632. green = hue2rgb(m1, m2, hue);
  10633. blue = hue2rgb(m1, m2, hue - 1 / 3);
  10634. }
  10635. if (!defined(result)) {
  10636. return new Color(red, green, blue, alpha);
  10637. }
  10638. result.red = red;
  10639. result.green = green;
  10640. result.blue = blue;
  10641. result.alpha = alpha;
  10642. return result;
  10643. };
  10644. /**
  10645. * Creates a random color using the provided options. For reproducible random colors, you should
  10646. * call {@link CesiumMath#setRandomNumberSeed} once at the beginning of your application.
  10647. *
  10648. * @param {Object} [options] Object with the following properties:
  10649. * @param {Number} [options.red] If specified, the red component to use instead of a randomized value.
  10650. * @param {Number} [options.minimumRed=0.0] The maximum red value to generate if none was specified.
  10651. * @param {Number} [options.maximumRed=1.0] The minimum red value to generate if none was specified.
  10652. * @param {Number} [options.green] If specified, the green component to use instead of a randomized value.
  10653. * @param {Number} [options.minimumGreen=0.0] The maximum green value to generate if none was specified.
  10654. * @param {Number} [options.maximumGreen=1.0] The minimum green value to generate if none was specified.
  10655. * @param {Number} [options.blue] If specified, the blue component to use instead of a randomized value.
  10656. * @param {Number} [options.minimumBlue=0.0] The maximum blue value to generate if none was specified.
  10657. * @param {Number} [options.maximumBlue=1.0] The minimum blue value to generate if none was specified.
  10658. * @param {Number} [options.alpha] If specified, the alpha component to use instead of a randomized value.
  10659. * @param {Number} [options.minimumAlpha=0.0] The maximum alpha value to generate if none was specified.
  10660. * @param {Number} [options.maximumAlpha=1.0] The minimum alpha value to generate if none was specified.
  10661. * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.
  10662. * @returns {Color} The modified result parameter or a new instance if result was undefined.
  10663. *
  10664. * @exception {DeveloperError} minimumRed must be less than or equal to maximumRed.
  10665. * @exception {DeveloperError} minimumGreen must be less than or equal to maximumGreen.
  10666. * @exception {DeveloperError} minimumBlue must be less than or equal to maximumBlue.
  10667. * @exception {DeveloperError} minimumAlpha must be less than or equal to maximumAlpha.
  10668. *
  10669. * @example
  10670. * //Create a completely random color
  10671. * var color = Cesium.Color.fromRandom();
  10672. *
  10673. * //Create a random shade of yellow.
  10674. * var color = Cesium.Color.fromRandom({
  10675. * red : 1.0,
  10676. * green : 1.0,
  10677. * alpha : 1.0
  10678. * });
  10679. *
  10680. * //Create a random bright color.
  10681. * var color = Cesium.Color.fromRandom({
  10682. * minimumRed : 0.75,
  10683. * minimumGreen : 0.75,
  10684. * minimumBlue : 0.75,
  10685. * alpha : 1.0
  10686. * });
  10687. */
  10688. Color.fromRandom = function(options, result) {
  10689. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  10690. var red = options.red;
  10691. if (!defined(red)) {
  10692. var minimumRed = defaultValue(options.minimumRed, 0);
  10693. var maximumRed = defaultValue(options.maximumRed, 1.0);
  10694. if (minimumRed > maximumRed) {
  10695. throw new DeveloperError("minimumRed must be less than or equal to maximumRed");
  10696. }
  10697. red = minimumRed + (CesiumMath.nextRandomNumber() * (maximumRed - minimumRed));
  10698. }
  10699. var green = options.green;
  10700. if (!defined(green)) {
  10701. var minimumGreen = defaultValue(options.minimumGreen, 0);
  10702. var maximumGreen = defaultValue(options.maximumGreen, 1.0);
  10703. if (minimumGreen > maximumGreen) {
  10704. throw new DeveloperError("minimumGreen must be less than or equal to maximumGreen");
  10705. }
  10706. green = minimumGreen + (CesiumMath.nextRandomNumber() * (maximumGreen - minimumGreen));
  10707. }
  10708. var blue = options.blue;
  10709. if (!defined(blue)) {
  10710. var minimumBlue = defaultValue(options.minimumBlue, 0);
  10711. var maximumBlue = defaultValue(options.maximumBlue, 1.0);
  10712. if (minimumBlue > maximumBlue) {
  10713. throw new DeveloperError("minimumBlue must be less than or equal to maximumBlue");
  10714. }
  10715. blue = minimumBlue + (CesiumMath.nextRandomNumber() * (maximumBlue - minimumBlue));
  10716. }
  10717. var alpha = options.alpha;
  10718. if (!defined(alpha)) {
  10719. var minimumAlpha = defaultValue(options.minimumAlpha, 0);
  10720. var maximumAlpha = defaultValue(options.maximumAlpha, 1.0);
  10721. if (minimumAlpha > maximumAlpha) {
  10722. throw new DeveloperError("minimumAlpha must be less than or equal to maximumAlpha");
  10723. }
  10724. alpha = minimumAlpha + (CesiumMath.nextRandomNumber() * (maximumAlpha - minimumAlpha));
  10725. }
  10726. if (!defined(result)) {
  10727. return new Color(red, green, blue, alpha);
  10728. }
  10729. result.red = red;
  10730. result.green = green;
  10731. result.blue = blue;
  10732. result.alpha = alpha;
  10733. return result;
  10734. };
  10735. //#rgb
  10736. var rgbMatcher = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i;
  10737. //#rrggbb
  10738. var rrggbbMatcher = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
  10739. //rgb(), rgba(), or rgb%()
  10740. var rgbParenthesesMatcher = /^rgba?\(\s*([0-9.]+%?)\s*,\s*([0-9.]+%?)\s*,\s*([0-9.]+%?)(?:\s*,\s*([0-9.]+))?\s*\)$/i;
  10741. //hsl(), hsla(), or hsl%()
  10742. var hslParenthesesMatcher = /^hsla?\(\s*([0-9.]+)\s*,\s*([0-9.]+%)\s*,\s*([0-9.]+%)(?:\s*,\s*([0-9.]+))?\s*\)$/i;
  10743. /**
  10744. * Creates a Color instance from a CSS color value.
  10745. *
  10746. * @param {String} color The CSS color value in #rgb, #rrggbb, rgb(), rgba(), hsl(), or hsla() format.
  10747. * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.
  10748. * @returns {Color} The color object, or undefined if the string was not a valid CSS color.
  10749. *
  10750. *
  10751. * @example
  10752. * var cesiumBlue = Cesium.Color.fromCssColorString('#67ADDF');
  10753. * var green = Cesium.Color.fromCssColorString('green');
  10754. *
  10755. * @see {@link http://www.w3.org/TR/css3-color|CSS color values}
  10756. */
  10757. Color.fromCssColorString = function(color, result) {
  10758. if (!defined(color)) {
  10759. throw new DeveloperError('color is required');
  10760. }
  10761. if (!defined(result)) {
  10762. result = new Color();
  10763. }
  10764. var namedColor = Color[color.toUpperCase()];
  10765. if (defined(namedColor)) {
  10766. Color.clone(namedColor, result);
  10767. return result;
  10768. }
  10769. var matches = rgbMatcher.exec(color);
  10770. if (matches !== null) {
  10771. result.red = parseInt(matches[1], 16) / 15;
  10772. result.green = parseInt(matches[2], 16) / 15.0;
  10773. result.blue = parseInt(matches[3], 16) / 15.0;
  10774. result.alpha = 1.0;
  10775. return result;
  10776. }
  10777. matches = rrggbbMatcher.exec(color);
  10778. if (matches !== null) {
  10779. result.red = parseInt(matches[1], 16) / 255.0;
  10780. result.green = parseInt(matches[2], 16) / 255.0;
  10781. result.blue = parseInt(matches[3], 16) / 255.0;
  10782. result.alpha = 1.0;
  10783. return result;
  10784. }
  10785. matches = rgbParenthesesMatcher.exec(color);
  10786. if (matches !== null) {
  10787. result.red = parseFloat(matches[1]) / ('%' === matches[1].substr(-1) ? 100.0 : 255.0);
  10788. result.green = parseFloat(matches[2]) / ('%' === matches[2].substr(-1) ? 100.0 : 255.0);
  10789. result.blue = parseFloat(matches[3]) / ('%' === matches[3].substr(-1) ? 100.0 : 255.0);
  10790. result.alpha = parseFloat(defaultValue(matches[4], '1.0'));
  10791. return result;
  10792. }
  10793. matches = hslParenthesesMatcher.exec(color);
  10794. if (matches !== null) {
  10795. return Color.fromHsl(parseFloat(matches[1]) / 360.0,
  10796. parseFloat(matches[2]) / 100.0,
  10797. parseFloat(matches[3]) / 100.0,
  10798. parseFloat(defaultValue(matches[4], '1.0')), result);
  10799. }
  10800. result = undefined;
  10801. return result;
  10802. };
  10803. /**
  10804. * The number of elements used to pack the object into an array.
  10805. * @type {Number}
  10806. */
  10807. Color.packedLength = 4;
  10808. /**
  10809. * Stores the provided instance into the provided array.
  10810. *
  10811. * @param {Color} value The value to pack.
  10812. * @param {Number[]} array The array to pack into.
  10813. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  10814. *
  10815. * @returns {Number[]} The array that was packed into
  10816. */
  10817. Color.pack = function(value, array, startingIndex) {
  10818. if (!defined(value)) {
  10819. throw new DeveloperError('value is required');
  10820. }
  10821. if (!defined(array)) {
  10822. throw new DeveloperError('array is required');
  10823. }
  10824. startingIndex = defaultValue(startingIndex, 0);
  10825. array[startingIndex++] = value.red;
  10826. array[startingIndex++] = value.green;
  10827. array[startingIndex++] = value.blue;
  10828. array[startingIndex] = value.alpha;
  10829. return array;
  10830. };
  10831. /**
  10832. * Retrieves an instance from a packed array.
  10833. *
  10834. * @param {Number[]} array The packed array.
  10835. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  10836. * @param {Color} [result] The object into which to store the result.
  10837. * @returns {Color} The modified result parameter or a new Color instance if one was not provided.
  10838. */
  10839. Color.unpack = function(array, startingIndex, result) {
  10840. if (!defined(array)) {
  10841. throw new DeveloperError('array is required');
  10842. }
  10843. startingIndex = defaultValue(startingIndex, 0);
  10844. if (!defined(result)) {
  10845. result = new Color();
  10846. }
  10847. result.red = array[startingIndex++];
  10848. result.green = array[startingIndex++];
  10849. result.blue = array[startingIndex++];
  10850. result.alpha = array[startingIndex];
  10851. return result;
  10852. };
  10853. /**
  10854. * Converts a 'byte' color component in the range of 0 to 255 into
  10855. * a 'float' color component in the range of 0 to 1.0.
  10856. *
  10857. * @param {Number} number The number to be converted.
  10858. * @returns {Number} The converted number.
  10859. */
  10860. Color.byteToFloat = function(number) {
  10861. return number / 255.0;
  10862. };
  10863. /**
  10864. * Converts a 'float' color component in the range of 0 to 1.0 into
  10865. * a 'byte' color component in the range of 0 to 255.
  10866. *
  10867. * @param {Number} number The number to be converted.
  10868. * @returns {Number} The converted number.
  10869. */
  10870. Color.floatToByte = function(number) {
  10871. return number === 1.0 ? 255.0 : (number * 256.0) | 0;
  10872. };
  10873. /**
  10874. * Duplicates a Color.
  10875. *
  10876. * @param {Color} color The Color to duplicate.
  10877. * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.
  10878. * @returns {Color} The modified result parameter or a new instance if result was undefined. (Returns undefined if color is undefined)
  10879. */
  10880. Color.clone = function(color, result) {
  10881. if (!defined(color)) {
  10882. return undefined;
  10883. }
  10884. if (!defined(result)) {
  10885. return new Color(color.red, color.green, color.blue, color.alpha);
  10886. }
  10887. result.red = color.red;
  10888. result.green = color.green;
  10889. result.blue = color.blue;
  10890. result.alpha = color.alpha;
  10891. return result;
  10892. };
  10893. /**
  10894. * Returns true if the first Color equals the second color.
  10895. *
  10896. * @param {Color} left The first Color to compare for equality.
  10897. * @param {Color} right The second Color to compare for equality.
  10898. * @returns {Boolean} <code>true</code> if the Colors are equal; otherwise, <code>false</code>.
  10899. */
  10900. Color.equals = function(left, right) {
  10901. return (left === right) || //
  10902. (defined(left) && //
  10903. defined(right) && //
  10904. left.red === right.red && //
  10905. left.green === right.green && //
  10906. left.blue === right.blue && //
  10907. left.alpha === right.alpha);
  10908. };
  10909. /**
  10910. * @private
  10911. */
  10912. Color.equalsArray = function(color, array, offset) {
  10913. return color.red === array[offset] &&
  10914. color.green === array[offset + 1] &&
  10915. color.blue === array[offset + 2] &&
  10916. color.alpha === array[offset + 3];
  10917. };
  10918. /**
  10919. * Returns a duplicate of a Color instance.
  10920. *
  10921. * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.
  10922. * @returns {Color} The modified result parameter or a new instance if result was undefined.
  10923. */
  10924. Color.prototype.clone = function(result) {
  10925. return Color.clone(this, result);
  10926. };
  10927. /**
  10928. * Returns true if this Color equals other.
  10929. *
  10930. * @param {Color} other The Color to compare for equality.
  10931. * @returns {Boolean} <code>true</code> if the Colors are equal; otherwise, <code>false</code>.
  10932. */
  10933. Color.prototype.equals = function(other) {
  10934. return Color.equals(this, other);
  10935. };
  10936. /**
  10937. * Returns <code>true</code> if this Color equals other componentwise within the specified epsilon.
  10938. *
  10939. * @param {Color} other The Color to compare for equality.
  10940. * @param {Number} [epsilon=0.0] The epsilon to use for equality testing.
  10941. * @returns {Boolean} <code>true</code> if the Colors are equal within the specified epsilon; otherwise, <code>false</code>.
  10942. */
  10943. Color.prototype.equalsEpsilon = function(other, epsilon) {
  10944. return (this === other) || //
  10945. ((defined(other)) && //
  10946. (Math.abs(this.red - other.red) <= epsilon) && //
  10947. (Math.abs(this.green - other.green) <= epsilon) && //
  10948. (Math.abs(this.blue - other.blue) <= epsilon) && //
  10949. (Math.abs(this.alpha - other.alpha) <= epsilon));
  10950. };
  10951. /**
  10952. * Creates a string representing this Color in the format '(red, green, blue, alpha)'.
  10953. *
  10954. * @returns {String} A string representing this Color in the format '(red, green, blue, alpha)'.
  10955. */
  10956. Color.prototype.toString = function() {
  10957. return '(' + this.red + ', ' + this.green + ', ' + this.blue + ', ' + this.alpha + ')';
  10958. };
  10959. /**
  10960. * Creates a string containing the CSS color value for this color.
  10961. *
  10962. * @returns {String} The CSS equivalent of this color.
  10963. *
  10964. * @see {@link http://www.w3.org/TR/css3-color/#rgba-color|CSS RGB or RGBA color values}
  10965. */
  10966. Color.prototype.toCssColorString = function() {
  10967. var red = Color.floatToByte(this.red);
  10968. var green = Color.floatToByte(this.green);
  10969. var blue = Color.floatToByte(this.blue);
  10970. if (this.alpha === 1) {
  10971. return 'rgb(' + red + ',' + green + ',' + blue + ')';
  10972. }
  10973. return 'rgba(' + red + ',' + green + ',' + blue + ',' + this.alpha + ')';
  10974. };
  10975. /**
  10976. * Converts this color to an array of red, green, blue, and alpha values
  10977. * that are in the range of 0 to 255.
  10978. *
  10979. * @param {Number[]} [result] The array to store the result in, if undefined a new instance will be created.
  10980. * @returns {Number[]} The modified result parameter or a new instance if result was undefined.
  10981. */
  10982. Color.prototype.toBytes = function(result) {
  10983. var red = Color.floatToByte(this.red);
  10984. var green = Color.floatToByte(this.green);
  10985. var blue = Color.floatToByte(this.blue);
  10986. var alpha = Color.floatToByte(this.alpha);
  10987. if (!defined(result)) {
  10988. return [red, green, blue, alpha];
  10989. }
  10990. result[0] = red;
  10991. result[1] = green;
  10992. result[2] = blue;
  10993. result[3] = alpha;
  10994. return result;
  10995. };
  10996. /**
  10997. * Converts this color to a single numeric unsigned 32-bit RGBA value, using the endianness
  10998. * of the system.
  10999. *
  11000. * @returns {Number} A single numeric unsigned 32-bit RGBA value.
  11001. *
  11002. *
  11003. * @example
  11004. * var rgba = Cesium.Color.BLUE.toRgba();
  11005. *
  11006. * @see Color.fromRgba
  11007. */
  11008. Color.prototype.toRgba = function() {
  11009. // scratchUint32Array and scratchUint8Array share an underlying array buffer
  11010. scratchUint8Array[0] = Color.floatToByte(this.red);
  11011. scratchUint8Array[1] = Color.floatToByte(this.green);
  11012. scratchUint8Array[2] = Color.floatToByte(this.blue);
  11013. scratchUint8Array[3] = Color.floatToByte(this.alpha);
  11014. return scratchUint32Array[0];
  11015. };
  11016. /**
  11017. * Brightens this color by the provided magnitude.
  11018. *
  11019. * @param {Number} magnitude A positive number indicating the amount to brighten.
  11020. * @param {Color} result The object onto which to store the result.
  11021. * @returns {Color} The modified result parameter.
  11022. *
  11023. * @example
  11024. * var brightBlue = Cesium.Color.BLUE.brighten(0.5, new Cesium.Color());
  11025. */
  11026. Color.prototype.brighten = function(magnitude, result) {
  11027. if (!defined(magnitude)) {
  11028. throw new DeveloperError('magnitude is required.');
  11029. }
  11030. if (magnitude < 0.0) {
  11031. throw new DeveloperError('magnitude must be positive.');
  11032. }
  11033. if (!defined(result)) {
  11034. throw new DeveloperError('result is required.');
  11035. }
  11036. magnitude = (1.0 - magnitude);
  11037. result.red = 1.0 - ((1.0 - this.red) * magnitude);
  11038. result.green = 1.0 - ((1.0 - this.green) * magnitude);
  11039. result.blue = 1.0 - ((1.0 - this.blue) * magnitude);
  11040. result.alpha = this.alpha;
  11041. return result;
  11042. };
  11043. /**
  11044. * Darkens this color by the provided magnitude.
  11045. *
  11046. * @param {Number} magnitude A positive number indicating the amount to darken.
  11047. * @param {Color} result The object onto which to store the result.
  11048. * @returns {Color} The modified result parameter.
  11049. *
  11050. * @example
  11051. * var darkBlue = Cesium.Color.BLUE.darken(0.5, new Cesium.Color());
  11052. */
  11053. Color.prototype.darken = function(magnitude, result) {
  11054. if (!defined(magnitude)) {
  11055. throw new DeveloperError('magnitude is required.');
  11056. }
  11057. if (magnitude < 0.0) {
  11058. throw new DeveloperError('magnitude must be positive.');
  11059. }
  11060. if (!defined(result)) {
  11061. throw new DeveloperError('result is required.');
  11062. }
  11063. magnitude = (1.0 - magnitude);
  11064. result.red = this.red * magnitude;
  11065. result.green = this.green * magnitude;
  11066. result.blue = this.blue * magnitude;
  11067. result.alpha = this.alpha;
  11068. return result;
  11069. };
  11070. /**
  11071. * Creates a new Color that has the same red, green, and blue components
  11072. * as this Color, but with the specified alpha value.
  11073. *
  11074. * @param {Number} alpha The new alpha component.
  11075. * @param {Color} [result] The object onto which to store the result.
  11076. * @returns {Color} The modified result parameter or a new Color instance if one was not provided.
  11077. *
  11078. * @example var translucentRed = Cesium.Color.RED.withAlpha(0.9);
  11079. */
  11080. Color.prototype.withAlpha = function(alpha, result) {
  11081. return Color.fromAlpha(this, alpha, result);
  11082. };
  11083. /**
  11084. * Computes the componentwise sum of two Colors.
  11085. *
  11086. * @param {Color} left The first Color.
  11087. * @param {Color} right The second Color.
  11088. * @param {Color} result The object onto which to store the result.
  11089. * @returns {Color} The modified result parameter.
  11090. */
  11091. Color.add = function(left, right, result) {
  11092. if (!defined(left)) {
  11093. throw new DeveloperError('left is required');
  11094. }
  11095. if (!defined(right)) {
  11096. throw new DeveloperError('right is required');
  11097. }
  11098. if (!defined(result)) {
  11099. throw new DeveloperError('result is required');
  11100. }
  11101. result.red = left.red + right.red;
  11102. result.green = left.green + right.green;
  11103. result.blue = left.blue + right.blue;
  11104. result.alpha = left.alpha + right.alpha;
  11105. return result;
  11106. };
  11107. /**
  11108. * Computes the componentwise difference of two Colors.
  11109. *
  11110. * @param {Color} left The first Color.
  11111. * @param {Color} right The second Color.
  11112. * @param {Color} result The object onto which to store the result.
  11113. * @returns {Color} The modified result parameter.
  11114. */
  11115. Color.subtract = function(left, right, result) {
  11116. if (!defined(left)) {
  11117. throw new DeveloperError('left is required');
  11118. }
  11119. if (!defined(right)) {
  11120. throw new DeveloperError('right is required');
  11121. }
  11122. if (!defined(result)) {
  11123. throw new DeveloperError('result is required');
  11124. }
  11125. result.red = left.red - right.red;
  11126. result.green = left.green - right.green;
  11127. result.blue = left.blue - right.blue;
  11128. result.alpha = left.alpha - right.alpha;
  11129. return result;
  11130. };
  11131. /**
  11132. * Computes the componentwise product of two Colors.
  11133. *
  11134. * @param {Color} left The first Color.
  11135. * @param {Color} right The second Color.
  11136. * @param {Color} result The object onto which to store the result.
  11137. * @returns {Color} The modified result parameter.
  11138. */
  11139. Color.multiply = function(left, right, result) {
  11140. if (!defined(left)) {
  11141. throw new DeveloperError('left is required');
  11142. }
  11143. if (!defined(right)) {
  11144. throw new DeveloperError('right is required');
  11145. }
  11146. if (!defined(result)) {
  11147. throw new DeveloperError('result is required');
  11148. }
  11149. result.red = left.red * right.red;
  11150. result.green = left.green * right.green;
  11151. result.blue = left.blue * right.blue;
  11152. result.alpha = left.alpha * right.alpha;
  11153. return result;
  11154. };
  11155. /**
  11156. * Computes the componentwise quotient of two Colors.
  11157. *
  11158. * @param {Color} left The first Color.
  11159. * @param {Color} right The second Color.
  11160. * @param {Color} result The object onto which to store the result.
  11161. * @returns {Color} The modified result parameter.
  11162. */
  11163. Color.divide = function(left, right, result) {
  11164. if (!defined(left)) {
  11165. throw new DeveloperError('left is required');
  11166. }
  11167. if (!defined(right)) {
  11168. throw new DeveloperError('right is required');
  11169. }
  11170. if (!defined(result)) {
  11171. throw new DeveloperError('result is required');
  11172. }
  11173. result.red = left.red / right.red;
  11174. result.green = left.green / right.green;
  11175. result.blue = left.blue / right.blue;
  11176. result.alpha = left.alpha / right.alpha;
  11177. return result;
  11178. };
  11179. /**
  11180. * Computes the componentwise modulus of two Colors.
  11181. *
  11182. * @param {Color} left The first Color.
  11183. * @param {Color} right The second Color.
  11184. * @param {Color} result The object onto which to store the result.
  11185. * @returns {Color} The modified result parameter.
  11186. */
  11187. Color.mod = function(left, right, result) {
  11188. if (!defined(left)) {
  11189. throw new DeveloperError('left is required');
  11190. }
  11191. if (!defined(right)) {
  11192. throw new DeveloperError('right is required');
  11193. }
  11194. if (!defined(result)) {
  11195. throw new DeveloperError('result is required');
  11196. }
  11197. result.red = left.red % right.red;
  11198. result.green = left.green % right.green;
  11199. result.blue = left.blue % right.blue;
  11200. result.alpha = left.alpha % right.alpha;
  11201. return result;
  11202. };
  11203. /**
  11204. * Multiplies the provided Color componentwise by the provided scalar.
  11205. *
  11206. * @param {Color} color The Color to be scaled.
  11207. * @param {Number} scalar The scalar to multiply with.
  11208. * @param {Color} result The object onto which to store the result.
  11209. * @returns {Color} The modified result parameter.
  11210. */
  11211. Color.multiplyByScalar = function(color, scalar, result) {
  11212. if (!defined(color)) {
  11213. throw new DeveloperError('cartesian is required');
  11214. }
  11215. if (typeof scalar !== 'number') {
  11216. throw new DeveloperError('scalar is required and must be a number.');
  11217. }
  11218. if (!defined(result)) {
  11219. throw new DeveloperError('result is required');
  11220. }
  11221. result.red = color.red * scalar;
  11222. result.green = color.green * scalar;
  11223. result.blue = color.blue * scalar;
  11224. result.alpha = color.alpha * scalar;
  11225. return result;
  11226. };
  11227. /**
  11228. * Divides the provided Color componentwise by the provided scalar.
  11229. *
  11230. * @param {Color} color The Color to be divided.
  11231. * @param {Number} scalar The scalar to divide with.
  11232. * @param {Color} result The object onto which to store the result.
  11233. * @returns {Color} The modified result parameter.
  11234. */
  11235. Color.divideByScalar = function(color, scalar, result) {
  11236. if (!defined(color)) {
  11237. throw new DeveloperError('cartesian is required');
  11238. }
  11239. if (typeof scalar !== 'number') {
  11240. throw new DeveloperError('scalar is required and must be a number.');
  11241. }
  11242. if (!defined(result)) {
  11243. throw new DeveloperError('result is required');
  11244. }
  11245. result.red = color.red / scalar;
  11246. result.green = color.green / scalar;
  11247. result.blue = color.blue / scalar;
  11248. result.alpha = color.alpha / scalar;
  11249. return result;
  11250. };
  11251. /**
  11252. * An immutable Color instance initialized to CSS color #F0F8FF
  11253. * <span class="colorSwath" style="background: #F0F8FF;"></span>
  11254. *
  11255. * @constant
  11256. * @type {Color}
  11257. */
  11258. Color.ALICEBLUE = freezeObject(Color.fromCssColorString('#F0F8FF'));
  11259. /**
  11260. * An immutable Color instance initialized to CSS color #FAEBD7
  11261. * <span class="colorSwath" style="background: #FAEBD7;"></span>
  11262. *
  11263. * @constant
  11264. * @type {Color}
  11265. */
  11266. Color.ANTIQUEWHITE = freezeObject(Color.fromCssColorString('#FAEBD7'));
  11267. /**
  11268. * An immutable Color instance initialized to CSS color #00FFFF
  11269. * <span class="colorSwath" style="background: #00FFFF;"></span>
  11270. *
  11271. * @constant
  11272. * @type {Color}
  11273. */
  11274. Color.AQUA = freezeObject(Color.fromCssColorString('#00FFFF'));
  11275. /**
  11276. * An immutable Color instance initialized to CSS color #7FFFD4
  11277. * <span class="colorSwath" style="background: #7FFFD4;"></span>
  11278. *
  11279. * @constant
  11280. * @type {Color}
  11281. */
  11282. Color.AQUAMARINE = freezeObject(Color.fromCssColorString('#7FFFD4'));
  11283. /**
  11284. * An immutable Color instance initialized to CSS color #F0FFFF
  11285. * <span class="colorSwath" style="background: #F0FFFF;"></span>
  11286. *
  11287. * @constant
  11288. * @type {Color}
  11289. */
  11290. Color.AZURE = freezeObject(Color.fromCssColorString('#F0FFFF'));
  11291. /**
  11292. * An immutable Color instance initialized to CSS color #F5F5DC
  11293. * <span class="colorSwath" style="background: #F5F5DC;"></span>
  11294. *
  11295. * @constant
  11296. * @type {Color}
  11297. */
  11298. Color.BEIGE = freezeObject(Color.fromCssColorString('#F5F5DC'));
  11299. /**
  11300. * An immutable Color instance initialized to CSS color #FFE4C4
  11301. * <span class="colorSwath" style="background: #FFE4C4;"></span>
  11302. *
  11303. * @constant
  11304. * @type {Color}
  11305. */
  11306. Color.BISQUE = freezeObject(Color.fromCssColorString('#FFE4C4'));
  11307. /**
  11308. * An immutable Color instance initialized to CSS color #000000
  11309. * <span class="colorSwath" style="background: #000000;"></span>
  11310. *
  11311. * @constant
  11312. * @type {Color}
  11313. */
  11314. Color.BLACK = freezeObject(Color.fromCssColorString('#000000'));
  11315. /**
  11316. * An immutable Color instance initialized to CSS color #FFEBCD
  11317. * <span class="colorSwath" style="background: #FFEBCD;"></span>
  11318. *
  11319. * @constant
  11320. * @type {Color}
  11321. */
  11322. Color.BLANCHEDALMOND = freezeObject(Color.fromCssColorString('#FFEBCD'));
  11323. /**
  11324. * An immutable Color instance initialized to CSS color #0000FF
  11325. * <span class="colorSwath" style="background: #0000FF;"></span>
  11326. *
  11327. * @constant
  11328. * @type {Color}
  11329. */
  11330. Color.BLUE = freezeObject(Color.fromCssColorString('#0000FF'));
  11331. /**
  11332. * An immutable Color instance initialized to CSS color #8A2BE2
  11333. * <span class="colorSwath" style="background: #8A2BE2;"></span>
  11334. *
  11335. * @constant
  11336. * @type {Color}
  11337. */
  11338. Color.BLUEVIOLET = freezeObject(Color.fromCssColorString('#8A2BE2'));
  11339. /**
  11340. * An immutable Color instance initialized to CSS color #A52A2A
  11341. * <span class="colorSwath" style="background: #A52A2A;"></span>
  11342. *
  11343. * @constant
  11344. * @type {Color}
  11345. */
  11346. Color.BROWN = freezeObject(Color.fromCssColorString('#A52A2A'));
  11347. /**
  11348. * An immutable Color instance initialized to CSS color #DEB887
  11349. * <span class="colorSwath" style="background: #DEB887;"></span>
  11350. *
  11351. * @constant
  11352. * @type {Color}
  11353. */
  11354. Color.BURLYWOOD = freezeObject(Color.fromCssColorString('#DEB887'));
  11355. /**
  11356. * An immutable Color instance initialized to CSS color #5F9EA0
  11357. * <span class="colorSwath" style="background: #5F9EA0;"></span>
  11358. *
  11359. * @constant
  11360. * @type {Color}
  11361. */
  11362. Color.CADETBLUE = freezeObject(Color.fromCssColorString('#5F9EA0'));
  11363. /**
  11364. * An immutable Color instance initialized to CSS color #7FFF00
  11365. * <span class="colorSwath" style="background: #7FFF00;"></span>
  11366. *
  11367. * @constant
  11368. * @type {Color}
  11369. */
  11370. Color.CHARTREUSE = freezeObject(Color.fromCssColorString('#7FFF00'));
  11371. /**
  11372. * An immutable Color instance initialized to CSS color #D2691E
  11373. * <span class="colorSwath" style="background: #D2691E;"></span>
  11374. *
  11375. * @constant
  11376. * @type {Color}
  11377. */
  11378. Color.CHOCOLATE = freezeObject(Color.fromCssColorString('#D2691E'));
  11379. /**
  11380. * An immutable Color instance initialized to CSS color #FF7F50
  11381. * <span class="colorSwath" style="background: #FF7F50;"></span>
  11382. *
  11383. * @constant
  11384. * @type {Color}
  11385. */
  11386. Color.CORAL = freezeObject(Color.fromCssColorString('#FF7F50'));
  11387. /**
  11388. * An immutable Color instance initialized to CSS color #6495ED
  11389. * <span class="colorSwath" style="background: #6495ED;"></span>
  11390. *
  11391. * @constant
  11392. * @type {Color}
  11393. */
  11394. Color.CORNFLOWERBLUE = freezeObject(Color.fromCssColorString('#6495ED'));
  11395. /**
  11396. * An immutable Color instance initialized to CSS color #FFF8DC
  11397. * <span class="colorSwath" style="background: #FFF8DC;"></span>
  11398. *
  11399. * @constant
  11400. * @type {Color}
  11401. */
  11402. Color.CORNSILK = freezeObject(Color.fromCssColorString('#FFF8DC'));
  11403. /**
  11404. * An immutable Color instance initialized to CSS color #DC143C
  11405. * <span class="colorSwath" style="background: #DC143C;"></span>
  11406. *
  11407. * @constant
  11408. * @type {Color}
  11409. */
  11410. Color.CRIMSON = freezeObject(Color.fromCssColorString('#DC143C'));
  11411. /**
  11412. * An immutable Color instance initialized to CSS color #00FFFF
  11413. * <span class="colorSwath" style="background: #00FFFF;"></span>
  11414. *
  11415. * @constant
  11416. * @type {Color}
  11417. */
  11418. Color.CYAN = freezeObject(Color.fromCssColorString('#00FFFF'));
  11419. /**
  11420. * An immutable Color instance initialized to CSS color #00008B
  11421. * <span class="colorSwath" style="background: #00008B;"></span>
  11422. *
  11423. * @constant
  11424. * @type {Color}
  11425. */
  11426. Color.DARKBLUE = freezeObject(Color.fromCssColorString('#00008B'));
  11427. /**
  11428. * An immutable Color instance initialized to CSS color #008B8B
  11429. * <span class="colorSwath" style="background: #008B8B;"></span>
  11430. *
  11431. * @constant
  11432. * @type {Color}
  11433. */
  11434. Color.DARKCYAN = freezeObject(Color.fromCssColorString('#008B8B'));
  11435. /**
  11436. * An immutable Color instance initialized to CSS color #B8860B
  11437. * <span class="colorSwath" style="background: #B8860B;"></span>
  11438. *
  11439. * @constant
  11440. * @type {Color}
  11441. */
  11442. Color.DARKGOLDENROD = freezeObject(Color.fromCssColorString('#B8860B'));
  11443. /**
  11444. * An immutable Color instance initialized to CSS color #A9A9A9
  11445. * <span class="colorSwath" style="background: #A9A9A9;"></span>
  11446. *
  11447. * @constant
  11448. * @type {Color}
  11449. */
  11450. Color.DARKGRAY = freezeObject(Color.fromCssColorString('#A9A9A9'));
  11451. /**
  11452. * An immutable Color instance initialized to CSS color #006400
  11453. * <span class="colorSwath" style="background: #006400;"></span>
  11454. *
  11455. * @constant
  11456. * @type {Color}
  11457. */
  11458. Color.DARKGREEN = freezeObject(Color.fromCssColorString('#006400'));
  11459. /**
  11460. * An immutable Color instance initialized to CSS color #A9A9A9
  11461. * <span class="colorSwath" style="background: #A9A9A9;"></span>
  11462. *
  11463. * @constant
  11464. * @type {Color}
  11465. */
  11466. Color.DARKGREY = Color.DARKGRAY;
  11467. /**
  11468. * An immutable Color instance initialized to CSS color #BDB76B
  11469. * <span class="colorSwath" style="background: #BDB76B;"></span>
  11470. *
  11471. * @constant
  11472. * @type {Color}
  11473. */
  11474. Color.DARKKHAKI = freezeObject(Color.fromCssColorString('#BDB76B'));
  11475. /**
  11476. * An immutable Color instance initialized to CSS color #8B008B
  11477. * <span class="colorSwath" style="background: #8B008B;"></span>
  11478. *
  11479. * @constant
  11480. * @type {Color}
  11481. */
  11482. Color.DARKMAGENTA = freezeObject(Color.fromCssColorString('#8B008B'));
  11483. /**
  11484. * An immutable Color instance initialized to CSS color #556B2F
  11485. * <span class="colorSwath" style="background: #556B2F;"></span>
  11486. *
  11487. * @constant
  11488. * @type {Color}
  11489. */
  11490. Color.DARKOLIVEGREEN = freezeObject(Color.fromCssColorString('#556B2F'));
  11491. /**
  11492. * An immutable Color instance initialized to CSS color #FF8C00
  11493. * <span class="colorSwath" style="background: #FF8C00;"></span>
  11494. *
  11495. * @constant
  11496. * @type {Color}
  11497. */
  11498. Color.DARKORANGE = freezeObject(Color.fromCssColorString('#FF8C00'));
  11499. /**
  11500. * An immutable Color instance initialized to CSS color #9932CC
  11501. * <span class="colorSwath" style="background: #9932CC;"></span>
  11502. *
  11503. * @constant
  11504. * @type {Color}
  11505. */
  11506. Color.DARKORCHID = freezeObject(Color.fromCssColorString('#9932CC'));
  11507. /**
  11508. * An immutable Color instance initialized to CSS color #8B0000
  11509. * <span class="colorSwath" style="background: #8B0000;"></span>
  11510. *
  11511. * @constant
  11512. * @type {Color}
  11513. */
  11514. Color.DARKRED = freezeObject(Color.fromCssColorString('#8B0000'));
  11515. /**
  11516. * An immutable Color instance initialized to CSS color #E9967A
  11517. * <span class="colorSwath" style="background: #E9967A;"></span>
  11518. *
  11519. * @constant
  11520. * @type {Color}
  11521. */
  11522. Color.DARKSALMON = freezeObject(Color.fromCssColorString('#E9967A'));
  11523. /**
  11524. * An immutable Color instance initialized to CSS color #8FBC8F
  11525. * <span class="colorSwath" style="background: #8FBC8F;"></span>
  11526. *
  11527. * @constant
  11528. * @type {Color}
  11529. */
  11530. Color.DARKSEAGREEN = freezeObject(Color.fromCssColorString('#8FBC8F'));
  11531. /**
  11532. * An immutable Color instance initialized to CSS color #483D8B
  11533. * <span class="colorSwath" style="background: #483D8B;"></span>
  11534. *
  11535. * @constant
  11536. * @type {Color}
  11537. */
  11538. Color.DARKSLATEBLUE = freezeObject(Color.fromCssColorString('#483D8B'));
  11539. /**
  11540. * An immutable Color instance initialized to CSS color #2F4F4F
  11541. * <span class="colorSwath" style="background: #2F4F4F;"></span>
  11542. *
  11543. * @constant
  11544. * @type {Color}
  11545. */
  11546. Color.DARKSLATEGRAY = freezeObject(Color.fromCssColorString('#2F4F4F'));
  11547. /**
  11548. * An immutable Color instance initialized to CSS color #2F4F4F
  11549. * <span class="colorSwath" style="background: #2F4F4F;"></span>
  11550. *
  11551. * @constant
  11552. * @type {Color}
  11553. */
  11554. Color.DARKSLATEGREY = Color.DARKSLATEGRAY;
  11555. /**
  11556. * An immutable Color instance initialized to CSS color #00CED1
  11557. * <span class="colorSwath" style="background: #00CED1;"></span>
  11558. *
  11559. * @constant
  11560. * @type {Color}
  11561. */
  11562. Color.DARKTURQUOISE = freezeObject(Color.fromCssColorString('#00CED1'));
  11563. /**
  11564. * An immutable Color instance initialized to CSS color #9400D3
  11565. * <span class="colorSwath" style="background: #9400D3;"></span>
  11566. *
  11567. * @constant
  11568. * @type {Color}
  11569. */
  11570. Color.DARKVIOLET = freezeObject(Color.fromCssColorString('#9400D3'));
  11571. /**
  11572. * An immutable Color instance initialized to CSS color #FF1493
  11573. * <span class="colorSwath" style="background: #FF1493;"></span>
  11574. *
  11575. * @constant
  11576. * @type {Color}
  11577. */
  11578. Color.DEEPPINK = freezeObject(Color.fromCssColorString('#FF1493'));
  11579. /**
  11580. * An immutable Color instance initialized to CSS color #00BFFF
  11581. * <span class="colorSwath" style="background: #00BFFF;"></span>
  11582. *
  11583. * @constant
  11584. * @type {Color}
  11585. */
  11586. Color.DEEPSKYBLUE = freezeObject(Color.fromCssColorString('#00BFFF'));
  11587. /**
  11588. * An immutable Color instance initialized to CSS color #696969
  11589. * <span class="colorSwath" style="background: #696969;"></span>
  11590. *
  11591. * @constant
  11592. * @type {Color}
  11593. */
  11594. Color.DIMGRAY = freezeObject(Color.fromCssColorString('#696969'));
  11595. /**
  11596. * An immutable Color instance initialized to CSS color #696969
  11597. * <span class="colorSwath" style="background: #696969;"></span>
  11598. *
  11599. * @constant
  11600. * @type {Color}
  11601. */
  11602. Color.DIMGREY = Color.DIMGRAY;
  11603. /**
  11604. * An immutable Color instance initialized to CSS color #1E90FF
  11605. * <span class="colorSwath" style="background: #1E90FF;"></span>
  11606. *
  11607. * @constant
  11608. * @type {Color}
  11609. */
  11610. Color.DODGERBLUE = freezeObject(Color.fromCssColorString('#1E90FF'));
  11611. /**
  11612. * An immutable Color instance initialized to CSS color #B22222
  11613. * <span class="colorSwath" style="background: #B22222;"></span>
  11614. *
  11615. * @constant
  11616. * @type {Color}
  11617. */
  11618. Color.FIREBRICK = freezeObject(Color.fromCssColorString('#B22222'));
  11619. /**
  11620. * An immutable Color instance initialized to CSS color #FFFAF0
  11621. * <span class="colorSwath" style="background: #FFFAF0;"></span>
  11622. *
  11623. * @constant
  11624. * @type {Color}
  11625. */
  11626. Color.FLORALWHITE = freezeObject(Color.fromCssColorString('#FFFAF0'));
  11627. /**
  11628. * An immutable Color instance initialized to CSS color #228B22
  11629. * <span class="colorSwath" style="background: #228B22;"></span>
  11630. *
  11631. * @constant
  11632. * @type {Color}
  11633. */
  11634. Color.FORESTGREEN = freezeObject(Color.fromCssColorString('#228B22'));
  11635. /**
  11636. * An immutable Color instance initialized to CSS color #FF00FF
  11637. * <span class="colorSwath" style="background: #FF00FF;"></span>
  11638. *
  11639. * @constant
  11640. * @type {Color}
  11641. */
  11642. Color.FUSCHIA = freezeObject(Color.fromCssColorString('#FF00FF'));
  11643. /**
  11644. * An immutable Color instance initialized to CSS color #DCDCDC
  11645. * <span class="colorSwath" style="background: #DCDCDC;"></span>
  11646. *
  11647. * @constant
  11648. * @type {Color}
  11649. */
  11650. Color.GAINSBORO = freezeObject(Color.fromCssColorString('#DCDCDC'));
  11651. /**
  11652. * An immutable Color instance initialized to CSS color #F8F8FF
  11653. * <span class="colorSwath" style="background: #F8F8FF;"></span>
  11654. *
  11655. * @constant
  11656. * @type {Color}
  11657. */
  11658. Color.GHOSTWHITE = freezeObject(Color.fromCssColorString('#F8F8FF'));
  11659. /**
  11660. * An immutable Color instance initialized to CSS color #FFD700
  11661. * <span class="colorSwath" style="background: #FFD700;"></span>
  11662. *
  11663. * @constant
  11664. * @type {Color}
  11665. */
  11666. Color.GOLD = freezeObject(Color.fromCssColorString('#FFD700'));
  11667. /**
  11668. * An immutable Color instance initialized to CSS color #DAA520
  11669. * <span class="colorSwath" style="background: #DAA520;"></span>
  11670. *
  11671. * @constant
  11672. * @type {Color}
  11673. */
  11674. Color.GOLDENROD = freezeObject(Color.fromCssColorString('#DAA520'));
  11675. /**
  11676. * An immutable Color instance initialized to CSS color #808080
  11677. * <span class="colorSwath" style="background: #808080;"></span>
  11678. *
  11679. * @constant
  11680. * @type {Color}
  11681. */
  11682. Color.GRAY = freezeObject(Color.fromCssColorString('#808080'));
  11683. /**
  11684. * An immutable Color instance initialized to CSS color #008000
  11685. * <span class="colorSwath" style="background: #008000;"></span>
  11686. *
  11687. * @constant
  11688. * @type {Color}
  11689. */
  11690. Color.GREEN = freezeObject(Color.fromCssColorString('#008000'));
  11691. /**
  11692. * An immutable Color instance initialized to CSS color #ADFF2F
  11693. * <span class="colorSwath" style="background: #ADFF2F;"></span>
  11694. *
  11695. * @constant
  11696. * @type {Color}
  11697. */
  11698. Color.GREENYELLOW = freezeObject(Color.fromCssColorString('#ADFF2F'));
  11699. /**
  11700. * An immutable Color instance initialized to CSS color #808080
  11701. * <span class="colorSwath" style="background: #808080;"></span>
  11702. *
  11703. * @constant
  11704. * @type {Color}
  11705. */
  11706. Color.GREY = Color.GRAY;
  11707. /**
  11708. * An immutable Color instance initialized to CSS color #F0FFF0
  11709. * <span class="colorSwath" style="background: #F0FFF0;"></span>
  11710. *
  11711. * @constant
  11712. * @type {Color}
  11713. */
  11714. Color.HONEYDEW = freezeObject(Color.fromCssColorString('#F0FFF0'));
  11715. /**
  11716. * An immutable Color instance initialized to CSS color #FF69B4
  11717. * <span class="colorSwath" style="background: #FF69B4;"></span>
  11718. *
  11719. * @constant
  11720. * @type {Color}
  11721. */
  11722. Color.HOTPINK = freezeObject(Color.fromCssColorString('#FF69B4'));
  11723. /**
  11724. * An immutable Color instance initialized to CSS color #CD5C5C
  11725. * <span class="colorSwath" style="background: #CD5C5C;"></span>
  11726. *
  11727. * @constant
  11728. * @type {Color}
  11729. */
  11730. Color.INDIANRED = freezeObject(Color.fromCssColorString('#CD5C5C'));
  11731. /**
  11732. * An immutable Color instance initialized to CSS color #4B0082
  11733. * <span class="colorSwath" style="background: #4B0082;"></span>
  11734. *
  11735. * @constant
  11736. * @type {Color}
  11737. */
  11738. Color.INDIGO = freezeObject(Color.fromCssColorString('#4B0082'));
  11739. /**
  11740. * An immutable Color instance initialized to CSS color #FFFFF0
  11741. * <span class="colorSwath" style="background: #FFFFF0;"></span>
  11742. *
  11743. * @constant
  11744. * @type {Color}
  11745. */
  11746. Color.IVORY = freezeObject(Color.fromCssColorString('#FFFFF0'));
  11747. /**
  11748. * An immutable Color instance initialized to CSS color #F0E68C
  11749. * <span class="colorSwath" style="background: #F0E68C;"></span>
  11750. *
  11751. * @constant
  11752. * @type {Color}
  11753. */
  11754. Color.KHAKI = freezeObject(Color.fromCssColorString('#F0E68C'));
  11755. /**
  11756. * An immutable Color instance initialized to CSS color #E6E6FA
  11757. * <span class="colorSwath" style="background: #E6E6FA;"></span>
  11758. *
  11759. * @constant
  11760. * @type {Color}
  11761. */
  11762. Color.LAVENDER = freezeObject(Color.fromCssColorString('#E6E6FA'));
  11763. /**
  11764. * An immutable Color instance initialized to CSS color #FFF0F5
  11765. * <span class="colorSwath" style="background: #FFF0F5;"></span>
  11766. *
  11767. * @constant
  11768. * @type {Color}
  11769. */
  11770. Color.LAVENDAR_BLUSH = freezeObject(Color.fromCssColorString('#FFF0F5'));
  11771. /**
  11772. * An immutable Color instance initialized to CSS color #7CFC00
  11773. * <span class="colorSwath" style="background: #7CFC00;"></span>
  11774. *
  11775. * @constant
  11776. * @type {Color}
  11777. */
  11778. Color.LAWNGREEN = freezeObject(Color.fromCssColorString('#7CFC00'));
  11779. /**
  11780. * An immutable Color instance initialized to CSS color #FFFACD
  11781. * <span class="colorSwath" style="background: #FFFACD;"></span>
  11782. *
  11783. * @constant
  11784. * @type {Color}
  11785. */
  11786. Color.LEMONCHIFFON = freezeObject(Color.fromCssColorString('#FFFACD'));
  11787. /**
  11788. * An immutable Color instance initialized to CSS color #ADD8E6
  11789. * <span class="colorSwath" style="background: #ADD8E6;"></span>
  11790. *
  11791. * @constant
  11792. * @type {Color}
  11793. */
  11794. Color.LIGHTBLUE = freezeObject(Color.fromCssColorString('#ADD8E6'));
  11795. /**
  11796. * An immutable Color instance initialized to CSS color #F08080
  11797. * <span class="colorSwath" style="background: #F08080;"></span>
  11798. *
  11799. * @constant
  11800. * @type {Color}
  11801. */
  11802. Color.LIGHTCORAL = freezeObject(Color.fromCssColorString('#F08080'));
  11803. /**
  11804. * An immutable Color instance initialized to CSS color #E0FFFF
  11805. * <span class="colorSwath" style="background: #E0FFFF;"></span>
  11806. *
  11807. * @constant
  11808. * @type {Color}
  11809. */
  11810. Color.LIGHTCYAN = freezeObject(Color.fromCssColorString('#E0FFFF'));
  11811. /**
  11812. * An immutable Color instance initialized to CSS color #FAFAD2
  11813. * <span class="colorSwath" style="background: #FAFAD2;"></span>
  11814. *
  11815. * @constant
  11816. * @type {Color}
  11817. */
  11818. Color.LIGHTGOLDENRODYELLOW = freezeObject(Color.fromCssColorString('#FAFAD2'));
  11819. /**
  11820. * An immutable Color instance initialized to CSS color #D3D3D3
  11821. * <span class="colorSwath" style="background: #D3D3D3;"></span>
  11822. *
  11823. * @constant
  11824. * @type {Color}
  11825. */
  11826. Color.LIGHTGRAY = freezeObject(Color.fromCssColorString('#D3D3D3'));
  11827. /**
  11828. * An immutable Color instance initialized to CSS color #90EE90
  11829. * <span class="colorSwath" style="background: #90EE90;"></span>
  11830. *
  11831. * @constant
  11832. * @type {Color}
  11833. */
  11834. Color.LIGHTGREEN = freezeObject(Color.fromCssColorString('#90EE90'));
  11835. /**
  11836. * An immutable Color instance initialized to CSS color #D3D3D3
  11837. * <span class="colorSwath" style="background: #D3D3D3;"></span>
  11838. *
  11839. * @constant
  11840. * @type {Color}
  11841. */
  11842. Color.LIGHTGREY = Color.LIGHTGRAY;
  11843. /**
  11844. * An immutable Color instance initialized to CSS color #FFB6C1
  11845. * <span class="colorSwath" style="background: #FFB6C1;"></span>
  11846. *
  11847. * @constant
  11848. * @type {Color}
  11849. */
  11850. Color.LIGHTPINK = freezeObject(Color.fromCssColorString('#FFB6C1'));
  11851. /**
  11852. * An immutable Color instance initialized to CSS color #20B2AA
  11853. * <span class="colorSwath" style="background: #20B2AA;"></span>
  11854. *
  11855. * @constant
  11856. * @type {Color}
  11857. */
  11858. Color.LIGHTSEAGREEN = freezeObject(Color.fromCssColorString('#20B2AA'));
  11859. /**
  11860. * An immutable Color instance initialized to CSS color #87CEFA
  11861. * <span class="colorSwath" style="background: #87CEFA;"></span>
  11862. *
  11863. * @constant
  11864. * @type {Color}
  11865. */
  11866. Color.LIGHTSKYBLUE = freezeObject(Color.fromCssColorString('#87CEFA'));
  11867. /**
  11868. * An immutable Color instance initialized to CSS color #778899
  11869. * <span class="colorSwath" style="background: #778899;"></span>
  11870. *
  11871. * @constant
  11872. * @type {Color}
  11873. */
  11874. Color.LIGHTSLATEGRAY = freezeObject(Color.fromCssColorString('#778899'));
  11875. /**
  11876. * An immutable Color instance initialized to CSS color #778899
  11877. * <span class="colorSwath" style="background: #778899;"></span>
  11878. *
  11879. * @constant
  11880. * @type {Color}
  11881. */
  11882. Color.LIGHTSLATEGREY = Color.LIGHTSLATEGRAY;
  11883. /**
  11884. * An immutable Color instance initialized to CSS color #B0C4DE
  11885. * <span class="colorSwath" style="background: #B0C4DE;"></span>
  11886. *
  11887. * @constant
  11888. * @type {Color}
  11889. */
  11890. Color.LIGHTSTEELBLUE = freezeObject(Color.fromCssColorString('#B0C4DE'));
  11891. /**
  11892. * An immutable Color instance initialized to CSS color #FFFFE0
  11893. * <span class="colorSwath" style="background: #FFFFE0;"></span>
  11894. *
  11895. * @constant
  11896. * @type {Color}
  11897. */
  11898. Color.LIGHTYELLOW = freezeObject(Color.fromCssColorString('#FFFFE0'));
  11899. /**
  11900. * An immutable Color instance initialized to CSS color #00FF00
  11901. * <span class="colorSwath" style="background: #00FF00;"></span>
  11902. *
  11903. * @constant
  11904. * @type {Color}
  11905. */
  11906. Color.LIME = freezeObject(Color.fromCssColorString('#00FF00'));
  11907. /**
  11908. * An immutable Color instance initialized to CSS color #32CD32
  11909. * <span class="colorSwath" style="background: #32CD32;"></span>
  11910. *
  11911. * @constant
  11912. * @type {Color}
  11913. */
  11914. Color.LIMEGREEN = freezeObject(Color.fromCssColorString('#32CD32'));
  11915. /**
  11916. * An immutable Color instance initialized to CSS color #FAF0E6
  11917. * <span class="colorSwath" style="background: #FAF0E6;"></span>
  11918. *
  11919. * @constant
  11920. * @type {Color}
  11921. */
  11922. Color.LINEN = freezeObject(Color.fromCssColorString('#FAF0E6'));
  11923. /**
  11924. * An immutable Color instance initialized to CSS color #FF00FF
  11925. * <span class="colorSwath" style="background: #FF00FF;"></span>
  11926. *
  11927. * @constant
  11928. * @type {Color}
  11929. */
  11930. Color.MAGENTA = freezeObject(Color.fromCssColorString('#FF00FF'));
  11931. /**
  11932. * An immutable Color instance initialized to CSS color #800000
  11933. * <span class="colorSwath" style="background: #800000;"></span>
  11934. *
  11935. * @constant
  11936. * @type {Color}
  11937. */
  11938. Color.MAROON = freezeObject(Color.fromCssColorString('#800000'));
  11939. /**
  11940. * An immutable Color instance initialized to CSS color #66CDAA
  11941. * <span class="colorSwath" style="background: #66CDAA;"></span>
  11942. *
  11943. * @constant
  11944. * @type {Color}
  11945. */
  11946. Color.MEDIUMAQUAMARINE = freezeObject(Color.fromCssColorString('#66CDAA'));
  11947. /**
  11948. * An immutable Color instance initialized to CSS color #0000CD
  11949. * <span class="colorSwath" style="background: #0000CD;"></span>
  11950. *
  11951. * @constant
  11952. * @type {Color}
  11953. */
  11954. Color.MEDIUMBLUE = freezeObject(Color.fromCssColorString('#0000CD'));
  11955. /**
  11956. * An immutable Color instance initialized to CSS color #BA55D3
  11957. * <span class="colorSwath" style="background: #BA55D3;"></span>
  11958. *
  11959. * @constant
  11960. * @type {Color}
  11961. */
  11962. Color.MEDIUMORCHID = freezeObject(Color.fromCssColorString('#BA55D3'));
  11963. /**
  11964. * An immutable Color instance initialized to CSS color #9370DB
  11965. * <span class="colorSwath" style="background: #9370DB;"></span>
  11966. *
  11967. * @constant
  11968. * @type {Color}
  11969. */
  11970. Color.MEDIUMPURPLE = freezeObject(Color.fromCssColorString('#9370DB'));
  11971. /**
  11972. * An immutable Color instance initialized to CSS color #3CB371
  11973. * <span class="colorSwath" style="background: #3CB371;"></span>
  11974. *
  11975. * @constant
  11976. * @type {Color}
  11977. */
  11978. Color.MEDIUMSEAGREEN = freezeObject(Color.fromCssColorString('#3CB371'));
  11979. /**
  11980. * An immutable Color instance initialized to CSS color #7B68EE
  11981. * <span class="colorSwath" style="background: #7B68EE;"></span>
  11982. *
  11983. * @constant
  11984. * @type {Color}
  11985. */
  11986. Color.MEDIUMSLATEBLUE = freezeObject(Color.fromCssColorString('#7B68EE'));
  11987. /**
  11988. * An immutable Color instance initialized to CSS color #00FA9A
  11989. * <span class="colorSwath" style="background: #00FA9A;"></span>
  11990. *
  11991. * @constant
  11992. * @type {Color}
  11993. */
  11994. Color.MEDIUMSPRINGGREEN = freezeObject(Color.fromCssColorString('#00FA9A'));
  11995. /**
  11996. * An immutable Color instance initialized to CSS color #48D1CC
  11997. * <span class="colorSwath" style="background: #48D1CC;"></span>
  11998. *
  11999. * @constant
  12000. * @type {Color}
  12001. */
  12002. Color.MEDIUMTURQUOISE = freezeObject(Color.fromCssColorString('#48D1CC'));
  12003. /**
  12004. * An immutable Color instance initialized to CSS color #C71585
  12005. * <span class="colorSwath" style="background: #C71585;"></span>
  12006. *
  12007. * @constant
  12008. * @type {Color}
  12009. */
  12010. Color.MEDIUMVIOLETRED = freezeObject(Color.fromCssColorString('#C71585'));
  12011. /**
  12012. * An immutable Color instance initialized to CSS color #191970
  12013. * <span class="colorSwath" style="background: #191970;"></span>
  12014. *
  12015. * @constant
  12016. * @type {Color}
  12017. */
  12018. Color.MIDNIGHTBLUE = freezeObject(Color.fromCssColorString('#191970'));
  12019. /**
  12020. * An immutable Color instance initialized to CSS color #F5FFFA
  12021. * <span class="colorSwath" style="background: #F5FFFA;"></span>
  12022. *
  12023. * @constant
  12024. * @type {Color}
  12025. */
  12026. Color.MINTCREAM = freezeObject(Color.fromCssColorString('#F5FFFA'));
  12027. /**
  12028. * An immutable Color instance initialized to CSS color #FFE4E1
  12029. * <span class="colorSwath" style="background: #FFE4E1;"></span>
  12030. *
  12031. * @constant
  12032. * @type {Color}
  12033. */
  12034. Color.MISTYROSE = freezeObject(Color.fromCssColorString('#FFE4E1'));
  12035. /**
  12036. * An immutable Color instance initialized to CSS color #FFE4B5
  12037. * <span class="colorSwath" style="background: #FFE4B5;"></span>
  12038. *
  12039. * @constant
  12040. * @type {Color}
  12041. */
  12042. Color.MOCCASIN = freezeObject(Color.fromCssColorString('#FFE4B5'));
  12043. /**
  12044. * An immutable Color instance initialized to CSS color #FFDEAD
  12045. * <span class="colorSwath" style="background: #FFDEAD;"></span>
  12046. *
  12047. * @constant
  12048. * @type {Color}
  12049. */
  12050. Color.NAVAJOWHITE = freezeObject(Color.fromCssColorString('#FFDEAD'));
  12051. /**
  12052. * An immutable Color instance initialized to CSS color #000080
  12053. * <span class="colorSwath" style="background: #000080;"></span>
  12054. *
  12055. * @constant
  12056. * @type {Color}
  12057. */
  12058. Color.NAVY = freezeObject(Color.fromCssColorString('#000080'));
  12059. /**
  12060. * An immutable Color instance initialized to CSS color #FDF5E6
  12061. * <span class="colorSwath" style="background: #FDF5E6;"></span>
  12062. *
  12063. * @constant
  12064. * @type {Color}
  12065. */
  12066. Color.OLDLACE = freezeObject(Color.fromCssColorString('#FDF5E6'));
  12067. /**
  12068. * An immutable Color instance initialized to CSS color #808000
  12069. * <span class="colorSwath" style="background: #808000;"></span>
  12070. *
  12071. * @constant
  12072. * @type {Color}
  12073. */
  12074. Color.OLIVE = freezeObject(Color.fromCssColorString('#808000'));
  12075. /**
  12076. * An immutable Color instance initialized to CSS color #6B8E23
  12077. * <span class="colorSwath" style="background: #6B8E23;"></span>
  12078. *
  12079. * @constant
  12080. * @type {Color}
  12081. */
  12082. Color.OLIVEDRAB = freezeObject(Color.fromCssColorString('#6B8E23'));
  12083. /**
  12084. * An immutable Color instance initialized to CSS color #FFA500
  12085. * <span class="colorSwath" style="background: #FFA500;"></span>
  12086. *
  12087. * @constant
  12088. * @type {Color}
  12089. */
  12090. Color.ORANGE = freezeObject(Color.fromCssColorString('#FFA500'));
  12091. /**
  12092. * An immutable Color instance initialized to CSS color #FF4500
  12093. * <span class="colorSwath" style="background: #FF4500;"></span>
  12094. *
  12095. * @constant
  12096. * @type {Color}
  12097. */
  12098. Color.ORANGERED = freezeObject(Color.fromCssColorString('#FF4500'));
  12099. /**
  12100. * An immutable Color instance initialized to CSS color #DA70D6
  12101. * <span class="colorSwath" style="background: #DA70D6;"></span>
  12102. *
  12103. * @constant
  12104. * @type {Color}
  12105. */
  12106. Color.ORCHID = freezeObject(Color.fromCssColorString('#DA70D6'));
  12107. /**
  12108. * An immutable Color instance initialized to CSS color #EEE8AA
  12109. * <span class="colorSwath" style="background: #EEE8AA;"></span>
  12110. *
  12111. * @constant
  12112. * @type {Color}
  12113. */
  12114. Color.PALEGOLDENROD = freezeObject(Color.fromCssColorString('#EEE8AA'));
  12115. /**
  12116. * An immutable Color instance initialized to CSS color #98FB98
  12117. * <span class="colorSwath" style="background: #98FB98;"></span>
  12118. *
  12119. * @constant
  12120. * @type {Color}
  12121. */
  12122. Color.PALEGREEN = freezeObject(Color.fromCssColorString('#98FB98'));
  12123. /**
  12124. * An immutable Color instance initialized to CSS color #AFEEEE
  12125. * <span class="colorSwath" style="background: #AFEEEE;"></span>
  12126. *
  12127. * @constant
  12128. * @type {Color}
  12129. */
  12130. Color.PALETURQUOISE = freezeObject(Color.fromCssColorString('#AFEEEE'));
  12131. /**
  12132. * An immutable Color instance initialized to CSS color #DB7093
  12133. * <span class="colorSwath" style="background: #DB7093;"></span>
  12134. *
  12135. * @constant
  12136. * @type {Color}
  12137. */
  12138. Color.PALEVIOLETRED = freezeObject(Color.fromCssColorString('#DB7093'));
  12139. /**
  12140. * An immutable Color instance initialized to CSS color #FFEFD5
  12141. * <span class="colorSwath" style="background: #FFEFD5;"></span>
  12142. *
  12143. * @constant
  12144. * @type {Color}
  12145. */
  12146. Color.PAPAYAWHIP = freezeObject(Color.fromCssColorString('#FFEFD5'));
  12147. /**
  12148. * An immutable Color instance initialized to CSS color #FFDAB9
  12149. * <span class="colorSwath" style="background: #FFDAB9;"></span>
  12150. *
  12151. * @constant
  12152. * @type {Color}
  12153. */
  12154. Color.PEACHPUFF = freezeObject(Color.fromCssColorString('#FFDAB9'));
  12155. /**
  12156. * An immutable Color instance initialized to CSS color #CD853F
  12157. * <span class="colorSwath" style="background: #CD853F;"></span>
  12158. *
  12159. * @constant
  12160. * @type {Color}
  12161. */
  12162. Color.PERU = freezeObject(Color.fromCssColorString('#CD853F'));
  12163. /**
  12164. * An immutable Color instance initialized to CSS color #FFC0CB
  12165. * <span class="colorSwath" style="background: #FFC0CB;"></span>
  12166. *
  12167. * @constant
  12168. * @type {Color}
  12169. */
  12170. Color.PINK = freezeObject(Color.fromCssColorString('#FFC0CB'));
  12171. /**
  12172. * An immutable Color instance initialized to CSS color #DDA0DD
  12173. * <span class="colorSwath" style="background: #DDA0DD;"></span>
  12174. *
  12175. * @constant
  12176. * @type {Color}
  12177. */
  12178. Color.PLUM = freezeObject(Color.fromCssColorString('#DDA0DD'));
  12179. /**
  12180. * An immutable Color instance initialized to CSS color #B0E0E6
  12181. * <span class="colorSwath" style="background: #B0E0E6;"></span>
  12182. *
  12183. * @constant
  12184. * @type {Color}
  12185. */
  12186. Color.POWDERBLUE = freezeObject(Color.fromCssColorString('#B0E0E6'));
  12187. /**
  12188. * An immutable Color instance initialized to CSS color #800080
  12189. * <span class="colorSwath" style="background: #800080;"></span>
  12190. *
  12191. * @constant
  12192. * @type {Color}
  12193. */
  12194. Color.PURPLE = freezeObject(Color.fromCssColorString('#800080'));
  12195. /**
  12196. * An immutable Color instance initialized to CSS color #FF0000
  12197. * <span class="colorSwath" style="background: #FF0000;"></span>
  12198. *
  12199. * @constant
  12200. * @type {Color}
  12201. */
  12202. Color.RED = freezeObject(Color.fromCssColorString('#FF0000'));
  12203. /**
  12204. * An immutable Color instance initialized to CSS color #BC8F8F
  12205. * <span class="colorSwath" style="background: #BC8F8F;"></span>
  12206. *
  12207. * @constant
  12208. * @type {Color}
  12209. */
  12210. Color.ROSYBROWN = freezeObject(Color.fromCssColorString('#BC8F8F'));
  12211. /**
  12212. * An immutable Color instance initialized to CSS color #4169E1
  12213. * <span class="colorSwath" style="background: #4169E1;"></span>
  12214. *
  12215. * @constant
  12216. * @type {Color}
  12217. */
  12218. Color.ROYALBLUE = freezeObject(Color.fromCssColorString('#4169E1'));
  12219. /**
  12220. * An immutable Color instance initialized to CSS color #8B4513
  12221. * <span class="colorSwath" style="background: #8B4513;"></span>
  12222. *
  12223. * @constant
  12224. * @type {Color}
  12225. */
  12226. Color.SADDLEBROWN = freezeObject(Color.fromCssColorString('#8B4513'));
  12227. /**
  12228. * An immutable Color instance initialized to CSS color #FA8072
  12229. * <span class="colorSwath" style="background: #FA8072;"></span>
  12230. *
  12231. * @constant
  12232. * @type {Color}
  12233. */
  12234. Color.SALMON = freezeObject(Color.fromCssColorString('#FA8072'));
  12235. /**
  12236. * An immutable Color instance initialized to CSS color #F4A460
  12237. * <span class="colorSwath" style="background: #F4A460;"></span>
  12238. *
  12239. * @constant
  12240. * @type {Color}
  12241. */
  12242. Color.SANDYBROWN = freezeObject(Color.fromCssColorString('#F4A460'));
  12243. /**
  12244. * An immutable Color instance initialized to CSS color #2E8B57
  12245. * <span class="colorSwath" style="background: #2E8B57;"></span>
  12246. *
  12247. * @constant
  12248. * @type {Color}
  12249. */
  12250. Color.SEAGREEN = freezeObject(Color.fromCssColorString('#2E8B57'));
  12251. /**
  12252. * An immutable Color instance initialized to CSS color #FFF5EE
  12253. * <span class="colorSwath" style="background: #FFF5EE;"></span>
  12254. *
  12255. * @constant
  12256. * @type {Color}
  12257. */
  12258. Color.SEASHELL = freezeObject(Color.fromCssColorString('#FFF5EE'));
  12259. /**
  12260. * An immutable Color instance initialized to CSS color #A0522D
  12261. * <span class="colorSwath" style="background: #A0522D;"></span>
  12262. *
  12263. * @constant
  12264. * @type {Color}
  12265. */
  12266. Color.SIENNA = freezeObject(Color.fromCssColorString('#A0522D'));
  12267. /**
  12268. * An immutable Color instance initialized to CSS color #C0C0C0
  12269. * <span class="colorSwath" style="background: #C0C0C0;"></span>
  12270. *
  12271. * @constant
  12272. * @type {Color}
  12273. */
  12274. Color.SILVER = freezeObject(Color.fromCssColorString('#C0C0C0'));
  12275. /**
  12276. * An immutable Color instance initialized to CSS color #87CEEB
  12277. * <span class="colorSwath" style="background: #87CEEB;"></span>
  12278. *
  12279. * @constant
  12280. * @type {Color}
  12281. */
  12282. Color.SKYBLUE = freezeObject(Color.fromCssColorString('#87CEEB'));
  12283. /**
  12284. * An immutable Color instance initialized to CSS color #6A5ACD
  12285. * <span class="colorSwath" style="background: #6A5ACD;"></span>
  12286. *
  12287. * @constant
  12288. * @type {Color}
  12289. */
  12290. Color.SLATEBLUE = freezeObject(Color.fromCssColorString('#6A5ACD'));
  12291. /**
  12292. * An immutable Color instance initialized to CSS color #708090
  12293. * <span class="colorSwath" style="background: #708090;"></span>
  12294. *
  12295. * @constant
  12296. * @type {Color}
  12297. */
  12298. Color.SLATEGRAY = freezeObject(Color.fromCssColorString('#708090'));
  12299. /**
  12300. * An immutable Color instance initialized to CSS color #708090
  12301. * <span class="colorSwath" style="background: #708090;"></span>
  12302. *
  12303. * @constant
  12304. * @type {Color}
  12305. */
  12306. Color.SLATEGREY = Color.SLATEGRAY;
  12307. /**
  12308. * An immutable Color instance initialized to CSS color #FFFAFA
  12309. * <span class="colorSwath" style="background: #FFFAFA;"></span>
  12310. *
  12311. * @constant
  12312. * @type {Color}
  12313. */
  12314. Color.SNOW = freezeObject(Color.fromCssColorString('#FFFAFA'));
  12315. /**
  12316. * An immutable Color instance initialized to CSS color #00FF7F
  12317. * <span class="colorSwath" style="background: #00FF7F;"></span>
  12318. *
  12319. * @constant
  12320. * @type {Color}
  12321. */
  12322. Color.SPRINGGREEN = freezeObject(Color.fromCssColorString('#00FF7F'));
  12323. /**
  12324. * An immutable Color instance initialized to CSS color #4682B4
  12325. * <span class="colorSwath" style="background: #4682B4;"></span>
  12326. *
  12327. * @constant
  12328. * @type {Color}
  12329. */
  12330. Color.STEELBLUE = freezeObject(Color.fromCssColorString('#4682B4'));
  12331. /**
  12332. * An immutable Color instance initialized to CSS color #D2B48C
  12333. * <span class="colorSwath" style="background: #D2B48C;"></span>
  12334. *
  12335. * @constant
  12336. * @type {Color}
  12337. */
  12338. Color.TAN = freezeObject(Color.fromCssColorString('#D2B48C'));
  12339. /**
  12340. * An immutable Color instance initialized to CSS color #008080
  12341. * <span class="colorSwath" style="background: #008080;"></span>
  12342. *
  12343. * @constant
  12344. * @type {Color}
  12345. */
  12346. Color.TEAL = freezeObject(Color.fromCssColorString('#008080'));
  12347. /**
  12348. * An immutable Color instance initialized to CSS color #D8BFD8
  12349. * <span class="colorSwath" style="background: #D8BFD8;"></span>
  12350. *
  12351. * @constant
  12352. * @type {Color}
  12353. */
  12354. Color.THISTLE = freezeObject(Color.fromCssColorString('#D8BFD8'));
  12355. /**
  12356. * An immutable Color instance initialized to CSS color #FF6347
  12357. * <span class="colorSwath" style="background: #FF6347;"></span>
  12358. *
  12359. * @constant
  12360. * @type {Color}
  12361. */
  12362. Color.TOMATO = freezeObject(Color.fromCssColorString('#FF6347'));
  12363. /**
  12364. * An immutable Color instance initialized to CSS color #40E0D0
  12365. * <span class="colorSwath" style="background: #40E0D0;"></span>
  12366. *
  12367. * @constant
  12368. * @type {Color}
  12369. */
  12370. Color.TURQUOISE = freezeObject(Color.fromCssColorString('#40E0D0'));
  12371. /**
  12372. * An immutable Color instance initialized to CSS color #EE82EE
  12373. * <span class="colorSwath" style="background: #EE82EE;"></span>
  12374. *
  12375. * @constant
  12376. * @type {Color}
  12377. */
  12378. Color.VIOLET = freezeObject(Color.fromCssColorString('#EE82EE'));
  12379. /**
  12380. * An immutable Color instance initialized to CSS color #F5DEB3
  12381. * <span class="colorSwath" style="background: #F5DEB3;"></span>
  12382. *
  12383. * @constant
  12384. * @type {Color}
  12385. */
  12386. Color.WHEAT = freezeObject(Color.fromCssColorString('#F5DEB3'));
  12387. /**
  12388. * An immutable Color instance initialized to CSS color #FFFFFF
  12389. * <span class="colorSwath" style="background: #FFFFFF;"></span>
  12390. *
  12391. * @constant
  12392. * @type {Color}
  12393. */
  12394. Color.WHITE = freezeObject(Color.fromCssColorString('#FFFFFF'));
  12395. /**
  12396. * An immutable Color instance initialized to CSS color #F5F5F5
  12397. * <span class="colorSwath" style="background: #F5F5F5;"></span>
  12398. *
  12399. * @constant
  12400. * @type {Color}
  12401. */
  12402. Color.WHITESMOKE = freezeObject(Color.fromCssColorString('#F5F5F5'));
  12403. /**
  12404. * An immutable Color instance initialized to CSS color #FFFF00
  12405. * <span class="colorSwath" style="background: #FFFF00;"></span>
  12406. *
  12407. * @constant
  12408. * @type {Color}
  12409. */
  12410. Color.YELLOW = freezeObject(Color.fromCssColorString('#FFFF00'));
  12411. /**
  12412. * An immutable Color instance initialized to CSS color #9ACD32
  12413. * <span class="colorSwath" style="background: #9ACD32;"></span>
  12414. *
  12415. * @constant
  12416. * @type {Color}
  12417. */
  12418. Color.YELLOWGREEN = freezeObject(Color.fromCssColorString('#9ACD32'));
  12419. /**
  12420. * An immutable Color instance initialized to CSS transparent.
  12421. * <span class="colorSwath" style="background: transparent;"></span>
  12422. *
  12423. * @constant
  12424. * @type {Color}
  12425. */
  12426. Color.TRANSPARENT = freezeObject(new Color(0, 0, 0, 0));
  12427. return Color;
  12428. });
  12429. /*global define*/
  12430. define('Core/WebGLConstants',[
  12431. './freezeObject'
  12432. ], function(
  12433. freezeObject) {
  12434. 'use strict';
  12435. /**
  12436. * Enum containing WebGL Constant values by name.
  12437. * for use without an active WebGL context, or in cases where certain constants are unavailable using the WebGL context
  12438. * (For example, in [Safari 9]{@link https://github.com/AnalyticalGraphicsInc/cesium/issues/2989}).
  12439. *
  12440. * These match the constants from the [WebGL 1.0]{@link https://www.khronos.org/registry/webgl/specs/latest/1.0/}
  12441. * and [WebGL 2.0]{@link https://www.khronos.org/registry/webgl/specs/latest/2.0/}
  12442. * specifications.
  12443. *
  12444. * @exports WebGLConstants
  12445. */
  12446. var WebGLConstants = {
  12447. DEPTH_BUFFER_BIT : 0x00000100,
  12448. STENCIL_BUFFER_BIT : 0x00000400,
  12449. COLOR_BUFFER_BIT : 0x00004000,
  12450. POINTS : 0x0000,
  12451. LINES : 0x0001,
  12452. LINE_LOOP : 0x0002,
  12453. LINE_STRIP : 0x0003,
  12454. TRIANGLES : 0x0004,
  12455. TRIANGLE_STRIP : 0x0005,
  12456. TRIANGLE_FAN : 0x0006,
  12457. ZERO : 0,
  12458. ONE : 1,
  12459. SRC_COLOR : 0x0300,
  12460. ONE_MINUS_SRC_COLOR : 0x0301,
  12461. SRC_ALPHA : 0x0302,
  12462. ONE_MINUS_SRC_ALPHA : 0x0303,
  12463. DST_ALPHA : 0x0304,
  12464. ONE_MINUS_DST_ALPHA : 0x0305,
  12465. DST_COLOR : 0x0306,
  12466. ONE_MINUS_DST_COLOR : 0x0307,
  12467. SRC_ALPHA_SATURATE : 0x0308,
  12468. FUNC_ADD : 0x8006,
  12469. BLEND_EQUATION : 0x8009,
  12470. BLEND_EQUATION_RGB : 0x8009, // same as BLEND_EQUATION
  12471. BLEND_EQUATION_ALPHA : 0x883D,
  12472. FUNC_SUBTRACT : 0x800A,
  12473. FUNC_REVERSE_SUBTRACT : 0x800B,
  12474. BLEND_DST_RGB : 0x80C8,
  12475. BLEND_SRC_RGB : 0x80C9,
  12476. BLEND_DST_ALPHA : 0x80CA,
  12477. BLEND_SRC_ALPHA : 0x80CB,
  12478. CONSTANT_COLOR : 0x8001,
  12479. ONE_MINUS_CONSTANT_COLOR : 0x8002,
  12480. CONSTANT_ALPHA : 0x8003,
  12481. ONE_MINUS_CONSTANT_ALPHA : 0x8004,
  12482. BLEND_COLOR : 0x8005,
  12483. ARRAY_BUFFER : 0x8892,
  12484. ELEMENT_ARRAY_BUFFER : 0x8893,
  12485. ARRAY_BUFFER_BINDING : 0x8894,
  12486. ELEMENT_ARRAY_BUFFER_BINDING : 0x8895,
  12487. STREAM_DRAW : 0x88E0,
  12488. STATIC_DRAW : 0x88E4,
  12489. DYNAMIC_DRAW : 0x88E8,
  12490. BUFFER_SIZE : 0x8764,
  12491. BUFFER_USAGE : 0x8765,
  12492. CURRENT_VERTEX_ATTRIB : 0x8626,
  12493. FRONT : 0x0404,
  12494. BACK : 0x0405,
  12495. FRONT_AND_BACK : 0x0408,
  12496. CULL_FACE : 0x0B44,
  12497. BLEND : 0x0BE2,
  12498. DITHER : 0x0BD0,
  12499. STENCIL_TEST : 0x0B90,
  12500. DEPTH_TEST : 0x0B71,
  12501. SCISSOR_TEST : 0x0C11,
  12502. POLYGON_OFFSET_FILL : 0x8037,
  12503. SAMPLE_ALPHA_TO_COVERAGE : 0x809E,
  12504. SAMPLE_COVERAGE : 0x80A0,
  12505. NO_ERROR : 0,
  12506. INVALID_ENUM : 0x0500,
  12507. INVALID_VALUE : 0x0501,
  12508. INVALID_OPERATION : 0x0502,
  12509. OUT_OF_MEMORY : 0x0505,
  12510. CW : 0x0900,
  12511. CCW : 0x0901,
  12512. LINE_WIDTH : 0x0B21,
  12513. ALIASED_POINT_SIZE_RANGE : 0x846D,
  12514. ALIASED_LINE_WIDTH_RANGE : 0x846E,
  12515. CULL_FACE_MODE : 0x0B45,
  12516. FRONT_FACE : 0x0B46,
  12517. DEPTH_RANGE : 0x0B70,
  12518. DEPTH_WRITEMASK : 0x0B72,
  12519. DEPTH_CLEAR_VALUE : 0x0B73,
  12520. DEPTH_FUNC : 0x0B74,
  12521. STENCIL_CLEAR_VALUE : 0x0B91,
  12522. STENCIL_FUNC : 0x0B92,
  12523. STENCIL_FAIL : 0x0B94,
  12524. STENCIL_PASS_DEPTH_FAIL : 0x0B95,
  12525. STENCIL_PASS_DEPTH_PASS : 0x0B96,
  12526. STENCIL_REF : 0x0B97,
  12527. STENCIL_VALUE_MASK : 0x0B93,
  12528. STENCIL_WRITEMASK : 0x0B98,
  12529. STENCIL_BACK_FUNC : 0x8800,
  12530. STENCIL_BACK_FAIL : 0x8801,
  12531. STENCIL_BACK_PASS_DEPTH_FAIL : 0x8802,
  12532. STENCIL_BACK_PASS_DEPTH_PASS : 0x8803,
  12533. STENCIL_BACK_REF : 0x8CA3,
  12534. STENCIL_BACK_VALUE_MASK : 0x8CA4,
  12535. STENCIL_BACK_WRITEMASK : 0x8CA5,
  12536. VIEWPORT : 0x0BA2,
  12537. SCISSOR_BOX : 0x0C10,
  12538. COLOR_CLEAR_VALUE : 0x0C22,
  12539. COLOR_WRITEMASK : 0x0C23,
  12540. UNPACK_ALIGNMENT : 0x0CF5,
  12541. PACK_ALIGNMENT : 0x0D05,
  12542. MAX_TEXTURE_SIZE : 0x0D33,
  12543. MAX_VIEWPORT_DIMS : 0x0D3A,
  12544. SUBPIXEL_BITS : 0x0D50,
  12545. RED_BITS : 0x0D52,
  12546. GREEN_BITS : 0x0D53,
  12547. BLUE_BITS : 0x0D54,
  12548. ALPHA_BITS : 0x0D55,
  12549. DEPTH_BITS : 0x0D56,
  12550. STENCIL_BITS : 0x0D57,
  12551. POLYGON_OFFSET_UNITS : 0x2A00,
  12552. POLYGON_OFFSET_FACTOR : 0x8038,
  12553. TEXTURE_BINDING_2D : 0x8069,
  12554. SAMPLE_BUFFERS : 0x80A8,
  12555. SAMPLES : 0x80A9,
  12556. SAMPLE_COVERAGE_VALUE : 0x80AA,
  12557. SAMPLE_COVERAGE_INVERT : 0x80AB,
  12558. COMPRESSED_TEXTURE_FORMATS : 0x86A3,
  12559. DONT_CARE : 0x1100,
  12560. FASTEST : 0x1101,
  12561. NICEST : 0x1102,
  12562. GENERATE_MIPMAP_HINT : 0x8192,
  12563. BYTE : 0x1400,
  12564. UNSIGNED_BYTE : 0x1401,
  12565. SHORT : 0x1402,
  12566. UNSIGNED_SHORT : 0x1403,
  12567. INT : 0x1404,
  12568. UNSIGNED_INT : 0x1405,
  12569. FLOAT : 0x1406,
  12570. DEPTH_COMPONENT : 0x1902,
  12571. ALPHA : 0x1906,
  12572. RGB : 0x1907,
  12573. RGBA : 0x1908,
  12574. LUMINANCE : 0x1909,
  12575. LUMINANCE_ALPHA : 0x190A,
  12576. UNSIGNED_SHORT_4_4_4_4 : 0x8033,
  12577. UNSIGNED_SHORT_5_5_5_1 : 0x8034,
  12578. UNSIGNED_SHORT_5_6_5 : 0x8363,
  12579. FRAGMENT_SHADER : 0x8B30,
  12580. VERTEX_SHADER : 0x8B31,
  12581. MAX_VERTEX_ATTRIBS : 0x8869,
  12582. MAX_VERTEX_UNIFORM_VECTORS : 0x8DFB,
  12583. MAX_VARYING_VECTORS : 0x8DFC,
  12584. MAX_COMBINED_TEXTURE_IMAGE_UNITS : 0x8B4D,
  12585. MAX_VERTEX_TEXTURE_IMAGE_UNITS : 0x8B4C,
  12586. MAX_TEXTURE_IMAGE_UNITS : 0x8872,
  12587. MAX_FRAGMENT_UNIFORM_VECTORS : 0x8DFD,
  12588. SHADER_TYPE : 0x8B4F,
  12589. DELETE_STATUS : 0x8B80,
  12590. LINK_STATUS : 0x8B82,
  12591. VALIDATE_STATUS : 0x8B83,
  12592. ATTACHED_SHADERS : 0x8B85,
  12593. ACTIVE_UNIFORMS : 0x8B86,
  12594. ACTIVE_ATTRIBUTES : 0x8B89,
  12595. SHADING_LANGUAGE_VERSION : 0x8B8C,
  12596. CURRENT_PROGRAM : 0x8B8D,
  12597. NEVER : 0x0200,
  12598. LESS : 0x0201,
  12599. EQUAL : 0x0202,
  12600. LEQUAL : 0x0203,
  12601. GREATER : 0x0204,
  12602. NOTEQUAL : 0x0205,
  12603. GEQUAL : 0x0206,
  12604. ALWAYS : 0x0207,
  12605. KEEP : 0x1E00,
  12606. REPLACE : 0x1E01,
  12607. INCR : 0x1E02,
  12608. DECR : 0x1E03,
  12609. INVERT : 0x150A,
  12610. INCR_WRAP : 0x8507,
  12611. DECR_WRAP : 0x8508,
  12612. VENDOR : 0x1F00,
  12613. RENDERER : 0x1F01,
  12614. VERSION : 0x1F02,
  12615. NEAREST : 0x2600,
  12616. LINEAR : 0x2601,
  12617. NEAREST_MIPMAP_NEAREST : 0x2700,
  12618. LINEAR_MIPMAP_NEAREST : 0x2701,
  12619. NEAREST_MIPMAP_LINEAR : 0x2702,
  12620. LINEAR_MIPMAP_LINEAR : 0x2703,
  12621. TEXTURE_MAG_FILTER : 0x2800,
  12622. TEXTURE_MIN_FILTER : 0x2801,
  12623. TEXTURE_WRAP_S : 0x2802,
  12624. TEXTURE_WRAP_T : 0x2803,
  12625. TEXTURE_2D : 0x0DE1,
  12626. TEXTURE : 0x1702,
  12627. TEXTURE_CUBE_MAP : 0x8513,
  12628. TEXTURE_BINDING_CUBE_MAP : 0x8514,
  12629. TEXTURE_CUBE_MAP_POSITIVE_X : 0x8515,
  12630. TEXTURE_CUBE_MAP_NEGATIVE_X : 0x8516,
  12631. TEXTURE_CUBE_MAP_POSITIVE_Y : 0x8517,
  12632. TEXTURE_CUBE_MAP_NEGATIVE_Y : 0x8518,
  12633. TEXTURE_CUBE_MAP_POSITIVE_Z : 0x8519,
  12634. TEXTURE_CUBE_MAP_NEGATIVE_Z : 0x851A,
  12635. MAX_CUBE_MAP_TEXTURE_SIZE : 0x851C,
  12636. TEXTURE0 : 0x84C0,
  12637. TEXTURE1 : 0x84C1,
  12638. TEXTURE2 : 0x84C2,
  12639. TEXTURE3 : 0x84C3,
  12640. TEXTURE4 : 0x84C4,
  12641. TEXTURE5 : 0x84C5,
  12642. TEXTURE6 : 0x84C6,
  12643. TEXTURE7 : 0x84C7,
  12644. TEXTURE8 : 0x84C8,
  12645. TEXTURE9 : 0x84C9,
  12646. TEXTURE10 : 0x84CA,
  12647. TEXTURE11 : 0x84CB,
  12648. TEXTURE12 : 0x84CC,
  12649. TEXTURE13 : 0x84CD,
  12650. TEXTURE14 : 0x84CE,
  12651. TEXTURE15 : 0x84CF,
  12652. TEXTURE16 : 0x84D0,
  12653. TEXTURE17 : 0x84D1,
  12654. TEXTURE18 : 0x84D2,
  12655. TEXTURE19 : 0x84D3,
  12656. TEXTURE20 : 0x84D4,
  12657. TEXTURE21 : 0x84D5,
  12658. TEXTURE22 : 0x84D6,
  12659. TEXTURE23 : 0x84D7,
  12660. TEXTURE24 : 0x84D8,
  12661. TEXTURE25 : 0x84D9,
  12662. TEXTURE26 : 0x84DA,
  12663. TEXTURE27 : 0x84DB,
  12664. TEXTURE28 : 0x84DC,
  12665. TEXTURE29 : 0x84DD,
  12666. TEXTURE30 : 0x84DE,
  12667. TEXTURE31 : 0x84DF,
  12668. ACTIVE_TEXTURE : 0x84E0,
  12669. REPEAT : 0x2901,
  12670. CLAMP_TO_EDGE : 0x812F,
  12671. MIRRORED_REPEAT : 0x8370,
  12672. FLOAT_VEC2 : 0x8B50,
  12673. FLOAT_VEC3 : 0x8B51,
  12674. FLOAT_VEC4 : 0x8B52,
  12675. INT_VEC2 : 0x8B53,
  12676. INT_VEC3 : 0x8B54,
  12677. INT_VEC4 : 0x8B55,
  12678. BOOL : 0x8B56,
  12679. BOOL_VEC2 : 0x8B57,
  12680. BOOL_VEC3 : 0x8B58,
  12681. BOOL_VEC4 : 0x8B59,
  12682. FLOAT_MAT2 : 0x8B5A,
  12683. FLOAT_MAT3 : 0x8B5B,
  12684. FLOAT_MAT4 : 0x8B5C,
  12685. SAMPLER_2D : 0x8B5E,
  12686. SAMPLER_CUBE : 0x8B60,
  12687. VERTEX_ATTRIB_ARRAY_ENABLED : 0x8622,
  12688. VERTEX_ATTRIB_ARRAY_SIZE : 0x8623,
  12689. VERTEX_ATTRIB_ARRAY_STRIDE : 0x8624,
  12690. VERTEX_ATTRIB_ARRAY_TYPE : 0x8625,
  12691. VERTEX_ATTRIB_ARRAY_NORMALIZED : 0x886A,
  12692. VERTEX_ATTRIB_ARRAY_POINTER : 0x8645,
  12693. VERTEX_ATTRIB_ARRAY_BUFFER_BINDING : 0x889F,
  12694. IMPLEMENTATION_COLOR_READ_TYPE : 0x8B9A,
  12695. IMPLEMENTATION_COLOR_READ_FORMAT : 0x8B9B,
  12696. COMPILE_STATUS : 0x8B81,
  12697. LOW_FLOAT : 0x8DF0,
  12698. MEDIUM_FLOAT : 0x8DF1,
  12699. HIGH_FLOAT : 0x8DF2,
  12700. LOW_INT : 0x8DF3,
  12701. MEDIUM_INT : 0x8DF4,
  12702. HIGH_INT : 0x8DF5,
  12703. FRAMEBUFFER : 0x8D40,
  12704. RENDERBUFFER : 0x8D41,
  12705. RGBA4 : 0x8056,
  12706. RGB5_A1 : 0x8057,
  12707. RGB565 : 0x8D62,
  12708. DEPTH_COMPONENT16 : 0x81A5,
  12709. STENCIL_INDEX : 0x1901,
  12710. STENCIL_INDEX8 : 0x8D48,
  12711. DEPTH_STENCIL : 0x84F9,
  12712. RENDERBUFFER_WIDTH : 0x8D42,
  12713. RENDERBUFFER_HEIGHT : 0x8D43,
  12714. RENDERBUFFER_INTERNAL_FORMAT : 0x8D44,
  12715. RENDERBUFFER_RED_SIZE : 0x8D50,
  12716. RENDERBUFFER_GREEN_SIZE : 0x8D51,
  12717. RENDERBUFFER_BLUE_SIZE : 0x8D52,
  12718. RENDERBUFFER_ALPHA_SIZE : 0x8D53,
  12719. RENDERBUFFER_DEPTH_SIZE : 0x8D54,
  12720. RENDERBUFFER_STENCIL_SIZE : 0x8D55,
  12721. FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE : 0x8CD0,
  12722. FRAMEBUFFER_ATTACHMENT_OBJECT_NAME : 0x8CD1,
  12723. FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL : 0x8CD2,
  12724. FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE : 0x8CD3,
  12725. COLOR_ATTACHMENT0 : 0x8CE0,
  12726. DEPTH_ATTACHMENT : 0x8D00,
  12727. STENCIL_ATTACHMENT : 0x8D20,
  12728. DEPTH_STENCIL_ATTACHMENT : 0x821A,
  12729. NONE : 0,
  12730. FRAMEBUFFER_COMPLETE : 0x8CD5,
  12731. FRAMEBUFFER_INCOMPLETE_ATTACHMENT : 0x8CD6,
  12732. FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : 0x8CD7,
  12733. FRAMEBUFFER_INCOMPLETE_DIMENSIONS : 0x8CD9,
  12734. FRAMEBUFFER_UNSUPPORTED : 0x8CDD,
  12735. FRAMEBUFFER_BINDING : 0x8CA6,
  12736. RENDERBUFFER_BINDING : 0x8CA7,
  12737. MAX_RENDERBUFFER_SIZE : 0x84E8,
  12738. INVALID_FRAMEBUFFER_OPERATION : 0x0506,
  12739. UNPACK_FLIP_Y_WEBGL : 0x9240,
  12740. UNPACK_PREMULTIPLY_ALPHA_WEBGL : 0x9241,
  12741. CONTEXT_LOST_WEBGL : 0x9242,
  12742. UNPACK_COLORSPACE_CONVERSION_WEBGL : 0x9243,
  12743. BROWSER_DEFAULT_WEBGL : 0x9244,
  12744. // Desktop OpenGL
  12745. DOUBLE : 0x140A,
  12746. // WebGL 2
  12747. READ_BUFFER : 0x0C02,
  12748. UNPACK_ROW_LENGTH : 0x0CF2,
  12749. UNPACK_SKIP_ROWS : 0x0CF3,
  12750. UNPACK_SKIP_PIXELS : 0x0CF4,
  12751. PACK_ROW_LENGTH : 0x0D02,
  12752. PACK_SKIP_ROWS : 0x0D03,
  12753. PACK_SKIP_PIXELS : 0x0D04,
  12754. COLOR : 0x1800,
  12755. DEPTH : 0x1801,
  12756. STENCIL : 0x1802,
  12757. RED : 0x1903,
  12758. RGB8 : 0x8051,
  12759. RGBA8 : 0x8058,
  12760. RGB10_A2 : 0x8059,
  12761. TEXTURE_BINDING_3D : 0x806A,
  12762. UNPACK_SKIP_IMAGES : 0x806D,
  12763. UNPACK_IMAGE_HEIGHT : 0x806E,
  12764. TEXTURE_3D : 0x806F,
  12765. TEXTURE_WRAP_R : 0x8072,
  12766. MAX_3D_TEXTURE_SIZE : 0x8073,
  12767. UNSIGNED_INT_2_10_10_10_REV : 0x8368,
  12768. MAX_ELEMENTS_VERTICES : 0x80E8,
  12769. MAX_ELEMENTS_INDICES : 0x80E9,
  12770. TEXTURE_MIN_LOD : 0x813A,
  12771. TEXTURE_MAX_LOD : 0x813B,
  12772. TEXTURE_BASE_LEVEL : 0x813C,
  12773. TEXTURE_MAX_LEVEL : 0x813D,
  12774. MIN : 0x8007,
  12775. MAX : 0x8008,
  12776. DEPTH_COMPONENT24 : 0x81A6,
  12777. MAX_TEXTURE_LOD_BIAS : 0x84FD,
  12778. TEXTURE_COMPARE_MODE : 0x884C,
  12779. TEXTURE_COMPARE_FUNC : 0x884D,
  12780. CURRENT_QUERY : 0x8865,
  12781. QUERY_RESULT : 0x8866,
  12782. QUERY_RESULT_AVAILABLE : 0x8867,
  12783. STREAM_READ : 0x88E1,
  12784. STREAM_COPY : 0x88E2,
  12785. STATIC_READ : 0x88E5,
  12786. STATIC_COPY : 0x88E6,
  12787. DYNAMIC_READ : 0x88E9,
  12788. DYNAMIC_COPY : 0x88EA,
  12789. MAX_DRAW_BUFFERS : 0x8824,
  12790. DRAW_BUFFER0 : 0x8825,
  12791. DRAW_BUFFER1 : 0x8826,
  12792. DRAW_BUFFER2 : 0x8827,
  12793. DRAW_BUFFER3 : 0x8828,
  12794. DRAW_BUFFER4 : 0x8829,
  12795. DRAW_BUFFER5 : 0x882A,
  12796. DRAW_BUFFER6 : 0x882B,
  12797. DRAW_BUFFER7 : 0x882C,
  12798. DRAW_BUFFER8 : 0x882D,
  12799. DRAW_BUFFER9 : 0x882E,
  12800. DRAW_BUFFER10 : 0x882F,
  12801. DRAW_BUFFER11 : 0x8830,
  12802. DRAW_BUFFER12 : 0x8831,
  12803. DRAW_BUFFER13 : 0x8832,
  12804. DRAW_BUFFER14 : 0x8833,
  12805. DRAW_BUFFER15 : 0x8834,
  12806. MAX_FRAGMENT_UNIFORM_COMPONENTS : 0x8B49,
  12807. MAX_VERTEX_UNIFORM_COMPONENTS : 0x8B4A,
  12808. SAMPLER_3D : 0x8B5F,
  12809. SAMPLER_2D_SHADOW : 0x8B62,
  12810. FRAGMENT_SHADER_DERIVATIVE_HINT : 0x8B8B,
  12811. PIXEL_PACK_BUFFER : 0x88EB,
  12812. PIXEL_UNPACK_BUFFER : 0x88EC,
  12813. PIXEL_PACK_BUFFER_BINDING : 0x88ED,
  12814. PIXEL_UNPACK_BUFFER_BINDING : 0x88EF,
  12815. FLOAT_MAT2x3 : 0x8B65,
  12816. FLOAT_MAT2x4 : 0x8B66,
  12817. FLOAT_MAT3x2 : 0x8B67,
  12818. FLOAT_MAT3x4 : 0x8B68,
  12819. FLOAT_MAT4x2 : 0x8B69,
  12820. FLOAT_MAT4x3 : 0x8B6A,
  12821. SRGB : 0x8C40,
  12822. SRGB8 : 0x8C41,
  12823. SRGB8_ALPHA8 : 0x8C43,
  12824. COMPARE_REF_TO_TEXTURE : 0x884E,
  12825. RGBA32F : 0x8814,
  12826. RGB32F : 0x8815,
  12827. RGBA16F : 0x881A,
  12828. RGB16F : 0x881B,
  12829. VERTEX_ATTRIB_ARRAY_INTEGER : 0x88FD,
  12830. MAX_ARRAY_TEXTURE_LAYERS : 0x88FF,
  12831. MIN_PROGRAM_TEXEL_OFFSET : 0x8904,
  12832. MAX_PROGRAM_TEXEL_OFFSET : 0x8905,
  12833. MAX_VARYING_COMPONENTS : 0x8B4B,
  12834. TEXTURE_2D_ARRAY : 0x8C1A,
  12835. TEXTURE_BINDING_2D_ARRAY : 0x8C1D,
  12836. R11F_G11F_B10F : 0x8C3A,
  12837. UNSIGNED_INT_10F_11F_11F_REV : 0x8C3B,
  12838. RGB9_E5 : 0x8C3D,
  12839. UNSIGNED_INT_5_9_9_9_REV : 0x8C3E,
  12840. TRANSFORM_FEEDBACK_BUFFER_MODE : 0x8C7F,
  12841. MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS : 0x8C80,
  12842. TRANSFORM_FEEDBACK_VARYINGS : 0x8C83,
  12843. TRANSFORM_FEEDBACK_BUFFER_START : 0x8C84,
  12844. TRANSFORM_FEEDBACK_BUFFER_SIZE : 0x8C85,
  12845. TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN : 0x8C88,
  12846. RASTERIZER_DISCARD : 0x8C89,
  12847. MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS : 0x8C8A,
  12848. MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS : 0x8C8B,
  12849. INTERLEAVED_ATTRIBS : 0x8C8C,
  12850. SEPARATE_ATTRIBS : 0x8C8D,
  12851. TRANSFORM_FEEDBACK_BUFFER : 0x8C8E,
  12852. TRANSFORM_FEEDBACK_BUFFER_BINDING : 0x8C8F,
  12853. RGBA32UI : 0x8D70,
  12854. RGB32UI : 0x8D71,
  12855. RGBA16UI : 0x8D76,
  12856. RGB16UI : 0x8D77,
  12857. RGBA8UI : 0x8D7C,
  12858. RGB8UI : 0x8D7D,
  12859. RGBA32I : 0x8D82,
  12860. RGB32I : 0x8D83,
  12861. RGBA16I : 0x8D88,
  12862. RGB16I : 0x8D89,
  12863. RGBA8I : 0x8D8E,
  12864. RGB8I : 0x8D8F,
  12865. RED_INTEGER : 0x8D94,
  12866. RGB_INTEGER : 0x8D98,
  12867. RGBA_INTEGER : 0x8D99,
  12868. SAMPLER_2D_ARRAY : 0x8DC1,
  12869. SAMPLER_2D_ARRAY_SHADOW : 0x8DC4,
  12870. SAMPLER_CUBE_SHADOW : 0x8DC5,
  12871. UNSIGNED_INT_VEC2 : 0x8DC6,
  12872. UNSIGNED_INT_VEC3 : 0x8DC7,
  12873. UNSIGNED_INT_VEC4 : 0x8DC8,
  12874. INT_SAMPLER_2D : 0x8DCA,
  12875. INT_SAMPLER_3D : 0x8DCB,
  12876. INT_SAMPLER_CUBE : 0x8DCC,
  12877. INT_SAMPLER_2D_ARRAY : 0x8DCF,
  12878. UNSIGNED_INT_SAMPLER_2D : 0x8DD2,
  12879. UNSIGNED_INT_SAMPLER_3D : 0x8DD3,
  12880. UNSIGNED_INT_SAMPLER_CUBE : 0x8DD4,
  12881. UNSIGNED_INT_SAMPLER_2D_ARRAY : 0x8DD7,
  12882. DEPTH_COMPONENT32F : 0x8CAC,
  12883. DEPTH32F_STENCIL8 : 0x8CAD,
  12884. FLOAT_32_UNSIGNED_INT_24_8_REV : 0x8DAD,
  12885. FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING : 0x8210,
  12886. FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE : 0x8211,
  12887. FRAMEBUFFER_ATTACHMENT_RED_SIZE : 0x8212,
  12888. FRAMEBUFFER_ATTACHMENT_GREEN_SIZE : 0x8213,
  12889. FRAMEBUFFER_ATTACHMENT_BLUE_SIZE : 0x8214,
  12890. FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE : 0x8215,
  12891. FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE : 0x8216,
  12892. FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE : 0x8217,
  12893. FRAMEBUFFER_DEFAULT : 0x8218,
  12894. UNSIGNED_INT_24_8 : 0x84FA,
  12895. DEPTH24_STENCIL8 : 0x88F0,
  12896. UNSIGNED_NORMALIZED : 0x8C17,
  12897. DRAW_FRAMEBUFFER_BINDING : 0x8CA6, // Same as FRAMEBUFFER_BINDING
  12898. READ_FRAMEBUFFER : 0x8CA8,
  12899. DRAW_FRAMEBUFFER : 0x8CA9,
  12900. READ_FRAMEBUFFER_BINDING : 0x8CAA,
  12901. RENDERBUFFER_SAMPLES : 0x8CAB,
  12902. FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER : 0x8CD4,
  12903. MAX_COLOR_ATTACHMENTS : 0x8CDF,
  12904. COLOR_ATTACHMENT1 : 0x8CE1,
  12905. COLOR_ATTACHMENT2 : 0x8CE2,
  12906. COLOR_ATTACHMENT3 : 0x8CE3,
  12907. COLOR_ATTACHMENT4 : 0x8CE4,
  12908. COLOR_ATTACHMENT5 : 0x8CE5,
  12909. COLOR_ATTACHMENT6 : 0x8CE6,
  12910. COLOR_ATTACHMENT7 : 0x8CE7,
  12911. COLOR_ATTACHMENT8 : 0x8CE8,
  12912. COLOR_ATTACHMENT9 : 0x8CE9,
  12913. COLOR_ATTACHMENT10 : 0x8CEA,
  12914. COLOR_ATTACHMENT11 : 0x8CEB,
  12915. COLOR_ATTACHMENT12 : 0x8CEC,
  12916. COLOR_ATTACHMENT13 : 0x8CED,
  12917. COLOR_ATTACHMENT14 : 0x8CEE,
  12918. COLOR_ATTACHMENT15 : 0x8CEF,
  12919. FRAMEBUFFER_INCOMPLETE_MULTISAMPLE : 0x8D56,
  12920. MAX_SAMPLES : 0x8D57,
  12921. HALF_FLOAT : 0x140B,
  12922. RG : 0x8227,
  12923. RG_INTEGER : 0x8228,
  12924. R8 : 0x8229,
  12925. RG8 : 0x822B,
  12926. R16F : 0x822D,
  12927. R32F : 0x822E,
  12928. RG16F : 0x822F,
  12929. RG32F : 0x8230,
  12930. R8I : 0x8231,
  12931. R8UI : 0x8232,
  12932. R16I : 0x8233,
  12933. R16UI : 0x8234,
  12934. R32I : 0x8235,
  12935. R32UI : 0x8236,
  12936. RG8I : 0x8237,
  12937. RG8UI : 0x8238,
  12938. RG16I : 0x8239,
  12939. RG16UI : 0x823A,
  12940. RG32I : 0x823B,
  12941. RG32UI : 0x823C,
  12942. VERTEX_ARRAY_BINDING : 0x85B5,
  12943. R8_SNORM : 0x8F94,
  12944. RG8_SNORM : 0x8F95,
  12945. RGB8_SNORM : 0x8F96,
  12946. RGBA8_SNORM : 0x8F97,
  12947. SIGNED_NORMALIZED : 0x8F9C,
  12948. COPY_READ_BUFFER : 0x8F36,
  12949. COPY_WRITE_BUFFER : 0x8F37,
  12950. COPY_READ_BUFFER_BINDING : 0x8F36, // Same as COPY_READ_BUFFER
  12951. COPY_WRITE_BUFFER_BINDING : 0x8F37, // Same as COPY_WRITE_BUFFER
  12952. UNIFORM_BUFFER : 0x8A11,
  12953. UNIFORM_BUFFER_BINDING : 0x8A28,
  12954. UNIFORM_BUFFER_START : 0x8A29,
  12955. UNIFORM_BUFFER_SIZE : 0x8A2A,
  12956. MAX_VERTEX_UNIFORM_BLOCKS : 0x8A2B,
  12957. MAX_FRAGMENT_UNIFORM_BLOCKS : 0x8A2D,
  12958. MAX_COMBINED_UNIFORM_BLOCKS : 0x8A2E,
  12959. MAX_UNIFORM_BUFFER_BINDINGS : 0x8A2F,
  12960. MAX_UNIFORM_BLOCK_SIZE : 0x8A30,
  12961. MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS : 0x8A31,
  12962. MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS : 0x8A33,
  12963. UNIFORM_BUFFER_OFFSET_ALIGNMENT : 0x8A34,
  12964. ACTIVE_UNIFORM_BLOCKS : 0x8A36,
  12965. UNIFORM_TYPE : 0x8A37,
  12966. UNIFORM_SIZE : 0x8A38,
  12967. UNIFORM_BLOCK_INDEX : 0x8A3A,
  12968. UNIFORM_OFFSET : 0x8A3B,
  12969. UNIFORM_ARRAY_STRIDE : 0x8A3C,
  12970. UNIFORM_MATRIX_STRIDE : 0x8A3D,
  12971. UNIFORM_IS_ROW_MAJOR : 0x8A3E,
  12972. UNIFORM_BLOCK_BINDING : 0x8A3F,
  12973. UNIFORM_BLOCK_DATA_SIZE : 0x8A40,
  12974. UNIFORM_BLOCK_ACTIVE_UNIFORMS : 0x8A42,
  12975. UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES : 0x8A43,
  12976. UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER : 0x8A44,
  12977. UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER : 0x8A46,
  12978. INVALID_INDEX : 0xFFFFFFFF,
  12979. MAX_VERTEX_OUTPUT_COMPONENTS : 0x9122,
  12980. MAX_FRAGMENT_INPUT_COMPONENTS : 0x9125,
  12981. MAX_SERVER_WAIT_TIMEOUT : 0x9111,
  12982. OBJECT_TYPE : 0x9112,
  12983. SYNC_CONDITION : 0x9113,
  12984. SYNC_STATUS : 0x9114,
  12985. SYNC_FLAGS : 0x9115,
  12986. SYNC_FENCE : 0x9116,
  12987. SYNC_GPU_COMMANDS_COMPLETE : 0x9117,
  12988. UNSIGNALED : 0x9118,
  12989. SIGNALED : 0x9119,
  12990. ALREADY_SIGNALED : 0x911A,
  12991. TIMEOUT_EXPIRED : 0x911B,
  12992. CONDITION_SATISFIED : 0x911C,
  12993. WAIT_FAILED : 0x911D,
  12994. SYNC_FLUSH_COMMANDS_BIT : 0x00000001,
  12995. VERTEX_ATTRIB_ARRAY_DIVISOR : 0x88FE,
  12996. ANY_SAMPLES_PASSED : 0x8C2F,
  12997. ANY_SAMPLES_PASSED_CONSERVATIVE : 0x8D6A,
  12998. SAMPLER_BINDING : 0x8919,
  12999. RGB10_A2UI : 0x906F,
  13000. INT_2_10_10_10_REV : 0x8D9F,
  13001. TRANSFORM_FEEDBACK : 0x8E22,
  13002. TRANSFORM_FEEDBACK_PAUSED : 0x8E23,
  13003. TRANSFORM_FEEDBACK_ACTIVE : 0x8E24,
  13004. TRANSFORM_FEEDBACK_BINDING : 0x8E25,
  13005. COMPRESSED_R11_EAC : 0x9270,
  13006. COMPRESSED_SIGNED_R11_EAC : 0x9271,
  13007. COMPRESSED_RG11_EAC : 0x9272,
  13008. COMPRESSED_SIGNED_RG11_EAC : 0x9273,
  13009. COMPRESSED_RGB8_ETC2 : 0x9274,
  13010. COMPRESSED_SRGB8_ETC2 : 0x9275,
  13011. COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 : 0x9276,
  13012. COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 : 0x9277,
  13013. COMPRESSED_RGBA8_ETC2_EAC : 0x9278,
  13014. COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : 0x9279,
  13015. TEXTURE_IMMUTABLE_FORMAT : 0x912F,
  13016. MAX_ELEMENT_INDEX : 0x8D6B,
  13017. TEXTURE_IMMUTABLE_LEVELS : 0x82DF
  13018. };
  13019. return freezeObject(WebGLConstants);
  13020. });
  13021. /*global define*/
  13022. define('Core/ComponentDatatype',[
  13023. './defaultValue',
  13024. './defined',
  13025. './DeveloperError',
  13026. './FeatureDetection',
  13027. './freezeObject',
  13028. './WebGLConstants'
  13029. ], function(
  13030. defaultValue,
  13031. defined,
  13032. DeveloperError,
  13033. FeatureDetection,
  13034. freezeObject,
  13035. WebGLConstants) {
  13036. 'use strict';
  13037. // Bail out if the browser doesn't support typed arrays, to prevent the setup function
  13038. // from failing, since we won't be able to create a WebGL context anyway.
  13039. if (!FeatureDetection.supportsTypedArrays()) {
  13040. return {};
  13041. }
  13042. /**
  13043. * WebGL component datatypes. Components are intrinsics,
  13044. * which form attributes, which form vertices.
  13045. *
  13046. * @exports ComponentDatatype
  13047. */
  13048. var ComponentDatatype = {
  13049. /**
  13050. * 8-bit signed byte corresponding to <code>gl.BYTE</code> and the type
  13051. * of an element in <code>Int8Array</code>.
  13052. *
  13053. * @type {Number}
  13054. * @constant
  13055. */
  13056. BYTE : WebGLConstants.BYTE,
  13057. /**
  13058. * 8-bit unsigned byte corresponding to <code>UNSIGNED_BYTE</code> and the type
  13059. * of an element in <code>Uint8Array</code>.
  13060. *
  13061. * @type {Number}
  13062. * @constant
  13063. */
  13064. UNSIGNED_BYTE : WebGLConstants.UNSIGNED_BYTE,
  13065. /**
  13066. * 16-bit signed short corresponding to <code>SHORT</code> and the type
  13067. * of an element in <code>Int16Array</code>.
  13068. *
  13069. * @type {Number}
  13070. * @constant
  13071. */
  13072. SHORT : WebGLConstants.SHORT,
  13073. /**
  13074. * 16-bit unsigned short corresponding to <code>UNSIGNED_SHORT</code> and the type
  13075. * of an element in <code>Uint16Array</code>.
  13076. *
  13077. * @type {Number}
  13078. * @constant
  13079. */
  13080. UNSIGNED_SHORT : WebGLConstants.UNSIGNED_SHORT,
  13081. /**
  13082. * 32-bit signed int corresponding to <code>INT</code> and the type
  13083. * of an element in <code>Int32Array</code>.
  13084. *
  13085. * @memberOf ComponentDatatype
  13086. *
  13087. * @type {Number}
  13088. * @constant
  13089. */
  13090. INT : WebGLConstants.INT,
  13091. /**
  13092. * 32-bit unsigned int corresponding to <code>UNSIGNED_INT</code> and the type
  13093. * of an element in <code>Uint32Array</code>.
  13094. *
  13095. * @memberOf ComponentDatatype
  13096. *
  13097. * @type {Number}
  13098. * @constant
  13099. */
  13100. UNSIGNED_INT : WebGLConstants.UNSIGNED_INT,
  13101. /**
  13102. * 32-bit floating-point corresponding to <code>FLOAT</code> and the type
  13103. * of an element in <code>Float32Array</code>.
  13104. *
  13105. * @type {Number}
  13106. * @constant
  13107. */
  13108. FLOAT : WebGLConstants.FLOAT,
  13109. /**
  13110. * 64-bit floating-point corresponding to <code>gl.DOUBLE</code> (in Desktop OpenGL;
  13111. * this is not supported in WebGL, and is emulated in Cesium via {@link GeometryPipeline.encodeAttribute})
  13112. * and the type of an element in <code>Float64Array</code>.
  13113. *
  13114. * @memberOf ComponentDatatype
  13115. *
  13116. * @type {Number}
  13117. * @constant
  13118. * @default 0x140A
  13119. */
  13120. DOUBLE : WebGLConstants.DOUBLE
  13121. };
  13122. /**
  13123. * Returns the size, in bytes, of the corresponding datatype.
  13124. *
  13125. * @param {ComponentDatatype} componentDatatype The component datatype to get the size of.
  13126. * @returns {Number} The size in bytes.
  13127. *
  13128. * @exception {DeveloperError} componentDatatype is not a valid value.
  13129. *
  13130. * @example
  13131. * // Returns Int8Array.BYTES_PER_ELEMENT
  13132. * var size = Cesium.ComponentDatatype.getSizeInBytes(Cesium.ComponentDatatype.BYTE);
  13133. */
  13134. ComponentDatatype.getSizeInBytes = function(componentDatatype){
  13135. if (!defined(componentDatatype)) {
  13136. throw new DeveloperError('value is required.');
  13137. }
  13138. switch (componentDatatype) {
  13139. case ComponentDatatype.BYTE:
  13140. return Int8Array.BYTES_PER_ELEMENT;
  13141. case ComponentDatatype.UNSIGNED_BYTE:
  13142. return Uint8Array.BYTES_PER_ELEMENT;
  13143. case ComponentDatatype.SHORT:
  13144. return Int16Array.BYTES_PER_ELEMENT;
  13145. case ComponentDatatype.UNSIGNED_SHORT:
  13146. return Uint16Array.BYTES_PER_ELEMENT;
  13147. case ComponentDatatype.INT:
  13148. return Int32Array.BYTES_PER_ELEMENT;
  13149. case ComponentDatatype.UNSIGNED_INT:
  13150. return Uint32Array.BYTES_PER_ELEMENT;
  13151. case ComponentDatatype.FLOAT:
  13152. return Float32Array.BYTES_PER_ELEMENT;
  13153. case ComponentDatatype.DOUBLE:
  13154. return Float64Array.BYTES_PER_ELEMENT;
  13155. default:
  13156. throw new DeveloperError('componentDatatype is not a valid value.');
  13157. }
  13158. };
  13159. /**
  13160. * Gets the {@link ComponentDatatype} for the provided TypedArray instance.
  13161. *
  13162. * @param {TypedArray} array The typed array.
  13163. * @returns {ComponentDatatype} The ComponentDatatype for the provided array, or undefined if the array is not a TypedArray.
  13164. */
  13165. ComponentDatatype.fromTypedArray = function(array) {
  13166. if (array instanceof Int8Array) {
  13167. return ComponentDatatype.BYTE;
  13168. }
  13169. if (array instanceof Uint8Array) {
  13170. return ComponentDatatype.UNSIGNED_BYTE;
  13171. }
  13172. if (array instanceof Int16Array) {
  13173. return ComponentDatatype.SHORT;
  13174. }
  13175. if (array instanceof Uint16Array) {
  13176. return ComponentDatatype.UNSIGNED_SHORT;
  13177. }
  13178. if (array instanceof Int32Array) {
  13179. return ComponentDatatype.INT;
  13180. }
  13181. if (array instanceof Uint32Array) {
  13182. return ComponentDatatype.UNSIGNED_INT;
  13183. }
  13184. if (array instanceof Float32Array) {
  13185. return ComponentDatatype.FLOAT;
  13186. }
  13187. if (array instanceof Float64Array) {
  13188. return ComponentDatatype.DOUBLE;
  13189. }
  13190. };
  13191. /**
  13192. * Validates that the provided component datatype is a valid {@link ComponentDatatype}
  13193. *
  13194. * @param {ComponentDatatype} componentDatatype The component datatype to validate.
  13195. * @returns {Boolean} <code>true</code> if the provided component datatype is a valid value; otherwise, <code>false</code>.
  13196. *
  13197. * @example
  13198. * if (!Cesium.ComponentDatatype.validate(componentDatatype)) {
  13199. * throw new Cesium.DeveloperError('componentDatatype must be a valid value.');
  13200. * }
  13201. */
  13202. ComponentDatatype.validate = function(componentDatatype) {
  13203. return defined(componentDatatype) &&
  13204. (componentDatatype === ComponentDatatype.BYTE ||
  13205. componentDatatype === ComponentDatatype.UNSIGNED_BYTE ||
  13206. componentDatatype === ComponentDatatype.SHORT ||
  13207. componentDatatype === ComponentDatatype.UNSIGNED_SHORT ||
  13208. componentDatatype === ComponentDatatype.INT ||
  13209. componentDatatype === ComponentDatatype.UNSIGNED_INT ||
  13210. componentDatatype === ComponentDatatype.FLOAT ||
  13211. componentDatatype === ComponentDatatype.DOUBLE);
  13212. };
  13213. /**
  13214. * Creates a typed array corresponding to component data type.
  13215. *
  13216. * @param {ComponentDatatype} componentDatatype The component data type.
  13217. * @param {Number|Array} valuesOrLength The length of the array to create or an array.
  13218. * @returns {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} A typed array.
  13219. *
  13220. * @exception {DeveloperError} componentDatatype is not a valid value.
  13221. *
  13222. * @example
  13223. * // creates a Float32Array with length of 100
  13224. * var typedArray = Cesium.ComponentDatatype.createTypedArray(Cesium.ComponentDatatype.FLOAT, 100);
  13225. */
  13226. ComponentDatatype.createTypedArray = function(componentDatatype, valuesOrLength) {
  13227. if (!defined(componentDatatype)) {
  13228. throw new DeveloperError('componentDatatype is required.');
  13229. }
  13230. if (!defined(valuesOrLength)) {
  13231. throw new DeveloperError('valuesOrLength is required.');
  13232. }
  13233. switch (componentDatatype) {
  13234. case ComponentDatatype.BYTE:
  13235. return new Int8Array(valuesOrLength);
  13236. case ComponentDatatype.UNSIGNED_BYTE:
  13237. return new Uint8Array(valuesOrLength);
  13238. case ComponentDatatype.SHORT:
  13239. return new Int16Array(valuesOrLength);
  13240. case ComponentDatatype.UNSIGNED_SHORT:
  13241. return new Uint16Array(valuesOrLength);
  13242. case ComponentDatatype.INT:
  13243. return new Int32Array(valuesOrLength);
  13244. case ComponentDatatype.UNSIGNED_INT:
  13245. return new Uint32Array(valuesOrLength);
  13246. case ComponentDatatype.FLOAT:
  13247. return new Float32Array(valuesOrLength);
  13248. case ComponentDatatype.DOUBLE:
  13249. return new Float64Array(valuesOrLength);
  13250. default:
  13251. throw new DeveloperError('componentDatatype is not a valid value.');
  13252. }
  13253. };
  13254. /**
  13255. * Creates a typed view of an array of bytes.
  13256. *
  13257. * @param {ComponentDatatype} componentDatatype The type of the view to create.
  13258. * @param {ArrayBuffer} buffer The buffer storage to use for the view.
  13259. * @param {Number} [byteOffset] The offset, in bytes, to the first element in the view.
  13260. * @param {Number} [length] The number of elements in the view.
  13261. * @returns {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} A typed array view of the buffer.
  13262. *
  13263. * @exception {DeveloperError} componentDatatype is not a valid value.
  13264. */
  13265. ComponentDatatype.createArrayBufferView = function(componentDatatype, buffer, byteOffset, length) {
  13266. if (!defined(componentDatatype)) {
  13267. throw new DeveloperError('componentDatatype is required.');
  13268. }
  13269. if (!defined(buffer)) {
  13270. throw new DeveloperError('buffer is required.');
  13271. }
  13272. byteOffset = defaultValue(byteOffset, 0);
  13273. length = defaultValue(length, (buffer.byteLength - byteOffset) / ComponentDatatype.getSizeInBytes(componentDatatype));
  13274. switch (componentDatatype) {
  13275. case ComponentDatatype.BYTE:
  13276. return new Int8Array(buffer, byteOffset, length);
  13277. case ComponentDatatype.UNSIGNED_BYTE:
  13278. return new Uint8Array(buffer, byteOffset, length);
  13279. case ComponentDatatype.SHORT:
  13280. return new Int16Array(buffer, byteOffset, length);
  13281. case ComponentDatatype.UNSIGNED_SHORT:
  13282. return new Uint16Array(buffer, byteOffset, length);
  13283. case ComponentDatatype.INT:
  13284. return new Int32Array(buffer, byteOffset, length);
  13285. case ComponentDatatype.UNSIGNED_INT:
  13286. return new Uint32Array(buffer, byteOffset, length);
  13287. case ComponentDatatype.FLOAT:
  13288. return new Float32Array(buffer, byteOffset, length);
  13289. case ComponentDatatype.DOUBLE:
  13290. return new Float64Array(buffer, byteOffset, length);
  13291. default:
  13292. throw new DeveloperError('componentDatatype is not a valid value.');
  13293. }
  13294. };
  13295. /**
  13296. * Get the ComponentDatatype from its name.
  13297. *
  13298. * @param {String} name The name of the ComponentDatatype.
  13299. * @returns {ComponentDatatype} The ComponentDatatype.
  13300. *
  13301. * @exception {DeveloperError} name is not a valid value.
  13302. */
  13303. ComponentDatatype.fromName = function(name) {
  13304. switch (name) {
  13305. case 'BYTE':
  13306. return ComponentDatatype.BYTE;
  13307. case 'UNSIGNED_BYTE':
  13308. return ComponentDatatype.UNSIGNED_BYTE;
  13309. case 'SHORT':
  13310. return ComponentDatatype.SHORT;
  13311. case 'UNSIGNED_SHORT':
  13312. return ComponentDatatype.UNSIGNED_SHORT;
  13313. case 'INT':
  13314. return ComponentDatatype.INT;
  13315. case 'UNSIGNED_INT':
  13316. return ComponentDatatype.UNSIGNED_INT;
  13317. case 'FLOAT':
  13318. return ComponentDatatype.FLOAT;
  13319. case 'DOUBLE':
  13320. return ComponentDatatype.DOUBLE;
  13321. default:
  13322. throw new DeveloperError('name is not a valid value.');
  13323. }
  13324. };
  13325. return freezeObject(ComponentDatatype);
  13326. });
  13327. /*global define*/
  13328. define('Core/GeometryType',[
  13329. './freezeObject'
  13330. ], function(
  13331. freezeObject) {
  13332. 'use strict';
  13333. /**
  13334. * @private
  13335. */
  13336. var GeometryType = {
  13337. NONE : 0,
  13338. TRIANGLES : 1,
  13339. LINES : 2,
  13340. POLYLINES : 3
  13341. };
  13342. return freezeObject(GeometryType);
  13343. });
  13344. /*global define*/
  13345. define('Core/PrimitiveType',[
  13346. './freezeObject',
  13347. './WebGLConstants'
  13348. ], function(
  13349. freezeObject,
  13350. WebGLConstants) {
  13351. 'use strict';
  13352. /**
  13353. * The type of a geometric primitive, i.e., points, lines, and triangles.
  13354. *
  13355. * @exports PrimitiveType
  13356. */
  13357. var PrimitiveType = {
  13358. /**
  13359. * Points primitive where each vertex (or index) is a separate point.
  13360. *
  13361. * @type {Number}
  13362. * @constant
  13363. */
  13364. POINTS : WebGLConstants.POINTS,
  13365. /**
  13366. * Lines primitive where each two vertices (or indices) is a line segment. Line segments are not necessarily connected.
  13367. *
  13368. * @type {Number}
  13369. * @constant
  13370. */
  13371. LINES : WebGLConstants.LINES,
  13372. /**
  13373. * Line loop primitive where each vertex (or index) after the first connects a line to
  13374. * the previous vertex, and the last vertex implicitly connects to the first.
  13375. *
  13376. * @type {Number}
  13377. * @constant
  13378. */
  13379. LINE_LOOP : WebGLConstants.LINE_LOOP,
  13380. /**
  13381. * Line strip primitive where each vertex (or index) after the first connects a line to the previous vertex.
  13382. *
  13383. * @type {Number}
  13384. * @constant
  13385. */
  13386. LINE_STRIP : WebGLConstants.LINE_STRIP,
  13387. /**
  13388. * Triangles primitive where each three vertices (or indices) is a triangle. Triangles do not necessarily share edges.
  13389. *
  13390. * @type {Number}
  13391. * @constant
  13392. */
  13393. TRIANGLES : WebGLConstants.TRIANGLES,
  13394. /**
  13395. * Triangle strip primitive where each vertex (or index) after the first two connect to
  13396. * the previous two vertices forming a triangle. For example, this can be used to model a wall.
  13397. *
  13398. * @type {Number}
  13399. * @constant
  13400. */
  13401. TRIANGLE_STRIP : WebGLConstants.TRIANGLE_STRIP,
  13402. /**
  13403. * Triangle fan primitive where each vertex (or index) after the first two connect to
  13404. * the previous vertex and the first vertex forming a triangle. For example, this can be used
  13405. * to model a cone or circle.
  13406. *
  13407. * @type {Number}
  13408. * @constant
  13409. */
  13410. TRIANGLE_FAN : WebGLConstants.TRIANGLE_FAN,
  13411. /**
  13412. * @private
  13413. */
  13414. validate : function(primitiveType) {
  13415. return primitiveType === PrimitiveType.POINTS ||
  13416. primitiveType === PrimitiveType.LINES ||
  13417. primitiveType === PrimitiveType.LINE_LOOP ||
  13418. primitiveType === PrimitiveType.LINE_STRIP ||
  13419. primitiveType === PrimitiveType.TRIANGLES ||
  13420. primitiveType === PrimitiveType.TRIANGLE_STRIP ||
  13421. primitiveType === PrimitiveType.TRIANGLE_FAN;
  13422. }
  13423. };
  13424. return freezeObject(PrimitiveType);
  13425. });
  13426. /*global define*/
  13427. define('Core/Geometry',[
  13428. './defaultValue',
  13429. './defined',
  13430. './DeveloperError',
  13431. './GeometryType',
  13432. './PrimitiveType'
  13433. ], function(
  13434. defaultValue,
  13435. defined,
  13436. DeveloperError,
  13437. GeometryType,
  13438. PrimitiveType) {
  13439. 'use strict';
  13440. /**
  13441. * A geometry representation with attributes forming vertices and optional index data
  13442. * defining primitives. Geometries and an {@link Appearance}, which describes the shading,
  13443. * can be assigned to a {@link Primitive} for visualization. A <code>Primitive</code> can
  13444. * be created from many heterogeneous - in many cases - geometries for performance.
  13445. * <p>
  13446. * Geometries can be transformed and optimized using functions in {@link GeometryPipeline}.
  13447. * </p>
  13448. *
  13449. * @alias Geometry
  13450. * @constructor
  13451. *
  13452. * @param {Object} options Object with the following properties:
  13453. * @param {GeometryAttributes} options.attributes Attributes, which make up the geometry's vertices.
  13454. * @param {PrimitiveType} [options.primitiveType=PrimitiveType.TRIANGLES] The type of primitives in the geometry.
  13455. * @param {Uint16Array|Uint32Array} [options.indices] Optional index data that determines the primitives in the geometry.
  13456. * @param {BoundingSphere} [options.boundingSphere] An optional bounding sphere that fully enclosed the geometry.
  13457. *
  13458. * @see PolygonGeometry
  13459. * @see RectangleGeometry
  13460. * @see EllipseGeometry
  13461. * @see CircleGeometry
  13462. * @see WallGeometry
  13463. * @see SimplePolylineGeometry
  13464. * @see BoxGeometry
  13465. * @see EllipsoidGeometry
  13466. *
  13467. * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Geometry%20and%20Appearances.html|Geometry and Appearances Demo}
  13468. *
  13469. * @example
  13470. * // Create geometry with a position attribute and indexed lines.
  13471. * var positions = new Float64Array([
  13472. * 0.0, 0.0, 0.0,
  13473. * 7500000.0, 0.0, 0.0,
  13474. * 0.0, 7500000.0, 0.0
  13475. * ]);
  13476. *
  13477. * var geometry = new Cesium.Geometry({
  13478. * attributes : {
  13479. * position : new Cesium.GeometryAttribute({
  13480. * componentDatatype : Cesium.ComponentDatatype.DOUBLE,
  13481. * componentsPerAttribute : 3,
  13482. * values : positions
  13483. * })
  13484. * },
  13485. * indices : new Uint16Array([0, 1, 1, 2, 2, 0]),
  13486. * primitiveType : Cesium.PrimitiveType.LINES,
  13487. * boundingSphere : Cesium.BoundingSphere.fromVertices(positions)
  13488. * });
  13489. */
  13490. function Geometry(options) {
  13491. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  13492. if (!defined(options.attributes)) {
  13493. throw new DeveloperError('options.attributes is required.');
  13494. }
  13495. /**
  13496. * Attributes, which make up the geometry's vertices. Each property in this object corresponds to a
  13497. * {@link GeometryAttribute} containing the attribute's data.
  13498. * <p>
  13499. * Attributes are always stored non-interleaved in a Geometry.
  13500. * </p>
  13501. * <p>
  13502. * There are reserved attribute names with well-known semantics. The following attributes
  13503. * are created by a Geometry (depending on the provided {@link VertexFormat}.
  13504. * <ul>
  13505. * <li><code>position</code> - 3D vertex position. 64-bit floating-point (for precision). 3 components per attribute. See {@link VertexFormat#position}.</li>
  13506. * <li><code>normal</code> - Normal (normalized), commonly used for lighting. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#normal}.</li>
  13507. * <li><code>st</code> - 2D texture coordinate. 32-bit floating-point. 2 components per attribute. See {@link VertexFormat#st}.</li>
  13508. * <li><code>binormal</code> - Binormal (normalized), used for tangent-space effects like bump mapping. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#binormal}.</li>
  13509. * <li><code>tangent</code> - Tangent (normalized), used for tangent-space effects like bump mapping. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#tangent}.</li>
  13510. * </ul>
  13511. * </p>
  13512. * <p>
  13513. * The following attribute names are generally not created by a Geometry, but are added
  13514. * to a Geometry by a {@link Primitive} or {@link GeometryPipeline} functions to prepare
  13515. * the geometry for rendering.
  13516. * <ul>
  13517. * <li><code>position3DHigh</code> - High 32 bits for encoded 64-bit position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.</li>
  13518. * <li><code>position3DLow</code> - Low 32 bits for encoded 64-bit position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.</li>
  13519. * <li><code>position3DHigh</code> - High 32 bits for encoded 64-bit 2D (Columbus view) position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.</li>
  13520. * <li><code>position2DLow</code> - Low 32 bits for encoded 64-bit 2D (Columbus view) position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.</li>
  13521. * <li><code>color</code> - RGBA color (normalized) usually from {@link GeometryInstance#color}. 32-bit floating-point. 4 components per attribute.</li>
  13522. * <li><code>pickColor</code> - RGBA color used for picking. 32-bit floating-point. 4 components per attribute.</li>
  13523. * </ul>
  13524. * </p>
  13525. *
  13526. * @type GeometryAttributes
  13527. *
  13528. * @default undefined
  13529. *
  13530. *
  13531. * @example
  13532. * geometry.attributes.position = new Cesium.GeometryAttribute({
  13533. * componentDatatype : Cesium.ComponentDatatype.FLOAT,
  13534. * componentsPerAttribute : 3,
  13535. * values : new Float32Array(0)
  13536. * });
  13537. *
  13538. * @see GeometryAttribute
  13539. * @see VertexFormat
  13540. */
  13541. this.attributes = options.attributes;
  13542. /**
  13543. * Optional index data that - along with {@link Geometry#primitiveType} -
  13544. * determines the primitives in the geometry.
  13545. *
  13546. * @type Array
  13547. *
  13548. * @default undefined
  13549. */
  13550. this.indices = options.indices;
  13551. /**
  13552. * The type of primitives in the geometry. This is most often {@link PrimitiveType.TRIANGLES},
  13553. * but can varying based on the specific geometry.
  13554. *
  13555. * @type PrimitiveType
  13556. *
  13557. * @default undefined
  13558. */
  13559. this.primitiveType = defaultValue(options.primitiveType, PrimitiveType.TRIANGLES);
  13560. /**
  13561. * An optional bounding sphere that fully encloses the geometry. This is
  13562. * commonly used for culling.
  13563. *
  13564. * @type BoundingSphere
  13565. *
  13566. * @default undefined
  13567. */
  13568. this.boundingSphere = options.boundingSphere;
  13569. /**
  13570. * @private
  13571. */
  13572. this.geometryType = defaultValue(options.geometryType, GeometryType.NONE);
  13573. /**
  13574. * @private
  13575. */
  13576. this.boundingSphereCV = options.boundingSphereCV;
  13577. }
  13578. /**
  13579. * Computes the number of vertices in a geometry. The runtime is linear with
  13580. * respect to the number of attributes in a vertex, not the number of vertices.
  13581. *
  13582. * @param {Geometry} geometry The geometry.
  13583. * @returns {Number} The number of vertices in the geometry.
  13584. *
  13585. * @example
  13586. * var numVertices = Cesium.Geometry.computeNumberOfVertices(geometry);
  13587. */
  13588. Geometry.computeNumberOfVertices = function(geometry) {
  13589. if (!defined(geometry)) {
  13590. throw new DeveloperError('geometry is required.');
  13591. }
  13592. var numberOfVertices = -1;
  13593. for ( var property in geometry.attributes) {
  13594. if (geometry.attributes.hasOwnProperty(property) &&
  13595. defined(geometry.attributes[property]) &&
  13596. defined(geometry.attributes[property].values)) {
  13597. var attribute = geometry.attributes[property];
  13598. var num = attribute.values.length / attribute.componentsPerAttribute;
  13599. if ((numberOfVertices !== num) && (numberOfVertices !== -1)) {
  13600. throw new DeveloperError('All attribute lists must have the same number of attributes.');
  13601. }
  13602. numberOfVertices = num;
  13603. }
  13604. }
  13605. return numberOfVertices;
  13606. };
  13607. return Geometry;
  13608. });
  13609. /*global define*/
  13610. define('Core/GeometryAttribute',[
  13611. './defaultValue',
  13612. './defined',
  13613. './DeveloperError'
  13614. ], function(
  13615. defaultValue,
  13616. defined,
  13617. DeveloperError) {
  13618. 'use strict';
  13619. /**
  13620. * Values and type information for geometry attributes. A {@link Geometry}
  13621. * generally contains one or more attributes. All attributes together form
  13622. * the geometry's vertices.
  13623. *
  13624. * @alias GeometryAttribute
  13625. * @constructor
  13626. *
  13627. * @param {Object} [options] Object with the following properties:
  13628. * @param {ComponentDatatype} [options.componentDatatype] The datatype of each component in the attribute, e.g., individual elements in values.
  13629. * @param {Number} [options.componentsPerAttribute] A number between 1 and 4 that defines the number of components in an attributes.
  13630. * @param {Boolean} [options.normalize=false] When <code>true</code> and <code>componentDatatype</code> is an integer format, indicate that the components should be mapped to the range [0, 1] (unsigned) or [-1, 1] (signed) when they are accessed as floating-point for rendering.
  13631. * @param {TypedArray} [options.values] The values for the attributes stored in a typed array.
  13632. *
  13633. * @exception {DeveloperError} options.componentsPerAttribute must be between 1 and 4.
  13634. *
  13635. *
  13636. * @example
  13637. * var geometry = new Cesium.Geometry({
  13638. * attributes : {
  13639. * position : new Cesium.GeometryAttribute({
  13640. * componentDatatype : Cesium.ComponentDatatype.FLOAT,
  13641. * componentsPerAttribute : 3,
  13642. * values : new Float32Array([
  13643. * 0.0, 0.0, 0.0,
  13644. * 7500000.0, 0.0, 0.0,
  13645. * 0.0, 7500000.0, 0.0
  13646. * ])
  13647. * })
  13648. * },
  13649. * primitiveType : Cesium.PrimitiveType.LINE_LOOP
  13650. * });
  13651. *
  13652. * @see Geometry
  13653. */
  13654. function GeometryAttribute(options) {
  13655. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  13656. if (!defined(options.componentDatatype)) {
  13657. throw new DeveloperError('options.componentDatatype is required.');
  13658. }
  13659. if (!defined(options.componentsPerAttribute)) {
  13660. throw new DeveloperError('options.componentsPerAttribute is required.');
  13661. }
  13662. if (options.componentsPerAttribute < 1 || options.componentsPerAttribute > 4) {
  13663. throw new DeveloperError('options.componentsPerAttribute must be between 1 and 4.');
  13664. }
  13665. if (!defined(options.values)) {
  13666. throw new DeveloperError('options.values is required.');
  13667. }
  13668. /**
  13669. * The datatype of each component in the attribute, e.g., individual elements in
  13670. * {@link GeometryAttribute#values}.
  13671. *
  13672. * @type ComponentDatatype
  13673. *
  13674. * @default undefined
  13675. */
  13676. this.componentDatatype = options.componentDatatype;
  13677. /**
  13678. * A number between 1 and 4 that defines the number of components in an attributes.
  13679. * For example, a position attribute with x, y, and z components would have 3 as
  13680. * shown in the code example.
  13681. *
  13682. * @type Number
  13683. *
  13684. * @default undefined
  13685. *
  13686. * @example
  13687. * attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;
  13688. * attribute.componentsPerAttribute = 3;
  13689. * attribute.values = new Float32Array([
  13690. * 0.0, 0.0, 0.0,
  13691. * 7500000.0, 0.0, 0.0,
  13692. * 0.0, 7500000.0, 0.0
  13693. * ]);
  13694. */
  13695. this.componentsPerAttribute = options.componentsPerAttribute;
  13696. /**
  13697. * When <code>true</code> and <code>componentDatatype</code> is an integer format,
  13698. * indicate that the components should be mapped to the range [0, 1] (unsigned)
  13699. * or [-1, 1] (signed) when they are accessed as floating-point for rendering.
  13700. * <p>
  13701. * This is commonly used when storing colors using {@link ComponentDatatype.UNSIGNED_BYTE}.
  13702. * </p>
  13703. *
  13704. * @type Boolean
  13705. *
  13706. * @default false
  13707. *
  13708. * @example
  13709. * attribute.componentDatatype = Cesium.ComponentDatatype.UNSIGNED_BYTE;
  13710. * attribute.componentsPerAttribute = 4;
  13711. * attribute.normalize = true;
  13712. * attribute.values = new Uint8Array([
  13713. * Cesium.Color.floatToByte(color.red),
  13714. * Cesium.Color.floatToByte(color.green),
  13715. * Cesium.Color.floatToByte(color.blue),
  13716. * Cesium.Color.floatToByte(color.alpha)
  13717. * ]);
  13718. */
  13719. this.normalize = defaultValue(options.normalize, false);
  13720. /**
  13721. * The values for the attributes stored in a typed array. In the code example,
  13722. * every three elements in <code>values</code> defines one attributes since
  13723. * <code>componentsPerAttribute</code> is 3.
  13724. *
  13725. * @type TypedArray
  13726. *
  13727. * @default undefined
  13728. *
  13729. * @example
  13730. * attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;
  13731. * attribute.componentsPerAttribute = 3;
  13732. * attribute.values = new Float32Array([
  13733. * 0.0, 0.0, 0.0,
  13734. * 7500000.0, 0.0, 0.0,
  13735. * 0.0, 7500000.0, 0.0
  13736. * ]);
  13737. */
  13738. this.values = options.values;
  13739. }
  13740. return GeometryAttribute;
  13741. });
  13742. /*global define*/
  13743. define('Core/GeometryAttributes',[
  13744. './defaultValue'
  13745. ], function(
  13746. defaultValue) {
  13747. 'use strict';
  13748. /**
  13749. * Attributes, which make up a geometry's vertices. Each property in this object corresponds to a
  13750. * {@link GeometryAttribute} containing the attribute's data.
  13751. * <p>
  13752. * Attributes are always stored non-interleaved in a Geometry.
  13753. * </p>
  13754. *
  13755. * @alias GeometryAttributes
  13756. * @constructor
  13757. */
  13758. function GeometryAttributes(options) {
  13759. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  13760. /**
  13761. * The 3D position attribute.
  13762. * <p>
  13763. * 64-bit floating-point (for precision). 3 components per attribute.
  13764. * </p>
  13765. *
  13766. * @type GeometryAttribute
  13767. *
  13768. * @default undefined
  13769. */
  13770. this.position = options.position;
  13771. /**
  13772. * The normal attribute (normalized), which is commonly used for lighting.
  13773. * <p>
  13774. * 32-bit floating-point. 3 components per attribute.
  13775. * </p>
  13776. *
  13777. * @type GeometryAttribute
  13778. *
  13779. * @default undefined
  13780. */
  13781. this.normal = options.normal;
  13782. /**
  13783. * The 2D texture coordinate attribute.
  13784. * <p>
  13785. * 32-bit floating-point. 2 components per attribute
  13786. * </p>
  13787. *
  13788. * @type GeometryAttribute
  13789. *
  13790. * @default undefined
  13791. */
  13792. this.st = options.st;
  13793. /**
  13794. * The binormal attribute (normalized), which is used for tangent-space effects like bump mapping.
  13795. * <p>
  13796. * 32-bit floating-point. 3 components per attribute.
  13797. * </p>
  13798. *
  13799. * @type GeometryAttribute
  13800. *
  13801. * @default undefined
  13802. */
  13803. this.binormal = options.binormal;
  13804. /**
  13805. * The tangent attribute (normalized), which is used for tangent-space effects like bump mapping.
  13806. * <p>
  13807. * 32-bit floating-point. 3 components per attribute.
  13808. * </p>
  13809. *
  13810. * @type GeometryAttribute
  13811. *
  13812. * @default undefined
  13813. */
  13814. this.tangent = options.tangent;
  13815. /**
  13816. * The color attribute.
  13817. * <p>
  13818. * 8-bit unsigned integer. 4 components per attribute.
  13819. * </p>
  13820. *
  13821. * @type GeometryAttribute
  13822. *
  13823. * @default undefined
  13824. */
  13825. this.color = options.color;
  13826. }
  13827. return GeometryAttributes;
  13828. });
  13829. /*global define*/
  13830. define('Core/IndexDatatype',[
  13831. './defined',
  13832. './DeveloperError',
  13833. './freezeObject',
  13834. './Math',
  13835. './WebGLConstants'
  13836. ], function(
  13837. defined,
  13838. DeveloperError,
  13839. freezeObject,
  13840. CesiumMath,
  13841. WebGLConstants) {
  13842. 'use strict';
  13843. /**
  13844. * Constants for WebGL index datatypes. These corresponds to the
  13845. * <code>type</code> parameter of {@link http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDrawElements.xml|drawElements}.
  13846. *
  13847. * @exports IndexDatatype
  13848. */
  13849. var IndexDatatype = {
  13850. /**
  13851. * 8-bit unsigned byte corresponding to <code>UNSIGNED_BYTE</code> and the type
  13852. * of an element in <code>Uint8Array</code>.
  13853. *
  13854. * @type {Number}
  13855. * @constant
  13856. */
  13857. UNSIGNED_BYTE : WebGLConstants.UNSIGNED_BYTE,
  13858. /**
  13859. * 16-bit unsigned short corresponding to <code>UNSIGNED_SHORT</code> and the type
  13860. * of an element in <code>Uint16Array</code>.
  13861. *
  13862. * @type {Number}
  13863. * @constant
  13864. */
  13865. UNSIGNED_SHORT : WebGLConstants.UNSIGNED_SHORT,
  13866. /**
  13867. * 32-bit unsigned int corresponding to <code>UNSIGNED_INT</code> and the type
  13868. * of an element in <code>Uint32Array</code>.
  13869. *
  13870. * @type {Number}
  13871. * @constant
  13872. */
  13873. UNSIGNED_INT : WebGLConstants.UNSIGNED_INT
  13874. };
  13875. /**
  13876. * Returns the size, in bytes, of the corresponding datatype.
  13877. *
  13878. * @param {IndexDatatype} indexDatatype The index datatype to get the size of.
  13879. * @returns {Number} The size in bytes.
  13880. *
  13881. * @example
  13882. * // Returns 2
  13883. * var size = Cesium.IndexDatatype.getSizeInBytes(Cesium.IndexDatatype.UNSIGNED_SHORT);
  13884. */
  13885. IndexDatatype.getSizeInBytes = function(indexDatatype) {
  13886. switch(indexDatatype) {
  13887. case IndexDatatype.UNSIGNED_BYTE:
  13888. return Uint8Array.BYTES_PER_ELEMENT;
  13889. case IndexDatatype.UNSIGNED_SHORT:
  13890. return Uint16Array.BYTES_PER_ELEMENT;
  13891. case IndexDatatype.UNSIGNED_INT:
  13892. return Uint32Array.BYTES_PER_ELEMENT;
  13893. }
  13894. throw new DeveloperError('indexDatatype is required and must be a valid IndexDatatype constant.');
  13895. };
  13896. /**
  13897. * Validates that the provided index datatype is a valid {@link IndexDatatype}.
  13898. *
  13899. * @param {IndexDatatype} indexDatatype The index datatype to validate.
  13900. * @returns {Boolean} <code>true</code> if the provided index datatype is a valid value; otherwise, <code>false</code>.
  13901. *
  13902. * @example
  13903. * if (!Cesium.IndexDatatype.validate(indexDatatype)) {
  13904. * throw new Cesium.DeveloperError('indexDatatype must be a valid value.');
  13905. * }
  13906. */
  13907. IndexDatatype.validate = function(indexDatatype) {
  13908. return defined(indexDatatype) &&
  13909. (indexDatatype === IndexDatatype.UNSIGNED_BYTE ||
  13910. indexDatatype === IndexDatatype.UNSIGNED_SHORT ||
  13911. indexDatatype === IndexDatatype.UNSIGNED_INT);
  13912. };
  13913. /**
  13914. * Creates a typed array that will store indices, using either <code><Uint16Array</code>
  13915. * or <code>Uint32Array</code> depending on the number of vertices.
  13916. *
  13917. * @param {Number} numberOfVertices Number of vertices that the indices will reference.
  13918. * @param {Any} indicesLengthOrArray Passed through to the typed array constructor.
  13919. * @returns {Uint16Array|Uint32Array} A <code>Uint16Array</code> or <code>Uint32Array</code> constructed with <code>indicesLengthOrArray</code>.
  13920. *
  13921. * @example
  13922. * this.indices = Cesium.IndexDatatype.createTypedArray(positions.length / 3, numberOfIndices);
  13923. */
  13924. IndexDatatype.createTypedArray = function(numberOfVertices, indicesLengthOrArray) {
  13925. if (!defined(numberOfVertices)) {
  13926. throw new DeveloperError('numberOfVertices is required.');
  13927. }
  13928. if (numberOfVertices >= CesiumMath.SIXTY_FOUR_KILOBYTES) {
  13929. return new Uint32Array(indicesLengthOrArray);
  13930. }
  13931. return new Uint16Array(indicesLengthOrArray);
  13932. };
  13933. /**
  13934. * Creates a typed array from a source array buffer. The resulting typed array will store indices, using either <code><Uint16Array</code>
  13935. * or <code>Uint32Array</code> depending on the number of vertices.
  13936. *
  13937. * @param {Number} numberOfVertices Number of vertices that the indices will reference.
  13938. * @param {ArrayBuffer} sourceArray Passed through to the typed array constructor.
  13939. * @param {Number} byteOffset Passed through to the typed array constructor.
  13940. * @param {Number} length Passed through to the typed array constructor.
  13941. * @returns {Uint16Array|Uint32Array} A <code>Uint16Array</code> or <code>Uint32Array</code> constructed with <code>sourceArray</code>, <code>byteOffset</code>, and <code>length</code>.
  13942. *
  13943. */
  13944. IndexDatatype.createTypedArrayFromArrayBuffer = function(numberOfVertices, sourceArray, byteOffset, length) {
  13945. if (!defined(numberOfVertices)) {
  13946. throw new DeveloperError('numberOfVertices is required.');
  13947. }
  13948. if (!defined(sourceArray)) {
  13949. throw new DeveloperError('sourceArray is required.');
  13950. }
  13951. if (!defined(byteOffset)) {
  13952. throw new DeveloperError('byteOffset is required.');
  13953. }
  13954. if (numberOfVertices >= CesiumMath.SIXTY_FOUR_KILOBYTES) {
  13955. return new Uint32Array(sourceArray, byteOffset, length);
  13956. }
  13957. return new Uint16Array(sourceArray, byteOffset, length);
  13958. };
  13959. return freezeObject(IndexDatatype);
  13960. });
  13961. /*global define*/
  13962. define('Core/EllipsoidGeodesic',[
  13963. './Cartesian3',
  13964. './Cartographic',
  13965. './defaultValue',
  13966. './defined',
  13967. './defineProperties',
  13968. './DeveloperError',
  13969. './Ellipsoid',
  13970. './Math'
  13971. ], function(
  13972. Cartesian3,
  13973. Cartographic,
  13974. defaultValue,
  13975. defined,
  13976. defineProperties,
  13977. DeveloperError,
  13978. Ellipsoid,
  13979. CesiumMath) {
  13980. 'use strict';
  13981. function setConstants(ellipsoidGeodesic) {
  13982. var uSquared = ellipsoidGeodesic._uSquared;
  13983. var a = ellipsoidGeodesic._ellipsoid.maximumRadius;
  13984. var b = ellipsoidGeodesic._ellipsoid.minimumRadius;
  13985. var f = (a - b) / a;
  13986. var cosineHeading = Math.cos(ellipsoidGeodesic._startHeading);
  13987. var sineHeading = Math.sin(ellipsoidGeodesic._startHeading);
  13988. var tanU = (1 - f) * Math.tan(ellipsoidGeodesic._start.latitude);
  13989. var cosineU = 1.0 / Math.sqrt(1.0 + tanU * tanU);
  13990. var sineU = cosineU * tanU;
  13991. var sigma = Math.atan2(tanU, cosineHeading);
  13992. var sineAlpha = cosineU * sineHeading;
  13993. var sineSquaredAlpha = sineAlpha * sineAlpha;
  13994. var cosineSquaredAlpha = 1.0 - sineSquaredAlpha;
  13995. var cosineAlpha = Math.sqrt(cosineSquaredAlpha);
  13996. var u2Over4 = uSquared / 4.0;
  13997. var u4Over16 = u2Over4 * u2Over4;
  13998. var u6Over64 = u4Over16 * u2Over4;
  13999. var u8Over256 = u4Over16 * u4Over16;
  14000. var a0 = (1.0 + u2Over4 - 3.0 * u4Over16 / 4.0 + 5.0 * u6Over64 / 4.0 - 175.0 * u8Over256 / 64.0);
  14001. var a1 = (1.0 - u2Over4 + 15.0 * u4Over16 / 8.0 - 35.0 * u6Over64 / 8.0);
  14002. var a2 = (1.0 - 3.0 * u2Over4 + 35.0 * u4Over16 / 4.0);
  14003. var a3 = (1.0 - 5.0 * u2Over4);
  14004. var distanceRatio = a0 * sigma - a1 * Math.sin(2.0 * sigma) * u2Over4 / 2.0 - a2 * Math.sin(4.0 * sigma) * u4Over16 / 16.0 -
  14005. a3 * Math.sin(6.0 * sigma) * u6Over64 / 48.0 - Math.sin(8.0 * sigma) * 5.0 * u8Over256 / 512;
  14006. var constants = ellipsoidGeodesic._constants;
  14007. constants.a = a;
  14008. constants.b = b;
  14009. constants.f = f;
  14010. constants.cosineHeading = cosineHeading;
  14011. constants.sineHeading = sineHeading;
  14012. constants.tanU = tanU;
  14013. constants.cosineU = cosineU;
  14014. constants.sineU = sineU;
  14015. constants.sigma = sigma;
  14016. constants.sineAlpha = sineAlpha;
  14017. constants.sineSquaredAlpha = sineSquaredAlpha;
  14018. constants.cosineSquaredAlpha = cosineSquaredAlpha;
  14019. constants.cosineAlpha = cosineAlpha;
  14020. constants.u2Over4 = u2Over4;
  14021. constants.u4Over16 = u4Over16;
  14022. constants.u6Over64 = u6Over64;
  14023. constants.u8Over256 = u8Over256;
  14024. constants.a0 = a0;
  14025. constants.a1 = a1;
  14026. constants.a2 = a2;
  14027. constants.a3 = a3;
  14028. constants.distanceRatio = distanceRatio;
  14029. }
  14030. function computeC(f, cosineSquaredAlpha) {
  14031. return f * cosineSquaredAlpha * (4.0 + f * (4.0 - 3.0 * cosineSquaredAlpha)) / 16.0;
  14032. }
  14033. function computeDeltaLambda(f, sineAlpha, cosineSquaredAlpha, sigma, sineSigma, cosineSigma, cosineTwiceSigmaMidpoint) {
  14034. var C = computeC(f, cosineSquaredAlpha);
  14035. return (1.0 - C) * f * sineAlpha * (sigma + C * sineSigma * (cosineTwiceSigmaMidpoint +
  14036. C * cosineSigma * (2.0 * cosineTwiceSigmaMidpoint * cosineTwiceSigmaMidpoint - 1.0)));
  14037. }
  14038. function vincentyInverseFormula(ellipsoidGeodesic, major, minor, firstLongitude, firstLatitude, secondLongitude, secondLatitude) {
  14039. var eff = (major - minor) / major;
  14040. var l = secondLongitude - firstLongitude;
  14041. var u1 = Math.atan((1 - eff) * Math.tan(firstLatitude));
  14042. var u2 = Math.atan((1 - eff) * Math.tan(secondLatitude));
  14043. var cosineU1 = Math.cos(u1);
  14044. var sineU1 = Math.sin(u1);
  14045. var cosineU2 = Math.cos(u2);
  14046. var sineU2 = Math.sin(u2);
  14047. var cc = cosineU1 * cosineU2;
  14048. var cs = cosineU1 * sineU2;
  14049. var ss = sineU1 * sineU2;
  14050. var sc = sineU1 * cosineU2;
  14051. var lambda = l;
  14052. var lambdaDot = CesiumMath.TWO_PI;
  14053. var cosineLambda = Math.cos(lambda);
  14054. var sineLambda = Math.sin(lambda);
  14055. var sigma;
  14056. var cosineSigma;
  14057. var sineSigma;
  14058. var cosineSquaredAlpha;
  14059. var cosineTwiceSigmaMidpoint;
  14060. do {
  14061. cosineLambda = Math.cos(lambda);
  14062. sineLambda = Math.sin(lambda);
  14063. var temp = cs - sc * cosineLambda;
  14064. sineSigma = Math.sqrt(cosineU2 * cosineU2 * sineLambda * sineLambda + temp * temp);
  14065. cosineSigma = ss + cc * cosineLambda;
  14066. sigma = Math.atan2(sineSigma, cosineSigma);
  14067. var sineAlpha;
  14068. if (sineSigma === 0.0) {
  14069. sineAlpha = 0.0;
  14070. cosineSquaredAlpha = 1.0;
  14071. } else {
  14072. sineAlpha = cc * sineLambda / sineSigma;
  14073. cosineSquaredAlpha = 1.0 - sineAlpha * sineAlpha;
  14074. }
  14075. lambdaDot = lambda;
  14076. cosineTwiceSigmaMidpoint = cosineSigma - 2.0 * ss / cosineSquaredAlpha;
  14077. if (isNaN(cosineTwiceSigmaMidpoint)) {
  14078. cosineTwiceSigmaMidpoint = 0.0;
  14079. }
  14080. lambda = l + computeDeltaLambda(eff, sineAlpha, cosineSquaredAlpha,
  14081. sigma, sineSigma, cosineSigma, cosineTwiceSigmaMidpoint);
  14082. } while (Math.abs(lambda - lambdaDot) > CesiumMath.EPSILON12);
  14083. var uSquared = cosineSquaredAlpha * (major * major - minor * minor) / (minor * minor);
  14084. var A = 1.0 + uSquared * (4096.0 + uSquared * (uSquared * (320.0 - 175.0 * uSquared) - 768.0)) / 16384.0;
  14085. var B = uSquared * (256.0 + uSquared * (uSquared * (74.0 - 47.0 * uSquared) - 128.0)) / 1024.0;
  14086. var cosineSquaredTwiceSigmaMidpoint = cosineTwiceSigmaMidpoint * cosineTwiceSigmaMidpoint;
  14087. var deltaSigma = B * sineSigma * (cosineTwiceSigmaMidpoint + B * (cosineSigma *
  14088. (2.0 * cosineSquaredTwiceSigmaMidpoint - 1.0) - B * cosineTwiceSigmaMidpoint *
  14089. (4.0 * sineSigma * sineSigma - 3.0) * (4.0 * cosineSquaredTwiceSigmaMidpoint - 3.0) / 6.0) / 4.0);
  14090. var distance = minor * A * (sigma - deltaSigma);
  14091. var startHeading = Math.atan2(cosineU2 * sineLambda, cs - sc * cosineLambda);
  14092. var endHeading = Math.atan2(cosineU1 * sineLambda, cs * cosineLambda - sc);
  14093. ellipsoidGeodesic._distance = distance;
  14094. ellipsoidGeodesic._startHeading = startHeading;
  14095. ellipsoidGeodesic._endHeading = endHeading;
  14096. ellipsoidGeodesic._uSquared = uSquared;
  14097. }
  14098. function computeProperties(ellipsoidGeodesic, start, end, ellipsoid) {
  14099. var firstCartesian = Cartesian3.normalize(ellipsoid.cartographicToCartesian(start, scratchCart2), scratchCart1);
  14100. var lastCartesian = Cartesian3.normalize(ellipsoid.cartographicToCartesian(end, scratchCart2), scratchCart2);
  14101. if (Math.abs(Math.abs(Cartesian3.angleBetween(firstCartesian, lastCartesian)) - Math.PI) < 0.0125) {
  14102. throw new DeveloperError('geodesic position is not unique');
  14103. }
  14104. vincentyInverseFormula(ellipsoidGeodesic, ellipsoid.maximumRadius, ellipsoid.minimumRadius,
  14105. start.longitude, start.latitude, end.longitude, end.latitude);
  14106. ellipsoidGeodesic._start = Cartographic.clone(start, ellipsoidGeodesic._start);
  14107. ellipsoidGeodesic._end = Cartographic.clone(end, ellipsoidGeodesic._end);
  14108. ellipsoidGeodesic._start.height = 0;
  14109. ellipsoidGeodesic._end.height = 0;
  14110. setConstants(ellipsoidGeodesic);
  14111. }
  14112. var scratchCart1 = new Cartesian3();
  14113. var scratchCart2 = new Cartesian3();
  14114. /**
  14115. * Initializes a geodesic on the ellipsoid connecting the two provided planetodetic points.
  14116. *
  14117. * @alias EllipsoidGeodesic
  14118. * @constructor
  14119. *
  14120. * @param {Cartographic} [start] The initial planetodetic point on the path.
  14121. * @param {Cartographic} [end] The final planetodetic point on the path.
  14122. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the geodesic lies.
  14123. */
  14124. function EllipsoidGeodesic(start, end, ellipsoid) {
  14125. var e = defaultValue(ellipsoid, Ellipsoid.WGS84);
  14126. this._ellipsoid = e;
  14127. this._start = new Cartographic();
  14128. this._end = new Cartographic();
  14129. this._constants = {};
  14130. this._startHeading = undefined;
  14131. this._endHeading = undefined;
  14132. this._distance = undefined;
  14133. this._uSquared = undefined;
  14134. if (defined(start) && defined(end)) {
  14135. computeProperties(this, start, end, e);
  14136. }
  14137. }
  14138. defineProperties(EllipsoidGeodesic.prototype, {
  14139. /**
  14140. * Gets the ellipsoid.
  14141. * @memberof EllipsoidGeodesic.prototype
  14142. * @type {Ellipsoid}
  14143. * @readonly
  14144. */
  14145. ellipsoid : {
  14146. get : function() {
  14147. return this._ellipsoid;
  14148. }
  14149. },
  14150. /**
  14151. * Gets the surface distance between the start and end point
  14152. * @memberof EllipsoidGeodesic.prototype
  14153. * @type {Number}
  14154. * @readonly
  14155. */
  14156. surfaceDistance : {
  14157. get : function() {
  14158. if (!defined(this._distance)) {
  14159. throw new DeveloperError('set end positions before getting surfaceDistance');
  14160. }
  14161. return this._distance;
  14162. }
  14163. },
  14164. /**
  14165. * Gets the initial planetodetic point on the path.
  14166. * @memberof EllipsoidGeodesic.prototype
  14167. * @type {Cartographic}
  14168. * @readonly
  14169. */
  14170. start : {
  14171. get : function() {
  14172. return this._start;
  14173. }
  14174. },
  14175. /**
  14176. * Gets the final planetodetic point on the path.
  14177. * @memberof EllipsoidGeodesic.prototype
  14178. * @type {Cartographic}
  14179. * @readonly
  14180. */
  14181. end : {
  14182. get : function() {
  14183. return this._end;
  14184. }
  14185. },
  14186. /**
  14187. * Gets the heading at the initial point.
  14188. * @memberof EllipsoidGeodesic.prototype
  14189. * @type {Number}
  14190. * @readonly
  14191. */
  14192. startHeading : {
  14193. get : function() {
  14194. if (!defined(this._distance)) {
  14195. throw new DeveloperError('set end positions before getting startHeading');
  14196. }
  14197. return this._startHeading;
  14198. }
  14199. },
  14200. /**
  14201. * Gets the heading at the final point.
  14202. * @memberof EllipsoidGeodesic.prototype
  14203. * @type {Number}
  14204. * @readonly
  14205. */
  14206. endHeading : {
  14207. get : function() {
  14208. if (!defined(this._distance)) {
  14209. throw new DeveloperError('set end positions before getting endHeading');
  14210. }
  14211. return this._endHeading;
  14212. }
  14213. }
  14214. });
  14215. /**
  14216. * Sets the start and end points of the geodesic
  14217. *
  14218. * @param {Cartographic} start The initial planetodetic point on the path.
  14219. * @param {Cartographic} end The final planetodetic point on the path.
  14220. */
  14221. EllipsoidGeodesic.prototype.setEndPoints = function(start, end) {
  14222. if (!defined(start)) {
  14223. throw new DeveloperError('start cartographic position is required');
  14224. }
  14225. if (!defined(end)) {
  14226. throw new DeveloperError('end cartgraphic position is required');
  14227. }
  14228. computeProperties(this, start, end, this._ellipsoid);
  14229. };
  14230. /**
  14231. * Provides the location of a point at the indicated portion along the geodesic.
  14232. *
  14233. * @param {Number} fraction The portion of the distance between the initial and final points.
  14234. * @returns {Cartographic} The location of the point along the geodesic.
  14235. */
  14236. EllipsoidGeodesic.prototype.interpolateUsingFraction = function(fraction, result) {
  14237. return this.interpolateUsingSurfaceDistance(this._distance * fraction, result);
  14238. };
  14239. /**
  14240. * Provides the location of a point at the indicated distance along the geodesic.
  14241. *
  14242. * @param {Number} distance The distance from the inital point to the point of interest along the geodesic
  14243. * @returns {Cartographic} The location of the point along the geodesic.
  14244. *
  14245. * @exception {DeveloperError} start and end must be set before calling function interpolateUsingSurfaceDistance
  14246. */
  14247. EllipsoidGeodesic.prototype.interpolateUsingSurfaceDistance = function(distance, result) {
  14248. if (!defined(this._distance)) {
  14249. throw new DeveloperError('start and end must be set before calling function interpolateUsingSurfaceDistance');
  14250. }
  14251. var constants = this._constants;
  14252. var s = constants.distanceRatio + distance / constants.b;
  14253. var cosine2S = Math.cos(2.0 * s);
  14254. var cosine4S = Math.cos(4.0 * s);
  14255. var cosine6S = Math.cos(6.0 * s);
  14256. var sine2S = Math.sin(2.0 * s);
  14257. var sine4S = Math.sin(4.0 * s);
  14258. var sine6S = Math.sin(6.0 * s);
  14259. var sine8S = Math.sin(8.0 * s);
  14260. var s2 = s * s;
  14261. var s3 = s * s2;
  14262. var u8Over256 = constants.u8Over256;
  14263. var u2Over4 = constants.u2Over4;
  14264. var u6Over64 = constants.u6Over64;
  14265. var u4Over16 = constants.u4Over16;
  14266. var sigma = 2.0 * s3 * u8Over256 * cosine2S / 3.0 +
  14267. s * (1.0 - u2Over4 + 7.0 * u4Over16 / 4.0 - 15.0 * u6Over64 / 4.0 + 579.0 * u8Over256 / 64.0 -
  14268. (u4Over16 - 15.0 * u6Over64 / 4.0 + 187.0 * u8Over256 / 16.0) * cosine2S -
  14269. (5.0 * u6Over64 / 4.0 - 115.0 * u8Over256 / 16.0) * cosine4S -
  14270. 29.0 * u8Over256 * cosine6S / 16.0) +
  14271. (u2Over4 / 2.0 - u4Over16 + 71.0 * u6Over64 / 32.0 - 85.0 * u8Over256 / 16.0) * sine2S +
  14272. (5.0 * u4Over16 / 16.0 - 5.0 * u6Over64 / 4.0 + 383.0 * u8Over256 / 96.0) * sine4S -
  14273. s2 * ((u6Over64 - 11.0 * u8Over256 / 2.0) * sine2S + 5.0 * u8Over256 * sine4S / 2.0) +
  14274. (29.0 * u6Over64 / 96.0 - 29.0 * u8Over256 / 16.0) * sine6S +
  14275. 539.0 * u8Over256 * sine8S / 1536.0;
  14276. var theta = Math.asin(Math.sin(sigma) * constants.cosineAlpha);
  14277. var latitude = Math.atan(constants.a / constants.b * Math.tan(theta));
  14278. // Redefine in terms of relative argument of latitude.
  14279. sigma = sigma - constants.sigma;
  14280. var cosineTwiceSigmaMidpoint = Math.cos(2.0 * constants.sigma + sigma);
  14281. var sineSigma = Math.sin(sigma);
  14282. var cosineSigma = Math.cos(sigma);
  14283. var cc = constants.cosineU * cosineSigma;
  14284. var ss = constants.sineU * sineSigma;
  14285. var lambda = Math.atan2(sineSigma * constants.sineHeading, cc - ss * constants.cosineHeading);
  14286. var l = lambda - computeDeltaLambda(constants.f, constants.sineAlpha, constants.cosineSquaredAlpha,
  14287. sigma, sineSigma, cosineSigma, cosineTwiceSigmaMidpoint);
  14288. if (defined(result)) {
  14289. result.longitude = this._start.longitude + l;
  14290. result.latitude = latitude;
  14291. result.height = 0.0;
  14292. return result;
  14293. }
  14294. return new Cartographic(this._start.longitude + l, latitude, 0.0);
  14295. };
  14296. return EllipsoidGeodesic;
  14297. });
  14298. /*global define*/
  14299. define('Core/QuadraticRealPolynomial',[
  14300. './DeveloperError',
  14301. './Math'
  14302. ], function(
  14303. DeveloperError,
  14304. CesiumMath) {
  14305. 'use strict';
  14306. /**
  14307. * Defines functions for 2nd order polynomial functions of one variable with only real coefficients.
  14308. *
  14309. * @exports QuadraticRealPolynomial
  14310. */
  14311. var QuadraticRealPolynomial = {};
  14312. /**
  14313. * Provides the discriminant of the quadratic equation from the supplied coefficients.
  14314. *
  14315. * @param {Number} a The coefficient of the 2nd order monomial.
  14316. * @param {Number} b The coefficient of the 1st order monomial.
  14317. * @param {Number} c The coefficient of the 0th order monomial.
  14318. * @returns {Number} The value of the discriminant.
  14319. */
  14320. QuadraticRealPolynomial.computeDiscriminant = function(a, b, c) {
  14321. if (typeof a !== 'number') {
  14322. throw new DeveloperError('a is a required number.');
  14323. }
  14324. if (typeof b !== 'number') {
  14325. throw new DeveloperError('b is a required number.');
  14326. }
  14327. if (typeof c !== 'number') {
  14328. throw new DeveloperError('c is a required number.');
  14329. }
  14330. var discriminant = b * b - 4.0 * a * c;
  14331. return discriminant;
  14332. };
  14333. function addWithCancellationCheck(left, right, tolerance) {
  14334. var difference = left + right;
  14335. if ((CesiumMath.sign(left) !== CesiumMath.sign(right)) &&
  14336. Math.abs(difference / Math.max(Math.abs(left), Math.abs(right))) < tolerance) {
  14337. return 0.0;
  14338. }
  14339. return difference;
  14340. }
  14341. /**
  14342. * Provides the real valued roots of the quadratic polynomial with the provided coefficients.
  14343. *
  14344. * @param {Number} a The coefficient of the 2nd order monomial.
  14345. * @param {Number} b The coefficient of the 1st order monomial.
  14346. * @param {Number} c The coefficient of the 0th order monomial.
  14347. * @returns {Number[]} The real valued roots.
  14348. */
  14349. QuadraticRealPolynomial.computeRealRoots = function(a, b, c) {
  14350. if (typeof a !== 'number') {
  14351. throw new DeveloperError('a is a required number.');
  14352. }
  14353. if (typeof b !== 'number') {
  14354. throw new DeveloperError('b is a required number.');
  14355. }
  14356. if (typeof c !== 'number') {
  14357. throw new DeveloperError('c is a required number.');
  14358. }
  14359. var ratio;
  14360. if (a === 0.0) {
  14361. if (b === 0.0) {
  14362. // Constant function: c = 0.
  14363. return [];
  14364. }
  14365. // Linear function: b * x + c = 0.
  14366. return [-c / b];
  14367. } else if (b === 0.0) {
  14368. if (c === 0.0) {
  14369. // 2nd order monomial: a * x^2 = 0.
  14370. return [0.0, 0.0];
  14371. }
  14372. var cMagnitude = Math.abs(c);
  14373. var aMagnitude = Math.abs(a);
  14374. if ((cMagnitude < aMagnitude) && (cMagnitude / aMagnitude < CesiumMath.EPSILON14)) { // c ~= 0.0.
  14375. // 2nd order monomial: a * x^2 = 0.
  14376. return [0.0, 0.0];
  14377. } else if ((cMagnitude > aMagnitude) && (aMagnitude / cMagnitude < CesiumMath.EPSILON14)) { // a ~= 0.0.
  14378. // Constant function: c = 0.
  14379. return [];
  14380. }
  14381. // a * x^2 + c = 0
  14382. ratio = -c / a;
  14383. if (ratio < 0.0) {
  14384. // Both roots are complex.
  14385. return [];
  14386. }
  14387. // Both roots are real.
  14388. var root = Math.sqrt(ratio);
  14389. return [-root, root];
  14390. } else if (c === 0.0) {
  14391. // a * x^2 + b * x = 0
  14392. ratio = -b / a;
  14393. if (ratio < 0.0) {
  14394. return [ratio, 0.0];
  14395. }
  14396. return [0.0, ratio];
  14397. }
  14398. // a * x^2 + b * x + c = 0
  14399. var b2 = b * b;
  14400. var four_ac = 4.0 * a * c;
  14401. var radicand = addWithCancellationCheck(b2, -four_ac, CesiumMath.EPSILON14);
  14402. if (radicand < 0.0) {
  14403. // Both roots are complex.
  14404. return [];
  14405. }
  14406. var q = -0.5 * addWithCancellationCheck(b, CesiumMath.sign(b) * Math.sqrt(radicand), CesiumMath.EPSILON14);
  14407. if (b > 0.0) {
  14408. return [q / a, c / q];
  14409. }
  14410. return [c / q, q / a];
  14411. };
  14412. return QuadraticRealPolynomial;
  14413. });
  14414. /*global define*/
  14415. define('Core/CubicRealPolynomial',[
  14416. './DeveloperError',
  14417. './QuadraticRealPolynomial'
  14418. ], function(
  14419. DeveloperError,
  14420. QuadraticRealPolynomial) {
  14421. 'use strict';
  14422. /**
  14423. * Defines functions for 3rd order polynomial functions of one variable with only real coefficients.
  14424. *
  14425. * @exports CubicRealPolynomial
  14426. */
  14427. var CubicRealPolynomial = {};
  14428. /**
  14429. * Provides the discriminant of the cubic equation from the supplied coefficients.
  14430. *
  14431. * @param {Number} a The coefficient of the 3rd order monomial.
  14432. * @param {Number} b The coefficient of the 2nd order monomial.
  14433. * @param {Number} c The coefficient of the 1st order monomial.
  14434. * @param {Number} d The coefficient of the 0th order monomial.
  14435. * @returns {Number} The value of the discriminant.
  14436. */
  14437. CubicRealPolynomial.computeDiscriminant = function(a, b, c, d) {
  14438. if (typeof a !== 'number') {
  14439. throw new DeveloperError('a is a required number.');
  14440. }
  14441. if (typeof b !== 'number') {
  14442. throw new DeveloperError('b is a required number.');
  14443. }
  14444. if (typeof c !== 'number') {
  14445. throw new DeveloperError('c is a required number.');
  14446. }
  14447. if (typeof d !== 'number') {
  14448. throw new DeveloperError('d is a required number.');
  14449. }
  14450. var a2 = a * a;
  14451. var b2 = b * b;
  14452. var c2 = c * c;
  14453. var d2 = d * d;
  14454. var discriminant = 18.0 * a * b * c * d + b2 * c2 - 27.0 * a2 * d2 - 4.0 * (a * c2 * c + b2 * b * d);
  14455. return discriminant;
  14456. };
  14457. function computeRealRoots(a, b, c, d) {
  14458. var A = a;
  14459. var B = b / 3.0;
  14460. var C = c / 3.0;
  14461. var D = d;
  14462. var AC = A * C;
  14463. var BD = B * D;
  14464. var B2 = B * B;
  14465. var C2 = C * C;
  14466. var delta1 = A * C - B2;
  14467. var delta2 = A * D - B * C;
  14468. var delta3 = B * D - C2;
  14469. var discriminant = 4.0 * delta1 * delta3 - delta2 * delta2;
  14470. var temp;
  14471. var temp1;
  14472. if (discriminant < 0.0) {
  14473. var ABar;
  14474. var CBar;
  14475. var DBar;
  14476. if (B2 * BD >= AC * C2) {
  14477. ABar = A;
  14478. CBar = delta1;
  14479. DBar = -2.0 * B * delta1 + A * delta2;
  14480. } else {
  14481. ABar = D;
  14482. CBar = delta3;
  14483. DBar = -D * delta2 + 2.0 * C * delta3;
  14484. }
  14485. var s = (DBar < 0.0) ? -1.0 : 1.0; // This is not Math.Sign()!
  14486. var temp0 = -s * Math.abs(ABar) * Math.sqrt(-discriminant);
  14487. temp1 = -DBar + temp0;
  14488. var x = temp1 / 2.0;
  14489. var p = x < 0.0 ? -Math.pow(-x, 1.0 / 3.0) : Math.pow(x, 1.0 / 3.0);
  14490. var q = (temp1 === temp0) ? -p : -CBar / p;
  14491. temp = (CBar <= 0.0) ? p + q : -DBar / (p * p + q * q + CBar);
  14492. if (B2 * BD >= AC * C2) {
  14493. return [(temp - B) / A];
  14494. }
  14495. return [-D / (temp + C)];
  14496. }
  14497. var CBarA = delta1;
  14498. var DBarA = -2.0 * B * delta1 + A * delta2;
  14499. var CBarD = delta3;
  14500. var DBarD = -D * delta2 + 2.0 * C * delta3;
  14501. var squareRootOfDiscriminant = Math.sqrt(discriminant);
  14502. var halfSquareRootOf3 = Math.sqrt(3.0) / 2.0;
  14503. var theta = Math.abs(Math.atan2(A * squareRootOfDiscriminant, -DBarA) / 3.0);
  14504. temp = 2.0 * Math.sqrt(-CBarA);
  14505. var cosine = Math.cos(theta);
  14506. temp1 = temp * cosine;
  14507. var temp3 = temp * (-cosine / 2.0 - halfSquareRootOf3 * Math.sin(theta));
  14508. var numeratorLarge = (temp1 + temp3 > 2.0 * B) ? temp1 - B : temp3 - B;
  14509. var denominatorLarge = A;
  14510. var root1 = numeratorLarge / denominatorLarge;
  14511. theta = Math.abs(Math.atan2(D * squareRootOfDiscriminant, -DBarD) / 3.0);
  14512. temp = 2.0 * Math.sqrt(-CBarD);
  14513. cosine = Math.cos(theta);
  14514. temp1 = temp * cosine;
  14515. temp3 = temp * (-cosine / 2.0 - halfSquareRootOf3 * Math.sin(theta));
  14516. var numeratorSmall = -D;
  14517. var denominatorSmall = (temp1 + temp3 < 2.0 * C) ? temp1 + C : temp3 + C;
  14518. var root3 = numeratorSmall / denominatorSmall;
  14519. var E = denominatorLarge * denominatorSmall;
  14520. var F = -numeratorLarge * denominatorSmall - denominatorLarge * numeratorSmall;
  14521. var G = numeratorLarge * numeratorSmall;
  14522. var root2 = (C * F - B * G) / (-B * F + C * E);
  14523. if (root1 <= root2) {
  14524. if (root1 <= root3) {
  14525. if (root2 <= root3) {
  14526. return [root1, root2, root3];
  14527. }
  14528. return [root1, root3, root2];
  14529. }
  14530. return [root3, root1, root2];
  14531. }
  14532. if (root1 <= root3) {
  14533. return [root2, root1, root3];
  14534. }
  14535. if (root2 <= root3) {
  14536. return [root2, root3, root1];
  14537. }
  14538. return [root3, root2, root1];
  14539. }
  14540. /**
  14541. * Provides the real valued roots of the cubic polynomial with the provided coefficients.
  14542. *
  14543. * @param {Number} a The coefficient of the 3rd order monomial.
  14544. * @param {Number} b The coefficient of the 2nd order monomial.
  14545. * @param {Number} c The coefficient of the 1st order monomial.
  14546. * @param {Number} d The coefficient of the 0th order monomial.
  14547. * @returns {Number[]} The real valued roots.
  14548. */
  14549. CubicRealPolynomial.computeRealRoots = function(a, b, c, d) {
  14550. if (typeof a !== 'number') {
  14551. throw new DeveloperError('a is a required number.');
  14552. }
  14553. if (typeof b !== 'number') {
  14554. throw new DeveloperError('b is a required number.');
  14555. }
  14556. if (typeof c !== 'number') {
  14557. throw new DeveloperError('c is a required number.');
  14558. }
  14559. if (typeof d !== 'number') {
  14560. throw new DeveloperError('d is a required number.');
  14561. }
  14562. var roots;
  14563. var ratio;
  14564. if (a === 0.0) {
  14565. // Quadratic function: b * x^2 + c * x + d = 0.
  14566. return QuadraticRealPolynomial.computeRealRoots(b, c, d);
  14567. } else if (b === 0.0) {
  14568. if (c === 0.0) {
  14569. if (d === 0.0) {
  14570. // 3rd order monomial: a * x^3 = 0.
  14571. return [0.0, 0.0, 0.0];
  14572. }
  14573. // a * x^3 + d = 0
  14574. ratio = -d / a;
  14575. var root = (ratio < 0.0) ? -Math.pow(-ratio, 1.0 / 3.0) : Math.pow(ratio, 1.0 / 3.0);
  14576. return [root, root, root];
  14577. } else if (d === 0.0) {
  14578. // x * (a * x^2 + c) = 0.
  14579. roots = QuadraticRealPolynomial.computeRealRoots(a, 0, c);
  14580. // Return the roots in ascending order.
  14581. if (roots.Length === 0) {
  14582. return [0.0];
  14583. }
  14584. return [roots[0], 0.0, roots[1]];
  14585. }
  14586. // Deflated cubic polynomial: a * x^3 + c * x + d= 0.
  14587. return computeRealRoots(a, 0, c, d);
  14588. } else if (c === 0.0) {
  14589. if (d === 0.0) {
  14590. // x^2 * (a * x + b) = 0.
  14591. ratio = -b / a;
  14592. if (ratio < 0.0) {
  14593. return [ratio, 0.0, 0.0];
  14594. }
  14595. return [0.0, 0.0, ratio];
  14596. }
  14597. // a * x^3 + b * x^2 + d = 0.
  14598. return computeRealRoots(a, b, 0, d);
  14599. } else if (d === 0.0) {
  14600. // x * (a * x^2 + b * x + c) = 0
  14601. roots = QuadraticRealPolynomial.computeRealRoots(a, b, c);
  14602. // Return the roots in ascending order.
  14603. if (roots.length === 0) {
  14604. return [0.0];
  14605. } else if (roots[1] <= 0.0) {
  14606. return [roots[0], roots[1], 0.0];
  14607. } else if (roots[0] >= 0.0) {
  14608. return [0.0, roots[0], roots[1]];
  14609. }
  14610. return [roots[0], 0.0, roots[1]];
  14611. }
  14612. return computeRealRoots(a, b, c, d);
  14613. };
  14614. return CubicRealPolynomial;
  14615. });
  14616. /*global define*/
  14617. define('Core/QuarticRealPolynomial',[
  14618. './CubicRealPolynomial',
  14619. './DeveloperError',
  14620. './Math',
  14621. './QuadraticRealPolynomial'
  14622. ], function(
  14623. CubicRealPolynomial,
  14624. DeveloperError,
  14625. CesiumMath,
  14626. QuadraticRealPolynomial) {
  14627. 'use strict';
  14628. /**
  14629. * Defines functions for 4th order polynomial functions of one variable with only real coefficients.
  14630. *
  14631. * @exports QuarticRealPolynomial
  14632. */
  14633. var QuarticRealPolynomial = {};
  14634. /**
  14635. * Provides the discriminant of the quartic equation from the supplied coefficients.
  14636. *
  14637. * @param {Number} a The coefficient of the 4th order monomial.
  14638. * @param {Number} b The coefficient of the 3rd order monomial.
  14639. * @param {Number} c The coefficient of the 2nd order monomial.
  14640. * @param {Number} d The coefficient of the 1st order monomial.
  14641. * @param {Number} e The coefficient of the 0th order monomial.
  14642. * @returns {Number} The value of the discriminant.
  14643. */
  14644. QuarticRealPolynomial.computeDiscriminant = function(a, b, c, d, e) {
  14645. if (typeof a !== 'number') {
  14646. throw new DeveloperError('a is a required number.');
  14647. }
  14648. if (typeof b !== 'number') {
  14649. throw new DeveloperError('b is a required number.');
  14650. }
  14651. if (typeof c !== 'number') {
  14652. throw new DeveloperError('c is a required number.');
  14653. }
  14654. if (typeof d !== 'number') {
  14655. throw new DeveloperError('d is a required number.');
  14656. }
  14657. if (typeof e !== 'number') {
  14658. throw new DeveloperError('e is a required number.');
  14659. }
  14660. var a2 = a * a;
  14661. var a3 = a2 * a;
  14662. var b2 = b * b;
  14663. var b3 = b2 * b;
  14664. var c2 = c * c;
  14665. var c3 = c2 * c;
  14666. var d2 = d * d;
  14667. var d3 = d2 * d;
  14668. var e2 = e * e;
  14669. var e3 = e2 * e;
  14670. var discriminant = (b2 * c2 * d2 - 4.0 * b3 * d3 - 4.0 * a * c3 * d2 + 18 * a * b * c * d3 - 27.0 * a2 * d2 * d2 + 256.0 * a3 * e3) +
  14671. e * (18.0 * b3 * c * d - 4.0 * b2 * c3 + 16.0 * a * c2 * c2 - 80.0 * a * b * c2 * d - 6.0 * a * b2 * d2 + 144.0 * a2 * c * d2) +
  14672. e2 * (144.0 * a * b2 * c - 27.0 * b2 * b2 - 128.0 * a2 * c2 - 192.0 * a2 * b * d);
  14673. return discriminant;
  14674. };
  14675. function original(a3, a2, a1, a0) {
  14676. var a3Squared = a3 * a3;
  14677. var p = a2 - 3.0 * a3Squared / 8.0;
  14678. var q = a1 - a2 * a3 / 2.0 + a3Squared * a3 / 8.0;
  14679. var r = a0 - a1 * a3 / 4.0 + a2 * a3Squared / 16.0 - 3.0 * a3Squared * a3Squared / 256.0;
  14680. // Find the roots of the cubic equations: h^6 + 2 p h^4 + (p^2 - 4 r) h^2 - q^2 = 0.
  14681. var cubicRoots = CubicRealPolynomial.computeRealRoots(1.0, 2.0 * p, p * p - 4.0 * r, -q * q);
  14682. if (cubicRoots.length > 0) {
  14683. var temp = -a3 / 4.0;
  14684. // Use the largest positive root.
  14685. var hSquared = cubicRoots[cubicRoots.length - 1];
  14686. if (Math.abs(hSquared) < CesiumMath.EPSILON14) {
  14687. // y^4 + p y^2 + r = 0.
  14688. var roots = QuadraticRealPolynomial.computeRealRoots(1.0, p, r);
  14689. if (roots.length === 2) {
  14690. var root0 = roots[0];
  14691. var root1 = roots[1];
  14692. var y;
  14693. if (root0 >= 0.0 && root1 >= 0.0) {
  14694. var y0 = Math.sqrt(root0);
  14695. var y1 = Math.sqrt(root1);
  14696. return [temp - y1, temp - y0, temp + y0, temp + y1];
  14697. } else if (root0 >= 0.0 && root1 < 0.0) {
  14698. y = Math.sqrt(root0);
  14699. return [temp - y, temp + y];
  14700. } else if (root0 < 0.0 && root1 >= 0.0) {
  14701. y = Math.sqrt(root1);
  14702. return [temp - y, temp + y];
  14703. }
  14704. }
  14705. return [];
  14706. } else if (hSquared > 0.0) {
  14707. var h = Math.sqrt(hSquared);
  14708. var m = (p + hSquared - q / h) / 2.0;
  14709. var n = (p + hSquared + q / h) / 2.0;
  14710. // Now solve the two quadratic factors: (y^2 + h y + m)(y^2 - h y + n);
  14711. var roots1 = QuadraticRealPolynomial.computeRealRoots(1.0, h, m);
  14712. var roots2 = QuadraticRealPolynomial.computeRealRoots(1.0, -h, n);
  14713. if (roots1.length !== 0) {
  14714. roots1[0] += temp;
  14715. roots1[1] += temp;
  14716. if (roots2.length !== 0) {
  14717. roots2[0] += temp;
  14718. roots2[1] += temp;
  14719. if (roots1[1] <= roots2[0]) {
  14720. return [roots1[0], roots1[1], roots2[0], roots2[1]];
  14721. } else if (roots2[1] <= roots1[0]) {
  14722. return [roots2[0], roots2[1], roots1[0], roots1[1]];
  14723. } else if (roots1[0] >= roots2[0] && roots1[1] <= roots2[1]) {
  14724. return [roots2[0], roots1[0], roots1[1], roots2[1]];
  14725. } else if (roots2[0] >= roots1[0] && roots2[1] <= roots1[1]) {
  14726. return [roots1[0], roots2[0], roots2[1], roots1[1]];
  14727. } else if (roots1[0] > roots2[0] && roots1[0] < roots2[1]) {
  14728. return [roots2[0], roots1[0], roots2[1], roots1[1]];
  14729. }
  14730. return [roots1[0], roots2[0], roots1[1], roots2[1]];
  14731. }
  14732. return roots1;
  14733. }
  14734. if (roots2.length !== 0) {
  14735. roots2[0] += temp;
  14736. roots2[1] += temp;
  14737. return roots2;
  14738. }
  14739. return [];
  14740. }
  14741. }
  14742. return [];
  14743. }
  14744. function neumark(a3, a2, a1, a0) {
  14745. var a1Squared = a1 * a1;
  14746. var a2Squared = a2 * a2;
  14747. var a3Squared = a3 * a3;
  14748. var p = -2.0 * a2;
  14749. var q = a1 * a3 + a2Squared - 4.0 * a0;
  14750. var r = a3Squared * a0 - a1 * a2 * a3 + a1Squared;
  14751. var cubicRoots = CubicRealPolynomial.computeRealRoots(1.0, p, q, r);
  14752. if (cubicRoots.length > 0) {
  14753. // Use the most positive root
  14754. var y = cubicRoots[0];
  14755. var temp = (a2 - y);
  14756. var tempSquared = temp * temp;
  14757. var g1 = a3 / 2.0;
  14758. var h1 = temp / 2.0;
  14759. var m = tempSquared - 4.0 * a0;
  14760. var mError = tempSquared + 4.0 * Math.abs(a0);
  14761. var n = a3Squared - 4.0 * y;
  14762. var nError = a3Squared + 4.0 * Math.abs(y);
  14763. var g2;
  14764. var h2;
  14765. if (y < 0.0 || (m * nError < n * mError)) {
  14766. var squareRootOfN = Math.sqrt(n);
  14767. g2 = squareRootOfN / 2.0;
  14768. h2 = squareRootOfN === 0.0 ? 0.0 : (a3 * h1 - a1) / squareRootOfN;
  14769. } else {
  14770. var squareRootOfM = Math.sqrt(m);
  14771. g2 = squareRootOfM === 0.0 ? 0.0 : (a3 * h1 - a1) / squareRootOfM;
  14772. h2 = squareRootOfM / 2.0;
  14773. }
  14774. var G;
  14775. var g;
  14776. if (g1 === 0.0 && g2 === 0.0) {
  14777. G = 0.0;
  14778. g = 0.0;
  14779. } else if (CesiumMath.sign(g1) === CesiumMath.sign(g2)) {
  14780. G = g1 + g2;
  14781. g = y / G;
  14782. } else {
  14783. g = g1 - g2;
  14784. G = y / g;
  14785. }
  14786. var H;
  14787. var h;
  14788. if (h1 === 0.0 && h2 === 0.0) {
  14789. H = 0.0;
  14790. h = 0.0;
  14791. } else if (CesiumMath.sign(h1) === CesiumMath.sign(h2)) {
  14792. H = h1 + h2;
  14793. h = a0 / H;
  14794. } else {
  14795. h = h1 - h2;
  14796. H = a0 / h;
  14797. }
  14798. // Now solve the two quadratic factors: (y^2 + G y + H)(y^2 + g y + h);
  14799. var roots1 = QuadraticRealPolynomial.computeRealRoots(1.0, G, H);
  14800. var roots2 = QuadraticRealPolynomial.computeRealRoots(1.0, g, h);
  14801. if (roots1.length !== 0) {
  14802. if (roots2.length !== 0) {
  14803. if (roots1[1] <= roots2[0]) {
  14804. return [roots1[0], roots1[1], roots2[0], roots2[1]];
  14805. } else if (roots2[1] <= roots1[0]) {
  14806. return [roots2[0], roots2[1], roots1[0], roots1[1]];
  14807. } else if (roots1[0] >= roots2[0] && roots1[1] <= roots2[1]) {
  14808. return [roots2[0], roots1[0], roots1[1], roots2[1]];
  14809. } else if (roots2[0] >= roots1[0] && roots2[1] <= roots1[1]) {
  14810. return [roots1[0], roots2[0], roots2[1], roots1[1]];
  14811. } else if (roots1[0] > roots2[0] && roots1[0] < roots2[1]) {
  14812. return [roots2[0], roots1[0], roots2[1], roots1[1]];
  14813. } else {
  14814. return [roots1[0], roots2[0], roots1[1], roots2[1]];
  14815. }
  14816. }
  14817. return roots1;
  14818. }
  14819. if (roots2.length !== 0) {
  14820. return roots2;
  14821. }
  14822. }
  14823. return [];
  14824. }
  14825. /**
  14826. * Provides the real valued roots of the quartic polynomial with the provided coefficients.
  14827. *
  14828. * @param {Number} a The coefficient of the 4th order monomial.
  14829. * @param {Number} b The coefficient of the 3rd order monomial.
  14830. * @param {Number} c The coefficient of the 2nd order monomial.
  14831. * @param {Number} d The coefficient of the 1st order monomial.
  14832. * @param {Number} e The coefficient of the 0th order monomial.
  14833. * @returns {Number[]} The real valued roots.
  14834. */
  14835. QuarticRealPolynomial.computeRealRoots = function(a, b, c, d, e) {
  14836. if (typeof a !== 'number') {
  14837. throw new DeveloperError('a is a required number.');
  14838. }
  14839. if (typeof b !== 'number') {
  14840. throw new DeveloperError('b is a required number.');
  14841. }
  14842. if (typeof c !== 'number') {
  14843. throw new DeveloperError('c is a required number.');
  14844. }
  14845. if (typeof d !== 'number') {
  14846. throw new DeveloperError('d is a required number.');
  14847. }
  14848. if (typeof e !== 'number') {
  14849. throw new DeveloperError('e is a required number.');
  14850. }
  14851. if (Math.abs(a) < CesiumMath.EPSILON15) {
  14852. return CubicRealPolynomial.computeRealRoots(b, c, d, e);
  14853. }
  14854. var a3 = b / a;
  14855. var a2 = c / a;
  14856. var a1 = d / a;
  14857. var a0 = e / a;
  14858. var k = (a3 < 0.0) ? 1 : 0;
  14859. k += (a2 < 0.0) ? k + 1 : k;
  14860. k += (a1 < 0.0) ? k + 1 : k;
  14861. k += (a0 < 0.0) ? k + 1 : k;
  14862. switch (k) {
  14863. case 0:
  14864. return original(a3, a2, a1, a0);
  14865. case 1:
  14866. return neumark(a3, a2, a1, a0);
  14867. case 2:
  14868. return neumark(a3, a2, a1, a0);
  14869. case 3:
  14870. return original(a3, a2, a1, a0);
  14871. case 4:
  14872. return original(a3, a2, a1, a0);
  14873. case 5:
  14874. return neumark(a3, a2, a1, a0);
  14875. case 6:
  14876. return original(a3, a2, a1, a0);
  14877. case 7:
  14878. return original(a3, a2, a1, a0);
  14879. case 8:
  14880. return neumark(a3, a2, a1, a0);
  14881. case 9:
  14882. return original(a3, a2, a1, a0);
  14883. case 10:
  14884. return original(a3, a2, a1, a0);
  14885. case 11:
  14886. return neumark(a3, a2, a1, a0);
  14887. case 12:
  14888. return original(a3, a2, a1, a0);
  14889. case 13:
  14890. return original(a3, a2, a1, a0);
  14891. case 14:
  14892. return original(a3, a2, a1, a0);
  14893. case 15:
  14894. return original(a3, a2, a1, a0);
  14895. default:
  14896. return undefined;
  14897. }
  14898. };
  14899. return QuarticRealPolynomial;
  14900. });
  14901. /*global define*/
  14902. define('Core/Ray',[
  14903. './Cartesian3',
  14904. './defaultValue',
  14905. './defined',
  14906. './DeveloperError'
  14907. ], function(
  14908. Cartesian3,
  14909. defaultValue,
  14910. defined,
  14911. DeveloperError) {
  14912. 'use strict';
  14913. /**
  14914. * Represents a ray that extends infinitely from the provided origin in the provided direction.
  14915. * @alias Ray
  14916. * @constructor
  14917. *
  14918. * @param {Cartesian3} [origin=Cartesian3.ZERO] The origin of the ray.
  14919. * @param {Cartesian3} [direction=Cartesian3.ZERO] The direction of the ray.
  14920. */
  14921. function Ray(origin, direction) {
  14922. direction = Cartesian3.clone(defaultValue(direction, Cartesian3.ZERO));
  14923. if (!Cartesian3.equals(direction, Cartesian3.ZERO)) {
  14924. Cartesian3.normalize(direction, direction);
  14925. }
  14926. /**
  14927. * The origin of the ray.
  14928. * @type {Cartesian3}
  14929. * @default {@link Cartesian3.ZERO}
  14930. */
  14931. this.origin = Cartesian3.clone(defaultValue(origin, Cartesian3.ZERO));
  14932. /**
  14933. * The direction of the ray.
  14934. * @type {Cartesian3}
  14935. */
  14936. this.direction = direction;
  14937. }
  14938. /**
  14939. * Computes the point along the ray given by r(t) = o + t*d,
  14940. * where o is the origin of the ray and d is the direction.
  14941. *
  14942. * @param {Ray} ray The ray.
  14943. * @param {Number} t A scalar value.
  14944. * @param {Cartesian3} [result] The object in which the result will be stored.
  14945. * @returns {Cartesian3} The modified result parameter, or a new instance if none was provided.
  14946. *
  14947. * @example
  14948. * //Get the first intersection point of a ray and an ellipsoid.
  14949. * var intersection = Cesium.IntersectionTests.rayEllipsoid(ray, ellipsoid);
  14950. * var point = Cesium.Ray.getPoint(ray, intersection.start);
  14951. */
  14952. Ray.getPoint = function(ray, t, result) {
  14953. if (!defined(ray)){
  14954. throw new DeveloperError('ray is requred');
  14955. }
  14956. if (typeof t !== 'number') {
  14957. throw new DeveloperError('t is a required number');
  14958. }
  14959. if (!defined(result)) {
  14960. result = new Cartesian3();
  14961. }
  14962. result = Cartesian3.multiplyByScalar(ray.direction, t, result);
  14963. return Cartesian3.add(ray.origin, result, result);
  14964. };
  14965. return Ray;
  14966. });
  14967. /*global define*/
  14968. define('Core/IntersectionTests',[
  14969. './Cartesian3',
  14970. './Cartographic',
  14971. './defaultValue',
  14972. './defined',
  14973. './DeveloperError',
  14974. './Math',
  14975. './Matrix3',
  14976. './QuadraticRealPolynomial',
  14977. './QuarticRealPolynomial',
  14978. './Ray'
  14979. ], function(
  14980. Cartesian3,
  14981. Cartographic,
  14982. defaultValue,
  14983. defined,
  14984. DeveloperError,
  14985. CesiumMath,
  14986. Matrix3,
  14987. QuadraticRealPolynomial,
  14988. QuarticRealPolynomial,
  14989. Ray) {
  14990. 'use strict';
  14991. /**
  14992. * Functions for computing the intersection between geometries such as rays, planes, triangles, and ellipsoids.
  14993. *
  14994. * @exports IntersectionTests
  14995. */
  14996. var IntersectionTests = {};
  14997. /**
  14998. * Computes the intersection of a ray and a plane.
  14999. *
  15000. * @param {Ray} ray The ray.
  15001. * @param {Plane} plane The plane.
  15002. * @param {Cartesian3} [result] The object onto which to store the result.
  15003. * @returns {Cartesian3} The intersection point or undefined if there is no intersections.
  15004. */
  15005. IntersectionTests.rayPlane = function(ray, plane, result) {
  15006. if (!defined(ray)) {
  15007. throw new DeveloperError('ray is required.');
  15008. }
  15009. if (!defined(plane)) {
  15010. throw new DeveloperError('plane is required.');
  15011. }
  15012. if (!defined(result)) {
  15013. result = new Cartesian3();
  15014. }
  15015. var origin = ray.origin;
  15016. var direction = ray.direction;
  15017. var normal = plane.normal;
  15018. var denominator = Cartesian3.dot(normal, direction);
  15019. if (Math.abs(denominator) < CesiumMath.EPSILON15) {
  15020. // Ray is parallel to plane. The ray may be in the polygon's plane.
  15021. return undefined;
  15022. }
  15023. var t = (-plane.distance - Cartesian3.dot(normal, origin)) / denominator;
  15024. if (t < 0) {
  15025. return undefined;
  15026. }
  15027. result = Cartesian3.multiplyByScalar(direction, t, result);
  15028. return Cartesian3.add(origin, result, result);
  15029. };
  15030. var scratchEdge0 = new Cartesian3();
  15031. var scratchEdge1 = new Cartesian3();
  15032. var scratchPVec = new Cartesian3();
  15033. var scratchTVec = new Cartesian3();
  15034. var scratchQVec = new Cartesian3();
  15035. /**
  15036. * Computes the intersection of a ray and a triangle as a parametric distance along the input ray.
  15037. *
  15038. * Implements {@link https://cadxfem.org/inf/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf|
  15039. * Fast Minimum Storage Ray/Triangle Intersection} by Tomas Moller and Ben Trumbore.
  15040. *
  15041. * @memberof IntersectionTests
  15042. *
  15043. * @param {Ray} ray The ray.
  15044. * @param {Cartesian3} p0 The first vertex of the triangle.
  15045. * @param {Cartesian3} p1 The second vertex of the triangle.
  15046. * @param {Cartesian3} p2 The third vertex of the triangle.
  15047. * @param {Boolean} [cullBackFaces=false] If <code>true</code>, will only compute an intersection with the front face of the triangle
  15048. * and return undefined for intersections with the back face.
  15049. * @returns {Number} The intersection as a parametric distance along the ray, or undefined if there is no intersection.
  15050. */
  15051. IntersectionTests.rayTriangleParametric = function(ray, p0, p1, p2, cullBackFaces) {
  15052. if (!defined(ray)) {
  15053. throw new DeveloperError('ray is required.');
  15054. }
  15055. if (!defined(p0)) {
  15056. throw new DeveloperError('p0 is required.');
  15057. }
  15058. if (!defined(p1)) {
  15059. throw new DeveloperError('p1 is required.');
  15060. }
  15061. if (!defined(p2)) {
  15062. throw new DeveloperError('p2 is required.');
  15063. }
  15064. cullBackFaces = defaultValue(cullBackFaces, false);
  15065. var origin = ray.origin;
  15066. var direction = ray.direction;
  15067. var edge0 = Cartesian3.subtract(p1, p0, scratchEdge0);
  15068. var edge1 = Cartesian3.subtract(p2, p0, scratchEdge1);
  15069. var p = Cartesian3.cross(direction, edge1, scratchPVec);
  15070. var det = Cartesian3.dot(edge0, p);
  15071. var tvec;
  15072. var q;
  15073. var u;
  15074. var v;
  15075. var t;
  15076. if (cullBackFaces) {
  15077. if (det < CesiumMath.EPSILON6) {
  15078. return undefined;
  15079. }
  15080. tvec = Cartesian3.subtract(origin, p0, scratchTVec);
  15081. u = Cartesian3.dot(tvec, p);
  15082. if (u < 0.0 || u > det) {
  15083. return undefined;
  15084. }
  15085. q = Cartesian3.cross(tvec, edge0, scratchQVec);
  15086. v = Cartesian3.dot(direction, q);
  15087. if (v < 0.0 || u + v > det) {
  15088. return undefined;
  15089. }
  15090. t = Cartesian3.dot(edge1, q) / det;
  15091. } else {
  15092. if (Math.abs(det) < CesiumMath.EPSILON6) {
  15093. return undefined;
  15094. }
  15095. var invDet = 1.0 / det;
  15096. tvec = Cartesian3.subtract(origin, p0, scratchTVec);
  15097. u = Cartesian3.dot(tvec, p) * invDet;
  15098. if (u < 0.0 || u > 1.0) {
  15099. return undefined;
  15100. }
  15101. q = Cartesian3.cross(tvec, edge0, scratchQVec);
  15102. v = Cartesian3.dot(direction, q) * invDet;
  15103. if (v < 0.0 || u + v > 1.0) {
  15104. return undefined;
  15105. }
  15106. t = Cartesian3.dot(edge1, q) * invDet;
  15107. }
  15108. return t;
  15109. };
  15110. /**
  15111. * Computes the intersection of a ray and a triangle as a Cartesian3 coordinate.
  15112. *
  15113. * Implements {@link https://cadxfem.org/inf/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf|
  15114. * Fast Minimum Storage Ray/Triangle Intersection} by Tomas Moller and Ben Trumbore.
  15115. *
  15116. * @memberof IntersectionTests
  15117. *
  15118. * @param {Ray} ray The ray.
  15119. * @param {Cartesian3} p0 The first vertex of the triangle.
  15120. * @param {Cartesian3} p1 The second vertex of the triangle.
  15121. * @param {Cartesian3} p2 The third vertex of the triangle.
  15122. * @param {Boolean} [cullBackFaces=false] If <code>true</code>, will only compute an intersection with the front face of the triangle
  15123. * and return undefined for intersections with the back face.
  15124. * @param {Cartesian3} [result] The <code>Cartesian3</code> onto which to store the result.
  15125. * @returns {Cartesian3} The intersection point or undefined if there is no intersections.
  15126. */
  15127. IntersectionTests.rayTriangle = function(ray, p0, p1, p2, cullBackFaces, result) {
  15128. var t = IntersectionTests.rayTriangleParametric(ray, p0, p1, p2, cullBackFaces);
  15129. if (!defined(t) || t < 0.0) {
  15130. return undefined;
  15131. }
  15132. if (!defined(result)) {
  15133. result = new Cartesian3();
  15134. }
  15135. Cartesian3.multiplyByScalar(ray.direction, t, result);
  15136. return Cartesian3.add(ray.origin, result, result);
  15137. };
  15138. var scratchLineSegmentTriangleRay = new Ray();
  15139. /**
  15140. * Computes the intersection of a line segment and a triangle.
  15141. * @memberof IntersectionTests
  15142. *
  15143. * @param {Cartesian3} v0 The an end point of the line segment.
  15144. * @param {Cartesian3} v1 The other end point of the line segment.
  15145. * @param {Cartesian3} p0 The first vertex of the triangle.
  15146. * @param {Cartesian3} p1 The second vertex of the triangle.
  15147. * @param {Cartesian3} p2 The third vertex of the triangle.
  15148. * @param {Boolean} [cullBackFaces=false] If <code>true</code>, will only compute an intersection with the front face of the triangle
  15149. * and return undefined for intersections with the back face.
  15150. * @param {Cartesian3} [result] The <code>Cartesian3</code> onto which to store the result.
  15151. * @returns {Cartesian3} The intersection point or undefined if there is no intersections.
  15152. */
  15153. IntersectionTests.lineSegmentTriangle = function(v0, v1, p0, p1, p2, cullBackFaces, result) {
  15154. if (!defined(v0)) {
  15155. throw new DeveloperError('v0 is required.');
  15156. }
  15157. if (!defined(v1)) {
  15158. throw new DeveloperError('v1 is required.');
  15159. }
  15160. if (!defined(p0)) {
  15161. throw new DeveloperError('p0 is required.');
  15162. }
  15163. if (!defined(p1)) {
  15164. throw new DeveloperError('p1 is required.');
  15165. }
  15166. if (!defined(p2)) {
  15167. throw new DeveloperError('p2 is required.');
  15168. }
  15169. var ray = scratchLineSegmentTriangleRay;
  15170. Cartesian3.clone(v0, ray.origin);
  15171. Cartesian3.subtract(v1, v0, ray.direction);
  15172. Cartesian3.normalize(ray.direction, ray.direction);
  15173. var t = IntersectionTests.rayTriangleParametric(ray, p0, p1, p2, cullBackFaces);
  15174. if (!defined(t) || t < 0.0 || t > Cartesian3.distance(v0, v1)) {
  15175. return undefined;
  15176. }
  15177. if (!defined(result)) {
  15178. result = new Cartesian3();
  15179. }
  15180. Cartesian3.multiplyByScalar(ray.direction, t, result);
  15181. return Cartesian3.add(ray.origin, result, result);
  15182. };
  15183. function solveQuadratic(a, b, c, result) {
  15184. var det = b * b - 4.0 * a * c;
  15185. if (det < 0.0) {
  15186. return undefined;
  15187. } else if (det > 0.0) {
  15188. var denom = 1.0 / (2.0 * a);
  15189. var disc = Math.sqrt(det);
  15190. var root0 = (-b + disc) * denom;
  15191. var root1 = (-b - disc) * denom;
  15192. if (root0 < root1) {
  15193. result.root0 = root0;
  15194. result.root1 = root1;
  15195. } else {
  15196. result.root0 = root1;
  15197. result.root1 = root0;
  15198. }
  15199. return result;
  15200. }
  15201. var root = -b / (2.0 * a);
  15202. if (root === 0.0) {
  15203. return undefined;
  15204. }
  15205. result.root0 = result.root1 = root;
  15206. return result;
  15207. }
  15208. var raySphereRoots = {
  15209. root0 : 0.0,
  15210. root1 : 0.0
  15211. };
  15212. function raySphere(ray, sphere, result) {
  15213. if (!defined(result)) {
  15214. result = {};
  15215. }
  15216. var origin = ray.origin;
  15217. var direction = ray.direction;
  15218. var center = sphere.center;
  15219. var radiusSquared = sphere.radius * sphere.radius;
  15220. var diff = Cartesian3.subtract(origin, center, scratchPVec);
  15221. var a = Cartesian3.dot(direction, direction);
  15222. var b = 2.0 * Cartesian3.dot(direction, diff);
  15223. var c = Cartesian3.magnitudeSquared(diff) - radiusSquared;
  15224. var roots = solveQuadratic(a, b, c, raySphereRoots);
  15225. if (!defined(roots)) {
  15226. return undefined;
  15227. }
  15228. result.start = roots.root0;
  15229. result.stop = roots.root1;
  15230. return result;
  15231. }
  15232. /**
  15233. * Computes the intersection points of a ray with a sphere.
  15234. * @memberof IntersectionTests
  15235. *
  15236. * @param {Ray} ray The ray.
  15237. * @param {BoundingSphere} sphere The sphere.
  15238. * @param {Object} [result] The result onto which to store the result.
  15239. * @returns {Object} An object with the first (<code>start</code>) and the second (<code>stop</code>) intersection scalars for points along the ray or undefined if there are no intersections.
  15240. */
  15241. IntersectionTests.raySphere = function(ray, sphere, result) {
  15242. if (!defined(ray)) {
  15243. throw new DeveloperError('ray is required.');
  15244. }
  15245. if (!defined(sphere)) {
  15246. throw new DeveloperError('sphere is required.');
  15247. }
  15248. result = raySphere(ray, sphere, result);
  15249. if (!defined(result) || result.stop < 0.0) {
  15250. return undefined;
  15251. }
  15252. result.start = Math.max(result.start, 0.0);
  15253. return result;
  15254. };
  15255. var scratchLineSegmentRay = new Ray();
  15256. /**
  15257. * Computes the intersection points of a line segment with a sphere.
  15258. * @memberof IntersectionTests
  15259. *
  15260. * @param {Cartesian3} p0 An end point of the line segment.
  15261. * @param {Cartesian3} p1 The other end point of the line segment.
  15262. * @param {BoundingSphere} sphere The sphere.
  15263. * @param {Object} [result] The result onto which to store the result.
  15264. * @returns {Object} An object with the first (<code>start</code>) and the second (<code>stop</code>) intersection scalars for points along the line segment or undefined if there are no intersections.
  15265. */
  15266. IntersectionTests.lineSegmentSphere = function(p0, p1, sphere, result) {
  15267. if (!defined(p0)) {
  15268. throw new DeveloperError('p0 is required.');
  15269. }
  15270. if (!defined(p1)) {
  15271. throw new DeveloperError('p1 is required.');
  15272. }
  15273. if (!defined(sphere)) {
  15274. throw new DeveloperError('sphere is required.');
  15275. }
  15276. var ray = scratchLineSegmentRay;
  15277. Cartesian3.clone(p0, ray.origin);
  15278. var direction = Cartesian3.subtract(p1, p0, ray.direction);
  15279. var maxT = Cartesian3.magnitude(direction);
  15280. Cartesian3.normalize(direction, direction);
  15281. result = raySphere(ray, sphere, result);
  15282. if (!defined(result) || result.stop < 0.0 || result.start > maxT) {
  15283. return undefined;
  15284. }
  15285. result.start = Math.max(result.start, 0.0);
  15286. result.stop = Math.min(result.stop, maxT);
  15287. return result;
  15288. };
  15289. var scratchQ = new Cartesian3();
  15290. var scratchW = new Cartesian3();
  15291. /**
  15292. * Computes the intersection points of a ray with an ellipsoid.
  15293. *
  15294. * @param {Ray} ray The ray.
  15295. * @param {Ellipsoid} ellipsoid The ellipsoid.
  15296. * @returns {Object} An object with the first (<code>start</code>) and the second (<code>stop</code>) intersection scalars for points along the ray or undefined if there are no intersections.
  15297. */
  15298. IntersectionTests.rayEllipsoid = function(ray, ellipsoid) {
  15299. if (!defined(ray)) {
  15300. throw new DeveloperError('ray is required.');
  15301. }
  15302. if (!defined(ellipsoid)) {
  15303. throw new DeveloperError('ellipsoid is required.');
  15304. }
  15305. var inverseRadii = ellipsoid.oneOverRadii;
  15306. var q = Cartesian3.multiplyComponents(inverseRadii, ray.origin, scratchQ);
  15307. var w = Cartesian3.multiplyComponents(inverseRadii, ray.direction, scratchW);
  15308. var q2 = Cartesian3.magnitudeSquared(q);
  15309. var qw = Cartesian3.dot(q, w);
  15310. var difference, w2, product, discriminant, temp;
  15311. if (q2 > 1.0) {
  15312. // Outside ellipsoid.
  15313. if (qw >= 0.0) {
  15314. // Looking outward or tangent (0 intersections).
  15315. return undefined;
  15316. }
  15317. // qw < 0.0.
  15318. var qw2 = qw * qw;
  15319. difference = q2 - 1.0; // Positively valued.
  15320. w2 = Cartesian3.magnitudeSquared(w);
  15321. product = w2 * difference;
  15322. if (qw2 < product) {
  15323. // Imaginary roots (0 intersections).
  15324. return undefined;
  15325. } else if (qw2 > product) {
  15326. // Distinct roots (2 intersections).
  15327. discriminant = qw * qw - product;
  15328. temp = -qw + Math.sqrt(discriminant); // Avoid cancellation.
  15329. var root0 = temp / w2;
  15330. var root1 = difference / temp;
  15331. if (root0 < root1) {
  15332. return {
  15333. start : root0,
  15334. stop : root1
  15335. };
  15336. }
  15337. return {
  15338. start : root1,
  15339. stop : root0
  15340. };
  15341. } else {
  15342. // qw2 == product. Repeated roots (2 intersections).
  15343. var root = Math.sqrt(difference / w2);
  15344. return {
  15345. start : root,
  15346. stop : root
  15347. };
  15348. }
  15349. } else if (q2 < 1.0) {
  15350. // Inside ellipsoid (2 intersections).
  15351. difference = q2 - 1.0; // Negatively valued.
  15352. w2 = Cartesian3.magnitudeSquared(w);
  15353. product = w2 * difference; // Negatively valued.
  15354. discriminant = qw * qw - product;
  15355. temp = -qw + Math.sqrt(discriminant); // Positively valued.
  15356. return {
  15357. start : 0.0,
  15358. stop : temp / w2
  15359. };
  15360. } else {
  15361. // q2 == 1.0. On ellipsoid.
  15362. if (qw < 0.0) {
  15363. // Looking inward.
  15364. w2 = Cartesian3.magnitudeSquared(w);
  15365. return {
  15366. start : 0.0,
  15367. stop : -qw / w2
  15368. };
  15369. }
  15370. // qw >= 0.0. Looking outward or tangent.
  15371. return undefined;
  15372. }
  15373. };
  15374. function addWithCancellationCheck(left, right, tolerance) {
  15375. var difference = left + right;
  15376. if ((CesiumMath.sign(left) !== CesiumMath.sign(right)) &&
  15377. Math.abs(difference / Math.max(Math.abs(left), Math.abs(right))) < tolerance) {
  15378. return 0.0;
  15379. }
  15380. return difference;
  15381. }
  15382. function quadraticVectorExpression(A, b, c, x, w) {
  15383. var xSquared = x * x;
  15384. var wSquared = w * w;
  15385. var l2 = (A[Matrix3.COLUMN1ROW1] - A[Matrix3.COLUMN2ROW2]) * wSquared;
  15386. var l1 = w * (x * addWithCancellationCheck(A[Matrix3.COLUMN1ROW0], A[Matrix3.COLUMN0ROW1], CesiumMath.EPSILON15) + b.y);
  15387. var l0 = (A[Matrix3.COLUMN0ROW0] * xSquared + A[Matrix3.COLUMN2ROW2] * wSquared) + x * b.x + c;
  15388. var r1 = wSquared * addWithCancellationCheck(A[Matrix3.COLUMN2ROW1], A[Matrix3.COLUMN1ROW2], CesiumMath.EPSILON15);
  15389. var r0 = w * (x * addWithCancellationCheck(A[Matrix3.COLUMN2ROW0], A[Matrix3.COLUMN0ROW2]) + b.z);
  15390. var cosines;
  15391. var solutions = [];
  15392. if (r0 === 0.0 && r1 === 0.0) {
  15393. cosines = QuadraticRealPolynomial.computeRealRoots(l2, l1, l0);
  15394. if (cosines.length === 0) {
  15395. return solutions;
  15396. }
  15397. var cosine0 = cosines[0];
  15398. var sine0 = Math.sqrt(Math.max(1.0 - cosine0 * cosine0, 0.0));
  15399. solutions.push(new Cartesian3(x, w * cosine0, w * -sine0));
  15400. solutions.push(new Cartesian3(x, w * cosine0, w * sine0));
  15401. if (cosines.length === 2) {
  15402. var cosine1 = cosines[1];
  15403. var sine1 = Math.sqrt(Math.max(1.0 - cosine1 * cosine1, 0.0));
  15404. solutions.push(new Cartesian3(x, w * cosine1, w * -sine1));
  15405. solutions.push(new Cartesian3(x, w * cosine1, w * sine1));
  15406. }
  15407. return solutions;
  15408. }
  15409. var r0Squared = r0 * r0;
  15410. var r1Squared = r1 * r1;
  15411. var l2Squared = l2 * l2;
  15412. var r0r1 = r0 * r1;
  15413. var c4 = l2Squared + r1Squared;
  15414. var c3 = 2.0 * (l1 * l2 + r0r1);
  15415. var c2 = 2.0 * l0 * l2 + l1 * l1 - r1Squared + r0Squared;
  15416. var c1 = 2.0 * (l0 * l1 - r0r1);
  15417. var c0 = l0 * l0 - r0Squared;
  15418. if (c4 === 0.0 && c3 === 0.0 && c2 === 0.0 && c1 === 0.0) {
  15419. return solutions;
  15420. }
  15421. cosines = QuarticRealPolynomial.computeRealRoots(c4, c3, c2, c1, c0);
  15422. var length = cosines.length;
  15423. if (length === 0) {
  15424. return solutions;
  15425. }
  15426. for ( var i = 0; i < length; ++i) {
  15427. var cosine = cosines[i];
  15428. var cosineSquared = cosine * cosine;
  15429. var sineSquared = Math.max(1.0 - cosineSquared, 0.0);
  15430. var sine = Math.sqrt(sineSquared);
  15431. //var left = l2 * cosineSquared + l1 * cosine + l0;
  15432. var left;
  15433. if (CesiumMath.sign(l2) === CesiumMath.sign(l0)) {
  15434. left = addWithCancellationCheck(l2 * cosineSquared + l0, l1 * cosine, CesiumMath.EPSILON12);
  15435. } else if (CesiumMath.sign(l0) === CesiumMath.sign(l1 * cosine)) {
  15436. left = addWithCancellationCheck(l2 * cosineSquared, l1 * cosine + l0, CesiumMath.EPSILON12);
  15437. } else {
  15438. left = addWithCancellationCheck(l2 * cosineSquared + l1 * cosine, l0, CesiumMath.EPSILON12);
  15439. }
  15440. var right = addWithCancellationCheck(r1 * cosine, r0, CesiumMath.EPSILON15);
  15441. var product = left * right;
  15442. if (product < 0.0) {
  15443. solutions.push(new Cartesian3(x, w * cosine, w * sine));
  15444. } else if (product > 0.0) {
  15445. solutions.push(new Cartesian3(x, w * cosine, w * -sine));
  15446. } else if (sine !== 0.0) {
  15447. solutions.push(new Cartesian3(x, w * cosine, w * -sine));
  15448. solutions.push(new Cartesian3(x, w * cosine, w * sine));
  15449. ++i;
  15450. } else {
  15451. solutions.push(new Cartesian3(x, w * cosine, w * sine));
  15452. }
  15453. }
  15454. return solutions;
  15455. }
  15456. var firstAxisScratch = new Cartesian3();
  15457. var secondAxisScratch = new Cartesian3();
  15458. var thirdAxisScratch = new Cartesian3();
  15459. var referenceScratch = new Cartesian3();
  15460. var bCart = new Cartesian3();
  15461. var bScratch = new Matrix3();
  15462. var btScratch = new Matrix3();
  15463. var diScratch = new Matrix3();
  15464. var dScratch = new Matrix3();
  15465. var cScratch = new Matrix3();
  15466. var tempMatrix = new Matrix3();
  15467. var aScratch = new Matrix3();
  15468. var sScratch = new Cartesian3();
  15469. var closestScratch = new Cartesian3();
  15470. var surfPointScratch = new Cartographic();
  15471. /**
  15472. * Provides the point along the ray which is nearest to the ellipsoid.
  15473. *
  15474. * @param {Ray} ray The ray.
  15475. * @param {Ellipsoid} ellipsoid The ellipsoid.
  15476. * @returns {Cartesian3} The nearest planetodetic point on the ray.
  15477. */
  15478. IntersectionTests.grazingAltitudeLocation = function(ray, ellipsoid) {
  15479. if (!defined(ray)) {
  15480. throw new DeveloperError('ray is required.');
  15481. }
  15482. if (!defined(ellipsoid)) {
  15483. throw new DeveloperError('ellipsoid is required.');
  15484. }
  15485. var position = ray.origin;
  15486. var direction = ray.direction;
  15487. if (!Cartesian3.equals(position, Cartesian3.ZERO)) {
  15488. var normal = ellipsoid.geodeticSurfaceNormal(position, firstAxisScratch);
  15489. if (Cartesian3.dot(direction, normal) >= 0.0) { // The location provided is the closest point in altitude
  15490. return position;
  15491. }
  15492. }
  15493. var intersects = defined(this.rayEllipsoid(ray, ellipsoid));
  15494. // Compute the scaled direction vector.
  15495. var f = ellipsoid.transformPositionToScaledSpace(direction, firstAxisScratch);
  15496. // Constructs a basis from the unit scaled direction vector. Construct its rotation and transpose.
  15497. var firstAxis = Cartesian3.normalize(f, f);
  15498. var reference = Cartesian3.mostOrthogonalAxis(f, referenceScratch);
  15499. var secondAxis = Cartesian3.normalize(Cartesian3.cross(reference, firstAxis, secondAxisScratch), secondAxisScratch);
  15500. var thirdAxis = Cartesian3.normalize(Cartesian3.cross(firstAxis, secondAxis, thirdAxisScratch), thirdAxisScratch);
  15501. var B = bScratch;
  15502. B[0] = firstAxis.x;
  15503. B[1] = firstAxis.y;
  15504. B[2] = firstAxis.z;
  15505. B[3] = secondAxis.x;
  15506. B[4] = secondAxis.y;
  15507. B[5] = secondAxis.z;
  15508. B[6] = thirdAxis.x;
  15509. B[7] = thirdAxis.y;
  15510. B[8] = thirdAxis.z;
  15511. var B_T = Matrix3.transpose(B, btScratch);
  15512. // Get the scaling matrix and its inverse.
  15513. var D_I = Matrix3.fromScale(ellipsoid.radii, diScratch);
  15514. var D = Matrix3.fromScale(ellipsoid.oneOverRadii, dScratch);
  15515. var C = cScratch;
  15516. C[0] = 0.0;
  15517. C[1] = -direction.z;
  15518. C[2] = direction.y;
  15519. C[3] = direction.z;
  15520. C[4] = 0.0;
  15521. C[5] = -direction.x;
  15522. C[6] = -direction.y;
  15523. C[7] = direction.x;
  15524. C[8] = 0.0;
  15525. var temp = Matrix3.multiply(Matrix3.multiply(B_T, D, tempMatrix), C, tempMatrix);
  15526. var A = Matrix3.multiply(Matrix3.multiply(temp, D_I, aScratch), B, aScratch);
  15527. var b = Matrix3.multiplyByVector(temp, position, bCart);
  15528. // Solve for the solutions to the expression in standard form:
  15529. var solutions = quadraticVectorExpression(A, Cartesian3.negate(b, firstAxisScratch), 0.0, 0.0, 1.0);
  15530. var s;
  15531. var altitude;
  15532. var length = solutions.length;
  15533. if (length > 0) {
  15534. var closest = Cartesian3.clone(Cartesian3.ZERO, closestScratch);
  15535. var maximumValue = Number.NEGATIVE_INFINITY;
  15536. for ( var i = 0; i < length; ++i) {
  15537. s = Matrix3.multiplyByVector(D_I, Matrix3.multiplyByVector(B, solutions[i], sScratch), sScratch);
  15538. var v = Cartesian3.normalize(Cartesian3.subtract(s, position, referenceScratch), referenceScratch);
  15539. var dotProduct = Cartesian3.dot(v, direction);
  15540. if (dotProduct > maximumValue) {
  15541. maximumValue = dotProduct;
  15542. closest = Cartesian3.clone(s, closest);
  15543. }
  15544. }
  15545. var surfacePoint = ellipsoid.cartesianToCartographic(closest, surfPointScratch);
  15546. maximumValue = CesiumMath.clamp(maximumValue, 0.0, 1.0);
  15547. altitude = Cartesian3.magnitude(Cartesian3.subtract(closest, position, referenceScratch)) * Math.sqrt(1.0 - maximumValue * maximumValue);
  15548. altitude = intersects ? -altitude : altitude;
  15549. surfacePoint.height = altitude;
  15550. return ellipsoid.cartographicToCartesian(surfacePoint, new Cartesian3());
  15551. }
  15552. return undefined;
  15553. };
  15554. var lineSegmentPlaneDifference = new Cartesian3();
  15555. /**
  15556. * Computes the intersection of a line segment and a plane.
  15557. *
  15558. * @param {Cartesian3} endPoint0 An end point of the line segment.
  15559. * @param {Cartesian3} endPoint1 The other end point of the line segment.
  15560. * @param {Plane} plane The plane.
  15561. * @param {Cartesian3} [result] The object onto which to store the result.
  15562. * @returns {Cartesian3} The intersection point or undefined if there is no intersection.
  15563. *
  15564. * @example
  15565. * var origin = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);
  15566. * var normal = ellipsoid.geodeticSurfaceNormal(origin);
  15567. * var plane = Cesium.Plane.fromPointNormal(origin, normal);
  15568. *
  15569. * var p0 = new Cesium.Cartesian3(...);
  15570. * var p1 = new Cesium.Cartesian3(...);
  15571. *
  15572. * // find the intersection of the line segment from p0 to p1 and the tangent plane at origin.
  15573. * var intersection = Cesium.IntersectionTests.lineSegmentPlane(p0, p1, plane);
  15574. */
  15575. IntersectionTests.lineSegmentPlane = function(endPoint0, endPoint1, plane, result) {
  15576. if (!defined(endPoint0)) {
  15577. throw new DeveloperError('endPoint0 is required.');
  15578. }
  15579. if (!defined(endPoint1)) {
  15580. throw new DeveloperError('endPoint1 is required.');
  15581. }
  15582. if (!defined(plane)) {
  15583. throw new DeveloperError('plane is required.');
  15584. }
  15585. if (!defined(result)) {
  15586. result = new Cartesian3();
  15587. }
  15588. var difference = Cartesian3.subtract(endPoint1, endPoint0, lineSegmentPlaneDifference);
  15589. var normal = plane.normal;
  15590. var nDotDiff = Cartesian3.dot(normal, difference);
  15591. // check if the segment and plane are parallel
  15592. if (Math.abs(nDotDiff) < CesiumMath.EPSILON6) {
  15593. return undefined;
  15594. }
  15595. var nDotP0 = Cartesian3.dot(normal, endPoint0);
  15596. var t = -(plane.distance + nDotP0) / nDotDiff;
  15597. // intersection only if t is in [0, 1]
  15598. if (t < 0.0 || t > 1.0) {
  15599. return undefined;
  15600. }
  15601. // intersection is endPoint0 + t * (endPoint1 - endPoint0)
  15602. Cartesian3.multiplyByScalar(difference, t, result);
  15603. Cartesian3.add(endPoint0, result, result);
  15604. return result;
  15605. };
  15606. /**
  15607. * Computes the intersection of a triangle and a plane
  15608. *
  15609. * @param {Cartesian3} p0 First point of the triangle
  15610. * @param {Cartesian3} p1 Second point of the triangle
  15611. * @param {Cartesian3} p2 Third point of the triangle
  15612. * @param {Plane} plane Intersection plane
  15613. * @returns {Object} An object with properties <code>positions</code> and <code>indices</code>, which are arrays that represent three triangles that do not cross the plane. (Undefined if no intersection exists)
  15614. *
  15615. * @example
  15616. * var origin = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);
  15617. * var normal = ellipsoid.geodeticSurfaceNormal(origin);
  15618. * var plane = Cesium.Plane.fromPointNormal(origin, normal);
  15619. *
  15620. * var p0 = new Cesium.Cartesian3(...);
  15621. * var p1 = new Cesium.Cartesian3(...);
  15622. * var p2 = new Cesium.Cartesian3(...);
  15623. *
  15624. * // convert the triangle composed of points (p0, p1, p2) to three triangles that don't cross the plane
  15625. * var triangles = Cesium.IntersectionTests.trianglePlaneIntersection(p0, p1, p2, plane);
  15626. */
  15627. IntersectionTests.trianglePlaneIntersection = function(p0, p1, p2, plane) {
  15628. if ((!defined(p0)) ||
  15629. (!defined(p1)) ||
  15630. (!defined(p2)) ||
  15631. (!defined(plane))) {
  15632. throw new DeveloperError('p0, p1, p2, and plane are required.');
  15633. }
  15634. var planeNormal = plane.normal;
  15635. var planeD = plane.distance;
  15636. var p0Behind = (Cartesian3.dot(planeNormal, p0) + planeD) < 0.0;
  15637. var p1Behind = (Cartesian3.dot(planeNormal, p1) + planeD) < 0.0;
  15638. var p2Behind = (Cartesian3.dot(planeNormal, p2) + planeD) < 0.0;
  15639. // Given these dots products, the calls to lineSegmentPlaneIntersection
  15640. // always have defined results.
  15641. var numBehind = 0;
  15642. numBehind += p0Behind ? 1 : 0;
  15643. numBehind += p1Behind ? 1 : 0;
  15644. numBehind += p2Behind ? 1 : 0;
  15645. var u1, u2;
  15646. if (numBehind === 1 || numBehind === 2) {
  15647. u1 = new Cartesian3();
  15648. u2 = new Cartesian3();
  15649. }
  15650. if (numBehind === 1) {
  15651. if (p0Behind) {
  15652. IntersectionTests.lineSegmentPlane(p0, p1, plane, u1);
  15653. IntersectionTests.lineSegmentPlane(p0, p2, plane, u2);
  15654. return {
  15655. positions : [p0, p1, p2, u1, u2 ],
  15656. indices : [
  15657. // Behind
  15658. 0, 3, 4,
  15659. // In front
  15660. 1, 2, 4,
  15661. 1, 4, 3
  15662. ]
  15663. };
  15664. } else if (p1Behind) {
  15665. IntersectionTests.lineSegmentPlane(p1, p2, plane, u1);
  15666. IntersectionTests.lineSegmentPlane(p1, p0, plane, u2);
  15667. return {
  15668. positions : [p0, p1, p2, u1, u2 ],
  15669. indices : [
  15670. // Behind
  15671. 1, 3, 4,
  15672. // In front
  15673. 2, 0, 4,
  15674. 2, 4, 3
  15675. ]
  15676. };
  15677. } else if (p2Behind) {
  15678. IntersectionTests.lineSegmentPlane(p2, p0, plane, u1);
  15679. IntersectionTests.lineSegmentPlane(p2, p1, plane, u2);
  15680. return {
  15681. positions : [p0, p1, p2, u1, u2 ],
  15682. indices : [
  15683. // Behind
  15684. 2, 3, 4,
  15685. // In front
  15686. 0, 1, 4,
  15687. 0, 4, 3
  15688. ]
  15689. };
  15690. }
  15691. } else if (numBehind === 2) {
  15692. if (!p0Behind) {
  15693. IntersectionTests.lineSegmentPlane(p1, p0, plane, u1);
  15694. IntersectionTests.lineSegmentPlane(p2, p0, plane, u2);
  15695. return {
  15696. positions : [p0, p1, p2, u1, u2 ],
  15697. indices : [
  15698. // Behind
  15699. 1, 2, 4,
  15700. 1, 4, 3,
  15701. // In front
  15702. 0, 3, 4
  15703. ]
  15704. };
  15705. } else if (!p1Behind) {
  15706. IntersectionTests.lineSegmentPlane(p2, p1, plane, u1);
  15707. IntersectionTests.lineSegmentPlane(p0, p1, plane, u2);
  15708. return {
  15709. positions : [p0, p1, p2, u1, u2 ],
  15710. indices : [
  15711. // Behind
  15712. 2, 0, 4,
  15713. 2, 4, 3,
  15714. // In front
  15715. 1, 3, 4
  15716. ]
  15717. };
  15718. } else if (!p2Behind) {
  15719. IntersectionTests.lineSegmentPlane(p0, p2, plane, u1);
  15720. IntersectionTests.lineSegmentPlane(p1, p2, plane, u2);
  15721. return {
  15722. positions : [p0, p1, p2, u1, u2 ],
  15723. indices : [
  15724. // Behind
  15725. 0, 1, 4,
  15726. 0, 4, 3,
  15727. // In front
  15728. 2, 3, 4
  15729. ]
  15730. };
  15731. }
  15732. }
  15733. // if numBehind is 3, the triangle is completely behind the plane;
  15734. // otherwise, it is completely in front (numBehind is 0).
  15735. return undefined;
  15736. };
  15737. return IntersectionTests;
  15738. });
  15739. /*global define*/
  15740. define('Core/Plane',[
  15741. './Cartesian3',
  15742. './defined',
  15743. './DeveloperError',
  15744. './freezeObject'
  15745. ], function(
  15746. Cartesian3,
  15747. defined,
  15748. DeveloperError,
  15749. freezeObject) {
  15750. 'use strict';
  15751. /**
  15752. * A plane in Hessian Normal Form defined by
  15753. * <pre>
  15754. * ax + by + cz + d = 0
  15755. * </pre>
  15756. * where (a, b, c) is the plane's <code>normal</code>, d is the signed
  15757. * <code>distance</code> to the plane, and (x, y, z) is any point on
  15758. * the plane.
  15759. *
  15760. * @alias Plane
  15761. * @constructor
  15762. *
  15763. * @param {Cartesian3} normal The plane's normal (normalized).
  15764. * @param {Number} distance The shortest distance from the origin to the plane. The sign of
  15765. * <code>distance</code> determines which side of the plane the origin
  15766. * is on. If <code>distance</code> is positive, the origin is in the half-space
  15767. * in the direction of the normal; if negative, the origin is in the half-space
  15768. * opposite to the normal; if zero, the plane passes through the origin.
  15769. *
  15770. * @example
  15771. * // The plane x=0
  15772. * var plane = new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0.0);
  15773. */
  15774. function Plane(normal, distance) {
  15775. if (!defined(normal)) {
  15776. throw new DeveloperError('normal is required.');
  15777. }
  15778. if (!defined(distance)) {
  15779. throw new DeveloperError('distance is required.');
  15780. }
  15781. /**
  15782. * The plane's normal.
  15783. *
  15784. * @type {Cartesian3}
  15785. */
  15786. this.normal = Cartesian3.clone(normal);
  15787. /**
  15788. * The shortest distance from the origin to the plane. The sign of
  15789. * <code>distance</code> determines which side of the plane the origin
  15790. * is on. If <code>distance</code> is positive, the origin is in the half-space
  15791. * in the direction of the normal; if negative, the origin is in the half-space
  15792. * opposite to the normal; if zero, the plane passes through the origin.
  15793. *
  15794. * @type {Number}
  15795. */
  15796. this.distance = distance;
  15797. }
  15798. /**
  15799. * Creates a plane from a normal and a point on the plane.
  15800. *
  15801. * @param {Cartesian3} point The point on the plane.
  15802. * @param {Cartesian3} normal The plane's normal (normalized).
  15803. * @param {Plane} [result] The object onto which to store the result.
  15804. * @returns {Plane} A new plane instance or the modified result parameter.
  15805. *
  15806. * @example
  15807. * var point = Cesium.Cartesian3.fromDegrees(-72.0, 40.0);
  15808. * var normal = ellipsoid.geodeticSurfaceNormal(point);
  15809. * var tangentPlane = Cesium.Plane.fromPointNormal(point, normal);
  15810. */
  15811. Plane.fromPointNormal = function(point, normal, result) {
  15812. if (!defined(point)) {
  15813. throw new DeveloperError('point is required.');
  15814. }
  15815. if (!defined(normal)) {
  15816. throw new DeveloperError('normal is required.');
  15817. }
  15818. var distance = -Cartesian3.dot(normal, point);
  15819. if (!defined(result)) {
  15820. return new Plane(normal, distance);
  15821. }
  15822. Cartesian3.clone(normal, result.normal);
  15823. result.distance = distance;
  15824. return result;
  15825. };
  15826. var scratchNormal = new Cartesian3();
  15827. /**
  15828. * Creates a plane from the general equation
  15829. *
  15830. * @param {Cartesian4} coefficients The plane's normal (normalized).
  15831. * @param {Plane} [result] The object onto which to store the result.
  15832. * @returns {Plane} A new plane instance or the modified result parameter.
  15833. */
  15834. Plane.fromCartesian4 = function(coefficients, result) {
  15835. if (!defined(coefficients)) {
  15836. throw new DeveloperError('coefficients is required.');
  15837. }
  15838. var normal = Cartesian3.fromCartesian4(coefficients, scratchNormal);
  15839. var distance = coefficients.w;
  15840. if (!defined(result)) {
  15841. return new Plane(normal, distance);
  15842. } else {
  15843. Cartesian3.clone(normal, result.normal);
  15844. result.distance = distance;
  15845. return result;
  15846. }
  15847. };
  15848. /**
  15849. * Computes the signed shortest distance of a point to a plane.
  15850. * The sign of the distance determines which side of the plane the point
  15851. * is on. If the distance is positive, the point is in the half-space
  15852. * in the direction of the normal; if negative, the point is in the half-space
  15853. * opposite to the normal; if zero, the plane passes through the point.
  15854. *
  15855. * @param {Plane} plane The plane.
  15856. * @param {Cartesian3} point The point.
  15857. * @returns {Number} The signed shortest distance of the point to the plane.
  15858. */
  15859. Plane.getPointDistance = function(plane, point) {
  15860. if (!defined(plane)) {
  15861. throw new DeveloperError('plane is required.');
  15862. }
  15863. if (!defined(point)) {
  15864. throw new DeveloperError('point is required.');
  15865. }
  15866. return Cartesian3.dot(plane.normal, point) + plane.distance;
  15867. };
  15868. /**
  15869. * A constant initialized to the XY plane passing through the origin, with normal in positive Z.
  15870. *
  15871. * @type {Plane}
  15872. * @constant
  15873. */
  15874. Plane.ORIGIN_XY_PLANE = freezeObject(new Plane(Cartesian3.UNIT_Z, 0.0));
  15875. /**
  15876. * A constant initialized to the YZ plane passing through the origin, with normal in positive X.
  15877. *
  15878. * @type {Plane}
  15879. * @constant
  15880. */
  15881. Plane.ORIGIN_YZ_PLANE = freezeObject(new Plane(Cartesian3.UNIT_X, 0.0));
  15882. /**
  15883. * A constant initialized to the ZX plane passing through the origin, with normal in positive Y.
  15884. *
  15885. * @type {Plane}
  15886. * @constant
  15887. */
  15888. Plane.ORIGIN_ZX_PLANE = freezeObject(new Plane(Cartesian3.UNIT_Y, 0.0));
  15889. return Plane;
  15890. });
  15891. /*global define*/
  15892. define('Core/PolylinePipeline',[
  15893. './Cartesian3',
  15894. './Cartographic',
  15895. './defaultValue',
  15896. './defined',
  15897. './DeveloperError',
  15898. './Ellipsoid',
  15899. './EllipsoidGeodesic',
  15900. './IntersectionTests',
  15901. './isArray',
  15902. './Math',
  15903. './Matrix4',
  15904. './Plane'
  15905. ], function(
  15906. Cartesian3,
  15907. Cartographic,
  15908. defaultValue,
  15909. defined,
  15910. DeveloperError,
  15911. Ellipsoid,
  15912. EllipsoidGeodesic,
  15913. IntersectionTests,
  15914. isArray,
  15915. CesiumMath,
  15916. Matrix4,
  15917. Plane) {
  15918. 'use strict';
  15919. /**
  15920. * @private
  15921. */
  15922. var PolylinePipeline = {};
  15923. PolylinePipeline.numberOfPoints = function(p0, p1, minDistance) {
  15924. var distance = Cartesian3.distance(p0, p1);
  15925. return Math.ceil(distance / minDistance);
  15926. };
  15927. var cartoScratch = new Cartographic();
  15928. PolylinePipeline.extractHeights = function(positions, ellipsoid) {
  15929. var length = positions.length;
  15930. var heights = new Array(length);
  15931. for (var i = 0; i < length; i++) {
  15932. var p = positions[i];
  15933. heights[i] = ellipsoid.cartesianToCartographic(p, cartoScratch).height;
  15934. }
  15935. return heights;
  15936. };
  15937. var wrapLongitudeInversMatrix = new Matrix4();
  15938. var wrapLongitudeOrigin = new Cartesian3();
  15939. var wrapLongitudeXZNormal = new Cartesian3();
  15940. var wrapLongitudeXZPlane = new Plane(Cartesian3.ZERO, 0.0);
  15941. var wrapLongitudeYZNormal = new Cartesian3();
  15942. var wrapLongitudeYZPlane = new Plane(Cartesian3.ZERO, 0.0);
  15943. var wrapLongitudeIntersection = new Cartesian3();
  15944. var wrapLongitudeOffset = new Cartesian3();
  15945. var subdivideHeightsScratchArray = [];
  15946. function subdivideHeights(numPoints, h0, h1) {
  15947. var heights = subdivideHeightsScratchArray;
  15948. heights.length = numPoints;
  15949. var i;
  15950. if (h0 === h1) {
  15951. for (i = 0; i < numPoints; i++) {
  15952. heights[i] = h0;
  15953. }
  15954. return heights;
  15955. }
  15956. var dHeight = h1 - h0;
  15957. var heightPerVertex = dHeight / numPoints;
  15958. for (i = 0; i < numPoints; i++) {
  15959. var h = h0 + i*heightPerVertex;
  15960. heights[i] = h;
  15961. }
  15962. return heights;
  15963. }
  15964. var carto1 = new Cartographic();
  15965. var carto2 = new Cartographic();
  15966. var cartesian = new Cartesian3();
  15967. var scaleFirst = new Cartesian3();
  15968. var scaleLast = new Cartesian3();
  15969. var ellipsoidGeodesic = new EllipsoidGeodesic();
  15970. //Returns subdivided line scaled to ellipsoid surface starting at p1 and ending at p2.
  15971. //Result includes p1, but not include p2. This function is called for a sequence of line segments,
  15972. //and this prevents duplication of end point.
  15973. function generateCartesianArc(p0, p1, minDistance, ellipsoid, h0, h1, array, offset) {
  15974. var first = ellipsoid.scaleToGeodeticSurface(p0, scaleFirst);
  15975. var last = ellipsoid.scaleToGeodeticSurface(p1, scaleLast);
  15976. var numPoints = PolylinePipeline.numberOfPoints(p0, p1, minDistance);
  15977. var start = ellipsoid.cartesianToCartographic(first, carto1);
  15978. var end = ellipsoid.cartesianToCartographic(last, carto2);
  15979. var heights = subdivideHeights(numPoints, h0, h1);
  15980. ellipsoidGeodesic.setEndPoints(start, end);
  15981. var surfaceDistanceBetweenPoints = ellipsoidGeodesic.surfaceDistance / numPoints;
  15982. var index = offset;
  15983. start.height = h0;
  15984. var cart = ellipsoid.cartographicToCartesian(start, cartesian);
  15985. Cartesian3.pack(cart, array, index);
  15986. index += 3;
  15987. for (var i = 1; i < numPoints; i++) {
  15988. var carto = ellipsoidGeodesic.interpolateUsingSurfaceDistance(i * surfaceDistanceBetweenPoints, carto2);
  15989. carto.height = heights[i];
  15990. cart = ellipsoid.cartographicToCartesian(carto, cartesian);
  15991. Cartesian3.pack(cart, array, index);
  15992. index += 3;
  15993. }
  15994. return index;
  15995. }
  15996. /**
  15997. * Breaks a {@link Polyline} into segments such that it does not cross the &plusmn;180 degree meridian of an ellipsoid.
  15998. *
  15999. * @param {Cartesian3[]} positions The polyline's Cartesian positions.
  16000. * @param {Matrix4} [modelMatrix=Matrix4.IDENTITY] The polyline's model matrix. Assumed to be an affine
  16001. * transformation matrix, where the upper left 3x3 elements are a rotation matrix, and
  16002. * the upper three elements in the fourth column are the translation. The bottom row is assumed to be [0, 0, 0, 1].
  16003. * The matrix is not verified to be in the proper form.
  16004. * @returns {Object} An object with a <code>positions</code> property that is an array of positions and a
  16005. * <code>segments</code> property.
  16006. *
  16007. *
  16008. * @example
  16009. * var polylines = new Cesium.PolylineCollection();
  16010. * var polyline = polylines.add(...);
  16011. * var positions = polyline.positions;
  16012. * var modelMatrix = polylines.modelMatrix;
  16013. * var segments = Cesium.PolylinePipeline.wrapLongitude(positions, modelMatrix);
  16014. *
  16015. * @see PolygonPipeline.wrapLongitude
  16016. * @see Polyline
  16017. * @see PolylineCollection
  16018. */
  16019. PolylinePipeline.wrapLongitude = function(positions, modelMatrix) {
  16020. var cartesians = [];
  16021. var segments = [];
  16022. if (defined(positions) && positions.length > 0) {
  16023. modelMatrix = defaultValue(modelMatrix, Matrix4.IDENTITY);
  16024. var inverseModelMatrix = Matrix4.inverseTransformation(modelMatrix, wrapLongitudeInversMatrix);
  16025. var origin = Matrix4.multiplyByPoint(inverseModelMatrix, Cartesian3.ZERO, wrapLongitudeOrigin);
  16026. var xzNormal = Matrix4.multiplyByPointAsVector(inverseModelMatrix, Cartesian3.UNIT_Y, wrapLongitudeXZNormal);
  16027. var xzPlane = Plane.fromPointNormal(origin, xzNormal, wrapLongitudeXZPlane);
  16028. var yzNormal = Matrix4.multiplyByPointAsVector(inverseModelMatrix, Cartesian3.UNIT_X, wrapLongitudeYZNormal);
  16029. var yzPlane = Plane.fromPointNormal(origin, yzNormal, wrapLongitudeYZPlane);
  16030. var count = 1;
  16031. cartesians.push(Cartesian3.clone(positions[0]));
  16032. var prev = cartesians[0];
  16033. var length = positions.length;
  16034. for (var i = 1; i < length; ++i) {
  16035. var cur = positions[i];
  16036. // intersects the IDL if either endpoint is on the negative side of the yz-plane
  16037. if (Plane.getPointDistance(yzPlane, prev) < 0.0 || Plane.getPointDistance(yzPlane, cur) < 0.0) {
  16038. // and intersects the xz-plane
  16039. var intersection = IntersectionTests.lineSegmentPlane(prev, cur, xzPlane, wrapLongitudeIntersection);
  16040. if (defined(intersection)) {
  16041. // move point on the xz-plane slightly away from the plane
  16042. var offset = Cartesian3.multiplyByScalar(xzNormal, 5.0e-9, wrapLongitudeOffset);
  16043. if (Plane.getPointDistance(xzPlane, prev) < 0.0) {
  16044. Cartesian3.negate(offset, offset);
  16045. }
  16046. cartesians.push(Cartesian3.add(intersection, offset, new Cartesian3()));
  16047. segments.push(count + 1);
  16048. Cartesian3.negate(offset, offset);
  16049. cartesians.push(Cartesian3.add(intersection, offset, new Cartesian3()));
  16050. count = 1;
  16051. }
  16052. }
  16053. cartesians.push(Cartesian3.clone(positions[i]));
  16054. count++;
  16055. prev = cur;
  16056. }
  16057. segments.push(count);
  16058. }
  16059. return {
  16060. positions : cartesians,
  16061. lengths : segments
  16062. };
  16063. };
  16064. /**
  16065. * Subdivides polyline and raises all points to the specified height. Returns an array of numbers to represent the positions.
  16066. * @param {Cartesian3[]} positions The array of type {Cartesian3} representing positions.
  16067. * @param {Number|Number[]} [height=0.0] A number or array of numbers representing the heights of each position.
  16068. * @param {Number} [granularity = CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.
  16069. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie.
  16070. * @returns {Number[]} A new array of positions of type {Number} that have been subdivided and raised to the surface of the ellipsoid.
  16071. *
  16072. * @example
  16073. * var positions = Cesium.Cartesian3.fromDegreesArray([
  16074. * -105.0, 40.0,
  16075. * -100.0, 38.0,
  16076. * -105.0, 35.0,
  16077. * -100.0, 32.0
  16078. * ]);
  16079. * var surfacePositions = Cesium.PolylinePipeline.generateArc({
  16080. * positons: positions
  16081. * });
  16082. */
  16083. PolylinePipeline.generateArc = function(options) {
  16084. if (!defined(options)) {
  16085. options = {};
  16086. }
  16087. var positions = options.positions;
  16088. if (!defined(positions)) {
  16089. throw new DeveloperError('options.positions is required.');
  16090. }
  16091. var length = positions.length;
  16092. var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);
  16093. var height = defaultValue(options.height, 0);
  16094. var hasHeightArray = isArray(height);
  16095. if (length < 1) {
  16096. return [];
  16097. } else if (length === 1) {
  16098. var p = ellipsoid.scaleToGeodeticSurface(positions[0], scaleFirst);
  16099. height = hasHeightArray ? height[0] : height;
  16100. if (height !== 0) {
  16101. var n = ellipsoid.geodeticSurfaceNormal(p, cartesian);
  16102. Cartesian3.multiplyByScalar(n, height, n);
  16103. Cartesian3.add(p, n, p);
  16104. }
  16105. return [p.x, p.y, p.z];
  16106. }
  16107. var minDistance = options.minDistance;
  16108. if (!defined(minDistance)) {
  16109. var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE);
  16110. minDistance = CesiumMath.chordLength(granularity, ellipsoid.maximumRadius);
  16111. }
  16112. var numPoints = 0;
  16113. var i;
  16114. for (i = 0; i < length -1; i++) {
  16115. numPoints += PolylinePipeline.numberOfPoints(positions[i], positions[i+1], minDistance);
  16116. }
  16117. var arrayLength = (numPoints + 1) * 3;
  16118. var newPositions = new Array(arrayLength);
  16119. var offset = 0;
  16120. for (i = 0; i < length - 1; i++) {
  16121. var p0 = positions[i];
  16122. var p1 = positions[i + 1];
  16123. var h0 = hasHeightArray ? height[i] : height;
  16124. var h1 = hasHeightArray ? height[i + 1] : height;
  16125. offset = generateCartesianArc(p0, p1, minDistance, ellipsoid, h0, h1, newPositions, offset);
  16126. }
  16127. subdivideHeightsScratchArray.length = 0;
  16128. var lastPoint = positions[length - 1];
  16129. var carto = ellipsoid.cartesianToCartographic(lastPoint, carto1);
  16130. carto.height = hasHeightArray ? height[length - 1] : height;
  16131. var cart = ellipsoid.cartographicToCartesian(carto, cartesian);
  16132. Cartesian3.pack(cart, newPositions, arrayLength - 3);
  16133. return newPositions;
  16134. };
  16135. /**
  16136. * Subdivides polyline and raises all points to the specified height. Returns an array of new {Cartesian3} positions.
  16137. * @param {Cartesian3[]} positions The array of type {Cartesian3} representing positions.
  16138. * @param {Number|Number[]} [height=0.0] A number or array of numbers representing the heights of each position.
  16139. * @param {Number} [granularity = CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.
  16140. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie.
  16141. * @returns {Cartesian3[]} A new array of cartesian3 positions that have been subdivided and raised to the surface of the ellipsoid.
  16142. *
  16143. * @example
  16144. * var positions = Cesium.Cartesian3.fromDegreesArray([
  16145. * -105.0, 40.0,
  16146. * -100.0, 38.0,
  16147. * -105.0, 35.0,
  16148. * -100.0, 32.0
  16149. * ]);
  16150. * var surfacePositions = Cesium.PolylinePipeline.generateCartesianArc({
  16151. * positons: positions
  16152. * });
  16153. */
  16154. PolylinePipeline.generateCartesianArc = function(options) {
  16155. var numberArray = PolylinePipeline.generateArc(options);
  16156. var size = numberArray.length/3;
  16157. var newPositions = new Array(size);
  16158. for (var i = 0; i < size; i++) {
  16159. newPositions[i] = Cartesian3.unpack(numberArray, i*3);
  16160. }
  16161. return newPositions;
  16162. };
  16163. return PolylinePipeline;
  16164. });
  16165. /*global define*/
  16166. define('Core/VertexFormat',[
  16167. './defaultValue',
  16168. './defined',
  16169. './DeveloperError',
  16170. './freezeObject'
  16171. ], function(
  16172. defaultValue,
  16173. defined,
  16174. DeveloperError,
  16175. freezeObject) {
  16176. 'use strict';
  16177. /**
  16178. * A vertex format defines what attributes make up a vertex. A VertexFormat can be provided
  16179. * to a {@link Geometry} to request that certain properties be computed, e.g., just position,
  16180. * position and normal, etc.
  16181. *
  16182. * @param {Object} [options] An object with boolean properties corresponding to VertexFormat properties as shown in the code example.
  16183. *
  16184. * @alias VertexFormat
  16185. * @constructor
  16186. *
  16187. * @example
  16188. * // Create a vertex format with position and 2D texture coordinate attributes.
  16189. * var format = new Cesium.VertexFormat({
  16190. * position : true,
  16191. * st : true
  16192. * });
  16193. *
  16194. * @see Geometry#attributes
  16195. * @see Packable
  16196. */
  16197. function VertexFormat(options) {
  16198. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  16199. /**
  16200. * When <code>true</code>, the vertex has a 3D position attribute.
  16201. * <p>
  16202. * 64-bit floating-point (for precision). 3 components per attribute.
  16203. * </p>
  16204. *
  16205. * @type Boolean
  16206. *
  16207. * @default false
  16208. */
  16209. this.position = defaultValue(options.position, false);
  16210. /**
  16211. * When <code>true</code>, the vertex has a normal attribute (normalized), which is commonly used for lighting.
  16212. * <p>
  16213. * 32-bit floating-point. 3 components per attribute.
  16214. * </p>
  16215. *
  16216. * @type Boolean
  16217. *
  16218. * @default false
  16219. */
  16220. this.normal = defaultValue(options.normal, false);
  16221. /**
  16222. * When <code>true</code>, the vertex has a 2D texture coordinate attribute.
  16223. * <p>
  16224. * 32-bit floating-point. 2 components per attribute
  16225. * </p>
  16226. *
  16227. * @type Boolean
  16228. *
  16229. * @default false
  16230. */
  16231. this.st = defaultValue(options.st, false);
  16232. /**
  16233. * When <code>true</code>, the vertex has a binormal attribute (normalized), which is used for tangent-space effects like bump mapping.
  16234. * <p>
  16235. * 32-bit floating-point. 3 components per attribute.
  16236. * </p>
  16237. *
  16238. * @type Boolean
  16239. *
  16240. * @default false
  16241. */
  16242. this.binormal = defaultValue(options.binormal, false);
  16243. /**
  16244. * When <code>true</code>, the vertex has a tangent attribute (normalized), which is used for tangent-space effects like bump mapping.
  16245. * <p>
  16246. * 32-bit floating-point. 3 components per attribute.
  16247. * </p>
  16248. *
  16249. * @type Boolean
  16250. *
  16251. * @default false
  16252. */
  16253. this.tangent = defaultValue(options.tangent, false);
  16254. /**
  16255. * When <code>true</code>, the vertex has an RGB color attribute.
  16256. * <p>
  16257. * 8-bit unsigned byte. 3 components per attribute.
  16258. * </p>
  16259. *
  16260. * @type Boolean
  16261. *
  16262. * @default false
  16263. */
  16264. this.color = defaultValue(options.color, false);
  16265. }
  16266. /**
  16267. * An immutable vertex format with only a position attribute.
  16268. *
  16269. * @type {VertexFormat}
  16270. * @constant
  16271. *
  16272. * @see VertexFormat#position
  16273. */
  16274. VertexFormat.POSITION_ONLY = freezeObject(new VertexFormat({
  16275. position : true
  16276. }));
  16277. /**
  16278. * An immutable vertex format with position and normal attributes.
  16279. * This is compatible with per-instance color appearances like {@link PerInstanceColorAppearance}.
  16280. *
  16281. * @type {VertexFormat}
  16282. * @constant
  16283. *
  16284. * @see VertexFormat#position
  16285. * @see VertexFormat#normal
  16286. */
  16287. VertexFormat.POSITION_AND_NORMAL = freezeObject(new VertexFormat({
  16288. position : true,
  16289. normal : true
  16290. }));
  16291. /**
  16292. * An immutable vertex format with position, normal, and st attributes.
  16293. * This is compatible with {@link MaterialAppearance} when {@link MaterialAppearance#materialSupport}
  16294. * is <code>TEXTURED/code>.
  16295. *
  16296. * @type {VertexFormat}
  16297. * @constant
  16298. *
  16299. * @see VertexFormat#position
  16300. * @see VertexFormat#normal
  16301. * @see VertexFormat#st
  16302. */
  16303. VertexFormat.POSITION_NORMAL_AND_ST = freezeObject(new VertexFormat({
  16304. position : true,
  16305. normal : true,
  16306. st : true
  16307. }));
  16308. /**
  16309. * An immutable vertex format with position and st attributes.
  16310. * This is compatible with {@link EllipsoidSurfaceAppearance}.
  16311. *
  16312. * @type {VertexFormat}
  16313. * @constant
  16314. *
  16315. * @see VertexFormat#position
  16316. * @see VertexFormat#st
  16317. */
  16318. VertexFormat.POSITION_AND_ST = freezeObject(new VertexFormat({
  16319. position : true,
  16320. st : true
  16321. }));
  16322. /**
  16323. * An immutable vertex format with position and color attributes.
  16324. *
  16325. * @type {VertexFormat}
  16326. * @constant
  16327. *
  16328. * @see VertexFormat#position
  16329. * @see VertexFormat#color
  16330. */
  16331. VertexFormat.POSITION_AND_COLOR = freezeObject(new VertexFormat({
  16332. position : true,
  16333. color : true
  16334. }));
  16335. /**
  16336. * An immutable vertex format with well-known attributes: position, normal, st, binormal, and tangent.
  16337. *
  16338. * @type {VertexFormat}
  16339. * @constant
  16340. *
  16341. * @see VertexFormat#position
  16342. * @see VertexFormat#normal
  16343. * @see VertexFormat#st
  16344. * @see VertexFormat#binormal
  16345. * @see VertexFormat#tangent
  16346. */
  16347. VertexFormat.ALL = freezeObject(new VertexFormat({
  16348. position : true,
  16349. normal : true,
  16350. st : true,
  16351. binormal : true,
  16352. tangent : true
  16353. }));
  16354. /**
  16355. * An immutable vertex format with position, normal, and st attributes.
  16356. * This is compatible with most appearances and materials; however
  16357. * normal and st attributes are not always required. When this is
  16358. * known in advance, another <code>VertexFormat</code> should be used.
  16359. *
  16360. * @type {VertexFormat}
  16361. * @constant
  16362. *
  16363. * @see VertexFormat#position
  16364. * @see VertexFormat#normal
  16365. */
  16366. VertexFormat.DEFAULT = VertexFormat.POSITION_NORMAL_AND_ST;
  16367. /**
  16368. * The number of elements used to pack the object into an array.
  16369. * @type {Number}
  16370. */
  16371. VertexFormat.packedLength = 6;
  16372. /**
  16373. * Stores the provided instance into the provided array.
  16374. *
  16375. * @param {VertexFormat} value The value to pack.
  16376. * @param {Number[]} array The array to pack into.
  16377. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  16378. *
  16379. * @returns {Number[]} The array that was packed into
  16380. */
  16381. VertexFormat.pack = function(value, array, startingIndex) {
  16382. if (!defined(value)) {
  16383. throw new DeveloperError('value is required');
  16384. }
  16385. if (!defined(array)) {
  16386. throw new DeveloperError('array is required');
  16387. }
  16388. startingIndex = defaultValue(startingIndex, 0);
  16389. array[startingIndex++] = value.position ? 1.0 : 0.0;
  16390. array[startingIndex++] = value.normal ? 1.0 : 0.0;
  16391. array[startingIndex++] = value.st ? 1.0 : 0.0;
  16392. array[startingIndex++] = value.binormal ? 1.0 : 0.0;
  16393. array[startingIndex++] = value.tangent ? 1.0 : 0.0;
  16394. array[startingIndex++] = value.color ? 1.0 : 0.0;
  16395. return array;
  16396. };
  16397. /**
  16398. * Retrieves an instance from a packed array.
  16399. *
  16400. * @param {Number[]} array The packed array.
  16401. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  16402. * @param {VertexFormat} [result] The object into which to store the result.
  16403. * @returns {VertexFormat} The modified result parameter or a new VertexFormat instance if one was not provided.
  16404. */
  16405. VertexFormat.unpack = function(array, startingIndex, result) {
  16406. if (!defined(array)) {
  16407. throw new DeveloperError('array is required');
  16408. }
  16409. startingIndex = defaultValue(startingIndex, 0);
  16410. if (!defined(result)) {
  16411. result = new VertexFormat();
  16412. }
  16413. result.position = array[startingIndex++] === 1.0;
  16414. result.normal = array[startingIndex++] === 1.0;
  16415. result.st = array[startingIndex++] === 1.0;
  16416. result.binormal = array[startingIndex++] === 1.0;
  16417. result.tangent = array[startingIndex++] === 1.0;
  16418. result.color = array[startingIndex++] === 1.0;
  16419. return result;
  16420. };
  16421. /**
  16422. * Duplicates a VertexFormat instance.
  16423. *
  16424. * @param {VertexFormat} cartesian The vertex format to duplicate.
  16425. * @param {VertexFormat} [result] The object onto which to store the result.
  16426. * @returns {VertexFormat} The modified result parameter or a new VertexFormat instance if one was not provided. (Returns undefined if vertexFormat is undefined)
  16427. */
  16428. VertexFormat.clone = function(vertexFormat, result) {
  16429. if (!defined(vertexFormat)) {
  16430. return undefined;
  16431. }
  16432. if (!defined(result)) {
  16433. result = new VertexFormat();
  16434. }
  16435. result.position = vertexFormat.position;
  16436. result.normal = vertexFormat.normal;
  16437. result.st = vertexFormat.st;
  16438. result.binormal = vertexFormat.binormal;
  16439. result.tangent = vertexFormat.tangent;
  16440. result.color = vertexFormat.color;
  16441. return result;
  16442. };
  16443. return VertexFormat;
  16444. });
  16445. /*global define*/
  16446. define('Core/PolylineGeometry',[
  16447. './arrayRemoveDuplicates',
  16448. './BoundingSphere',
  16449. './Cartesian3',
  16450. './Color',
  16451. './ComponentDatatype',
  16452. './defaultValue',
  16453. './defined',
  16454. './DeveloperError',
  16455. './Ellipsoid',
  16456. './Geometry',
  16457. './GeometryAttribute',
  16458. './GeometryAttributes',
  16459. './GeometryType',
  16460. './IndexDatatype',
  16461. './Math',
  16462. './PolylinePipeline',
  16463. './PrimitiveType',
  16464. './VertexFormat'
  16465. ], function(
  16466. arrayRemoveDuplicates,
  16467. BoundingSphere,
  16468. Cartesian3,
  16469. Color,
  16470. ComponentDatatype,
  16471. defaultValue,
  16472. defined,
  16473. DeveloperError,
  16474. Ellipsoid,
  16475. Geometry,
  16476. GeometryAttribute,
  16477. GeometryAttributes,
  16478. GeometryType,
  16479. IndexDatatype,
  16480. CesiumMath,
  16481. PolylinePipeline,
  16482. PrimitiveType,
  16483. VertexFormat) {
  16484. 'use strict';
  16485. var scratchInterpolateColorsArray = [];
  16486. function interpolateColors(p0, p1, color0, color1, numPoints) {
  16487. var colors = scratchInterpolateColorsArray;
  16488. colors.length = numPoints;
  16489. var i;
  16490. var r0 = color0.red;
  16491. var g0 = color0.green;
  16492. var b0 = color0.blue;
  16493. var a0 = color0.alpha;
  16494. var r1 = color1.red;
  16495. var g1 = color1.green;
  16496. var b1 = color1.blue;
  16497. var a1 = color1.alpha;
  16498. if (Color.equals(color0, color1)) {
  16499. for (i = 0; i < numPoints; i++) {
  16500. colors[i] = Color.clone(color0);
  16501. }
  16502. return colors;
  16503. }
  16504. var redPerVertex = (r1 - r0) / numPoints;
  16505. var greenPerVertex = (g1 - g0) / numPoints;
  16506. var bluePerVertex = (b1 - b0) / numPoints;
  16507. var alphaPerVertex = (a1 - a0) / numPoints;
  16508. for (i = 0; i < numPoints; i++) {
  16509. colors[i] = new Color(r0 + i * redPerVertex, g0 + i * greenPerVertex, b0 + i * bluePerVertex, a0 + i * alphaPerVertex);
  16510. }
  16511. return colors;
  16512. }
  16513. /**
  16514. * A description of a polyline modeled as a line strip; the first two positions define a line segment,
  16515. * and each additional position defines a line segment from the previous position. The polyline is capable of
  16516. * displaying with a material.
  16517. *
  16518. * @alias PolylineGeometry
  16519. * @constructor
  16520. *
  16521. * @param {Object} options Object with the following properties:
  16522. * @param {Cartesian3[]} options.positions An array of {@link Cartesian3} defining the positions in the polyline as a line strip.
  16523. * @param {Number} [options.width=1.0] The width in pixels.
  16524. * @param {Color[]} [options.colors] An Array of {@link Color} defining the per vertex or per segment colors.
  16525. * @param {Boolean} [options.colorsPerVertex=false] A boolean that determines whether the colors will be flat across each segment of the line or interpolated across the vertices.
  16526. * @param {Boolean} [options.followSurface=true] A boolean that determines whether positions will be adjusted to the surface of the ellipsoid via a great arc.
  16527. * @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude if options.followSurface=true. Determines the number of positions in the buffer.
  16528. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  16529. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.
  16530. *
  16531. * @exception {DeveloperError} At least two positions are required.
  16532. * @exception {DeveloperError} width must be greater than or equal to one.
  16533. * @exception {DeveloperError} colors has an invalid length.
  16534. *
  16535. * @see PolylineGeometry#createGeometry
  16536. *
  16537. * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Polyline.html|Cesium Sandcastle Polyline Demo}
  16538. *
  16539. * @example
  16540. * // A polyline with two connected line segments
  16541. * var polyline = new Cesium.PolylineGeometry({
  16542. * positions : Cesium.Cartesian3.fromDegreesArray([
  16543. * 0.0, 0.0,
  16544. * 5.0, 0.0,
  16545. * 5.0, 5.0
  16546. * ]),
  16547. * width : 10.0
  16548. * });
  16549. * var geometry = Cesium.PolylineGeometry.createGeometry(polyline);
  16550. */
  16551. function PolylineGeometry(options) {
  16552. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  16553. var positions = options.positions;
  16554. var colors = options.colors;
  16555. var width = defaultValue(options.width, 1.0);
  16556. var colorsPerVertex = defaultValue(options.colorsPerVertex, false);
  16557. if ((!defined(positions)) || (positions.length < 2)) {
  16558. throw new DeveloperError('At least two positions are required.');
  16559. }
  16560. if (typeof width !== 'number') {
  16561. throw new DeveloperError('width must be a number');
  16562. }
  16563. if (defined(colors) && ((colorsPerVertex && colors.length < positions.length) || (!colorsPerVertex && colors.length < positions.length - 1))) {
  16564. throw new DeveloperError('colors has an invalid length.');
  16565. }
  16566. this._positions = positions;
  16567. this._colors = colors;
  16568. this._width = width;
  16569. this._colorsPerVertex = colorsPerVertex;
  16570. this._vertexFormat = VertexFormat.clone(defaultValue(options.vertexFormat, VertexFormat.DEFAULT));
  16571. this._followSurface = defaultValue(options.followSurface, true);
  16572. this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE);
  16573. this._ellipsoid = Ellipsoid.clone(defaultValue(options.ellipsoid, Ellipsoid.WGS84));
  16574. this._workerName = 'createPolylineGeometry';
  16575. var numComponents = 1 + positions.length * Cartesian3.packedLength;
  16576. numComponents += defined(colors) ? 1 + colors.length * Color.packedLength : 1;
  16577. /**
  16578. * The number of elements used to pack the object into an array.
  16579. * @type {Number}
  16580. */
  16581. this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 4;
  16582. }
  16583. /**
  16584. * Stores the provided instance into the provided array.
  16585. *
  16586. * @param {PolylineGeometry} value The value to pack.
  16587. * @param {Number[]} array The array to pack into.
  16588. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  16589. *
  16590. * @returns {Number[]} The array that was packed into
  16591. */
  16592. PolylineGeometry.pack = function(value, array, startingIndex) {
  16593. if (!defined(value)) {
  16594. throw new DeveloperError('value is required');
  16595. }
  16596. if (!defined(array)) {
  16597. throw new DeveloperError('array is required');
  16598. }
  16599. startingIndex = defaultValue(startingIndex, 0);
  16600. var i;
  16601. var positions = value._positions;
  16602. var length = positions.length;
  16603. array[startingIndex++] = length;
  16604. for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {
  16605. Cartesian3.pack(positions[i], array, startingIndex);
  16606. }
  16607. var colors = value._colors;
  16608. length = defined(colors) ? colors.length : 0.0;
  16609. array[startingIndex++] = length;
  16610. for (i = 0; i < length; ++i, startingIndex += Color.packedLength) {
  16611. Color.pack(colors[i], array, startingIndex);
  16612. }
  16613. Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  16614. startingIndex += Ellipsoid.packedLength;
  16615. VertexFormat.pack(value._vertexFormat, array, startingIndex);
  16616. startingIndex += VertexFormat.packedLength;
  16617. array[startingIndex++] = value._width;
  16618. array[startingIndex++] = value._colorsPerVertex ? 1.0 : 0.0;
  16619. array[startingIndex++] = value._followSurface ? 1.0 : 0.0;
  16620. array[startingIndex] = value._granularity;
  16621. return array;
  16622. };
  16623. var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);
  16624. var scratchVertexFormat = new VertexFormat();
  16625. var scratchOptions = {
  16626. positions : undefined,
  16627. colors : undefined,
  16628. ellipsoid : scratchEllipsoid,
  16629. vertexFormat : scratchVertexFormat,
  16630. width : undefined,
  16631. colorsPerVertex : undefined,
  16632. followSurface : undefined,
  16633. granularity : undefined
  16634. };
  16635. /**
  16636. * Retrieves an instance from a packed array.
  16637. *
  16638. * @param {Number[]} array The packed array.
  16639. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  16640. * @param {PolylineGeometry} [result] The object into which to store the result.
  16641. * @returns {PolylineGeometry} The modified result parameter or a new PolylineGeometry instance if one was not provided.
  16642. */
  16643. PolylineGeometry.unpack = function(array, startingIndex, result) {
  16644. if (!defined(array)) {
  16645. throw new DeveloperError('array is required');
  16646. }
  16647. startingIndex = defaultValue(startingIndex, 0);
  16648. var i;
  16649. var length = array[startingIndex++];
  16650. var positions = new Array(length);
  16651. for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {
  16652. positions[i] = Cartesian3.unpack(array, startingIndex);
  16653. }
  16654. length = array[startingIndex++];
  16655. var colors = length > 0 ? new Array(length) : undefined;
  16656. for (i = 0; i < length; ++i, startingIndex += Color.packedLength) {
  16657. colors[i] = Color.unpack(array, startingIndex);
  16658. }
  16659. var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  16660. startingIndex += Ellipsoid.packedLength;
  16661. var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat);
  16662. startingIndex += VertexFormat.packedLength;
  16663. var width = array[startingIndex++];
  16664. var colorsPerVertex = array[startingIndex++] === 1.0;
  16665. var followSurface = array[startingIndex++] === 1.0;
  16666. var granularity = array[startingIndex];
  16667. if (!defined(result)) {
  16668. scratchOptions.positions = positions;
  16669. scratchOptions.colors = colors;
  16670. scratchOptions.width = width;
  16671. scratchOptions.colorsPerVertex = colorsPerVertex;
  16672. scratchOptions.followSurface = followSurface;
  16673. scratchOptions.granularity = granularity;
  16674. return new PolylineGeometry(scratchOptions);
  16675. }
  16676. result._positions = positions;
  16677. result._colors = colors;
  16678. result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);
  16679. result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);
  16680. result._width = width;
  16681. result._colorsPerVertex = colorsPerVertex;
  16682. result._followSurface = followSurface;
  16683. result._granularity = granularity;
  16684. return result;
  16685. };
  16686. var scratchCartesian3 = new Cartesian3();
  16687. var scratchPosition = new Cartesian3();
  16688. var scratchPrevPosition = new Cartesian3();
  16689. var scratchNextPosition = new Cartesian3();
  16690. /**
  16691. * Computes the geometric representation of a polyline, including its vertices, indices, and a bounding sphere.
  16692. *
  16693. * @param {PolylineGeometry} polylineGeometry A description of the polyline.
  16694. * @returns {Geometry|undefined} The computed vertices and indices.
  16695. */
  16696. PolylineGeometry.createGeometry = function(polylineGeometry) {
  16697. var width = polylineGeometry._width;
  16698. var vertexFormat = polylineGeometry._vertexFormat;
  16699. var colors = polylineGeometry._colors;
  16700. var colorsPerVertex = polylineGeometry._colorsPerVertex;
  16701. var followSurface = polylineGeometry._followSurface;
  16702. var granularity = polylineGeometry._granularity;
  16703. var ellipsoid = polylineGeometry._ellipsoid;
  16704. var i;
  16705. var j;
  16706. var k;
  16707. var positions = arrayRemoveDuplicates(polylineGeometry._positions, Cartesian3.equalsEpsilon);
  16708. var positionsLength = positions.length;
  16709. // A width of a pixel or less is not a valid geometry, but in order to support external data
  16710. // that may have errors we treat this as an empty geometry.
  16711. if (positionsLength < 2 || width <= 0.0) {
  16712. return undefined;
  16713. }
  16714. if (followSurface) {
  16715. var heights = PolylinePipeline.extractHeights(positions, ellipsoid);
  16716. var minDistance = CesiumMath.chordLength(granularity, ellipsoid.maximumRadius);
  16717. if (defined(colors)) {
  16718. var colorLength = 1;
  16719. for (i = 0; i < positionsLength - 1; ++i) {
  16720. colorLength += PolylinePipeline.numberOfPoints(positions[i], positions[i+1], minDistance);
  16721. }
  16722. var newColors = new Array(colorLength);
  16723. var newColorIndex = 0;
  16724. for (i = 0; i < positionsLength - 1; ++i) {
  16725. var p0 = positions[i];
  16726. var p1 = positions[i+1];
  16727. var c0 = colors[i];
  16728. var numColors = PolylinePipeline.numberOfPoints(p0, p1, minDistance);
  16729. if (colorsPerVertex && i < colorLength) {
  16730. var c1 = colors[i+1];
  16731. var interpolatedColors = interpolateColors(p0, p1, c0, c1, numColors);
  16732. var interpolatedColorsLength = interpolatedColors.length;
  16733. for (j = 0; j < interpolatedColorsLength; ++j) {
  16734. newColors[newColorIndex++] = interpolatedColors[j];
  16735. }
  16736. } else {
  16737. for (j = 0; j < numColors; ++j) {
  16738. newColors[newColorIndex++] = Color.clone(c0);
  16739. }
  16740. }
  16741. }
  16742. newColors[newColorIndex] = Color.clone(colors[colors.length-1]);
  16743. colors = newColors;
  16744. scratchInterpolateColorsArray.length = 0;
  16745. }
  16746. positions = PolylinePipeline.generateCartesianArc({
  16747. positions: positions,
  16748. minDistance: minDistance,
  16749. ellipsoid: ellipsoid,
  16750. height: heights
  16751. });
  16752. }
  16753. positionsLength = positions.length;
  16754. var size = positionsLength * 4.0 - 4.0;
  16755. var finalPositions = new Float64Array(size * 3);
  16756. var prevPositions = new Float64Array(size * 3);
  16757. var nextPositions = new Float64Array(size * 3);
  16758. var expandAndWidth = new Float32Array(size * 2);
  16759. var st = vertexFormat.st ? new Float32Array(size * 2) : undefined;
  16760. var finalColors = defined(colors) ? new Uint8Array(size * 4) : undefined;
  16761. var positionIndex = 0;
  16762. var expandAndWidthIndex = 0;
  16763. var stIndex = 0;
  16764. var colorIndex = 0;
  16765. var position;
  16766. for (j = 0; j < positionsLength; ++j) {
  16767. if (j === 0) {
  16768. position = scratchCartesian3;
  16769. Cartesian3.subtract(positions[0], positions[1], position);
  16770. Cartesian3.add(positions[0], position, position);
  16771. } else {
  16772. position = positions[j - 1];
  16773. }
  16774. Cartesian3.clone(position, scratchPrevPosition);
  16775. Cartesian3.clone(positions[j], scratchPosition);
  16776. if (j === positionsLength - 1) {
  16777. position = scratchCartesian3;
  16778. Cartesian3.subtract(positions[positionsLength - 1], positions[positionsLength - 2], position);
  16779. Cartesian3.add(positions[positionsLength - 1], position, position);
  16780. } else {
  16781. position = positions[j + 1];
  16782. }
  16783. Cartesian3.clone(position, scratchNextPosition);
  16784. var color0, color1;
  16785. if (defined(finalColors)) {
  16786. if (j !== 0 && !colorsPerVertex) {
  16787. color0 = colors[j - 1];
  16788. } else {
  16789. color0 = colors[j];
  16790. }
  16791. if (j !== positionsLength - 1) {
  16792. color1 = colors[j];
  16793. }
  16794. }
  16795. var startK = j === 0 ? 2 : 0;
  16796. var endK = j === positionsLength - 1 ? 2 : 4;
  16797. for (k = startK; k < endK; ++k) {
  16798. Cartesian3.pack(scratchPosition, finalPositions, positionIndex);
  16799. Cartesian3.pack(scratchPrevPosition, prevPositions, positionIndex);
  16800. Cartesian3.pack(scratchNextPosition, nextPositions, positionIndex);
  16801. positionIndex += 3;
  16802. var direction = (k - 2 < 0) ? -1.0 : 1.0;
  16803. expandAndWidth[expandAndWidthIndex++] = 2 * (k % 2) - 1; // expand direction
  16804. expandAndWidth[expandAndWidthIndex++] = direction * width;
  16805. if (vertexFormat.st) {
  16806. st[stIndex++] = j / (positionsLength - 1);
  16807. st[stIndex++] = Math.max(expandAndWidth[expandAndWidthIndex - 2], 0.0);
  16808. }
  16809. if (defined(finalColors)) {
  16810. var color = (k < 2) ? color0 : color1;
  16811. finalColors[colorIndex++] = Color.floatToByte(color.red);
  16812. finalColors[colorIndex++] = Color.floatToByte(color.green);
  16813. finalColors[colorIndex++] = Color.floatToByte(color.blue);
  16814. finalColors[colorIndex++] = Color.floatToByte(color.alpha);
  16815. }
  16816. }
  16817. }
  16818. var attributes = new GeometryAttributes();
  16819. attributes.position = new GeometryAttribute({
  16820. componentDatatype : ComponentDatatype.DOUBLE,
  16821. componentsPerAttribute : 3,
  16822. values : finalPositions
  16823. });
  16824. attributes.prevPosition = new GeometryAttribute({
  16825. componentDatatype : ComponentDatatype.DOUBLE,
  16826. componentsPerAttribute : 3,
  16827. values : prevPositions
  16828. });
  16829. attributes.nextPosition = new GeometryAttribute({
  16830. componentDatatype : ComponentDatatype.DOUBLE,
  16831. componentsPerAttribute : 3,
  16832. values : nextPositions
  16833. });
  16834. attributes.expandAndWidth = new GeometryAttribute({
  16835. componentDatatype : ComponentDatatype.FLOAT,
  16836. componentsPerAttribute : 2,
  16837. values : expandAndWidth
  16838. });
  16839. if (vertexFormat.st) {
  16840. attributes.st = new GeometryAttribute({
  16841. componentDatatype : ComponentDatatype.FLOAT,
  16842. componentsPerAttribute : 2,
  16843. values : st
  16844. });
  16845. }
  16846. if (defined(finalColors)) {
  16847. attributes.color = new GeometryAttribute({
  16848. componentDatatype : ComponentDatatype.UNSIGNED_BYTE,
  16849. componentsPerAttribute : 4,
  16850. values : finalColors,
  16851. normalize : true
  16852. });
  16853. }
  16854. var indices = IndexDatatype.createTypedArray(size, positionsLength * 6 - 6);
  16855. var index = 0;
  16856. var indicesIndex = 0;
  16857. var length = positionsLength - 1.0;
  16858. for (j = 0; j < length; ++j) {
  16859. indices[indicesIndex++] = index;
  16860. indices[indicesIndex++] = index + 2;
  16861. indices[indicesIndex++] = index + 1;
  16862. indices[indicesIndex++] = index + 1;
  16863. indices[indicesIndex++] = index + 2;
  16864. indices[indicesIndex++] = index + 3;
  16865. index += 4;
  16866. }
  16867. return new Geometry({
  16868. attributes : attributes,
  16869. indices : indices,
  16870. primitiveType : PrimitiveType.TRIANGLES,
  16871. boundingSphere : BoundingSphere.fromPoints(positions),
  16872. geometryType : GeometryType.POLYLINES
  16873. });
  16874. };
  16875. return PolylineGeometry;
  16876. });
  16877. /*global define*/
  16878. define('Workers/createPolylineGeometry',[
  16879. '../Core/defined',
  16880. '../Core/Ellipsoid',
  16881. '../Core/PolylineGeometry'
  16882. ], function(
  16883. defined,
  16884. Ellipsoid,
  16885. PolylineGeometry) {
  16886. 'use strict';
  16887. function createPolylineGeometry(polylineGeometry, offset) {
  16888. if (defined(offset)) {
  16889. polylineGeometry = PolylineGeometry.unpack(polylineGeometry, offset);
  16890. }
  16891. polylineGeometry._ellipsoid = Ellipsoid.clone(polylineGeometry._ellipsoid);
  16892. return PolylineGeometry.createGeometry(polylineGeometry);
  16893. }
  16894. return createPolylineGeometry;
  16895. });
  16896. }());