createWallGeometry.js 949 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904
  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/GeographicProjection',[
  3058. './Cartesian3',
  3059. './Cartographic',
  3060. './defaultValue',
  3061. './defined',
  3062. './defineProperties',
  3063. './DeveloperError',
  3064. './Ellipsoid'
  3065. ], function(
  3066. Cartesian3,
  3067. Cartographic,
  3068. defaultValue,
  3069. defined,
  3070. defineProperties,
  3071. DeveloperError,
  3072. Ellipsoid) {
  3073. 'use strict';
  3074. /**
  3075. * A simple map projection where longitude and latitude are linearly mapped to X and Y by multiplying
  3076. * them by the {@link Ellipsoid#maximumRadius}. This projection
  3077. * is commonly known as geographic, equirectangular, equidistant cylindrical, or plate carrée. It
  3078. * is also known as EPSG:4326.
  3079. *
  3080. * @alias GeographicProjection
  3081. * @constructor
  3082. *
  3083. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid.
  3084. *
  3085. * @see WebMercatorProjection
  3086. */
  3087. function GeographicProjection(ellipsoid) {
  3088. this._ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
  3089. this._semimajorAxis = this._ellipsoid.maximumRadius;
  3090. this._oneOverSemimajorAxis = 1.0 / this._semimajorAxis;
  3091. }
  3092. defineProperties(GeographicProjection.prototype, {
  3093. /**
  3094. * Gets the {@link Ellipsoid}.
  3095. *
  3096. * @memberof GeographicProjection.prototype
  3097. *
  3098. * @type {Ellipsoid}
  3099. * @readonly
  3100. */
  3101. ellipsoid : {
  3102. get : function() {
  3103. return this._ellipsoid;
  3104. }
  3105. }
  3106. });
  3107. /**
  3108. * Projects a set of {@link Cartographic} coordinates, in radians, to map coordinates, in meters.
  3109. * X and Y are the longitude and latitude, respectively, multiplied by the maximum radius of the
  3110. * ellipsoid. Z is the unmodified height.
  3111. *
  3112. * @param {Cartographic} cartographic The coordinates to project.
  3113. * @param {Cartesian3} [result] An instance into which to copy the result. If this parameter is
  3114. * undefined, a new instance is created and returned.
  3115. * @returns {Cartesian3} The projected coordinates. If the result parameter is not undefined, the
  3116. * coordinates are copied there and that instance is returned. Otherwise, a new instance is
  3117. * created and returned.
  3118. */
  3119. GeographicProjection.prototype.project = function(cartographic, result) {
  3120. // Actually this is the special case of equidistant cylindrical called the plate carree
  3121. var semimajorAxis = this._semimajorAxis;
  3122. var x = cartographic.longitude * semimajorAxis;
  3123. var y = cartographic.latitude * semimajorAxis;
  3124. var z = cartographic.height;
  3125. if (!defined(result)) {
  3126. return new Cartesian3(x, y, z);
  3127. }
  3128. result.x = x;
  3129. result.y = y;
  3130. result.z = z;
  3131. return result;
  3132. };
  3133. /**
  3134. * Unprojects a set of projected {@link Cartesian3} coordinates, in meters, to {@link Cartographic}
  3135. * coordinates, in radians. Longitude and Latitude are the X and Y coordinates, respectively,
  3136. * divided by the maximum radius of the ellipsoid. Height is the unmodified Z coordinate.
  3137. *
  3138. * @param {Cartesian3} cartesian The Cartesian position to unproject with height (z) in meters.
  3139. * @param {Cartographic} [result] An instance into which to copy the result. If this parameter is
  3140. * undefined, a new instance is created and returned.
  3141. * @returns {Cartographic} The unprojected coordinates. If the result parameter is not undefined, the
  3142. * coordinates are copied there and that instance is returned. Otherwise, a new instance is
  3143. * created and returned.
  3144. */
  3145. GeographicProjection.prototype.unproject = function(cartesian, result) {
  3146. if (!defined(cartesian)) {
  3147. throw new DeveloperError('cartesian is required');
  3148. }
  3149. var oneOverEarthSemimajorAxis = this._oneOverSemimajorAxis;
  3150. var longitude = cartesian.x * oneOverEarthSemimajorAxis;
  3151. var latitude = cartesian.y * oneOverEarthSemimajorAxis;
  3152. var height = cartesian.z;
  3153. if (!defined(result)) {
  3154. return new Cartographic(longitude, latitude, height);
  3155. }
  3156. result.longitude = longitude;
  3157. result.latitude = latitude;
  3158. result.height = height;
  3159. return result;
  3160. };
  3161. return GeographicProjection;
  3162. });
  3163. /*global define*/
  3164. define('Core/Intersect',[
  3165. './freezeObject'
  3166. ], function(
  3167. freezeObject) {
  3168. 'use strict';
  3169. /**
  3170. * This enumerated type is used in determining where, relative to the frustum, an
  3171. * object is located. The object can either be fully contained within the frustum (INSIDE),
  3172. * partially inside the frustum and partially outside (INTERSECTING), or somwhere entirely
  3173. * outside of the frustum's 6 planes (OUTSIDE).
  3174. *
  3175. * @exports Intersect
  3176. */
  3177. var Intersect = {
  3178. /**
  3179. * Represents that an object is not contained within the frustum.
  3180. *
  3181. * @type {Number}
  3182. * @constant
  3183. */
  3184. OUTSIDE : -1,
  3185. /**
  3186. * Represents that an object intersects one of the frustum's planes.
  3187. *
  3188. * @type {Number}
  3189. * @constant
  3190. */
  3191. INTERSECTING : 0,
  3192. /**
  3193. * Represents that an object is fully within the frustum.
  3194. *
  3195. * @type {Number}
  3196. * @constant
  3197. */
  3198. INSIDE : 1
  3199. };
  3200. return freezeObject(Intersect);
  3201. });
  3202. /*global define*/
  3203. define('Core/Interval',[
  3204. './defaultValue'
  3205. ], function(
  3206. defaultValue) {
  3207. 'use strict';
  3208. /**
  3209. * Represents the closed interval [start, stop].
  3210. * @alias Interval
  3211. * @constructor
  3212. *
  3213. * @param {Number} [start=0.0] The beginning of the interval.
  3214. * @param {Number} [stop=0.0] The end of the interval.
  3215. */
  3216. function Interval(start, stop) {
  3217. /**
  3218. * The beginning of the interval.
  3219. * @type {Number}
  3220. * @default 0.0
  3221. */
  3222. this.start = defaultValue(start, 0.0);
  3223. /**
  3224. * The end of the interval.
  3225. * @type {Number}
  3226. * @default 0.0
  3227. */
  3228. this.stop = defaultValue(stop, 0.0);
  3229. }
  3230. return Interval;
  3231. });
  3232. /*global define*/
  3233. define('Core/Matrix3',[
  3234. './Cartesian3',
  3235. './defaultValue',
  3236. './defined',
  3237. './defineProperties',
  3238. './DeveloperError',
  3239. './freezeObject',
  3240. './Math'
  3241. ], function(
  3242. Cartesian3,
  3243. defaultValue,
  3244. defined,
  3245. defineProperties,
  3246. DeveloperError,
  3247. freezeObject,
  3248. CesiumMath) {
  3249. 'use strict';
  3250. /**
  3251. * A 3x3 matrix, indexable as a column-major order array.
  3252. * Constructor parameters are in row-major order for code readability.
  3253. * @alias Matrix3
  3254. * @constructor
  3255. *
  3256. * @param {Number} [column0Row0=0.0] The value for column 0, row 0.
  3257. * @param {Number} [column1Row0=0.0] The value for column 1, row 0.
  3258. * @param {Number} [column2Row0=0.0] The value for column 2, row 0.
  3259. * @param {Number} [column0Row1=0.0] The value for column 0, row 1.
  3260. * @param {Number} [column1Row1=0.0] The value for column 1, row 1.
  3261. * @param {Number} [column2Row1=0.0] The value for column 2, row 1.
  3262. * @param {Number} [column0Row2=0.0] The value for column 0, row 2.
  3263. * @param {Number} [column1Row2=0.0] The value for column 1, row 2.
  3264. * @param {Number} [column2Row2=0.0] The value for column 2, row 2.
  3265. *
  3266. * @see Matrix3.fromColumnMajorArray
  3267. * @see Matrix3.fromRowMajorArray
  3268. * @see Matrix3.fromQuaternion
  3269. * @see Matrix3.fromScale
  3270. * @see Matrix3.fromUniformScale
  3271. * @see Matrix2
  3272. * @see Matrix4
  3273. */
  3274. function Matrix3(column0Row0, column1Row0, column2Row0,
  3275. column0Row1, column1Row1, column2Row1,
  3276. column0Row2, column1Row2, column2Row2) {
  3277. this[0] = defaultValue(column0Row0, 0.0);
  3278. this[1] = defaultValue(column0Row1, 0.0);
  3279. this[2] = defaultValue(column0Row2, 0.0);
  3280. this[3] = defaultValue(column1Row0, 0.0);
  3281. this[4] = defaultValue(column1Row1, 0.0);
  3282. this[5] = defaultValue(column1Row2, 0.0);
  3283. this[6] = defaultValue(column2Row0, 0.0);
  3284. this[7] = defaultValue(column2Row1, 0.0);
  3285. this[8] = defaultValue(column2Row2, 0.0);
  3286. }
  3287. /**
  3288. * The number of elements used to pack the object into an array.
  3289. * @type {Number}
  3290. */
  3291. Matrix3.packedLength = 9;
  3292. /**
  3293. * Stores the provided instance into the provided array.
  3294. *
  3295. * @param {Matrix3} value The value to pack.
  3296. * @param {Number[]} array The array to pack into.
  3297. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  3298. *
  3299. * @returns {Number[]} The array that was packed into
  3300. */
  3301. Matrix3.pack = function(value, array, startingIndex) {
  3302. if (!defined(value)) {
  3303. throw new DeveloperError('value is required');
  3304. }
  3305. if (!defined(array)) {
  3306. throw new DeveloperError('array is required');
  3307. }
  3308. startingIndex = defaultValue(startingIndex, 0);
  3309. array[startingIndex++] = value[0];
  3310. array[startingIndex++] = value[1];
  3311. array[startingIndex++] = value[2];
  3312. array[startingIndex++] = value[3];
  3313. array[startingIndex++] = value[4];
  3314. array[startingIndex++] = value[5];
  3315. array[startingIndex++] = value[6];
  3316. array[startingIndex++] = value[7];
  3317. array[startingIndex++] = value[8];
  3318. return array;
  3319. };
  3320. /**
  3321. * Retrieves an instance from a packed array.
  3322. *
  3323. * @param {Number[]} array The packed array.
  3324. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  3325. * @param {Matrix3} [result] The object into which to store the result.
  3326. * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
  3327. */
  3328. Matrix3.unpack = function(array, startingIndex, result) {
  3329. if (!defined(array)) {
  3330. throw new DeveloperError('array is required');
  3331. }
  3332. startingIndex = defaultValue(startingIndex, 0);
  3333. if (!defined(result)) {
  3334. result = new Matrix3();
  3335. }
  3336. result[0] = array[startingIndex++];
  3337. result[1] = array[startingIndex++];
  3338. result[2] = array[startingIndex++];
  3339. result[3] = array[startingIndex++];
  3340. result[4] = array[startingIndex++];
  3341. result[5] = array[startingIndex++];
  3342. result[6] = array[startingIndex++];
  3343. result[7] = array[startingIndex++];
  3344. result[8] = array[startingIndex++];
  3345. return result;
  3346. };
  3347. /**
  3348. * Duplicates a Matrix3 instance.
  3349. *
  3350. * @param {Matrix3} matrix The matrix to duplicate.
  3351. * @param {Matrix3} [result] The object onto which to store the result.
  3352. * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided. (Returns undefined if matrix is undefined)
  3353. */
  3354. Matrix3.clone = function(values, result) {
  3355. if (!defined(values)) {
  3356. return undefined;
  3357. }
  3358. if (!defined(result)) {
  3359. return new Matrix3(values[0], values[3], values[6],
  3360. values[1], values[4], values[7],
  3361. values[2], values[5], values[8]);
  3362. }
  3363. result[0] = values[0];
  3364. result[1] = values[1];
  3365. result[2] = values[2];
  3366. result[3] = values[3];
  3367. result[4] = values[4];
  3368. result[5] = values[5];
  3369. result[6] = values[6];
  3370. result[7] = values[7];
  3371. result[8] = values[8];
  3372. return result;
  3373. };
  3374. /**
  3375. * Creates a Matrix3 from 9 consecutive elements in an array.
  3376. *
  3377. * @param {Number[]} array The array whose 9 consecutive elements correspond to the positions of the matrix. Assumes column-major order.
  3378. * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.
  3379. * @param {Matrix3} [result] The object onto which to store the result.
  3380. * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
  3381. *
  3382. * @example
  3383. * // Create the Matrix3:
  3384. * // [1.0, 2.0, 3.0]
  3385. * // [1.0, 2.0, 3.0]
  3386. * // [1.0, 2.0, 3.0]
  3387. *
  3388. * var v = [1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];
  3389. * var m = Cesium.Matrix3.fromArray(v);
  3390. *
  3391. * // Create same Matrix3 with using an offset into an array
  3392. * var v2 = [0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];
  3393. * var m2 = Cesium.Matrix3.fromArray(v2, 2);
  3394. */
  3395. Matrix3.fromArray = function(array, startingIndex, result) {
  3396. if (!defined(array)) {
  3397. throw new DeveloperError('array is required');
  3398. }
  3399. startingIndex = defaultValue(startingIndex, 0);
  3400. if (!defined(result)) {
  3401. result = new Matrix3();
  3402. }
  3403. result[0] = array[startingIndex];
  3404. result[1] = array[startingIndex + 1];
  3405. result[2] = array[startingIndex + 2];
  3406. result[3] = array[startingIndex + 3];
  3407. result[4] = array[startingIndex + 4];
  3408. result[5] = array[startingIndex + 5];
  3409. result[6] = array[startingIndex + 6];
  3410. result[7] = array[startingIndex + 7];
  3411. result[8] = array[startingIndex + 8];
  3412. return result;
  3413. };
  3414. /**
  3415. * Creates a Matrix3 instance from a column-major order array.
  3416. *
  3417. * @param {Number[]} values The column-major order array.
  3418. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3419. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3420. */
  3421. Matrix3.fromColumnMajorArray = function(values, result) {
  3422. if (!defined(values)) {
  3423. throw new DeveloperError('values parameter is required');
  3424. }
  3425. return Matrix3.clone(values, result);
  3426. };
  3427. /**
  3428. * Creates a Matrix3 instance from a row-major order array.
  3429. * The resulting matrix will be in column-major order.
  3430. *
  3431. * @param {Number[]} values The row-major order array.
  3432. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3433. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3434. */
  3435. Matrix3.fromRowMajorArray = function(values, result) {
  3436. if (!defined(values)) {
  3437. throw new DeveloperError('values is required.');
  3438. }
  3439. if (!defined(result)) {
  3440. return new Matrix3(values[0], values[1], values[2],
  3441. values[3], values[4], values[5],
  3442. values[6], values[7], values[8]);
  3443. }
  3444. result[0] = values[0];
  3445. result[1] = values[3];
  3446. result[2] = values[6];
  3447. result[3] = values[1];
  3448. result[4] = values[4];
  3449. result[5] = values[7];
  3450. result[6] = values[2];
  3451. result[7] = values[5];
  3452. result[8] = values[8];
  3453. return result;
  3454. };
  3455. /**
  3456. * Computes a 3x3 rotation matrix from the provided quaternion.
  3457. *
  3458. * @param {Quaternion} quaternion the quaternion to use.
  3459. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3460. * @returns {Matrix3} The 3x3 rotation matrix from this quaternion.
  3461. */
  3462. Matrix3.fromQuaternion = function(quaternion, result) {
  3463. if (!defined(quaternion)) {
  3464. throw new DeveloperError('quaternion is required');
  3465. }
  3466. var x2 = quaternion.x * quaternion.x;
  3467. var xy = quaternion.x * quaternion.y;
  3468. var xz = quaternion.x * quaternion.z;
  3469. var xw = quaternion.x * quaternion.w;
  3470. var y2 = quaternion.y * quaternion.y;
  3471. var yz = quaternion.y * quaternion.z;
  3472. var yw = quaternion.y * quaternion.w;
  3473. var z2 = quaternion.z * quaternion.z;
  3474. var zw = quaternion.z * quaternion.w;
  3475. var w2 = quaternion.w * quaternion.w;
  3476. var m00 = x2 - y2 - z2 + w2;
  3477. var m01 = 2.0 * (xy - zw);
  3478. var m02 = 2.0 * (xz + yw);
  3479. var m10 = 2.0 * (xy + zw);
  3480. var m11 = -x2 + y2 - z2 + w2;
  3481. var m12 = 2.0 * (yz - xw);
  3482. var m20 = 2.0 * (xz - yw);
  3483. var m21 = 2.0 * (yz + xw);
  3484. var m22 = -x2 - y2 + z2 + w2;
  3485. if (!defined(result)) {
  3486. return new Matrix3(m00, m01, m02,
  3487. m10, m11, m12,
  3488. m20, m21, m22);
  3489. }
  3490. result[0] = m00;
  3491. result[1] = m10;
  3492. result[2] = m20;
  3493. result[3] = m01;
  3494. result[4] = m11;
  3495. result[5] = m21;
  3496. result[6] = m02;
  3497. result[7] = m12;
  3498. result[8] = m22;
  3499. return result;
  3500. };
  3501. /**
  3502. * Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )
  3503. *
  3504. * @param {HeadingPitchRoll} headingPitchRoll the headingPitchRoll to use.
  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 3x3 rotation matrix from this headingPitchRoll.
  3507. */
  3508. Matrix3.fromHeadingPitchRoll = function(headingPitchRoll, result) {
  3509. if (!defined(headingPitchRoll)) {
  3510. throw new DeveloperError('headingPitchRoll is required');
  3511. }
  3512. var cosTheta = Math.cos(-headingPitchRoll.pitch);
  3513. var cosPsi = Math.cos(-headingPitchRoll.heading);
  3514. var cosPhi = Math.cos(headingPitchRoll.roll);
  3515. var sinTheta = Math.sin(-headingPitchRoll.pitch);
  3516. var sinPsi = Math.sin(-headingPitchRoll.heading);
  3517. var sinPhi = Math.sin(headingPitchRoll.roll);
  3518. var m00 = cosTheta * cosPsi;
  3519. var m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi;
  3520. var m02 = sinPhi * sinPsi + cosPhi * sinTheta * cosPsi;
  3521. var m10 = cosTheta * sinPsi;
  3522. var m11 = cosPhi * cosPsi + sinPhi * sinTheta * sinPsi;
  3523. var m12 = -sinTheta * cosPhi + cosPhi * sinTheta * sinPsi;
  3524. var m20 = -sinTheta;
  3525. var m21 = sinPhi * cosTheta;
  3526. var m22 = cosPhi * cosTheta;
  3527. if (!defined(result)) {
  3528. return new Matrix3(m00, m01, m02,
  3529. m10, m11, m12,
  3530. m20, m21, m22);
  3531. }
  3532. result[0] = m00;
  3533. result[1] = m10;
  3534. result[2] = m20;
  3535. result[3] = m01;
  3536. result[4] = m11;
  3537. result[5] = m21;
  3538. result[6] = m02;
  3539. result[7] = m12;
  3540. result[8] = m22;
  3541. return result;
  3542. };
  3543. /**
  3544. * Computes a Matrix3 instance representing a non-uniform scale.
  3545. *
  3546. * @param {Cartesian3} scale The x, y, and z scale factors.
  3547. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3548. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3549. *
  3550. * @example
  3551. * // Creates
  3552. * // [7.0, 0.0, 0.0]
  3553. * // [0.0, 8.0, 0.0]
  3554. * // [0.0, 0.0, 9.0]
  3555. * var m = Cesium.Matrix3.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));
  3556. */
  3557. Matrix3.fromScale = function(scale, result) {
  3558. if (!defined(scale)) {
  3559. throw new DeveloperError('scale is required.');
  3560. }
  3561. if (!defined(result)) {
  3562. return new Matrix3(
  3563. scale.x, 0.0, 0.0,
  3564. 0.0, scale.y, 0.0,
  3565. 0.0, 0.0, scale.z);
  3566. }
  3567. result[0] = scale.x;
  3568. result[1] = 0.0;
  3569. result[2] = 0.0;
  3570. result[3] = 0.0;
  3571. result[4] = scale.y;
  3572. result[5] = 0.0;
  3573. result[6] = 0.0;
  3574. result[7] = 0.0;
  3575. result[8] = scale.z;
  3576. return result;
  3577. };
  3578. /**
  3579. * Computes a Matrix3 instance representing a uniform scale.
  3580. *
  3581. * @param {Number} scale The uniform scale factor.
  3582. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3583. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3584. *
  3585. * @example
  3586. * // Creates
  3587. * // [2.0, 0.0, 0.0]
  3588. * // [0.0, 2.0, 0.0]
  3589. * // [0.0, 0.0, 2.0]
  3590. * var m = Cesium.Matrix3.fromUniformScale(2.0);
  3591. */
  3592. Matrix3.fromUniformScale = function(scale, result) {
  3593. if (typeof scale !== 'number') {
  3594. throw new DeveloperError('scale is required.');
  3595. }
  3596. if (!defined(result)) {
  3597. return new Matrix3(
  3598. scale, 0.0, 0.0,
  3599. 0.0, scale, 0.0,
  3600. 0.0, 0.0, scale);
  3601. }
  3602. result[0] = scale;
  3603. result[1] = 0.0;
  3604. result[2] = 0.0;
  3605. result[3] = 0.0;
  3606. result[4] = scale;
  3607. result[5] = 0.0;
  3608. result[6] = 0.0;
  3609. result[7] = 0.0;
  3610. result[8] = scale;
  3611. return result;
  3612. };
  3613. /**
  3614. * Computes a Matrix3 instance representing the cross product equivalent matrix of a Cartesian3 vector.
  3615. *
  3616. * @param {Cartesian3} the vector on the left hand side of the cross product operation.
  3617. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3618. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3619. *
  3620. * @example
  3621. * // Creates
  3622. * // [0.0, -9.0, 8.0]
  3623. * // [9.0, 0.0, -7.0]
  3624. * // [-8.0, 7.0, 0.0]
  3625. * var m = Cesium.Matrix3.fromCrossProduct(new Cesium.Cartesian3(7.0, 8.0, 9.0));
  3626. */
  3627. Matrix3.fromCrossProduct = function(vector, result) {
  3628. if (!defined(vector)) {
  3629. throw new DeveloperError('vector is required.');
  3630. }
  3631. if (!defined(result)) {
  3632. return new Matrix3(
  3633. 0.0, -vector.z, vector.y,
  3634. vector.z, 0.0, -vector.x,
  3635. -vector.y, vector.x, 0.0);
  3636. }
  3637. result[0] = 0.0;
  3638. result[1] = vector.z;
  3639. result[2] = -vector.y;
  3640. result[3] = -vector.z;
  3641. result[4] = 0.0;
  3642. result[5] = vector.x;
  3643. result[6] = vector.y;
  3644. result[7] = -vector.x;
  3645. result[8] = 0.0;
  3646. return result;
  3647. };
  3648. /**
  3649. * Creates a rotation matrix around the x-axis.
  3650. *
  3651. * @param {Number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
  3652. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3653. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3654. *
  3655. * @example
  3656. * // Rotate a point 45 degrees counterclockwise around the x-axis.
  3657. * var p = new Cesium.Cartesian3(5, 6, 7);
  3658. * var m = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(45.0));
  3659. * var rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
  3660. */
  3661. Matrix3.fromRotationX = function(angle, result) {
  3662. if (!defined(angle)) {
  3663. throw new DeveloperError('angle is required.');
  3664. }
  3665. var cosAngle = Math.cos(angle);
  3666. var sinAngle = Math.sin(angle);
  3667. if (!defined(result)) {
  3668. return new Matrix3(
  3669. 1.0, 0.0, 0.0,
  3670. 0.0, cosAngle, -sinAngle,
  3671. 0.0, sinAngle, cosAngle);
  3672. }
  3673. result[0] = 1.0;
  3674. result[1] = 0.0;
  3675. result[2] = 0.0;
  3676. result[3] = 0.0;
  3677. result[4] = cosAngle;
  3678. result[5] = sinAngle;
  3679. result[6] = 0.0;
  3680. result[7] = -sinAngle;
  3681. result[8] = cosAngle;
  3682. return result;
  3683. };
  3684. /**
  3685. * Creates a rotation matrix around the y-axis.
  3686. *
  3687. * @param {Number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
  3688. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3689. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3690. *
  3691. * @example
  3692. * // Rotate a point 45 degrees counterclockwise around the y-axis.
  3693. * var p = new Cesium.Cartesian3(5, 6, 7);
  3694. * var m = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(45.0));
  3695. * var rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
  3696. */
  3697. Matrix3.fromRotationY = function(angle, result) {
  3698. if (!defined(angle)) {
  3699. throw new DeveloperError('angle is required.');
  3700. }
  3701. var cosAngle = Math.cos(angle);
  3702. var sinAngle = Math.sin(angle);
  3703. if (!defined(result)) {
  3704. return new Matrix3(
  3705. cosAngle, 0.0, sinAngle,
  3706. 0.0, 1.0, 0.0,
  3707. -sinAngle, 0.0, cosAngle);
  3708. }
  3709. result[0] = cosAngle;
  3710. result[1] = 0.0;
  3711. result[2] = -sinAngle;
  3712. result[3] = 0.0;
  3713. result[4] = 1.0;
  3714. result[5] = 0.0;
  3715. result[6] = sinAngle;
  3716. result[7] = 0.0;
  3717. result[8] = cosAngle;
  3718. return result;
  3719. };
  3720. /**
  3721. * Creates a rotation matrix around the z-axis.
  3722. *
  3723. * @param {Number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
  3724. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
  3725. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
  3726. *
  3727. * @example
  3728. * // Rotate a point 45 degrees counterclockwise around the z-axis.
  3729. * var p = new Cesium.Cartesian3(5, 6, 7);
  3730. * var m = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(45.0));
  3731. * var rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
  3732. */
  3733. Matrix3.fromRotationZ = function(angle, result) {
  3734. if (!defined(angle)) {
  3735. throw new DeveloperError('angle is required.');
  3736. }
  3737. var cosAngle = Math.cos(angle);
  3738. var sinAngle = Math.sin(angle);
  3739. if (!defined(result)) {
  3740. return new Matrix3(
  3741. cosAngle, -sinAngle, 0.0,
  3742. sinAngle, cosAngle, 0.0,
  3743. 0.0, 0.0, 1.0);
  3744. }
  3745. result[0] = cosAngle;
  3746. result[1] = sinAngle;
  3747. result[2] = 0.0;
  3748. result[3] = -sinAngle;
  3749. result[4] = cosAngle;
  3750. result[5] = 0.0;
  3751. result[6] = 0.0;
  3752. result[7] = 0.0;
  3753. result[8] = 1.0;
  3754. return result;
  3755. };
  3756. /**
  3757. * Creates an Array from the provided Matrix3 instance.
  3758. * The array will be in column-major order.
  3759. *
  3760. * @param {Matrix3} matrix The matrix to use..
  3761. * @param {Number[]} [result] The Array onto which to store the result.
  3762. * @returns {Number[]} The modified Array parameter or a new Array instance if one was not provided.
  3763. */
  3764. Matrix3.toArray = function(matrix, result) {
  3765. if (!defined(matrix)) {
  3766. throw new DeveloperError('matrix is required');
  3767. }
  3768. if (!defined(result)) {
  3769. return [matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5], matrix[6], matrix[7], matrix[8]];
  3770. }
  3771. result[0] = matrix[0];
  3772. result[1] = matrix[1];
  3773. result[2] = matrix[2];
  3774. result[3] = matrix[3];
  3775. result[4] = matrix[4];
  3776. result[5] = matrix[5];
  3777. result[6] = matrix[6];
  3778. result[7] = matrix[7];
  3779. result[8] = matrix[8];
  3780. return result;
  3781. };
  3782. /**
  3783. * Computes the array index of the element at the provided row and column.
  3784. *
  3785. * @param {Number} row The zero-based index of the row.
  3786. * @param {Number} column The zero-based index of the column.
  3787. * @returns {Number} The index of the element at the provided row and column.
  3788. *
  3789. * @exception {DeveloperError} row must be 0, 1, or 2.
  3790. * @exception {DeveloperError} column must be 0, 1, or 2.
  3791. *
  3792. * @example
  3793. * var myMatrix = new Cesium.Matrix3();
  3794. * var column1Row0Index = Cesium.Matrix3.getElementIndex(1, 0);
  3795. * var column1Row0 = myMatrix[column1Row0Index]
  3796. * myMatrix[column1Row0Index] = 10.0;
  3797. */
  3798. Matrix3.getElementIndex = function(column, row) {
  3799. if (typeof row !== 'number' || row < 0 || row > 2) {
  3800. throw new DeveloperError('row must be 0, 1, or 2.');
  3801. }
  3802. if (typeof column !== 'number' || column < 0 || column > 2) {
  3803. throw new DeveloperError('column must be 0, 1, or 2.');
  3804. }
  3805. return column * 3 + row;
  3806. };
  3807. /**
  3808. * Retrieves a copy of the matrix column at the provided index as a Cartesian3 instance.
  3809. *
  3810. * @param {Matrix3} matrix The matrix to use.
  3811. * @param {Number} index The zero-based index of the column to retrieve.
  3812. * @param {Cartesian3} result The object onto which to store the result.
  3813. * @returns {Cartesian3} The modified result parameter.
  3814. *
  3815. * @exception {DeveloperError} index must be 0, 1, or 2.
  3816. */
  3817. Matrix3.getColumn = function(matrix, index, result) {
  3818. if (!defined(matrix)) {
  3819. throw new DeveloperError('matrix is required.');
  3820. }
  3821. if (typeof index !== 'number' || index < 0 || index > 2) {
  3822. throw new DeveloperError('index must be 0, 1, or 2.');
  3823. }
  3824. if (!defined(result)) {
  3825. throw new DeveloperError('result is required');
  3826. }
  3827. var startIndex = index * 3;
  3828. var x = matrix[startIndex];
  3829. var y = matrix[startIndex + 1];
  3830. var z = matrix[startIndex + 2];
  3831. result.x = x;
  3832. result.y = y;
  3833. result.z = z;
  3834. return result;
  3835. };
  3836. /**
  3837. * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian3 instance.
  3838. *
  3839. * @param {Matrix3} matrix The matrix to use.
  3840. * @param {Number} index The zero-based index of the column to set.
  3841. * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified column.
  3842. * @param {Matrix3} result The object onto which to store the result.
  3843. * @returns {Matrix3} The modified result parameter.
  3844. *
  3845. * @exception {DeveloperError} index must be 0, 1, or 2.
  3846. */
  3847. Matrix3.setColumn = function(matrix, index, cartesian, result) {
  3848. if (!defined(matrix)) {
  3849. throw new DeveloperError('matrix is required');
  3850. }
  3851. if (!defined(cartesian)) {
  3852. throw new DeveloperError('cartesian is required');
  3853. }
  3854. if (typeof index !== 'number' || index < 0 || index > 2) {
  3855. throw new DeveloperError('index must be 0, 1, or 2.');
  3856. }
  3857. if (!defined(result)) {
  3858. throw new DeveloperError('result is required');
  3859. }
  3860. result = Matrix3.clone(matrix, result);
  3861. var startIndex = index * 3;
  3862. result[startIndex] = cartesian.x;
  3863. result[startIndex + 1] = cartesian.y;
  3864. result[startIndex + 2] = cartesian.z;
  3865. return result;
  3866. };
  3867. /**
  3868. * Retrieves a copy of the matrix row at the provided index as a Cartesian3 instance.
  3869. *
  3870. * @param {Matrix3} matrix The matrix to use.
  3871. * @param {Number} index The zero-based index of the row to retrieve.
  3872. * @param {Cartesian3} result The object onto which to store the result.
  3873. * @returns {Cartesian3} The modified result parameter.
  3874. *
  3875. * @exception {DeveloperError} index must be 0, 1, or 2.
  3876. */
  3877. Matrix3.getRow = function(matrix, index, result) {
  3878. if (!defined(matrix)) {
  3879. throw new DeveloperError('matrix is required.');
  3880. }
  3881. if (typeof index !== 'number' || index < 0 || index > 2) {
  3882. throw new DeveloperError('index must be 0, 1, or 2.');
  3883. }
  3884. if (!defined(result)) {
  3885. throw new DeveloperError('result is required');
  3886. }
  3887. var x = matrix[index];
  3888. var y = matrix[index + 3];
  3889. var z = matrix[index + 6];
  3890. result.x = x;
  3891. result.y = y;
  3892. result.z = z;
  3893. return result;
  3894. };
  3895. /**
  3896. * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian3 instance.
  3897. *
  3898. * @param {Matrix3} matrix The matrix to use.
  3899. * @param {Number} index The zero-based index of the row to set.
  3900. * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified row.
  3901. * @param {Matrix3} result The object onto which to store the result.
  3902. * @returns {Matrix3} The modified result parameter.
  3903. *
  3904. * @exception {DeveloperError} index must be 0, 1, or 2.
  3905. */
  3906. Matrix3.setRow = function(matrix, index, cartesian, result) {
  3907. if (!defined(matrix)) {
  3908. throw new DeveloperError('matrix is required');
  3909. }
  3910. if (!defined(cartesian)) {
  3911. throw new DeveloperError('cartesian is required');
  3912. }
  3913. if (typeof index !== 'number' || index < 0 || index > 2) {
  3914. throw new DeveloperError('index must be 0, 1, or 2.');
  3915. }
  3916. if (!defined(result)) {
  3917. throw new DeveloperError('result is required');
  3918. }
  3919. result = Matrix3.clone(matrix, result);
  3920. result[index] = cartesian.x;
  3921. result[index + 3] = cartesian.y;
  3922. result[index + 6] = cartesian.z;
  3923. return result;
  3924. };
  3925. var scratchColumn = new Cartesian3();
  3926. /**
  3927. * Extracts the non-uniform scale assuming the matrix is an affine transformation.
  3928. *
  3929. * @param {Matrix3} matrix The matrix.
  3930. * @param {Cartesian3} result The object onto which to store the result.
  3931. * @returns {Cartesian3} The modified result parameter.
  3932. */
  3933. Matrix3.getScale = function(matrix, result) {
  3934. if (!defined(matrix)) {
  3935. throw new DeveloperError('matrix is required.');
  3936. }
  3937. if (!defined(result)) {
  3938. throw new DeveloperError('result is required');
  3939. }
  3940. result.x = Cartesian3.magnitude(Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn));
  3941. result.y = Cartesian3.magnitude(Cartesian3.fromElements(matrix[3], matrix[4], matrix[5], scratchColumn));
  3942. result.z = Cartesian3.magnitude(Cartesian3.fromElements(matrix[6], matrix[7], matrix[8], scratchColumn));
  3943. return result;
  3944. };
  3945. var scratchScale = new Cartesian3();
  3946. /**
  3947. * Computes the maximum scale assuming the matrix is an affine transformation.
  3948. * The maximum scale is the maximum length of the column vectors.
  3949. *
  3950. * @param {Matrix3} matrix The matrix.
  3951. * @returns {Number} The maximum scale.
  3952. */
  3953. Matrix3.getMaximumScale = function(matrix) {
  3954. Matrix3.getScale(matrix, scratchScale);
  3955. return Cartesian3.maximumComponent(scratchScale);
  3956. };
  3957. /**
  3958. * Computes the product of two matrices.
  3959. *
  3960. * @param {Matrix3} left The first matrix.
  3961. * @param {Matrix3} right The second matrix.
  3962. * @param {Matrix3} result The object onto which to store the result.
  3963. * @returns {Matrix3} The modified result parameter.
  3964. */
  3965. Matrix3.multiply = function(left, right, result) {
  3966. if (!defined(left)) {
  3967. throw new DeveloperError('left is required');
  3968. }
  3969. if (!defined(right)) {
  3970. throw new DeveloperError('right is required');
  3971. }
  3972. if (!defined(result)) {
  3973. throw new DeveloperError('result is required');
  3974. }
  3975. var column0Row0 = left[0] * right[0] + left[3] * right[1] + left[6] * right[2];
  3976. var column0Row1 = left[1] * right[0] + left[4] * right[1] + left[7] * right[2];
  3977. var column0Row2 = left[2] * right[0] + left[5] * right[1] + left[8] * right[2];
  3978. var column1Row0 = left[0] * right[3] + left[3] * right[4] + left[6] * right[5];
  3979. var column1Row1 = left[1] * right[3] + left[4] * right[4] + left[7] * right[5];
  3980. var column1Row2 = left[2] * right[3] + left[5] * right[4] + left[8] * right[5];
  3981. var column2Row0 = left[0] * right[6] + left[3] * right[7] + left[6] * right[8];
  3982. var column2Row1 = left[1] * right[6] + left[4] * right[7] + left[7] * right[8];
  3983. var column2Row2 = left[2] * right[6] + left[5] * right[7] + left[8] * right[8];
  3984. result[0] = column0Row0;
  3985. result[1] = column0Row1;
  3986. result[2] = column0Row2;
  3987. result[3] = column1Row0;
  3988. result[4] = column1Row1;
  3989. result[5] = column1Row2;
  3990. result[6] = column2Row0;
  3991. result[7] = column2Row1;
  3992. result[8] = column2Row2;
  3993. return result;
  3994. };
  3995. /**
  3996. * Computes the sum of two matrices.
  3997. *
  3998. * @param {Matrix3} left The first matrix.
  3999. * @param {Matrix3} right The second matrix.
  4000. * @param {Matrix3} result The object onto which to store the result.
  4001. * @returns {Matrix3} The modified result parameter.
  4002. */
  4003. Matrix3.add = function(left, right, result) {
  4004. if (!defined(left)) {
  4005. throw new DeveloperError('left is required');
  4006. }
  4007. if (!defined(right)) {
  4008. throw new DeveloperError('right is required');
  4009. }
  4010. if (!defined(result)) {
  4011. throw new DeveloperError('result is required');
  4012. }
  4013. result[0] = left[0] + right[0];
  4014. result[1] = left[1] + right[1];
  4015. result[2] = left[2] + right[2];
  4016. result[3] = left[3] + right[3];
  4017. result[4] = left[4] + right[4];
  4018. result[5] = left[5] + right[5];
  4019. result[6] = left[6] + right[6];
  4020. result[7] = left[7] + right[7];
  4021. result[8] = left[8] + right[8];
  4022. return result;
  4023. };
  4024. /**
  4025. * Computes the difference of two matrices.
  4026. *
  4027. * @param {Matrix3} left The first matrix.
  4028. * @param {Matrix3} right The second matrix.
  4029. * @param {Matrix3} result The object onto which to store the result.
  4030. * @returns {Matrix3} The modified result parameter.
  4031. */
  4032. Matrix3.subtract = function(left, right, result) {
  4033. if (!defined(left)) {
  4034. throw new DeveloperError('left is required');
  4035. }
  4036. if (!defined(right)) {
  4037. throw new DeveloperError('right is required');
  4038. }
  4039. if (!defined(result)) {
  4040. throw new DeveloperError('result is required');
  4041. }
  4042. result[0] = left[0] - right[0];
  4043. result[1] = left[1] - right[1];
  4044. result[2] = left[2] - right[2];
  4045. result[3] = left[3] - right[3];
  4046. result[4] = left[4] - right[4];
  4047. result[5] = left[5] - right[5];
  4048. result[6] = left[6] - right[6];
  4049. result[7] = left[7] - right[7];
  4050. result[8] = left[8] - right[8];
  4051. return result;
  4052. };
  4053. /**
  4054. * Computes the product of a matrix and a column vector.
  4055. *
  4056. * @param {Matrix3} matrix The matrix.
  4057. * @param {Cartesian3} cartesian The column.
  4058. * @param {Cartesian3} result The object onto which to store the result.
  4059. * @returns {Cartesian3} The modified result parameter.
  4060. */
  4061. Matrix3.multiplyByVector = function(matrix, cartesian, result) {
  4062. if (!defined(matrix)) {
  4063. throw new DeveloperError('matrix is required');
  4064. }
  4065. if (!defined(cartesian)) {
  4066. throw new DeveloperError('cartesian is required');
  4067. }
  4068. if (!defined(result)) {
  4069. throw new DeveloperError('result is required');
  4070. }
  4071. var vX = cartesian.x;
  4072. var vY = cartesian.y;
  4073. var vZ = cartesian.z;
  4074. var x = matrix[0] * vX + matrix[3] * vY + matrix[6] * vZ;
  4075. var y = matrix[1] * vX + matrix[4] * vY + matrix[7] * vZ;
  4076. var z = matrix[2] * vX + matrix[5] * vY + matrix[8] * vZ;
  4077. result.x = x;
  4078. result.y = y;
  4079. result.z = z;
  4080. return result;
  4081. };
  4082. /**
  4083. * Computes the product of a matrix and a scalar.
  4084. *
  4085. * @param {Matrix3} matrix The matrix.
  4086. * @param {Number} scalar The number to multiply by.
  4087. * @param {Matrix3} result The object onto which to store the result.
  4088. * @returns {Matrix3} The modified result parameter.
  4089. */
  4090. Matrix3.multiplyByScalar = function(matrix, scalar, result) {
  4091. if (!defined(matrix)) {
  4092. throw new DeveloperError('matrix is required');
  4093. }
  4094. if (typeof scalar !== 'number') {
  4095. throw new DeveloperError('scalar must be a number');
  4096. }
  4097. if (!defined(result)) {
  4098. throw new DeveloperError('result is required');
  4099. }
  4100. result[0] = matrix[0] * scalar;
  4101. result[1] = matrix[1] * scalar;
  4102. result[2] = matrix[2] * scalar;
  4103. result[3] = matrix[3] * scalar;
  4104. result[4] = matrix[4] * scalar;
  4105. result[5] = matrix[5] * scalar;
  4106. result[6] = matrix[6] * scalar;
  4107. result[7] = matrix[7] * scalar;
  4108. result[8] = matrix[8] * scalar;
  4109. return result;
  4110. };
  4111. /**
  4112. * Computes the product of a matrix times a (non-uniform) scale, as if the scale were a scale matrix.
  4113. *
  4114. * @param {Matrix3} matrix The matrix on the left-hand side.
  4115. * @param {Cartesian3} scale The non-uniform scale on the right-hand side.
  4116. * @param {Matrix3} result The object onto which to store the result.
  4117. * @returns {Matrix3} The modified result parameter.
  4118. *
  4119. *
  4120. * @example
  4121. * // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromScale(scale), m);
  4122. * Cesium.Matrix3.multiplyByScale(m, scale, m);
  4123. *
  4124. * @see Matrix3.fromScale
  4125. * @see Matrix3.multiplyByUniformScale
  4126. */
  4127. Matrix3.multiplyByScale = function(matrix, scale, result) {
  4128. if (!defined(matrix)) {
  4129. throw new DeveloperError('matrix is required');
  4130. }
  4131. if (!defined(scale)) {
  4132. throw new DeveloperError('scale is required');
  4133. }
  4134. if (!defined(result)) {
  4135. throw new DeveloperError('result is required');
  4136. }
  4137. result[0] = matrix[0] * scale.x;
  4138. result[1] = matrix[1] * scale.x;
  4139. result[2] = matrix[2] * scale.x;
  4140. result[3] = matrix[3] * scale.y;
  4141. result[4] = matrix[4] * scale.y;
  4142. result[5] = matrix[5] * scale.y;
  4143. result[6] = matrix[6] * scale.z;
  4144. result[7] = matrix[7] * scale.z;
  4145. result[8] = matrix[8] * scale.z;
  4146. return result;
  4147. };
  4148. /**
  4149. * Creates a negated copy of the provided matrix.
  4150. *
  4151. * @param {Matrix3} matrix The matrix to negate.
  4152. * @param {Matrix3} result The object onto which to store the result.
  4153. * @returns {Matrix3} The modified result parameter.
  4154. */
  4155. Matrix3.negate = function(matrix, result) {
  4156. if (!defined(matrix)) {
  4157. throw new DeveloperError('matrix is required');
  4158. }
  4159. if (!defined(result)) {
  4160. throw new DeveloperError('result is required');
  4161. }
  4162. result[0] = -matrix[0];
  4163. result[1] = -matrix[1];
  4164. result[2] = -matrix[2];
  4165. result[3] = -matrix[3];
  4166. result[4] = -matrix[4];
  4167. result[5] = -matrix[5];
  4168. result[6] = -matrix[6];
  4169. result[7] = -matrix[7];
  4170. result[8] = -matrix[8];
  4171. return result;
  4172. };
  4173. /**
  4174. * Computes the transpose of the provided matrix.
  4175. *
  4176. * @param {Matrix3} matrix The matrix to transpose.
  4177. * @param {Matrix3} result The object onto which to store the result.
  4178. * @returns {Matrix3} The modified result parameter.
  4179. */
  4180. Matrix3.transpose = function(matrix, result) {
  4181. if (!defined(matrix)) {
  4182. throw new DeveloperError('matrix is required');
  4183. }
  4184. if (!defined(result)) {
  4185. throw new DeveloperError('result is required');
  4186. }
  4187. var column0Row0 = matrix[0];
  4188. var column0Row1 = matrix[3];
  4189. var column0Row2 = matrix[6];
  4190. var column1Row0 = matrix[1];
  4191. var column1Row1 = matrix[4];
  4192. var column1Row2 = matrix[7];
  4193. var column2Row0 = matrix[2];
  4194. var column2Row1 = matrix[5];
  4195. var column2Row2 = matrix[8];
  4196. result[0] = column0Row0;
  4197. result[1] = column0Row1;
  4198. result[2] = column0Row2;
  4199. result[3] = column1Row0;
  4200. result[4] = column1Row1;
  4201. result[5] = column1Row2;
  4202. result[6] = column2Row0;
  4203. result[7] = column2Row1;
  4204. result[8] = column2Row2;
  4205. return result;
  4206. };
  4207. function computeFrobeniusNorm(matrix) {
  4208. var norm = 0.0;
  4209. for (var i = 0; i < 9; ++i) {
  4210. var temp = matrix[i];
  4211. norm += temp * temp;
  4212. }
  4213. return Math.sqrt(norm);
  4214. }
  4215. var rowVal = [1, 0, 0];
  4216. var colVal = [2, 2, 1];
  4217. function offDiagonalFrobeniusNorm(matrix) {
  4218. // Computes the "off-diagonal" Frobenius norm.
  4219. // Assumes matrix is symmetric.
  4220. var norm = 0.0;
  4221. for (var i = 0; i < 3; ++i) {
  4222. var temp = matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])];
  4223. norm += 2.0 * temp * temp;
  4224. }
  4225. return Math.sqrt(norm);
  4226. }
  4227. function shurDecomposition(matrix, result) {
  4228. // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,
  4229. // section 8.4.2 The 2by2 Symmetric Schur Decomposition.
  4230. //
  4231. // The routine takes a matrix, which is assumed to be symmetric, and
  4232. // finds the largest off-diagonal term, and then creates
  4233. // a matrix (result) which can be used to help reduce it
  4234. var tolerance = CesiumMath.EPSILON15;
  4235. var maxDiagonal = 0.0;
  4236. var rotAxis = 1;
  4237. // find pivot (rotAxis) based on max diagonal of matrix
  4238. for (var i = 0; i < 3; ++i) {
  4239. var temp = Math.abs(matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])]);
  4240. if (temp > maxDiagonal) {
  4241. rotAxis = i;
  4242. maxDiagonal = temp;
  4243. }
  4244. }
  4245. var c = 1.0;
  4246. var s = 0.0;
  4247. var p = rowVal[rotAxis];
  4248. var q = colVal[rotAxis];
  4249. if (Math.abs(matrix[Matrix3.getElementIndex(q, p)]) > tolerance) {
  4250. var qq = matrix[Matrix3.getElementIndex(q, q)];
  4251. var pp = matrix[Matrix3.getElementIndex(p, p)];
  4252. var qp = matrix[Matrix3.getElementIndex(q, p)];
  4253. var tau = (qq - pp) / 2.0 / qp;
  4254. var t;
  4255. if (tau < 0.0) {
  4256. t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));
  4257. } else {
  4258. t = 1.0 / (tau + Math.sqrt(1.0 + tau * tau));
  4259. }
  4260. c = 1.0 / Math.sqrt(1.0 + t * t);
  4261. s = t * c;
  4262. }
  4263. result = Matrix3.clone(Matrix3.IDENTITY, result);
  4264. result[Matrix3.getElementIndex(p, p)] = result[Matrix3.getElementIndex(q, q)] = c;
  4265. result[Matrix3.getElementIndex(q, p)] = s;
  4266. result[Matrix3.getElementIndex(p, q)] = -s;
  4267. return result;
  4268. }
  4269. var jMatrix = new Matrix3();
  4270. var jMatrixTranspose = new Matrix3();
  4271. /**
  4272. * Computes the eigenvectors and eigenvalues of a symmetric matrix.
  4273. * <p>
  4274. * Returns a diagonal matrix and unitary matrix such that:
  4275. * <code>matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)</code>
  4276. * </p>
  4277. * <p>
  4278. * The values along the diagonal of the diagonal matrix are the eigenvalues. The columns
  4279. * of the unitary matrix are the corresponding eigenvectors.
  4280. * </p>
  4281. *
  4282. * @param {Matrix3} matrix The matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.
  4283. * @param {Object} [result] An object with unitary and diagonal properties which are matrices onto which to store the result.
  4284. * @returns {Object} An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.
  4285. *
  4286. * @example
  4287. * var a = //... symetric matrix
  4288. * var result = {
  4289. * unitary : new Cesium.Matrix3(),
  4290. * diagonal : new Cesium.Matrix3()
  4291. * };
  4292. * Cesium.Matrix3.computeEigenDecomposition(a, result);
  4293. *
  4294. * var unitaryTranspose = Cesium.Matrix3.transpose(result.unitary, new Cesium.Matrix3());
  4295. * var b = Cesium.Matrix3.multiply(result.unitary, result.diagonal, new Cesium.Matrix3());
  4296. * Cesium.Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a
  4297. *
  4298. * var lambda = Cesium.Matrix3.getColumn(result.diagonal, 0, new Cesium.Cartesian3()).x; // first eigenvalue
  4299. * var v = Cesium.Matrix3.getColumn(result.unitary, 0, new Cesium.Cartesian3()); // first eigenvector
  4300. * var c = Cesium.Cartesian3.multiplyByScalar(v, lambda, new Cesium.Cartesian3()); // equal to Cesium.Matrix3.multiplyByVector(a, v)
  4301. */
  4302. Matrix3.computeEigenDecomposition = function(matrix, result) {
  4303. if (!defined(matrix)) {
  4304. throw new DeveloperError('matrix is required.');
  4305. }
  4306. // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,
  4307. // section 8.4.3 The Classical Jacobi Algorithm
  4308. var tolerance = CesiumMath.EPSILON20;
  4309. var maxSweeps = 10;
  4310. var count = 0;
  4311. var sweep = 0;
  4312. if (!defined(result)) {
  4313. result = {};
  4314. }
  4315. var unitaryMatrix = result.unitary = Matrix3.clone(Matrix3.IDENTITY, result.unitary);
  4316. var diagMatrix = result.diagonal = Matrix3.clone(matrix, result.diagonal);
  4317. var epsilon = tolerance * computeFrobeniusNorm(diagMatrix);
  4318. while (sweep < maxSweeps && offDiagonalFrobeniusNorm(diagMatrix) > epsilon) {
  4319. shurDecomposition(diagMatrix, jMatrix);
  4320. Matrix3.transpose(jMatrix, jMatrixTranspose);
  4321. Matrix3.multiply(diagMatrix, jMatrix, diagMatrix);
  4322. Matrix3.multiply(jMatrixTranspose, diagMatrix, diagMatrix);
  4323. Matrix3.multiply(unitaryMatrix, jMatrix, unitaryMatrix);
  4324. if (++count > 2) {
  4325. ++sweep;
  4326. count = 0;
  4327. }
  4328. }
  4329. return result;
  4330. };
  4331. /**
  4332. * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.
  4333. *
  4334. * @param {Matrix3} matrix The matrix with signed elements.
  4335. * @param {Matrix3} result The object onto which to store the result.
  4336. * @returns {Matrix3} The modified result parameter.
  4337. */
  4338. Matrix3.abs = function(matrix, result) {
  4339. if (!defined(matrix)) {
  4340. throw new DeveloperError('matrix is required');
  4341. }
  4342. if (!defined(result)) {
  4343. throw new DeveloperError('result is required');
  4344. }
  4345. result[0] = Math.abs(matrix[0]);
  4346. result[1] = Math.abs(matrix[1]);
  4347. result[2] = Math.abs(matrix[2]);
  4348. result[3] = Math.abs(matrix[3]);
  4349. result[4] = Math.abs(matrix[4]);
  4350. result[5] = Math.abs(matrix[5]);
  4351. result[6] = Math.abs(matrix[6]);
  4352. result[7] = Math.abs(matrix[7]);
  4353. result[8] = Math.abs(matrix[8]);
  4354. return result;
  4355. };
  4356. /**
  4357. * Computes the determinant of the provided matrix.
  4358. *
  4359. * @param {Matrix3} matrix The matrix to use.
  4360. * @returns {Number} The value of the determinant of the matrix.
  4361. */
  4362. Matrix3.determinant = function(matrix) {
  4363. if (!defined(matrix)) {
  4364. throw new DeveloperError('matrix is required');
  4365. }
  4366. var m11 = matrix[0];
  4367. var m21 = matrix[3];
  4368. var m31 = matrix[6];
  4369. var m12 = matrix[1];
  4370. var m22 = matrix[4];
  4371. var m32 = matrix[7];
  4372. var m13 = matrix[2];
  4373. var m23 = matrix[5];
  4374. var m33 = matrix[8];
  4375. return m11 * (m22 * m33 - m23 * m32) + m12 * (m23 * m31 - m21 * m33) + m13 * (m21 * m32 - m22 * m31);
  4376. };
  4377. /**
  4378. * Computes the inverse of the provided matrix.
  4379. *
  4380. * @param {Matrix3} matrix The matrix to invert.
  4381. * @param {Matrix3} result The object onto which to store the result.
  4382. * @returns {Matrix3} The modified result parameter.
  4383. *
  4384. * @exception {DeveloperError} matrix is not invertible.
  4385. */
  4386. Matrix3.inverse = function(matrix, result) {
  4387. if (!defined(matrix)) {
  4388. throw new DeveloperError('matrix is required');
  4389. }
  4390. if (!defined(result)) {
  4391. throw new DeveloperError('result is required');
  4392. }
  4393. var m11 = matrix[0];
  4394. var m21 = matrix[1];
  4395. var m31 = matrix[2];
  4396. var m12 = matrix[3];
  4397. var m22 = matrix[4];
  4398. var m32 = matrix[5];
  4399. var m13 = matrix[6];
  4400. var m23 = matrix[7];
  4401. var m33 = matrix[8];
  4402. var determinant = Matrix3.determinant(matrix);
  4403. if (Math.abs(determinant) <= CesiumMath.EPSILON15) {
  4404. throw new DeveloperError('matrix is not invertible');
  4405. }
  4406. result[0] = m22 * m33 - m23 * m32;
  4407. result[1] = m23 * m31 - m21 * m33;
  4408. result[2] = m21 * m32 - m22 * m31;
  4409. result[3] = m13 * m32 - m12 * m33;
  4410. result[4] = m11 * m33 - m13 * m31;
  4411. result[5] = m12 * m31 - m11 * m32;
  4412. result[6] = m12 * m23 - m13 * m22;
  4413. result[7] = m13 * m21 - m11 * m23;
  4414. result[8] = m11 * m22 - m12 * m21;
  4415. var scale = 1.0 / determinant;
  4416. return Matrix3.multiplyByScalar(result, scale, result);
  4417. };
  4418. /**
  4419. * Compares the provided matrices componentwise and returns
  4420. * <code>true</code> if they are equal, <code>false</code> otherwise.
  4421. *
  4422. * @param {Matrix3} [left] The first matrix.
  4423. * @param {Matrix3} [right] The second matrix.
  4424. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  4425. */
  4426. Matrix3.equals = function(left, right) {
  4427. return (left === right) ||
  4428. (defined(left) &&
  4429. defined(right) &&
  4430. left[0] === right[0] &&
  4431. left[1] === right[1] &&
  4432. left[2] === right[2] &&
  4433. left[3] === right[3] &&
  4434. left[4] === right[4] &&
  4435. left[5] === right[5] &&
  4436. left[6] === right[6] &&
  4437. left[7] === right[7] &&
  4438. left[8] === right[8]);
  4439. };
  4440. /**
  4441. * Compares the provided matrices componentwise and returns
  4442. * <code>true</code> if they are within the provided epsilon,
  4443. * <code>false</code> otherwise.
  4444. *
  4445. * @param {Matrix3} [left] The first matrix.
  4446. * @param {Matrix3} [right] The second matrix.
  4447. * @param {Number} epsilon The epsilon to use for equality testing.
  4448. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  4449. */
  4450. Matrix3.equalsEpsilon = function(left, right, epsilon) {
  4451. if (typeof epsilon !== 'number') {
  4452. throw new DeveloperError('epsilon must be a number');
  4453. }
  4454. return (left === right) ||
  4455. (defined(left) &&
  4456. defined(right) &&
  4457. Math.abs(left[0] - right[0]) <= epsilon &&
  4458. Math.abs(left[1] - right[1]) <= epsilon &&
  4459. Math.abs(left[2] - right[2]) <= epsilon &&
  4460. Math.abs(left[3] - right[3]) <= epsilon &&
  4461. Math.abs(left[4] - right[4]) <= epsilon &&
  4462. Math.abs(left[5] - right[5]) <= epsilon &&
  4463. Math.abs(left[6] - right[6]) <= epsilon &&
  4464. Math.abs(left[7] - right[7]) <= epsilon &&
  4465. Math.abs(left[8] - right[8]) <= epsilon);
  4466. };
  4467. /**
  4468. * An immutable Matrix3 instance initialized to the identity matrix.
  4469. *
  4470. * @type {Matrix3}
  4471. * @constant
  4472. */
  4473. Matrix3.IDENTITY = freezeObject(new Matrix3(1.0, 0.0, 0.0,
  4474. 0.0, 1.0, 0.0,
  4475. 0.0, 0.0, 1.0));
  4476. /**
  4477. * An immutable Matrix3 instance initialized to the zero matrix.
  4478. *
  4479. * @type {Matrix3}
  4480. * @constant
  4481. */
  4482. Matrix3.ZERO = freezeObject(new Matrix3(0.0, 0.0, 0.0,
  4483. 0.0, 0.0, 0.0,
  4484. 0.0, 0.0, 0.0));
  4485. /**
  4486. * The index into Matrix3 for column 0, row 0.
  4487. *
  4488. * @type {Number}
  4489. * @constant
  4490. */
  4491. Matrix3.COLUMN0ROW0 = 0;
  4492. /**
  4493. * The index into Matrix3 for column 0, row 1.
  4494. *
  4495. * @type {Number}
  4496. * @constant
  4497. */
  4498. Matrix3.COLUMN0ROW1 = 1;
  4499. /**
  4500. * The index into Matrix3 for column 0, row 2.
  4501. *
  4502. * @type {Number}
  4503. * @constant
  4504. */
  4505. Matrix3.COLUMN0ROW2 = 2;
  4506. /**
  4507. * The index into Matrix3 for column 1, row 0.
  4508. *
  4509. * @type {Number}
  4510. * @constant
  4511. */
  4512. Matrix3.COLUMN1ROW0 = 3;
  4513. /**
  4514. * The index into Matrix3 for column 1, row 1.
  4515. *
  4516. * @type {Number}
  4517. * @constant
  4518. */
  4519. Matrix3.COLUMN1ROW1 = 4;
  4520. /**
  4521. * The index into Matrix3 for column 1, row 2.
  4522. *
  4523. * @type {Number}
  4524. * @constant
  4525. */
  4526. Matrix3.COLUMN1ROW2 = 5;
  4527. /**
  4528. * The index into Matrix3 for column 2, row 0.
  4529. *
  4530. * @type {Number}
  4531. * @constant
  4532. */
  4533. Matrix3.COLUMN2ROW0 = 6;
  4534. /**
  4535. * The index into Matrix3 for column 2, row 1.
  4536. *
  4537. * @type {Number}
  4538. * @constant
  4539. */
  4540. Matrix3.COLUMN2ROW1 = 7;
  4541. /**
  4542. * The index into Matrix3 for column 2, row 2.
  4543. *
  4544. * @type {Number}
  4545. * @constant
  4546. */
  4547. Matrix3.COLUMN2ROW2 = 8;
  4548. defineProperties(Matrix3.prototype, {
  4549. /**
  4550. * Gets the number of items in the collection.
  4551. * @memberof Matrix3.prototype
  4552. *
  4553. * @type {Number}
  4554. */
  4555. length : {
  4556. get : function() {
  4557. return Matrix3.packedLength;
  4558. }
  4559. }
  4560. });
  4561. /**
  4562. * Duplicates the provided Matrix3 instance.
  4563. *
  4564. * @param {Matrix3} [result] The object onto which to store the result.
  4565. * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
  4566. */
  4567. Matrix3.prototype.clone = function(result) {
  4568. return Matrix3.clone(this, result);
  4569. };
  4570. /**
  4571. * Compares this matrix to the provided matrix componentwise and returns
  4572. * <code>true</code> if they are equal, <code>false</code> otherwise.
  4573. *
  4574. * @param {Matrix3} [right] The right hand side matrix.
  4575. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  4576. */
  4577. Matrix3.prototype.equals = function(right) {
  4578. return Matrix3.equals(this, right);
  4579. };
  4580. /**
  4581. * @private
  4582. */
  4583. Matrix3.equalsArray = function(matrix, array, offset) {
  4584. return matrix[0] === array[offset] &&
  4585. matrix[1] === array[offset + 1] &&
  4586. matrix[2] === array[offset + 2] &&
  4587. matrix[3] === array[offset + 3] &&
  4588. matrix[4] === array[offset + 4] &&
  4589. matrix[5] === array[offset + 5] &&
  4590. matrix[6] === array[offset + 6] &&
  4591. matrix[7] === array[offset + 7] &&
  4592. matrix[8] === array[offset + 8];
  4593. };
  4594. /**
  4595. * Compares this matrix to the provided matrix componentwise and returns
  4596. * <code>true</code> if they are within the provided epsilon,
  4597. * <code>false</code> otherwise.
  4598. *
  4599. * @param {Matrix3} [right] The right hand side matrix.
  4600. * @param {Number} epsilon The epsilon to use for equality testing.
  4601. * @returns {Boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
  4602. */
  4603. Matrix3.prototype.equalsEpsilon = function(right, epsilon) {
  4604. return Matrix3.equalsEpsilon(this, right, epsilon);
  4605. };
  4606. /**
  4607. * Creates a string representing this Matrix with each row being
  4608. * on a separate line and in the format '(column0, column1, column2)'.
  4609. *
  4610. * @returns {String} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2)'.
  4611. */
  4612. Matrix3.prototype.toString = function() {
  4613. return '(' + this[0] + ', ' + this[3] + ', ' + this[6] + ')\n' +
  4614. '(' + this[1] + ', ' + this[4] + ', ' + this[7] + ')\n' +
  4615. '(' + this[2] + ', ' + this[5] + ', ' + this[8] + ')';
  4616. };
  4617. return Matrix3;
  4618. });
  4619. /*global define*/
  4620. define('Core/Cartesian4',[
  4621. './defaultValue',
  4622. './defined',
  4623. './DeveloperError',
  4624. './freezeObject',
  4625. './Math'
  4626. ], function(
  4627. defaultValue,
  4628. defined,
  4629. DeveloperError,
  4630. freezeObject,
  4631. CesiumMath) {
  4632. 'use strict';
  4633. /**
  4634. * A 4D Cartesian point.
  4635. * @alias Cartesian4
  4636. * @constructor
  4637. *
  4638. * @param {Number} [x=0.0] The X component.
  4639. * @param {Number} [y=0.0] The Y component.
  4640. * @param {Number} [z=0.0] The Z component.
  4641. * @param {Number} [w=0.0] The W component.
  4642. *
  4643. * @see Cartesian2
  4644. * @see Cartesian3
  4645. * @see Packable
  4646. */
  4647. function Cartesian4(x, y, z, w) {
  4648. /**
  4649. * The X component.
  4650. * @type {Number}
  4651. * @default 0.0
  4652. */
  4653. this.x = defaultValue(x, 0.0);
  4654. /**
  4655. * The Y component.
  4656. * @type {Number}
  4657. * @default 0.0
  4658. */
  4659. this.y = defaultValue(y, 0.0);
  4660. /**
  4661. * The Z component.
  4662. * @type {Number}
  4663. * @default 0.0
  4664. */
  4665. this.z = defaultValue(z, 0.0);
  4666. /**
  4667. * The W component.
  4668. * @type {Number}
  4669. * @default 0.0
  4670. */
  4671. this.w = defaultValue(w, 0.0);
  4672. }
  4673. /**
  4674. * Creates a Cartesian4 instance from x, y, z and w coordinates.
  4675. *
  4676. * @param {Number} x The x coordinate.
  4677. * @param {Number} y The y coordinate.
  4678. * @param {Number} z The z coordinate.
  4679. * @param {Number} w The w coordinate.
  4680. * @param {Cartesian4} [result] The object onto which to store the result.
  4681. * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
  4682. */
  4683. Cartesian4.fromElements = function(x, y, z, w, result) {
  4684. if (!defined(result)) {
  4685. return new Cartesian4(x, y, z, w);
  4686. }
  4687. result.x = x;
  4688. result.y = y;
  4689. result.z = z;
  4690. result.w = w;
  4691. return result;
  4692. };
  4693. /**
  4694. * Creates a Cartesian4 instance from a {@link Color}. <code>red</code>, <code>green</code>, <code>blue</code>,
  4695. * and <code>alpha</code> map to <code>x</code>, <code>y</code>, <code>z</code>, and <code>w</code>, respectively.
  4696. *
  4697. * @param {Color} color The source color.
  4698. * @param {Cartesian4} [result] The object onto which to store the result.
  4699. * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
  4700. */
  4701. Cartesian4.fromColor = function(color, result) {
  4702. if (!defined(color)) {
  4703. throw new DeveloperError('color is required');
  4704. }
  4705. if (!defined(result)) {
  4706. return new Cartesian4(color.red, color.green, color.blue, color.alpha);
  4707. }
  4708. result.x = color.red;
  4709. result.y = color.green;
  4710. result.z = color.blue;
  4711. result.w = color.alpha;
  4712. return result;
  4713. };
  4714. /**
  4715. * Duplicates a Cartesian4 instance.
  4716. *
  4717. * @param {Cartesian4} cartesian The Cartesian to duplicate.
  4718. * @param {Cartesian4} [result] The object onto which to store the result.
  4719. * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided. (Returns undefined if cartesian is undefined)
  4720. */
  4721. Cartesian4.clone = function(cartesian, result) {
  4722. if (!defined(cartesian)) {
  4723. return undefined;
  4724. }
  4725. if (!defined(result)) {
  4726. return new Cartesian4(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
  4727. }
  4728. result.x = cartesian.x;
  4729. result.y = cartesian.y;
  4730. result.z = cartesian.z;
  4731. result.w = cartesian.w;
  4732. return result;
  4733. };
  4734. /**
  4735. * The number of elements used to pack the object into an array.
  4736. * @type {Number}
  4737. */
  4738. Cartesian4.packedLength = 4;
  4739. /**
  4740. * Stores the provided instance into the provided array.
  4741. *
  4742. * @param {Cartesian4} value The value to pack.
  4743. * @param {Number[]} array The array to pack into.
  4744. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  4745. *
  4746. * @returns {Number[]} The array that was packed into
  4747. */
  4748. Cartesian4.pack = function(value, array, startingIndex) {
  4749. if (!defined(value)) {
  4750. throw new DeveloperError('value is required');
  4751. }
  4752. if (!defined(array)) {
  4753. throw new DeveloperError('array is required');
  4754. }
  4755. startingIndex = defaultValue(startingIndex, 0);
  4756. array[startingIndex++] = value.x;
  4757. array[startingIndex++] = value.y;
  4758. array[startingIndex++] = value.z;
  4759. array[startingIndex] = value.w;
  4760. return array;
  4761. };
  4762. /**
  4763. * Retrieves an instance from a packed array.
  4764. *
  4765. * @param {Number[]} array The packed array.
  4766. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  4767. * @param {Cartesian4} [result] The object into 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.unpack = function(array, startingIndex, result) {
  4771. if (!defined(array)) {
  4772. throw new DeveloperError('array is required');
  4773. }
  4774. startingIndex = defaultValue(startingIndex, 0);
  4775. if (!defined(result)) {
  4776. result = new Cartesian4();
  4777. }
  4778. result.x = array[startingIndex++];
  4779. result.y = array[startingIndex++];
  4780. result.z = array[startingIndex++];
  4781. result.w = array[startingIndex];
  4782. return result;
  4783. };
  4784. /**
  4785. * Flattens an array of Cartesian4s into and array of components.
  4786. *
  4787. * @param {Cartesian4[]} array The array of cartesians to pack.
  4788. * @param {Number[]} result The array onto which to store the result.
  4789. * @returns {Number[]} The packed array.
  4790. */
  4791. Cartesian4.packArray = function(array, result) {
  4792. if (!defined(array)) {
  4793. throw new DeveloperError('array is required');
  4794. }
  4795. var length = array.length;
  4796. if (!defined(result)) {
  4797. result = new Array(length * 4);
  4798. } else {
  4799. result.length = length * 4;
  4800. }
  4801. for (var i = 0; i < length; ++i) {
  4802. Cartesian4.pack(array[i], result, i * 4);
  4803. }
  4804. return result;
  4805. };
  4806. /**
  4807. * Unpacks an array of cartesian components into and array of Cartesian4s.
  4808. *
  4809. * @param {Number[]} array The array of components to unpack.
  4810. * @param {Cartesian4[]} result The array onto which to store the result.
  4811. * @returns {Cartesian4[]} The unpacked array.
  4812. */
  4813. Cartesian4.unpackArray = function(array, result) {
  4814. if (!defined(array)) {
  4815. throw new DeveloperError('array is required');
  4816. }
  4817. var length = array.length;
  4818. if (!defined(result)) {
  4819. result = new Array(length / 4);
  4820. } else {
  4821. result.length = length / 4;
  4822. }
  4823. for (var i = 0; i < length; i += 4) {
  4824. var index = i / 4;
  4825. result[index] = Cartesian4.unpack(array, i, result[index]);
  4826. }
  4827. return result;
  4828. };
  4829. /**
  4830. * Creates a Cartesian4 from four consecutive elements in an array.
  4831. * @function
  4832. *
  4833. * @param {Number[]} array The array whose four consecutive elements correspond to the x, y, z, and w components, respectively.
  4834. * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.
  4835. * @param {Cartesian4} [result] The object onto which to store the result.
  4836. * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
  4837. *
  4838. * @example
  4839. * // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0)
  4840. * var v = [1.0, 2.0, 3.0, 4.0];
  4841. * var p = Cesium.Cartesian4.fromArray(v);
  4842. *
  4843. * // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0) using an offset into an array
  4844. * var v2 = [0.0, 0.0, 1.0, 2.0, 3.0, 4.0];
  4845. * var p2 = Cesium.Cartesian4.fromArray(v2, 2);
  4846. */
  4847. Cartesian4.fromArray = Cartesian4.unpack;
  4848. /**
  4849. * Computes the value of the maximum component for the supplied Cartesian.
  4850. *
  4851. * @param {Cartesian4} cartesian The cartesian to use.
  4852. * @returns {Number} The value of the maximum component.
  4853. */
  4854. Cartesian4.maximumComponent = function(cartesian) {
  4855. if (!defined(cartesian)) {
  4856. throw new DeveloperError('cartesian is required');
  4857. }
  4858. return Math.max(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
  4859. };
  4860. /**
  4861. * Computes the value of the minimum component for the supplied Cartesian.
  4862. *
  4863. * @param {Cartesian4} cartesian The cartesian to use.
  4864. * @returns {Number} The value of the minimum component.
  4865. */
  4866. Cartesian4.minimumComponent = function(cartesian) {
  4867. if (!defined(cartesian)) {
  4868. throw new DeveloperError('cartesian is required');
  4869. }
  4870. return Math.min(cartesian.x, cartesian.y, cartesian.z, cartesian.w);
  4871. };
  4872. /**
  4873. * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
  4874. *
  4875. * @param {Cartesian4} first A cartesian to compare.
  4876. * @param {Cartesian4} second A cartesian to compare.
  4877. * @param {Cartesian4} result The object into which to store the result.
  4878. * @returns {Cartesian4} A cartesian with the minimum components.
  4879. */
  4880. Cartesian4.minimumByComponent = function(first, second, result) {
  4881. if (!defined(first)) {
  4882. throw new DeveloperError('first is required.');
  4883. }
  4884. if (!defined(second)) {
  4885. throw new DeveloperError('second is required.');
  4886. }
  4887. if (!defined(result)) {
  4888. throw new DeveloperError('result is required.');
  4889. }
  4890. result.x = Math.min(first.x, second.x);
  4891. result.y = Math.min(first.y, second.y);
  4892. result.z = Math.min(first.z, second.z);
  4893. result.w = Math.min(first.w, second.w);
  4894. return result;
  4895. };
  4896. /**
  4897. * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
  4898. *
  4899. * @param {Cartesian4} first A cartesian to compare.
  4900. * @param {Cartesian4} second A cartesian to compare.
  4901. * @param {Cartesian4} result The object into which to store the result.
  4902. * @returns {Cartesian4} A cartesian with the maximum components.
  4903. */
  4904. Cartesian4.maximumByComponent = function(first, second, result) {
  4905. if (!defined(first)) {
  4906. throw new DeveloperError('first is required.');
  4907. }
  4908. if (!defined(second)) {
  4909. throw new DeveloperError('second is required.');
  4910. }
  4911. if (!defined(result)) {
  4912. throw new DeveloperError('result is required.');
  4913. }
  4914. result.x = Math.max(first.x, second.x);
  4915. result.y = Math.max(first.y, second.y);
  4916. result.z = Math.max(first.z, second.z);
  4917. result.w = Math.max(first.w, second.w);
  4918. return result;
  4919. };
  4920. /**
  4921. * Computes the provided Cartesian's squared magnitude.
  4922. *
  4923. * @param {Cartesian4} cartesian The Cartesian instance whose squared magnitude is to be computed.
  4924. * @returns {Number} The squared magnitude.
  4925. */
  4926. Cartesian4.magnitudeSquared = function(cartesian) {
  4927. if (!defined(cartesian)) {
  4928. throw new DeveloperError('cartesian is required');
  4929. }
  4930. return cartesian.x * cartesian.x + cartesian.y * cartesian.y + cartesian.z * cartesian.z + cartesian.w * cartesian.w;
  4931. };
  4932. /**
  4933. * Computes the Cartesian's magnitude (length).
  4934. *
  4935. * @param {Cartesian4} cartesian The Cartesian instance whose magnitude is to be computed.
  4936. * @returns {Number} The magnitude.
  4937. */
  4938. Cartesian4.magnitude = function(cartesian) {
  4939. return Math.sqrt(Cartesian4.magnitudeSquared(cartesian));
  4940. };
  4941. var distanceScratch = new Cartesian4();
  4942. /**
  4943. * Computes the 4-space distance between two points.
  4944. *
  4945. * @param {Cartesian4} left The first point to compute the distance from.
  4946. * @param {Cartesian4} right The second point to compute the distance to.
  4947. * @returns {Number} The distance between two points.
  4948. *
  4949. * @example
  4950. * // Returns 1.0
  4951. * var d = Cesium.Cartesian4.distance(
  4952. * new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),
  4953. * new Cesium.Cartesian4(2.0, 0.0, 0.0, 0.0));
  4954. */
  4955. Cartesian4.distance = function(left, right) {
  4956. if (!defined(left) || !defined(right)) {
  4957. throw new DeveloperError('left and right are required.');
  4958. }
  4959. Cartesian4.subtract(left, right, distanceScratch);
  4960. return Cartesian4.magnitude(distanceScratch);
  4961. };
  4962. /**
  4963. * Computes the squared distance between two points. Comparing squared distances
  4964. * using this function is more efficient than comparing distances using {@link Cartesian4#distance}.
  4965. *
  4966. * @param {Cartesian4} left The first point to compute the distance from.
  4967. * @param {Cartesian4} right The second point to compute the distance to.
  4968. * @returns {Number} The distance between two points.
  4969. *
  4970. * @example
  4971. * // Returns 4.0, not 2.0
  4972. * var d = Cesium.Cartesian4.distance(
  4973. * new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),
  4974. * new Cesium.Cartesian4(3.0, 0.0, 0.0, 0.0));
  4975. */
  4976. Cartesian4.distanceSquared = function(left, right) {
  4977. if (!defined(left) || !defined(right)) {
  4978. throw new DeveloperError('left and right are required.');
  4979. }
  4980. Cartesian4.subtract(left, right, distanceScratch);
  4981. return Cartesian4.magnitudeSquared(distanceScratch);
  4982. };
  4983. /**
  4984. * Computes the normalized form of the supplied Cartesian.
  4985. *
  4986. * @param {Cartesian4} cartesian The Cartesian to be normalized.
  4987. * @param {Cartesian4} result The object onto which to store the result.
  4988. * @returns {Cartesian4} The modified result parameter.
  4989. */
  4990. Cartesian4.normalize = function(cartesian, result) {
  4991. if (!defined(cartesian)) {
  4992. throw new DeveloperError('cartesian is required');
  4993. }
  4994. if (!defined(result)) {
  4995. throw new DeveloperError('result is required');
  4996. }
  4997. var magnitude = Cartesian4.magnitude(cartesian);
  4998. result.x = cartesian.x / magnitude;
  4999. result.y = cartesian.y / magnitude;
  5000. result.z = cartesian.z / magnitude;
  5001. result.w = cartesian.w / magnitude;
  5002. if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z) || isNaN(result.w)) {
  5003. throw new DeveloperError('normalized result is not a number');
  5004. }
  5005. return result;
  5006. };
  5007. /**
  5008. * Computes the dot (scalar) product of two Cartesians.
  5009. *
  5010. * @param {Cartesian4} left The first Cartesian.
  5011. * @param {Cartesian4} right The second Cartesian.
  5012. * @returns {Number} The dot product.
  5013. */
  5014. Cartesian4.dot = function(left, right) {
  5015. if (!defined(left)) {
  5016. throw new DeveloperError('left is required');
  5017. }
  5018. if (!defined(right)) {
  5019. throw new DeveloperError('right is required');
  5020. }
  5021. return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
  5022. };
  5023. /**
  5024. * Computes the componentwise product of two Cartesians.
  5025. *
  5026. * @param {Cartesian4} left The first Cartesian.
  5027. * @param {Cartesian4} right The second Cartesian.
  5028. * @param {Cartesian4} result The object onto which to store the result.
  5029. * @returns {Cartesian4} The modified result parameter.
  5030. */
  5031. Cartesian4.multiplyComponents = function(left, right, result) {
  5032. if (!defined(left)) {
  5033. throw new DeveloperError('left is required');
  5034. }
  5035. if (!defined(right)) {
  5036. throw new DeveloperError('right is required');
  5037. }
  5038. if (!defined(result)) {
  5039. throw new DeveloperError('result is required');
  5040. }
  5041. result.x = left.x * right.x;
  5042. result.y = left.y * right.y;
  5043. result.z = left.z * right.z;
  5044. result.w = left.w * right.w;
  5045. return result;
  5046. };
  5047. /**
  5048. * Computes the componentwise quotient of two Cartesians.
  5049. *
  5050. * @param {Cartesian4} left The first Cartesian.
  5051. * @param {Cartesian4} right The second Cartesian.
  5052. * @param {Cartesian4} result The object onto which to store the result.
  5053. * @returns {Cartesian4} The modified result parameter.
  5054. */
  5055. Cartesian4.divideComponents = function(left, right, result) {
  5056. if (!defined(left)) {
  5057. throw new DeveloperError('left is required');
  5058. }
  5059. if (!defined(right)) {
  5060. throw new DeveloperError('right is required');
  5061. }
  5062. if (!defined(result)) {
  5063. throw new DeveloperError('result is required');
  5064. }
  5065. result.x = left.x / right.x;
  5066. result.y = left.y / right.y;
  5067. result.z = left.z / right.z;
  5068. result.w = left.w / right.w;
  5069. return result;
  5070. };
  5071. /**
  5072. * Computes the componentwise sum of two Cartesians.
  5073. *
  5074. * @param {Cartesian4} left The first Cartesian.
  5075. * @param {Cartesian4} right The second Cartesian.
  5076. * @param {Cartesian4} result The object onto which to store the result.
  5077. * @returns {Cartesian4} The modified result parameter.
  5078. */
  5079. Cartesian4.add = function(left, right, result) {
  5080. if (!defined(left)) {
  5081. throw new DeveloperError('left is required');
  5082. }
  5083. if (!defined(right)) {
  5084. throw new DeveloperError('right is required');
  5085. }
  5086. if (!defined(result)) {
  5087. throw new DeveloperError('result is required');
  5088. }
  5089. result.x = left.x + right.x;
  5090. result.y = left.y + right.y;
  5091. result.z = left.z + right.z;
  5092. result.w = left.w + right.w;
  5093. return result;
  5094. };
  5095. /**
  5096. * Computes the componentwise difference of two Cartesians.
  5097. *
  5098. * @param {Cartesian4} left The first Cartesian.
  5099. * @param {Cartesian4} right The second Cartesian.
  5100. * @param {Cartesian4} result The object onto which to store the result.
  5101. * @returns {Cartesian4} The modified result parameter.
  5102. */
  5103. Cartesian4.subtract = function(left, right, result) {
  5104. if (!defined(left)) {
  5105. throw new DeveloperError('left is required');
  5106. }
  5107. if (!defined(right)) {
  5108. throw new DeveloperError('right is required');
  5109. }
  5110. if (!defined(result)) {
  5111. throw new DeveloperError('result is required');
  5112. }
  5113. result.x = left.x - right.x;
  5114. result.y = left.y - right.y;
  5115. result.z = left.z - right.z;
  5116. result.w = left.w - right.w;
  5117. return result;
  5118. };
  5119. /**
  5120. * Multiplies the provided Cartesian componentwise by the provided scalar.
  5121. *
  5122. * @param {Cartesian4} cartesian The Cartesian to be scaled.
  5123. * @param {Number} scalar The scalar to multiply with.
  5124. * @param {Cartesian4} result The object onto which to store the result.
  5125. * @returns {Cartesian4} The modified result parameter.
  5126. */
  5127. Cartesian4.multiplyByScalar = function(cartesian, scalar, result) {
  5128. if (!defined(cartesian)) {
  5129. throw new DeveloperError('cartesian is required');
  5130. }
  5131. if (typeof scalar !== 'number') {
  5132. throw new DeveloperError('scalar is required and must be a number.');
  5133. }
  5134. if (!defined(result)) {
  5135. throw new DeveloperError('result is required');
  5136. }
  5137. result.x = cartesian.x * scalar;
  5138. result.y = cartesian.y * scalar;
  5139. result.z = cartesian.z * scalar;
  5140. result.w = cartesian.w * scalar;
  5141. return result;
  5142. };
  5143. /**
  5144. * Divides the provided Cartesian componentwise by the provided scalar.
  5145. *
  5146. * @param {Cartesian4} cartesian The Cartesian to be divided.
  5147. * @param {Number} scalar The scalar to divide by.
  5148. * @param {Cartesian4} result The object onto which to store the result.
  5149. * @returns {Cartesian4} The modified result parameter.
  5150. */
  5151. Cartesian4.divideByScalar = function(cartesian, scalar, result) {
  5152. if (!defined(cartesian)) {
  5153. throw new DeveloperError('cartesian is required');
  5154. }
  5155. if (typeof scalar !== 'number') {
  5156. throw new DeveloperError('scalar is required and must be a number.');
  5157. }
  5158. if (!defined(result)) {
  5159. throw new DeveloperError('result is required');
  5160. }
  5161. result.x = cartesian.x / scalar;
  5162. result.y = cartesian.y / scalar;
  5163. result.z = cartesian.z / scalar;
  5164. result.w = cartesian.w / scalar;
  5165. return result;
  5166. };
  5167. /**
  5168. * Negates the provided Cartesian.
  5169. *
  5170. * @param {Cartesian4} cartesian The Cartesian to be negated.
  5171. * @param {Cartesian4} result The object onto which to store the result.
  5172. * @returns {Cartesian4} The modified result parameter.
  5173. */
  5174. Cartesian4.negate = function(cartesian, result) {
  5175. if (!defined(cartesian)) {
  5176. throw new DeveloperError('cartesian is required');
  5177. }
  5178. if (!defined(result)) {
  5179. throw new DeveloperError('result is required');
  5180. }
  5181. result.x = -cartesian.x;
  5182. result.y = -cartesian.y;
  5183. result.z = -cartesian.z;
  5184. result.w = -cartesian.w;
  5185. return result;
  5186. };
  5187. /**
  5188. * Computes the absolute value of the provided Cartesian.
  5189. *
  5190. * @param {Cartesian4} cartesian The Cartesian whose absolute value is to be computed.
  5191. * @param {Cartesian4} result The object onto which to store the result.
  5192. * @returns {Cartesian4} The modified result parameter.
  5193. */
  5194. Cartesian4.abs = function(cartesian, result) {
  5195. if (!defined(cartesian)) {
  5196. throw new DeveloperError('cartesian is required');
  5197. }
  5198. if (!defined(result)) {
  5199. throw new DeveloperError('result is required');
  5200. }
  5201. result.x = Math.abs(cartesian.x);
  5202. result.y = Math.abs(cartesian.y);
  5203. result.z = Math.abs(cartesian.z);
  5204. result.w = Math.abs(cartesian.w);
  5205. return result;
  5206. };
  5207. var lerpScratch = new Cartesian4();
  5208. /**
  5209. * Computes the linear interpolation or extrapolation at t using the provided cartesians.
  5210. *
  5211. * @param {Cartesian4} start The value corresponding to t at 0.0.
  5212. * @param {Cartesian4}end The value corresponding to t at 1.0.
  5213. * @param {Number} t The point along t at which to interpolate.
  5214. * @param {Cartesian4} result The object onto which to store the result.
  5215. * @returns {Cartesian4} The modified result parameter.
  5216. */
  5217. Cartesian4.lerp = function(start, end, t, result) {
  5218. if (!defined(start)) {
  5219. throw new DeveloperError('start is required.');
  5220. }
  5221. if (!defined(end)) {
  5222. throw new DeveloperError('end is required.');
  5223. }
  5224. if (typeof t !== 'number') {
  5225. throw new DeveloperError('t is required and must be a number.');
  5226. }
  5227. if (!defined(result)) {
  5228. throw new DeveloperError('result is required.');
  5229. }
  5230. Cartesian4.multiplyByScalar(end, t, lerpScratch);
  5231. result = Cartesian4.multiplyByScalar(start, 1.0 - t, result);
  5232. return Cartesian4.add(lerpScratch, result, result);
  5233. };
  5234. var mostOrthogonalAxisScratch = new Cartesian4();
  5235. /**
  5236. * Returns the axis that is most orthogonal to the provided Cartesian.
  5237. *
  5238. * @param {Cartesian4} cartesian The Cartesian on which to find the most orthogonal axis.
  5239. * @param {Cartesian4} result The object onto which to store the result.
  5240. * @returns {Cartesian4} The most orthogonal axis.
  5241. */
  5242. Cartesian4.mostOrthogonalAxis = function(cartesian, result) {
  5243. if (!defined(cartesian)) {
  5244. throw new DeveloperError('cartesian is required.');
  5245. }
  5246. if (!defined(result)) {
  5247. throw new DeveloperError('result is required.');
  5248. }
  5249. var f = Cartesian4.normalize(cartesian, mostOrthogonalAxisScratch);
  5250. Cartesian4.abs(f, f);
  5251. if (f.x <= f.y) {
  5252. if (f.x <= f.z) {
  5253. if (f.x <= f.w) {
  5254. result = Cartesian4.clone(Cartesian4.UNIT_X, result);
  5255. } else {
  5256. result = Cartesian4.clone(Cartesian4.UNIT_W, result);
  5257. }
  5258. } else if (f.z <= f.w) {
  5259. result = Cartesian4.clone(Cartesian4.UNIT_Z, result);
  5260. } else {
  5261. result = Cartesian4.clone(Cartesian4.UNIT_W, result);
  5262. }
  5263. } else if (f.y <= f.z) {
  5264. if (f.y <= f.w) {
  5265. result = Cartesian4.clone(Cartesian4.UNIT_Y, result);
  5266. } else {
  5267. result = Cartesian4.clone(Cartesian4.UNIT_W, result);
  5268. }
  5269. } else if (f.z <= f.w) {
  5270. result = Cartesian4.clone(Cartesian4.UNIT_Z, result);
  5271. } else {
  5272. result = Cartesian4.clone(Cartesian4.UNIT_W, result);
  5273. }
  5274. return result;
  5275. };
  5276. /**
  5277. * Compares the provided Cartesians componentwise and returns
  5278. * <code>true</code> if they are equal, <code>false</code> otherwise.
  5279. *
  5280. * @param {Cartesian4} [left] The first Cartesian.
  5281. * @param {Cartesian4} [right] The second Cartesian.
  5282. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  5283. */
  5284. Cartesian4.equals = function(left, right) {
  5285. return (left === right) ||
  5286. ((defined(left)) &&
  5287. (defined(right)) &&
  5288. (left.x === right.x) &&
  5289. (left.y === right.y) &&
  5290. (left.z === right.z) &&
  5291. (left.w === right.w));
  5292. };
  5293. /**
  5294. * @private
  5295. */
  5296. Cartesian4.equalsArray = function(cartesian, array, offset) {
  5297. return cartesian.x === array[offset] &&
  5298. cartesian.y === array[offset + 1] &&
  5299. cartesian.z === array[offset + 2] &&
  5300. cartesian.w === array[offset + 3];
  5301. };
  5302. /**
  5303. * Compares the provided Cartesians componentwise and returns
  5304. * <code>true</code> if they pass an absolute or relative tolerance test,
  5305. * <code>false</code> otherwise.
  5306. *
  5307. * @param {Cartesian4} [left] The first Cartesian.
  5308. * @param {Cartesian4} [right] The second Cartesian.
  5309. * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
  5310. * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  5311. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  5312. */
  5313. Cartesian4.equalsEpsilon = function(left, right, relativeEpsilon, absoluteEpsilon) {
  5314. return (left === right) ||
  5315. (defined(left) &&
  5316. defined(right) &&
  5317. CesiumMath.equalsEpsilon(left.x, right.x, relativeEpsilon, absoluteEpsilon) &&
  5318. CesiumMath.equalsEpsilon(left.y, right.y, relativeEpsilon, absoluteEpsilon) &&
  5319. CesiumMath.equalsEpsilon(left.z, right.z, relativeEpsilon, absoluteEpsilon) &&
  5320. CesiumMath.equalsEpsilon(left.w, right.w, relativeEpsilon, absoluteEpsilon));
  5321. };
  5322. /**
  5323. * An immutable Cartesian4 instance initialized to (0.0, 0.0, 0.0, 0.0).
  5324. *
  5325. * @type {Cartesian4}
  5326. * @constant
  5327. */
  5328. Cartesian4.ZERO = freezeObject(new Cartesian4(0.0, 0.0, 0.0, 0.0));
  5329. /**
  5330. * An immutable Cartesian4 instance initialized to (1.0, 0.0, 0.0, 0.0).
  5331. *
  5332. * @type {Cartesian4}
  5333. * @constant
  5334. */
  5335. Cartesian4.UNIT_X = freezeObject(new Cartesian4(1.0, 0.0, 0.0, 0.0));
  5336. /**
  5337. * An immutable Cartesian4 instance initialized to (0.0, 1.0, 0.0, 0.0).
  5338. *
  5339. * @type {Cartesian4}
  5340. * @constant
  5341. */
  5342. Cartesian4.UNIT_Y = freezeObject(new Cartesian4(0.0, 1.0, 0.0, 0.0));
  5343. /**
  5344. * An immutable Cartesian4 instance initialized to (0.0, 0.0, 1.0, 0.0).
  5345. *
  5346. * @type {Cartesian4}
  5347. * @constant
  5348. */
  5349. Cartesian4.UNIT_Z = freezeObject(new Cartesian4(0.0, 0.0, 1.0, 0.0));
  5350. /**
  5351. * An immutable Cartesian4 instance initialized to (0.0, 0.0, 0.0, 1.0).
  5352. *
  5353. * @type {Cartesian4}
  5354. * @constant
  5355. */
  5356. Cartesian4.UNIT_W = freezeObject(new Cartesian4(0.0, 0.0, 0.0, 1.0));
  5357. /**
  5358. * Duplicates this Cartesian4 instance.
  5359. *
  5360. * @param {Cartesian4} [result] The object onto which to store the result.
  5361. * @returns {Cartesian4} The modified result parameter or a new Cartesian4 instance if one was not provided.
  5362. */
  5363. Cartesian4.prototype.clone = function(result) {
  5364. return Cartesian4.clone(this, result);
  5365. };
  5366. /**
  5367. * Compares this Cartesian against the provided Cartesian componentwise and returns
  5368. * <code>true</code> if they are equal, <code>false</code> otherwise.
  5369. *
  5370. * @param {Cartesian4} [right] The right hand side Cartesian.
  5371. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  5372. */
  5373. Cartesian4.prototype.equals = function(right) {
  5374. return Cartesian4.equals(this, right);
  5375. };
  5376. /**
  5377. * Compares this Cartesian against the provided Cartesian componentwise and returns
  5378. * <code>true</code> if they pass an absolute or relative tolerance test,
  5379. * <code>false</code> otherwise.
  5380. *
  5381. * @param {Cartesian4} [right] The right hand side Cartesian.
  5382. * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
  5383. * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  5384. * @returns {Boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
  5385. */
  5386. Cartesian4.prototype.equalsEpsilon = function(right, relativeEpsilon, absoluteEpsilon) {
  5387. return Cartesian4.equalsEpsilon(this, right, relativeEpsilon, absoluteEpsilon);
  5388. };
  5389. /**
  5390. * Creates a string representing this Cartesian in the format '(x, y)'.
  5391. *
  5392. * @returns {String} A string representing the provided Cartesian in the format '(x, y)'.
  5393. */
  5394. Cartesian4.prototype.toString = function() {
  5395. return '(' + this.x + ', ' + this.y + ', ' + this.z + ', ' + this.w + ')';
  5396. };
  5397. return Cartesian4;
  5398. });
  5399. /*global define*/
  5400. define('Core/RuntimeError',[
  5401. './defined'
  5402. ], function(
  5403. defined) {
  5404. 'use strict';
  5405. /**
  5406. * Constructs an exception object that is thrown due to an error that can occur at runtime, e.g.,
  5407. * out of memory, could not compile shader, etc. If a function may throw this
  5408. * exception, the calling code should be prepared to catch it.
  5409. * <br /><br />
  5410. * On the other hand, a {@link DeveloperError} indicates an exception due
  5411. * to a developer error, e.g., invalid argument, that usually indicates a bug in the
  5412. * calling code.
  5413. *
  5414. * @alias RuntimeError
  5415. * @constructor
  5416. * @extends Error
  5417. *
  5418. * @param {String} [message] The error message for this exception.
  5419. *
  5420. * @see DeveloperError
  5421. */
  5422. function RuntimeError(message) {
  5423. /**
  5424. * 'RuntimeError' indicating that this exception was thrown due to a runtime error.
  5425. * @type {String}
  5426. * @readonly
  5427. */
  5428. this.name = 'RuntimeError';
  5429. /**
  5430. * The explanation for why this exception was thrown.
  5431. * @type {String}
  5432. * @readonly
  5433. */
  5434. this.message = message;
  5435. //Browsers such as IE don't have a stack property until you actually throw the error.
  5436. var stack;
  5437. try {
  5438. throw new Error();
  5439. } catch (e) {
  5440. stack = e.stack;
  5441. }
  5442. /**
  5443. * The stack trace of this exception, if available.
  5444. * @type {String}
  5445. * @readonly
  5446. */
  5447. this.stack = stack;
  5448. }
  5449. if (defined(Object.create)) {
  5450. RuntimeError.prototype = Object.create(Error.prototype);
  5451. RuntimeError.prototype.constructor = RuntimeError;
  5452. }
  5453. RuntimeError.prototype.toString = function() {
  5454. var str = this.name + ': ' + this.message;
  5455. if (defined(this.stack)) {
  5456. str += '\n' + this.stack.toString();
  5457. }
  5458. return str;
  5459. };
  5460. return RuntimeError;
  5461. });
  5462. /*global define*/
  5463. define('Core/Matrix4',[
  5464. './Cartesian3',
  5465. './Cartesian4',
  5466. './defaultValue',
  5467. './defined',
  5468. './defineProperties',
  5469. './DeveloperError',
  5470. './freezeObject',
  5471. './Math',
  5472. './Matrix3',
  5473. './RuntimeError'
  5474. ], function(
  5475. Cartesian3,
  5476. Cartesian4,
  5477. defaultValue,
  5478. defined,
  5479. defineProperties,
  5480. DeveloperError,
  5481. freezeObject,
  5482. CesiumMath,
  5483. Matrix3,
  5484. RuntimeError) {
  5485. 'use strict';
  5486. /**
  5487. * A 4x4 matrix, indexable as a column-major order array.
  5488. * Constructor parameters are in row-major order for code readability.
  5489. * @alias Matrix4
  5490. * @constructor
  5491. *
  5492. * @param {Number} [column0Row0=0.0] The value for column 0, row 0.
  5493. * @param {Number} [column1Row0=0.0] The value for column 1, row 0.
  5494. * @param {Number} [column2Row0=0.0] The value for column 2, row 0.
  5495. * @param {Number} [column3Row0=0.0] The value for column 3, row 0.
  5496. * @param {Number} [column0Row1=0.0] The value for column 0, row 1.
  5497. * @param {Number} [column1Row1=0.0] The value for column 1, row 1.
  5498. * @param {Number} [column2Row1=0.0] The value for column 2, row 1.
  5499. * @param {Number} [column3Row1=0.0] The value for column 3, row 1.
  5500. * @param {Number} [column0Row2=0.0] The value for column 0, row 2.
  5501. * @param {Number} [column1Row2=0.0] The value for column 1, row 2.
  5502. * @param {Number} [column2Row2=0.0] The value for column 2, row 2.
  5503. * @param {Number} [column3Row2=0.0] The value for column 3, row 2.
  5504. * @param {Number} [column0Row3=0.0] The value for column 0, row 3.
  5505. * @param {Number} [column1Row3=0.0] The value for column 1, row 3.
  5506. * @param {Number} [column2Row3=0.0] The value for column 2, row 3.
  5507. * @param {Number} [column3Row3=0.0] The value for column 3, row 3.
  5508. *
  5509. * @see Matrix4.fromColumnMajorArray
  5510. * @see Matrix4.fromRowMajorArray
  5511. * @see Matrix4.fromRotationTranslation
  5512. * @see Matrix4.fromTranslationRotationScale
  5513. * @see Matrix4.fromTranslationQuaternionRotationScale
  5514. * @see Matrix4.fromTranslation
  5515. * @see Matrix4.fromScale
  5516. * @see Matrix4.fromUniformScale
  5517. * @see Matrix4.fromCamera
  5518. * @see Matrix4.computePerspectiveFieldOfView
  5519. * @see Matrix4.computeOrthographicOffCenter
  5520. * @see Matrix4.computePerspectiveOffCenter
  5521. * @see Matrix4.computeInfinitePerspectiveOffCenter
  5522. * @see Matrix4.computeViewportTransformation
  5523. * @see Matrix4.computeView
  5524. * @see Matrix2
  5525. * @see Matrix3
  5526. * @see Packable
  5527. */
  5528. function Matrix4(column0Row0, column1Row0, column2Row0, column3Row0,
  5529. column0Row1, column1Row1, column2Row1, column3Row1,
  5530. column0Row2, column1Row2, column2Row2, column3Row2,
  5531. column0Row3, column1Row3, column2Row3, column3Row3) {
  5532. this[0] = defaultValue(column0Row0, 0.0);
  5533. this[1] = defaultValue(column0Row1, 0.0);
  5534. this[2] = defaultValue(column0Row2, 0.0);
  5535. this[3] = defaultValue(column0Row3, 0.0);
  5536. this[4] = defaultValue(column1Row0, 0.0);
  5537. this[5] = defaultValue(column1Row1, 0.0);
  5538. this[6] = defaultValue(column1Row2, 0.0);
  5539. this[7] = defaultValue(column1Row3, 0.0);
  5540. this[8] = defaultValue(column2Row0, 0.0);
  5541. this[9] = defaultValue(column2Row1, 0.0);
  5542. this[10] = defaultValue(column2Row2, 0.0);
  5543. this[11] = defaultValue(column2Row3, 0.0);
  5544. this[12] = defaultValue(column3Row0, 0.0);
  5545. this[13] = defaultValue(column3Row1, 0.0);
  5546. this[14] = defaultValue(column3Row2, 0.0);
  5547. this[15] = defaultValue(column3Row3, 0.0);
  5548. }
  5549. /**
  5550. * The number of elements used to pack the object into an array.
  5551. * @type {Number}
  5552. */
  5553. Matrix4.packedLength = 16;
  5554. /**
  5555. * Stores the provided instance into the provided array.
  5556. *
  5557. * @param {Matrix4} value The value to pack.
  5558. * @param {Number[]} array The array to pack into.
  5559. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  5560. *
  5561. * @returns {Number[]} The array that was packed into
  5562. */
  5563. Matrix4.pack = function(value, array, startingIndex) {
  5564. if (!defined(value)) {
  5565. throw new DeveloperError('value is required');
  5566. }
  5567. if (!defined(array)) {
  5568. throw new DeveloperError('array is required');
  5569. }
  5570. startingIndex = defaultValue(startingIndex, 0);
  5571. array[startingIndex++] = value[0];
  5572. array[startingIndex++] = value[1];
  5573. array[startingIndex++] = value[2];
  5574. array[startingIndex++] = value[3];
  5575. array[startingIndex++] = value[4];
  5576. array[startingIndex++] = value[5];
  5577. array[startingIndex++] = value[6];
  5578. array[startingIndex++] = value[7];
  5579. array[startingIndex++] = value[8];
  5580. array[startingIndex++] = value[9];
  5581. array[startingIndex++] = value[10];
  5582. array[startingIndex++] = value[11];
  5583. array[startingIndex++] = value[12];
  5584. array[startingIndex++] = value[13];
  5585. array[startingIndex++] = value[14];
  5586. array[startingIndex] = value[15];
  5587. return array;
  5588. };
  5589. /**
  5590. * Retrieves an instance from a packed array.
  5591. *
  5592. * @param {Number[]} array The packed array.
  5593. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  5594. * @param {Matrix4} [result] The object into which to store the result.
  5595. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
  5596. */
  5597. Matrix4.unpack = function(array, startingIndex, result) {
  5598. if (!defined(array)) {
  5599. throw new DeveloperError('array is required');
  5600. }
  5601. startingIndex = defaultValue(startingIndex, 0);
  5602. if (!defined(result)) {
  5603. result = new Matrix4();
  5604. }
  5605. result[0] = array[startingIndex++];
  5606. result[1] = array[startingIndex++];
  5607. result[2] = array[startingIndex++];
  5608. result[3] = array[startingIndex++];
  5609. result[4] = array[startingIndex++];
  5610. result[5] = array[startingIndex++];
  5611. result[6] = array[startingIndex++];
  5612. result[7] = array[startingIndex++];
  5613. result[8] = array[startingIndex++];
  5614. result[9] = array[startingIndex++];
  5615. result[10] = array[startingIndex++];
  5616. result[11] = array[startingIndex++];
  5617. result[12] = array[startingIndex++];
  5618. result[13] = array[startingIndex++];
  5619. result[14] = array[startingIndex++];
  5620. result[15] = array[startingIndex];
  5621. return result;
  5622. };
  5623. /**
  5624. * Duplicates a Matrix4 instance.
  5625. *
  5626. * @param {Matrix4} matrix The matrix to duplicate.
  5627. * @param {Matrix4} [result] The object onto which to store the result.
  5628. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided. (Returns undefined if matrix is undefined)
  5629. */
  5630. Matrix4.clone = function(matrix, result) {
  5631. if (!defined(matrix)) {
  5632. return undefined;
  5633. }
  5634. if (!defined(result)) {
  5635. return new Matrix4(matrix[0], matrix[4], matrix[8], matrix[12],
  5636. matrix[1], matrix[5], matrix[9], matrix[13],
  5637. matrix[2], matrix[6], matrix[10], matrix[14],
  5638. matrix[3], matrix[7], matrix[11], matrix[15]);
  5639. }
  5640. result[0] = matrix[0];
  5641. result[1] = matrix[1];
  5642. result[2] = matrix[2];
  5643. result[3] = matrix[3];
  5644. result[4] = matrix[4];
  5645. result[5] = matrix[5];
  5646. result[6] = matrix[6];
  5647. result[7] = matrix[7];
  5648. result[8] = matrix[8];
  5649. result[9] = matrix[9];
  5650. result[10] = matrix[10];
  5651. result[11] = matrix[11];
  5652. result[12] = matrix[12];
  5653. result[13] = matrix[13];
  5654. result[14] = matrix[14];
  5655. result[15] = matrix[15];
  5656. return result;
  5657. };
  5658. /**
  5659. * Creates a Matrix4 from 16 consecutive elements in an array.
  5660. * @function
  5661. *
  5662. * @param {Number[]} array The array whose 16 consecutive elements correspond to the positions of the matrix. Assumes column-major order.
  5663. * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.
  5664. * @param {Matrix4} [result] The object onto which to store the result.
  5665. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
  5666. *
  5667. * @example
  5668. * // Create the Matrix4:
  5669. * // [1.0, 2.0, 3.0, 4.0]
  5670. * // [1.0, 2.0, 3.0, 4.0]
  5671. * // [1.0, 2.0, 3.0, 4.0]
  5672. * // [1.0, 2.0, 3.0, 4.0]
  5673. *
  5674. * 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];
  5675. * var m = Cesium.Matrix4.fromArray(v);
  5676. *
  5677. * // Create same Matrix4 with using an offset into an array
  5678. * 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];
  5679. * var m2 = Cesium.Matrix4.fromArray(v2, 2);
  5680. */
  5681. Matrix4.fromArray = Matrix4.unpack;
  5682. /**
  5683. * Computes a Matrix4 instance from a column-major order array.
  5684. *
  5685. * @param {Number[]} values The column-major order array.
  5686. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5687. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5688. */
  5689. Matrix4.fromColumnMajorArray = function(values, result) {
  5690. if (!defined(values)) {
  5691. throw new DeveloperError('values is required');
  5692. }
  5693. return Matrix4.clone(values, result);
  5694. };
  5695. /**
  5696. * Computes a Matrix4 instance from a row-major order array.
  5697. * The resulting matrix will be in column-major order.
  5698. *
  5699. * @param {Number[]} values The row-major order array.
  5700. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5701. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5702. */
  5703. Matrix4.fromRowMajorArray = function(values, result) {
  5704. if (!defined(values)) {
  5705. throw new DeveloperError('values is required.');
  5706. }
  5707. if (!defined(result)) {
  5708. return new Matrix4(values[0], values[1], values[2], values[3],
  5709. values[4], values[5], values[6], values[7],
  5710. values[8], values[9], values[10], values[11],
  5711. values[12], values[13], values[14], values[15]);
  5712. }
  5713. result[0] = values[0];
  5714. result[1] = values[4];
  5715. result[2] = values[8];
  5716. result[3] = values[12];
  5717. result[4] = values[1];
  5718. result[5] = values[5];
  5719. result[6] = values[9];
  5720. result[7] = values[13];
  5721. result[8] = values[2];
  5722. result[9] = values[6];
  5723. result[10] = values[10];
  5724. result[11] = values[14];
  5725. result[12] = values[3];
  5726. result[13] = values[7];
  5727. result[14] = values[11];
  5728. result[15] = values[15];
  5729. return result;
  5730. };
  5731. /**
  5732. * Computes a Matrix4 instance from a Matrix3 representing the rotation
  5733. * and a Cartesian3 representing the translation.
  5734. *
  5735. * @param {Matrix3} rotation The upper left portion of the matrix representing the rotation.
  5736. * @param {Cartesian3} [translation=Cartesian3.ZERO] The upper right portion of the matrix representing the translation.
  5737. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5738. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5739. */
  5740. Matrix4.fromRotationTranslation = function(rotation, translation, result) {
  5741. if (!defined(rotation)) {
  5742. throw new DeveloperError('rotation is required.');
  5743. }
  5744. translation = defaultValue(translation, Cartesian3.ZERO);
  5745. if (!defined(result)) {
  5746. return new Matrix4(rotation[0], rotation[3], rotation[6], translation.x,
  5747. rotation[1], rotation[4], rotation[7], translation.y,
  5748. rotation[2], rotation[5], rotation[8], translation.z,
  5749. 0.0, 0.0, 0.0, 1.0);
  5750. }
  5751. result[0] = rotation[0];
  5752. result[1] = rotation[1];
  5753. result[2] = rotation[2];
  5754. result[3] = 0.0;
  5755. result[4] = rotation[3];
  5756. result[5] = rotation[4];
  5757. result[6] = rotation[5];
  5758. result[7] = 0.0;
  5759. result[8] = rotation[6];
  5760. result[9] = rotation[7];
  5761. result[10] = rotation[8];
  5762. result[11] = 0.0;
  5763. result[12] = translation.x;
  5764. result[13] = translation.y;
  5765. result[14] = translation.z;
  5766. result[15] = 1.0;
  5767. return result;
  5768. };
  5769. /**
  5770. * Computes a Matrix4 instance from a translation, rotation, and scale (TRS)
  5771. * representation with the rotation represented as a quaternion.
  5772. *
  5773. * @param {Cartesian3} translation The translation transformation.
  5774. * @param {Quaternion} rotation The rotation transformation.
  5775. * @param {Cartesian3} scale The non-uniform scale transformation.
  5776. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5777. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5778. *
  5779. * @example
  5780. * var result = Cesium.Matrix4.fromTranslationQuaternionRotationScale(
  5781. * new Cesium.Cartesian3(1.0, 2.0, 3.0), // translation
  5782. * Cesium.Quaternion.IDENTITY, // rotation
  5783. * new Cesium.Cartesian3(7.0, 8.0, 9.0), // scale
  5784. * result);
  5785. */
  5786. Matrix4.fromTranslationQuaternionRotationScale = function(translation, rotation, scale, result) {
  5787. if (!defined(translation)) {
  5788. throw new DeveloperError('translation is required.');
  5789. }
  5790. if (!defined(rotation)) {
  5791. throw new DeveloperError('rotation is required.');
  5792. }
  5793. if (!defined(scale)) {
  5794. throw new DeveloperError('scale is required.');
  5795. }
  5796. if (!defined(result)) {
  5797. result = new Matrix4();
  5798. }
  5799. var scaleX = scale.x;
  5800. var scaleY = scale.y;
  5801. var scaleZ = scale.z;
  5802. var x2 = rotation.x * rotation.x;
  5803. var xy = rotation.x * rotation.y;
  5804. var xz = rotation.x * rotation.z;
  5805. var xw = rotation.x * rotation.w;
  5806. var y2 = rotation.y * rotation.y;
  5807. var yz = rotation.y * rotation.z;
  5808. var yw = rotation.y * rotation.w;
  5809. var z2 = rotation.z * rotation.z;
  5810. var zw = rotation.z * rotation.w;
  5811. var w2 = rotation.w * rotation.w;
  5812. var m00 = x2 - y2 - z2 + w2;
  5813. var m01 = 2.0 * (xy - zw);
  5814. var m02 = 2.0 * (xz + yw);
  5815. var m10 = 2.0 * (xy + zw);
  5816. var m11 = -x2 + y2 - z2 + w2;
  5817. var m12 = 2.0 * (yz - xw);
  5818. var m20 = 2.0 * (xz - yw);
  5819. var m21 = 2.0 * (yz + xw);
  5820. var m22 = -x2 - y2 + z2 + w2;
  5821. result[0] = m00 * scaleX;
  5822. result[1] = m10 * scaleX;
  5823. result[2] = m20 * scaleX;
  5824. result[3] = 0.0;
  5825. result[4] = m01 * scaleY;
  5826. result[5] = m11 * scaleY;
  5827. result[6] = m21 * scaleY;
  5828. result[7] = 0.0;
  5829. result[8] = m02 * scaleZ;
  5830. result[9] = m12 * scaleZ;
  5831. result[10] = m22 * scaleZ;
  5832. result[11] = 0.0;
  5833. result[12] = translation.x;
  5834. result[13] = translation.y;
  5835. result[14] = translation.z;
  5836. result[15] = 1.0;
  5837. return result;
  5838. };
  5839. /**
  5840. * Creates a Matrix4 instance from a {@link TranslationRotationScale} instance.
  5841. *
  5842. * @param {TranslationRotationScale} translationRotationScale The instance.
  5843. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5844. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5845. */
  5846. Matrix4.fromTranslationRotationScale = function(translationRotationScale, result) {
  5847. if (!defined(translationRotationScale)) {
  5848. throw new DeveloperError('translationRotationScale is required.');
  5849. }
  5850. return Matrix4.fromTranslationQuaternionRotationScale(translationRotationScale.translation, translationRotationScale.rotation, translationRotationScale.scale, result);
  5851. };
  5852. /**
  5853. * Creates a Matrix4 instance from a Cartesian3 representing the translation.
  5854. *
  5855. * @param {Cartesian3} translation The upper right portion of the matrix representing the translation.
  5856. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5857. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5858. *
  5859. * @see Matrix4.multiplyByTranslation
  5860. */
  5861. Matrix4.fromTranslation = function(translation, result) {
  5862. if (!defined(translation)) {
  5863. throw new DeveloperError('translation is required.');
  5864. }
  5865. return Matrix4.fromRotationTranslation(Matrix3.IDENTITY, translation, result);
  5866. };
  5867. /**
  5868. * Computes a Matrix4 instance representing a non-uniform scale.
  5869. *
  5870. * @param {Cartesian3} scale The x, y, and z scale factors.
  5871. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5872. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5873. *
  5874. * @example
  5875. * // Creates
  5876. * // [7.0, 0.0, 0.0, 0.0]
  5877. * // [0.0, 8.0, 0.0, 0.0]
  5878. * // [0.0, 0.0, 9.0, 0.0]
  5879. * // [0.0, 0.0, 0.0, 1.0]
  5880. * var m = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));
  5881. */
  5882. Matrix4.fromScale = function(scale, result) {
  5883. if (!defined(scale)) {
  5884. throw new DeveloperError('scale is required.');
  5885. }
  5886. if (!defined(result)) {
  5887. return new Matrix4(
  5888. scale.x, 0.0, 0.0, 0.0,
  5889. 0.0, scale.y, 0.0, 0.0,
  5890. 0.0, 0.0, scale.z, 0.0,
  5891. 0.0, 0.0, 0.0, 1.0);
  5892. }
  5893. result[0] = scale.x;
  5894. result[1] = 0.0;
  5895. result[2] = 0.0;
  5896. result[3] = 0.0;
  5897. result[4] = 0.0;
  5898. result[5] = scale.y;
  5899. result[6] = 0.0;
  5900. result[7] = 0.0;
  5901. result[8] = 0.0;
  5902. result[9] = 0.0;
  5903. result[10] = scale.z;
  5904. result[11] = 0.0;
  5905. result[12] = 0.0;
  5906. result[13] = 0.0;
  5907. result[14] = 0.0;
  5908. result[15] = 1.0;
  5909. return result;
  5910. };
  5911. /**
  5912. * Computes a Matrix4 instance representing a uniform scale.
  5913. *
  5914. * @param {Number} scale The uniform scale factor.
  5915. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5916. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5917. *
  5918. * @example
  5919. * // Creates
  5920. * // [2.0, 0.0, 0.0, 0.0]
  5921. * // [0.0, 2.0, 0.0, 0.0]
  5922. * // [0.0, 0.0, 2.0, 0.0]
  5923. * // [0.0, 0.0, 0.0, 1.0]
  5924. * var m = Cesium.Matrix4.fromUniformScale(2.0);
  5925. */
  5926. Matrix4.fromUniformScale = function(scale, result) {
  5927. if (typeof scale !== 'number') {
  5928. throw new DeveloperError('scale is required.');
  5929. }
  5930. if (!defined(result)) {
  5931. return new Matrix4(scale, 0.0, 0.0, 0.0,
  5932. 0.0, scale, 0.0, 0.0,
  5933. 0.0, 0.0, scale, 0.0,
  5934. 0.0, 0.0, 0.0, 1.0);
  5935. }
  5936. result[0] = scale;
  5937. result[1] = 0.0;
  5938. result[2] = 0.0;
  5939. result[3] = 0.0;
  5940. result[4] = 0.0;
  5941. result[5] = scale;
  5942. result[6] = 0.0;
  5943. result[7] = 0.0;
  5944. result[8] = 0.0;
  5945. result[9] = 0.0;
  5946. result[10] = scale;
  5947. result[11] = 0.0;
  5948. result[12] = 0.0;
  5949. result[13] = 0.0;
  5950. result[14] = 0.0;
  5951. result[15] = 1.0;
  5952. return result;
  5953. };
  5954. var fromCameraF = new Cartesian3();
  5955. var fromCameraR = new Cartesian3();
  5956. var fromCameraU = new Cartesian3();
  5957. /**
  5958. * Computes a Matrix4 instance from a Camera.
  5959. *
  5960. * @param {Camera} camera The camera to use.
  5961. * @param {Matrix4} [result] The object in which the result will be stored, if undefined a new instance will be created.
  5962. * @returns {Matrix4} The modified result parameter, or a new Matrix4 instance if one was not provided.
  5963. */
  5964. Matrix4.fromCamera = function(camera, result) {
  5965. if (!defined(camera)) {
  5966. throw new DeveloperError('camera is required.');
  5967. }
  5968. var position = camera.position;
  5969. var direction = camera.direction;
  5970. var up = camera.up;
  5971. if (!defined(position)) {
  5972. throw new DeveloperError('camera.position is required.');
  5973. }
  5974. if (!defined(direction)) {
  5975. throw new DeveloperError('camera.direction is required.');
  5976. }
  5977. if (!defined(up)) {
  5978. throw new DeveloperError('camera.up is required.');
  5979. }
  5980. Cartesian3.normalize(direction, fromCameraF);
  5981. Cartesian3.normalize(Cartesian3.cross(fromCameraF, up, fromCameraR), fromCameraR);
  5982. Cartesian3.normalize(Cartesian3.cross(fromCameraR, fromCameraF, fromCameraU), fromCameraU);
  5983. var sX = fromCameraR.x;
  5984. var sY = fromCameraR.y;
  5985. var sZ = fromCameraR.z;
  5986. var fX = fromCameraF.x;
  5987. var fY = fromCameraF.y;
  5988. var fZ = fromCameraF.z;
  5989. var uX = fromCameraU.x;
  5990. var uY = fromCameraU.y;
  5991. var uZ = fromCameraU.z;
  5992. var positionX = position.x;
  5993. var positionY = position.y;
  5994. var positionZ = position.z;
  5995. var t0 = sX * -positionX + sY * -positionY+ sZ * -positionZ;
  5996. var t1 = uX * -positionX + uY * -positionY+ uZ * -positionZ;
  5997. var t2 = fX * positionX + fY * positionY + fZ * positionZ;
  5998. // The code below this comment is an optimized
  5999. // version of the commented lines.
  6000. // Rather that create two matrices and then multiply,
  6001. // we just bake in the multiplcation as part of creation.
  6002. // var rotation = new Matrix4(
  6003. // sX, sY, sZ, 0.0,
  6004. // uX, uY, uZ, 0.0,
  6005. // -fX, -fY, -fZ, 0.0,
  6006. // 0.0, 0.0, 0.0, 1.0);
  6007. // var translation = new Matrix4(
  6008. // 1.0, 0.0, 0.0, -position.x,
  6009. // 0.0, 1.0, 0.0, -position.y,
  6010. // 0.0, 0.0, 1.0, -position.z,
  6011. // 0.0, 0.0, 0.0, 1.0);
  6012. // return rotation.multiply(translation);
  6013. if (!defined(result)) {
  6014. return new Matrix4(
  6015. sX, sY, sZ, t0,
  6016. uX, uY, uZ, t1,
  6017. -fX, -fY, -fZ, t2,
  6018. 0.0, 0.0, 0.0, 1.0);
  6019. }
  6020. result[0] = sX;
  6021. result[1] = uX;
  6022. result[2] = -fX;
  6023. result[3] = 0.0;
  6024. result[4] = sY;
  6025. result[5] = uY;
  6026. result[6] = -fY;
  6027. result[7] = 0.0;
  6028. result[8] = sZ;
  6029. result[9] = uZ;
  6030. result[10] = -fZ;
  6031. result[11] = 0.0;
  6032. result[12] = t0;
  6033. result[13] = t1;
  6034. result[14] = t2;
  6035. result[15] = 1.0;
  6036. return result;
  6037. };
  6038. /**
  6039. * Computes a Matrix4 instance representing a perspective transformation matrix.
  6040. *
  6041. * @param {Number} fovY The field of view along the Y axis in radians.
  6042. * @param {Number} aspectRatio The aspect ratio.
  6043. * @param {Number} near The distance to the near plane in meters.
  6044. * @param {Number} far The distance to the far plane in meters.
  6045. * @param {Matrix4} result The object in which the result will be stored.
  6046. * @returns {Matrix4} The modified result parameter.
  6047. *
  6048. * @exception {DeveloperError} fovY must be in (0, PI].
  6049. * @exception {DeveloperError} aspectRatio must be greater than zero.
  6050. * @exception {DeveloperError} near must be greater than zero.
  6051. * @exception {DeveloperError} far must be greater than zero.
  6052. */
  6053. Matrix4.computePerspectiveFieldOfView = function(fovY, aspectRatio, near, far, result) {
  6054. if (fovY <= 0.0 || fovY > Math.PI) {
  6055. throw new DeveloperError('fovY must be in (0, PI].');
  6056. }
  6057. if (aspectRatio <= 0.0) {
  6058. throw new DeveloperError('aspectRatio must be greater than zero.');
  6059. }
  6060. if (near <= 0.0) {
  6061. throw new DeveloperError('near must be greater than zero.');
  6062. }
  6063. if (far <= 0.0) {
  6064. throw new DeveloperError('far must be greater than zero.');
  6065. }
  6066. if (!defined(result)) {
  6067. throw new DeveloperError('result is required');
  6068. }
  6069. var bottom = Math.tan(fovY * 0.5);
  6070. var column1Row1 = 1.0 / bottom;
  6071. var column0Row0 = column1Row1 / aspectRatio;
  6072. var column2Row2 = (far + near) / (near - far);
  6073. var column3Row2 = (2.0 * far * near) / (near - far);
  6074. result[0] = column0Row0;
  6075. result[1] = 0.0;
  6076. result[2] = 0.0;
  6077. result[3] = 0.0;
  6078. result[4] = 0.0;
  6079. result[5] = column1Row1;
  6080. result[6] = 0.0;
  6081. result[7] = 0.0;
  6082. result[8] = 0.0;
  6083. result[9] = 0.0;
  6084. result[10] = column2Row2;
  6085. result[11] = -1.0;
  6086. result[12] = 0.0;
  6087. result[13] = 0.0;
  6088. result[14] = column3Row2;
  6089. result[15] = 0.0;
  6090. return result;
  6091. };
  6092. /**
  6093. * Computes a Matrix4 instance representing an orthographic transformation matrix.
  6094. *
  6095. * @param {Number} left The number of meters to the left of the camera that will be in view.
  6096. * @param {Number} right The number of meters to the right of the camera that will be in view.
  6097. * @param {Number} bottom The number of meters below of the camera that will be in view.
  6098. * @param {Number} top The number of meters above of the camera that will be in view.
  6099. * @param {Number} near The distance to the near plane in meters.
  6100. * @param {Number} far The distance to the far plane in meters.
  6101. * @param {Matrix4} result The object in which the result will be stored.
  6102. * @returns {Matrix4} The modified result parameter.
  6103. */
  6104. Matrix4.computeOrthographicOffCenter = function(left, right, bottom, top, near, far, result) {
  6105. if (!defined(left)) {
  6106. throw new DeveloperError('left is required.');
  6107. }
  6108. if (!defined(right)) {
  6109. throw new DeveloperError('right is required.');
  6110. }
  6111. if (!defined(bottom)) {
  6112. throw new DeveloperError('bottom is required.');
  6113. }
  6114. if (!defined(top)) {
  6115. throw new DeveloperError('top is required.');
  6116. }
  6117. if (!defined(near)) {
  6118. throw new DeveloperError('near is required.');
  6119. }
  6120. if (!defined(far)) {
  6121. throw new DeveloperError('far is required.');
  6122. }
  6123. if (!defined(result)) {
  6124. throw new DeveloperError('result is required');
  6125. }
  6126. var a = 1.0 / (right - left);
  6127. var b = 1.0 / (top - bottom);
  6128. var c = 1.0 / (far - near);
  6129. var tx = -(right + left) * a;
  6130. var ty = -(top + bottom) * b;
  6131. var tz = -(far + near) * c;
  6132. a *= 2.0;
  6133. b *= 2.0;
  6134. c *= -2.0;
  6135. result[0] = a;
  6136. result[1] = 0.0;
  6137. result[2] = 0.0;
  6138. result[3] = 0.0;
  6139. result[4] = 0.0;
  6140. result[5] = b;
  6141. result[6] = 0.0;
  6142. result[7] = 0.0;
  6143. result[8] = 0.0;
  6144. result[9] = 0.0;
  6145. result[10] = c;
  6146. result[11] = 0.0;
  6147. result[12] = tx;
  6148. result[13] = ty;
  6149. result[14] = tz;
  6150. result[15] = 1.0;
  6151. return result;
  6152. };
  6153. /**
  6154. * Computes a Matrix4 instance representing an off center perspective transformation.
  6155. *
  6156. * @param {Number} left The number of meters to the left of the camera that will be in view.
  6157. * @param {Number} right The number of meters to the right of the camera that will be in view.
  6158. * @param {Number} bottom The number of meters below of the camera that will be in view.
  6159. * @param {Number} top The number of meters above of the camera that will be in view.
  6160. * @param {Number} near The distance to the near plane in meters.
  6161. * @param {Number} far The distance to the far plane in meters.
  6162. * @param {Matrix4} result The object in which the result will be stored.
  6163. * @returns {Matrix4} The modified result parameter.
  6164. */
  6165. Matrix4.computePerspectiveOffCenter = function(left, right, bottom, top, near, far, result) {
  6166. if (!defined(left)) {
  6167. throw new DeveloperError('left is required.');
  6168. }
  6169. if (!defined(right)) {
  6170. throw new DeveloperError('right is required.');
  6171. }
  6172. if (!defined(bottom)) {
  6173. throw new DeveloperError('bottom is required.');
  6174. }
  6175. if (!defined(top)) {
  6176. throw new DeveloperError('top is required.');
  6177. }
  6178. if (!defined(near)) {
  6179. throw new DeveloperError('near is required.');
  6180. }
  6181. if (!defined(far)) {
  6182. throw new DeveloperError('far is required.');
  6183. }
  6184. if (!defined(result)) {
  6185. throw new DeveloperError('result is required');
  6186. }
  6187. var column0Row0 = 2.0 * near / (right - left);
  6188. var column1Row1 = 2.0 * near / (top - bottom);
  6189. var column2Row0 = (right + left) / (right - left);
  6190. var column2Row1 = (top + bottom) / (top - bottom);
  6191. var column2Row2 = -(far + near) / (far - near);
  6192. var column2Row3 = -1.0;
  6193. var column3Row2 = -2.0 * far * near / (far - near);
  6194. result[0] = column0Row0;
  6195. result[1] = 0.0;
  6196. result[2] = 0.0;
  6197. result[3] = 0.0;
  6198. result[4] = 0.0;
  6199. result[5] = column1Row1;
  6200. result[6] = 0.0;
  6201. result[7] = 0.0;
  6202. result[8] = column2Row0;
  6203. result[9] = column2Row1;
  6204. result[10] = column2Row2;
  6205. result[11] = column2Row3;
  6206. result[12] = 0.0;
  6207. result[13] = 0.0;
  6208. result[14] = column3Row2;
  6209. result[15] = 0.0;
  6210. return result;
  6211. };
  6212. /**
  6213. * Computes a Matrix4 instance representing an infinite off center perspective transformation.
  6214. *
  6215. * @param {Number} left The number of meters to the left of the camera that will be in view.
  6216. * @param {Number} right The number of meters to the right of the camera that will be in view.
  6217. * @param {Number} bottom The number of meters below of the camera that will be in view.
  6218. * @param {Number} top The number of meters above of the camera that will be in view.
  6219. * @param {Number} near The distance to the near plane in meters.
  6220. * @param {Matrix4} result The object in which the result will be stored.
  6221. * @returns {Matrix4} The modified result parameter.
  6222. */
  6223. Matrix4.computeInfinitePerspectiveOffCenter = function(left, right, bottom, top, near, result) {
  6224. if (!defined(left)) {
  6225. throw new DeveloperError('left is required.');
  6226. }
  6227. if (!defined(right)) {
  6228. throw new DeveloperError('right is required.');
  6229. }
  6230. if (!defined(bottom)) {
  6231. throw new DeveloperError('bottom is required.');
  6232. }
  6233. if (!defined(top)) {
  6234. throw new DeveloperError('top is required.');
  6235. }
  6236. if (!defined(near)) {
  6237. throw new DeveloperError('near is required.');
  6238. }
  6239. if (!defined(result)) {
  6240. throw new DeveloperError('result is required');
  6241. }
  6242. var column0Row0 = 2.0 * near / (right - left);
  6243. var column1Row1 = 2.0 * near / (top - bottom);
  6244. var column2Row0 = (right + left) / (right - left);
  6245. var column2Row1 = (top + bottom) / (top - bottom);
  6246. var column2Row2 = -1.0;
  6247. var column2Row3 = -1.0;
  6248. var column3Row2 = -2.0 * near;
  6249. result[0] = column0Row0;
  6250. result[1] = 0.0;
  6251. result[2] = 0.0;
  6252. result[3] = 0.0;
  6253. result[4] = 0.0;
  6254. result[5] = column1Row1;
  6255. result[6] = 0.0;
  6256. result[7] = 0.0;
  6257. result[8] = column2Row0;
  6258. result[9] = column2Row1;
  6259. result[10] = column2Row2;
  6260. result[11] = column2Row3;
  6261. result[12] = 0.0;
  6262. result[13] = 0.0;
  6263. result[14] = column3Row2;
  6264. result[15] = 0.0;
  6265. return result;
  6266. };
  6267. /**
  6268. * Computes a Matrix4 instance that transforms from normalized device coordinates to window coordinates.
  6269. *
  6270. * @param {Object}[viewport = { x : 0.0, y : 0.0, width : 0.0, height : 0.0 }] The viewport's corners as shown in Example 1.
  6271. * @param {Number}[nearDepthRange=0.0] The near plane distance in window coordinates.
  6272. * @param {Number}[farDepthRange=1.0] The far plane distance in window coordinates.
  6273. * @param {Matrix4} result The object in which the result will be stored.
  6274. * @returns {Matrix4} The modified result parameter.
  6275. *
  6276. * @example
  6277. * // Create viewport transformation using an explicit viewport and depth range.
  6278. * var m = Cesium.Matrix4.computeViewportTransformation({
  6279. * x : 0.0,
  6280. * y : 0.0,
  6281. * width : 1024.0,
  6282. * height : 768.0
  6283. * }, 0.0, 1.0, new Cesium.Matrix4());
  6284. */
  6285. Matrix4.computeViewportTransformation = function(viewport, nearDepthRange, farDepthRange, result) {
  6286. if (!defined(result)) {
  6287. throw new DeveloperError('result is required');
  6288. }
  6289. viewport = defaultValue(viewport, defaultValue.EMPTY_OBJECT);
  6290. var x = defaultValue(viewport.x, 0.0);
  6291. var y = defaultValue(viewport.y, 0.0);
  6292. var width = defaultValue(viewport.width, 0.0);
  6293. var height = defaultValue(viewport.height, 0.0);
  6294. nearDepthRange = defaultValue(nearDepthRange, 0.0);
  6295. farDepthRange = defaultValue(farDepthRange, 1.0);
  6296. var halfWidth = width * 0.5;
  6297. var halfHeight = height * 0.5;
  6298. var halfDepth = (farDepthRange - nearDepthRange) * 0.5;
  6299. var column0Row0 = halfWidth;
  6300. var column1Row1 = halfHeight;
  6301. var column2Row2 = halfDepth;
  6302. var column3Row0 = x + halfWidth;
  6303. var column3Row1 = y + halfHeight;
  6304. var column3Row2 = nearDepthRange + halfDepth;
  6305. var column3Row3 = 1.0;
  6306. result[0] = column0Row0;
  6307. result[1] = 0.0;
  6308. result[2] = 0.0;
  6309. result[3] = 0.0;
  6310. result[4] = 0.0;
  6311. result[5] = column1Row1;
  6312. result[6] = 0.0;
  6313. result[7] = 0.0;
  6314. result[8] = 0.0;
  6315. result[9] = 0.0;
  6316. result[10] = column2Row2;
  6317. result[11] = 0.0;
  6318. result[12] = column3Row0;
  6319. result[13] = column3Row1;
  6320. result[14] = column3Row2;
  6321. result[15] = column3Row3;
  6322. return result;
  6323. };
  6324. /**
  6325. * Computes a Matrix4 instance that transforms from world space to view space.
  6326. *
  6327. * @param {Cartesian3} position The position of the camera.
  6328. * @param {Cartesian3} direction The forward direction.
  6329. * @param {Cartesian3} up The up direction.
  6330. * @param {Cartesian3} right The right direction.
  6331. * @param {Matrix4} result The object in which the result will be stored.
  6332. * @returns {Matrix4} The modified result parameter.
  6333. */
  6334. Matrix4.computeView = function(position, direction, up, right, result) {
  6335. if (!defined(position)) {
  6336. throw new DeveloperError('position is required');
  6337. }
  6338. if (!defined(direction)) {
  6339. throw new DeveloperError('direction is required');
  6340. }
  6341. if (!defined(up)) {
  6342. throw new DeveloperError('up is required');
  6343. }
  6344. if (!defined(right)) {
  6345. throw new DeveloperError('right is required');
  6346. }
  6347. if (!defined(result)) {
  6348. throw new DeveloperError('result is required');
  6349. }
  6350. result[0] = right.x;
  6351. result[1] = up.x;
  6352. result[2] = -direction.x;
  6353. result[3] = 0.0;
  6354. result[4] = right.y;
  6355. result[5] = up.y;
  6356. result[6] = -direction.y;
  6357. result[7] = 0.0;
  6358. result[8] = right.z;
  6359. result[9] = up.z;
  6360. result[10] = -direction.z;
  6361. result[11] = 0.0;
  6362. result[12] = -Cartesian3.dot(right, position);
  6363. result[13] = -Cartesian3.dot(up, position);
  6364. result[14] = Cartesian3.dot(direction, position);
  6365. result[15] = 1.0;
  6366. return result;
  6367. };
  6368. /**
  6369. * Computes an Array from the provided Matrix4 instance.
  6370. * The array will be in column-major order.
  6371. *
  6372. * @param {Matrix4} matrix The matrix to use..
  6373. * @param {Number[]} [result] The Array onto which to store the result.
  6374. * @returns {Number[]} The modified Array parameter or a new Array instance if one was not provided.
  6375. *
  6376. * @example
  6377. * //create an array from an instance of Matrix4
  6378. * // m = [10.0, 14.0, 18.0, 22.0]
  6379. * // [11.0, 15.0, 19.0, 23.0]
  6380. * // [12.0, 16.0, 20.0, 24.0]
  6381. * // [13.0, 17.0, 21.0, 25.0]
  6382. * var a = Cesium.Matrix4.toArray(m);
  6383. *
  6384. * // m remains the same
  6385. * //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]
  6386. */
  6387. Matrix4.toArray = function(matrix, result) {
  6388. if (!defined(matrix)) {
  6389. throw new DeveloperError('matrix is required');
  6390. }
  6391. if (!defined(result)) {
  6392. return [matrix[0], matrix[1], matrix[2], matrix[3],
  6393. matrix[4], matrix[5], matrix[6], matrix[7],
  6394. matrix[8], matrix[9], matrix[10], matrix[11],
  6395. matrix[12], matrix[13], matrix[14], matrix[15]];
  6396. }
  6397. result[0] = matrix[0];
  6398. result[1] = matrix[1];
  6399. result[2] = matrix[2];
  6400. result[3] = matrix[3];
  6401. result[4] = matrix[4];
  6402. result[5] = matrix[5];
  6403. result[6] = matrix[6];
  6404. result[7] = matrix[7];
  6405. result[8] = matrix[8];
  6406. result[9] = matrix[9];
  6407. result[10] = matrix[10];
  6408. result[11] = matrix[11];
  6409. result[12] = matrix[12];
  6410. result[13] = matrix[13];
  6411. result[14] = matrix[14];
  6412. result[15] = matrix[15];
  6413. return result;
  6414. };
  6415. /**
  6416. * Computes the array index of the element at the provided row and column.
  6417. *
  6418. * @param {Number} row The zero-based index of the row.
  6419. * @param {Number} column The zero-based index of the column.
  6420. * @returns {Number} The index of the element at the provided row and column.
  6421. *
  6422. * @exception {DeveloperError} row must be 0, 1, 2, or 3.
  6423. * @exception {DeveloperError} column must be 0, 1, 2, or 3.
  6424. *
  6425. * @example
  6426. * var myMatrix = new Cesium.Matrix4();
  6427. * var column1Row0Index = Cesium.Matrix4.getElementIndex(1, 0);
  6428. * var column1Row0 = myMatrix[column1Row0Index];
  6429. * myMatrix[column1Row0Index] = 10.0;
  6430. */
  6431. Matrix4.getElementIndex = function(column, row) {
  6432. if (typeof row !== 'number' || row < 0 || row > 3) {
  6433. throw new DeveloperError('row must be 0, 1, 2, or 3.');
  6434. }
  6435. if (typeof column !== 'number' || column < 0 || column > 3) {
  6436. throw new DeveloperError('column must be 0, 1, 2, or 3.');
  6437. }
  6438. return column * 4 + row;
  6439. };
  6440. /**
  6441. * Retrieves a copy of the matrix column at the provided index as a Cartesian4 instance.
  6442. *
  6443. * @param {Matrix4} matrix The matrix to use.
  6444. * @param {Number} index The zero-based index of the column to retrieve.
  6445. * @param {Cartesian4} result The object onto which to store the result.
  6446. * @returns {Cartesian4} The modified result parameter.
  6447. *
  6448. * @exception {DeveloperError} index must be 0, 1, 2, or 3.
  6449. *
  6450. * @example
  6451. * //returns a Cartesian4 instance with values from the specified column
  6452. * // m = [10.0, 11.0, 12.0, 13.0]
  6453. * // [14.0, 15.0, 16.0, 17.0]
  6454. * // [18.0, 19.0, 20.0, 21.0]
  6455. * // [22.0, 23.0, 24.0, 25.0]
  6456. *
  6457. * //Example 1: Creates an instance of Cartesian
  6458. * var a = Cesium.Matrix4.getColumn(m, 2, new Cesium.Cartesian4());
  6459. *
  6460. * @example
  6461. * //Example 2: Sets values for Cartesian instance
  6462. * var a = new Cesium.Cartesian4();
  6463. * Cesium.Matrix4.getColumn(m, 2, a);
  6464. *
  6465. * // a.x = 12.0; a.y = 16.0; a.z = 20.0; a.w = 24.0;
  6466. */
  6467. Matrix4.getColumn = function(matrix, index, result) {
  6468. if (!defined(matrix)) {
  6469. throw new DeveloperError('matrix is required.');
  6470. }
  6471. if (typeof index !== 'number' || index < 0 || index > 3) {
  6472. throw new DeveloperError('index must be 0, 1, 2, or 3.');
  6473. }
  6474. if (!defined(result)) {
  6475. throw new DeveloperError('result is required');
  6476. }
  6477. var startIndex = index * 4;
  6478. var x = matrix[startIndex];
  6479. var y = matrix[startIndex + 1];
  6480. var z = matrix[startIndex + 2];
  6481. var w = matrix[startIndex + 3];
  6482. result.x = x;
  6483. result.y = y;
  6484. result.z = z;
  6485. result.w = w;
  6486. return result;
  6487. };
  6488. /**
  6489. * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian4 instance.
  6490. *
  6491. * @param {Matrix4} matrix The matrix to use.
  6492. * @param {Number} index The zero-based index of the column to set.
  6493. * @param {Cartesian4} cartesian The Cartesian whose values will be assigned to the specified column.
  6494. * @param {Matrix4} result The object onto which to store the result.
  6495. * @returns {Matrix4} The modified result parameter.
  6496. *
  6497. * @exception {DeveloperError} index must be 0, 1, 2, or 3.
  6498. *
  6499. * @example
  6500. * //creates a new Matrix4 instance with new column values from the Cartesian4 instance
  6501. * // m = [10.0, 11.0, 12.0, 13.0]
  6502. * // [14.0, 15.0, 16.0, 17.0]
  6503. * // [18.0, 19.0, 20.0, 21.0]
  6504. * // [22.0, 23.0, 24.0, 25.0]
  6505. *
  6506. * var a = Cesium.Matrix4.setColumn(m, 2, new Cesium.Cartesian4(99.0, 98.0, 97.0, 96.0), new Cesium.Matrix4());
  6507. *
  6508. * // m remains the same
  6509. * // a = [10.0, 11.0, 99.0, 13.0]
  6510. * // [14.0, 15.0, 98.0, 17.0]
  6511. * // [18.0, 19.0, 97.0, 21.0]
  6512. * // [22.0, 23.0, 96.0, 25.0]
  6513. */
  6514. Matrix4.setColumn = function(matrix, index, cartesian, result) {
  6515. if (!defined(matrix)) {
  6516. throw new DeveloperError('matrix is required');
  6517. }
  6518. if (!defined(cartesian)) {
  6519. throw new DeveloperError('cartesian is required');
  6520. }
  6521. if (typeof index !== 'number' || index < 0 || index > 3) {
  6522. throw new DeveloperError('index must be 0, 1, 2, or 3.');
  6523. }
  6524. if (!defined(result)) {
  6525. throw new DeveloperError('result is required');
  6526. }
  6527. result = Matrix4.clone(matrix, result);
  6528. var startIndex = index * 4;
  6529. result[startIndex] = cartesian.x;
  6530. result[startIndex + 1] = cartesian.y;
  6531. result[startIndex + 2] = cartesian.z;
  6532. result[startIndex + 3] = cartesian.w;
  6533. return result;
  6534. };
  6535. /**
  6536. * Computes a new matrix that replaces the translation in the rightmost column of the provided
  6537. * matrix with the provided translation. This assumes the matrix is an affine transformation
  6538. *
  6539. * @param {Matrix4} matrix The matrix to use.
  6540. * @param {Cartesian3} translation The translation that replaces the translation of the provided matrix.
  6541. * @param {Cartesian4} result The object onto which to store the result.
  6542. * @returns {Matrix4} The modified result parameter.
  6543. */
  6544. Matrix4.setTranslation = function(matrix, translation, result) {
  6545. if (!defined(matrix)) {
  6546. throw new DeveloperError('matrix is required');
  6547. }
  6548. if (!defined(translation)) {
  6549. throw new DeveloperError('translation is required');
  6550. }
  6551. if (!defined(result)) {
  6552. throw new DeveloperError('result is required');
  6553. }
  6554. result[0] = matrix[0];
  6555. result[1] = matrix[1];
  6556. result[2] = matrix[2];
  6557. result[3] = matrix[3];
  6558. result[4] = matrix[4];
  6559. result[5] = matrix[5];
  6560. result[6] = matrix[6];
  6561. result[7] = matrix[7];
  6562. result[8] = matrix[8];
  6563. result[9] = matrix[9];
  6564. result[10] = matrix[10];
  6565. result[11] = matrix[11];
  6566. result[12] = translation.x;
  6567. result[13] = translation.y;
  6568. result[14] = translation.z;
  6569. result[15] = matrix[15];
  6570. return result;
  6571. };
  6572. /**
  6573. * Retrieves a copy of the matrix row at the provided index as a Cartesian4 instance.
  6574. *
  6575. * @param {Matrix4} matrix The matrix to use.
  6576. * @param {Number} index The zero-based index of the row to retrieve.
  6577. * @param {Cartesian4} result The object onto which to store the result.
  6578. * @returns {Cartesian4} The modified result parameter.
  6579. *
  6580. * @exception {DeveloperError} index must be 0, 1, 2, or 3.
  6581. *
  6582. * @example
  6583. * //returns a Cartesian4 instance with values from the specified column
  6584. * // m = [10.0, 11.0, 12.0, 13.0]
  6585. * // [14.0, 15.0, 16.0, 17.0]
  6586. * // [18.0, 19.0, 20.0, 21.0]
  6587. * // [22.0, 23.0, 24.0, 25.0]
  6588. *
  6589. * //Example 1: Returns an instance of Cartesian
  6590. * var a = Cesium.Matrix4.getRow(m, 2, new Cesium.Cartesian4());
  6591. *
  6592. * @example
  6593. * //Example 2: Sets values for a Cartesian instance
  6594. * var a = new Cesium.Cartesian4();
  6595. * Cesium.Matrix4.getRow(m, 2, a);
  6596. *
  6597. * // a.x = 18.0; a.y = 19.0; a.z = 20.0; a.w = 21.0;
  6598. */
  6599. Matrix4.getRow = function(matrix, index, result) {
  6600. if (!defined(matrix)) {
  6601. throw new DeveloperError('matrix is required.');
  6602. }
  6603. if (typeof index !== 'number' || index < 0 || index > 3) {
  6604. throw new DeveloperError('index must be 0, 1, 2, or 3.');
  6605. }
  6606. if (!defined(result)) {
  6607. throw new DeveloperError('result is required');
  6608. }
  6609. var x = matrix[index];
  6610. var y = matrix[index + 4];
  6611. var z = matrix[index + 8];
  6612. var w = matrix[index + 12];
  6613. result.x = x;
  6614. result.y = y;
  6615. result.z = z;
  6616. result.w = w;
  6617. return result;
  6618. };
  6619. /**
  6620. * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian4 instance.
  6621. *
  6622. * @param {Matrix4} matrix The matrix to use.
  6623. * @param {Number} index The zero-based index of the row to set.
  6624. * @param {Cartesian4} cartesian The Cartesian whose values will be assigned to the specified row.
  6625. * @param {Matrix4} result The object onto which to store the result.
  6626. * @returns {Matrix4} The modified result parameter.
  6627. *
  6628. * @exception {DeveloperError} index must be 0, 1, 2, or 3.
  6629. *
  6630. * @example
  6631. * //create a new Matrix4 instance with new row values from the Cartesian4 instance
  6632. * // m = [10.0, 11.0, 12.0, 13.0]
  6633. * // [14.0, 15.0, 16.0, 17.0]
  6634. * // [18.0, 19.0, 20.0, 21.0]
  6635. * // [22.0, 23.0, 24.0, 25.0]
  6636. *
  6637. * var a = Cesium.Matrix4.setRow(m, 2, new Cesium.Cartesian4(99.0, 98.0, 97.0, 96.0), new Cesium.Matrix4());
  6638. *
  6639. * // m remains the same
  6640. * // a = [10.0, 11.0, 12.0, 13.0]
  6641. * // [14.0, 15.0, 16.0, 17.0]
  6642. * // [99.0, 98.0, 97.0, 96.0]
  6643. * // [22.0, 23.0, 24.0, 25.0]
  6644. */
  6645. Matrix4.setRow = function(matrix, index, cartesian, result) {
  6646. if (!defined(matrix)) {
  6647. throw new DeveloperError('matrix is required');
  6648. }
  6649. if (!defined(cartesian)) {
  6650. throw new DeveloperError('cartesian is required');
  6651. }
  6652. if (typeof index !== 'number' || index < 0 || index > 3) {
  6653. throw new DeveloperError('index must be 0, 1, 2, or 3.');
  6654. }
  6655. if (!defined(result)) {
  6656. throw new DeveloperError('result is required');
  6657. }
  6658. result = Matrix4.clone(matrix, result);
  6659. result[index] = cartesian.x;
  6660. result[index + 4] = cartesian.y;
  6661. result[index + 8] = cartesian.z;
  6662. result[index + 12] = cartesian.w;
  6663. return result;
  6664. };
  6665. var scratchColumn = new Cartesian3();
  6666. /**
  6667. * Extracts the non-uniform scale assuming the matrix is an affine transformation.
  6668. *
  6669. * @param {Matrix4} matrix The matrix.
  6670. * @param {Cartesian3} result The object onto which to store the result.
  6671. * @returns {Cartesian3} The modified result parameter
  6672. */
  6673. Matrix4.getScale = function(matrix, result) {
  6674. if (!defined(matrix)) {
  6675. throw new DeveloperError('matrix is required.');
  6676. }
  6677. if (!defined(result)) {
  6678. throw new DeveloperError('result is required');
  6679. }
  6680. result.x = Cartesian3.magnitude(Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn));
  6681. result.y = Cartesian3.magnitude(Cartesian3.fromElements(matrix[4], matrix[5], matrix[6], scratchColumn));
  6682. result.z = Cartesian3.magnitude(Cartesian3.fromElements(matrix[8], matrix[9], matrix[10], scratchColumn));
  6683. return result;
  6684. };
  6685. var scratchScale = new Cartesian3();
  6686. /**
  6687. * Computes the maximum scale assuming the matrix is an affine transformation.
  6688. * The maximum scale is the maximum length of the column vectors in the upper-left
  6689. * 3x3 matrix.
  6690. *
  6691. * @param {Matrix4} matrix The matrix.
  6692. * @returns {Number} The maximum scale.
  6693. */
  6694. Matrix4.getMaximumScale = function(matrix) {
  6695. Matrix4.getScale(matrix, scratchScale);
  6696. return Cartesian3.maximumComponent(scratchScale);
  6697. };
  6698. /**
  6699. * Computes the product of two matrices.
  6700. *
  6701. * @param {Matrix4} left The first matrix.
  6702. * @param {Matrix4} right The second matrix.
  6703. * @param {Matrix4} result The object onto which to store the result.
  6704. * @returns {Matrix4} The modified result parameter.
  6705. */
  6706. Matrix4.multiply = function(left, right, result) {
  6707. if (!defined(left)) {
  6708. throw new DeveloperError('left is required');
  6709. }
  6710. if (!defined(right)) {
  6711. throw new DeveloperError('right is required');
  6712. }
  6713. if (!defined(result)) {
  6714. throw new DeveloperError('result is required');
  6715. }
  6716. var left0 = left[0];
  6717. var left1 = left[1];
  6718. var left2 = left[2];
  6719. var left3 = left[3];
  6720. var left4 = left[4];
  6721. var left5 = left[5];
  6722. var left6 = left[6];
  6723. var left7 = left[7];
  6724. var left8 = left[8];
  6725. var left9 = left[9];
  6726. var left10 = left[10];
  6727. var left11 = left[11];
  6728. var left12 = left[12];
  6729. var left13 = left[13];
  6730. var left14 = left[14];
  6731. var left15 = left[15];
  6732. var right0 = right[0];
  6733. var right1 = right[1];
  6734. var right2 = right[2];
  6735. var right3 = right[3];
  6736. var right4 = right[4];
  6737. var right5 = right[5];
  6738. var right6 = right[6];
  6739. var right7 = right[7];
  6740. var right8 = right[8];
  6741. var right9 = right[9];
  6742. var right10 = right[10];
  6743. var right11 = right[11];
  6744. var right12 = right[12];
  6745. var right13 = right[13];
  6746. var right14 = right[14];
  6747. var right15 = right[15];
  6748. var column0Row0 = left0 * right0 + left4 * right1 + left8 * right2 + left12 * right3;
  6749. var column0Row1 = left1 * right0 + left5 * right1 + left9 * right2 + left13 * right3;
  6750. var column0Row2 = left2 * right0 + left6 * right1 + left10 * right2 + left14 * right3;
  6751. var column0Row3 = left3 * right0 + left7 * right1 + left11 * right2 + left15 * right3;
  6752. var column1Row0 = left0 * right4 + left4 * right5 + left8 * right6 + left12 * right7;
  6753. var column1Row1 = left1 * right4 + left5 * right5 + left9 * right6 + left13 * right7;
  6754. var column1Row2 = left2 * right4 + left6 * right5 + left10 * right6 + left14 * right7;
  6755. var column1Row3 = left3 * right4 + left7 * right5 + left11 * right6 + left15 * right7;
  6756. var column2Row0 = left0 * right8 + left4 * right9 + left8 * right10 + left12 * right11;
  6757. var column2Row1 = left1 * right8 + left5 * right9 + left9 * right10 + left13 * right11;
  6758. var column2Row2 = left2 * right8 + left6 * right9 + left10 * right10 + left14 * right11;
  6759. var column2Row3 = left3 * right8 + left7 * right9 + left11 * right10 + left15 * right11;
  6760. var column3Row0 = left0 * right12 + left4 * right13 + left8 * right14 + left12 * right15;
  6761. var column3Row1 = left1 * right12 + left5 * right13 + left9 * right14 + left13 * right15;
  6762. var column3Row2 = left2 * right12 + left6 * right13 + left10 * right14 + left14 * right15;
  6763. var column3Row3 = left3 * right12 + left7 * right13 + left11 * right14 + left15 * right15;
  6764. result[0] = column0Row0;
  6765. result[1] = column0Row1;
  6766. result[2] = column0Row2;
  6767. result[3] = column0Row3;
  6768. result[4] = column1Row0;
  6769. result[5] = column1Row1;
  6770. result[6] = column1Row2;
  6771. result[7] = column1Row3;
  6772. result[8] = column2Row0;
  6773. result[9] = column2Row1;
  6774. result[10] = column2Row2;
  6775. result[11] = column2Row3;
  6776. result[12] = column3Row0;
  6777. result[13] = column3Row1;
  6778. result[14] = column3Row2;
  6779. result[15] = column3Row3;
  6780. return result;
  6781. };
  6782. /**
  6783. * Computes the sum of two matrices.
  6784. *
  6785. * @param {Matrix4} left The first matrix.
  6786. * @param {Matrix4} right The second matrix.
  6787. * @param {Matrix4} result The object onto which to store the result.
  6788. * @returns {Matrix4} The modified result parameter.
  6789. */
  6790. Matrix4.add = function(left, right, result) {
  6791. if (!defined(left)) {
  6792. throw new DeveloperError('left is required');
  6793. }
  6794. if (!defined(right)) {
  6795. throw new DeveloperError('right is required');
  6796. }
  6797. if (!defined(result)) {
  6798. throw new DeveloperError('result is required');
  6799. }
  6800. result[0] = left[0] + right[0];
  6801. result[1] = left[1] + right[1];
  6802. result[2] = left[2] + right[2];
  6803. result[3] = left[3] + right[3];
  6804. result[4] = left[4] + right[4];
  6805. result[5] = left[5] + right[5];
  6806. result[6] = left[6] + right[6];
  6807. result[7] = left[7] + right[7];
  6808. result[8] = left[8] + right[8];
  6809. result[9] = left[9] + right[9];
  6810. result[10] = left[10] + right[10];
  6811. result[11] = left[11] + right[11];
  6812. result[12] = left[12] + right[12];
  6813. result[13] = left[13] + right[13];
  6814. result[14] = left[14] + right[14];
  6815. result[15] = left[15] + right[15];
  6816. return result;
  6817. };
  6818. /**
  6819. * Computes the difference of two matrices.
  6820. *
  6821. * @param {Matrix4} left The first matrix.
  6822. * @param {Matrix4} right The second matrix.
  6823. * @param {Matrix4} result The object onto which to store the result.
  6824. * @returns {Matrix4} The modified result parameter.
  6825. */
  6826. Matrix4.subtract = function(left, right, result) {
  6827. if (!defined(left)) {
  6828. throw new DeveloperError('left is required');
  6829. }
  6830. if (!defined(right)) {
  6831. throw new DeveloperError('right is required');
  6832. }
  6833. if (!defined(result)) {
  6834. throw new DeveloperError('result is required');
  6835. }
  6836. result[0] = left[0] - right[0];
  6837. result[1] = left[1] - right[1];
  6838. result[2] = left[2] - right[2];
  6839. result[3] = left[3] - right[3];
  6840. result[4] = left[4] - right[4];
  6841. result[5] = left[5] - right[5];
  6842. result[6] = left[6] - right[6];
  6843. result[7] = left[7] - right[7];
  6844. result[8] = left[8] - right[8];
  6845. result[9] = left[9] - right[9];
  6846. result[10] = left[10] - right[10];
  6847. result[11] = left[11] - right[11];
  6848. result[12] = left[12] - right[12];
  6849. result[13] = left[13] - right[13];
  6850. result[14] = left[14] - right[14];
  6851. result[15] = left[15] - right[15];
  6852. return result;
  6853. };
  6854. /**
  6855. * Computes the product of two matrices assuming the matrices are
  6856. * affine transformation matrices, where the upper left 3x3 elements
  6857. * are a rotation matrix, and the upper three elements in the fourth
  6858. * column are the translation. The bottom row is assumed to be [0, 0, 0, 1].
  6859. * The matrix is not verified to be in the proper form.
  6860. * This method is faster than computing the product for general 4x4
  6861. * matrices using {@link Matrix4.multiply}.
  6862. *
  6863. * @param {Matrix4} left The first matrix.
  6864. * @param {Matrix4} right The second matrix.
  6865. * @param {Matrix4} result The object onto which to store the result.
  6866. * @returns {Matrix4} The modified result parameter.
  6867. *
  6868. * @example
  6869. * 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);
  6870. * var m2 = Cesium.Transforms.eastNorthUpToFixedFrame(new Cesium.Cartesian3(1.0, 1.0, 1.0));
  6871. * var m3 = Cesium.Matrix4.multiplyTransformation(m1, m2, new Cesium.Matrix4());
  6872. */
  6873. Matrix4.multiplyTransformation = function(left, right, result) {
  6874. if (!defined(left)) {
  6875. throw new DeveloperError('left is required');
  6876. }
  6877. if (!defined(right)) {
  6878. throw new DeveloperError('right is required');
  6879. }
  6880. if (!defined(result)) {
  6881. throw new DeveloperError('result is required');
  6882. }
  6883. var left0 = left[0];
  6884. var left1 = left[1];
  6885. var left2 = left[2];
  6886. var left4 = left[4];
  6887. var left5 = left[5];
  6888. var left6 = left[6];
  6889. var left8 = left[8];
  6890. var left9 = left[9];
  6891. var left10 = left[10];
  6892. var left12 = left[12];
  6893. var left13 = left[13];
  6894. var left14 = left[14];
  6895. var right0 = right[0];
  6896. var right1 = right[1];
  6897. var right2 = right[2];
  6898. var right4 = right[4];
  6899. var right5 = right[5];
  6900. var right6 = right[6];
  6901. var right8 = right[8];
  6902. var right9 = right[9];
  6903. var right10 = right[10];
  6904. var right12 = right[12];
  6905. var right13 = right[13];
  6906. var right14 = right[14];
  6907. var column0Row0 = left0 * right0 + left4 * right1 + left8 * right2;
  6908. var column0Row1 = left1 * right0 + left5 * right1 + left9 * right2;
  6909. var column0Row2 = left2 * right0 + left6 * right1 + left10 * right2;
  6910. var column1Row0 = left0 * right4 + left4 * right5 + left8 * right6;
  6911. var column1Row1 = left1 * right4 + left5 * right5 + left9 * right6;
  6912. var column1Row2 = left2 * right4 + left6 * right5 + left10 * right6;
  6913. var column2Row0 = left0 * right8 + left4 * right9 + left8 * right10;
  6914. var column2Row1 = left1 * right8 + left5 * right9 + left9 * right10;
  6915. var column2Row2 = left2 * right8 + left6 * right9 + left10 * right10;
  6916. var column3Row0 = left0 * right12 + left4 * right13 + left8 * right14 + left12;
  6917. var column3Row1 = left1 * right12 + left5 * right13 + left9 * right14 + left13;
  6918. var column3Row2 = left2 * right12 + left6 * right13 + left10 * right14 + left14;
  6919. result[0] = column0Row0;
  6920. result[1] = column0Row1;
  6921. result[2] = column0Row2;
  6922. result[3] = 0.0;
  6923. result[4] = column1Row0;
  6924. result[5] = column1Row1;
  6925. result[6] = column1Row2;
  6926. result[7] = 0.0;
  6927. result[8] = column2Row0;
  6928. result[9] = column2Row1;
  6929. result[10] = column2Row2;
  6930. result[11] = 0.0;
  6931. result[12] = column3Row0;
  6932. result[13] = column3Row1;
  6933. result[14] = column3Row2;
  6934. result[15] = 1.0;
  6935. return result;
  6936. };
  6937. /**
  6938. * Multiplies a transformation matrix (with a bottom row of <code>[0.0, 0.0, 0.0, 1.0]</code>)
  6939. * by a 3x3 rotation matrix. This is an optimization
  6940. * for <code>Matrix4.multiply(m, Matrix4.fromRotationTranslation(rotation), m);</code> with less allocations and arithmetic operations.
  6941. *
  6942. * @param {Matrix4} matrix The matrix on the left-hand side.
  6943. * @param {Matrix3} rotation The 3x3 rotation matrix on the right-hand side.
  6944. * @param {Matrix4} result The object onto which to store the result.
  6945. * @returns {Matrix4} The modified result parameter.
  6946. *
  6947. * @example
  6948. * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromRotationTranslation(rotation), m);
  6949. * Cesium.Matrix4.multiplyByMatrix3(m, rotation, m);
  6950. */
  6951. Matrix4.multiplyByMatrix3 = function(matrix, rotation, result) {
  6952. if (!defined(matrix)) {
  6953. throw new DeveloperError('matrix is required');
  6954. }
  6955. if (!defined(rotation)) {
  6956. throw new DeveloperError('rotation is required');
  6957. }
  6958. if (!defined(result)) {
  6959. throw new DeveloperError('result is required');
  6960. }
  6961. var left0 = matrix[0];
  6962. var left1 = matrix[1];
  6963. var left2 = matrix[2];
  6964. var left4 = matrix[4];
  6965. var left5 = matrix[5];
  6966. var left6 = matrix[6];
  6967. var left8 = matrix[8];
  6968. var left9 = matrix[9];
  6969. var left10 = matrix[10];
  6970. var right0 = rotation[0];
  6971. var right1 = rotation[1];
  6972. var right2 = rotation[2];
  6973. var right4 = rotation[3];
  6974. var right5 = rotation[4];
  6975. var right6 = rotation[5];
  6976. var right8 = rotation[6];
  6977. var right9 = rotation[7];
  6978. var right10 = rotation[8];
  6979. var column0Row0 = left0 * right0 + left4 * right1 + left8 * right2;
  6980. var column0Row1 = left1 * right0 + left5 * right1 + left9 * right2;
  6981. var column0Row2 = left2 * right0 + left6 * right1 + left10 * right2;
  6982. var column1Row0 = left0 * right4 + left4 * right5 + left8 * right6;
  6983. var column1Row1 = left1 * right4 + left5 * right5 + left9 * right6;
  6984. var column1Row2 = left2 * right4 + left6 * right5 + left10 * right6;
  6985. var column2Row0 = left0 * right8 + left4 * right9 + left8 * right10;
  6986. var column2Row1 = left1 * right8 + left5 * right9 + left9 * right10;
  6987. var column2Row2 = left2 * right8 + left6 * right9 + left10 * right10;
  6988. result[0] = column0Row0;
  6989. result[1] = column0Row1;
  6990. result[2] = column0Row2;
  6991. result[3] = 0.0;
  6992. result[4] = column1Row0;
  6993. result[5] = column1Row1;
  6994. result[6] = column1Row2;
  6995. result[7] = 0.0;
  6996. result[8] = column2Row0;
  6997. result[9] = column2Row1;
  6998. result[10] = column2Row2;
  6999. result[11] = 0.0;
  7000. result[12] = matrix[12];
  7001. result[13] = matrix[13];
  7002. result[14] = matrix[14];
  7003. result[15] = matrix[15];
  7004. return result;
  7005. };
  7006. /**
  7007. * Multiplies a transformation matrix (with a bottom row of <code>[0.0, 0.0, 0.0, 1.0]</code>)
  7008. * by an implicit translation matrix defined by a {@link Cartesian3}. This is an optimization
  7009. * for <code>Matrix4.multiply(m, Matrix4.fromTranslation(position), m);</code> with less allocations and arithmetic operations.
  7010. *
  7011. * @param {Matrix4} matrix The matrix on the left-hand side.
  7012. * @param {Cartesian3} translation The translation on the right-hand side.
  7013. * @param {Matrix4} result The object onto which to store the result.
  7014. * @returns {Matrix4} The modified result parameter.
  7015. *
  7016. * @example
  7017. * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromTranslation(position), m);
  7018. * Cesium.Matrix4.multiplyByTranslation(m, position, m);
  7019. */
  7020. Matrix4.multiplyByTranslation = function(matrix, translation, result) {
  7021. if (!defined(matrix)) {
  7022. throw new DeveloperError('matrix is required');
  7023. }
  7024. if (!defined(translation)) {
  7025. throw new DeveloperError('translation is required');
  7026. }
  7027. if (!defined(result)) {
  7028. throw new DeveloperError('result is required');
  7029. }
  7030. var x = translation.x;
  7031. var y = translation.y;
  7032. var z = translation.z;
  7033. var tx = (x * matrix[0]) + (y * matrix[4]) + (z * matrix[8]) + matrix[12];
  7034. var ty = (x * matrix[1]) + (y * matrix[5]) + (z * matrix[9]) + matrix[13];
  7035. var tz = (x * matrix[2]) + (y * matrix[6]) + (z * matrix[10]) + matrix[14];
  7036. result[0] = matrix[0];
  7037. result[1] = matrix[1];
  7038. result[2] = matrix[2];
  7039. result[3] = matrix[3];
  7040. result[4] = matrix[4];
  7041. result[5] = matrix[5];
  7042. result[6] = matrix[6];
  7043. result[7] = matrix[7];
  7044. result[8] = matrix[8];
  7045. result[9] = matrix[9];
  7046. result[10] = matrix[10];
  7047. result[11] = matrix[11];
  7048. result[12] = tx;
  7049. result[13] = ty;
  7050. result[14] = tz;
  7051. result[15] = matrix[15];
  7052. return result;
  7053. };
  7054. var uniformScaleScratch = new Cartesian3();
  7055. /**
  7056. * Multiplies an affine transformation matrix (with a bottom row of <code>[0.0, 0.0, 0.0, 1.0]</code>)
  7057. * by an implicit uniform scale matrix. This is an optimization
  7058. * for <code>Matrix4.multiply(m, Matrix4.fromUniformScale(scale), m);</code>, where
  7059. * <code>m</code> must be an affine matrix.
  7060. * This function performs fewer allocations and arithmetic operations.
  7061. *
  7062. * @param {Matrix4} matrix The affine matrix on the left-hand side.
  7063. * @param {Number} scale The uniform scale on the right-hand side.
  7064. * @param {Matrix4} result The object onto which to store the result.
  7065. * @returns {Matrix4} The modified result parameter.
  7066. *
  7067. *
  7068. * @example
  7069. * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromUniformScale(scale), m);
  7070. * Cesium.Matrix4.multiplyByUniformScale(m, scale, m);
  7071. *
  7072. * @see Matrix4.fromUniformScale
  7073. * @see Matrix4.multiplyByScale
  7074. */
  7075. Matrix4.multiplyByUniformScale = function(matrix, scale, result) {
  7076. if (!defined(matrix)) {
  7077. throw new DeveloperError('matrix is required');
  7078. }
  7079. if (typeof scale !== 'number') {
  7080. throw new DeveloperError('scale is required');
  7081. }
  7082. if (!defined(result)) {
  7083. throw new DeveloperError('result is required');
  7084. }
  7085. uniformScaleScratch.x = scale;
  7086. uniformScaleScratch.y = scale;
  7087. uniformScaleScratch.z = scale;
  7088. return Matrix4.multiplyByScale(matrix, uniformScaleScratch, result);
  7089. };
  7090. /**
  7091. * Multiplies an affine transformation matrix (with a bottom row of <code>[0.0, 0.0, 0.0, 1.0]</code>)
  7092. * by an implicit non-uniform scale matrix. This is an optimization
  7093. * for <code>Matrix4.multiply(m, Matrix4.fromUniformScale(scale), m);</code>, where
  7094. * <code>m</code> must be an affine matrix.
  7095. * This function performs fewer allocations and arithmetic operations.
  7096. *
  7097. * @param {Matrix4} matrix The affine matrix on the left-hand side.
  7098. * @param {Cartesian3} scale The non-uniform scale on the right-hand side.
  7099. * @param {Matrix4} result The object onto which to store the result.
  7100. * @returns {Matrix4} The modified result parameter.
  7101. *
  7102. *
  7103. * @example
  7104. * // Instead of Cesium.Matrix4.multiply(m, Cesium.Matrix4.fromScale(scale), m);
  7105. * Cesium.Matrix4.multiplyByScale(m, scale, m);
  7106. *
  7107. * @see Matrix4.fromScale
  7108. * @see Matrix4.multiplyByUniformScale
  7109. */
  7110. Matrix4.multiplyByScale = function(matrix, scale, result) {
  7111. if (!defined(matrix)) {
  7112. throw new DeveloperError('matrix is required');
  7113. }
  7114. if (!defined(scale)) {
  7115. throw new DeveloperError('scale is required');
  7116. }
  7117. if (!defined(result)) {
  7118. throw new DeveloperError('result is required');
  7119. }
  7120. var scaleX = scale.x;
  7121. var scaleY = scale.y;
  7122. var scaleZ = scale.z;
  7123. // Faster than Cartesian3.equals
  7124. if ((scaleX === 1.0) && (scaleY === 1.0) && (scaleZ === 1.0)) {
  7125. return Matrix4.clone(matrix, result);
  7126. }
  7127. result[0] = scaleX * matrix[0];
  7128. result[1] = scaleX * matrix[1];
  7129. result[2] = scaleX * matrix[2];
  7130. result[3] = 0.0;
  7131. result[4] = scaleY * matrix[4];
  7132. result[5] = scaleY * matrix[5];
  7133. result[6] = scaleY * matrix[6];
  7134. result[7] = 0.0;
  7135. result[8] = scaleZ * matrix[8];
  7136. result[9] = scaleZ * matrix[9];
  7137. result[10] = scaleZ * matrix[10];
  7138. result[11] = 0.0;
  7139. result[12] = matrix[12];
  7140. result[13] = matrix[13];
  7141. result[14] = matrix[14];
  7142. result[15] = 1.0;
  7143. return result;
  7144. };
  7145. /**
  7146. * Computes the product of a matrix and a column vector.
  7147. *
  7148. * @param {Matrix4} matrix The matrix.
  7149. * @param {Cartesian4} cartesian The vector.
  7150. * @param {Cartesian4} result The object onto which to store the result.
  7151. * @returns {Cartesian4} The modified result parameter.
  7152. */
  7153. Matrix4.multiplyByVector = function(matrix, cartesian, result) {
  7154. if (!defined(matrix)) {
  7155. throw new DeveloperError('matrix is required');
  7156. }
  7157. if (!defined(cartesian)) {
  7158. throw new DeveloperError('cartesian is required');
  7159. }
  7160. if (!defined(result)) {
  7161. throw new DeveloperError('result is required');
  7162. }
  7163. var vX = cartesian.x;
  7164. var vY = cartesian.y;
  7165. var vZ = cartesian.z;
  7166. var vW = cartesian.w;
  7167. var x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ + matrix[12] * vW;
  7168. var y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ + matrix[13] * vW;
  7169. var z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ + matrix[14] * vW;
  7170. var w = matrix[3] * vX + matrix[7] * vY + matrix[11] * vZ + matrix[15] * vW;
  7171. result.x = x;
  7172. result.y = y;
  7173. result.z = z;
  7174. result.w = w;
  7175. return result;
  7176. };
  7177. /**
  7178. * Computes the product of a matrix and a {@link Cartesian3}. This is equivalent to calling {@link Matrix4.multiplyByVector}
  7179. * with a {@link Cartesian4} with a <code>w</code> component of zero.
  7180. *
  7181. * @param {Matrix4} matrix The matrix.
  7182. * @param {Cartesian3} cartesian The point.
  7183. * @param {Cartesian3} result The object onto which to store the result.
  7184. * @returns {Cartesian3} The modified result parameter.
  7185. *
  7186. * @example
  7187. * var p = new Cesium.Cartesian3(1.0, 2.0, 3.0);
  7188. * var result = Cesium.Matrix4.multiplyByPointAsVector(matrix, p, new Cesium.Cartesian3());
  7189. * // A shortcut for
  7190. * // Cartesian3 p = ...
  7191. * // Cesium.Matrix4.multiplyByVector(matrix, new Cesium.Cartesian4(p.x, p.y, p.z, 0.0), result);
  7192. */
  7193. Matrix4.multiplyByPointAsVector = function(matrix, cartesian, result) {
  7194. if (!defined(matrix)) {
  7195. throw new DeveloperError('matrix is required');
  7196. }
  7197. if (!defined(cartesian)) {
  7198. throw new DeveloperError('cartesian is required');
  7199. }
  7200. if (!defined(result)) {
  7201. throw new DeveloperError('result is required');
  7202. }
  7203. var vX = cartesian.x;
  7204. var vY = cartesian.y;
  7205. var vZ = cartesian.z;
  7206. var x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ;
  7207. var y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ;
  7208. var z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ;
  7209. result.x = x;
  7210. result.y = y;
  7211. result.z = z;
  7212. return result;
  7213. };
  7214. /**
  7215. * Computes the product of a matrix and a {@link Cartesian3}. This is equivalent to calling {@link Matrix4.multiplyByVector}
  7216. * with a {@link Cartesian4} with a <code>w</code> component of 1, but returns a {@link Cartesian3} instead of a {@link Cartesian4}.
  7217. *
  7218. * @param {Matrix4} matrix The matrix.
  7219. * @param {Cartesian3} cartesian The point.
  7220. * @param {Cartesian3} result The object onto which to store the result.
  7221. * @returns {Cartesian3} The modified result parameter.
  7222. *
  7223. * @example
  7224. * var p = new Cesium.Cartesian3(1.0, 2.0, 3.0);
  7225. * var result = Cesium.Matrix4.multiplyByPoint(matrix, p, new Cesium.Cartesian3());
  7226. */
  7227. Matrix4.multiplyByPoint = function(matrix, cartesian, result) {
  7228. if (!defined(matrix)) {
  7229. throw new DeveloperError('matrix is required');
  7230. }
  7231. if (!defined(cartesian)) {
  7232. throw new DeveloperError('cartesian is required');
  7233. }
  7234. if (!defined(result)) {
  7235. throw new DeveloperError('result is required');
  7236. }
  7237. var vX = cartesian.x;
  7238. var vY = cartesian.y;
  7239. var vZ = cartesian.z;
  7240. var x = matrix[0] * vX + matrix[4] * vY + matrix[8] * vZ + matrix[12];
  7241. var y = matrix[1] * vX + matrix[5] * vY + matrix[9] * vZ + matrix[13];
  7242. var z = matrix[2] * vX + matrix[6] * vY + matrix[10] * vZ + matrix[14];
  7243. result.x = x;
  7244. result.y = y;
  7245. result.z = z;
  7246. return result;
  7247. };
  7248. /**
  7249. * Computes the product of a matrix and a scalar.
  7250. *
  7251. * @param {Matrix4} matrix The matrix.
  7252. * @param {Number} scalar The number to multiply by.
  7253. * @param {Matrix4} result The object onto which to store the result.
  7254. * @returns {Matrix4} The modified result parameter.
  7255. *
  7256. * @example
  7257. * //create a Matrix4 instance which is a scaled version of the supplied Matrix4
  7258. * // m = [10.0, 11.0, 12.0, 13.0]
  7259. * // [14.0, 15.0, 16.0, 17.0]
  7260. * // [18.0, 19.0, 20.0, 21.0]
  7261. * // [22.0, 23.0, 24.0, 25.0]
  7262. *
  7263. * var a = Cesium.Matrix4.multiplyByScalar(m, -2, new Cesium.Matrix4());
  7264. *
  7265. * // m remains the same
  7266. * // a = [-20.0, -22.0, -24.0, -26.0]
  7267. * // [-28.0, -30.0, -32.0, -34.0]
  7268. * // [-36.0, -38.0, -40.0, -42.0]
  7269. * // [-44.0, -46.0, -48.0, -50.0]
  7270. */
  7271. Matrix4.multiplyByScalar = function(matrix, scalar, result) {
  7272. if (!defined(matrix)) {
  7273. throw new DeveloperError('matrix is required');
  7274. }
  7275. if (typeof scalar !== 'number') {
  7276. throw new DeveloperError('scalar must be a number');
  7277. }
  7278. if (!defined(result)) {
  7279. throw new DeveloperError('result is required');
  7280. }
  7281. result[0] = matrix[0] * scalar;
  7282. result[1] = matrix[1] * scalar;
  7283. result[2] = matrix[2] * scalar;
  7284. result[3] = matrix[3] * scalar;
  7285. result[4] = matrix[4] * scalar;
  7286. result[5] = matrix[5] * scalar;
  7287. result[6] = matrix[6] * scalar;
  7288. result[7] = matrix[7] * scalar;
  7289. result[8] = matrix[8] * scalar;
  7290. result[9] = matrix[9] * scalar;
  7291. result[10] = matrix[10] * scalar;
  7292. result[11] = matrix[11] * scalar;
  7293. result[12] = matrix[12] * scalar;
  7294. result[13] = matrix[13] * scalar;
  7295. result[14] = matrix[14] * scalar;
  7296. result[15] = matrix[15] * scalar;
  7297. return result;
  7298. };
  7299. /**
  7300. * Computes a negated copy of the provided matrix.
  7301. *
  7302. * @param {Matrix4} matrix The matrix to negate.
  7303. * @param {Matrix4} result The object onto which to store the result.
  7304. * @returns {Matrix4} The modified result parameter.
  7305. *
  7306. * @example
  7307. * //create a new Matrix4 instance which is a negation of a Matrix4
  7308. * // m = [10.0, 11.0, 12.0, 13.0]
  7309. * // [14.0, 15.0, 16.0, 17.0]
  7310. * // [18.0, 19.0, 20.0, 21.0]
  7311. * // [22.0, 23.0, 24.0, 25.0]
  7312. *
  7313. * var a = Cesium.Matrix4.negate(m, new Cesium.Matrix4());
  7314. *
  7315. * // m remains the same
  7316. * // a = [-10.0, -11.0, -12.0, -13.0]
  7317. * // [-14.0, -15.0, -16.0, -17.0]
  7318. * // [-18.0, -19.0, -20.0, -21.0]
  7319. * // [-22.0, -23.0, -24.0, -25.0]
  7320. */
  7321. Matrix4.negate = function(matrix, result) {
  7322. if (!defined(matrix)) {
  7323. throw new DeveloperError('matrix is required');
  7324. }
  7325. if (!defined(result)) {
  7326. throw new DeveloperError('result is required');
  7327. }
  7328. result[0] = -matrix[0];
  7329. result[1] = -matrix[1];
  7330. result[2] = -matrix[2];
  7331. result[3] = -matrix[3];
  7332. result[4] = -matrix[4];
  7333. result[5] = -matrix[5];
  7334. result[6] = -matrix[6];
  7335. result[7] = -matrix[7];
  7336. result[8] = -matrix[8];
  7337. result[9] = -matrix[9];
  7338. result[10] = -matrix[10];
  7339. result[11] = -matrix[11];
  7340. result[12] = -matrix[12];
  7341. result[13] = -matrix[13];
  7342. result[14] = -matrix[14];
  7343. result[15] = -matrix[15];
  7344. return result;
  7345. };
  7346. /**
  7347. * Computes the transpose of the provided matrix.
  7348. *
  7349. * @param {Matrix4} matrix The matrix to transpose.
  7350. * @param {Matrix4} result The object onto which to store the result.
  7351. * @returns {Matrix4} The modified result parameter.
  7352. *
  7353. * @example
  7354. * //returns transpose of a Matrix4
  7355. * // m = [10.0, 11.0, 12.0, 13.0]
  7356. * // [14.0, 15.0, 16.0, 17.0]
  7357. * // [18.0, 19.0, 20.0, 21.0]
  7358. * // [22.0, 23.0, 24.0, 25.0]
  7359. *
  7360. * var a = Cesium.Matrix4.transpose(m, new Cesium.Matrix4());
  7361. *
  7362. * // m remains the same
  7363. * // a = [10.0, 14.0, 18.0, 22.0]
  7364. * // [11.0, 15.0, 19.0, 23.0]
  7365. * // [12.0, 16.0, 20.0, 24.0]
  7366. * // [13.0, 17.0, 21.0, 25.0]
  7367. */
  7368. Matrix4.transpose = function(matrix, result) {
  7369. if (!defined(matrix)) {
  7370. throw new DeveloperError('matrix is required');
  7371. }
  7372. if (!defined(result)) {
  7373. throw new DeveloperError('result is required');
  7374. }
  7375. var matrix1 = matrix[1];
  7376. var matrix2 = matrix[2];
  7377. var matrix3 = matrix[3];
  7378. var matrix6 = matrix[6];
  7379. var matrix7 = matrix[7];
  7380. var matrix11 = matrix[11];
  7381. result[0] = matrix[0];
  7382. result[1] = matrix[4];
  7383. result[2] = matrix[8];
  7384. result[3] = matrix[12];
  7385. result[4] = matrix1;
  7386. result[5] = matrix[5];
  7387. result[6] = matrix[9];
  7388. result[7] = matrix[13];
  7389. result[8] = matrix2;
  7390. result[9] = matrix6;
  7391. result[10] = matrix[10];
  7392. result[11] = matrix[14];
  7393. result[12] = matrix3;
  7394. result[13] = matrix7;
  7395. result[14] = matrix11;
  7396. result[15] = matrix[15];
  7397. return result;
  7398. };
  7399. /**
  7400. * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.
  7401. *
  7402. * @param {Matrix4} matrix The matrix with signed elements.
  7403. * @param {Matrix4} result The object onto which to store the result.
  7404. * @returns {Matrix4} The modified result parameter.
  7405. */
  7406. Matrix4.abs = function(matrix, result) {
  7407. if (!defined(matrix)) {
  7408. throw new DeveloperError('matrix is required');
  7409. }
  7410. if (!defined(result)) {
  7411. throw new DeveloperError('result is required');
  7412. }
  7413. result[0] = Math.abs(matrix[0]);
  7414. result[1] = Math.abs(matrix[1]);
  7415. result[2] = Math.abs(matrix[2]);
  7416. result[3] = Math.abs(matrix[3]);
  7417. result[4] = Math.abs(matrix[4]);
  7418. result[5] = Math.abs(matrix[5]);
  7419. result[6] = Math.abs(matrix[6]);
  7420. result[7] = Math.abs(matrix[7]);
  7421. result[8] = Math.abs(matrix[8]);
  7422. result[9] = Math.abs(matrix[9]);
  7423. result[10] = Math.abs(matrix[10]);
  7424. result[11] = Math.abs(matrix[11]);
  7425. result[12] = Math.abs(matrix[12]);
  7426. result[13] = Math.abs(matrix[13]);
  7427. result[14] = Math.abs(matrix[14]);
  7428. result[15] = Math.abs(matrix[15]);
  7429. return result;
  7430. };
  7431. /**
  7432. * Compares the provided matrices componentwise and returns
  7433. * <code>true</code> if they are equal, <code>false</code> otherwise.
  7434. *
  7435. * @param {Matrix4} [left] The first matrix.
  7436. * @param {Matrix4} [right] The second matrix.
  7437. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  7438. *
  7439. * @example
  7440. * //compares two Matrix4 instances
  7441. *
  7442. * // a = [10.0, 14.0, 18.0, 22.0]
  7443. * // [11.0, 15.0, 19.0, 23.0]
  7444. * // [12.0, 16.0, 20.0, 24.0]
  7445. * // [13.0, 17.0, 21.0, 25.0]
  7446. *
  7447. * // b = [10.0, 14.0, 18.0, 22.0]
  7448. * // [11.0, 15.0, 19.0, 23.0]
  7449. * // [12.0, 16.0, 20.0, 24.0]
  7450. * // [13.0, 17.0, 21.0, 25.0]
  7451. *
  7452. * if(Cesium.Matrix4.equals(a,b)) {
  7453. * console.log("Both matrices are equal");
  7454. * } else {
  7455. * console.log("They are not equal");
  7456. * }
  7457. *
  7458. * //Prints "Both matrices are equal" on the console
  7459. */
  7460. Matrix4.equals = function(left, right) {
  7461. // Given that most matrices will be transformation matrices, the elements
  7462. // are tested in order such that the test is likely to fail as early
  7463. // as possible. I _think_ this is just as friendly to the L1 cache
  7464. // as testing in index order. It is certainty faster in practice.
  7465. return (left === right) ||
  7466. (defined(left) &&
  7467. defined(right) &&
  7468. // Translation
  7469. left[12] === right[12] &&
  7470. left[13] === right[13] &&
  7471. left[14] === right[14] &&
  7472. // Rotation/scale
  7473. left[0] === right[0] &&
  7474. left[1] === right[1] &&
  7475. left[2] === right[2] &&
  7476. left[4] === right[4] &&
  7477. left[5] === right[5] &&
  7478. left[6] === right[6] &&
  7479. left[8] === right[8] &&
  7480. left[9] === right[9] &&
  7481. left[10] === right[10] &&
  7482. // Bottom row
  7483. left[3] === right[3] &&
  7484. left[7] === right[7] &&
  7485. left[11] === right[11] &&
  7486. left[15] === right[15]);
  7487. };
  7488. /**
  7489. * Compares the provided matrices componentwise and returns
  7490. * <code>true</code> if they are within the provided epsilon,
  7491. * <code>false</code> otherwise.
  7492. *
  7493. * @param {Matrix4} [left] The first matrix.
  7494. * @param {Matrix4} [right] The second matrix.
  7495. * @param {Number} epsilon The epsilon to use for equality testing.
  7496. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  7497. *
  7498. * @example
  7499. * //compares two Matrix4 instances
  7500. *
  7501. * // a = [10.5, 14.5, 18.5, 22.5]
  7502. * // [11.5, 15.5, 19.5, 23.5]
  7503. * // [12.5, 16.5, 20.5, 24.5]
  7504. * // [13.5, 17.5, 21.5, 25.5]
  7505. *
  7506. * // b = [10.0, 14.0, 18.0, 22.0]
  7507. * // [11.0, 15.0, 19.0, 23.0]
  7508. * // [12.0, 16.0, 20.0, 24.0]
  7509. * // [13.0, 17.0, 21.0, 25.0]
  7510. *
  7511. * if(Cesium.Matrix4.equalsEpsilon(a,b,0.1)){
  7512. * console.log("Difference between both the matrices is less than 0.1");
  7513. * } else {
  7514. * console.log("Difference between both the matrices is not less than 0.1");
  7515. * }
  7516. *
  7517. * //Prints "Difference between both the matrices is not less than 0.1" on the console
  7518. */
  7519. Matrix4.equalsEpsilon = function(left, right, epsilon) {
  7520. if (typeof epsilon !== 'number') {
  7521. throw new DeveloperError('epsilon must be a number');
  7522. }
  7523. return (left === right) ||
  7524. (defined(left) &&
  7525. defined(right) &&
  7526. Math.abs(left[0] - right[0]) <= epsilon &&
  7527. Math.abs(left[1] - right[1]) <= epsilon &&
  7528. Math.abs(left[2] - right[2]) <= epsilon &&
  7529. Math.abs(left[3] - right[3]) <= epsilon &&
  7530. Math.abs(left[4] - right[4]) <= epsilon &&
  7531. Math.abs(left[5] - right[5]) <= epsilon &&
  7532. Math.abs(left[6] - right[6]) <= epsilon &&
  7533. Math.abs(left[7] - right[7]) <= epsilon &&
  7534. Math.abs(left[8] - right[8]) <= epsilon &&
  7535. Math.abs(left[9] - right[9]) <= epsilon &&
  7536. Math.abs(left[10] - right[10]) <= epsilon &&
  7537. Math.abs(left[11] - right[11]) <= epsilon &&
  7538. Math.abs(left[12] - right[12]) <= epsilon &&
  7539. Math.abs(left[13] - right[13]) <= epsilon &&
  7540. Math.abs(left[14] - right[14]) <= epsilon &&
  7541. Math.abs(left[15] - right[15]) <= epsilon);
  7542. };
  7543. /**
  7544. * Gets the translation portion of the provided matrix, assuming the matrix is a affine transformation matrix.
  7545. *
  7546. * @param {Matrix4} matrix The matrix to use.
  7547. * @param {Cartesian3} result The object onto which to store the result.
  7548. * @returns {Cartesian3} The modified result parameter.
  7549. */
  7550. Matrix4.getTranslation = function(matrix, result) {
  7551. if (!defined(matrix)) {
  7552. throw new DeveloperError('matrix is required');
  7553. }
  7554. if (!defined(result)) {
  7555. throw new DeveloperError('result is required');
  7556. }
  7557. result.x = matrix[12];
  7558. result.y = matrix[13];
  7559. result.z = matrix[14];
  7560. return result;
  7561. };
  7562. /**
  7563. * Gets the upper left 3x3 rotation matrix of the provided matrix, assuming the matrix is a affine transformation matrix.
  7564. *
  7565. * @param {Matrix4} matrix The matrix to use.
  7566. * @param {Matrix3} result The object onto which to store the result.
  7567. * @returns {Matrix3} The modified result parameter.
  7568. *
  7569. * @example
  7570. * // returns a Matrix3 instance from a Matrix4 instance
  7571. *
  7572. * // m = [10.0, 14.0, 18.0, 22.0]
  7573. * // [11.0, 15.0, 19.0, 23.0]
  7574. * // [12.0, 16.0, 20.0, 24.0]
  7575. * // [13.0, 17.0, 21.0, 25.0]
  7576. *
  7577. * var b = new Cesium.Matrix3();
  7578. * Cesium.Matrix4.getRotation(m,b);
  7579. *
  7580. * // b = [10.0, 14.0, 18.0]
  7581. * // [11.0, 15.0, 19.0]
  7582. * // [12.0, 16.0, 20.0]
  7583. */
  7584. Matrix4.getRotation = function(matrix, result) {
  7585. if (!defined(matrix)) {
  7586. throw new DeveloperError('matrix is required');
  7587. }
  7588. if (!defined(result)) {
  7589. throw new DeveloperError('result is required');
  7590. }
  7591. result[0] = matrix[0];
  7592. result[1] = matrix[1];
  7593. result[2] = matrix[2];
  7594. result[3] = matrix[4];
  7595. result[4] = matrix[5];
  7596. result[5] = matrix[6];
  7597. result[6] = matrix[8];
  7598. result[7] = matrix[9];
  7599. result[8] = matrix[10];
  7600. return result;
  7601. };
  7602. var scratchInverseRotation = new Matrix3();
  7603. var scratchMatrix3Zero = new Matrix3();
  7604. var scratchBottomRow = new Cartesian4();
  7605. var scratchExpectedBottomRow = new Cartesian4(0.0, 0.0, 0.0, 1.0);
  7606. /**
  7607. * Computes the inverse of the provided matrix using Cramers Rule.
  7608. * If the determinant is zero, the matrix can not be inverted, and an exception is thrown.
  7609. * If the matrix is an affine transformation matrix, it is more efficient
  7610. * to invert it with {@link Matrix4.inverseTransformation}.
  7611. *
  7612. * @param {Matrix4} matrix The matrix to invert.
  7613. * @param {Matrix4} result The object onto which to store the result.
  7614. * @returns {Matrix4} The modified result parameter.
  7615. *
  7616. * @exception {RuntimeError} matrix is not invertible because its determinate is zero.
  7617. */
  7618. Matrix4.inverse = function(matrix, result) {
  7619. if (!defined(matrix)) {
  7620. throw new DeveloperError('matrix is required');
  7621. }
  7622. if (!defined(result)) {
  7623. throw new DeveloperError('result is required');
  7624. }
  7625. // Special case for a zero scale matrix that can occur, for example,
  7626. // when a model's node has a [0, 0, 0] scale.
  7627. if (Matrix3.equalsEpsilon(Matrix4.getRotation(matrix, scratchInverseRotation), scratchMatrix3Zero, CesiumMath.EPSILON7) &&
  7628. Cartesian4.equals(Matrix4.getRow(matrix, 3, scratchBottomRow), scratchExpectedBottomRow)) {
  7629. result[0] = 0.0;
  7630. result[1] = 0.0;
  7631. result[2] = 0.0;
  7632. result[3] = 0.0;
  7633. result[4] = 0.0;
  7634. result[5] = 0.0;
  7635. result[6] = 0.0;
  7636. result[7] = 0.0;
  7637. result[8] = 0.0;
  7638. result[9] = 0.0;
  7639. result[10] = 0.0;
  7640. result[11] = 0.0;
  7641. result[12] = -matrix[12];
  7642. result[13] = -matrix[13];
  7643. result[14] = -matrix[14];
  7644. result[15] = 1.0;
  7645. return result;
  7646. }
  7647. //
  7648. // Ported from:
  7649. // ftp://download.intel.com/design/PentiumIII/sml/24504301.pdf
  7650. //
  7651. var src0 = matrix[0];
  7652. var src1 = matrix[4];
  7653. var src2 = matrix[8];
  7654. var src3 = matrix[12];
  7655. var src4 = matrix[1];
  7656. var src5 = matrix[5];
  7657. var src6 = matrix[9];
  7658. var src7 = matrix[13];
  7659. var src8 = matrix[2];
  7660. var src9 = matrix[6];
  7661. var src10 = matrix[10];
  7662. var src11 = matrix[14];
  7663. var src12 = matrix[3];
  7664. var src13 = matrix[7];
  7665. var src14 = matrix[11];
  7666. var src15 = matrix[15];
  7667. // calculate pairs for first 8 elements (cofactors)
  7668. var tmp0 = src10 * src15;
  7669. var tmp1 = src11 * src14;
  7670. var tmp2 = src9 * src15;
  7671. var tmp3 = src11 * src13;
  7672. var tmp4 = src9 * src14;
  7673. var tmp5 = src10 * src13;
  7674. var tmp6 = src8 * src15;
  7675. var tmp7 = src11 * src12;
  7676. var tmp8 = src8 * src14;
  7677. var tmp9 = src10 * src12;
  7678. var tmp10 = src8 * src13;
  7679. var tmp11 = src9 * src12;
  7680. // calculate first 8 elements (cofactors)
  7681. var dst0 = (tmp0 * src5 + tmp3 * src6 + tmp4 * src7) - (tmp1 * src5 + tmp2 * src6 + tmp5 * src7);
  7682. var dst1 = (tmp1 * src4 + tmp6 * src6 + tmp9 * src7) - (tmp0 * src4 + tmp7 * src6 + tmp8 * src7);
  7683. var dst2 = (tmp2 * src4 + tmp7 * src5 + tmp10 * src7) - (tmp3 * src4 + tmp6 * src5 + tmp11 * src7);
  7684. var dst3 = (tmp5 * src4 + tmp8 * src5 + tmp11 * src6) - (tmp4 * src4 + tmp9 * src5 + tmp10 * src6);
  7685. var dst4 = (tmp1 * src1 + tmp2 * src2 + tmp5 * src3) - (tmp0 * src1 + tmp3 * src2 + tmp4 * src3);
  7686. var dst5 = (tmp0 * src0 + tmp7 * src2 + tmp8 * src3) - (tmp1 * src0 + tmp6 * src2 + tmp9 * src3);
  7687. var dst6 = (tmp3 * src0 + tmp6 * src1 + tmp11 * src3) - (tmp2 * src0 + tmp7 * src1 + tmp10 * src3);
  7688. var dst7 = (tmp4 * src0 + tmp9 * src1 + tmp10 * src2) - (tmp5 * src0 + tmp8 * src1 + tmp11 * src2);
  7689. // calculate pairs for second 8 elements (cofactors)
  7690. tmp0 = src2 * src7;
  7691. tmp1 = src3 * src6;
  7692. tmp2 = src1 * src7;
  7693. tmp3 = src3 * src5;
  7694. tmp4 = src1 * src6;
  7695. tmp5 = src2 * src5;
  7696. tmp6 = src0 * src7;
  7697. tmp7 = src3 * src4;
  7698. tmp8 = src0 * src6;
  7699. tmp9 = src2 * src4;
  7700. tmp10 = src0 * src5;
  7701. tmp11 = src1 * src4;
  7702. // calculate second 8 elements (cofactors)
  7703. var dst8 = (tmp0 * src13 + tmp3 * src14 + tmp4 * src15) - (tmp1 * src13 + tmp2 * src14 + tmp5 * src15);
  7704. var dst9 = (tmp1 * src12 + tmp6 * src14 + tmp9 * src15) - (tmp0 * src12 + tmp7 * src14 + tmp8 * src15);
  7705. var dst10 = (tmp2 * src12 + tmp7 * src13 + tmp10 * src15) - (tmp3 * src12 + tmp6 * src13 + tmp11 * src15);
  7706. var dst11 = (tmp5 * src12 + tmp8 * src13 + tmp11 * src14) - (tmp4 * src12 + tmp9 * src13 + tmp10 * src14);
  7707. var dst12 = (tmp2 * src10 + tmp5 * src11 + tmp1 * src9) - (tmp4 * src11 + tmp0 * src9 + tmp3 * src10);
  7708. var dst13 = (tmp8 * src11 + tmp0 * src8 + tmp7 * src10) - (tmp6 * src10 + tmp9 * src11 + tmp1 * src8);
  7709. var dst14 = (tmp6 * src9 + tmp11 * src11 + tmp3 * src8) - (tmp10 * src11 + tmp2 * src8 + tmp7 * src9);
  7710. var dst15 = (tmp10 * src10 + tmp4 * src8 + tmp9 * src9) - (tmp8 * src9 + tmp11 * src10 + tmp5 * src8);
  7711. // calculate determinant
  7712. var det = src0 * dst0 + src1 * dst1 + src2 * dst2 + src3 * dst3;
  7713. if (Math.abs(det) < CesiumMath.EPSILON20) {
  7714. throw new RuntimeError('matrix is not invertible because its determinate is zero.');
  7715. }
  7716. // calculate matrix inverse
  7717. det = 1.0 / det;
  7718. result[0] = dst0 * det;
  7719. result[1] = dst1 * det;
  7720. result[2] = dst2 * det;
  7721. result[3] = dst3 * det;
  7722. result[4] = dst4 * det;
  7723. result[5] = dst5 * det;
  7724. result[6] = dst6 * det;
  7725. result[7] = dst7 * det;
  7726. result[8] = dst8 * det;
  7727. result[9] = dst9 * det;
  7728. result[10] = dst10 * det;
  7729. result[11] = dst11 * det;
  7730. result[12] = dst12 * det;
  7731. result[13] = dst13 * det;
  7732. result[14] = dst14 * det;
  7733. result[15] = dst15 * det;
  7734. return result;
  7735. };
  7736. /**
  7737. * Computes the inverse of the provided matrix assuming it is
  7738. * an affine transformation matrix, where the upper left 3x3 elements
  7739. * are a rotation matrix, and the upper three elements in the fourth
  7740. * column are the translation. The bottom row is assumed to be [0, 0, 0, 1].
  7741. * The matrix is not verified to be in the proper form.
  7742. * This method is faster than computing the inverse for a general 4x4
  7743. * matrix using {@link Matrix4.inverse}.
  7744. *
  7745. * @param {Matrix4} matrix The matrix to invert.
  7746. * @param {Matrix4} result The object onto which to store the result.
  7747. * @returns {Matrix4} The modified result parameter.
  7748. */
  7749. Matrix4.inverseTransformation = function(matrix, result) {
  7750. if (!defined(matrix)) {
  7751. throw new DeveloperError('matrix is required');
  7752. }
  7753. if (!defined(result)) {
  7754. throw new DeveloperError('result is required');
  7755. }
  7756. //This function is an optimized version of the below 4 lines.
  7757. //var rT = Matrix3.transpose(Matrix4.getRotation(matrix));
  7758. //var rTN = Matrix3.negate(rT);
  7759. //var rTT = Matrix3.multiplyByVector(rTN, Matrix4.getTranslation(matrix));
  7760. //return Matrix4.fromRotationTranslation(rT, rTT, result);
  7761. var matrix0 = matrix[0];
  7762. var matrix1 = matrix[1];
  7763. var matrix2 = matrix[2];
  7764. var matrix4 = matrix[4];
  7765. var matrix5 = matrix[5];
  7766. var matrix6 = matrix[6];
  7767. var matrix8 = matrix[8];
  7768. var matrix9 = matrix[9];
  7769. var matrix10 = matrix[10];
  7770. var vX = matrix[12];
  7771. var vY = matrix[13];
  7772. var vZ = matrix[14];
  7773. var x = -matrix0 * vX - matrix1 * vY - matrix2 * vZ;
  7774. var y = -matrix4 * vX - matrix5 * vY - matrix6 * vZ;
  7775. var z = -matrix8 * vX - matrix9 * vY - matrix10 * vZ;
  7776. result[0] = matrix0;
  7777. result[1] = matrix4;
  7778. result[2] = matrix8;
  7779. result[3] = 0.0;
  7780. result[4] = matrix1;
  7781. result[5] = matrix5;
  7782. result[6] = matrix9;
  7783. result[7] = 0.0;
  7784. result[8] = matrix2;
  7785. result[9] = matrix6;
  7786. result[10] = matrix10;
  7787. result[11] = 0.0;
  7788. result[12] = x;
  7789. result[13] = y;
  7790. result[14] = z;
  7791. result[15] = 1.0;
  7792. return result;
  7793. };
  7794. /**
  7795. * An immutable Matrix4 instance initialized to the identity matrix.
  7796. *
  7797. * @type {Matrix4}
  7798. * @constant
  7799. */
  7800. Matrix4.IDENTITY = freezeObject(new Matrix4(1.0, 0.0, 0.0, 0.0,
  7801. 0.0, 1.0, 0.0, 0.0,
  7802. 0.0, 0.0, 1.0, 0.0,
  7803. 0.0, 0.0, 0.0, 1.0));
  7804. /**
  7805. * An immutable Matrix4 instance initialized to the zero matrix.
  7806. *
  7807. * @type {Matrix4}
  7808. * @constant
  7809. */
  7810. Matrix4.ZERO = freezeObject(new Matrix4(0.0, 0.0, 0.0, 0.0,
  7811. 0.0, 0.0, 0.0, 0.0,
  7812. 0.0, 0.0, 0.0, 0.0,
  7813. 0.0, 0.0, 0.0, 0.0));
  7814. /**
  7815. * The index into Matrix4 for column 0, row 0.
  7816. *
  7817. * @type {Number}
  7818. * @constant
  7819. */
  7820. Matrix4.COLUMN0ROW0 = 0;
  7821. /**
  7822. * The index into Matrix4 for column 0, row 1.
  7823. *
  7824. * @type {Number}
  7825. * @constant
  7826. */
  7827. Matrix4.COLUMN0ROW1 = 1;
  7828. /**
  7829. * The index into Matrix4 for column 0, row 2.
  7830. *
  7831. * @type {Number}
  7832. * @constant
  7833. */
  7834. Matrix4.COLUMN0ROW2 = 2;
  7835. /**
  7836. * The index into Matrix4 for column 0, row 3.
  7837. *
  7838. * @type {Number}
  7839. * @constant
  7840. */
  7841. Matrix4.COLUMN0ROW3 = 3;
  7842. /**
  7843. * The index into Matrix4 for column 1, row 0.
  7844. *
  7845. * @type {Number}
  7846. * @constant
  7847. */
  7848. Matrix4.COLUMN1ROW0 = 4;
  7849. /**
  7850. * The index into Matrix4 for column 1, row 1.
  7851. *
  7852. * @type {Number}
  7853. * @constant
  7854. */
  7855. Matrix4.COLUMN1ROW1 = 5;
  7856. /**
  7857. * The index into Matrix4 for column 1, row 2.
  7858. *
  7859. * @type {Number}
  7860. * @constant
  7861. */
  7862. Matrix4.COLUMN1ROW2 = 6;
  7863. /**
  7864. * The index into Matrix4 for column 1, row 3.
  7865. *
  7866. * @type {Number}
  7867. * @constant
  7868. */
  7869. Matrix4.COLUMN1ROW3 = 7;
  7870. /**
  7871. * The index into Matrix4 for column 2, row 0.
  7872. *
  7873. * @type {Number}
  7874. * @constant
  7875. */
  7876. Matrix4.COLUMN2ROW0 = 8;
  7877. /**
  7878. * The index into Matrix4 for column 2, row 1.
  7879. *
  7880. * @type {Number}
  7881. * @constant
  7882. */
  7883. Matrix4.COLUMN2ROW1 = 9;
  7884. /**
  7885. * The index into Matrix4 for column 2, row 2.
  7886. *
  7887. * @type {Number}
  7888. * @constant
  7889. */
  7890. Matrix4.COLUMN2ROW2 = 10;
  7891. /**
  7892. * The index into Matrix4 for column 2, row 3.
  7893. *
  7894. * @type {Number}
  7895. * @constant
  7896. */
  7897. Matrix4.COLUMN2ROW3 = 11;
  7898. /**
  7899. * The index into Matrix4 for column 3, row 0.
  7900. *
  7901. * @type {Number}
  7902. * @constant
  7903. */
  7904. Matrix4.COLUMN3ROW0 = 12;
  7905. /**
  7906. * The index into Matrix4 for column 3, row 1.
  7907. *
  7908. * @type {Number}
  7909. * @constant
  7910. */
  7911. Matrix4.COLUMN3ROW1 = 13;
  7912. /**
  7913. * The index into Matrix4 for column 3, row 2.
  7914. *
  7915. * @type {Number}
  7916. * @constant
  7917. */
  7918. Matrix4.COLUMN3ROW2 = 14;
  7919. /**
  7920. * The index into Matrix4 for column 3, row 3.
  7921. *
  7922. * @type {Number}
  7923. * @constant
  7924. */
  7925. Matrix4.COLUMN3ROW3 = 15;
  7926. defineProperties(Matrix4.prototype, {
  7927. /**
  7928. * Gets the number of items in the collection.
  7929. * @memberof Matrix4.prototype
  7930. *
  7931. * @type {Number}
  7932. */
  7933. length : {
  7934. get : function() {
  7935. return Matrix4.packedLength;
  7936. }
  7937. }
  7938. });
  7939. /**
  7940. * Duplicates the provided Matrix4 instance.
  7941. *
  7942. * @param {Matrix4} [result] The object onto which to store the result.
  7943. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
  7944. */
  7945. Matrix4.prototype.clone = function(result) {
  7946. return Matrix4.clone(this, result);
  7947. };
  7948. /**
  7949. * Compares this matrix to the provided matrix componentwise and returns
  7950. * <code>true</code> if they are equal, <code>false</code> otherwise.
  7951. *
  7952. * @param {Matrix4} [right] The right hand side matrix.
  7953. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  7954. */
  7955. Matrix4.prototype.equals = function(right) {
  7956. return Matrix4.equals(this, right);
  7957. };
  7958. /**
  7959. * @private
  7960. */
  7961. Matrix4.equalsArray = function(matrix, array, offset) {
  7962. return matrix[0] === array[offset] &&
  7963. matrix[1] === array[offset + 1] &&
  7964. matrix[2] === array[offset + 2] &&
  7965. matrix[3] === array[offset + 3] &&
  7966. matrix[4] === array[offset + 4] &&
  7967. matrix[5] === array[offset + 5] &&
  7968. matrix[6] === array[offset + 6] &&
  7969. matrix[7] === array[offset + 7] &&
  7970. matrix[8] === array[offset + 8] &&
  7971. matrix[9] === array[offset + 9] &&
  7972. matrix[10] === array[offset + 10] &&
  7973. matrix[11] === array[offset + 11] &&
  7974. matrix[12] === array[offset + 12] &&
  7975. matrix[13] === array[offset + 13] &&
  7976. matrix[14] === array[offset + 14] &&
  7977. matrix[15] === array[offset + 15];
  7978. };
  7979. /**
  7980. * Compares this matrix to the provided matrix componentwise and returns
  7981. * <code>true</code> if they are within the provided epsilon,
  7982. * <code>false</code> otherwise.
  7983. *
  7984. * @param {Matrix4} [right] The right hand side matrix.
  7985. * @param {Number} epsilon The epsilon to use for equality testing.
  7986. * @returns {Boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
  7987. */
  7988. Matrix4.prototype.equalsEpsilon = function(right, epsilon) {
  7989. return Matrix4.equalsEpsilon(this, right, epsilon);
  7990. };
  7991. /**
  7992. * Computes a string representing this Matrix with each row being
  7993. * on a separate line and in the format '(column0, column1, column2, column3)'.
  7994. *
  7995. * @returns {String} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2, column3)'.
  7996. */
  7997. Matrix4.prototype.toString = function() {
  7998. return '(' + this[0] + ', ' + this[4] + ', ' + this[8] + ', ' + this[12] +')\n' +
  7999. '(' + this[1] + ', ' + this[5] + ', ' + this[9] + ', ' + this[13] +')\n' +
  8000. '(' + this[2] + ', ' + this[6] + ', ' + this[10] + ', ' + this[14] +')\n' +
  8001. '(' + this[3] + ', ' + this[7] + ', ' + this[11] + ', ' + this[15] +')';
  8002. };
  8003. return Matrix4;
  8004. });
  8005. /*global define*/
  8006. define('Core/Rectangle',[
  8007. './Cartographic',
  8008. './defaultValue',
  8009. './defined',
  8010. './defineProperties',
  8011. './DeveloperError',
  8012. './Ellipsoid',
  8013. './freezeObject',
  8014. './Math'
  8015. ], function(
  8016. Cartographic,
  8017. defaultValue,
  8018. defined,
  8019. defineProperties,
  8020. DeveloperError,
  8021. Ellipsoid,
  8022. freezeObject,
  8023. CesiumMath) {
  8024. 'use strict';
  8025. /**
  8026. * A two dimensional region specified as longitude and latitude coordinates.
  8027. *
  8028. * @alias Rectangle
  8029. * @constructor
  8030. *
  8031. * @param {Number} [west=0.0] The westernmost longitude, in radians, in the range [-Pi, Pi].
  8032. * @param {Number} [south=0.0] The southernmost latitude, in radians, in the range [-Pi/2, Pi/2].
  8033. * @param {Number} [east=0.0] The easternmost longitude, in radians, in the range [-Pi, Pi].
  8034. * @param {Number} [north=0.0] The northernmost latitude, in radians, in the range [-Pi/2, Pi/2].
  8035. *
  8036. * @see Packable
  8037. */
  8038. function Rectangle(west, south, east, north) {
  8039. /**
  8040. * The westernmost longitude in radians in the range [-Pi, Pi].
  8041. *
  8042. * @type {Number}
  8043. * @default 0.0
  8044. */
  8045. this.west = defaultValue(west, 0.0);
  8046. /**
  8047. * The southernmost latitude in radians in the range [-Pi/2, Pi/2].
  8048. *
  8049. * @type {Number}
  8050. * @default 0.0
  8051. */
  8052. this.south = defaultValue(south, 0.0);
  8053. /**
  8054. * The easternmost longitude in radians in the range [-Pi, Pi].
  8055. *
  8056. * @type {Number}
  8057. * @default 0.0
  8058. */
  8059. this.east = defaultValue(east, 0.0);
  8060. /**
  8061. * The northernmost latitude in radians in the range [-Pi/2, Pi/2].
  8062. *
  8063. * @type {Number}
  8064. * @default 0.0
  8065. */
  8066. this.north = defaultValue(north, 0.0);
  8067. }
  8068. defineProperties(Rectangle.prototype, {
  8069. /**
  8070. * Gets the width of the rectangle in radians.
  8071. * @memberof Rectangle.prototype
  8072. * @type {Number}
  8073. */
  8074. width : {
  8075. get : function() {
  8076. return Rectangle.computeWidth(this);
  8077. }
  8078. },
  8079. /**
  8080. * Gets the height of the rectangle in radians.
  8081. * @memberof Rectangle.prototype
  8082. * @type {Number}
  8083. */
  8084. height : {
  8085. get : function() {
  8086. return Rectangle.computeHeight(this);
  8087. }
  8088. }
  8089. });
  8090. /**
  8091. * The number of elements used to pack the object into an array.
  8092. * @type {Number}
  8093. */
  8094. Rectangle.packedLength = 4;
  8095. /**
  8096. * Stores the provided instance into the provided array.
  8097. *
  8098. * @param {Rectangle} value The value to pack.
  8099. * @param {Number[]} array The array to pack into.
  8100. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  8101. *
  8102. * @returns {Number[]} The array that was packed into
  8103. */
  8104. Rectangle.pack = function(value, array, startingIndex) {
  8105. if (!defined(value)) {
  8106. throw new DeveloperError('value is required');
  8107. }
  8108. if (!defined(array)) {
  8109. throw new DeveloperError('array is required');
  8110. }
  8111. startingIndex = defaultValue(startingIndex, 0);
  8112. array[startingIndex++] = value.west;
  8113. array[startingIndex++] = value.south;
  8114. array[startingIndex++] = value.east;
  8115. array[startingIndex] = value.north;
  8116. return array;
  8117. };
  8118. /**
  8119. * Retrieves an instance from a packed array.
  8120. *
  8121. * @param {Number[]} array The packed array.
  8122. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  8123. * @param {Rectangle} [result] The object into which to store the result.
  8124. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if one was not provided.
  8125. */
  8126. Rectangle.unpack = function(array, startingIndex, result) {
  8127. if (!defined(array)) {
  8128. throw new DeveloperError('array is required');
  8129. }
  8130. startingIndex = defaultValue(startingIndex, 0);
  8131. if (!defined(result)) {
  8132. result = new Rectangle();
  8133. }
  8134. result.west = array[startingIndex++];
  8135. result.south = array[startingIndex++];
  8136. result.east = array[startingIndex++];
  8137. result.north = array[startingIndex];
  8138. return result;
  8139. };
  8140. /**
  8141. * Computes the width of a rectangle in radians.
  8142. * @param {Rectangle} rectangle The rectangle to compute the width of.
  8143. * @returns {Number} The width.
  8144. */
  8145. Rectangle.computeWidth = function(rectangle) {
  8146. if (!defined(rectangle)) {
  8147. throw new DeveloperError('rectangle is required.');
  8148. }
  8149. var east = rectangle.east;
  8150. var west = rectangle.west;
  8151. if (east < west) {
  8152. east += CesiumMath.TWO_PI;
  8153. }
  8154. return east - west;
  8155. };
  8156. /**
  8157. * Computes the height of a rectangle in radians.
  8158. * @param {Rectangle} rectangle The rectangle to compute the height of.
  8159. * @returns {Number} The height.
  8160. */
  8161. Rectangle.computeHeight = function(rectangle) {
  8162. if (!defined(rectangle)) {
  8163. throw new DeveloperError('rectangle is required.');
  8164. }
  8165. return rectangle.north - rectangle.south;
  8166. };
  8167. /**
  8168. * Creates an rectangle given the boundary longitude and latitude in degrees.
  8169. *
  8170. * @param {Number} [west=0.0] The westernmost longitude in degrees in the range [-180.0, 180.0].
  8171. * @param {Number} [south=0.0] The southernmost latitude in degrees in the range [-90.0, 90.0].
  8172. * @param {Number} [east=0.0] The easternmost longitude in degrees in the range [-180.0, 180.0].
  8173. * @param {Number} [north=0.0] The northernmost latitude in degrees in the range [-90.0, 90.0].
  8174. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  8175. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  8176. *
  8177. * @example
  8178. * var rectangle = Cesium.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0);
  8179. */
  8180. Rectangle.fromDegrees = function(west, south, east, north, result) {
  8181. west = CesiumMath.toRadians(defaultValue(west, 0.0));
  8182. south = CesiumMath.toRadians(defaultValue(south, 0.0));
  8183. east = CesiumMath.toRadians(defaultValue(east, 0.0));
  8184. north = CesiumMath.toRadians(defaultValue(north, 0.0));
  8185. if (!defined(result)) {
  8186. return new Rectangle(west, south, east, north);
  8187. }
  8188. result.west = west;
  8189. result.south = south;
  8190. result.east = east;
  8191. result.north = north;
  8192. return result;
  8193. };
  8194. /**
  8195. * Creates the smallest possible Rectangle that encloses all positions in the provided array.
  8196. *
  8197. * @param {Cartographic[]} cartographics The list of Cartographic instances.
  8198. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  8199. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  8200. */
  8201. Rectangle.fromCartographicArray = function(cartographics, result) {
  8202. if (!defined(cartographics)) {
  8203. throw new DeveloperError('cartographics is required.');
  8204. }
  8205. var west = Number.MAX_VALUE;
  8206. var east = -Number.MAX_VALUE;
  8207. var westOverIDL = Number.MAX_VALUE;
  8208. var eastOverIDL = -Number.MAX_VALUE;
  8209. var south = Number.MAX_VALUE;
  8210. var north = -Number.MAX_VALUE;
  8211. for ( var i = 0, len = cartographics.length; i < len; i++) {
  8212. var position = cartographics[i];
  8213. west = Math.min(west, position.longitude);
  8214. east = Math.max(east, position.longitude);
  8215. south = Math.min(south, position.latitude);
  8216. north = Math.max(north, position.latitude);
  8217. var lonAdjusted = position.longitude >= 0 ? position.longitude : position.longitude + CesiumMath.TWO_PI;
  8218. westOverIDL = Math.min(westOverIDL, lonAdjusted);
  8219. eastOverIDL = Math.max(eastOverIDL, lonAdjusted);
  8220. }
  8221. if(east - west > eastOverIDL - westOverIDL) {
  8222. west = westOverIDL;
  8223. east = eastOverIDL;
  8224. if (east > CesiumMath.PI) {
  8225. east = east - CesiumMath.TWO_PI;
  8226. }
  8227. if (west > CesiumMath.PI) {
  8228. west = west - CesiumMath.TWO_PI;
  8229. }
  8230. }
  8231. if (!defined(result)) {
  8232. return new Rectangle(west, south, east, north);
  8233. }
  8234. result.west = west;
  8235. result.south = south;
  8236. result.east = east;
  8237. result.north = north;
  8238. return result;
  8239. };
  8240. /**
  8241. * Creates the smallest possible Rectangle that encloses all positions in the provided array.
  8242. *
  8243. * @param {Cartesian[]} cartesians The list of Cartesian instances.
  8244. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid the cartesians are on.
  8245. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  8246. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  8247. */
  8248. Rectangle.fromCartesianArray = function(cartesians, ellipsoid, result) {
  8249. if (!defined(cartesians)) {
  8250. throw new DeveloperError('cartesians is required.');
  8251. }
  8252. var west = Number.MAX_VALUE;
  8253. var east = -Number.MAX_VALUE;
  8254. var westOverIDL = Number.MAX_VALUE;
  8255. var eastOverIDL = -Number.MAX_VALUE;
  8256. var south = Number.MAX_VALUE;
  8257. var north = -Number.MAX_VALUE;
  8258. for ( var i = 0, len = cartesians.length; i < len; i++) {
  8259. var position = ellipsoid.cartesianToCartographic(cartesians[i]);
  8260. west = Math.min(west, position.longitude);
  8261. east = Math.max(east, position.longitude);
  8262. south = Math.min(south, position.latitude);
  8263. north = Math.max(north, position.latitude);
  8264. var lonAdjusted = position.longitude >= 0 ? position.longitude : position.longitude + CesiumMath.TWO_PI;
  8265. westOverIDL = Math.min(westOverIDL, lonAdjusted);
  8266. eastOverIDL = Math.max(eastOverIDL, lonAdjusted);
  8267. }
  8268. if(east - west > eastOverIDL - westOverIDL) {
  8269. west = westOverIDL;
  8270. east = eastOverIDL;
  8271. if (east > CesiumMath.PI) {
  8272. east = east - CesiumMath.TWO_PI;
  8273. }
  8274. if (west > CesiumMath.PI) {
  8275. west = west - CesiumMath.TWO_PI;
  8276. }
  8277. }
  8278. if (!defined(result)) {
  8279. return new Rectangle(west, south, east, north);
  8280. }
  8281. result.west = west;
  8282. result.south = south;
  8283. result.east = east;
  8284. result.north = north;
  8285. return result;
  8286. };
  8287. /**
  8288. * Duplicates an Rectangle.
  8289. *
  8290. * @param {Rectangle} rectangle The rectangle to clone.
  8291. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  8292. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided. (Returns undefined if rectangle is undefined)
  8293. */
  8294. Rectangle.clone = function(rectangle, result) {
  8295. if (!defined(rectangle)) {
  8296. return undefined;
  8297. }
  8298. if (!defined(result)) {
  8299. return new Rectangle(rectangle.west, rectangle.south, rectangle.east, rectangle.north);
  8300. }
  8301. result.west = rectangle.west;
  8302. result.south = rectangle.south;
  8303. result.east = rectangle.east;
  8304. result.north = rectangle.north;
  8305. return result;
  8306. };
  8307. /**
  8308. * Duplicates this Rectangle.
  8309. *
  8310. * @param {Rectangle} [result] The object onto which to store the result.
  8311. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  8312. */
  8313. Rectangle.prototype.clone = function(result) {
  8314. return Rectangle.clone(this, result);
  8315. };
  8316. /**
  8317. * Compares the provided Rectangle with this Rectangle componentwise and returns
  8318. * <code>true</code> if they are equal, <code>false</code> otherwise.
  8319. *
  8320. * @param {Rectangle} [other] The Rectangle to compare.
  8321. * @returns {Boolean} <code>true</code> if the Rectangles are equal, <code>false</code> otherwise.
  8322. */
  8323. Rectangle.prototype.equals = function(other) {
  8324. return Rectangle.equals(this, other);
  8325. };
  8326. /**
  8327. * Compares the provided rectangles and returns <code>true</code> if they are equal,
  8328. * <code>false</code> otherwise.
  8329. *
  8330. * @param {Rectangle} [left] The first Rectangle.
  8331. * @param {Rectangle} [right] The second Rectangle.
  8332. * @returns {Boolean} <code>true</code> if left and right are equal; otherwise <code>false</code>.
  8333. */
  8334. Rectangle.equals = function(left, right) {
  8335. return (left === right) ||
  8336. ((defined(left)) &&
  8337. (defined(right)) &&
  8338. (left.west === right.west) &&
  8339. (left.south === right.south) &&
  8340. (left.east === right.east) &&
  8341. (left.north === right.north));
  8342. };
  8343. /**
  8344. * Compares the provided Rectangle with this Rectangle componentwise and returns
  8345. * <code>true</code> if they are within the provided epsilon,
  8346. * <code>false</code> otherwise.
  8347. *
  8348. * @param {Rectangle} [other] The Rectangle to compare.
  8349. * @param {Number} epsilon The epsilon to use for equality testing.
  8350. * @returns {Boolean} <code>true</code> if the Rectangles are within the provided epsilon, <code>false</code> otherwise.
  8351. */
  8352. Rectangle.prototype.equalsEpsilon = function(other, epsilon) {
  8353. if (typeof epsilon !== 'number') {
  8354. throw new DeveloperError('epsilon is required and must be a number.');
  8355. }
  8356. return defined(other) &&
  8357. (Math.abs(this.west - other.west) <= epsilon) &&
  8358. (Math.abs(this.south - other.south) <= epsilon) &&
  8359. (Math.abs(this.east - other.east) <= epsilon) &&
  8360. (Math.abs(this.north - other.north) <= epsilon);
  8361. };
  8362. /**
  8363. * Checks an Rectangle's properties and throws if they are not in valid ranges.
  8364. *
  8365. * @param {Rectangle} rectangle The rectangle to validate
  8366. *
  8367. * @exception {DeveloperError} <code>north</code> must be in the interval [<code>-Pi/2</code>, <code>Pi/2</code>].
  8368. * @exception {DeveloperError} <code>south</code> must be in the interval [<code>-Pi/2</code>, <code>Pi/2</code>].
  8369. * @exception {DeveloperError} <code>east</code> must be in the interval [<code>-Pi</code>, <code>Pi</code>].
  8370. * @exception {DeveloperError} <code>west</code> must be in the interval [<code>-Pi</code>, <code>Pi</code>].
  8371. */
  8372. Rectangle.validate = function(rectangle) {
  8373. if (!defined(rectangle)) {
  8374. throw new DeveloperError('rectangle is required');
  8375. }
  8376. var north = rectangle.north;
  8377. if (typeof north !== 'number') {
  8378. throw new DeveloperError('north is required to be a number.');
  8379. }
  8380. if (north < -CesiumMath.PI_OVER_TWO || north > CesiumMath.PI_OVER_TWO) {
  8381. throw new DeveloperError('north must be in the interval [-Pi/2, Pi/2].');
  8382. }
  8383. var south = rectangle.south;
  8384. if (typeof south !== 'number') {
  8385. throw new DeveloperError('south is required to be a number.');
  8386. }
  8387. if (south < -CesiumMath.PI_OVER_TWO || south > CesiumMath.PI_OVER_TWO) {
  8388. throw new DeveloperError('south must be in the interval [-Pi/2, Pi/2].');
  8389. }
  8390. var west = rectangle.west;
  8391. if (typeof west !== 'number') {
  8392. throw new DeveloperError('west is required to be a number.');
  8393. }
  8394. if (west < -Math.PI || west > Math.PI) {
  8395. throw new DeveloperError('west must be in the interval [-Pi, Pi].');
  8396. }
  8397. var east = rectangle.east;
  8398. if (typeof east !== 'number') {
  8399. throw new DeveloperError('east is required to be a number.');
  8400. }
  8401. if (east < -Math.PI || east > Math.PI) {
  8402. throw new DeveloperError('east must be in the interval [-Pi, Pi].');
  8403. }
  8404. };
  8405. /**
  8406. * Computes the southwest corner of an rectangle.
  8407. *
  8408. * @param {Rectangle} rectangle The rectangle for which to find the corner
  8409. * @param {Cartographic} [result] The object onto which to store the result.
  8410. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  8411. */
  8412. Rectangle.southwest = function(rectangle, result) {
  8413. if (!defined(rectangle)) {
  8414. throw new DeveloperError('rectangle is required');
  8415. }
  8416. if (!defined(result)) {
  8417. return new Cartographic(rectangle.west, rectangle.south);
  8418. }
  8419. result.longitude = rectangle.west;
  8420. result.latitude = rectangle.south;
  8421. result.height = 0.0;
  8422. return result;
  8423. };
  8424. /**
  8425. * Computes the northwest corner of an rectangle.
  8426. *
  8427. * @param {Rectangle} rectangle The rectangle for which to find the corner
  8428. * @param {Cartographic} [result] The object onto which to store the result.
  8429. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  8430. */
  8431. Rectangle.northwest = function(rectangle, result) {
  8432. if (!defined(rectangle)) {
  8433. throw new DeveloperError('rectangle is required');
  8434. }
  8435. if (!defined(result)) {
  8436. return new Cartographic(rectangle.west, rectangle.north);
  8437. }
  8438. result.longitude = rectangle.west;
  8439. result.latitude = rectangle.north;
  8440. result.height = 0.0;
  8441. return result;
  8442. };
  8443. /**
  8444. * Computes the northeast corner of an rectangle.
  8445. *
  8446. * @param {Rectangle} rectangle The rectangle for which to find the corner
  8447. * @param {Cartographic} [result] The object onto which to store the result.
  8448. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  8449. */
  8450. Rectangle.northeast = function(rectangle, result) {
  8451. if (!defined(rectangle)) {
  8452. throw new DeveloperError('rectangle is required');
  8453. }
  8454. if (!defined(result)) {
  8455. return new Cartographic(rectangle.east, rectangle.north);
  8456. }
  8457. result.longitude = rectangle.east;
  8458. result.latitude = rectangle.north;
  8459. result.height = 0.0;
  8460. return result;
  8461. };
  8462. /**
  8463. * Computes the southeast corner of an rectangle.
  8464. *
  8465. * @param {Rectangle} rectangle The rectangle for which to find the corner
  8466. * @param {Cartographic} [result] The object onto which to store the result.
  8467. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  8468. */
  8469. Rectangle.southeast = function(rectangle, result) {
  8470. if (!defined(rectangle)) {
  8471. throw new DeveloperError('rectangle is required');
  8472. }
  8473. if (!defined(result)) {
  8474. return new Cartographic(rectangle.east, rectangle.south);
  8475. }
  8476. result.longitude = rectangle.east;
  8477. result.latitude = rectangle.south;
  8478. result.height = 0.0;
  8479. return result;
  8480. };
  8481. /**
  8482. * Computes the center of an rectangle.
  8483. *
  8484. * @param {Rectangle} rectangle The rectangle for which to find the center
  8485. * @param {Cartographic} [result] The object onto which to store the result.
  8486. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  8487. */
  8488. Rectangle.center = function(rectangle, result) {
  8489. if (!defined(rectangle)) {
  8490. throw new DeveloperError('rectangle is required');
  8491. }
  8492. var east = rectangle.east;
  8493. var west = rectangle.west;
  8494. if (east < west) {
  8495. east += CesiumMath.TWO_PI;
  8496. }
  8497. var longitude = CesiumMath.negativePiToPi((west + east) * 0.5);
  8498. var latitude = (rectangle.south + rectangle.north) * 0.5;
  8499. if (!defined(result)) {
  8500. return new Cartographic(longitude, latitude);
  8501. }
  8502. result.longitude = longitude;
  8503. result.latitude = latitude;
  8504. result.height = 0.0;
  8505. return result;
  8506. };
  8507. /**
  8508. * Computes the intersection of two rectangles. This function assumes that the rectangle's coordinates are
  8509. * latitude and longitude in radians and produces a correct intersection, taking into account the fact that
  8510. * the same angle can be represented with multiple values as well as the wrapping of longitude at the
  8511. * anti-meridian. For a simple intersection that ignores these factors and can be used with projected
  8512. * coordinates, see {@link Rectangle.simpleIntersection}.
  8513. *
  8514. * @param {Rectangle} rectangle On rectangle to find an intersection
  8515. * @param {Rectangle} otherRectangle Another rectangle to find an intersection
  8516. * @param {Rectangle} [result] The object onto which to store the result.
  8517. * @returns {Rectangle|undefined} The modified result parameter, a new Rectangle instance if none was provided or undefined if there is no intersection.
  8518. */
  8519. Rectangle.intersection = function(rectangle, otherRectangle, result) {
  8520. if (!defined(rectangle)) {
  8521. throw new DeveloperError('rectangle is required');
  8522. }
  8523. if (!defined(otherRectangle)) {
  8524. throw new DeveloperError('otherRectangle is required.');
  8525. }
  8526. var rectangleEast = rectangle.east;
  8527. var rectangleWest = rectangle.west;
  8528. var otherRectangleEast = otherRectangle.east;
  8529. var otherRectangleWest = otherRectangle.west;
  8530. if (rectangleEast < rectangleWest && otherRectangleEast > 0.0) {
  8531. rectangleEast += CesiumMath.TWO_PI;
  8532. } else if (otherRectangleEast < otherRectangleWest && rectangleEast > 0.0) {
  8533. otherRectangleEast += CesiumMath.TWO_PI;
  8534. }
  8535. if (rectangleEast < rectangleWest && otherRectangleWest < 0.0) {
  8536. otherRectangleWest += CesiumMath.TWO_PI;
  8537. } else if (otherRectangleEast < otherRectangleWest && rectangleWest < 0.0) {
  8538. rectangleWest += CesiumMath.TWO_PI;
  8539. }
  8540. var west = CesiumMath.negativePiToPi(Math.max(rectangleWest, otherRectangleWest));
  8541. var east = CesiumMath.negativePiToPi(Math.min(rectangleEast, otherRectangleEast));
  8542. if ((rectangle.west < rectangle.east || otherRectangle.west < otherRectangle.east) && east <= west) {
  8543. return undefined;
  8544. }
  8545. var south = Math.max(rectangle.south, otherRectangle.south);
  8546. var north = Math.min(rectangle.north, otherRectangle.north);
  8547. if (south >= north) {
  8548. return undefined;
  8549. }
  8550. if (!defined(result)) {
  8551. return new Rectangle(west, south, east, north);
  8552. }
  8553. result.west = west;
  8554. result.south = south;
  8555. result.east = east;
  8556. result.north = north;
  8557. return result;
  8558. };
  8559. /**
  8560. * Computes a simple intersection of two rectangles. Unlike {@link Rectangle.intersection}, this function
  8561. * does not attempt to put the angular coordinates into a consistent range or to account for crossing the
  8562. * anti-meridian. As such, it can be used for rectangles where the coordinates are not simply latitude
  8563. * and longitude (i.e. projected coordinates).
  8564. *
  8565. * @param {Rectangle} rectangle On rectangle to find an intersection
  8566. * @param {Rectangle} otherRectangle Another rectangle to find an intersection
  8567. * @param {Rectangle} [result] The object onto which to store the result.
  8568. * @returns {Rectangle|undefined} The modified result parameter, a new Rectangle instance if none was provided or undefined if there is no intersection.
  8569. */
  8570. Rectangle.simpleIntersection = function(rectangle, otherRectangle, result) {
  8571. if (!defined(rectangle)) {
  8572. throw new DeveloperError('rectangle is required');
  8573. }
  8574. if (!defined(otherRectangle)) {
  8575. throw new DeveloperError('otherRectangle is required.');
  8576. }
  8577. var west = Math.max(rectangle.west, otherRectangle.west);
  8578. var south = Math.max(rectangle.south, otherRectangle.south);
  8579. var east = Math.min(rectangle.east, otherRectangle.east);
  8580. var north = Math.min(rectangle.north, otherRectangle.north);
  8581. if (south >= north || west >= east) {
  8582. return undefined;
  8583. }
  8584. if (!defined(result)) {
  8585. return new Rectangle(west, south, east, north);
  8586. }
  8587. result.west = west;
  8588. result.south = south;
  8589. result.east = east;
  8590. result.north = north;
  8591. return result;
  8592. };
  8593. /**
  8594. * Computes a rectangle that is the union of two rectangles.
  8595. *
  8596. * @param {Rectangle} rectangle A rectangle to enclose in rectangle.
  8597. * @param {Rectangle} otherRectangle A rectangle to enclose in a rectangle.
  8598. * @param {Rectangle} [result] The object onto which to store the result.
  8599. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  8600. */
  8601. Rectangle.union = function(rectangle, otherRectangle, result) {
  8602. if (!defined(rectangle)) {
  8603. throw new DeveloperError('rectangle is required');
  8604. }
  8605. if (!defined(otherRectangle)) {
  8606. throw new DeveloperError('otherRectangle is required.');
  8607. }
  8608. if (!defined(result)) {
  8609. result = new Rectangle();
  8610. }
  8611. var rectangleEast = rectangle.east;
  8612. var rectangleWest = rectangle.west;
  8613. var otherRectangleEast = otherRectangle.east;
  8614. var otherRectangleWest = otherRectangle.west;
  8615. if (rectangleEast < rectangleWest && otherRectangleEast > 0.0) {
  8616. rectangleEast += CesiumMath.TWO_PI;
  8617. } else if (otherRectangleEast < otherRectangleWest && rectangleEast > 0.0) {
  8618. otherRectangleEast += CesiumMath.TWO_PI;
  8619. }
  8620. if (rectangleEast < rectangleWest && otherRectangleWest < 0.0) {
  8621. otherRectangleWest += CesiumMath.TWO_PI;
  8622. } else if (otherRectangleEast < otherRectangleWest && rectangleWest < 0.0) {
  8623. rectangleWest += CesiumMath.TWO_PI;
  8624. }
  8625. var west = CesiumMath.convertLongitudeRange(Math.min(rectangleWest, otherRectangleWest));
  8626. var east = CesiumMath.convertLongitudeRange(Math.max(rectangleEast, otherRectangleEast));
  8627. result.west = west;
  8628. result.south = Math.min(rectangle.south, otherRectangle.south);
  8629. result.east = east;
  8630. result.north = Math.max(rectangle.north, otherRectangle.north);
  8631. return result;
  8632. };
  8633. /**
  8634. * Computes a rectangle by enlarging the provided rectangle until it contains the provided cartographic.
  8635. *
  8636. * @param {Rectangle} rectangle A rectangle to expand.
  8637. * @param {Cartographic} cartographic A cartographic to enclose in a rectangle.
  8638. * @param {Rectangle} [result] The object onto which to store the result.
  8639. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if one was not provided.
  8640. */
  8641. Rectangle.expand = function(rectangle, cartographic, result) {
  8642. if (!defined(rectangle)) {
  8643. throw new DeveloperError('rectangle is required.');
  8644. }
  8645. if (!defined(cartographic)) {
  8646. throw new DeveloperError('cartographic is required.');
  8647. }
  8648. if (!defined(result)) {
  8649. result = new Rectangle();
  8650. }
  8651. result.west = Math.min(rectangle.west, cartographic.longitude);
  8652. result.south = Math.min(rectangle.south, cartographic.latitude);
  8653. result.east = Math.max(rectangle.east, cartographic.longitude);
  8654. result.north = Math.max(rectangle.north, cartographic.latitude);
  8655. return result;
  8656. };
  8657. /**
  8658. * Returns true if the cartographic is on or inside the rectangle, false otherwise.
  8659. *
  8660. * @param {Rectangle} rectangle The rectangle
  8661. * @param {Cartographic} cartographic The cartographic to test.
  8662. * @returns {Boolean} true if the provided cartographic is inside the rectangle, false otherwise.
  8663. */
  8664. Rectangle.contains = function(rectangle, cartographic) {
  8665. if (!defined(rectangle)) {
  8666. throw new DeveloperError('rectangle is required');
  8667. }
  8668. if (!defined(cartographic)) {
  8669. throw new DeveloperError('cartographic is required.');
  8670. }
  8671. var longitude = cartographic.longitude;
  8672. var latitude = cartographic.latitude;
  8673. var west = rectangle.west;
  8674. var east = rectangle.east;
  8675. if (east < west) {
  8676. east += CesiumMath.TWO_PI;
  8677. if (longitude < 0.0) {
  8678. longitude += CesiumMath.TWO_PI;
  8679. }
  8680. }
  8681. return (longitude > west || CesiumMath.equalsEpsilon(longitude, west, CesiumMath.EPSILON14)) &&
  8682. (longitude < east || CesiumMath.equalsEpsilon(longitude, east, CesiumMath.EPSILON14)) &&
  8683. latitude >= rectangle.south &&
  8684. latitude <= rectangle.north;
  8685. };
  8686. var subsampleLlaScratch = new Cartographic();
  8687. /**
  8688. * Samples an rectangle so that it includes a list of Cartesian points suitable for passing to
  8689. * {@link BoundingSphere#fromPoints}. Sampling is necessary to account
  8690. * for rectangles that cover the poles or cross the equator.
  8691. *
  8692. * @param {Rectangle} rectangle The rectangle to subsample.
  8693. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use.
  8694. * @param {Number} [surfaceHeight=0.0] The height of the rectangle above the ellipsoid.
  8695. * @param {Cartesian3[]} [result] The array of Cartesians onto which to store the result.
  8696. * @returns {Cartesian3[]} The modified result parameter or a new Array of Cartesians instances if none was provided.
  8697. */
  8698. Rectangle.subsample = function(rectangle, ellipsoid, surfaceHeight, result) {
  8699. if (!defined(rectangle)) {
  8700. throw new DeveloperError('rectangle is required');
  8701. }
  8702. ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
  8703. surfaceHeight = defaultValue(surfaceHeight, 0.0);
  8704. if (!defined(result)) {
  8705. result = [];
  8706. }
  8707. var length = 0;
  8708. var north = rectangle.north;
  8709. var south = rectangle.south;
  8710. var east = rectangle.east;
  8711. var west = rectangle.west;
  8712. var lla = subsampleLlaScratch;
  8713. lla.height = surfaceHeight;
  8714. lla.longitude = west;
  8715. lla.latitude = north;
  8716. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8717. length++;
  8718. lla.longitude = east;
  8719. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8720. length++;
  8721. lla.latitude = south;
  8722. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8723. length++;
  8724. lla.longitude = west;
  8725. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8726. length++;
  8727. if (north < 0.0) {
  8728. lla.latitude = north;
  8729. } else if (south > 0.0) {
  8730. lla.latitude = south;
  8731. } else {
  8732. lla.latitude = 0.0;
  8733. }
  8734. for ( var i = 1; i < 8; ++i) {
  8735. lla.longitude = -Math.PI + i * CesiumMath.PI_OVER_TWO;
  8736. if (Rectangle.contains(rectangle, lla)) {
  8737. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8738. length++;
  8739. }
  8740. }
  8741. if (lla.latitude === 0.0) {
  8742. lla.longitude = west;
  8743. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8744. length++;
  8745. lla.longitude = east;
  8746. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  8747. length++;
  8748. }
  8749. result.length = length;
  8750. return result;
  8751. };
  8752. /**
  8753. * The largest possible rectangle.
  8754. *
  8755. * @type {Rectangle}
  8756. * @constant
  8757. */
  8758. Rectangle.MAX_VALUE = freezeObject(new Rectangle(-Math.PI, -CesiumMath.PI_OVER_TWO, Math.PI, CesiumMath.PI_OVER_TWO));
  8759. return Rectangle;
  8760. });
  8761. /*global define*/
  8762. define('Core/BoundingSphere',[
  8763. './Cartesian3',
  8764. './Cartographic',
  8765. './defaultValue',
  8766. './defined',
  8767. './DeveloperError',
  8768. './Ellipsoid',
  8769. './GeographicProjection',
  8770. './Intersect',
  8771. './Interval',
  8772. './Matrix3',
  8773. './Matrix4',
  8774. './Rectangle'
  8775. ], function(
  8776. Cartesian3,
  8777. Cartographic,
  8778. defaultValue,
  8779. defined,
  8780. DeveloperError,
  8781. Ellipsoid,
  8782. GeographicProjection,
  8783. Intersect,
  8784. Interval,
  8785. Matrix3,
  8786. Matrix4,
  8787. Rectangle) {
  8788. 'use strict';
  8789. /**
  8790. * A bounding sphere with a center and a radius.
  8791. * @alias BoundingSphere
  8792. * @constructor
  8793. *
  8794. * @param {Cartesian3} [center=Cartesian3.ZERO] The center of the bounding sphere.
  8795. * @param {Number} [radius=0.0] The radius of the bounding sphere.
  8796. *
  8797. * @see AxisAlignedBoundingBox
  8798. * @see BoundingRectangle
  8799. * @see Packable
  8800. */
  8801. function BoundingSphere(center, radius) {
  8802. /**
  8803. * The center point of the sphere.
  8804. * @type {Cartesian3}
  8805. * @default {@link Cartesian3.ZERO}
  8806. */
  8807. this.center = Cartesian3.clone(defaultValue(center, Cartesian3.ZERO));
  8808. /**
  8809. * The radius of the sphere.
  8810. * @type {Number}
  8811. * @default 0.0
  8812. */
  8813. this.radius = defaultValue(radius, 0.0);
  8814. }
  8815. var fromPointsXMin = new Cartesian3();
  8816. var fromPointsYMin = new Cartesian3();
  8817. var fromPointsZMin = new Cartesian3();
  8818. var fromPointsXMax = new Cartesian3();
  8819. var fromPointsYMax = new Cartesian3();
  8820. var fromPointsZMax = new Cartesian3();
  8821. var fromPointsCurrentPos = new Cartesian3();
  8822. var fromPointsScratch = new Cartesian3();
  8823. var fromPointsRitterCenter = new Cartesian3();
  8824. var fromPointsMinBoxPt = new Cartesian3();
  8825. var fromPointsMaxBoxPt = new Cartesian3();
  8826. var fromPointsNaiveCenterScratch = new Cartesian3();
  8827. /**
  8828. * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.
  8829. * The bounding sphere is computed by running two algorithms, a naive algorithm and
  8830. * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.
  8831. *
  8832. * @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.
  8833. * @param {BoundingSphere} [result] The object onto which to store the result.
  8834. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.
  8835. *
  8836. * @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}
  8837. */
  8838. BoundingSphere.fromPoints = function(positions, result) {
  8839. if (!defined(result)) {
  8840. result = new BoundingSphere();
  8841. }
  8842. if (!defined(positions) || positions.length === 0) {
  8843. result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);
  8844. result.radius = 0.0;
  8845. return result;
  8846. }
  8847. var currentPos = Cartesian3.clone(positions[0], fromPointsCurrentPos);
  8848. var xMin = Cartesian3.clone(currentPos, fromPointsXMin);
  8849. var yMin = Cartesian3.clone(currentPos, fromPointsYMin);
  8850. var zMin = Cartesian3.clone(currentPos, fromPointsZMin);
  8851. var xMax = Cartesian3.clone(currentPos, fromPointsXMax);
  8852. var yMax = Cartesian3.clone(currentPos, fromPointsYMax);
  8853. var zMax = Cartesian3.clone(currentPos, fromPointsZMax);
  8854. var numPositions = positions.length;
  8855. for (var i = 1; i < numPositions; i++) {
  8856. Cartesian3.clone(positions[i], currentPos);
  8857. var x = currentPos.x;
  8858. var y = currentPos.y;
  8859. var z = currentPos.z;
  8860. // Store points containing the the smallest and largest components
  8861. if (x < xMin.x) {
  8862. Cartesian3.clone(currentPos, xMin);
  8863. }
  8864. if (x > xMax.x) {
  8865. Cartesian3.clone(currentPos, xMax);
  8866. }
  8867. if (y < yMin.y) {
  8868. Cartesian3.clone(currentPos, yMin);
  8869. }
  8870. if (y > yMax.y) {
  8871. Cartesian3.clone(currentPos, yMax);
  8872. }
  8873. if (z < zMin.z) {
  8874. Cartesian3.clone(currentPos, zMin);
  8875. }
  8876. if (z > zMax.z) {
  8877. Cartesian3.clone(currentPos, zMax);
  8878. }
  8879. }
  8880. // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).
  8881. var xSpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(xMax, xMin, fromPointsScratch));
  8882. var ySpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(yMax, yMin, fromPointsScratch));
  8883. var zSpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(zMax, zMin, fromPointsScratch));
  8884. // Set the diameter endpoints to the largest span.
  8885. var diameter1 = xMin;
  8886. var diameter2 = xMax;
  8887. var maxSpan = xSpan;
  8888. if (ySpan > maxSpan) {
  8889. maxSpan = ySpan;
  8890. diameter1 = yMin;
  8891. diameter2 = yMax;
  8892. }
  8893. if (zSpan > maxSpan) {
  8894. maxSpan = zSpan;
  8895. diameter1 = zMin;
  8896. diameter2 = zMax;
  8897. }
  8898. // Calculate the center of the initial sphere found by Ritter's algorithm
  8899. var ritterCenter = fromPointsRitterCenter;
  8900. ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
  8901. ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
  8902. ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
  8903. // Calculate the radius of the initial sphere found by Ritter's algorithm
  8904. var radiusSquared = Cartesian3.magnitudeSquared(Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch));
  8905. var ritterRadius = Math.sqrt(radiusSquared);
  8906. // Find the center of the sphere found using the Naive method.
  8907. var minBoxPt = fromPointsMinBoxPt;
  8908. minBoxPt.x = xMin.x;
  8909. minBoxPt.y = yMin.y;
  8910. minBoxPt.z = zMin.z;
  8911. var maxBoxPt = fromPointsMaxBoxPt;
  8912. maxBoxPt.x = xMax.x;
  8913. maxBoxPt.y = yMax.y;
  8914. maxBoxPt.z = zMax.z;
  8915. var naiveCenter = Cartesian3.multiplyByScalar(Cartesian3.add(minBoxPt, maxBoxPt, fromPointsScratch), 0.5, fromPointsNaiveCenterScratch);
  8916. // Begin 2nd pass to find naive radius and modify the ritter sphere.
  8917. var naiveRadius = 0;
  8918. for (i = 0; i < numPositions; i++) {
  8919. Cartesian3.clone(positions[i], currentPos);
  8920. // Find the furthest point from the naive center to calculate the naive radius.
  8921. var r = Cartesian3.magnitude(Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch));
  8922. if (r > naiveRadius) {
  8923. naiveRadius = r;
  8924. }
  8925. // Make adjustments to the Ritter Sphere to include all points.
  8926. var oldCenterToPointSquared = Cartesian3.magnitudeSquared(Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch));
  8927. if (oldCenterToPointSquared > radiusSquared) {
  8928. var oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
  8929. // Calculate new radius to include the point that lies outside
  8930. ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
  8931. radiusSquared = ritterRadius * ritterRadius;
  8932. // Calculate center of new Ritter sphere
  8933. var oldToNew = oldCenterToPoint - ritterRadius;
  8934. ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
  8935. ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
  8936. ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
  8937. }
  8938. }
  8939. if (ritterRadius < naiveRadius) {
  8940. Cartesian3.clone(ritterCenter, result.center);
  8941. result.radius = ritterRadius;
  8942. } else {
  8943. Cartesian3.clone(naiveCenter, result.center);
  8944. result.radius = naiveRadius;
  8945. }
  8946. return result;
  8947. };
  8948. var defaultProjection = new GeographicProjection();
  8949. var fromRectangle2DLowerLeft = new Cartesian3();
  8950. var fromRectangle2DUpperRight = new Cartesian3();
  8951. var fromRectangle2DSouthwest = new Cartographic();
  8952. var fromRectangle2DNortheast = new Cartographic();
  8953. /**
  8954. * Computes a bounding sphere from an rectangle projected in 2D.
  8955. *
  8956. * @param {Rectangle} rectangle The rectangle around which to create a bounding sphere.
  8957. * @param {Object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.
  8958. * @param {BoundingSphere} [result] The object onto which to store the result.
  8959. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  8960. */
  8961. BoundingSphere.fromRectangle2D = function(rectangle, projection, result) {
  8962. return BoundingSphere.fromRectangleWithHeights2D(rectangle, projection, 0.0, 0.0, result);
  8963. };
  8964. /**
  8965. * Computes a bounding sphere from an rectangle projected in 2D. The bounding sphere accounts for the
  8966. * object's minimum and maximum heights over the rectangle.
  8967. *
  8968. * @param {Rectangle} rectangle The rectangle around which to create a bounding sphere.
  8969. * @param {Object} [projection=GeographicProjection] The projection used to project the rectangle into 2D.
  8970. * @param {Number} [minimumHeight=0.0] The minimum height over the rectangle.
  8971. * @param {Number} [maximumHeight=0.0] The maximum height over the rectangle.
  8972. * @param {BoundingSphere} [result] The object onto which to store the result.
  8973. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  8974. */
  8975. BoundingSphere.fromRectangleWithHeights2D = function(rectangle, projection, minimumHeight, maximumHeight, result) {
  8976. if (!defined(result)) {
  8977. result = new BoundingSphere();
  8978. }
  8979. if (!defined(rectangle)) {
  8980. result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);
  8981. result.radius = 0.0;
  8982. return result;
  8983. }
  8984. projection = defaultValue(projection, defaultProjection);
  8985. Rectangle.southwest(rectangle, fromRectangle2DSouthwest);
  8986. fromRectangle2DSouthwest.height = minimumHeight;
  8987. Rectangle.northeast(rectangle, fromRectangle2DNortheast);
  8988. fromRectangle2DNortheast.height = maximumHeight;
  8989. var lowerLeft = projection.project(fromRectangle2DSouthwest, fromRectangle2DLowerLeft);
  8990. var upperRight = projection.project(fromRectangle2DNortheast, fromRectangle2DUpperRight);
  8991. var width = upperRight.x - lowerLeft.x;
  8992. var height = upperRight.y - lowerLeft.y;
  8993. var elevation = upperRight.z - lowerLeft.z;
  8994. result.radius = Math.sqrt(width * width + height * height + elevation * elevation) * 0.5;
  8995. var center = result.center;
  8996. center.x = lowerLeft.x + width * 0.5;
  8997. center.y = lowerLeft.y + height * 0.5;
  8998. center.z = lowerLeft.z + elevation * 0.5;
  8999. return result;
  9000. };
  9001. var fromRectangle3DScratch = [];
  9002. /**
  9003. * Computes a bounding sphere from an rectangle in 3D. The bounding sphere is created using a subsample of points
  9004. * on the ellipsoid and contained in the rectangle. It may not be accurate for all rectangles on all types of ellipsoids.
  9005. *
  9006. * @param {Rectangle} rectangle The valid rectangle used to create a bounding sphere.
  9007. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid used to determine positions of the rectangle.
  9008. * @param {Number} [surfaceHeight=0.0] The height above the surface of the ellipsoid.
  9009. * @param {BoundingSphere} [result] The object onto which to store the result.
  9010. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9011. */
  9012. BoundingSphere.fromRectangle3D = function(rectangle, ellipsoid, surfaceHeight, result) {
  9013. ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
  9014. surfaceHeight = defaultValue(surfaceHeight, 0.0);
  9015. var positions;
  9016. if (defined(rectangle)) {
  9017. positions = Rectangle.subsample(rectangle, ellipsoid, surfaceHeight, fromRectangle3DScratch);
  9018. }
  9019. return BoundingSphere.fromPoints(positions, result);
  9020. };
  9021. /**
  9022. * Computes a tight-fitting bounding sphere enclosing a list of 3D points, where the points are
  9023. * stored in a flat array in X, Y, Z, order. The bounding sphere is computed by running two
  9024. * algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to
  9025. * ensure a tight fit.
  9026. *
  9027. * @param {Number[]} positions An array of points that the bounding sphere will enclose. Each point
  9028. * is formed from three elements in the array in the order X, Y, Z.
  9029. * @param {Cartesian3} [center=Cartesian3.ZERO] The position to which the positions are relative, which need not be the
  9030. * origin of the coordinate system. This is useful when the positions are to be used for
  9031. * relative-to-center (RTC) rendering.
  9032. * @param {Number} [stride=3] The number of array elements per vertex. It must be at least 3, but it may
  9033. * be higher. Regardless of the value of this parameter, the X coordinate of the first position
  9034. * is at array index 0, the Y coordinate is at array index 1, and the Z coordinate is at array index
  9035. * 2. When stride is 3, the X coordinate of the next position then begins at array index 3. If
  9036. * the stride is 5, however, two array elements are skipped and the next position begins at array
  9037. * index 5.
  9038. * @param {BoundingSphere} [result] The object onto which to store the result.
  9039. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.
  9040. *
  9041. * @example
  9042. * // Compute the bounding sphere from 3 positions, each specified relative to a center.
  9043. * // In addition to the X, Y, and Z coordinates, the points array contains two additional
  9044. * // elements per point which are ignored for the purpose of computing the bounding sphere.
  9045. * var center = new Cesium.Cartesian3(1.0, 2.0, 3.0);
  9046. * var points = [1.0, 2.0, 3.0, 0.1, 0.2,
  9047. * 4.0, 5.0, 6.0, 0.1, 0.2,
  9048. * 7.0, 8.0, 9.0, 0.1, 0.2];
  9049. * var sphere = Cesium.BoundingSphere.fromVertices(points, center, 5);
  9050. *
  9051. * @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}
  9052. */
  9053. BoundingSphere.fromVertices = function(positions, center, stride, result) {
  9054. if (!defined(result)) {
  9055. result = new BoundingSphere();
  9056. }
  9057. if (!defined(positions) || positions.length === 0) {
  9058. result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);
  9059. result.radius = 0.0;
  9060. return result;
  9061. }
  9062. center = defaultValue(center, Cartesian3.ZERO);
  9063. stride = defaultValue(stride, 3);
  9064. if (stride < 3) {
  9065. throw new DeveloperError('stride must be 3 or greater.');
  9066. }
  9067. var currentPos = fromPointsCurrentPos;
  9068. currentPos.x = positions[0] + center.x;
  9069. currentPos.y = positions[1] + center.y;
  9070. currentPos.z = positions[2] + center.z;
  9071. var xMin = Cartesian3.clone(currentPos, fromPointsXMin);
  9072. var yMin = Cartesian3.clone(currentPos, fromPointsYMin);
  9073. var zMin = Cartesian3.clone(currentPos, fromPointsZMin);
  9074. var xMax = Cartesian3.clone(currentPos, fromPointsXMax);
  9075. var yMax = Cartesian3.clone(currentPos, fromPointsYMax);
  9076. var zMax = Cartesian3.clone(currentPos, fromPointsZMax);
  9077. var numElements = positions.length;
  9078. for (var i = 0; i < numElements; i += stride) {
  9079. var x = positions[i] + center.x;
  9080. var y = positions[i + 1] + center.y;
  9081. var z = positions[i + 2] + center.z;
  9082. currentPos.x = x;
  9083. currentPos.y = y;
  9084. currentPos.z = z;
  9085. // Store points containing the the smallest and largest components
  9086. if (x < xMin.x) {
  9087. Cartesian3.clone(currentPos, xMin);
  9088. }
  9089. if (x > xMax.x) {
  9090. Cartesian3.clone(currentPos, xMax);
  9091. }
  9092. if (y < yMin.y) {
  9093. Cartesian3.clone(currentPos, yMin);
  9094. }
  9095. if (y > yMax.y) {
  9096. Cartesian3.clone(currentPos, yMax);
  9097. }
  9098. if (z < zMin.z) {
  9099. Cartesian3.clone(currentPos, zMin);
  9100. }
  9101. if (z > zMax.z) {
  9102. Cartesian3.clone(currentPos, zMax);
  9103. }
  9104. }
  9105. // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).
  9106. var xSpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(xMax, xMin, fromPointsScratch));
  9107. var ySpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(yMax, yMin, fromPointsScratch));
  9108. var zSpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(zMax, zMin, fromPointsScratch));
  9109. // Set the diameter endpoints to the largest span.
  9110. var diameter1 = xMin;
  9111. var diameter2 = xMax;
  9112. var maxSpan = xSpan;
  9113. if (ySpan > maxSpan) {
  9114. maxSpan = ySpan;
  9115. diameter1 = yMin;
  9116. diameter2 = yMax;
  9117. }
  9118. if (zSpan > maxSpan) {
  9119. maxSpan = zSpan;
  9120. diameter1 = zMin;
  9121. diameter2 = zMax;
  9122. }
  9123. // Calculate the center of the initial sphere found by Ritter's algorithm
  9124. var ritterCenter = fromPointsRitterCenter;
  9125. ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
  9126. ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
  9127. ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
  9128. // Calculate the radius of the initial sphere found by Ritter's algorithm
  9129. var radiusSquared = Cartesian3.magnitudeSquared(Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch));
  9130. var ritterRadius = Math.sqrt(radiusSquared);
  9131. // Find the center of the sphere found using the Naive method.
  9132. var minBoxPt = fromPointsMinBoxPt;
  9133. minBoxPt.x = xMin.x;
  9134. minBoxPt.y = yMin.y;
  9135. minBoxPt.z = zMin.z;
  9136. var maxBoxPt = fromPointsMaxBoxPt;
  9137. maxBoxPt.x = xMax.x;
  9138. maxBoxPt.y = yMax.y;
  9139. maxBoxPt.z = zMax.z;
  9140. var naiveCenter = Cartesian3.multiplyByScalar(Cartesian3.add(minBoxPt, maxBoxPt, fromPointsScratch), 0.5, fromPointsNaiveCenterScratch);
  9141. // Begin 2nd pass to find naive radius and modify the ritter sphere.
  9142. var naiveRadius = 0;
  9143. for (i = 0; i < numElements; i += stride) {
  9144. currentPos.x = positions[i] + center.x;
  9145. currentPos.y = positions[i + 1] + center.y;
  9146. currentPos.z = positions[i + 2] + center.z;
  9147. // Find the furthest point from the naive center to calculate the naive radius.
  9148. var r = Cartesian3.magnitude(Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch));
  9149. if (r > naiveRadius) {
  9150. naiveRadius = r;
  9151. }
  9152. // Make adjustments to the Ritter Sphere to include all points.
  9153. var oldCenterToPointSquared = Cartesian3.magnitudeSquared(Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch));
  9154. if (oldCenterToPointSquared > radiusSquared) {
  9155. var oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
  9156. // Calculate new radius to include the point that lies outside
  9157. ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
  9158. radiusSquared = ritterRadius * ritterRadius;
  9159. // Calculate center of new Ritter sphere
  9160. var oldToNew = oldCenterToPoint - ritterRadius;
  9161. ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
  9162. ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
  9163. ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
  9164. }
  9165. }
  9166. if (ritterRadius < naiveRadius) {
  9167. Cartesian3.clone(ritterCenter, result.center);
  9168. result.radius = ritterRadius;
  9169. } else {
  9170. Cartesian3.clone(naiveCenter, result.center);
  9171. result.radius = naiveRadius;
  9172. }
  9173. return result;
  9174. };
  9175. /**
  9176. * Computes a tight-fitting bounding sphere enclosing a list of {@link EncodedCartesian3}s, where the points are
  9177. * stored in parallel flat arrays in X, Y, Z, order. The bounding sphere is computed by running two
  9178. * algorithms, a naive algorithm and Ritter's algorithm. The smaller of the two spheres is used to
  9179. * ensure a tight fit.
  9180. *
  9181. * @param {Number[]} positionsHigh An array of high bits of the encoded cartesians that the bounding sphere will enclose. Each point
  9182. * is formed from three elements in the array in the order X, Y, Z.
  9183. * @param {Number[]} positionsLow An array of low bits of the encoded cartesians that the bounding sphere will enclose. Each point
  9184. * is formed from three elements in the array in the order X, Y, Z.
  9185. * @param {BoundingSphere} [result] The object onto which to store the result.
  9186. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.
  9187. *
  9188. * @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}
  9189. */
  9190. BoundingSphere.fromEncodedCartesianVertices = function(positionsHigh, positionsLow, result) {
  9191. if (!defined(result)) {
  9192. result = new BoundingSphere();
  9193. }
  9194. if (!defined(positionsHigh) || !defined(positionsLow) || positionsHigh.length !== positionsLow.length || positionsHigh.length === 0) {
  9195. result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);
  9196. result.radius = 0.0;
  9197. return result;
  9198. }
  9199. var currentPos = fromPointsCurrentPos;
  9200. currentPos.x = positionsHigh[0] + positionsLow[0];
  9201. currentPos.y = positionsHigh[1] + positionsLow[1];
  9202. currentPos.z = positionsHigh[2] + positionsLow[2];
  9203. var xMin = Cartesian3.clone(currentPos, fromPointsXMin);
  9204. var yMin = Cartesian3.clone(currentPos, fromPointsYMin);
  9205. var zMin = Cartesian3.clone(currentPos, fromPointsZMin);
  9206. var xMax = Cartesian3.clone(currentPos, fromPointsXMax);
  9207. var yMax = Cartesian3.clone(currentPos, fromPointsYMax);
  9208. var zMax = Cartesian3.clone(currentPos, fromPointsZMax);
  9209. var numElements = positionsHigh.length;
  9210. for (var i = 0; i < numElements; i += 3) {
  9211. var x = positionsHigh[i] + positionsLow[i];
  9212. var y = positionsHigh[i + 1] + positionsLow[i + 1];
  9213. var z = positionsHigh[i + 2] + positionsLow[i + 2];
  9214. currentPos.x = x;
  9215. currentPos.y = y;
  9216. currentPos.z = z;
  9217. // Store points containing the the smallest and largest components
  9218. if (x < xMin.x) {
  9219. Cartesian3.clone(currentPos, xMin);
  9220. }
  9221. if (x > xMax.x) {
  9222. Cartesian3.clone(currentPos, xMax);
  9223. }
  9224. if (y < yMin.y) {
  9225. Cartesian3.clone(currentPos, yMin);
  9226. }
  9227. if (y > yMax.y) {
  9228. Cartesian3.clone(currentPos, yMax);
  9229. }
  9230. if (z < zMin.z) {
  9231. Cartesian3.clone(currentPos, zMin);
  9232. }
  9233. if (z > zMax.z) {
  9234. Cartesian3.clone(currentPos, zMax);
  9235. }
  9236. }
  9237. // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).
  9238. var xSpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(xMax, xMin, fromPointsScratch));
  9239. var ySpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(yMax, yMin, fromPointsScratch));
  9240. var zSpan = Cartesian3.magnitudeSquared(Cartesian3.subtract(zMax, zMin, fromPointsScratch));
  9241. // Set the diameter endpoints to the largest span.
  9242. var diameter1 = xMin;
  9243. var diameter2 = xMax;
  9244. var maxSpan = xSpan;
  9245. if (ySpan > maxSpan) {
  9246. maxSpan = ySpan;
  9247. diameter1 = yMin;
  9248. diameter2 = yMax;
  9249. }
  9250. if (zSpan > maxSpan) {
  9251. maxSpan = zSpan;
  9252. diameter1 = zMin;
  9253. diameter2 = zMax;
  9254. }
  9255. // Calculate the center of the initial sphere found by Ritter's algorithm
  9256. var ritterCenter = fromPointsRitterCenter;
  9257. ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
  9258. ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
  9259. ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
  9260. // Calculate the radius of the initial sphere found by Ritter's algorithm
  9261. var radiusSquared = Cartesian3.magnitudeSquared(Cartesian3.subtract(diameter2, ritterCenter, fromPointsScratch));
  9262. var ritterRadius = Math.sqrt(radiusSquared);
  9263. // Find the center of the sphere found using the Naive method.
  9264. var minBoxPt = fromPointsMinBoxPt;
  9265. minBoxPt.x = xMin.x;
  9266. minBoxPt.y = yMin.y;
  9267. minBoxPt.z = zMin.z;
  9268. var maxBoxPt = fromPointsMaxBoxPt;
  9269. maxBoxPt.x = xMax.x;
  9270. maxBoxPt.y = yMax.y;
  9271. maxBoxPt.z = zMax.z;
  9272. var naiveCenter = Cartesian3.multiplyByScalar(Cartesian3.add(minBoxPt, maxBoxPt, fromPointsScratch), 0.5, fromPointsNaiveCenterScratch);
  9273. // Begin 2nd pass to find naive radius and modify the ritter sphere.
  9274. var naiveRadius = 0;
  9275. for (i = 0; i < numElements; i += 3) {
  9276. currentPos.x = positionsHigh[i] + positionsLow[i];
  9277. currentPos.y = positionsHigh[i + 1] + positionsLow[i + 1];
  9278. currentPos.z = positionsHigh[i + 2] + positionsLow[i + 2];
  9279. // Find the furthest point from the naive center to calculate the naive radius.
  9280. var r = Cartesian3.magnitude(Cartesian3.subtract(currentPos, naiveCenter, fromPointsScratch));
  9281. if (r > naiveRadius) {
  9282. naiveRadius = r;
  9283. }
  9284. // Make adjustments to the Ritter Sphere to include all points.
  9285. var oldCenterToPointSquared = Cartesian3.magnitudeSquared(Cartesian3.subtract(currentPos, ritterCenter, fromPointsScratch));
  9286. if (oldCenterToPointSquared > radiusSquared) {
  9287. var oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
  9288. // Calculate new radius to include the point that lies outside
  9289. ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
  9290. radiusSquared = ritterRadius * ritterRadius;
  9291. // Calculate center of new Ritter sphere
  9292. var oldToNew = oldCenterToPoint - ritterRadius;
  9293. ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
  9294. ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
  9295. ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
  9296. }
  9297. }
  9298. if (ritterRadius < naiveRadius) {
  9299. Cartesian3.clone(ritterCenter, result.center);
  9300. result.radius = ritterRadius;
  9301. } else {
  9302. Cartesian3.clone(naiveCenter, result.center);
  9303. result.radius = naiveRadius;
  9304. }
  9305. return result;
  9306. };
  9307. /**
  9308. * Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere
  9309. * tighly and fully encompases the box.
  9310. *
  9311. * @param {Cartesian3} [corner] The minimum height over the rectangle.
  9312. * @param {Cartesian3} [oppositeCorner] The maximum height over the rectangle.
  9313. * @param {BoundingSphere} [result] The object onto which to store the result.
  9314. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9315. *
  9316. * @example
  9317. * // Create a bounding sphere around the unit cube
  9318. * var sphere = Cesium.BoundingSphere.fromCornerPoints(new Cesium.Cartesian3(-0.5, -0.5, -0.5), new Cesium.Cartesian3(0.5, 0.5, 0.5));
  9319. */
  9320. BoundingSphere.fromCornerPoints = function(corner, oppositeCorner, result) {
  9321. if (!defined(corner) || !defined(oppositeCorner)) {
  9322. throw new DeveloperError('corner and oppositeCorner are required.');
  9323. }
  9324. if (!defined(result)) {
  9325. result = new BoundingSphere();
  9326. }
  9327. var center = result.center;
  9328. Cartesian3.add(corner, oppositeCorner, center);
  9329. Cartesian3.multiplyByScalar(center, 0.5, center);
  9330. result.radius = Cartesian3.distance(center, oppositeCorner);
  9331. return result;
  9332. };
  9333. /**
  9334. * Creates a bounding sphere encompassing an ellipsoid.
  9335. *
  9336. * @param {Ellipsoid} ellipsoid The ellipsoid around which to create a bounding sphere.
  9337. * @param {BoundingSphere} [result] The object onto which to store the result.
  9338. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9339. *
  9340. * @example
  9341. * var boundingSphere = Cesium.BoundingSphere.fromEllipsoid(ellipsoid);
  9342. */
  9343. BoundingSphere.fromEllipsoid = function(ellipsoid, result) {
  9344. if (!defined(ellipsoid)) {
  9345. throw new DeveloperError('ellipsoid is required.');
  9346. }
  9347. if (!defined(result)) {
  9348. result = new BoundingSphere();
  9349. }
  9350. Cartesian3.clone(Cartesian3.ZERO, result.center);
  9351. result.radius = ellipsoid.maximumRadius;
  9352. return result;
  9353. };
  9354. var fromBoundingSpheresScratch = new Cartesian3();
  9355. /**
  9356. * Computes a tight-fitting bounding sphere enclosing the provided array of bounding spheres.
  9357. *
  9358. * @param {BoundingSphere[]} boundingSpheres The array of bounding spheres.
  9359. * @param {BoundingSphere} [result] The object onto which to store the result.
  9360. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9361. */
  9362. BoundingSphere.fromBoundingSpheres = function(boundingSpheres, result) {
  9363. if (!defined(result)) {
  9364. result = new BoundingSphere();
  9365. }
  9366. if (!defined(boundingSpheres) || boundingSpheres.length === 0) {
  9367. result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);
  9368. result.radius = 0.0;
  9369. return result;
  9370. }
  9371. var length = boundingSpheres.length;
  9372. if (length === 1) {
  9373. return BoundingSphere.clone(boundingSpheres[0], result);
  9374. }
  9375. if (length === 2) {
  9376. return BoundingSphere.union(boundingSpheres[0], boundingSpheres[1], result);
  9377. }
  9378. var positions = [];
  9379. for (var i = 0; i < length; i++) {
  9380. positions.push(boundingSpheres[i].center);
  9381. }
  9382. result = BoundingSphere.fromPoints(positions, result);
  9383. var center = result.center;
  9384. var radius = result.radius;
  9385. for (i = 0; i < length; i++) {
  9386. var tmp = boundingSpheres[i];
  9387. radius = Math.max(radius, Cartesian3.distance(center, tmp.center, fromBoundingSpheresScratch) + tmp.radius);
  9388. }
  9389. result.radius = radius;
  9390. return result;
  9391. };
  9392. var fromOrientedBoundingBoxScratchU = new Cartesian3();
  9393. var fromOrientedBoundingBoxScratchV = new Cartesian3();
  9394. var fromOrientedBoundingBoxScratchW = new Cartesian3();
  9395. /**
  9396. * Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box.
  9397. *
  9398. * @param {OrientedBoundingBox} orientedBoundingBox The oriented bounding box.
  9399. * @param {BoundingSphere} [result] The object onto which to store the result.
  9400. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9401. */
  9402. BoundingSphere.fromOrientedBoundingBox = function(orientedBoundingBox, result) {
  9403. if (!defined(result)) {
  9404. result = new BoundingSphere();
  9405. }
  9406. var halfAxes = orientedBoundingBox.halfAxes;
  9407. var u = Matrix3.getColumn(halfAxes, 0, fromOrientedBoundingBoxScratchU);
  9408. var v = Matrix3.getColumn(halfAxes, 1, fromOrientedBoundingBoxScratchV);
  9409. var w = Matrix3.getColumn(halfAxes, 2, fromOrientedBoundingBoxScratchW);
  9410. var uHalf = Cartesian3.magnitude(u);
  9411. var vHalf = Cartesian3.magnitude(v);
  9412. var wHalf = Cartesian3.magnitude(w);
  9413. result.center = Cartesian3.clone(orientedBoundingBox.center, result.center);
  9414. result.radius = Math.max(uHalf, vHalf, wHalf);
  9415. return result;
  9416. };
  9417. /**
  9418. * Duplicates a BoundingSphere instance.
  9419. *
  9420. * @param {BoundingSphere} sphere The bounding sphere to duplicate.
  9421. * @param {BoundingSphere} [result] The object onto which to store the result.
  9422. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided. (Returns undefined if sphere is undefined)
  9423. */
  9424. BoundingSphere.clone = function(sphere, result) {
  9425. if (!defined(sphere)) {
  9426. return undefined;
  9427. }
  9428. if (!defined(result)) {
  9429. return new BoundingSphere(sphere.center, sphere.radius);
  9430. }
  9431. result.center = Cartesian3.clone(sphere.center, result.center);
  9432. result.radius = sphere.radius;
  9433. return result;
  9434. };
  9435. /**
  9436. * The number of elements used to pack the object into an array.
  9437. * @type {Number}
  9438. */
  9439. BoundingSphere.packedLength = 4;
  9440. /**
  9441. * Stores the provided instance into the provided array.
  9442. *
  9443. * @param {BoundingSphere} value The value to pack.
  9444. * @param {Number[]} array The array to pack into.
  9445. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  9446. *
  9447. * @returns {Number[]} The array that was packed into
  9448. */
  9449. BoundingSphere.pack = function(value, array, startingIndex) {
  9450. if (!defined(value)) {
  9451. throw new DeveloperError('value is required');
  9452. }
  9453. if (!defined(array)) {
  9454. throw new DeveloperError('array is required');
  9455. }
  9456. startingIndex = defaultValue(startingIndex, 0);
  9457. var center = value.center;
  9458. array[startingIndex++] = center.x;
  9459. array[startingIndex++] = center.y;
  9460. array[startingIndex++] = center.z;
  9461. array[startingIndex] = value.radius;
  9462. return array;
  9463. };
  9464. /**
  9465. * Retrieves an instance from a packed array.
  9466. *
  9467. * @param {Number[]} array The packed array.
  9468. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  9469. * @param {BoundingSphere} [result] The object into which to store the result.
  9470. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if one was not provided.
  9471. */
  9472. BoundingSphere.unpack = function(array, startingIndex, result) {
  9473. if (!defined(array)) {
  9474. throw new DeveloperError('array is required');
  9475. }
  9476. startingIndex = defaultValue(startingIndex, 0);
  9477. if (!defined(result)) {
  9478. result = new BoundingSphere();
  9479. }
  9480. var center = result.center;
  9481. center.x = array[startingIndex++];
  9482. center.y = array[startingIndex++];
  9483. center.z = array[startingIndex++];
  9484. result.radius = array[startingIndex];
  9485. return result;
  9486. };
  9487. var unionScratch = new Cartesian3();
  9488. var unionScratchCenter = new Cartesian3();
  9489. /**
  9490. * Computes a bounding sphere that contains both the left and right bounding spheres.
  9491. *
  9492. * @param {BoundingSphere} left A sphere to enclose in a bounding sphere.
  9493. * @param {BoundingSphere} right A sphere to enclose in a bounding sphere.
  9494. * @param {BoundingSphere} [result] The object onto which to store the result.
  9495. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9496. */
  9497. BoundingSphere.union = function(left, right, result) {
  9498. if (!defined(left)) {
  9499. throw new DeveloperError('left is required.');
  9500. }
  9501. if (!defined(right)) {
  9502. throw new DeveloperError('right is required.');
  9503. }
  9504. if (!defined(result)) {
  9505. result = new BoundingSphere();
  9506. }
  9507. var leftCenter = left.center;
  9508. var leftRadius = left.radius;
  9509. var rightCenter = right.center;
  9510. var rightRadius = right.radius;
  9511. var toRightCenter = Cartesian3.subtract(rightCenter, leftCenter, unionScratch);
  9512. var centerSeparation = Cartesian3.magnitude(toRightCenter);
  9513. if (leftRadius >= (centerSeparation + rightRadius)) {
  9514. // Left sphere wins.
  9515. left.clone(result);
  9516. return result;
  9517. }
  9518. if (rightRadius >= (centerSeparation + leftRadius)) {
  9519. // Right sphere wins.
  9520. right.clone(result);
  9521. return result;
  9522. }
  9523. // There are two tangent points, one on far side of each sphere.
  9524. var halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;
  9525. // Compute the center point halfway between the two tangent points.
  9526. var center = Cartesian3.multiplyByScalar(toRightCenter,
  9527. (-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation, unionScratchCenter);
  9528. Cartesian3.add(center, leftCenter, center);
  9529. Cartesian3.clone(center, result.center);
  9530. result.radius = halfDistanceBetweenTangentPoints;
  9531. return result;
  9532. };
  9533. var expandScratch = new Cartesian3();
  9534. /**
  9535. * Computes a bounding sphere by enlarging the provided sphere to contain the provided point.
  9536. *
  9537. * @param {BoundingSphere} sphere A sphere to expand.
  9538. * @param {Cartesian3} point A point to enclose in a bounding sphere.
  9539. * @param {BoundingSphere} [result] The object onto which to store the result.
  9540. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9541. */
  9542. BoundingSphere.expand = function(sphere, point, result) {
  9543. if (!defined(sphere)) {
  9544. throw new DeveloperError('sphere is required.');
  9545. }
  9546. if (!defined(point)) {
  9547. throw new DeveloperError('point is required.');
  9548. }
  9549. result = BoundingSphere.clone(sphere, result);
  9550. var radius = Cartesian3.magnitude(Cartesian3.subtract(point, result.center, expandScratch));
  9551. if (radius > result.radius) {
  9552. result.radius = radius;
  9553. }
  9554. return result;
  9555. };
  9556. /**
  9557. * Determines which side of a plane a sphere is located.
  9558. *
  9559. * @param {BoundingSphere} sphere The bounding sphere to test.
  9560. * @param {Plane} plane The plane to test against.
  9561. * @returns {Intersect} {@link Intersect.INSIDE} if the entire sphere is on the side of the plane
  9562. * the normal is pointing, {@link Intersect.OUTSIDE} if the entire sphere is
  9563. * on the opposite side, and {@link Intersect.INTERSECTING} if the sphere
  9564. * intersects the plane.
  9565. */
  9566. BoundingSphere.intersectPlane = function(sphere, plane) {
  9567. if (!defined(sphere)) {
  9568. throw new DeveloperError('sphere is required.');
  9569. }
  9570. if (!defined(plane)) {
  9571. throw new DeveloperError('plane is required.');
  9572. }
  9573. var center = sphere.center;
  9574. var radius = sphere.radius;
  9575. var normal = plane.normal;
  9576. var distanceToPlane = Cartesian3.dot(normal, center) + plane.distance;
  9577. if (distanceToPlane < -radius) {
  9578. // The center point is negative side of the plane normal
  9579. return Intersect.OUTSIDE;
  9580. } else if (distanceToPlane < radius) {
  9581. // The center point is positive side of the plane, but radius extends beyond it; partial overlap
  9582. return Intersect.INTERSECTING;
  9583. }
  9584. return Intersect.INSIDE;
  9585. };
  9586. /**
  9587. * Applies a 4x4 affine transformation matrix to a bounding sphere.
  9588. *
  9589. * @param {BoundingSphere} sphere The bounding sphere to apply the transformation to.
  9590. * @param {Matrix4} transform The transformation matrix to apply to the bounding sphere.
  9591. * @param {BoundingSphere} [result] The object onto which to store the result.
  9592. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9593. */
  9594. BoundingSphere.transform = function(sphere, transform, result) {
  9595. if (!defined(sphere)) {
  9596. throw new DeveloperError('sphere is required.');
  9597. }
  9598. if (!defined(transform)) {
  9599. throw new DeveloperError('transform is required.');
  9600. }
  9601. if (!defined(result)) {
  9602. result = new BoundingSphere();
  9603. }
  9604. result.center = Matrix4.multiplyByPoint(transform, sphere.center, result.center);
  9605. result.radius = Matrix4.getMaximumScale(transform) * sphere.radius;
  9606. return result;
  9607. };
  9608. var distanceSquaredToScratch = new Cartesian3();
  9609. /**
  9610. * Computes the estimated distance squared from the closest point on a bounding sphere to a point.
  9611. *
  9612. * @param {BoundingSphere} sphere The sphere.
  9613. * @param {Cartesian3} cartesian The point
  9614. * @returns {Number} The estimated distance squared from the bounding sphere to the point.
  9615. *
  9616. * @example
  9617. * // Sort bounding spheres from back to front
  9618. * spheres.sort(function(a, b) {
  9619. * return Cesium.BoundingSphere.distanceSquaredTo(b, camera.positionWC) - Cesium.BoundingSphere.distanceSquaredTo(a, camera.positionWC);
  9620. * });
  9621. */
  9622. BoundingSphere.distanceSquaredTo = function(sphere, cartesian) {
  9623. if (!defined(sphere)) {
  9624. throw new DeveloperError('sphere is required.');
  9625. }
  9626. if (!defined(cartesian)) {
  9627. throw new DeveloperError('cartesian is required.');
  9628. }
  9629. var diff = Cartesian3.subtract(sphere.center, cartesian, distanceSquaredToScratch);
  9630. return Cartesian3.magnitudeSquared(diff) - sphere.radius * sphere.radius;
  9631. };
  9632. /**
  9633. * Applies a 4x4 affine transformation matrix to a bounding sphere where there is no scale
  9634. * The transformation matrix is not verified to have a uniform scale of 1.
  9635. * This method is faster than computing the general bounding sphere transform using {@link BoundingSphere.transform}.
  9636. *
  9637. * @param {BoundingSphere} sphere The bounding sphere to apply the transformation to.
  9638. * @param {Matrix4} transform The transformation matrix to apply to the bounding sphere.
  9639. * @param {BoundingSphere} [result] The object onto which to store the result.
  9640. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9641. *
  9642. * @example
  9643. * var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid);
  9644. * var boundingSphere = new Cesium.BoundingSphere();
  9645. * var newBoundingSphere = Cesium.BoundingSphere.transformWithoutScale(boundingSphere, modelMatrix);
  9646. */
  9647. BoundingSphere.transformWithoutScale = function(sphere, transform, result) {
  9648. if (!defined(sphere)) {
  9649. throw new DeveloperError('sphere is required.');
  9650. }
  9651. if (!defined(transform)) {
  9652. throw new DeveloperError('transform is required.');
  9653. }
  9654. if (!defined(result)) {
  9655. result = new BoundingSphere();
  9656. }
  9657. result.center = Matrix4.multiplyByPoint(transform, sphere.center, result.center);
  9658. result.radius = sphere.radius;
  9659. return result;
  9660. };
  9661. var scratchCartesian3 = new Cartesian3();
  9662. /**
  9663. * The distances calculated by the vector from the center of the bounding sphere to position projected onto direction
  9664. * plus/minus the radius of the bounding sphere.
  9665. * <br>
  9666. * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the
  9667. * closest and farthest planes from position that intersect the bounding sphere.
  9668. *
  9669. * @param {BoundingSphere} sphere The bounding sphere to calculate the distance to.
  9670. * @param {Cartesian3} position The position to calculate the distance from.
  9671. * @param {Cartesian3} direction The direction from position.
  9672. * @param {Interval} [result] A Interval to store the nearest and farthest distances.
  9673. * @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.
  9674. */
  9675. BoundingSphere.computePlaneDistances = function(sphere, position, direction, result) {
  9676. if (!defined(sphere)) {
  9677. throw new DeveloperError('sphere is required.');
  9678. }
  9679. if (!defined(position)) {
  9680. throw new DeveloperError('position is required.');
  9681. }
  9682. if (!defined(direction)) {
  9683. throw new DeveloperError('direction is required.');
  9684. }
  9685. if (!defined(result)) {
  9686. result = new Interval();
  9687. }
  9688. var toCenter = Cartesian3.subtract(sphere.center, position, scratchCartesian3);
  9689. var mag = Cartesian3.dot(direction, toCenter);
  9690. result.start = mag - sphere.radius;
  9691. result.stop = mag + sphere.radius;
  9692. return result;
  9693. };
  9694. var projectTo2DNormalScratch = new Cartesian3();
  9695. var projectTo2DEastScratch = new Cartesian3();
  9696. var projectTo2DNorthScratch = new Cartesian3();
  9697. var projectTo2DWestScratch = new Cartesian3();
  9698. var projectTo2DSouthScratch = new Cartesian3();
  9699. var projectTo2DCartographicScratch = new Cartographic();
  9700. var projectTo2DPositionsScratch = new Array(8);
  9701. for (var n = 0; n < 8; ++n) {
  9702. projectTo2DPositionsScratch[n] = new Cartesian3();
  9703. }
  9704. var projectTo2DProjection = new GeographicProjection();
  9705. /**
  9706. * Creates a bounding sphere in 2D from a bounding sphere in 3D world coordinates.
  9707. *
  9708. * @param {BoundingSphere} sphere The bounding sphere to transform to 2D.
  9709. * @param {Object} [projection=GeographicProjection] The projection to 2D.
  9710. * @param {BoundingSphere} [result] The object onto which to store the result.
  9711. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9712. */
  9713. BoundingSphere.projectTo2D = function(sphere, projection, result) {
  9714. if (!defined(sphere)) {
  9715. throw new DeveloperError('sphere is required.');
  9716. }
  9717. projection = defaultValue(projection, projectTo2DProjection);
  9718. var ellipsoid = projection.ellipsoid;
  9719. var center = sphere.center;
  9720. var radius = sphere.radius;
  9721. var normal = ellipsoid.geodeticSurfaceNormal(center, projectTo2DNormalScratch);
  9722. var east = Cartesian3.cross(Cartesian3.UNIT_Z, normal, projectTo2DEastScratch);
  9723. Cartesian3.normalize(east, east);
  9724. var north = Cartesian3.cross(normal, east, projectTo2DNorthScratch);
  9725. Cartesian3.normalize(north, north);
  9726. Cartesian3.multiplyByScalar(normal, radius, normal);
  9727. Cartesian3.multiplyByScalar(north, radius, north);
  9728. Cartesian3.multiplyByScalar(east, radius, east);
  9729. var south = Cartesian3.negate(north, projectTo2DSouthScratch);
  9730. var west = Cartesian3.negate(east, projectTo2DWestScratch);
  9731. var positions = projectTo2DPositionsScratch;
  9732. // top NE corner
  9733. var corner = positions[0];
  9734. Cartesian3.add(normal, north, corner);
  9735. Cartesian3.add(corner, east, corner);
  9736. // top NW corner
  9737. corner = positions[1];
  9738. Cartesian3.add(normal, north, corner);
  9739. Cartesian3.add(corner, west, corner);
  9740. // top SW corner
  9741. corner = positions[2];
  9742. Cartesian3.add(normal, south, corner);
  9743. Cartesian3.add(corner, west, corner);
  9744. // top SE corner
  9745. corner = positions[3];
  9746. Cartesian3.add(normal, south, corner);
  9747. Cartesian3.add(corner, east, corner);
  9748. Cartesian3.negate(normal, normal);
  9749. // bottom NE corner
  9750. corner = positions[4];
  9751. Cartesian3.add(normal, north, corner);
  9752. Cartesian3.add(corner, east, corner);
  9753. // bottom NW corner
  9754. corner = positions[5];
  9755. Cartesian3.add(normal, north, corner);
  9756. Cartesian3.add(corner, west, corner);
  9757. // bottom SW corner
  9758. corner = positions[6];
  9759. Cartesian3.add(normal, south, corner);
  9760. Cartesian3.add(corner, west, corner);
  9761. // bottom SE corner
  9762. corner = positions[7];
  9763. Cartesian3.add(normal, south, corner);
  9764. Cartesian3.add(corner, east, corner);
  9765. var length = positions.length;
  9766. for (var i = 0; i < length; ++i) {
  9767. var position = positions[i];
  9768. Cartesian3.add(center, position, position);
  9769. var cartographic = ellipsoid.cartesianToCartographic(position, projectTo2DCartographicScratch);
  9770. projection.project(cartographic, position);
  9771. }
  9772. result = BoundingSphere.fromPoints(positions, result);
  9773. // swizzle center components
  9774. center = result.center;
  9775. var x = center.x;
  9776. var y = center.y;
  9777. var z = center.z;
  9778. center.x = z;
  9779. center.y = x;
  9780. center.z = y;
  9781. return result;
  9782. };
  9783. /**
  9784. * Determines whether or not a sphere is hidden from view by the occluder.
  9785. *
  9786. * @param {BoundingSphere} sphere The bounding sphere surrounding the occludee object.
  9787. * @param {Occluder} occluder The occluder.
  9788. * @returns {Boolean} <code>true</code> if the sphere is not visible; otherwise <code>false</code>.
  9789. */
  9790. BoundingSphere.isOccluded = function(sphere, occluder) {
  9791. if (!defined(sphere)) {
  9792. throw new DeveloperError('sphere is required.');
  9793. }
  9794. if (!defined(occluder)) {
  9795. throw new DeveloperError('occluder is required.');
  9796. }
  9797. return !occluder.isBoundingSphereVisible(sphere);
  9798. };
  9799. /**
  9800. * Compares the provided BoundingSphere componentwise and returns
  9801. * <code>true</code> if they are equal, <code>false</code> otherwise.
  9802. *
  9803. * @param {BoundingSphere} [left] The first BoundingSphere.
  9804. * @param {BoundingSphere} [right] The second BoundingSphere.
  9805. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  9806. */
  9807. BoundingSphere.equals = function(left, right) {
  9808. return (left === right) ||
  9809. ((defined(left)) &&
  9810. (defined(right)) &&
  9811. Cartesian3.equals(left.center, right.center) &&
  9812. left.radius === right.radius);
  9813. };
  9814. /**
  9815. * Determines which side of a plane the sphere is located.
  9816. *
  9817. * @param {Plane} plane The plane to test against.
  9818. * @returns {Intersect} {@link Intersect.INSIDE} if the entire sphere is on the side of the plane
  9819. * the normal is pointing, {@link Intersect.OUTSIDE} if the entire sphere is
  9820. * on the opposite side, and {@link Intersect.INTERSECTING} if the sphere
  9821. * intersects the plane.
  9822. */
  9823. BoundingSphere.prototype.intersectPlane = function(plane) {
  9824. return BoundingSphere.intersectPlane(this, plane);
  9825. };
  9826. /**
  9827. * Computes the estimated distance squared from the closest point on a bounding sphere to a point.
  9828. *
  9829. * @param {Cartesian3} cartesian The point
  9830. * @returns {Number} The estimated distance squared from the bounding sphere to the point.
  9831. *
  9832. * @example
  9833. * // Sort bounding spheres from back to front
  9834. * spheres.sort(function(a, b) {
  9835. * return b.distanceSquaredTo(camera.positionWC) - a.distanceSquaredTo(camera.positionWC);
  9836. * });
  9837. */
  9838. BoundingSphere.prototype.distanceSquaredTo = function(cartesian) {
  9839. return BoundingSphere.distanceSquaredTo(this, cartesian);
  9840. };
  9841. /**
  9842. * The distances calculated by the vector from the center of the bounding sphere to position projected onto direction
  9843. * plus/minus the radius of the bounding sphere.
  9844. * <br>
  9845. * If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the
  9846. * closest and farthest planes from position that intersect the bounding sphere.
  9847. *
  9848. * @param {Cartesian3} position The position to calculate the distance from.
  9849. * @param {Cartesian3} direction The direction from position.
  9850. * @param {Interval} [result] A Interval to store the nearest and farthest distances.
  9851. * @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.
  9852. */
  9853. BoundingSphere.prototype.computePlaneDistances = function(position, direction, result) {
  9854. return BoundingSphere.computePlaneDistances(this, position, direction, result);
  9855. };
  9856. /**
  9857. * Determines whether or not a sphere is hidden from view by the occluder.
  9858. *
  9859. * @param {Occluder} occluder The occluder.
  9860. * @returns {Boolean} <code>true</code> if the sphere is not visible; otherwise <code>false</code>.
  9861. */
  9862. BoundingSphere.prototype.isOccluded = function(occluder) {
  9863. return BoundingSphere.isOccluded(this, occluder);
  9864. };
  9865. /**
  9866. * Compares this BoundingSphere against the provided BoundingSphere componentwise and returns
  9867. * <code>true</code> if they are equal, <code>false</code> otherwise.
  9868. *
  9869. * @param {BoundingSphere} [right] The right hand side BoundingSphere.
  9870. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  9871. */
  9872. BoundingSphere.prototype.equals = function(right) {
  9873. return BoundingSphere.equals(this, right);
  9874. };
  9875. /**
  9876. * Duplicates this BoundingSphere instance.
  9877. *
  9878. * @param {BoundingSphere} [result] The object onto which to store the result.
  9879. * @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
  9880. */
  9881. BoundingSphere.prototype.clone = function(result) {
  9882. return BoundingSphere.clone(this, result);
  9883. };
  9884. return BoundingSphere;
  9885. });
  9886. /*global define*/
  9887. define('Core/Fullscreen',[
  9888. './defined',
  9889. './defineProperties'
  9890. ], function(
  9891. defined,
  9892. defineProperties) {
  9893. 'use strict';
  9894. var _supportsFullscreen;
  9895. var _names = {
  9896. requestFullscreen : undefined,
  9897. exitFullscreen : undefined,
  9898. fullscreenEnabled : undefined,
  9899. fullscreenElement : undefined,
  9900. fullscreenchange : undefined,
  9901. fullscreenerror : undefined
  9902. };
  9903. /**
  9904. * Browser-independent functions for working with the standard fullscreen API.
  9905. *
  9906. * @exports Fullscreen
  9907. *
  9908. * @see {@link http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html|W3C Fullscreen Living Specification}
  9909. */
  9910. var Fullscreen = {};
  9911. defineProperties(Fullscreen, {
  9912. /**
  9913. * The element that is currently fullscreen, if any. To simply check if the
  9914. * browser is in fullscreen mode or not, use {@link Fullscreen#fullscreen}.
  9915. * @memberof Fullscreen
  9916. * @type {Object}
  9917. * @readonly
  9918. */
  9919. element : {
  9920. get : function() {
  9921. if (!Fullscreen.supportsFullscreen()) {
  9922. return undefined;
  9923. }
  9924. return document[_names.fullscreenElement];
  9925. }
  9926. },
  9927. /**
  9928. * The name of the event on the document that is fired when fullscreen is
  9929. * entered or exited. This event name is intended for use with addEventListener.
  9930. * In your event handler, to determine if the browser is in fullscreen mode or not,
  9931. * use {@link Fullscreen#fullscreen}.
  9932. * @memberof Fullscreen
  9933. * @type {String}
  9934. * @readonly
  9935. */
  9936. changeEventName : {
  9937. get : function() {
  9938. if (!Fullscreen.supportsFullscreen()) {
  9939. return undefined;
  9940. }
  9941. return _names.fullscreenchange;
  9942. }
  9943. },
  9944. /**
  9945. * The name of the event that is fired when a fullscreen error
  9946. * occurs. This event name is intended for use with addEventListener.
  9947. * @memberof Fullscreen
  9948. * @type {String}
  9949. * @readonly
  9950. */
  9951. errorEventName : {
  9952. get : function() {
  9953. if (!Fullscreen.supportsFullscreen()) {
  9954. return undefined;
  9955. }
  9956. return _names.fullscreenerror;
  9957. }
  9958. },
  9959. /**
  9960. * Determine whether the browser will allow an element to be made fullscreen, or not.
  9961. * For example, by default, iframes cannot go fullscreen unless the containing page
  9962. * adds an "allowfullscreen" attribute (or prefixed equivalent).
  9963. * @memberof Fullscreen
  9964. * @type {Boolean}
  9965. * @readonly
  9966. */
  9967. enabled : {
  9968. get : function() {
  9969. if (!Fullscreen.supportsFullscreen()) {
  9970. return undefined;
  9971. }
  9972. return document[_names.fullscreenEnabled];
  9973. }
  9974. },
  9975. /**
  9976. * Determines if the browser is currently in fullscreen mode.
  9977. * @memberof Fullscreen
  9978. * @type {Boolean}
  9979. * @readonly
  9980. */
  9981. fullscreen : {
  9982. get : function() {
  9983. if (!Fullscreen.supportsFullscreen()) {
  9984. return undefined;
  9985. }
  9986. return Fullscreen.element !== null;
  9987. }
  9988. }
  9989. });
  9990. /**
  9991. * Detects whether the browser supports the standard fullscreen API.
  9992. *
  9993. * @returns {Boolean} <code>true</code> if the browser supports the standard fullscreen API,
  9994. * <code>false</code> otherwise.
  9995. */
  9996. Fullscreen.supportsFullscreen = function() {
  9997. if (defined(_supportsFullscreen)) {
  9998. return _supportsFullscreen;
  9999. }
  10000. _supportsFullscreen = false;
  10001. var body = document.body;
  10002. if (typeof body.requestFullscreen === 'function') {
  10003. // go with the unprefixed, standard set of names
  10004. _names.requestFullscreen = 'requestFullscreen';
  10005. _names.exitFullscreen = 'exitFullscreen';
  10006. _names.fullscreenEnabled = 'fullscreenEnabled';
  10007. _names.fullscreenElement = 'fullscreenElement';
  10008. _names.fullscreenchange = 'fullscreenchange';
  10009. _names.fullscreenerror = 'fullscreenerror';
  10010. _supportsFullscreen = true;
  10011. return _supportsFullscreen;
  10012. }
  10013. //check for the correct combination of prefix plus the various names that browsers use
  10014. var prefixes = ['webkit', 'moz', 'o', 'ms', 'khtml'];
  10015. var name;
  10016. for (var i = 0, len = prefixes.length; i < len; ++i) {
  10017. var prefix = prefixes[i];
  10018. // casing of Fullscreen differs across browsers
  10019. name = prefix + 'RequestFullscreen';
  10020. if (typeof body[name] === 'function') {
  10021. _names.requestFullscreen = name;
  10022. _supportsFullscreen = true;
  10023. } else {
  10024. name = prefix + 'RequestFullScreen';
  10025. if (typeof body[name] === 'function') {
  10026. _names.requestFullscreen = name;
  10027. _supportsFullscreen = true;
  10028. }
  10029. }
  10030. // disagreement about whether it's "exit" as per spec, or "cancel"
  10031. name = prefix + 'ExitFullscreen';
  10032. if (typeof document[name] === 'function') {
  10033. _names.exitFullscreen = name;
  10034. } else {
  10035. name = prefix + 'CancelFullScreen';
  10036. if (typeof document[name] === 'function') {
  10037. _names.exitFullscreen = name;
  10038. }
  10039. }
  10040. // casing of Fullscreen differs across browsers
  10041. name = prefix + 'FullscreenEnabled';
  10042. if (document[name] !== undefined) {
  10043. _names.fullscreenEnabled = name;
  10044. } else {
  10045. name = prefix + 'FullScreenEnabled';
  10046. if (document[name] !== undefined) {
  10047. _names.fullscreenEnabled = name;
  10048. }
  10049. }
  10050. // casing of Fullscreen differs across browsers
  10051. name = prefix + 'FullscreenElement';
  10052. if (document[name] !== undefined) {
  10053. _names.fullscreenElement = name;
  10054. } else {
  10055. name = prefix + 'FullScreenElement';
  10056. if (document[name] !== undefined) {
  10057. _names.fullscreenElement = name;
  10058. }
  10059. }
  10060. // thankfully, event names are all lowercase per spec
  10061. name = prefix + 'fullscreenchange';
  10062. // event names do not have 'on' in the front, but the property on the document does
  10063. if (document['on' + name] !== undefined) {
  10064. //except on IE
  10065. if (prefix === 'ms') {
  10066. name = 'MSFullscreenChange';
  10067. }
  10068. _names.fullscreenchange = name;
  10069. }
  10070. name = prefix + 'fullscreenerror';
  10071. if (document['on' + name] !== undefined) {
  10072. //except on IE
  10073. if (prefix === 'ms') {
  10074. name = 'MSFullscreenError';
  10075. }
  10076. _names.fullscreenerror = name;
  10077. }
  10078. }
  10079. return _supportsFullscreen;
  10080. };
  10081. /**
  10082. * Asynchronously requests the browser to enter fullscreen mode on the given element.
  10083. * If fullscreen mode is not supported by the browser, does nothing.
  10084. *
  10085. * @param {Object} element The HTML element which will be placed into fullscreen mode.
  10086. * @param {HMDVRDevice} [vrDevice] The VR device.
  10087. *
  10088. * @example
  10089. * // Put the entire page into fullscreen.
  10090. * Cesium.Fullscreen.requestFullscreen(document.body)
  10091. *
  10092. * // Place only the Cesium canvas into fullscreen.
  10093. * Cesium.Fullscreen.requestFullscreen(scene.canvas)
  10094. */
  10095. Fullscreen.requestFullscreen = function(element, vrDevice) {
  10096. if (!Fullscreen.supportsFullscreen()) {
  10097. return;
  10098. }
  10099. element[_names.requestFullscreen]({ vrDisplay: vrDevice });
  10100. };
  10101. /**
  10102. * Asynchronously exits fullscreen mode. If the browser is not currently
  10103. * in fullscreen, or if fullscreen mode is not supported by the browser, does nothing.
  10104. */
  10105. Fullscreen.exitFullscreen = function() {
  10106. if (!Fullscreen.supportsFullscreen()) {
  10107. return;
  10108. }
  10109. document[_names.exitFullscreen]();
  10110. };
  10111. return Fullscreen;
  10112. });
  10113. /*global define*/
  10114. define('Core/FeatureDetection',[
  10115. './defaultValue',
  10116. './defined',
  10117. './Fullscreen'
  10118. ], function(
  10119. defaultValue,
  10120. defined,
  10121. Fullscreen) {
  10122. 'use strict';
  10123. var theNavigator;
  10124. if (typeof navigator !== 'undefined') {
  10125. theNavigator = navigator;
  10126. } else {
  10127. theNavigator = {};
  10128. }
  10129. function extractVersion(versionString) {
  10130. var parts = versionString.split('.');
  10131. for (var i = 0, len = parts.length; i < len; ++i) {
  10132. parts[i] = parseInt(parts[i], 10);
  10133. }
  10134. return parts;
  10135. }
  10136. var isChromeResult;
  10137. var chromeVersionResult;
  10138. function isChrome() {
  10139. if (!defined(isChromeResult)) {
  10140. isChromeResult = false;
  10141. // Edge contains Chrome in the user agent too
  10142. if (!isEdge()) {
  10143. var fields = (/ Chrome\/([\.0-9]+)/).exec(theNavigator.userAgent);
  10144. if (fields !== null) {
  10145. isChromeResult = true;
  10146. chromeVersionResult = extractVersion(fields[1]);
  10147. }
  10148. }
  10149. }
  10150. return isChromeResult;
  10151. }
  10152. function chromeVersion() {
  10153. return isChrome() && chromeVersionResult;
  10154. }
  10155. var isSafariResult;
  10156. var safariVersionResult;
  10157. function isSafari() {
  10158. if (!defined(isSafariResult)) {
  10159. isSafariResult = false;
  10160. // Chrome and Edge contain Safari in the user agent too
  10161. if (!isChrome() && !isEdge() && (/ Safari\/[\.0-9]+/).test(theNavigator.userAgent)) {
  10162. var fields = (/ Version\/([\.0-9]+)/).exec(theNavigator.userAgent);
  10163. if (fields !== null) {
  10164. isSafariResult = true;
  10165. safariVersionResult = extractVersion(fields[1]);
  10166. }
  10167. }
  10168. }
  10169. return isSafariResult;
  10170. }
  10171. function safariVersion() {
  10172. return isSafari() && safariVersionResult;
  10173. }
  10174. var isWebkitResult;
  10175. var webkitVersionResult;
  10176. function isWebkit() {
  10177. if (!defined(isWebkitResult)) {
  10178. isWebkitResult = false;
  10179. var fields = (/ AppleWebKit\/([\.0-9]+)(\+?)/).exec(theNavigator.userAgent);
  10180. if (fields !== null) {
  10181. isWebkitResult = true;
  10182. webkitVersionResult = extractVersion(fields[1]);
  10183. webkitVersionResult.isNightly = !!fields[2];
  10184. }
  10185. }
  10186. return isWebkitResult;
  10187. }
  10188. function webkitVersion() {
  10189. return isWebkit() && webkitVersionResult;
  10190. }
  10191. var isInternetExplorerResult;
  10192. var internetExplorerVersionResult;
  10193. function isInternetExplorer() {
  10194. if (!defined(isInternetExplorerResult)) {
  10195. isInternetExplorerResult = false;
  10196. var fields;
  10197. if (theNavigator.appName === 'Microsoft Internet Explorer') {
  10198. fields = /MSIE ([0-9]{1,}[\.0-9]{0,})/.exec(theNavigator.userAgent);
  10199. if (fields !== null) {
  10200. isInternetExplorerResult = true;
  10201. internetExplorerVersionResult = extractVersion(fields[1]);
  10202. }
  10203. } else if (theNavigator.appName === 'Netscape') {
  10204. fields = /Trident\/.*rv:([0-9]{1,}[\.0-9]{0,})/.exec(theNavigator.userAgent);
  10205. if (fields !== null) {
  10206. isInternetExplorerResult = true;
  10207. internetExplorerVersionResult = extractVersion(fields[1]);
  10208. }
  10209. }
  10210. }
  10211. return isInternetExplorerResult;
  10212. }
  10213. function internetExplorerVersion() {
  10214. return isInternetExplorer() && internetExplorerVersionResult;
  10215. }
  10216. var isEdgeResult;
  10217. var edgeVersionResult;
  10218. function isEdge() {
  10219. if (!defined(isEdgeResult)) {
  10220. isEdgeResult = false;
  10221. var fields = (/ Edge\/([\.0-9]+)/).exec(theNavigator.userAgent);
  10222. if (fields !== null) {
  10223. isEdgeResult = true;
  10224. edgeVersionResult = extractVersion(fields[1]);
  10225. }
  10226. }
  10227. return isEdgeResult;
  10228. }
  10229. function edgeVersion() {
  10230. return isEdge() && edgeVersionResult;
  10231. }
  10232. var isFirefoxResult;
  10233. var firefoxVersionResult;
  10234. function isFirefox() {
  10235. if (!defined(isFirefoxResult)) {
  10236. isFirefoxResult = false;
  10237. var fields = /Firefox\/([\.0-9]+)/.exec(theNavigator.userAgent);
  10238. if (fields !== null) {
  10239. isFirefoxResult = true;
  10240. firefoxVersionResult = extractVersion(fields[1]);
  10241. }
  10242. }
  10243. return isFirefoxResult;
  10244. }
  10245. var isWindowsResult;
  10246. function isWindows() {
  10247. if (!defined(isWindowsResult)) {
  10248. isWindowsResult = /Windows/i.test(theNavigator.appVersion);
  10249. }
  10250. return isWindowsResult;
  10251. }
  10252. function firefoxVersion() {
  10253. return isFirefox() && firefoxVersionResult;
  10254. }
  10255. var hasPointerEvents;
  10256. function supportsPointerEvents() {
  10257. if (!defined(hasPointerEvents)) {
  10258. //While navigator.pointerEnabled is deprecated in the W3C specification
  10259. //we still need to use it if it exists in order to support browsers
  10260. //that rely on it, such as the Windows WebBrowser control which defines
  10261. //PointerEvent but sets navigator.pointerEnabled to false.
  10262. hasPointerEvents = typeof PointerEvent !== 'undefined' && (!defined(theNavigator.pointerEnabled) || theNavigator.pointerEnabled);
  10263. }
  10264. return hasPointerEvents;
  10265. }
  10266. var imageRenderingValueResult;
  10267. var supportsImageRenderingPixelatedResult;
  10268. function supportsImageRenderingPixelated() {
  10269. if (!defined(supportsImageRenderingPixelatedResult)) {
  10270. var canvas = document.createElement('canvas');
  10271. canvas.setAttribute('style',
  10272. 'image-rendering: -moz-crisp-edges;' +
  10273. 'image-rendering: pixelated;');
  10274. //canvas.style.imageRendering will be undefined, null or an empty string on unsupported browsers.
  10275. var tmp = canvas.style.imageRendering;
  10276. supportsImageRenderingPixelatedResult = defined(tmp) && tmp !== '';
  10277. if (supportsImageRenderingPixelatedResult) {
  10278. imageRenderingValueResult = tmp;
  10279. }
  10280. }
  10281. return supportsImageRenderingPixelatedResult;
  10282. }
  10283. function imageRenderingValue() {
  10284. return supportsImageRenderingPixelated() ? imageRenderingValueResult : undefined;
  10285. }
  10286. /**
  10287. * A set of functions to detect whether the current browser supports
  10288. * various features.
  10289. *
  10290. * @exports FeatureDetection
  10291. */
  10292. var FeatureDetection = {
  10293. isChrome : isChrome,
  10294. chromeVersion : chromeVersion,
  10295. isSafari : isSafari,
  10296. safariVersion : safariVersion,
  10297. isWebkit : isWebkit,
  10298. webkitVersion : webkitVersion,
  10299. isInternetExplorer : isInternetExplorer,
  10300. internetExplorerVersion : internetExplorerVersion,
  10301. isEdge : isEdge,
  10302. edgeVersion : edgeVersion,
  10303. isFirefox : isFirefox,
  10304. firefoxVersion : firefoxVersion,
  10305. isWindows : isWindows,
  10306. hardwareConcurrency : defaultValue(theNavigator.hardwareConcurrency, 3),
  10307. supportsPointerEvents : supportsPointerEvents,
  10308. supportsImageRenderingPixelated: supportsImageRenderingPixelated,
  10309. imageRenderingValue: imageRenderingValue
  10310. };
  10311. /**
  10312. * Detects whether the current browser supports the full screen standard.
  10313. *
  10314. * @returns {Boolean} true if the browser supports the full screen standard, false if not.
  10315. *
  10316. * @see Fullscreen
  10317. * @see {@link http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html|W3C Fullscreen Living Specification}
  10318. */
  10319. FeatureDetection.supportsFullscreen = function() {
  10320. return Fullscreen.supportsFullscreen();
  10321. };
  10322. /**
  10323. * Detects whether the current browser supports typed arrays.
  10324. *
  10325. * @returns {Boolean} true if the browser supports typed arrays, false if not.
  10326. *
  10327. * @see {@link http://www.khronos.org/registry/typedarray/specs/latest/|Typed Array Specification}
  10328. */
  10329. FeatureDetection.supportsTypedArrays = function() {
  10330. return typeof ArrayBuffer !== 'undefined';
  10331. };
  10332. /**
  10333. * Detects whether the current browser supports Web Workers.
  10334. *
  10335. * @returns {Boolean} true if the browsers supports Web Workers, false if not.
  10336. *
  10337. * @see {@link http://www.w3.org/TR/workers/}
  10338. */
  10339. FeatureDetection.supportsWebWorkers = function() {
  10340. return typeof Worker !== 'undefined';
  10341. };
  10342. return FeatureDetection;
  10343. });
  10344. /*global define*/
  10345. define('Core/WebGLConstants',[
  10346. './freezeObject'
  10347. ], function(
  10348. freezeObject) {
  10349. 'use strict';
  10350. /**
  10351. * Enum containing WebGL Constant values by name.
  10352. * for use without an active WebGL context, or in cases where certain constants are unavailable using the WebGL context
  10353. * (For example, in [Safari 9]{@link https://github.com/AnalyticalGraphicsInc/cesium/issues/2989}).
  10354. *
  10355. * These match the constants from the [WebGL 1.0]{@link https://www.khronos.org/registry/webgl/specs/latest/1.0/}
  10356. * and [WebGL 2.0]{@link https://www.khronos.org/registry/webgl/specs/latest/2.0/}
  10357. * specifications.
  10358. *
  10359. * @exports WebGLConstants
  10360. */
  10361. var WebGLConstants = {
  10362. DEPTH_BUFFER_BIT : 0x00000100,
  10363. STENCIL_BUFFER_BIT : 0x00000400,
  10364. COLOR_BUFFER_BIT : 0x00004000,
  10365. POINTS : 0x0000,
  10366. LINES : 0x0001,
  10367. LINE_LOOP : 0x0002,
  10368. LINE_STRIP : 0x0003,
  10369. TRIANGLES : 0x0004,
  10370. TRIANGLE_STRIP : 0x0005,
  10371. TRIANGLE_FAN : 0x0006,
  10372. ZERO : 0,
  10373. ONE : 1,
  10374. SRC_COLOR : 0x0300,
  10375. ONE_MINUS_SRC_COLOR : 0x0301,
  10376. SRC_ALPHA : 0x0302,
  10377. ONE_MINUS_SRC_ALPHA : 0x0303,
  10378. DST_ALPHA : 0x0304,
  10379. ONE_MINUS_DST_ALPHA : 0x0305,
  10380. DST_COLOR : 0x0306,
  10381. ONE_MINUS_DST_COLOR : 0x0307,
  10382. SRC_ALPHA_SATURATE : 0x0308,
  10383. FUNC_ADD : 0x8006,
  10384. BLEND_EQUATION : 0x8009,
  10385. BLEND_EQUATION_RGB : 0x8009, // same as BLEND_EQUATION
  10386. BLEND_EQUATION_ALPHA : 0x883D,
  10387. FUNC_SUBTRACT : 0x800A,
  10388. FUNC_REVERSE_SUBTRACT : 0x800B,
  10389. BLEND_DST_RGB : 0x80C8,
  10390. BLEND_SRC_RGB : 0x80C9,
  10391. BLEND_DST_ALPHA : 0x80CA,
  10392. BLEND_SRC_ALPHA : 0x80CB,
  10393. CONSTANT_COLOR : 0x8001,
  10394. ONE_MINUS_CONSTANT_COLOR : 0x8002,
  10395. CONSTANT_ALPHA : 0x8003,
  10396. ONE_MINUS_CONSTANT_ALPHA : 0x8004,
  10397. BLEND_COLOR : 0x8005,
  10398. ARRAY_BUFFER : 0x8892,
  10399. ELEMENT_ARRAY_BUFFER : 0x8893,
  10400. ARRAY_BUFFER_BINDING : 0x8894,
  10401. ELEMENT_ARRAY_BUFFER_BINDING : 0x8895,
  10402. STREAM_DRAW : 0x88E0,
  10403. STATIC_DRAW : 0x88E4,
  10404. DYNAMIC_DRAW : 0x88E8,
  10405. BUFFER_SIZE : 0x8764,
  10406. BUFFER_USAGE : 0x8765,
  10407. CURRENT_VERTEX_ATTRIB : 0x8626,
  10408. FRONT : 0x0404,
  10409. BACK : 0x0405,
  10410. FRONT_AND_BACK : 0x0408,
  10411. CULL_FACE : 0x0B44,
  10412. BLEND : 0x0BE2,
  10413. DITHER : 0x0BD0,
  10414. STENCIL_TEST : 0x0B90,
  10415. DEPTH_TEST : 0x0B71,
  10416. SCISSOR_TEST : 0x0C11,
  10417. POLYGON_OFFSET_FILL : 0x8037,
  10418. SAMPLE_ALPHA_TO_COVERAGE : 0x809E,
  10419. SAMPLE_COVERAGE : 0x80A0,
  10420. NO_ERROR : 0,
  10421. INVALID_ENUM : 0x0500,
  10422. INVALID_VALUE : 0x0501,
  10423. INVALID_OPERATION : 0x0502,
  10424. OUT_OF_MEMORY : 0x0505,
  10425. CW : 0x0900,
  10426. CCW : 0x0901,
  10427. LINE_WIDTH : 0x0B21,
  10428. ALIASED_POINT_SIZE_RANGE : 0x846D,
  10429. ALIASED_LINE_WIDTH_RANGE : 0x846E,
  10430. CULL_FACE_MODE : 0x0B45,
  10431. FRONT_FACE : 0x0B46,
  10432. DEPTH_RANGE : 0x0B70,
  10433. DEPTH_WRITEMASK : 0x0B72,
  10434. DEPTH_CLEAR_VALUE : 0x0B73,
  10435. DEPTH_FUNC : 0x0B74,
  10436. STENCIL_CLEAR_VALUE : 0x0B91,
  10437. STENCIL_FUNC : 0x0B92,
  10438. STENCIL_FAIL : 0x0B94,
  10439. STENCIL_PASS_DEPTH_FAIL : 0x0B95,
  10440. STENCIL_PASS_DEPTH_PASS : 0x0B96,
  10441. STENCIL_REF : 0x0B97,
  10442. STENCIL_VALUE_MASK : 0x0B93,
  10443. STENCIL_WRITEMASK : 0x0B98,
  10444. STENCIL_BACK_FUNC : 0x8800,
  10445. STENCIL_BACK_FAIL : 0x8801,
  10446. STENCIL_BACK_PASS_DEPTH_FAIL : 0x8802,
  10447. STENCIL_BACK_PASS_DEPTH_PASS : 0x8803,
  10448. STENCIL_BACK_REF : 0x8CA3,
  10449. STENCIL_BACK_VALUE_MASK : 0x8CA4,
  10450. STENCIL_BACK_WRITEMASK : 0x8CA5,
  10451. VIEWPORT : 0x0BA2,
  10452. SCISSOR_BOX : 0x0C10,
  10453. COLOR_CLEAR_VALUE : 0x0C22,
  10454. COLOR_WRITEMASK : 0x0C23,
  10455. UNPACK_ALIGNMENT : 0x0CF5,
  10456. PACK_ALIGNMENT : 0x0D05,
  10457. MAX_TEXTURE_SIZE : 0x0D33,
  10458. MAX_VIEWPORT_DIMS : 0x0D3A,
  10459. SUBPIXEL_BITS : 0x0D50,
  10460. RED_BITS : 0x0D52,
  10461. GREEN_BITS : 0x0D53,
  10462. BLUE_BITS : 0x0D54,
  10463. ALPHA_BITS : 0x0D55,
  10464. DEPTH_BITS : 0x0D56,
  10465. STENCIL_BITS : 0x0D57,
  10466. POLYGON_OFFSET_UNITS : 0x2A00,
  10467. POLYGON_OFFSET_FACTOR : 0x8038,
  10468. TEXTURE_BINDING_2D : 0x8069,
  10469. SAMPLE_BUFFERS : 0x80A8,
  10470. SAMPLES : 0x80A9,
  10471. SAMPLE_COVERAGE_VALUE : 0x80AA,
  10472. SAMPLE_COVERAGE_INVERT : 0x80AB,
  10473. COMPRESSED_TEXTURE_FORMATS : 0x86A3,
  10474. DONT_CARE : 0x1100,
  10475. FASTEST : 0x1101,
  10476. NICEST : 0x1102,
  10477. GENERATE_MIPMAP_HINT : 0x8192,
  10478. BYTE : 0x1400,
  10479. UNSIGNED_BYTE : 0x1401,
  10480. SHORT : 0x1402,
  10481. UNSIGNED_SHORT : 0x1403,
  10482. INT : 0x1404,
  10483. UNSIGNED_INT : 0x1405,
  10484. FLOAT : 0x1406,
  10485. DEPTH_COMPONENT : 0x1902,
  10486. ALPHA : 0x1906,
  10487. RGB : 0x1907,
  10488. RGBA : 0x1908,
  10489. LUMINANCE : 0x1909,
  10490. LUMINANCE_ALPHA : 0x190A,
  10491. UNSIGNED_SHORT_4_4_4_4 : 0x8033,
  10492. UNSIGNED_SHORT_5_5_5_1 : 0x8034,
  10493. UNSIGNED_SHORT_5_6_5 : 0x8363,
  10494. FRAGMENT_SHADER : 0x8B30,
  10495. VERTEX_SHADER : 0x8B31,
  10496. MAX_VERTEX_ATTRIBS : 0x8869,
  10497. MAX_VERTEX_UNIFORM_VECTORS : 0x8DFB,
  10498. MAX_VARYING_VECTORS : 0x8DFC,
  10499. MAX_COMBINED_TEXTURE_IMAGE_UNITS : 0x8B4D,
  10500. MAX_VERTEX_TEXTURE_IMAGE_UNITS : 0x8B4C,
  10501. MAX_TEXTURE_IMAGE_UNITS : 0x8872,
  10502. MAX_FRAGMENT_UNIFORM_VECTORS : 0x8DFD,
  10503. SHADER_TYPE : 0x8B4F,
  10504. DELETE_STATUS : 0x8B80,
  10505. LINK_STATUS : 0x8B82,
  10506. VALIDATE_STATUS : 0x8B83,
  10507. ATTACHED_SHADERS : 0x8B85,
  10508. ACTIVE_UNIFORMS : 0x8B86,
  10509. ACTIVE_ATTRIBUTES : 0x8B89,
  10510. SHADING_LANGUAGE_VERSION : 0x8B8C,
  10511. CURRENT_PROGRAM : 0x8B8D,
  10512. NEVER : 0x0200,
  10513. LESS : 0x0201,
  10514. EQUAL : 0x0202,
  10515. LEQUAL : 0x0203,
  10516. GREATER : 0x0204,
  10517. NOTEQUAL : 0x0205,
  10518. GEQUAL : 0x0206,
  10519. ALWAYS : 0x0207,
  10520. KEEP : 0x1E00,
  10521. REPLACE : 0x1E01,
  10522. INCR : 0x1E02,
  10523. DECR : 0x1E03,
  10524. INVERT : 0x150A,
  10525. INCR_WRAP : 0x8507,
  10526. DECR_WRAP : 0x8508,
  10527. VENDOR : 0x1F00,
  10528. RENDERER : 0x1F01,
  10529. VERSION : 0x1F02,
  10530. NEAREST : 0x2600,
  10531. LINEAR : 0x2601,
  10532. NEAREST_MIPMAP_NEAREST : 0x2700,
  10533. LINEAR_MIPMAP_NEAREST : 0x2701,
  10534. NEAREST_MIPMAP_LINEAR : 0x2702,
  10535. LINEAR_MIPMAP_LINEAR : 0x2703,
  10536. TEXTURE_MAG_FILTER : 0x2800,
  10537. TEXTURE_MIN_FILTER : 0x2801,
  10538. TEXTURE_WRAP_S : 0x2802,
  10539. TEXTURE_WRAP_T : 0x2803,
  10540. TEXTURE_2D : 0x0DE1,
  10541. TEXTURE : 0x1702,
  10542. TEXTURE_CUBE_MAP : 0x8513,
  10543. TEXTURE_BINDING_CUBE_MAP : 0x8514,
  10544. TEXTURE_CUBE_MAP_POSITIVE_X : 0x8515,
  10545. TEXTURE_CUBE_MAP_NEGATIVE_X : 0x8516,
  10546. TEXTURE_CUBE_MAP_POSITIVE_Y : 0x8517,
  10547. TEXTURE_CUBE_MAP_NEGATIVE_Y : 0x8518,
  10548. TEXTURE_CUBE_MAP_POSITIVE_Z : 0x8519,
  10549. TEXTURE_CUBE_MAP_NEGATIVE_Z : 0x851A,
  10550. MAX_CUBE_MAP_TEXTURE_SIZE : 0x851C,
  10551. TEXTURE0 : 0x84C0,
  10552. TEXTURE1 : 0x84C1,
  10553. TEXTURE2 : 0x84C2,
  10554. TEXTURE3 : 0x84C3,
  10555. TEXTURE4 : 0x84C4,
  10556. TEXTURE5 : 0x84C5,
  10557. TEXTURE6 : 0x84C6,
  10558. TEXTURE7 : 0x84C7,
  10559. TEXTURE8 : 0x84C8,
  10560. TEXTURE9 : 0x84C9,
  10561. TEXTURE10 : 0x84CA,
  10562. TEXTURE11 : 0x84CB,
  10563. TEXTURE12 : 0x84CC,
  10564. TEXTURE13 : 0x84CD,
  10565. TEXTURE14 : 0x84CE,
  10566. TEXTURE15 : 0x84CF,
  10567. TEXTURE16 : 0x84D0,
  10568. TEXTURE17 : 0x84D1,
  10569. TEXTURE18 : 0x84D2,
  10570. TEXTURE19 : 0x84D3,
  10571. TEXTURE20 : 0x84D4,
  10572. TEXTURE21 : 0x84D5,
  10573. TEXTURE22 : 0x84D6,
  10574. TEXTURE23 : 0x84D7,
  10575. TEXTURE24 : 0x84D8,
  10576. TEXTURE25 : 0x84D9,
  10577. TEXTURE26 : 0x84DA,
  10578. TEXTURE27 : 0x84DB,
  10579. TEXTURE28 : 0x84DC,
  10580. TEXTURE29 : 0x84DD,
  10581. TEXTURE30 : 0x84DE,
  10582. TEXTURE31 : 0x84DF,
  10583. ACTIVE_TEXTURE : 0x84E0,
  10584. REPEAT : 0x2901,
  10585. CLAMP_TO_EDGE : 0x812F,
  10586. MIRRORED_REPEAT : 0x8370,
  10587. FLOAT_VEC2 : 0x8B50,
  10588. FLOAT_VEC3 : 0x8B51,
  10589. FLOAT_VEC4 : 0x8B52,
  10590. INT_VEC2 : 0x8B53,
  10591. INT_VEC3 : 0x8B54,
  10592. INT_VEC4 : 0x8B55,
  10593. BOOL : 0x8B56,
  10594. BOOL_VEC2 : 0x8B57,
  10595. BOOL_VEC3 : 0x8B58,
  10596. BOOL_VEC4 : 0x8B59,
  10597. FLOAT_MAT2 : 0x8B5A,
  10598. FLOAT_MAT3 : 0x8B5B,
  10599. FLOAT_MAT4 : 0x8B5C,
  10600. SAMPLER_2D : 0x8B5E,
  10601. SAMPLER_CUBE : 0x8B60,
  10602. VERTEX_ATTRIB_ARRAY_ENABLED : 0x8622,
  10603. VERTEX_ATTRIB_ARRAY_SIZE : 0x8623,
  10604. VERTEX_ATTRIB_ARRAY_STRIDE : 0x8624,
  10605. VERTEX_ATTRIB_ARRAY_TYPE : 0x8625,
  10606. VERTEX_ATTRIB_ARRAY_NORMALIZED : 0x886A,
  10607. VERTEX_ATTRIB_ARRAY_POINTER : 0x8645,
  10608. VERTEX_ATTRIB_ARRAY_BUFFER_BINDING : 0x889F,
  10609. IMPLEMENTATION_COLOR_READ_TYPE : 0x8B9A,
  10610. IMPLEMENTATION_COLOR_READ_FORMAT : 0x8B9B,
  10611. COMPILE_STATUS : 0x8B81,
  10612. LOW_FLOAT : 0x8DF0,
  10613. MEDIUM_FLOAT : 0x8DF1,
  10614. HIGH_FLOAT : 0x8DF2,
  10615. LOW_INT : 0x8DF3,
  10616. MEDIUM_INT : 0x8DF4,
  10617. HIGH_INT : 0x8DF5,
  10618. FRAMEBUFFER : 0x8D40,
  10619. RENDERBUFFER : 0x8D41,
  10620. RGBA4 : 0x8056,
  10621. RGB5_A1 : 0x8057,
  10622. RGB565 : 0x8D62,
  10623. DEPTH_COMPONENT16 : 0x81A5,
  10624. STENCIL_INDEX : 0x1901,
  10625. STENCIL_INDEX8 : 0x8D48,
  10626. DEPTH_STENCIL : 0x84F9,
  10627. RENDERBUFFER_WIDTH : 0x8D42,
  10628. RENDERBUFFER_HEIGHT : 0x8D43,
  10629. RENDERBUFFER_INTERNAL_FORMAT : 0x8D44,
  10630. RENDERBUFFER_RED_SIZE : 0x8D50,
  10631. RENDERBUFFER_GREEN_SIZE : 0x8D51,
  10632. RENDERBUFFER_BLUE_SIZE : 0x8D52,
  10633. RENDERBUFFER_ALPHA_SIZE : 0x8D53,
  10634. RENDERBUFFER_DEPTH_SIZE : 0x8D54,
  10635. RENDERBUFFER_STENCIL_SIZE : 0x8D55,
  10636. FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE : 0x8CD0,
  10637. FRAMEBUFFER_ATTACHMENT_OBJECT_NAME : 0x8CD1,
  10638. FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL : 0x8CD2,
  10639. FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE : 0x8CD3,
  10640. COLOR_ATTACHMENT0 : 0x8CE0,
  10641. DEPTH_ATTACHMENT : 0x8D00,
  10642. STENCIL_ATTACHMENT : 0x8D20,
  10643. DEPTH_STENCIL_ATTACHMENT : 0x821A,
  10644. NONE : 0,
  10645. FRAMEBUFFER_COMPLETE : 0x8CD5,
  10646. FRAMEBUFFER_INCOMPLETE_ATTACHMENT : 0x8CD6,
  10647. FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : 0x8CD7,
  10648. FRAMEBUFFER_INCOMPLETE_DIMENSIONS : 0x8CD9,
  10649. FRAMEBUFFER_UNSUPPORTED : 0x8CDD,
  10650. FRAMEBUFFER_BINDING : 0x8CA6,
  10651. RENDERBUFFER_BINDING : 0x8CA7,
  10652. MAX_RENDERBUFFER_SIZE : 0x84E8,
  10653. INVALID_FRAMEBUFFER_OPERATION : 0x0506,
  10654. UNPACK_FLIP_Y_WEBGL : 0x9240,
  10655. UNPACK_PREMULTIPLY_ALPHA_WEBGL : 0x9241,
  10656. CONTEXT_LOST_WEBGL : 0x9242,
  10657. UNPACK_COLORSPACE_CONVERSION_WEBGL : 0x9243,
  10658. BROWSER_DEFAULT_WEBGL : 0x9244,
  10659. // Desktop OpenGL
  10660. DOUBLE : 0x140A,
  10661. // WebGL 2
  10662. READ_BUFFER : 0x0C02,
  10663. UNPACK_ROW_LENGTH : 0x0CF2,
  10664. UNPACK_SKIP_ROWS : 0x0CF3,
  10665. UNPACK_SKIP_PIXELS : 0x0CF4,
  10666. PACK_ROW_LENGTH : 0x0D02,
  10667. PACK_SKIP_ROWS : 0x0D03,
  10668. PACK_SKIP_PIXELS : 0x0D04,
  10669. COLOR : 0x1800,
  10670. DEPTH : 0x1801,
  10671. STENCIL : 0x1802,
  10672. RED : 0x1903,
  10673. RGB8 : 0x8051,
  10674. RGBA8 : 0x8058,
  10675. RGB10_A2 : 0x8059,
  10676. TEXTURE_BINDING_3D : 0x806A,
  10677. UNPACK_SKIP_IMAGES : 0x806D,
  10678. UNPACK_IMAGE_HEIGHT : 0x806E,
  10679. TEXTURE_3D : 0x806F,
  10680. TEXTURE_WRAP_R : 0x8072,
  10681. MAX_3D_TEXTURE_SIZE : 0x8073,
  10682. UNSIGNED_INT_2_10_10_10_REV : 0x8368,
  10683. MAX_ELEMENTS_VERTICES : 0x80E8,
  10684. MAX_ELEMENTS_INDICES : 0x80E9,
  10685. TEXTURE_MIN_LOD : 0x813A,
  10686. TEXTURE_MAX_LOD : 0x813B,
  10687. TEXTURE_BASE_LEVEL : 0x813C,
  10688. TEXTURE_MAX_LEVEL : 0x813D,
  10689. MIN : 0x8007,
  10690. MAX : 0x8008,
  10691. DEPTH_COMPONENT24 : 0x81A6,
  10692. MAX_TEXTURE_LOD_BIAS : 0x84FD,
  10693. TEXTURE_COMPARE_MODE : 0x884C,
  10694. TEXTURE_COMPARE_FUNC : 0x884D,
  10695. CURRENT_QUERY : 0x8865,
  10696. QUERY_RESULT : 0x8866,
  10697. QUERY_RESULT_AVAILABLE : 0x8867,
  10698. STREAM_READ : 0x88E1,
  10699. STREAM_COPY : 0x88E2,
  10700. STATIC_READ : 0x88E5,
  10701. STATIC_COPY : 0x88E6,
  10702. DYNAMIC_READ : 0x88E9,
  10703. DYNAMIC_COPY : 0x88EA,
  10704. MAX_DRAW_BUFFERS : 0x8824,
  10705. DRAW_BUFFER0 : 0x8825,
  10706. DRAW_BUFFER1 : 0x8826,
  10707. DRAW_BUFFER2 : 0x8827,
  10708. DRAW_BUFFER3 : 0x8828,
  10709. DRAW_BUFFER4 : 0x8829,
  10710. DRAW_BUFFER5 : 0x882A,
  10711. DRAW_BUFFER6 : 0x882B,
  10712. DRAW_BUFFER7 : 0x882C,
  10713. DRAW_BUFFER8 : 0x882D,
  10714. DRAW_BUFFER9 : 0x882E,
  10715. DRAW_BUFFER10 : 0x882F,
  10716. DRAW_BUFFER11 : 0x8830,
  10717. DRAW_BUFFER12 : 0x8831,
  10718. DRAW_BUFFER13 : 0x8832,
  10719. DRAW_BUFFER14 : 0x8833,
  10720. DRAW_BUFFER15 : 0x8834,
  10721. MAX_FRAGMENT_UNIFORM_COMPONENTS : 0x8B49,
  10722. MAX_VERTEX_UNIFORM_COMPONENTS : 0x8B4A,
  10723. SAMPLER_3D : 0x8B5F,
  10724. SAMPLER_2D_SHADOW : 0x8B62,
  10725. FRAGMENT_SHADER_DERIVATIVE_HINT : 0x8B8B,
  10726. PIXEL_PACK_BUFFER : 0x88EB,
  10727. PIXEL_UNPACK_BUFFER : 0x88EC,
  10728. PIXEL_PACK_BUFFER_BINDING : 0x88ED,
  10729. PIXEL_UNPACK_BUFFER_BINDING : 0x88EF,
  10730. FLOAT_MAT2x3 : 0x8B65,
  10731. FLOAT_MAT2x4 : 0x8B66,
  10732. FLOAT_MAT3x2 : 0x8B67,
  10733. FLOAT_MAT3x4 : 0x8B68,
  10734. FLOAT_MAT4x2 : 0x8B69,
  10735. FLOAT_MAT4x3 : 0x8B6A,
  10736. SRGB : 0x8C40,
  10737. SRGB8 : 0x8C41,
  10738. SRGB8_ALPHA8 : 0x8C43,
  10739. COMPARE_REF_TO_TEXTURE : 0x884E,
  10740. RGBA32F : 0x8814,
  10741. RGB32F : 0x8815,
  10742. RGBA16F : 0x881A,
  10743. RGB16F : 0x881B,
  10744. VERTEX_ATTRIB_ARRAY_INTEGER : 0x88FD,
  10745. MAX_ARRAY_TEXTURE_LAYERS : 0x88FF,
  10746. MIN_PROGRAM_TEXEL_OFFSET : 0x8904,
  10747. MAX_PROGRAM_TEXEL_OFFSET : 0x8905,
  10748. MAX_VARYING_COMPONENTS : 0x8B4B,
  10749. TEXTURE_2D_ARRAY : 0x8C1A,
  10750. TEXTURE_BINDING_2D_ARRAY : 0x8C1D,
  10751. R11F_G11F_B10F : 0x8C3A,
  10752. UNSIGNED_INT_10F_11F_11F_REV : 0x8C3B,
  10753. RGB9_E5 : 0x8C3D,
  10754. UNSIGNED_INT_5_9_9_9_REV : 0x8C3E,
  10755. TRANSFORM_FEEDBACK_BUFFER_MODE : 0x8C7F,
  10756. MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS : 0x8C80,
  10757. TRANSFORM_FEEDBACK_VARYINGS : 0x8C83,
  10758. TRANSFORM_FEEDBACK_BUFFER_START : 0x8C84,
  10759. TRANSFORM_FEEDBACK_BUFFER_SIZE : 0x8C85,
  10760. TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN : 0x8C88,
  10761. RASTERIZER_DISCARD : 0x8C89,
  10762. MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS : 0x8C8A,
  10763. MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS : 0x8C8B,
  10764. INTERLEAVED_ATTRIBS : 0x8C8C,
  10765. SEPARATE_ATTRIBS : 0x8C8D,
  10766. TRANSFORM_FEEDBACK_BUFFER : 0x8C8E,
  10767. TRANSFORM_FEEDBACK_BUFFER_BINDING : 0x8C8F,
  10768. RGBA32UI : 0x8D70,
  10769. RGB32UI : 0x8D71,
  10770. RGBA16UI : 0x8D76,
  10771. RGB16UI : 0x8D77,
  10772. RGBA8UI : 0x8D7C,
  10773. RGB8UI : 0x8D7D,
  10774. RGBA32I : 0x8D82,
  10775. RGB32I : 0x8D83,
  10776. RGBA16I : 0x8D88,
  10777. RGB16I : 0x8D89,
  10778. RGBA8I : 0x8D8E,
  10779. RGB8I : 0x8D8F,
  10780. RED_INTEGER : 0x8D94,
  10781. RGB_INTEGER : 0x8D98,
  10782. RGBA_INTEGER : 0x8D99,
  10783. SAMPLER_2D_ARRAY : 0x8DC1,
  10784. SAMPLER_2D_ARRAY_SHADOW : 0x8DC4,
  10785. SAMPLER_CUBE_SHADOW : 0x8DC5,
  10786. UNSIGNED_INT_VEC2 : 0x8DC6,
  10787. UNSIGNED_INT_VEC3 : 0x8DC7,
  10788. UNSIGNED_INT_VEC4 : 0x8DC8,
  10789. INT_SAMPLER_2D : 0x8DCA,
  10790. INT_SAMPLER_3D : 0x8DCB,
  10791. INT_SAMPLER_CUBE : 0x8DCC,
  10792. INT_SAMPLER_2D_ARRAY : 0x8DCF,
  10793. UNSIGNED_INT_SAMPLER_2D : 0x8DD2,
  10794. UNSIGNED_INT_SAMPLER_3D : 0x8DD3,
  10795. UNSIGNED_INT_SAMPLER_CUBE : 0x8DD4,
  10796. UNSIGNED_INT_SAMPLER_2D_ARRAY : 0x8DD7,
  10797. DEPTH_COMPONENT32F : 0x8CAC,
  10798. DEPTH32F_STENCIL8 : 0x8CAD,
  10799. FLOAT_32_UNSIGNED_INT_24_8_REV : 0x8DAD,
  10800. FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING : 0x8210,
  10801. FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE : 0x8211,
  10802. FRAMEBUFFER_ATTACHMENT_RED_SIZE : 0x8212,
  10803. FRAMEBUFFER_ATTACHMENT_GREEN_SIZE : 0x8213,
  10804. FRAMEBUFFER_ATTACHMENT_BLUE_SIZE : 0x8214,
  10805. FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE : 0x8215,
  10806. FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE : 0x8216,
  10807. FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE : 0x8217,
  10808. FRAMEBUFFER_DEFAULT : 0x8218,
  10809. UNSIGNED_INT_24_8 : 0x84FA,
  10810. DEPTH24_STENCIL8 : 0x88F0,
  10811. UNSIGNED_NORMALIZED : 0x8C17,
  10812. DRAW_FRAMEBUFFER_BINDING : 0x8CA6, // Same as FRAMEBUFFER_BINDING
  10813. READ_FRAMEBUFFER : 0x8CA8,
  10814. DRAW_FRAMEBUFFER : 0x8CA9,
  10815. READ_FRAMEBUFFER_BINDING : 0x8CAA,
  10816. RENDERBUFFER_SAMPLES : 0x8CAB,
  10817. FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER : 0x8CD4,
  10818. MAX_COLOR_ATTACHMENTS : 0x8CDF,
  10819. COLOR_ATTACHMENT1 : 0x8CE1,
  10820. COLOR_ATTACHMENT2 : 0x8CE2,
  10821. COLOR_ATTACHMENT3 : 0x8CE3,
  10822. COLOR_ATTACHMENT4 : 0x8CE4,
  10823. COLOR_ATTACHMENT5 : 0x8CE5,
  10824. COLOR_ATTACHMENT6 : 0x8CE6,
  10825. COLOR_ATTACHMENT7 : 0x8CE7,
  10826. COLOR_ATTACHMENT8 : 0x8CE8,
  10827. COLOR_ATTACHMENT9 : 0x8CE9,
  10828. COLOR_ATTACHMENT10 : 0x8CEA,
  10829. COLOR_ATTACHMENT11 : 0x8CEB,
  10830. COLOR_ATTACHMENT12 : 0x8CEC,
  10831. COLOR_ATTACHMENT13 : 0x8CED,
  10832. COLOR_ATTACHMENT14 : 0x8CEE,
  10833. COLOR_ATTACHMENT15 : 0x8CEF,
  10834. FRAMEBUFFER_INCOMPLETE_MULTISAMPLE : 0x8D56,
  10835. MAX_SAMPLES : 0x8D57,
  10836. HALF_FLOAT : 0x140B,
  10837. RG : 0x8227,
  10838. RG_INTEGER : 0x8228,
  10839. R8 : 0x8229,
  10840. RG8 : 0x822B,
  10841. R16F : 0x822D,
  10842. R32F : 0x822E,
  10843. RG16F : 0x822F,
  10844. RG32F : 0x8230,
  10845. R8I : 0x8231,
  10846. R8UI : 0x8232,
  10847. R16I : 0x8233,
  10848. R16UI : 0x8234,
  10849. R32I : 0x8235,
  10850. R32UI : 0x8236,
  10851. RG8I : 0x8237,
  10852. RG8UI : 0x8238,
  10853. RG16I : 0x8239,
  10854. RG16UI : 0x823A,
  10855. RG32I : 0x823B,
  10856. RG32UI : 0x823C,
  10857. VERTEX_ARRAY_BINDING : 0x85B5,
  10858. R8_SNORM : 0x8F94,
  10859. RG8_SNORM : 0x8F95,
  10860. RGB8_SNORM : 0x8F96,
  10861. RGBA8_SNORM : 0x8F97,
  10862. SIGNED_NORMALIZED : 0x8F9C,
  10863. COPY_READ_BUFFER : 0x8F36,
  10864. COPY_WRITE_BUFFER : 0x8F37,
  10865. COPY_READ_BUFFER_BINDING : 0x8F36, // Same as COPY_READ_BUFFER
  10866. COPY_WRITE_BUFFER_BINDING : 0x8F37, // Same as COPY_WRITE_BUFFER
  10867. UNIFORM_BUFFER : 0x8A11,
  10868. UNIFORM_BUFFER_BINDING : 0x8A28,
  10869. UNIFORM_BUFFER_START : 0x8A29,
  10870. UNIFORM_BUFFER_SIZE : 0x8A2A,
  10871. MAX_VERTEX_UNIFORM_BLOCKS : 0x8A2B,
  10872. MAX_FRAGMENT_UNIFORM_BLOCKS : 0x8A2D,
  10873. MAX_COMBINED_UNIFORM_BLOCKS : 0x8A2E,
  10874. MAX_UNIFORM_BUFFER_BINDINGS : 0x8A2F,
  10875. MAX_UNIFORM_BLOCK_SIZE : 0x8A30,
  10876. MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS : 0x8A31,
  10877. MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS : 0x8A33,
  10878. UNIFORM_BUFFER_OFFSET_ALIGNMENT : 0x8A34,
  10879. ACTIVE_UNIFORM_BLOCKS : 0x8A36,
  10880. UNIFORM_TYPE : 0x8A37,
  10881. UNIFORM_SIZE : 0x8A38,
  10882. UNIFORM_BLOCK_INDEX : 0x8A3A,
  10883. UNIFORM_OFFSET : 0x8A3B,
  10884. UNIFORM_ARRAY_STRIDE : 0x8A3C,
  10885. UNIFORM_MATRIX_STRIDE : 0x8A3D,
  10886. UNIFORM_IS_ROW_MAJOR : 0x8A3E,
  10887. UNIFORM_BLOCK_BINDING : 0x8A3F,
  10888. UNIFORM_BLOCK_DATA_SIZE : 0x8A40,
  10889. UNIFORM_BLOCK_ACTIVE_UNIFORMS : 0x8A42,
  10890. UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES : 0x8A43,
  10891. UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER : 0x8A44,
  10892. UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER : 0x8A46,
  10893. INVALID_INDEX : 0xFFFFFFFF,
  10894. MAX_VERTEX_OUTPUT_COMPONENTS : 0x9122,
  10895. MAX_FRAGMENT_INPUT_COMPONENTS : 0x9125,
  10896. MAX_SERVER_WAIT_TIMEOUT : 0x9111,
  10897. OBJECT_TYPE : 0x9112,
  10898. SYNC_CONDITION : 0x9113,
  10899. SYNC_STATUS : 0x9114,
  10900. SYNC_FLAGS : 0x9115,
  10901. SYNC_FENCE : 0x9116,
  10902. SYNC_GPU_COMMANDS_COMPLETE : 0x9117,
  10903. UNSIGNALED : 0x9118,
  10904. SIGNALED : 0x9119,
  10905. ALREADY_SIGNALED : 0x911A,
  10906. TIMEOUT_EXPIRED : 0x911B,
  10907. CONDITION_SATISFIED : 0x911C,
  10908. WAIT_FAILED : 0x911D,
  10909. SYNC_FLUSH_COMMANDS_BIT : 0x00000001,
  10910. VERTEX_ATTRIB_ARRAY_DIVISOR : 0x88FE,
  10911. ANY_SAMPLES_PASSED : 0x8C2F,
  10912. ANY_SAMPLES_PASSED_CONSERVATIVE : 0x8D6A,
  10913. SAMPLER_BINDING : 0x8919,
  10914. RGB10_A2UI : 0x906F,
  10915. INT_2_10_10_10_REV : 0x8D9F,
  10916. TRANSFORM_FEEDBACK : 0x8E22,
  10917. TRANSFORM_FEEDBACK_PAUSED : 0x8E23,
  10918. TRANSFORM_FEEDBACK_ACTIVE : 0x8E24,
  10919. TRANSFORM_FEEDBACK_BINDING : 0x8E25,
  10920. COMPRESSED_R11_EAC : 0x9270,
  10921. COMPRESSED_SIGNED_R11_EAC : 0x9271,
  10922. COMPRESSED_RG11_EAC : 0x9272,
  10923. COMPRESSED_SIGNED_RG11_EAC : 0x9273,
  10924. COMPRESSED_RGB8_ETC2 : 0x9274,
  10925. COMPRESSED_SRGB8_ETC2 : 0x9275,
  10926. COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 : 0x9276,
  10927. COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 : 0x9277,
  10928. COMPRESSED_RGBA8_ETC2_EAC : 0x9278,
  10929. COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : 0x9279,
  10930. TEXTURE_IMMUTABLE_FORMAT : 0x912F,
  10931. MAX_ELEMENT_INDEX : 0x8D6B,
  10932. TEXTURE_IMMUTABLE_LEVELS : 0x82DF
  10933. };
  10934. return freezeObject(WebGLConstants);
  10935. });
  10936. /*global define*/
  10937. define('Core/ComponentDatatype',[
  10938. './defaultValue',
  10939. './defined',
  10940. './DeveloperError',
  10941. './FeatureDetection',
  10942. './freezeObject',
  10943. './WebGLConstants'
  10944. ], function(
  10945. defaultValue,
  10946. defined,
  10947. DeveloperError,
  10948. FeatureDetection,
  10949. freezeObject,
  10950. WebGLConstants) {
  10951. 'use strict';
  10952. // Bail out if the browser doesn't support typed arrays, to prevent the setup function
  10953. // from failing, since we won't be able to create a WebGL context anyway.
  10954. if (!FeatureDetection.supportsTypedArrays()) {
  10955. return {};
  10956. }
  10957. /**
  10958. * WebGL component datatypes. Components are intrinsics,
  10959. * which form attributes, which form vertices.
  10960. *
  10961. * @exports ComponentDatatype
  10962. */
  10963. var ComponentDatatype = {
  10964. /**
  10965. * 8-bit signed byte corresponding to <code>gl.BYTE</code> and the type
  10966. * of an element in <code>Int8Array</code>.
  10967. *
  10968. * @type {Number}
  10969. * @constant
  10970. */
  10971. BYTE : WebGLConstants.BYTE,
  10972. /**
  10973. * 8-bit unsigned byte corresponding to <code>UNSIGNED_BYTE</code> and the type
  10974. * of an element in <code>Uint8Array</code>.
  10975. *
  10976. * @type {Number}
  10977. * @constant
  10978. */
  10979. UNSIGNED_BYTE : WebGLConstants.UNSIGNED_BYTE,
  10980. /**
  10981. * 16-bit signed short corresponding to <code>SHORT</code> and the type
  10982. * of an element in <code>Int16Array</code>.
  10983. *
  10984. * @type {Number}
  10985. * @constant
  10986. */
  10987. SHORT : WebGLConstants.SHORT,
  10988. /**
  10989. * 16-bit unsigned short corresponding to <code>UNSIGNED_SHORT</code> and the type
  10990. * of an element in <code>Uint16Array</code>.
  10991. *
  10992. * @type {Number}
  10993. * @constant
  10994. */
  10995. UNSIGNED_SHORT : WebGLConstants.UNSIGNED_SHORT,
  10996. /**
  10997. * 32-bit signed int corresponding to <code>INT</code> and the type
  10998. * of an element in <code>Int32Array</code>.
  10999. *
  11000. * @memberOf ComponentDatatype
  11001. *
  11002. * @type {Number}
  11003. * @constant
  11004. */
  11005. INT : WebGLConstants.INT,
  11006. /**
  11007. * 32-bit unsigned int corresponding to <code>UNSIGNED_INT</code> and the type
  11008. * of an element in <code>Uint32Array</code>.
  11009. *
  11010. * @memberOf ComponentDatatype
  11011. *
  11012. * @type {Number}
  11013. * @constant
  11014. */
  11015. UNSIGNED_INT : WebGLConstants.UNSIGNED_INT,
  11016. /**
  11017. * 32-bit floating-point corresponding to <code>FLOAT</code> and the type
  11018. * of an element in <code>Float32Array</code>.
  11019. *
  11020. * @type {Number}
  11021. * @constant
  11022. */
  11023. FLOAT : WebGLConstants.FLOAT,
  11024. /**
  11025. * 64-bit floating-point corresponding to <code>gl.DOUBLE</code> (in Desktop OpenGL;
  11026. * this is not supported in WebGL, and is emulated in Cesium via {@link GeometryPipeline.encodeAttribute})
  11027. * and the type of an element in <code>Float64Array</code>.
  11028. *
  11029. * @memberOf ComponentDatatype
  11030. *
  11031. * @type {Number}
  11032. * @constant
  11033. * @default 0x140A
  11034. */
  11035. DOUBLE : WebGLConstants.DOUBLE
  11036. };
  11037. /**
  11038. * Returns the size, in bytes, of the corresponding datatype.
  11039. *
  11040. * @param {ComponentDatatype} componentDatatype The component datatype to get the size of.
  11041. * @returns {Number} The size in bytes.
  11042. *
  11043. * @exception {DeveloperError} componentDatatype is not a valid value.
  11044. *
  11045. * @example
  11046. * // Returns Int8Array.BYTES_PER_ELEMENT
  11047. * var size = Cesium.ComponentDatatype.getSizeInBytes(Cesium.ComponentDatatype.BYTE);
  11048. */
  11049. ComponentDatatype.getSizeInBytes = function(componentDatatype){
  11050. if (!defined(componentDatatype)) {
  11051. throw new DeveloperError('value is required.');
  11052. }
  11053. switch (componentDatatype) {
  11054. case ComponentDatatype.BYTE:
  11055. return Int8Array.BYTES_PER_ELEMENT;
  11056. case ComponentDatatype.UNSIGNED_BYTE:
  11057. return Uint8Array.BYTES_PER_ELEMENT;
  11058. case ComponentDatatype.SHORT:
  11059. return Int16Array.BYTES_PER_ELEMENT;
  11060. case ComponentDatatype.UNSIGNED_SHORT:
  11061. return Uint16Array.BYTES_PER_ELEMENT;
  11062. case ComponentDatatype.INT:
  11063. return Int32Array.BYTES_PER_ELEMENT;
  11064. case ComponentDatatype.UNSIGNED_INT:
  11065. return Uint32Array.BYTES_PER_ELEMENT;
  11066. case ComponentDatatype.FLOAT:
  11067. return Float32Array.BYTES_PER_ELEMENT;
  11068. case ComponentDatatype.DOUBLE:
  11069. return Float64Array.BYTES_PER_ELEMENT;
  11070. default:
  11071. throw new DeveloperError('componentDatatype is not a valid value.');
  11072. }
  11073. };
  11074. /**
  11075. * Gets the {@link ComponentDatatype} for the provided TypedArray instance.
  11076. *
  11077. * @param {TypedArray} array The typed array.
  11078. * @returns {ComponentDatatype} The ComponentDatatype for the provided array, or undefined if the array is not a TypedArray.
  11079. */
  11080. ComponentDatatype.fromTypedArray = function(array) {
  11081. if (array instanceof Int8Array) {
  11082. return ComponentDatatype.BYTE;
  11083. }
  11084. if (array instanceof Uint8Array) {
  11085. return ComponentDatatype.UNSIGNED_BYTE;
  11086. }
  11087. if (array instanceof Int16Array) {
  11088. return ComponentDatatype.SHORT;
  11089. }
  11090. if (array instanceof Uint16Array) {
  11091. return ComponentDatatype.UNSIGNED_SHORT;
  11092. }
  11093. if (array instanceof Int32Array) {
  11094. return ComponentDatatype.INT;
  11095. }
  11096. if (array instanceof Uint32Array) {
  11097. return ComponentDatatype.UNSIGNED_INT;
  11098. }
  11099. if (array instanceof Float32Array) {
  11100. return ComponentDatatype.FLOAT;
  11101. }
  11102. if (array instanceof Float64Array) {
  11103. return ComponentDatatype.DOUBLE;
  11104. }
  11105. };
  11106. /**
  11107. * Validates that the provided component datatype is a valid {@link ComponentDatatype}
  11108. *
  11109. * @param {ComponentDatatype} componentDatatype The component datatype to validate.
  11110. * @returns {Boolean} <code>true</code> if the provided component datatype is a valid value; otherwise, <code>false</code>.
  11111. *
  11112. * @example
  11113. * if (!Cesium.ComponentDatatype.validate(componentDatatype)) {
  11114. * throw new Cesium.DeveloperError('componentDatatype must be a valid value.');
  11115. * }
  11116. */
  11117. ComponentDatatype.validate = function(componentDatatype) {
  11118. return defined(componentDatatype) &&
  11119. (componentDatatype === ComponentDatatype.BYTE ||
  11120. componentDatatype === ComponentDatatype.UNSIGNED_BYTE ||
  11121. componentDatatype === ComponentDatatype.SHORT ||
  11122. componentDatatype === ComponentDatatype.UNSIGNED_SHORT ||
  11123. componentDatatype === ComponentDatatype.INT ||
  11124. componentDatatype === ComponentDatatype.UNSIGNED_INT ||
  11125. componentDatatype === ComponentDatatype.FLOAT ||
  11126. componentDatatype === ComponentDatatype.DOUBLE);
  11127. };
  11128. /**
  11129. * Creates a typed array corresponding to component data type.
  11130. *
  11131. * @param {ComponentDatatype} componentDatatype The component data type.
  11132. * @param {Number|Array} valuesOrLength The length of the array to create or an array.
  11133. * @returns {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} A typed array.
  11134. *
  11135. * @exception {DeveloperError} componentDatatype is not a valid value.
  11136. *
  11137. * @example
  11138. * // creates a Float32Array with length of 100
  11139. * var typedArray = Cesium.ComponentDatatype.createTypedArray(Cesium.ComponentDatatype.FLOAT, 100);
  11140. */
  11141. ComponentDatatype.createTypedArray = function(componentDatatype, valuesOrLength) {
  11142. if (!defined(componentDatatype)) {
  11143. throw new DeveloperError('componentDatatype is required.');
  11144. }
  11145. if (!defined(valuesOrLength)) {
  11146. throw new DeveloperError('valuesOrLength is required.');
  11147. }
  11148. switch (componentDatatype) {
  11149. case ComponentDatatype.BYTE:
  11150. return new Int8Array(valuesOrLength);
  11151. case ComponentDatatype.UNSIGNED_BYTE:
  11152. return new Uint8Array(valuesOrLength);
  11153. case ComponentDatatype.SHORT:
  11154. return new Int16Array(valuesOrLength);
  11155. case ComponentDatatype.UNSIGNED_SHORT:
  11156. return new Uint16Array(valuesOrLength);
  11157. case ComponentDatatype.INT:
  11158. return new Int32Array(valuesOrLength);
  11159. case ComponentDatatype.UNSIGNED_INT:
  11160. return new Uint32Array(valuesOrLength);
  11161. case ComponentDatatype.FLOAT:
  11162. return new Float32Array(valuesOrLength);
  11163. case ComponentDatatype.DOUBLE:
  11164. return new Float64Array(valuesOrLength);
  11165. default:
  11166. throw new DeveloperError('componentDatatype is not a valid value.');
  11167. }
  11168. };
  11169. /**
  11170. * Creates a typed view of an array of bytes.
  11171. *
  11172. * @param {ComponentDatatype} componentDatatype The type of the view to create.
  11173. * @param {ArrayBuffer} buffer The buffer storage to use for the view.
  11174. * @param {Number} [byteOffset] The offset, in bytes, to the first element in the view.
  11175. * @param {Number} [length] The number of elements in the view.
  11176. * @returns {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} A typed array view of the buffer.
  11177. *
  11178. * @exception {DeveloperError} componentDatatype is not a valid value.
  11179. */
  11180. ComponentDatatype.createArrayBufferView = function(componentDatatype, buffer, byteOffset, length) {
  11181. if (!defined(componentDatatype)) {
  11182. throw new DeveloperError('componentDatatype is required.');
  11183. }
  11184. if (!defined(buffer)) {
  11185. throw new DeveloperError('buffer is required.');
  11186. }
  11187. byteOffset = defaultValue(byteOffset, 0);
  11188. length = defaultValue(length, (buffer.byteLength - byteOffset) / ComponentDatatype.getSizeInBytes(componentDatatype));
  11189. switch (componentDatatype) {
  11190. case ComponentDatatype.BYTE:
  11191. return new Int8Array(buffer, byteOffset, length);
  11192. case ComponentDatatype.UNSIGNED_BYTE:
  11193. return new Uint8Array(buffer, byteOffset, length);
  11194. case ComponentDatatype.SHORT:
  11195. return new Int16Array(buffer, byteOffset, length);
  11196. case ComponentDatatype.UNSIGNED_SHORT:
  11197. return new Uint16Array(buffer, byteOffset, length);
  11198. case ComponentDatatype.INT:
  11199. return new Int32Array(buffer, byteOffset, length);
  11200. case ComponentDatatype.UNSIGNED_INT:
  11201. return new Uint32Array(buffer, byteOffset, length);
  11202. case ComponentDatatype.FLOAT:
  11203. return new Float32Array(buffer, byteOffset, length);
  11204. case ComponentDatatype.DOUBLE:
  11205. return new Float64Array(buffer, byteOffset, length);
  11206. default:
  11207. throw new DeveloperError('componentDatatype is not a valid value.');
  11208. }
  11209. };
  11210. /**
  11211. * Get the ComponentDatatype from its name.
  11212. *
  11213. * @param {String} name The name of the ComponentDatatype.
  11214. * @returns {ComponentDatatype} The ComponentDatatype.
  11215. *
  11216. * @exception {DeveloperError} name is not a valid value.
  11217. */
  11218. ComponentDatatype.fromName = function(name) {
  11219. switch (name) {
  11220. case 'BYTE':
  11221. return ComponentDatatype.BYTE;
  11222. case 'UNSIGNED_BYTE':
  11223. return ComponentDatatype.UNSIGNED_BYTE;
  11224. case 'SHORT':
  11225. return ComponentDatatype.SHORT;
  11226. case 'UNSIGNED_SHORT':
  11227. return ComponentDatatype.UNSIGNED_SHORT;
  11228. case 'INT':
  11229. return ComponentDatatype.INT;
  11230. case 'UNSIGNED_INT':
  11231. return ComponentDatatype.UNSIGNED_INT;
  11232. case 'FLOAT':
  11233. return ComponentDatatype.FLOAT;
  11234. case 'DOUBLE':
  11235. return ComponentDatatype.DOUBLE;
  11236. default:
  11237. throw new DeveloperError('name is not a valid value.');
  11238. }
  11239. };
  11240. return freezeObject(ComponentDatatype);
  11241. });
  11242. /*global define*/
  11243. define('Core/GeometryType',[
  11244. './freezeObject'
  11245. ], function(
  11246. freezeObject) {
  11247. 'use strict';
  11248. /**
  11249. * @private
  11250. */
  11251. var GeometryType = {
  11252. NONE : 0,
  11253. TRIANGLES : 1,
  11254. LINES : 2,
  11255. POLYLINES : 3
  11256. };
  11257. return freezeObject(GeometryType);
  11258. });
  11259. /*global define*/
  11260. define('Core/PrimitiveType',[
  11261. './freezeObject',
  11262. './WebGLConstants'
  11263. ], function(
  11264. freezeObject,
  11265. WebGLConstants) {
  11266. 'use strict';
  11267. /**
  11268. * The type of a geometric primitive, i.e., points, lines, and triangles.
  11269. *
  11270. * @exports PrimitiveType
  11271. */
  11272. var PrimitiveType = {
  11273. /**
  11274. * Points primitive where each vertex (or index) is a separate point.
  11275. *
  11276. * @type {Number}
  11277. * @constant
  11278. */
  11279. POINTS : WebGLConstants.POINTS,
  11280. /**
  11281. * Lines primitive where each two vertices (or indices) is a line segment. Line segments are not necessarily connected.
  11282. *
  11283. * @type {Number}
  11284. * @constant
  11285. */
  11286. LINES : WebGLConstants.LINES,
  11287. /**
  11288. * Line loop primitive where each vertex (or index) after the first connects a line to
  11289. * the previous vertex, and the last vertex implicitly connects to the first.
  11290. *
  11291. * @type {Number}
  11292. * @constant
  11293. */
  11294. LINE_LOOP : WebGLConstants.LINE_LOOP,
  11295. /**
  11296. * Line strip primitive where each vertex (or index) after the first connects a line to the previous vertex.
  11297. *
  11298. * @type {Number}
  11299. * @constant
  11300. */
  11301. LINE_STRIP : WebGLConstants.LINE_STRIP,
  11302. /**
  11303. * Triangles primitive where each three vertices (or indices) is a triangle. Triangles do not necessarily share edges.
  11304. *
  11305. * @type {Number}
  11306. * @constant
  11307. */
  11308. TRIANGLES : WebGLConstants.TRIANGLES,
  11309. /**
  11310. * Triangle strip primitive where each vertex (or index) after the first two connect to
  11311. * the previous two vertices forming a triangle. For example, this can be used to model a wall.
  11312. *
  11313. * @type {Number}
  11314. * @constant
  11315. */
  11316. TRIANGLE_STRIP : WebGLConstants.TRIANGLE_STRIP,
  11317. /**
  11318. * Triangle fan primitive where each vertex (or index) after the first two connect to
  11319. * the previous vertex and the first vertex forming a triangle. For example, this can be used
  11320. * to model a cone or circle.
  11321. *
  11322. * @type {Number}
  11323. * @constant
  11324. */
  11325. TRIANGLE_FAN : WebGLConstants.TRIANGLE_FAN,
  11326. /**
  11327. * @private
  11328. */
  11329. validate : function(primitiveType) {
  11330. return primitiveType === PrimitiveType.POINTS ||
  11331. primitiveType === PrimitiveType.LINES ||
  11332. primitiveType === PrimitiveType.LINE_LOOP ||
  11333. primitiveType === PrimitiveType.LINE_STRIP ||
  11334. primitiveType === PrimitiveType.TRIANGLES ||
  11335. primitiveType === PrimitiveType.TRIANGLE_STRIP ||
  11336. primitiveType === PrimitiveType.TRIANGLE_FAN;
  11337. }
  11338. };
  11339. return freezeObject(PrimitiveType);
  11340. });
  11341. /*global define*/
  11342. define('Core/Geometry',[
  11343. './defaultValue',
  11344. './defined',
  11345. './DeveloperError',
  11346. './GeometryType',
  11347. './PrimitiveType'
  11348. ], function(
  11349. defaultValue,
  11350. defined,
  11351. DeveloperError,
  11352. GeometryType,
  11353. PrimitiveType) {
  11354. 'use strict';
  11355. /**
  11356. * A geometry representation with attributes forming vertices and optional index data
  11357. * defining primitives. Geometries and an {@link Appearance}, which describes the shading,
  11358. * can be assigned to a {@link Primitive} for visualization. A <code>Primitive</code> can
  11359. * be created from many heterogeneous - in many cases - geometries for performance.
  11360. * <p>
  11361. * Geometries can be transformed and optimized using functions in {@link GeometryPipeline}.
  11362. * </p>
  11363. *
  11364. * @alias Geometry
  11365. * @constructor
  11366. *
  11367. * @param {Object} options Object with the following properties:
  11368. * @param {GeometryAttributes} options.attributes Attributes, which make up the geometry's vertices.
  11369. * @param {PrimitiveType} [options.primitiveType=PrimitiveType.TRIANGLES] The type of primitives in the geometry.
  11370. * @param {Uint16Array|Uint32Array} [options.indices] Optional index data that determines the primitives in the geometry.
  11371. * @param {BoundingSphere} [options.boundingSphere] An optional bounding sphere that fully enclosed the geometry.
  11372. *
  11373. * @see PolygonGeometry
  11374. * @see RectangleGeometry
  11375. * @see EllipseGeometry
  11376. * @see CircleGeometry
  11377. * @see WallGeometry
  11378. * @see SimplePolylineGeometry
  11379. * @see BoxGeometry
  11380. * @see EllipsoidGeometry
  11381. *
  11382. * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Geometry%20and%20Appearances.html|Geometry and Appearances Demo}
  11383. *
  11384. * @example
  11385. * // Create geometry with a position attribute and indexed lines.
  11386. * var positions = new Float64Array([
  11387. * 0.0, 0.0, 0.0,
  11388. * 7500000.0, 0.0, 0.0,
  11389. * 0.0, 7500000.0, 0.0
  11390. * ]);
  11391. *
  11392. * var geometry = new Cesium.Geometry({
  11393. * attributes : {
  11394. * position : new Cesium.GeometryAttribute({
  11395. * componentDatatype : Cesium.ComponentDatatype.DOUBLE,
  11396. * componentsPerAttribute : 3,
  11397. * values : positions
  11398. * })
  11399. * },
  11400. * indices : new Uint16Array([0, 1, 1, 2, 2, 0]),
  11401. * primitiveType : Cesium.PrimitiveType.LINES,
  11402. * boundingSphere : Cesium.BoundingSphere.fromVertices(positions)
  11403. * });
  11404. */
  11405. function Geometry(options) {
  11406. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  11407. if (!defined(options.attributes)) {
  11408. throw new DeveloperError('options.attributes is required.');
  11409. }
  11410. /**
  11411. * Attributes, which make up the geometry's vertices. Each property in this object corresponds to a
  11412. * {@link GeometryAttribute} containing the attribute's data.
  11413. * <p>
  11414. * Attributes are always stored non-interleaved in a Geometry.
  11415. * </p>
  11416. * <p>
  11417. * There are reserved attribute names with well-known semantics. The following attributes
  11418. * are created by a Geometry (depending on the provided {@link VertexFormat}.
  11419. * <ul>
  11420. * <li><code>position</code> - 3D vertex position. 64-bit floating-point (for precision). 3 components per attribute. See {@link VertexFormat#position}.</li>
  11421. * <li><code>normal</code> - Normal (normalized), commonly used for lighting. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#normal}.</li>
  11422. * <li><code>st</code> - 2D texture coordinate. 32-bit floating-point. 2 components per attribute. See {@link VertexFormat#st}.</li>
  11423. * <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>
  11424. * <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>
  11425. * </ul>
  11426. * </p>
  11427. * <p>
  11428. * The following attribute names are generally not created by a Geometry, but are added
  11429. * to a Geometry by a {@link Primitive} or {@link GeometryPipeline} functions to prepare
  11430. * the geometry for rendering.
  11431. * <ul>
  11432. * <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>
  11433. * <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>
  11434. * <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>
  11435. * <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>
  11436. * <li><code>color</code> - RGBA color (normalized) usually from {@link GeometryInstance#color}. 32-bit floating-point. 4 components per attribute.</li>
  11437. * <li><code>pickColor</code> - RGBA color used for picking. 32-bit floating-point. 4 components per attribute.</li>
  11438. * </ul>
  11439. * </p>
  11440. *
  11441. * @type GeometryAttributes
  11442. *
  11443. * @default undefined
  11444. *
  11445. *
  11446. * @example
  11447. * geometry.attributes.position = new Cesium.GeometryAttribute({
  11448. * componentDatatype : Cesium.ComponentDatatype.FLOAT,
  11449. * componentsPerAttribute : 3,
  11450. * values : new Float32Array(0)
  11451. * });
  11452. *
  11453. * @see GeometryAttribute
  11454. * @see VertexFormat
  11455. */
  11456. this.attributes = options.attributes;
  11457. /**
  11458. * Optional index data that - along with {@link Geometry#primitiveType} -
  11459. * determines the primitives in the geometry.
  11460. *
  11461. * @type Array
  11462. *
  11463. * @default undefined
  11464. */
  11465. this.indices = options.indices;
  11466. /**
  11467. * The type of primitives in the geometry. This is most often {@link PrimitiveType.TRIANGLES},
  11468. * but can varying based on the specific geometry.
  11469. *
  11470. * @type PrimitiveType
  11471. *
  11472. * @default undefined
  11473. */
  11474. this.primitiveType = defaultValue(options.primitiveType, PrimitiveType.TRIANGLES);
  11475. /**
  11476. * An optional bounding sphere that fully encloses the geometry. This is
  11477. * commonly used for culling.
  11478. *
  11479. * @type BoundingSphere
  11480. *
  11481. * @default undefined
  11482. */
  11483. this.boundingSphere = options.boundingSphere;
  11484. /**
  11485. * @private
  11486. */
  11487. this.geometryType = defaultValue(options.geometryType, GeometryType.NONE);
  11488. /**
  11489. * @private
  11490. */
  11491. this.boundingSphereCV = options.boundingSphereCV;
  11492. }
  11493. /**
  11494. * Computes the number of vertices in a geometry. The runtime is linear with
  11495. * respect to the number of attributes in a vertex, not the number of vertices.
  11496. *
  11497. * @param {Geometry} geometry The geometry.
  11498. * @returns {Number} The number of vertices in the geometry.
  11499. *
  11500. * @example
  11501. * var numVertices = Cesium.Geometry.computeNumberOfVertices(geometry);
  11502. */
  11503. Geometry.computeNumberOfVertices = function(geometry) {
  11504. if (!defined(geometry)) {
  11505. throw new DeveloperError('geometry is required.');
  11506. }
  11507. var numberOfVertices = -1;
  11508. for ( var property in geometry.attributes) {
  11509. if (geometry.attributes.hasOwnProperty(property) &&
  11510. defined(geometry.attributes[property]) &&
  11511. defined(geometry.attributes[property].values)) {
  11512. var attribute = geometry.attributes[property];
  11513. var num = attribute.values.length / attribute.componentsPerAttribute;
  11514. if ((numberOfVertices !== num) && (numberOfVertices !== -1)) {
  11515. throw new DeveloperError('All attribute lists must have the same number of attributes.');
  11516. }
  11517. numberOfVertices = num;
  11518. }
  11519. }
  11520. return numberOfVertices;
  11521. };
  11522. return Geometry;
  11523. });
  11524. /*global define*/
  11525. define('Core/GeometryAttribute',[
  11526. './defaultValue',
  11527. './defined',
  11528. './DeveloperError'
  11529. ], function(
  11530. defaultValue,
  11531. defined,
  11532. DeveloperError) {
  11533. 'use strict';
  11534. /**
  11535. * Values and type information for geometry attributes. A {@link Geometry}
  11536. * generally contains one or more attributes. All attributes together form
  11537. * the geometry's vertices.
  11538. *
  11539. * @alias GeometryAttribute
  11540. * @constructor
  11541. *
  11542. * @param {Object} [options] Object with the following properties:
  11543. * @param {ComponentDatatype} [options.componentDatatype] The datatype of each component in the attribute, e.g., individual elements in values.
  11544. * @param {Number} [options.componentsPerAttribute] A number between 1 and 4 that defines the number of components in an attributes.
  11545. * @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.
  11546. * @param {TypedArray} [options.values] The values for the attributes stored in a typed array.
  11547. *
  11548. * @exception {DeveloperError} options.componentsPerAttribute must be between 1 and 4.
  11549. *
  11550. *
  11551. * @example
  11552. * var geometry = new Cesium.Geometry({
  11553. * attributes : {
  11554. * position : new Cesium.GeometryAttribute({
  11555. * componentDatatype : Cesium.ComponentDatatype.FLOAT,
  11556. * componentsPerAttribute : 3,
  11557. * values : new Float32Array([
  11558. * 0.0, 0.0, 0.0,
  11559. * 7500000.0, 0.0, 0.0,
  11560. * 0.0, 7500000.0, 0.0
  11561. * ])
  11562. * })
  11563. * },
  11564. * primitiveType : Cesium.PrimitiveType.LINE_LOOP
  11565. * });
  11566. *
  11567. * @see Geometry
  11568. */
  11569. function GeometryAttribute(options) {
  11570. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  11571. if (!defined(options.componentDatatype)) {
  11572. throw new DeveloperError('options.componentDatatype is required.');
  11573. }
  11574. if (!defined(options.componentsPerAttribute)) {
  11575. throw new DeveloperError('options.componentsPerAttribute is required.');
  11576. }
  11577. if (options.componentsPerAttribute < 1 || options.componentsPerAttribute > 4) {
  11578. throw new DeveloperError('options.componentsPerAttribute must be between 1 and 4.');
  11579. }
  11580. if (!defined(options.values)) {
  11581. throw new DeveloperError('options.values is required.');
  11582. }
  11583. /**
  11584. * The datatype of each component in the attribute, e.g., individual elements in
  11585. * {@link GeometryAttribute#values}.
  11586. *
  11587. * @type ComponentDatatype
  11588. *
  11589. * @default undefined
  11590. */
  11591. this.componentDatatype = options.componentDatatype;
  11592. /**
  11593. * A number between 1 and 4 that defines the number of components in an attributes.
  11594. * For example, a position attribute with x, y, and z components would have 3 as
  11595. * shown in the code example.
  11596. *
  11597. * @type Number
  11598. *
  11599. * @default undefined
  11600. *
  11601. * @example
  11602. * attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;
  11603. * attribute.componentsPerAttribute = 3;
  11604. * attribute.values = new Float32Array([
  11605. * 0.0, 0.0, 0.0,
  11606. * 7500000.0, 0.0, 0.0,
  11607. * 0.0, 7500000.0, 0.0
  11608. * ]);
  11609. */
  11610. this.componentsPerAttribute = options.componentsPerAttribute;
  11611. /**
  11612. * When <code>true</code> and <code>componentDatatype</code> is an integer format,
  11613. * indicate that the components should be mapped to the range [0, 1] (unsigned)
  11614. * or [-1, 1] (signed) when they are accessed as floating-point for rendering.
  11615. * <p>
  11616. * This is commonly used when storing colors using {@link ComponentDatatype.UNSIGNED_BYTE}.
  11617. * </p>
  11618. *
  11619. * @type Boolean
  11620. *
  11621. * @default false
  11622. *
  11623. * @example
  11624. * attribute.componentDatatype = Cesium.ComponentDatatype.UNSIGNED_BYTE;
  11625. * attribute.componentsPerAttribute = 4;
  11626. * attribute.normalize = true;
  11627. * attribute.values = new Uint8Array([
  11628. * Cesium.Color.floatToByte(color.red),
  11629. * Cesium.Color.floatToByte(color.green),
  11630. * Cesium.Color.floatToByte(color.blue),
  11631. * Cesium.Color.floatToByte(color.alpha)
  11632. * ]);
  11633. */
  11634. this.normalize = defaultValue(options.normalize, false);
  11635. /**
  11636. * The values for the attributes stored in a typed array. In the code example,
  11637. * every three elements in <code>values</code> defines one attributes since
  11638. * <code>componentsPerAttribute</code> is 3.
  11639. *
  11640. * @type TypedArray
  11641. *
  11642. * @default undefined
  11643. *
  11644. * @example
  11645. * attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;
  11646. * attribute.componentsPerAttribute = 3;
  11647. * attribute.values = new Float32Array([
  11648. * 0.0, 0.0, 0.0,
  11649. * 7500000.0, 0.0, 0.0,
  11650. * 0.0, 7500000.0, 0.0
  11651. * ]);
  11652. */
  11653. this.values = options.values;
  11654. }
  11655. return GeometryAttribute;
  11656. });
  11657. /*global define*/
  11658. define('Core/GeometryAttributes',[
  11659. './defaultValue'
  11660. ], function(
  11661. defaultValue) {
  11662. 'use strict';
  11663. /**
  11664. * Attributes, which make up a geometry's vertices. Each property in this object corresponds to a
  11665. * {@link GeometryAttribute} containing the attribute's data.
  11666. * <p>
  11667. * Attributes are always stored non-interleaved in a Geometry.
  11668. * </p>
  11669. *
  11670. * @alias GeometryAttributes
  11671. * @constructor
  11672. */
  11673. function GeometryAttributes(options) {
  11674. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  11675. /**
  11676. * The 3D position attribute.
  11677. * <p>
  11678. * 64-bit floating-point (for precision). 3 components per attribute.
  11679. * </p>
  11680. *
  11681. * @type GeometryAttribute
  11682. *
  11683. * @default undefined
  11684. */
  11685. this.position = options.position;
  11686. /**
  11687. * The normal attribute (normalized), which is commonly used for lighting.
  11688. * <p>
  11689. * 32-bit floating-point. 3 components per attribute.
  11690. * </p>
  11691. *
  11692. * @type GeometryAttribute
  11693. *
  11694. * @default undefined
  11695. */
  11696. this.normal = options.normal;
  11697. /**
  11698. * The 2D texture coordinate attribute.
  11699. * <p>
  11700. * 32-bit floating-point. 2 components per attribute
  11701. * </p>
  11702. *
  11703. * @type GeometryAttribute
  11704. *
  11705. * @default undefined
  11706. */
  11707. this.st = options.st;
  11708. /**
  11709. * The binormal attribute (normalized), which is used for tangent-space effects like bump mapping.
  11710. * <p>
  11711. * 32-bit floating-point. 3 components per attribute.
  11712. * </p>
  11713. *
  11714. * @type GeometryAttribute
  11715. *
  11716. * @default undefined
  11717. */
  11718. this.binormal = options.binormal;
  11719. /**
  11720. * The tangent attribute (normalized), which is used for tangent-space effects like bump mapping.
  11721. * <p>
  11722. * 32-bit floating-point. 3 components per attribute.
  11723. * </p>
  11724. *
  11725. * @type GeometryAttribute
  11726. *
  11727. * @default undefined
  11728. */
  11729. this.tangent = options.tangent;
  11730. /**
  11731. * The color attribute.
  11732. * <p>
  11733. * 8-bit unsigned integer. 4 components per attribute.
  11734. * </p>
  11735. *
  11736. * @type GeometryAttribute
  11737. *
  11738. * @default undefined
  11739. */
  11740. this.color = options.color;
  11741. }
  11742. return GeometryAttributes;
  11743. });
  11744. /*global define*/
  11745. define('Core/IndexDatatype',[
  11746. './defined',
  11747. './DeveloperError',
  11748. './freezeObject',
  11749. './Math',
  11750. './WebGLConstants'
  11751. ], function(
  11752. defined,
  11753. DeveloperError,
  11754. freezeObject,
  11755. CesiumMath,
  11756. WebGLConstants) {
  11757. 'use strict';
  11758. /**
  11759. * Constants for WebGL index datatypes. These corresponds to the
  11760. * <code>type</code> parameter of {@link http://www.khronos.org/opengles/sdk/docs/man/xhtml/glDrawElements.xml|drawElements}.
  11761. *
  11762. * @exports IndexDatatype
  11763. */
  11764. var IndexDatatype = {
  11765. /**
  11766. * 8-bit unsigned byte corresponding to <code>UNSIGNED_BYTE</code> and the type
  11767. * of an element in <code>Uint8Array</code>.
  11768. *
  11769. * @type {Number}
  11770. * @constant
  11771. */
  11772. UNSIGNED_BYTE : WebGLConstants.UNSIGNED_BYTE,
  11773. /**
  11774. * 16-bit unsigned short corresponding to <code>UNSIGNED_SHORT</code> and the type
  11775. * of an element in <code>Uint16Array</code>.
  11776. *
  11777. * @type {Number}
  11778. * @constant
  11779. */
  11780. UNSIGNED_SHORT : WebGLConstants.UNSIGNED_SHORT,
  11781. /**
  11782. * 32-bit unsigned int corresponding to <code>UNSIGNED_INT</code> and the type
  11783. * of an element in <code>Uint32Array</code>.
  11784. *
  11785. * @type {Number}
  11786. * @constant
  11787. */
  11788. UNSIGNED_INT : WebGLConstants.UNSIGNED_INT
  11789. };
  11790. /**
  11791. * Returns the size, in bytes, of the corresponding datatype.
  11792. *
  11793. * @param {IndexDatatype} indexDatatype The index datatype to get the size of.
  11794. * @returns {Number} The size in bytes.
  11795. *
  11796. * @example
  11797. * // Returns 2
  11798. * var size = Cesium.IndexDatatype.getSizeInBytes(Cesium.IndexDatatype.UNSIGNED_SHORT);
  11799. */
  11800. IndexDatatype.getSizeInBytes = function(indexDatatype) {
  11801. switch(indexDatatype) {
  11802. case IndexDatatype.UNSIGNED_BYTE:
  11803. return Uint8Array.BYTES_PER_ELEMENT;
  11804. case IndexDatatype.UNSIGNED_SHORT:
  11805. return Uint16Array.BYTES_PER_ELEMENT;
  11806. case IndexDatatype.UNSIGNED_INT:
  11807. return Uint32Array.BYTES_PER_ELEMENT;
  11808. }
  11809. throw new DeveloperError('indexDatatype is required and must be a valid IndexDatatype constant.');
  11810. };
  11811. /**
  11812. * Validates that the provided index datatype is a valid {@link IndexDatatype}.
  11813. *
  11814. * @param {IndexDatatype} indexDatatype The index datatype to validate.
  11815. * @returns {Boolean} <code>true</code> if the provided index datatype is a valid value; otherwise, <code>false</code>.
  11816. *
  11817. * @example
  11818. * if (!Cesium.IndexDatatype.validate(indexDatatype)) {
  11819. * throw new Cesium.DeveloperError('indexDatatype must be a valid value.');
  11820. * }
  11821. */
  11822. IndexDatatype.validate = function(indexDatatype) {
  11823. return defined(indexDatatype) &&
  11824. (indexDatatype === IndexDatatype.UNSIGNED_BYTE ||
  11825. indexDatatype === IndexDatatype.UNSIGNED_SHORT ||
  11826. indexDatatype === IndexDatatype.UNSIGNED_INT);
  11827. };
  11828. /**
  11829. * Creates a typed array that will store indices, using either <code><Uint16Array</code>
  11830. * or <code>Uint32Array</code> depending on the number of vertices.
  11831. *
  11832. * @param {Number} numberOfVertices Number of vertices that the indices will reference.
  11833. * @param {Any} indicesLengthOrArray Passed through to the typed array constructor.
  11834. * @returns {Uint16Array|Uint32Array} A <code>Uint16Array</code> or <code>Uint32Array</code> constructed with <code>indicesLengthOrArray</code>.
  11835. *
  11836. * @example
  11837. * this.indices = Cesium.IndexDatatype.createTypedArray(positions.length / 3, numberOfIndices);
  11838. */
  11839. IndexDatatype.createTypedArray = function(numberOfVertices, indicesLengthOrArray) {
  11840. if (!defined(numberOfVertices)) {
  11841. throw new DeveloperError('numberOfVertices is required.');
  11842. }
  11843. if (numberOfVertices >= CesiumMath.SIXTY_FOUR_KILOBYTES) {
  11844. return new Uint32Array(indicesLengthOrArray);
  11845. }
  11846. return new Uint16Array(indicesLengthOrArray);
  11847. };
  11848. /**
  11849. * Creates a typed array from a source array buffer. The resulting typed array will store indices, using either <code><Uint16Array</code>
  11850. * or <code>Uint32Array</code> depending on the number of vertices.
  11851. *
  11852. * @param {Number} numberOfVertices Number of vertices that the indices will reference.
  11853. * @param {ArrayBuffer} sourceArray Passed through to the typed array constructor.
  11854. * @param {Number} byteOffset Passed through to the typed array constructor.
  11855. * @param {Number} length Passed through to the typed array constructor.
  11856. * @returns {Uint16Array|Uint32Array} A <code>Uint16Array</code> or <code>Uint32Array</code> constructed with <code>sourceArray</code>, <code>byteOffset</code>, and <code>length</code>.
  11857. *
  11858. */
  11859. IndexDatatype.createTypedArrayFromArrayBuffer = function(numberOfVertices, sourceArray, byteOffset, length) {
  11860. if (!defined(numberOfVertices)) {
  11861. throw new DeveloperError('numberOfVertices is required.');
  11862. }
  11863. if (!defined(sourceArray)) {
  11864. throw new DeveloperError('sourceArray is required.');
  11865. }
  11866. if (!defined(byteOffset)) {
  11867. throw new DeveloperError('byteOffset is required.');
  11868. }
  11869. if (numberOfVertices >= CesiumMath.SIXTY_FOUR_KILOBYTES) {
  11870. return new Uint32Array(sourceArray, byteOffset, length);
  11871. }
  11872. return new Uint16Array(sourceArray, byteOffset, length);
  11873. };
  11874. return freezeObject(IndexDatatype);
  11875. });
  11876. /*global define*/
  11877. define('Core/VertexFormat',[
  11878. './defaultValue',
  11879. './defined',
  11880. './DeveloperError',
  11881. './freezeObject'
  11882. ], function(
  11883. defaultValue,
  11884. defined,
  11885. DeveloperError,
  11886. freezeObject) {
  11887. 'use strict';
  11888. /**
  11889. * A vertex format defines what attributes make up a vertex. A VertexFormat can be provided
  11890. * to a {@link Geometry} to request that certain properties be computed, e.g., just position,
  11891. * position and normal, etc.
  11892. *
  11893. * @param {Object} [options] An object with boolean properties corresponding to VertexFormat properties as shown in the code example.
  11894. *
  11895. * @alias VertexFormat
  11896. * @constructor
  11897. *
  11898. * @example
  11899. * // Create a vertex format with position and 2D texture coordinate attributes.
  11900. * var format = new Cesium.VertexFormat({
  11901. * position : true,
  11902. * st : true
  11903. * });
  11904. *
  11905. * @see Geometry#attributes
  11906. * @see Packable
  11907. */
  11908. function VertexFormat(options) {
  11909. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  11910. /**
  11911. * When <code>true</code>, the vertex has a 3D position attribute.
  11912. * <p>
  11913. * 64-bit floating-point (for precision). 3 components per attribute.
  11914. * </p>
  11915. *
  11916. * @type Boolean
  11917. *
  11918. * @default false
  11919. */
  11920. this.position = defaultValue(options.position, false);
  11921. /**
  11922. * When <code>true</code>, the vertex has a normal attribute (normalized), which is commonly used for lighting.
  11923. * <p>
  11924. * 32-bit floating-point. 3 components per attribute.
  11925. * </p>
  11926. *
  11927. * @type Boolean
  11928. *
  11929. * @default false
  11930. */
  11931. this.normal = defaultValue(options.normal, false);
  11932. /**
  11933. * When <code>true</code>, the vertex has a 2D texture coordinate attribute.
  11934. * <p>
  11935. * 32-bit floating-point. 2 components per attribute
  11936. * </p>
  11937. *
  11938. * @type Boolean
  11939. *
  11940. * @default false
  11941. */
  11942. this.st = defaultValue(options.st, false);
  11943. /**
  11944. * When <code>true</code>, the vertex has a binormal attribute (normalized), which is used for tangent-space effects like bump mapping.
  11945. * <p>
  11946. * 32-bit floating-point. 3 components per attribute.
  11947. * </p>
  11948. *
  11949. * @type Boolean
  11950. *
  11951. * @default false
  11952. */
  11953. this.binormal = defaultValue(options.binormal, false);
  11954. /**
  11955. * When <code>true</code>, the vertex has a tangent attribute (normalized), which is used for tangent-space effects like bump mapping.
  11956. * <p>
  11957. * 32-bit floating-point. 3 components per attribute.
  11958. * </p>
  11959. *
  11960. * @type Boolean
  11961. *
  11962. * @default false
  11963. */
  11964. this.tangent = defaultValue(options.tangent, false);
  11965. /**
  11966. * When <code>true</code>, the vertex has an RGB color attribute.
  11967. * <p>
  11968. * 8-bit unsigned byte. 3 components per attribute.
  11969. * </p>
  11970. *
  11971. * @type Boolean
  11972. *
  11973. * @default false
  11974. */
  11975. this.color = defaultValue(options.color, false);
  11976. }
  11977. /**
  11978. * An immutable vertex format with only a position attribute.
  11979. *
  11980. * @type {VertexFormat}
  11981. * @constant
  11982. *
  11983. * @see VertexFormat#position
  11984. */
  11985. VertexFormat.POSITION_ONLY = freezeObject(new VertexFormat({
  11986. position : true
  11987. }));
  11988. /**
  11989. * An immutable vertex format with position and normal attributes.
  11990. * This is compatible with per-instance color appearances like {@link PerInstanceColorAppearance}.
  11991. *
  11992. * @type {VertexFormat}
  11993. * @constant
  11994. *
  11995. * @see VertexFormat#position
  11996. * @see VertexFormat#normal
  11997. */
  11998. VertexFormat.POSITION_AND_NORMAL = freezeObject(new VertexFormat({
  11999. position : true,
  12000. normal : true
  12001. }));
  12002. /**
  12003. * An immutable vertex format with position, normal, and st attributes.
  12004. * This is compatible with {@link MaterialAppearance} when {@link MaterialAppearance#materialSupport}
  12005. * is <code>TEXTURED/code>.
  12006. *
  12007. * @type {VertexFormat}
  12008. * @constant
  12009. *
  12010. * @see VertexFormat#position
  12011. * @see VertexFormat#normal
  12012. * @see VertexFormat#st
  12013. */
  12014. VertexFormat.POSITION_NORMAL_AND_ST = freezeObject(new VertexFormat({
  12015. position : true,
  12016. normal : true,
  12017. st : true
  12018. }));
  12019. /**
  12020. * An immutable vertex format with position and st attributes.
  12021. * This is compatible with {@link EllipsoidSurfaceAppearance}.
  12022. *
  12023. * @type {VertexFormat}
  12024. * @constant
  12025. *
  12026. * @see VertexFormat#position
  12027. * @see VertexFormat#st
  12028. */
  12029. VertexFormat.POSITION_AND_ST = freezeObject(new VertexFormat({
  12030. position : true,
  12031. st : true
  12032. }));
  12033. /**
  12034. * An immutable vertex format with position and color attributes.
  12035. *
  12036. * @type {VertexFormat}
  12037. * @constant
  12038. *
  12039. * @see VertexFormat#position
  12040. * @see VertexFormat#color
  12041. */
  12042. VertexFormat.POSITION_AND_COLOR = freezeObject(new VertexFormat({
  12043. position : true,
  12044. color : true
  12045. }));
  12046. /**
  12047. * An immutable vertex format with well-known attributes: position, normal, st, binormal, and tangent.
  12048. *
  12049. * @type {VertexFormat}
  12050. * @constant
  12051. *
  12052. * @see VertexFormat#position
  12053. * @see VertexFormat#normal
  12054. * @see VertexFormat#st
  12055. * @see VertexFormat#binormal
  12056. * @see VertexFormat#tangent
  12057. */
  12058. VertexFormat.ALL = freezeObject(new VertexFormat({
  12059. position : true,
  12060. normal : true,
  12061. st : true,
  12062. binormal : true,
  12063. tangent : true
  12064. }));
  12065. /**
  12066. * An immutable vertex format with position, normal, and st attributes.
  12067. * This is compatible with most appearances and materials; however
  12068. * normal and st attributes are not always required. When this is
  12069. * known in advance, another <code>VertexFormat</code> should be used.
  12070. *
  12071. * @type {VertexFormat}
  12072. * @constant
  12073. *
  12074. * @see VertexFormat#position
  12075. * @see VertexFormat#normal
  12076. */
  12077. VertexFormat.DEFAULT = VertexFormat.POSITION_NORMAL_AND_ST;
  12078. /**
  12079. * The number of elements used to pack the object into an array.
  12080. * @type {Number}
  12081. */
  12082. VertexFormat.packedLength = 6;
  12083. /**
  12084. * Stores the provided instance into the provided array.
  12085. *
  12086. * @param {VertexFormat} value The value to pack.
  12087. * @param {Number[]} array The array to pack into.
  12088. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  12089. *
  12090. * @returns {Number[]} The array that was packed into
  12091. */
  12092. VertexFormat.pack = function(value, array, startingIndex) {
  12093. if (!defined(value)) {
  12094. throw new DeveloperError('value is required');
  12095. }
  12096. if (!defined(array)) {
  12097. throw new DeveloperError('array is required');
  12098. }
  12099. startingIndex = defaultValue(startingIndex, 0);
  12100. array[startingIndex++] = value.position ? 1.0 : 0.0;
  12101. array[startingIndex++] = value.normal ? 1.0 : 0.0;
  12102. array[startingIndex++] = value.st ? 1.0 : 0.0;
  12103. array[startingIndex++] = value.binormal ? 1.0 : 0.0;
  12104. array[startingIndex++] = value.tangent ? 1.0 : 0.0;
  12105. array[startingIndex++] = value.color ? 1.0 : 0.0;
  12106. return array;
  12107. };
  12108. /**
  12109. * Retrieves an instance from a packed array.
  12110. *
  12111. * @param {Number[]} array The packed array.
  12112. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  12113. * @param {VertexFormat} [result] The object into which to store the result.
  12114. * @returns {VertexFormat} The modified result parameter or a new VertexFormat instance if one was not provided.
  12115. */
  12116. VertexFormat.unpack = function(array, startingIndex, result) {
  12117. if (!defined(array)) {
  12118. throw new DeveloperError('array is required');
  12119. }
  12120. startingIndex = defaultValue(startingIndex, 0);
  12121. if (!defined(result)) {
  12122. result = new VertexFormat();
  12123. }
  12124. result.position = array[startingIndex++] === 1.0;
  12125. result.normal = array[startingIndex++] === 1.0;
  12126. result.st = array[startingIndex++] === 1.0;
  12127. result.binormal = array[startingIndex++] === 1.0;
  12128. result.tangent = array[startingIndex++] === 1.0;
  12129. result.color = array[startingIndex++] === 1.0;
  12130. return result;
  12131. };
  12132. /**
  12133. * Duplicates a VertexFormat instance.
  12134. *
  12135. * @param {VertexFormat} cartesian The vertex format to duplicate.
  12136. * @param {VertexFormat} [result] The object onto which to store the result.
  12137. * @returns {VertexFormat} The modified result parameter or a new VertexFormat instance if one was not provided. (Returns undefined if vertexFormat is undefined)
  12138. */
  12139. VertexFormat.clone = function(vertexFormat, result) {
  12140. if (!defined(vertexFormat)) {
  12141. return undefined;
  12142. }
  12143. if (!defined(result)) {
  12144. result = new VertexFormat();
  12145. }
  12146. result.position = vertexFormat.position;
  12147. result.normal = vertexFormat.normal;
  12148. result.st = vertexFormat.st;
  12149. result.binormal = vertexFormat.binormal;
  12150. result.tangent = vertexFormat.tangent;
  12151. result.color = vertexFormat.color;
  12152. return result;
  12153. };
  12154. return VertexFormat;
  12155. });
  12156. /*global define*/
  12157. define('Core/AxisAlignedBoundingBox',[
  12158. './Cartesian3',
  12159. './defaultValue',
  12160. './defined',
  12161. './DeveloperError',
  12162. './Intersect'
  12163. ], function(
  12164. Cartesian3,
  12165. defaultValue,
  12166. defined,
  12167. DeveloperError,
  12168. Intersect) {
  12169. 'use strict';
  12170. /**
  12171. * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.
  12172. * @alias AxisAlignedBoundingBox
  12173. * @constructor
  12174. *
  12175. * @param {Cartesian3} [minimum=Cartesian3.ZERO] The minimum point along the x, y, and z axes.
  12176. * @param {Cartesian3} [maximum=Cartesian3.ZERO] The maximum point along the x, y, and z axes.
  12177. * @param {Cartesian3} [center] The center of the box; automatically computed if not supplied.
  12178. *
  12179. * @see BoundingSphere
  12180. * @see BoundingRectangle
  12181. */
  12182. function AxisAlignedBoundingBox(minimum, maximum, center) {
  12183. /**
  12184. * The minimum point defining the bounding box.
  12185. * @type {Cartesian3}
  12186. * @default {@link Cartesian3.ZERO}
  12187. */
  12188. this.minimum = Cartesian3.clone(defaultValue(minimum, Cartesian3.ZERO));
  12189. /**
  12190. * The maximum point defining the bounding box.
  12191. * @type {Cartesian3}
  12192. * @default {@link Cartesian3.ZERO}
  12193. */
  12194. this.maximum = Cartesian3.clone(defaultValue(maximum, Cartesian3.ZERO));
  12195. //If center was not defined, compute it.
  12196. if (!defined(center)) {
  12197. center = Cartesian3.add(this.minimum, this.maximum, new Cartesian3());
  12198. Cartesian3.multiplyByScalar(center, 0.5, center);
  12199. } else {
  12200. center = Cartesian3.clone(center);
  12201. }
  12202. /**
  12203. * The center point of the bounding box.
  12204. * @type {Cartesian3}
  12205. */
  12206. this.center = center;
  12207. }
  12208. /**
  12209. * Computes an instance of an AxisAlignedBoundingBox. The box is determined by
  12210. * finding the points spaced the farthest apart on the x, y, and z axes.
  12211. *
  12212. * @param {Cartesian3[]} positions List of points that the bounding box will enclose. Each point must have a <code>x</code>, <code>y</code>, and <code>z</code> properties.
  12213. * @param {AxisAlignedBoundingBox} [result] The object onto which to store the result.
  12214. * @returns {AxisAlignedBoundingBox} The modified result parameter or a new AxisAlignedBoundingBox instance if one was not provided.
  12215. *
  12216. * @example
  12217. * // Compute an axis aligned bounding box enclosing two points.
  12218. * var box = Cesium.AxisAlignedBoundingBox.fromPoints([new Cesium.Cartesian3(2, 0, 0), new Cesium.Cartesian3(-2, 0, 0)]);
  12219. */
  12220. AxisAlignedBoundingBox.fromPoints = function(positions, result) {
  12221. if (!defined(result)) {
  12222. result = new AxisAlignedBoundingBox();
  12223. }
  12224. if (!defined(positions) || positions.length === 0) {
  12225. result.minimum = Cartesian3.clone(Cartesian3.ZERO, result.minimum);
  12226. result.maximum = Cartesian3.clone(Cartesian3.ZERO, result.maximum);
  12227. result.center = Cartesian3.clone(Cartesian3.ZERO, result.center);
  12228. return result;
  12229. }
  12230. var minimumX = positions[0].x;
  12231. var minimumY = positions[0].y;
  12232. var minimumZ = positions[0].z;
  12233. var maximumX = positions[0].x;
  12234. var maximumY = positions[0].y;
  12235. var maximumZ = positions[0].z;
  12236. var length = positions.length;
  12237. for ( var i = 1; i < length; i++) {
  12238. var p = positions[i];
  12239. var x = p.x;
  12240. var y = p.y;
  12241. var z = p.z;
  12242. minimumX = Math.min(x, minimumX);
  12243. maximumX = Math.max(x, maximumX);
  12244. minimumY = Math.min(y, minimumY);
  12245. maximumY = Math.max(y, maximumY);
  12246. minimumZ = Math.min(z, minimumZ);
  12247. maximumZ = Math.max(z, maximumZ);
  12248. }
  12249. var minimum = result.minimum;
  12250. minimum.x = minimumX;
  12251. minimum.y = minimumY;
  12252. minimum.z = minimumZ;
  12253. var maximum = result.maximum;
  12254. maximum.x = maximumX;
  12255. maximum.y = maximumY;
  12256. maximum.z = maximumZ;
  12257. var center = Cartesian3.add(minimum, maximum, result.center);
  12258. Cartesian3.multiplyByScalar(center, 0.5, center);
  12259. return result;
  12260. };
  12261. /**
  12262. * Duplicates a AxisAlignedBoundingBox instance.
  12263. *
  12264. * @param {AxisAlignedBoundingBox} box The bounding box to duplicate.
  12265. * @param {AxisAlignedBoundingBox} [result] The object onto which to store the result.
  12266. * @returns {AxisAlignedBoundingBox} The modified result parameter or a new AxisAlignedBoundingBox instance if none was provided. (Returns undefined if box is undefined)
  12267. */
  12268. AxisAlignedBoundingBox.clone = function(box, result) {
  12269. if (!defined(box)) {
  12270. return undefined;
  12271. }
  12272. if (!defined(result)) {
  12273. return new AxisAlignedBoundingBox(box.minimum, box.maximum);
  12274. }
  12275. result.minimum = Cartesian3.clone(box.minimum, result.minimum);
  12276. result.maximum = Cartesian3.clone(box.maximum, result.maximum);
  12277. result.center = Cartesian3.clone(box.center, result.center);
  12278. return result;
  12279. };
  12280. /**
  12281. * Compares the provided AxisAlignedBoundingBox componentwise and returns
  12282. * <code>true</code> if they are equal, <code>false</code> otherwise.
  12283. *
  12284. * @param {AxisAlignedBoundingBox} [left] The first AxisAlignedBoundingBox.
  12285. * @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox.
  12286. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  12287. */
  12288. AxisAlignedBoundingBox.equals = function(left, right) {
  12289. return (left === right) ||
  12290. ((defined(left)) &&
  12291. (defined(right)) &&
  12292. Cartesian3.equals(left.center, right.center) &&
  12293. Cartesian3.equals(left.minimum, right.minimum) &&
  12294. Cartesian3.equals(left.maximum, right.maximum));
  12295. };
  12296. var intersectScratch = new Cartesian3();
  12297. /**
  12298. * Determines which side of a plane a box is located.
  12299. *
  12300. * @param {AxisAlignedBoundingBox} box The bounding box to test.
  12301. * @param {Plane} plane The plane to test against.
  12302. * @returns {Intersect} {@link Intersect.INSIDE} if the entire box is on the side of the plane
  12303. * the normal is pointing, {@link Intersect.OUTSIDE} if the entire box is
  12304. * on the opposite side, and {@link Intersect.INTERSECTING} if the box
  12305. * intersects the plane.
  12306. */
  12307. AxisAlignedBoundingBox.intersectPlane = function(box, plane) {
  12308. if (!defined(box)) {
  12309. throw new DeveloperError('box is required.');
  12310. }
  12311. if (!defined(plane)) {
  12312. throw new DeveloperError('plane is required.');
  12313. }
  12314. intersectScratch = Cartesian3.subtract(box.maximum, box.minimum, intersectScratch);
  12315. var h = Cartesian3.multiplyByScalar(intersectScratch, 0.5, intersectScratch); //The positive half diagonal
  12316. var normal = plane.normal;
  12317. var e = h.x * Math.abs(normal.x) + h.y * Math.abs(normal.y) + h.z * Math.abs(normal.z);
  12318. var s = Cartesian3.dot(box.center, normal) + plane.distance; //signed distance from center
  12319. if (s - e > 0) {
  12320. return Intersect.INSIDE;
  12321. }
  12322. if (s + e < 0) {
  12323. //Not in front because normals point inward
  12324. return Intersect.OUTSIDE;
  12325. }
  12326. return Intersect.INTERSECTING;
  12327. };
  12328. /**
  12329. * Duplicates this AxisAlignedBoundingBox instance.
  12330. *
  12331. * @param {AxisAlignedBoundingBox} [result] The object onto which to store the result.
  12332. * @returns {AxisAlignedBoundingBox} The modified result parameter or a new AxisAlignedBoundingBox instance if one was not provided.
  12333. */
  12334. AxisAlignedBoundingBox.prototype.clone = function(result) {
  12335. return AxisAlignedBoundingBox.clone(this, result);
  12336. };
  12337. /**
  12338. * Determines which side of a plane this box is located.
  12339. *
  12340. * @param {Plane} plane The plane to test against.
  12341. * @returns {Intersect} {@link Intersect.INSIDE} if the entire box is on the side of the plane
  12342. * the normal is pointing, {@link Intersect.OUTSIDE} if the entire box is
  12343. * on the opposite side, and {@link Intersect.INTERSECTING} if the box
  12344. * intersects the plane.
  12345. */
  12346. AxisAlignedBoundingBox.prototype.intersectPlane = function(plane) {
  12347. return AxisAlignedBoundingBox.intersectPlane(this, plane);
  12348. };
  12349. /**
  12350. * Compares this AxisAlignedBoundingBox against the provided AxisAlignedBoundingBox componentwise and returns
  12351. * <code>true</code> if they are equal, <code>false</code> otherwise.
  12352. *
  12353. * @param {AxisAlignedBoundingBox} [right] The right hand side AxisAlignedBoundingBox.
  12354. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  12355. */
  12356. AxisAlignedBoundingBox.prototype.equals = function(right) {
  12357. return AxisAlignedBoundingBox.equals(this, right);
  12358. };
  12359. return AxisAlignedBoundingBox;
  12360. });
  12361. /*global define*/
  12362. define('Core/Cartesian2',[
  12363. './defaultValue',
  12364. './defined',
  12365. './DeveloperError',
  12366. './freezeObject',
  12367. './Math'
  12368. ], function(
  12369. defaultValue,
  12370. defined,
  12371. DeveloperError,
  12372. freezeObject,
  12373. CesiumMath) {
  12374. 'use strict';
  12375. /**
  12376. * A 2D Cartesian point.
  12377. * @alias Cartesian2
  12378. * @constructor
  12379. *
  12380. * @param {Number} [x=0.0] The X component.
  12381. * @param {Number} [y=0.0] The Y component.
  12382. *
  12383. * @see Cartesian3
  12384. * @see Cartesian4
  12385. * @see Packable
  12386. */
  12387. function Cartesian2(x, y) {
  12388. /**
  12389. * The X component.
  12390. * @type {Number}
  12391. * @default 0.0
  12392. */
  12393. this.x = defaultValue(x, 0.0);
  12394. /**
  12395. * The Y component.
  12396. * @type {Number}
  12397. * @default 0.0
  12398. */
  12399. this.y = defaultValue(y, 0.0);
  12400. }
  12401. /**
  12402. * Creates a Cartesian2 instance from x and y coordinates.
  12403. *
  12404. * @param {Number} x The x coordinate.
  12405. * @param {Number} y The y coordinate.
  12406. * @param {Cartesian2} [result] The object onto which to store the result.
  12407. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
  12408. */
  12409. Cartesian2.fromElements = function(x, y, result) {
  12410. if (!defined(result)) {
  12411. return new Cartesian2(x, y);
  12412. }
  12413. result.x = x;
  12414. result.y = y;
  12415. return result;
  12416. };
  12417. /**
  12418. * Duplicates a Cartesian2 instance.
  12419. *
  12420. * @param {Cartesian2} cartesian The Cartesian to duplicate.
  12421. * @param {Cartesian2} [result] The object onto which to store the result.
  12422. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided. (Returns undefined if cartesian is undefined)
  12423. */
  12424. Cartesian2.clone = function(cartesian, result) {
  12425. if (!defined(cartesian)) {
  12426. return undefined;
  12427. }
  12428. if (!defined(result)) {
  12429. return new Cartesian2(cartesian.x, cartesian.y);
  12430. }
  12431. result.x = cartesian.x;
  12432. result.y = cartesian.y;
  12433. return result;
  12434. };
  12435. /**
  12436. * Creates a Cartesian2 instance from an existing Cartesian3. This simply takes the
  12437. * x and y properties of the Cartesian3 and drops z.
  12438. * @function
  12439. *
  12440. * @param {Cartesian3} cartesian The Cartesian3 instance to create a Cartesian2 instance from.
  12441. * @param {Cartesian2} [result] The object onto which to store the result.
  12442. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
  12443. */
  12444. Cartesian2.fromCartesian3 = Cartesian2.clone;
  12445. /**
  12446. * Creates a Cartesian2 instance from an existing Cartesian4. This simply takes the
  12447. * x and y properties of the Cartesian4 and drops z and w.
  12448. * @function
  12449. *
  12450. * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian2 instance from.
  12451. * @param {Cartesian2} [result] The object onto which to store the result.
  12452. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
  12453. */
  12454. Cartesian2.fromCartesian4 = Cartesian2.clone;
  12455. /**
  12456. * The number of elements used to pack the object into an array.
  12457. * @type {Number}
  12458. */
  12459. Cartesian2.packedLength = 2;
  12460. /**
  12461. * Stores the provided instance into the provided array.
  12462. *
  12463. * @param {Cartesian2} value The value to pack.
  12464. * @param {Number[]} array The array to pack into.
  12465. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  12466. *
  12467. * @returns {Number[]} The array that was packed into
  12468. */
  12469. Cartesian2.pack = function(value, array, startingIndex) {
  12470. if (!defined(value)) {
  12471. throw new DeveloperError('value is required');
  12472. }
  12473. if (!defined(array)) {
  12474. throw new DeveloperError('array is required');
  12475. }
  12476. startingIndex = defaultValue(startingIndex, 0);
  12477. array[startingIndex++] = value.x;
  12478. array[startingIndex] = value.y;
  12479. return array;
  12480. };
  12481. /**
  12482. * Retrieves an instance from a packed array.
  12483. *
  12484. * @param {Number[]} array The packed array.
  12485. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  12486. * @param {Cartesian2} [result] The object into which to store the result.
  12487. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
  12488. */
  12489. Cartesian2.unpack = function(array, startingIndex, result) {
  12490. if (!defined(array)) {
  12491. throw new DeveloperError('array is required');
  12492. }
  12493. startingIndex = defaultValue(startingIndex, 0);
  12494. if (!defined(result)) {
  12495. result = new Cartesian2();
  12496. }
  12497. result.x = array[startingIndex++];
  12498. result.y = array[startingIndex];
  12499. return result;
  12500. };
  12501. /**
  12502. * Flattens an array of Cartesian2s into and array of components.
  12503. *
  12504. * @param {Cartesian2[]} array The array of cartesians to pack.
  12505. * @param {Number[]} result The array onto which to store the result.
  12506. * @returns {Number[]} The packed array.
  12507. */
  12508. Cartesian2.packArray = function(array, result) {
  12509. if (!defined(array)) {
  12510. throw new DeveloperError('array is required');
  12511. }
  12512. var length = array.length;
  12513. if (!defined(result)) {
  12514. result = new Array(length * 2);
  12515. } else {
  12516. result.length = length * 2;
  12517. }
  12518. for (var i = 0; i < length; ++i) {
  12519. Cartesian2.pack(array[i], result, i * 2);
  12520. }
  12521. return result;
  12522. };
  12523. /**
  12524. * Unpacks an array of cartesian components into and array of Cartesian2s.
  12525. *
  12526. * @param {Number[]} array The array of components to unpack.
  12527. * @param {Cartesian2[]} result The array onto which to store the result.
  12528. * @returns {Cartesian2[]} The unpacked array.
  12529. */
  12530. Cartesian2.unpackArray = function(array, result) {
  12531. if (!defined(array)) {
  12532. throw new DeveloperError('array is required');
  12533. }
  12534. var length = array.length;
  12535. if (!defined(result)) {
  12536. result = new Array(length / 2);
  12537. } else {
  12538. result.length = length / 2;
  12539. }
  12540. for (var i = 0; i < length; i += 2) {
  12541. var index = i / 2;
  12542. result[index] = Cartesian2.unpack(array, i, result[index]);
  12543. }
  12544. return result;
  12545. };
  12546. /**
  12547. * Creates a Cartesian2 from two consecutive elements in an array.
  12548. * @function
  12549. *
  12550. * @param {Number[]} array The array whose two consecutive elements correspond to the x and y components, respectively.
  12551. * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.
  12552. * @param {Cartesian2} [result] The object onto which to store the result.
  12553. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
  12554. *
  12555. * @example
  12556. * // Create a Cartesian2 with (1.0, 2.0)
  12557. * var v = [1.0, 2.0];
  12558. * var p = Cesium.Cartesian2.fromArray(v);
  12559. *
  12560. * // Create a Cartesian2 with (1.0, 2.0) using an offset into an array
  12561. * var v2 = [0.0, 0.0, 1.0, 2.0];
  12562. * var p2 = Cesium.Cartesian2.fromArray(v2, 2);
  12563. */
  12564. Cartesian2.fromArray = Cartesian2.unpack;
  12565. /**
  12566. * Computes the value of the maximum component for the supplied Cartesian.
  12567. *
  12568. * @param {Cartesian2} cartesian The cartesian to use.
  12569. * @returns {Number} The value of the maximum component.
  12570. */
  12571. Cartesian2.maximumComponent = function(cartesian) {
  12572. if (!defined(cartesian)) {
  12573. throw new DeveloperError('cartesian is required');
  12574. }
  12575. return Math.max(cartesian.x, cartesian.y);
  12576. };
  12577. /**
  12578. * Computes the value of the minimum component for the supplied Cartesian.
  12579. *
  12580. * @param {Cartesian2} cartesian The cartesian to use.
  12581. * @returns {Number} The value of the minimum component.
  12582. */
  12583. Cartesian2.minimumComponent = function(cartesian) {
  12584. if (!defined(cartesian)) {
  12585. throw new DeveloperError('cartesian is required');
  12586. }
  12587. return Math.min(cartesian.x, cartesian.y);
  12588. };
  12589. /**
  12590. * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
  12591. *
  12592. * @param {Cartesian2} first A cartesian to compare.
  12593. * @param {Cartesian2} second A cartesian to compare.
  12594. * @param {Cartesian2} result The object into which to store the result.
  12595. * @returns {Cartesian2} A cartesian with the minimum components.
  12596. */
  12597. Cartesian2.minimumByComponent = function(first, second, result) {
  12598. if (!defined(first)) {
  12599. throw new DeveloperError('first is required.');
  12600. }
  12601. if (!defined(second)) {
  12602. throw new DeveloperError('second is required.');
  12603. }
  12604. if (!defined(result)) {
  12605. throw new DeveloperError('result is required.');
  12606. }
  12607. result.x = Math.min(first.x, second.x);
  12608. result.y = Math.min(first.y, second.y);
  12609. return result;
  12610. };
  12611. /**
  12612. * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
  12613. *
  12614. * @param {Cartesian2} first A cartesian to compare.
  12615. * @param {Cartesian2} second A cartesian to compare.
  12616. * @param {Cartesian2} result The object into which to store the result.
  12617. * @returns {Cartesian2} A cartesian with the maximum components.
  12618. */
  12619. Cartesian2.maximumByComponent = function(first, second, result) {
  12620. if (!defined(first)) {
  12621. throw new DeveloperError('first is required.');
  12622. }
  12623. if (!defined(second)) {
  12624. throw new DeveloperError('second is required.');
  12625. }
  12626. if (!defined(result)) {
  12627. throw new DeveloperError('result is required.');
  12628. }
  12629. result.x = Math.max(first.x, second.x);
  12630. result.y = Math.max(first.y, second.y);
  12631. return result;
  12632. };
  12633. /**
  12634. * Computes the provided Cartesian's squared magnitude.
  12635. *
  12636. * @param {Cartesian2} cartesian The Cartesian instance whose squared magnitude is to be computed.
  12637. * @returns {Number} The squared magnitude.
  12638. */
  12639. Cartesian2.magnitudeSquared = function(cartesian) {
  12640. if (!defined(cartesian)) {
  12641. throw new DeveloperError('cartesian is required');
  12642. }
  12643. return cartesian.x * cartesian.x + cartesian.y * cartesian.y;
  12644. };
  12645. /**
  12646. * Computes the Cartesian's magnitude (length).
  12647. *
  12648. * @param {Cartesian2} cartesian The Cartesian instance whose magnitude is to be computed.
  12649. * @returns {Number} The magnitude.
  12650. */
  12651. Cartesian2.magnitude = function(cartesian) {
  12652. return Math.sqrt(Cartesian2.magnitudeSquared(cartesian));
  12653. };
  12654. var distanceScratch = new Cartesian2();
  12655. /**
  12656. * Computes the distance between two points.
  12657. *
  12658. * @param {Cartesian2} left The first point to compute the distance from.
  12659. * @param {Cartesian2} right The second point to compute the distance to.
  12660. * @returns {Number} The distance between two points.
  12661. *
  12662. * @example
  12663. * // Returns 1.0
  12664. * var d = Cesium.Cartesian2.distance(new Cesium.Cartesian2(1.0, 0.0), new Cesium.Cartesian2(2.0, 0.0));
  12665. */
  12666. Cartesian2.distance = function(left, right) {
  12667. if (!defined(left) || !defined(right)) {
  12668. throw new DeveloperError('left and right are required.');
  12669. }
  12670. Cartesian2.subtract(left, right, distanceScratch);
  12671. return Cartesian2.magnitude(distanceScratch);
  12672. };
  12673. /**
  12674. * Computes the squared distance between two points. Comparing squared distances
  12675. * using this function is more efficient than comparing distances using {@link Cartesian2#distance}.
  12676. *
  12677. * @param {Cartesian2} left The first point to compute the distance from.
  12678. * @param {Cartesian2} right The second point to compute the distance to.
  12679. * @returns {Number} The distance between two points.
  12680. *
  12681. * @example
  12682. * // Returns 4.0, not 2.0
  12683. * var d = Cesium.Cartesian2.distance(new Cesium.Cartesian2(1.0, 0.0), new Cesium.Cartesian2(3.0, 0.0));
  12684. */
  12685. Cartesian2.distanceSquared = function(left, right) {
  12686. if (!defined(left) || !defined(right)) {
  12687. throw new DeveloperError('left and right are required.');
  12688. }
  12689. Cartesian2.subtract(left, right, distanceScratch);
  12690. return Cartesian2.magnitudeSquared(distanceScratch);
  12691. };
  12692. /**
  12693. * Computes the normalized form of the supplied Cartesian.
  12694. *
  12695. * @param {Cartesian2} cartesian The Cartesian to be normalized.
  12696. * @param {Cartesian2} result The object onto which to store the result.
  12697. * @returns {Cartesian2} The modified result parameter.
  12698. */
  12699. Cartesian2.normalize = function(cartesian, result) {
  12700. if (!defined(cartesian)) {
  12701. throw new DeveloperError('cartesian is required');
  12702. }
  12703. if (!defined(result)) {
  12704. throw new DeveloperError('result is required');
  12705. }
  12706. var magnitude = Cartesian2.magnitude(cartesian);
  12707. result.x = cartesian.x / magnitude;
  12708. result.y = cartesian.y / magnitude;
  12709. if (isNaN(result.x) || isNaN(result.y)) {
  12710. throw new DeveloperError('normalized result is not a number');
  12711. }
  12712. return result;
  12713. };
  12714. /**
  12715. * Computes the dot (scalar) product of two Cartesians.
  12716. *
  12717. * @param {Cartesian2} left The first Cartesian.
  12718. * @param {Cartesian2} right The second Cartesian.
  12719. * @returns {Number} The dot product.
  12720. */
  12721. Cartesian2.dot = function(left, right) {
  12722. if (!defined(left)) {
  12723. throw new DeveloperError('left is required');
  12724. }
  12725. if (!defined(right)) {
  12726. throw new DeveloperError('right is required');
  12727. }
  12728. return left.x * right.x + left.y * right.y;
  12729. };
  12730. /**
  12731. * Computes the componentwise product of two Cartesians.
  12732. *
  12733. * @param {Cartesian2} left The first Cartesian.
  12734. * @param {Cartesian2} right The second Cartesian.
  12735. * @param {Cartesian2} result The object onto which to store the result.
  12736. * @returns {Cartesian2} The modified result parameter.
  12737. */
  12738. Cartesian2.multiplyComponents = function(left, right, result) {
  12739. if (!defined(left)) {
  12740. throw new DeveloperError('left is required');
  12741. }
  12742. if (!defined(right)) {
  12743. throw new DeveloperError('right is required');
  12744. }
  12745. if (!defined(result)) {
  12746. throw new DeveloperError('result is required');
  12747. }
  12748. result.x = left.x * right.x;
  12749. result.y = left.y * right.y;
  12750. return result;
  12751. };
  12752. /**
  12753. * Computes the componentwise quotient of two Cartesians.
  12754. *
  12755. * @param {Cartesian2} left The first Cartesian.
  12756. * @param {Cartesian2} right The second Cartesian.
  12757. * @param {Cartesian2} result The object onto which to store the result.
  12758. * @returns {Cartesian2} The modified result parameter.
  12759. */
  12760. Cartesian2.divideComponents = function(left, right, result) {
  12761. if (!defined(left)) {
  12762. throw new DeveloperError('left is required');
  12763. }
  12764. if (!defined(right)) {
  12765. throw new DeveloperError('right is required');
  12766. }
  12767. if (!defined(result)) {
  12768. throw new DeveloperError('result is required');
  12769. }
  12770. result.x = left.x / right.x;
  12771. result.y = left.y / right.y;
  12772. return result;
  12773. };
  12774. /**
  12775. * Computes the componentwise sum of two Cartesians.
  12776. *
  12777. * @param {Cartesian2} left The first Cartesian.
  12778. * @param {Cartesian2} right The second Cartesian.
  12779. * @param {Cartesian2} result The object onto which to store the result.
  12780. * @returns {Cartesian2} The modified result parameter.
  12781. */
  12782. Cartesian2.add = function(left, right, result) {
  12783. if (!defined(left)) {
  12784. throw new DeveloperError('left is required');
  12785. }
  12786. if (!defined(right)) {
  12787. throw new DeveloperError('right is required');
  12788. }
  12789. if (!defined(result)) {
  12790. throw new DeveloperError('result is required');
  12791. }
  12792. result.x = left.x + right.x;
  12793. result.y = left.y + right.y;
  12794. return result;
  12795. };
  12796. /**
  12797. * Computes the componentwise difference of two Cartesians.
  12798. *
  12799. * @param {Cartesian2} left The first Cartesian.
  12800. * @param {Cartesian2} right The second Cartesian.
  12801. * @param {Cartesian2} result The object onto which to store the result.
  12802. * @returns {Cartesian2} The modified result parameter.
  12803. */
  12804. Cartesian2.subtract = function(left, right, result) {
  12805. if (!defined(left)) {
  12806. throw new DeveloperError('left is required');
  12807. }
  12808. if (!defined(right)) {
  12809. throw new DeveloperError('right is required');
  12810. }
  12811. if (!defined(result)) {
  12812. throw new DeveloperError('result is required');
  12813. }
  12814. result.x = left.x - right.x;
  12815. result.y = left.y - right.y;
  12816. return result;
  12817. };
  12818. /**
  12819. * Multiplies the provided Cartesian componentwise by the provided scalar.
  12820. *
  12821. * @param {Cartesian2} cartesian The Cartesian to be scaled.
  12822. * @param {Number} scalar The scalar to multiply with.
  12823. * @param {Cartesian2} result The object onto which to store the result.
  12824. * @returns {Cartesian2} The modified result parameter.
  12825. */
  12826. Cartesian2.multiplyByScalar = function(cartesian, scalar, result) {
  12827. if (!defined(cartesian)) {
  12828. throw new DeveloperError('cartesian is required');
  12829. }
  12830. if (typeof scalar !== 'number') {
  12831. throw new DeveloperError('scalar is required and must be a number.');
  12832. }
  12833. if (!defined(result)) {
  12834. throw new DeveloperError('result is required');
  12835. }
  12836. result.x = cartesian.x * scalar;
  12837. result.y = cartesian.y * scalar;
  12838. return result;
  12839. };
  12840. /**
  12841. * Divides the provided Cartesian componentwise by the provided scalar.
  12842. *
  12843. * @param {Cartesian2} cartesian The Cartesian to be divided.
  12844. * @param {Number} scalar The scalar to divide by.
  12845. * @param {Cartesian2} result The object onto which to store the result.
  12846. * @returns {Cartesian2} The modified result parameter.
  12847. */
  12848. Cartesian2.divideByScalar = function(cartesian, scalar, result) {
  12849. if (!defined(cartesian)) {
  12850. throw new DeveloperError('cartesian is required');
  12851. }
  12852. if (typeof scalar !== 'number') {
  12853. throw new DeveloperError('scalar is required and must be a number.');
  12854. }
  12855. if (!defined(result)) {
  12856. throw new DeveloperError('result is required');
  12857. }
  12858. result.x = cartesian.x / scalar;
  12859. result.y = cartesian.y / scalar;
  12860. return result;
  12861. };
  12862. /**
  12863. * Negates the provided Cartesian.
  12864. *
  12865. * @param {Cartesian2} cartesian The Cartesian to be negated.
  12866. * @param {Cartesian2} result The object onto which to store the result.
  12867. * @returns {Cartesian2} The modified result parameter.
  12868. */
  12869. Cartesian2.negate = function(cartesian, result) {
  12870. if (!defined(cartesian)) {
  12871. throw new DeveloperError('cartesian is required');
  12872. }
  12873. if (!defined(result)) {
  12874. throw new DeveloperError('result is required');
  12875. }
  12876. result.x = -cartesian.x;
  12877. result.y = -cartesian.y;
  12878. return result;
  12879. };
  12880. /**
  12881. * Computes the absolute value of the provided Cartesian.
  12882. *
  12883. * @param {Cartesian2} cartesian The Cartesian whose absolute value is to be computed.
  12884. * @param {Cartesian2} result The object onto which to store the result.
  12885. * @returns {Cartesian2} The modified result parameter.
  12886. */
  12887. Cartesian2.abs = function(cartesian, result) {
  12888. if (!defined(cartesian)) {
  12889. throw new DeveloperError('cartesian is required');
  12890. }
  12891. if (!defined(result)) {
  12892. throw new DeveloperError('result is required');
  12893. }
  12894. result.x = Math.abs(cartesian.x);
  12895. result.y = Math.abs(cartesian.y);
  12896. return result;
  12897. };
  12898. var lerpScratch = new Cartesian2();
  12899. /**
  12900. * Computes the linear interpolation or extrapolation at t using the provided cartesians.
  12901. *
  12902. * @param {Cartesian2} start The value corresponding to t at 0.0.
  12903. * @param {Cartesian2} end The value corresponding to t at 1.0.
  12904. * @param {Number} t The point along t at which to interpolate.
  12905. * @param {Cartesian2} result The object onto which to store the result.
  12906. * @returns {Cartesian2} The modified result parameter.
  12907. */
  12908. Cartesian2.lerp = function(start, end, t, result) {
  12909. if (!defined(start)) {
  12910. throw new DeveloperError('start is required.');
  12911. }
  12912. if (!defined(end)) {
  12913. throw new DeveloperError('end is required.');
  12914. }
  12915. if (typeof t !== 'number') {
  12916. throw new DeveloperError('t is required and must be a number.');
  12917. }
  12918. if (!defined(result)) {
  12919. throw new DeveloperError('result is required.');
  12920. }
  12921. Cartesian2.multiplyByScalar(end, t, lerpScratch);
  12922. result = Cartesian2.multiplyByScalar(start, 1.0 - t, result);
  12923. return Cartesian2.add(lerpScratch, result, result);
  12924. };
  12925. var angleBetweenScratch = new Cartesian2();
  12926. var angleBetweenScratch2 = new Cartesian2();
  12927. /**
  12928. * Returns the angle, in radians, between the provided Cartesians.
  12929. *
  12930. * @param {Cartesian2} left The first Cartesian.
  12931. * @param {Cartesian2} right The second Cartesian.
  12932. * @returns {Number} The angle between the Cartesians.
  12933. */
  12934. Cartesian2.angleBetween = function(left, right) {
  12935. if (!defined(left)) {
  12936. throw new DeveloperError('left is required');
  12937. }
  12938. if (!defined(right)) {
  12939. throw new DeveloperError('right is required');
  12940. }
  12941. Cartesian2.normalize(left, angleBetweenScratch);
  12942. Cartesian2.normalize(right, angleBetweenScratch2);
  12943. return CesiumMath.acosClamped(Cartesian2.dot(angleBetweenScratch, angleBetweenScratch2));
  12944. };
  12945. var mostOrthogonalAxisScratch = new Cartesian2();
  12946. /**
  12947. * Returns the axis that is most orthogonal to the provided Cartesian.
  12948. *
  12949. * @param {Cartesian2} cartesian The Cartesian on which to find the most orthogonal axis.
  12950. * @param {Cartesian2} result The object onto which to store the result.
  12951. * @returns {Cartesian2} The most orthogonal axis.
  12952. */
  12953. Cartesian2.mostOrthogonalAxis = function(cartesian, result) {
  12954. if (!defined(cartesian)) {
  12955. throw new DeveloperError('cartesian is required.');
  12956. }
  12957. if (!defined(result)) {
  12958. throw new DeveloperError('result is required.');
  12959. }
  12960. var f = Cartesian2.normalize(cartesian, mostOrthogonalAxisScratch);
  12961. Cartesian2.abs(f, f);
  12962. if (f.x <= f.y) {
  12963. result = Cartesian2.clone(Cartesian2.UNIT_X, result);
  12964. } else {
  12965. result = Cartesian2.clone(Cartesian2.UNIT_Y, result);
  12966. }
  12967. return result;
  12968. };
  12969. /**
  12970. * Compares the provided Cartesians componentwise and returns
  12971. * <code>true</code> if they are equal, <code>false</code> otherwise.
  12972. *
  12973. * @param {Cartesian2} [left] The first Cartesian.
  12974. * @param {Cartesian2} [right] The second Cartesian.
  12975. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  12976. */
  12977. Cartesian2.equals = function(left, right) {
  12978. return (left === right) ||
  12979. ((defined(left)) &&
  12980. (defined(right)) &&
  12981. (left.x === right.x) &&
  12982. (left.y === right.y));
  12983. };
  12984. /**
  12985. * @private
  12986. */
  12987. Cartesian2.equalsArray = function(cartesian, array, offset) {
  12988. return cartesian.x === array[offset] &&
  12989. cartesian.y === array[offset + 1];
  12990. };
  12991. /**
  12992. * Compares the provided Cartesians componentwise and returns
  12993. * <code>true</code> if they pass an absolute or relative tolerance test,
  12994. * <code>false</code> otherwise.
  12995. *
  12996. * @param {Cartesian2} [left] The first Cartesian.
  12997. * @param {Cartesian2} [right] The second Cartesian.
  12998. * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
  12999. * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  13000. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  13001. */
  13002. Cartesian2.equalsEpsilon = function(left, right, relativeEpsilon, absoluteEpsilon) {
  13003. return (left === right) ||
  13004. (defined(left) &&
  13005. defined(right) &&
  13006. CesiumMath.equalsEpsilon(left.x, right.x, relativeEpsilon, absoluteEpsilon) &&
  13007. CesiumMath.equalsEpsilon(left.y, right.y, relativeEpsilon, absoluteEpsilon));
  13008. };
  13009. /**
  13010. * An immutable Cartesian2 instance initialized to (0.0, 0.0).
  13011. *
  13012. * @type {Cartesian2}
  13013. * @constant
  13014. */
  13015. Cartesian2.ZERO = freezeObject(new Cartesian2(0.0, 0.0));
  13016. /**
  13017. * An immutable Cartesian2 instance initialized to (1.0, 0.0).
  13018. *
  13019. * @type {Cartesian2}
  13020. * @constant
  13021. */
  13022. Cartesian2.UNIT_X = freezeObject(new Cartesian2(1.0, 0.0));
  13023. /**
  13024. * An immutable Cartesian2 instance initialized to (0.0, 1.0).
  13025. *
  13026. * @type {Cartesian2}
  13027. * @constant
  13028. */
  13029. Cartesian2.UNIT_Y = freezeObject(new Cartesian2(0.0, 1.0));
  13030. /**
  13031. * Duplicates this Cartesian2 instance.
  13032. *
  13033. * @param {Cartesian2} [result] The object onto which to store the result.
  13034. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
  13035. */
  13036. Cartesian2.prototype.clone = function(result) {
  13037. return Cartesian2.clone(this, result);
  13038. };
  13039. /**
  13040. * Compares this Cartesian against the provided Cartesian componentwise and returns
  13041. * <code>true</code> if they are equal, <code>false</code> otherwise.
  13042. *
  13043. * @param {Cartesian2} [right] The right hand side Cartesian.
  13044. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  13045. */
  13046. Cartesian2.prototype.equals = function(right) {
  13047. return Cartesian2.equals(this, right);
  13048. };
  13049. /**
  13050. * Compares this Cartesian against the provided Cartesian componentwise and returns
  13051. * <code>true</code> if they pass an absolute or relative tolerance test,
  13052. * <code>false</code> otherwise.
  13053. *
  13054. * @param {Cartesian2} [right] The right hand side Cartesian.
  13055. * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
  13056. * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  13057. * @returns {Boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
  13058. */
  13059. Cartesian2.prototype.equalsEpsilon = function(right, relativeEpsilon, absoluteEpsilon) {
  13060. return Cartesian2.equalsEpsilon(this, right, relativeEpsilon, absoluteEpsilon);
  13061. };
  13062. /**
  13063. * Creates a string representing this Cartesian in the format '(x, y)'.
  13064. *
  13065. * @returns {String} A string representing the provided Cartesian in the format '(x, y)'.
  13066. */
  13067. Cartesian2.prototype.toString = function() {
  13068. return '(' + this.x + ', ' + this.y + ')';
  13069. };
  13070. return Cartesian2;
  13071. });
  13072. /*global define*/
  13073. define('Core/QuadraticRealPolynomial',[
  13074. './DeveloperError',
  13075. './Math'
  13076. ], function(
  13077. DeveloperError,
  13078. CesiumMath) {
  13079. 'use strict';
  13080. /**
  13081. * Defines functions for 2nd order polynomial functions of one variable with only real coefficients.
  13082. *
  13083. * @exports QuadraticRealPolynomial
  13084. */
  13085. var QuadraticRealPolynomial = {};
  13086. /**
  13087. * Provides the discriminant of the quadratic equation from the supplied coefficients.
  13088. *
  13089. * @param {Number} a The coefficient of the 2nd order monomial.
  13090. * @param {Number} b The coefficient of the 1st order monomial.
  13091. * @param {Number} c The coefficient of the 0th order monomial.
  13092. * @returns {Number} The value of the discriminant.
  13093. */
  13094. QuadraticRealPolynomial.computeDiscriminant = function(a, b, c) {
  13095. if (typeof a !== 'number') {
  13096. throw new DeveloperError('a is a required number.');
  13097. }
  13098. if (typeof b !== 'number') {
  13099. throw new DeveloperError('b is a required number.');
  13100. }
  13101. if (typeof c !== 'number') {
  13102. throw new DeveloperError('c is a required number.');
  13103. }
  13104. var discriminant = b * b - 4.0 * a * c;
  13105. return discriminant;
  13106. };
  13107. function addWithCancellationCheck(left, right, tolerance) {
  13108. var difference = left + right;
  13109. if ((CesiumMath.sign(left) !== CesiumMath.sign(right)) &&
  13110. Math.abs(difference / Math.max(Math.abs(left), Math.abs(right))) < tolerance) {
  13111. return 0.0;
  13112. }
  13113. return difference;
  13114. }
  13115. /**
  13116. * Provides the real valued roots of the quadratic polynomial with the provided coefficients.
  13117. *
  13118. * @param {Number} a The coefficient of the 2nd order monomial.
  13119. * @param {Number} b The coefficient of the 1st order monomial.
  13120. * @param {Number} c The coefficient of the 0th order monomial.
  13121. * @returns {Number[]} The real valued roots.
  13122. */
  13123. QuadraticRealPolynomial.computeRealRoots = function(a, b, c) {
  13124. if (typeof a !== 'number') {
  13125. throw new DeveloperError('a is a required number.');
  13126. }
  13127. if (typeof b !== 'number') {
  13128. throw new DeveloperError('b is a required number.');
  13129. }
  13130. if (typeof c !== 'number') {
  13131. throw new DeveloperError('c is a required number.');
  13132. }
  13133. var ratio;
  13134. if (a === 0.0) {
  13135. if (b === 0.0) {
  13136. // Constant function: c = 0.
  13137. return [];
  13138. }
  13139. // Linear function: b * x + c = 0.
  13140. return [-c / b];
  13141. } else if (b === 0.0) {
  13142. if (c === 0.0) {
  13143. // 2nd order monomial: a * x^2 = 0.
  13144. return [0.0, 0.0];
  13145. }
  13146. var cMagnitude = Math.abs(c);
  13147. var aMagnitude = Math.abs(a);
  13148. if ((cMagnitude < aMagnitude) && (cMagnitude / aMagnitude < CesiumMath.EPSILON14)) { // c ~= 0.0.
  13149. // 2nd order monomial: a * x^2 = 0.
  13150. return [0.0, 0.0];
  13151. } else if ((cMagnitude > aMagnitude) && (aMagnitude / cMagnitude < CesiumMath.EPSILON14)) { // a ~= 0.0.
  13152. // Constant function: c = 0.
  13153. return [];
  13154. }
  13155. // a * x^2 + c = 0
  13156. ratio = -c / a;
  13157. if (ratio < 0.0) {
  13158. // Both roots are complex.
  13159. return [];
  13160. }
  13161. // Both roots are real.
  13162. var root = Math.sqrt(ratio);
  13163. return [-root, root];
  13164. } else if (c === 0.0) {
  13165. // a * x^2 + b * x = 0
  13166. ratio = -b / a;
  13167. if (ratio < 0.0) {
  13168. return [ratio, 0.0];
  13169. }
  13170. return [0.0, ratio];
  13171. }
  13172. // a * x^2 + b * x + c = 0
  13173. var b2 = b * b;
  13174. var four_ac = 4.0 * a * c;
  13175. var radicand = addWithCancellationCheck(b2, -four_ac, CesiumMath.EPSILON14);
  13176. if (radicand < 0.0) {
  13177. // Both roots are complex.
  13178. return [];
  13179. }
  13180. var q = -0.5 * addWithCancellationCheck(b, CesiumMath.sign(b) * Math.sqrt(radicand), CesiumMath.EPSILON14);
  13181. if (b > 0.0) {
  13182. return [q / a, c / q];
  13183. }
  13184. return [c / q, q / a];
  13185. };
  13186. return QuadraticRealPolynomial;
  13187. });
  13188. /*global define*/
  13189. define('Core/CubicRealPolynomial',[
  13190. './DeveloperError',
  13191. './QuadraticRealPolynomial'
  13192. ], function(
  13193. DeveloperError,
  13194. QuadraticRealPolynomial) {
  13195. 'use strict';
  13196. /**
  13197. * Defines functions for 3rd order polynomial functions of one variable with only real coefficients.
  13198. *
  13199. * @exports CubicRealPolynomial
  13200. */
  13201. var CubicRealPolynomial = {};
  13202. /**
  13203. * Provides the discriminant of the cubic equation from the supplied coefficients.
  13204. *
  13205. * @param {Number} a The coefficient of the 3rd order monomial.
  13206. * @param {Number} b The coefficient of the 2nd order monomial.
  13207. * @param {Number} c The coefficient of the 1st order monomial.
  13208. * @param {Number} d The coefficient of the 0th order monomial.
  13209. * @returns {Number} The value of the discriminant.
  13210. */
  13211. CubicRealPolynomial.computeDiscriminant = function(a, b, c, d) {
  13212. if (typeof a !== 'number') {
  13213. throw new DeveloperError('a is a required number.');
  13214. }
  13215. if (typeof b !== 'number') {
  13216. throw new DeveloperError('b is a required number.');
  13217. }
  13218. if (typeof c !== 'number') {
  13219. throw new DeveloperError('c is a required number.');
  13220. }
  13221. if (typeof d !== 'number') {
  13222. throw new DeveloperError('d is a required number.');
  13223. }
  13224. var a2 = a * a;
  13225. var b2 = b * b;
  13226. var c2 = c * c;
  13227. var d2 = d * d;
  13228. var discriminant = 18.0 * a * b * c * d + b2 * c2 - 27.0 * a2 * d2 - 4.0 * (a * c2 * c + b2 * b * d);
  13229. return discriminant;
  13230. };
  13231. function computeRealRoots(a, b, c, d) {
  13232. var A = a;
  13233. var B = b / 3.0;
  13234. var C = c / 3.0;
  13235. var D = d;
  13236. var AC = A * C;
  13237. var BD = B * D;
  13238. var B2 = B * B;
  13239. var C2 = C * C;
  13240. var delta1 = A * C - B2;
  13241. var delta2 = A * D - B * C;
  13242. var delta3 = B * D - C2;
  13243. var discriminant = 4.0 * delta1 * delta3 - delta2 * delta2;
  13244. var temp;
  13245. var temp1;
  13246. if (discriminant < 0.0) {
  13247. var ABar;
  13248. var CBar;
  13249. var DBar;
  13250. if (B2 * BD >= AC * C2) {
  13251. ABar = A;
  13252. CBar = delta1;
  13253. DBar = -2.0 * B * delta1 + A * delta2;
  13254. } else {
  13255. ABar = D;
  13256. CBar = delta3;
  13257. DBar = -D * delta2 + 2.0 * C * delta3;
  13258. }
  13259. var s = (DBar < 0.0) ? -1.0 : 1.0; // This is not Math.Sign()!
  13260. var temp0 = -s * Math.abs(ABar) * Math.sqrt(-discriminant);
  13261. temp1 = -DBar + temp0;
  13262. var x = temp1 / 2.0;
  13263. var p = x < 0.0 ? -Math.pow(-x, 1.0 / 3.0) : Math.pow(x, 1.0 / 3.0);
  13264. var q = (temp1 === temp0) ? -p : -CBar / p;
  13265. temp = (CBar <= 0.0) ? p + q : -DBar / (p * p + q * q + CBar);
  13266. if (B2 * BD >= AC * C2) {
  13267. return [(temp - B) / A];
  13268. }
  13269. return [-D / (temp + C)];
  13270. }
  13271. var CBarA = delta1;
  13272. var DBarA = -2.0 * B * delta1 + A * delta2;
  13273. var CBarD = delta3;
  13274. var DBarD = -D * delta2 + 2.0 * C * delta3;
  13275. var squareRootOfDiscriminant = Math.sqrt(discriminant);
  13276. var halfSquareRootOf3 = Math.sqrt(3.0) / 2.0;
  13277. var theta = Math.abs(Math.atan2(A * squareRootOfDiscriminant, -DBarA) / 3.0);
  13278. temp = 2.0 * Math.sqrt(-CBarA);
  13279. var cosine = Math.cos(theta);
  13280. temp1 = temp * cosine;
  13281. var temp3 = temp * (-cosine / 2.0 - halfSquareRootOf3 * Math.sin(theta));
  13282. var numeratorLarge = (temp1 + temp3 > 2.0 * B) ? temp1 - B : temp3 - B;
  13283. var denominatorLarge = A;
  13284. var root1 = numeratorLarge / denominatorLarge;
  13285. theta = Math.abs(Math.atan2(D * squareRootOfDiscriminant, -DBarD) / 3.0);
  13286. temp = 2.0 * Math.sqrt(-CBarD);
  13287. cosine = Math.cos(theta);
  13288. temp1 = temp * cosine;
  13289. temp3 = temp * (-cosine / 2.0 - halfSquareRootOf3 * Math.sin(theta));
  13290. var numeratorSmall = -D;
  13291. var denominatorSmall = (temp1 + temp3 < 2.0 * C) ? temp1 + C : temp3 + C;
  13292. var root3 = numeratorSmall / denominatorSmall;
  13293. var E = denominatorLarge * denominatorSmall;
  13294. var F = -numeratorLarge * denominatorSmall - denominatorLarge * numeratorSmall;
  13295. var G = numeratorLarge * numeratorSmall;
  13296. var root2 = (C * F - B * G) / (-B * F + C * E);
  13297. if (root1 <= root2) {
  13298. if (root1 <= root3) {
  13299. if (root2 <= root3) {
  13300. return [root1, root2, root3];
  13301. }
  13302. return [root1, root3, root2];
  13303. }
  13304. return [root3, root1, root2];
  13305. }
  13306. if (root1 <= root3) {
  13307. return [root2, root1, root3];
  13308. }
  13309. if (root2 <= root3) {
  13310. return [root2, root3, root1];
  13311. }
  13312. return [root3, root2, root1];
  13313. }
  13314. /**
  13315. * Provides the real valued roots of the cubic polynomial with the provided coefficients.
  13316. *
  13317. * @param {Number} a The coefficient of the 3rd order monomial.
  13318. * @param {Number} b The coefficient of the 2nd order monomial.
  13319. * @param {Number} c The coefficient of the 1st order monomial.
  13320. * @param {Number} d The coefficient of the 0th order monomial.
  13321. * @returns {Number[]} The real valued roots.
  13322. */
  13323. CubicRealPolynomial.computeRealRoots = function(a, b, c, d) {
  13324. if (typeof a !== 'number') {
  13325. throw new DeveloperError('a is a required number.');
  13326. }
  13327. if (typeof b !== 'number') {
  13328. throw new DeveloperError('b is a required number.');
  13329. }
  13330. if (typeof c !== 'number') {
  13331. throw new DeveloperError('c is a required number.');
  13332. }
  13333. if (typeof d !== 'number') {
  13334. throw new DeveloperError('d is a required number.');
  13335. }
  13336. var roots;
  13337. var ratio;
  13338. if (a === 0.0) {
  13339. // Quadratic function: b * x^2 + c * x + d = 0.
  13340. return QuadraticRealPolynomial.computeRealRoots(b, c, d);
  13341. } else if (b === 0.0) {
  13342. if (c === 0.0) {
  13343. if (d === 0.0) {
  13344. // 3rd order monomial: a * x^3 = 0.
  13345. return [0.0, 0.0, 0.0];
  13346. }
  13347. // a * x^3 + d = 0
  13348. ratio = -d / a;
  13349. var root = (ratio < 0.0) ? -Math.pow(-ratio, 1.0 / 3.0) : Math.pow(ratio, 1.0 / 3.0);
  13350. return [root, root, root];
  13351. } else if (d === 0.0) {
  13352. // x * (a * x^2 + c) = 0.
  13353. roots = QuadraticRealPolynomial.computeRealRoots(a, 0, c);
  13354. // Return the roots in ascending order.
  13355. if (roots.Length === 0) {
  13356. return [0.0];
  13357. }
  13358. return [roots[0], 0.0, roots[1]];
  13359. }
  13360. // Deflated cubic polynomial: a * x^3 + c * x + d= 0.
  13361. return computeRealRoots(a, 0, c, d);
  13362. } else if (c === 0.0) {
  13363. if (d === 0.0) {
  13364. // x^2 * (a * x + b) = 0.
  13365. ratio = -b / a;
  13366. if (ratio < 0.0) {
  13367. return [ratio, 0.0, 0.0];
  13368. }
  13369. return [0.0, 0.0, ratio];
  13370. }
  13371. // a * x^3 + b * x^2 + d = 0.
  13372. return computeRealRoots(a, b, 0, d);
  13373. } else if (d === 0.0) {
  13374. // x * (a * x^2 + b * x + c) = 0
  13375. roots = QuadraticRealPolynomial.computeRealRoots(a, b, c);
  13376. // Return the roots in ascending order.
  13377. if (roots.length === 0) {
  13378. return [0.0];
  13379. } else if (roots[1] <= 0.0) {
  13380. return [roots[0], roots[1], 0.0];
  13381. } else if (roots[0] >= 0.0) {
  13382. return [0.0, roots[0], roots[1]];
  13383. }
  13384. return [roots[0], 0.0, roots[1]];
  13385. }
  13386. return computeRealRoots(a, b, c, d);
  13387. };
  13388. return CubicRealPolynomial;
  13389. });
  13390. /*global define*/
  13391. define('Core/QuarticRealPolynomial',[
  13392. './CubicRealPolynomial',
  13393. './DeveloperError',
  13394. './Math',
  13395. './QuadraticRealPolynomial'
  13396. ], function(
  13397. CubicRealPolynomial,
  13398. DeveloperError,
  13399. CesiumMath,
  13400. QuadraticRealPolynomial) {
  13401. 'use strict';
  13402. /**
  13403. * Defines functions for 4th order polynomial functions of one variable with only real coefficients.
  13404. *
  13405. * @exports QuarticRealPolynomial
  13406. */
  13407. var QuarticRealPolynomial = {};
  13408. /**
  13409. * Provides the discriminant of the quartic equation from the supplied coefficients.
  13410. *
  13411. * @param {Number} a The coefficient of the 4th order monomial.
  13412. * @param {Number} b The coefficient of the 3rd order monomial.
  13413. * @param {Number} c The coefficient of the 2nd order monomial.
  13414. * @param {Number} d The coefficient of the 1st order monomial.
  13415. * @param {Number} e The coefficient of the 0th order monomial.
  13416. * @returns {Number} The value of the discriminant.
  13417. */
  13418. QuarticRealPolynomial.computeDiscriminant = function(a, b, c, d, e) {
  13419. if (typeof a !== 'number') {
  13420. throw new DeveloperError('a is a required number.');
  13421. }
  13422. if (typeof b !== 'number') {
  13423. throw new DeveloperError('b is a required number.');
  13424. }
  13425. if (typeof c !== 'number') {
  13426. throw new DeveloperError('c is a required number.');
  13427. }
  13428. if (typeof d !== 'number') {
  13429. throw new DeveloperError('d is a required number.');
  13430. }
  13431. if (typeof e !== 'number') {
  13432. throw new DeveloperError('e is a required number.');
  13433. }
  13434. var a2 = a * a;
  13435. var a3 = a2 * a;
  13436. var b2 = b * b;
  13437. var b3 = b2 * b;
  13438. var c2 = c * c;
  13439. var c3 = c2 * c;
  13440. var d2 = d * d;
  13441. var d3 = d2 * d;
  13442. var e2 = e * e;
  13443. var e3 = e2 * e;
  13444. 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) +
  13445. 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) +
  13446. e2 * (144.0 * a * b2 * c - 27.0 * b2 * b2 - 128.0 * a2 * c2 - 192.0 * a2 * b * d);
  13447. return discriminant;
  13448. };
  13449. function original(a3, a2, a1, a0) {
  13450. var a3Squared = a3 * a3;
  13451. var p = a2 - 3.0 * a3Squared / 8.0;
  13452. var q = a1 - a2 * a3 / 2.0 + a3Squared * a3 / 8.0;
  13453. var r = a0 - a1 * a3 / 4.0 + a2 * a3Squared / 16.0 - 3.0 * a3Squared * a3Squared / 256.0;
  13454. // Find the roots of the cubic equations: h^6 + 2 p h^4 + (p^2 - 4 r) h^2 - q^2 = 0.
  13455. var cubicRoots = CubicRealPolynomial.computeRealRoots(1.0, 2.0 * p, p * p - 4.0 * r, -q * q);
  13456. if (cubicRoots.length > 0) {
  13457. var temp = -a3 / 4.0;
  13458. // Use the largest positive root.
  13459. var hSquared = cubicRoots[cubicRoots.length - 1];
  13460. if (Math.abs(hSquared) < CesiumMath.EPSILON14) {
  13461. // y^4 + p y^2 + r = 0.
  13462. var roots = QuadraticRealPolynomial.computeRealRoots(1.0, p, r);
  13463. if (roots.length === 2) {
  13464. var root0 = roots[0];
  13465. var root1 = roots[1];
  13466. var y;
  13467. if (root0 >= 0.0 && root1 >= 0.0) {
  13468. var y0 = Math.sqrt(root0);
  13469. var y1 = Math.sqrt(root1);
  13470. return [temp - y1, temp - y0, temp + y0, temp + y1];
  13471. } else if (root0 >= 0.0 && root1 < 0.0) {
  13472. y = Math.sqrt(root0);
  13473. return [temp - y, temp + y];
  13474. } else if (root0 < 0.0 && root1 >= 0.0) {
  13475. y = Math.sqrt(root1);
  13476. return [temp - y, temp + y];
  13477. }
  13478. }
  13479. return [];
  13480. } else if (hSquared > 0.0) {
  13481. var h = Math.sqrt(hSquared);
  13482. var m = (p + hSquared - q / h) / 2.0;
  13483. var n = (p + hSquared + q / h) / 2.0;
  13484. // Now solve the two quadratic factors: (y^2 + h y + m)(y^2 - h y + n);
  13485. var roots1 = QuadraticRealPolynomial.computeRealRoots(1.0, h, m);
  13486. var roots2 = QuadraticRealPolynomial.computeRealRoots(1.0, -h, n);
  13487. if (roots1.length !== 0) {
  13488. roots1[0] += temp;
  13489. roots1[1] += temp;
  13490. if (roots2.length !== 0) {
  13491. roots2[0] += temp;
  13492. roots2[1] += temp;
  13493. if (roots1[1] <= roots2[0]) {
  13494. return [roots1[0], roots1[1], roots2[0], roots2[1]];
  13495. } else if (roots2[1] <= roots1[0]) {
  13496. return [roots2[0], roots2[1], roots1[0], roots1[1]];
  13497. } else if (roots1[0] >= roots2[0] && roots1[1] <= roots2[1]) {
  13498. return [roots2[0], roots1[0], roots1[1], roots2[1]];
  13499. } else if (roots2[0] >= roots1[0] && roots2[1] <= roots1[1]) {
  13500. return [roots1[0], roots2[0], roots2[1], roots1[1]];
  13501. } else if (roots1[0] > roots2[0] && roots1[0] < roots2[1]) {
  13502. return [roots2[0], roots1[0], roots2[1], roots1[1]];
  13503. }
  13504. return [roots1[0], roots2[0], roots1[1], roots2[1]];
  13505. }
  13506. return roots1;
  13507. }
  13508. if (roots2.length !== 0) {
  13509. roots2[0] += temp;
  13510. roots2[1] += temp;
  13511. return roots2;
  13512. }
  13513. return [];
  13514. }
  13515. }
  13516. return [];
  13517. }
  13518. function neumark(a3, a2, a1, a0) {
  13519. var a1Squared = a1 * a1;
  13520. var a2Squared = a2 * a2;
  13521. var a3Squared = a3 * a3;
  13522. var p = -2.0 * a2;
  13523. var q = a1 * a3 + a2Squared - 4.0 * a0;
  13524. var r = a3Squared * a0 - a1 * a2 * a3 + a1Squared;
  13525. var cubicRoots = CubicRealPolynomial.computeRealRoots(1.0, p, q, r);
  13526. if (cubicRoots.length > 0) {
  13527. // Use the most positive root
  13528. var y = cubicRoots[0];
  13529. var temp = (a2 - y);
  13530. var tempSquared = temp * temp;
  13531. var g1 = a3 / 2.0;
  13532. var h1 = temp / 2.0;
  13533. var m = tempSquared - 4.0 * a0;
  13534. var mError = tempSquared + 4.0 * Math.abs(a0);
  13535. var n = a3Squared - 4.0 * y;
  13536. var nError = a3Squared + 4.0 * Math.abs(y);
  13537. var g2;
  13538. var h2;
  13539. if (y < 0.0 || (m * nError < n * mError)) {
  13540. var squareRootOfN = Math.sqrt(n);
  13541. g2 = squareRootOfN / 2.0;
  13542. h2 = squareRootOfN === 0.0 ? 0.0 : (a3 * h1 - a1) / squareRootOfN;
  13543. } else {
  13544. var squareRootOfM = Math.sqrt(m);
  13545. g2 = squareRootOfM === 0.0 ? 0.0 : (a3 * h1 - a1) / squareRootOfM;
  13546. h2 = squareRootOfM / 2.0;
  13547. }
  13548. var G;
  13549. var g;
  13550. if (g1 === 0.0 && g2 === 0.0) {
  13551. G = 0.0;
  13552. g = 0.0;
  13553. } else if (CesiumMath.sign(g1) === CesiumMath.sign(g2)) {
  13554. G = g1 + g2;
  13555. g = y / G;
  13556. } else {
  13557. g = g1 - g2;
  13558. G = y / g;
  13559. }
  13560. var H;
  13561. var h;
  13562. if (h1 === 0.0 && h2 === 0.0) {
  13563. H = 0.0;
  13564. h = 0.0;
  13565. } else if (CesiumMath.sign(h1) === CesiumMath.sign(h2)) {
  13566. H = h1 + h2;
  13567. h = a0 / H;
  13568. } else {
  13569. h = h1 - h2;
  13570. H = a0 / h;
  13571. }
  13572. // Now solve the two quadratic factors: (y^2 + G y + H)(y^2 + g y + h);
  13573. var roots1 = QuadraticRealPolynomial.computeRealRoots(1.0, G, H);
  13574. var roots2 = QuadraticRealPolynomial.computeRealRoots(1.0, g, h);
  13575. if (roots1.length !== 0) {
  13576. if (roots2.length !== 0) {
  13577. if (roots1[1] <= roots2[0]) {
  13578. return [roots1[0], roots1[1], roots2[0], roots2[1]];
  13579. } else if (roots2[1] <= roots1[0]) {
  13580. return [roots2[0], roots2[1], roots1[0], roots1[1]];
  13581. } else if (roots1[0] >= roots2[0] && roots1[1] <= roots2[1]) {
  13582. return [roots2[0], roots1[0], roots1[1], roots2[1]];
  13583. } else if (roots2[0] >= roots1[0] && roots2[1] <= roots1[1]) {
  13584. return [roots1[0], roots2[0], roots2[1], roots1[1]];
  13585. } else if (roots1[0] > roots2[0] && roots1[0] < roots2[1]) {
  13586. return [roots2[0], roots1[0], roots2[1], roots1[1]];
  13587. } else {
  13588. return [roots1[0], roots2[0], roots1[1], roots2[1]];
  13589. }
  13590. }
  13591. return roots1;
  13592. }
  13593. if (roots2.length !== 0) {
  13594. return roots2;
  13595. }
  13596. }
  13597. return [];
  13598. }
  13599. /**
  13600. * Provides the real valued roots of the quartic polynomial with the provided coefficients.
  13601. *
  13602. * @param {Number} a The coefficient of the 4th order monomial.
  13603. * @param {Number} b The coefficient of the 3rd order monomial.
  13604. * @param {Number} c The coefficient of the 2nd order monomial.
  13605. * @param {Number} d The coefficient of the 1st order monomial.
  13606. * @param {Number} e The coefficient of the 0th order monomial.
  13607. * @returns {Number[]} The real valued roots.
  13608. */
  13609. QuarticRealPolynomial.computeRealRoots = function(a, b, c, d, e) {
  13610. if (typeof a !== 'number') {
  13611. throw new DeveloperError('a is a required number.');
  13612. }
  13613. if (typeof b !== 'number') {
  13614. throw new DeveloperError('b is a required number.');
  13615. }
  13616. if (typeof c !== 'number') {
  13617. throw new DeveloperError('c is a required number.');
  13618. }
  13619. if (typeof d !== 'number') {
  13620. throw new DeveloperError('d is a required number.');
  13621. }
  13622. if (typeof e !== 'number') {
  13623. throw new DeveloperError('e is a required number.');
  13624. }
  13625. if (Math.abs(a) < CesiumMath.EPSILON15) {
  13626. return CubicRealPolynomial.computeRealRoots(b, c, d, e);
  13627. }
  13628. var a3 = b / a;
  13629. var a2 = c / a;
  13630. var a1 = d / a;
  13631. var a0 = e / a;
  13632. var k = (a3 < 0.0) ? 1 : 0;
  13633. k += (a2 < 0.0) ? k + 1 : k;
  13634. k += (a1 < 0.0) ? k + 1 : k;
  13635. k += (a0 < 0.0) ? k + 1 : k;
  13636. switch (k) {
  13637. case 0:
  13638. return original(a3, a2, a1, a0);
  13639. case 1:
  13640. return neumark(a3, a2, a1, a0);
  13641. case 2:
  13642. return neumark(a3, a2, a1, a0);
  13643. case 3:
  13644. return original(a3, a2, a1, a0);
  13645. case 4:
  13646. return original(a3, a2, a1, a0);
  13647. case 5:
  13648. return neumark(a3, a2, a1, a0);
  13649. case 6:
  13650. return original(a3, a2, a1, a0);
  13651. case 7:
  13652. return original(a3, a2, a1, a0);
  13653. case 8:
  13654. return neumark(a3, a2, a1, a0);
  13655. case 9:
  13656. return original(a3, a2, a1, a0);
  13657. case 10:
  13658. return original(a3, a2, a1, a0);
  13659. case 11:
  13660. return neumark(a3, a2, a1, a0);
  13661. case 12:
  13662. return original(a3, a2, a1, a0);
  13663. case 13:
  13664. return original(a3, a2, a1, a0);
  13665. case 14:
  13666. return original(a3, a2, a1, a0);
  13667. case 15:
  13668. return original(a3, a2, a1, a0);
  13669. default:
  13670. return undefined;
  13671. }
  13672. };
  13673. return QuarticRealPolynomial;
  13674. });
  13675. /*global define*/
  13676. define('Core/Ray',[
  13677. './Cartesian3',
  13678. './defaultValue',
  13679. './defined',
  13680. './DeveloperError'
  13681. ], function(
  13682. Cartesian3,
  13683. defaultValue,
  13684. defined,
  13685. DeveloperError) {
  13686. 'use strict';
  13687. /**
  13688. * Represents a ray that extends infinitely from the provided origin in the provided direction.
  13689. * @alias Ray
  13690. * @constructor
  13691. *
  13692. * @param {Cartesian3} [origin=Cartesian3.ZERO] The origin of the ray.
  13693. * @param {Cartesian3} [direction=Cartesian3.ZERO] The direction of the ray.
  13694. */
  13695. function Ray(origin, direction) {
  13696. direction = Cartesian3.clone(defaultValue(direction, Cartesian3.ZERO));
  13697. if (!Cartesian3.equals(direction, Cartesian3.ZERO)) {
  13698. Cartesian3.normalize(direction, direction);
  13699. }
  13700. /**
  13701. * The origin of the ray.
  13702. * @type {Cartesian3}
  13703. * @default {@link Cartesian3.ZERO}
  13704. */
  13705. this.origin = Cartesian3.clone(defaultValue(origin, Cartesian3.ZERO));
  13706. /**
  13707. * The direction of the ray.
  13708. * @type {Cartesian3}
  13709. */
  13710. this.direction = direction;
  13711. }
  13712. /**
  13713. * Computes the point along the ray given by r(t) = o + t*d,
  13714. * where o is the origin of the ray and d is the direction.
  13715. *
  13716. * @param {Ray} ray The ray.
  13717. * @param {Number} t A scalar value.
  13718. * @param {Cartesian3} [result] The object in which the result will be stored.
  13719. * @returns {Cartesian3} The modified result parameter, or a new instance if none was provided.
  13720. *
  13721. * @example
  13722. * //Get the first intersection point of a ray and an ellipsoid.
  13723. * var intersection = Cesium.IntersectionTests.rayEllipsoid(ray, ellipsoid);
  13724. * var point = Cesium.Ray.getPoint(ray, intersection.start);
  13725. */
  13726. Ray.getPoint = function(ray, t, result) {
  13727. if (!defined(ray)){
  13728. throw new DeveloperError('ray is requred');
  13729. }
  13730. if (typeof t !== 'number') {
  13731. throw new DeveloperError('t is a required number');
  13732. }
  13733. if (!defined(result)) {
  13734. result = new Cartesian3();
  13735. }
  13736. result = Cartesian3.multiplyByScalar(ray.direction, t, result);
  13737. return Cartesian3.add(ray.origin, result, result);
  13738. };
  13739. return Ray;
  13740. });
  13741. /*global define*/
  13742. define('Core/IntersectionTests',[
  13743. './Cartesian3',
  13744. './Cartographic',
  13745. './defaultValue',
  13746. './defined',
  13747. './DeveloperError',
  13748. './Math',
  13749. './Matrix3',
  13750. './QuadraticRealPolynomial',
  13751. './QuarticRealPolynomial',
  13752. './Ray'
  13753. ], function(
  13754. Cartesian3,
  13755. Cartographic,
  13756. defaultValue,
  13757. defined,
  13758. DeveloperError,
  13759. CesiumMath,
  13760. Matrix3,
  13761. QuadraticRealPolynomial,
  13762. QuarticRealPolynomial,
  13763. Ray) {
  13764. 'use strict';
  13765. /**
  13766. * Functions for computing the intersection between geometries such as rays, planes, triangles, and ellipsoids.
  13767. *
  13768. * @exports IntersectionTests
  13769. */
  13770. var IntersectionTests = {};
  13771. /**
  13772. * Computes the intersection of a ray and a plane.
  13773. *
  13774. * @param {Ray} ray The ray.
  13775. * @param {Plane} plane The plane.
  13776. * @param {Cartesian3} [result] The object onto which to store the result.
  13777. * @returns {Cartesian3} The intersection point or undefined if there is no intersections.
  13778. */
  13779. IntersectionTests.rayPlane = function(ray, plane, result) {
  13780. if (!defined(ray)) {
  13781. throw new DeveloperError('ray is required.');
  13782. }
  13783. if (!defined(plane)) {
  13784. throw new DeveloperError('plane is required.');
  13785. }
  13786. if (!defined(result)) {
  13787. result = new Cartesian3();
  13788. }
  13789. var origin = ray.origin;
  13790. var direction = ray.direction;
  13791. var normal = plane.normal;
  13792. var denominator = Cartesian3.dot(normal, direction);
  13793. if (Math.abs(denominator) < CesiumMath.EPSILON15) {
  13794. // Ray is parallel to plane. The ray may be in the polygon's plane.
  13795. return undefined;
  13796. }
  13797. var t = (-plane.distance - Cartesian3.dot(normal, origin)) / denominator;
  13798. if (t < 0) {
  13799. return undefined;
  13800. }
  13801. result = Cartesian3.multiplyByScalar(direction, t, result);
  13802. return Cartesian3.add(origin, result, result);
  13803. };
  13804. var scratchEdge0 = new Cartesian3();
  13805. var scratchEdge1 = new Cartesian3();
  13806. var scratchPVec = new Cartesian3();
  13807. var scratchTVec = new Cartesian3();
  13808. var scratchQVec = new Cartesian3();
  13809. /**
  13810. * Computes the intersection of a ray and a triangle as a parametric distance along the input ray.
  13811. *
  13812. * Implements {@link https://cadxfem.org/inf/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf|
  13813. * Fast Minimum Storage Ray/Triangle Intersection} by Tomas Moller and Ben Trumbore.
  13814. *
  13815. * @memberof IntersectionTests
  13816. *
  13817. * @param {Ray} ray The ray.
  13818. * @param {Cartesian3} p0 The first vertex of the triangle.
  13819. * @param {Cartesian3} p1 The second vertex of the triangle.
  13820. * @param {Cartesian3} p2 The third vertex of the triangle.
  13821. * @param {Boolean} [cullBackFaces=false] If <code>true</code>, will only compute an intersection with the front face of the triangle
  13822. * and return undefined for intersections with the back face.
  13823. * @returns {Number} The intersection as a parametric distance along the ray, or undefined if there is no intersection.
  13824. */
  13825. IntersectionTests.rayTriangleParametric = function(ray, p0, p1, p2, cullBackFaces) {
  13826. if (!defined(ray)) {
  13827. throw new DeveloperError('ray is required.');
  13828. }
  13829. if (!defined(p0)) {
  13830. throw new DeveloperError('p0 is required.');
  13831. }
  13832. if (!defined(p1)) {
  13833. throw new DeveloperError('p1 is required.');
  13834. }
  13835. if (!defined(p2)) {
  13836. throw new DeveloperError('p2 is required.');
  13837. }
  13838. cullBackFaces = defaultValue(cullBackFaces, false);
  13839. var origin = ray.origin;
  13840. var direction = ray.direction;
  13841. var edge0 = Cartesian3.subtract(p1, p0, scratchEdge0);
  13842. var edge1 = Cartesian3.subtract(p2, p0, scratchEdge1);
  13843. var p = Cartesian3.cross(direction, edge1, scratchPVec);
  13844. var det = Cartesian3.dot(edge0, p);
  13845. var tvec;
  13846. var q;
  13847. var u;
  13848. var v;
  13849. var t;
  13850. if (cullBackFaces) {
  13851. if (det < CesiumMath.EPSILON6) {
  13852. return undefined;
  13853. }
  13854. tvec = Cartesian3.subtract(origin, p0, scratchTVec);
  13855. u = Cartesian3.dot(tvec, p);
  13856. if (u < 0.0 || u > det) {
  13857. return undefined;
  13858. }
  13859. q = Cartesian3.cross(tvec, edge0, scratchQVec);
  13860. v = Cartesian3.dot(direction, q);
  13861. if (v < 0.0 || u + v > det) {
  13862. return undefined;
  13863. }
  13864. t = Cartesian3.dot(edge1, q) / det;
  13865. } else {
  13866. if (Math.abs(det) < CesiumMath.EPSILON6) {
  13867. return undefined;
  13868. }
  13869. var invDet = 1.0 / det;
  13870. tvec = Cartesian3.subtract(origin, p0, scratchTVec);
  13871. u = Cartesian3.dot(tvec, p) * invDet;
  13872. if (u < 0.0 || u > 1.0) {
  13873. return undefined;
  13874. }
  13875. q = Cartesian3.cross(tvec, edge0, scratchQVec);
  13876. v = Cartesian3.dot(direction, q) * invDet;
  13877. if (v < 0.0 || u + v > 1.0) {
  13878. return undefined;
  13879. }
  13880. t = Cartesian3.dot(edge1, q) * invDet;
  13881. }
  13882. return t;
  13883. };
  13884. /**
  13885. * Computes the intersection of a ray and a triangle as a Cartesian3 coordinate.
  13886. *
  13887. * Implements {@link https://cadxfem.org/inf/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf|
  13888. * Fast Minimum Storage Ray/Triangle Intersection} by Tomas Moller and Ben Trumbore.
  13889. *
  13890. * @memberof IntersectionTests
  13891. *
  13892. * @param {Ray} ray The ray.
  13893. * @param {Cartesian3} p0 The first vertex of the triangle.
  13894. * @param {Cartesian3} p1 The second vertex of the triangle.
  13895. * @param {Cartesian3} p2 The third vertex of the triangle.
  13896. * @param {Boolean} [cullBackFaces=false] If <code>true</code>, will only compute an intersection with the front face of the triangle
  13897. * and return undefined for intersections with the back face.
  13898. * @param {Cartesian3} [result] The <code>Cartesian3</code> onto which to store the result.
  13899. * @returns {Cartesian3} The intersection point or undefined if there is no intersections.
  13900. */
  13901. IntersectionTests.rayTriangle = function(ray, p0, p1, p2, cullBackFaces, result) {
  13902. var t = IntersectionTests.rayTriangleParametric(ray, p0, p1, p2, cullBackFaces);
  13903. if (!defined(t) || t < 0.0) {
  13904. return undefined;
  13905. }
  13906. if (!defined(result)) {
  13907. result = new Cartesian3();
  13908. }
  13909. Cartesian3.multiplyByScalar(ray.direction, t, result);
  13910. return Cartesian3.add(ray.origin, result, result);
  13911. };
  13912. var scratchLineSegmentTriangleRay = new Ray();
  13913. /**
  13914. * Computes the intersection of a line segment and a triangle.
  13915. * @memberof IntersectionTests
  13916. *
  13917. * @param {Cartesian3} v0 The an end point of the line segment.
  13918. * @param {Cartesian3} v1 The other end point of the line segment.
  13919. * @param {Cartesian3} p0 The first vertex of the triangle.
  13920. * @param {Cartesian3} p1 The second vertex of the triangle.
  13921. * @param {Cartesian3} p2 The third vertex of the triangle.
  13922. * @param {Boolean} [cullBackFaces=false] If <code>true</code>, will only compute an intersection with the front face of the triangle
  13923. * and return undefined for intersections with the back face.
  13924. * @param {Cartesian3} [result] The <code>Cartesian3</code> onto which to store the result.
  13925. * @returns {Cartesian3} The intersection point or undefined if there is no intersections.
  13926. */
  13927. IntersectionTests.lineSegmentTriangle = function(v0, v1, p0, p1, p2, cullBackFaces, result) {
  13928. if (!defined(v0)) {
  13929. throw new DeveloperError('v0 is required.');
  13930. }
  13931. if (!defined(v1)) {
  13932. throw new DeveloperError('v1 is required.');
  13933. }
  13934. if (!defined(p0)) {
  13935. throw new DeveloperError('p0 is required.');
  13936. }
  13937. if (!defined(p1)) {
  13938. throw new DeveloperError('p1 is required.');
  13939. }
  13940. if (!defined(p2)) {
  13941. throw new DeveloperError('p2 is required.');
  13942. }
  13943. var ray = scratchLineSegmentTriangleRay;
  13944. Cartesian3.clone(v0, ray.origin);
  13945. Cartesian3.subtract(v1, v0, ray.direction);
  13946. Cartesian3.normalize(ray.direction, ray.direction);
  13947. var t = IntersectionTests.rayTriangleParametric(ray, p0, p1, p2, cullBackFaces);
  13948. if (!defined(t) || t < 0.0 || t > Cartesian3.distance(v0, v1)) {
  13949. return undefined;
  13950. }
  13951. if (!defined(result)) {
  13952. result = new Cartesian3();
  13953. }
  13954. Cartesian3.multiplyByScalar(ray.direction, t, result);
  13955. return Cartesian3.add(ray.origin, result, result);
  13956. };
  13957. function solveQuadratic(a, b, c, result) {
  13958. var det = b * b - 4.0 * a * c;
  13959. if (det < 0.0) {
  13960. return undefined;
  13961. } else if (det > 0.0) {
  13962. var denom = 1.0 / (2.0 * a);
  13963. var disc = Math.sqrt(det);
  13964. var root0 = (-b + disc) * denom;
  13965. var root1 = (-b - disc) * denom;
  13966. if (root0 < root1) {
  13967. result.root0 = root0;
  13968. result.root1 = root1;
  13969. } else {
  13970. result.root0 = root1;
  13971. result.root1 = root0;
  13972. }
  13973. return result;
  13974. }
  13975. var root = -b / (2.0 * a);
  13976. if (root === 0.0) {
  13977. return undefined;
  13978. }
  13979. result.root0 = result.root1 = root;
  13980. return result;
  13981. }
  13982. var raySphereRoots = {
  13983. root0 : 0.0,
  13984. root1 : 0.0
  13985. };
  13986. function raySphere(ray, sphere, result) {
  13987. if (!defined(result)) {
  13988. result = {};
  13989. }
  13990. var origin = ray.origin;
  13991. var direction = ray.direction;
  13992. var center = sphere.center;
  13993. var radiusSquared = sphere.radius * sphere.radius;
  13994. var diff = Cartesian3.subtract(origin, center, scratchPVec);
  13995. var a = Cartesian3.dot(direction, direction);
  13996. var b = 2.0 * Cartesian3.dot(direction, diff);
  13997. var c = Cartesian3.magnitudeSquared(diff) - radiusSquared;
  13998. var roots = solveQuadratic(a, b, c, raySphereRoots);
  13999. if (!defined(roots)) {
  14000. return undefined;
  14001. }
  14002. result.start = roots.root0;
  14003. result.stop = roots.root1;
  14004. return result;
  14005. }
  14006. /**
  14007. * Computes the intersection points of a ray with a sphere.
  14008. * @memberof IntersectionTests
  14009. *
  14010. * @param {Ray} ray The ray.
  14011. * @param {BoundingSphere} sphere The sphere.
  14012. * @param {Object} [result] The result onto which to store the result.
  14013. * @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.
  14014. */
  14015. IntersectionTests.raySphere = function(ray, sphere, result) {
  14016. if (!defined(ray)) {
  14017. throw new DeveloperError('ray is required.');
  14018. }
  14019. if (!defined(sphere)) {
  14020. throw new DeveloperError('sphere is required.');
  14021. }
  14022. result = raySphere(ray, sphere, result);
  14023. if (!defined(result) || result.stop < 0.0) {
  14024. return undefined;
  14025. }
  14026. result.start = Math.max(result.start, 0.0);
  14027. return result;
  14028. };
  14029. var scratchLineSegmentRay = new Ray();
  14030. /**
  14031. * Computes the intersection points of a line segment with a sphere.
  14032. * @memberof IntersectionTests
  14033. *
  14034. * @param {Cartesian3} p0 An end point of the line segment.
  14035. * @param {Cartesian3} p1 The other end point of the line segment.
  14036. * @param {BoundingSphere} sphere The sphere.
  14037. * @param {Object} [result] The result onto which to store the result.
  14038. * @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.
  14039. */
  14040. IntersectionTests.lineSegmentSphere = function(p0, p1, sphere, result) {
  14041. if (!defined(p0)) {
  14042. throw new DeveloperError('p0 is required.');
  14043. }
  14044. if (!defined(p1)) {
  14045. throw new DeveloperError('p1 is required.');
  14046. }
  14047. if (!defined(sphere)) {
  14048. throw new DeveloperError('sphere is required.');
  14049. }
  14050. var ray = scratchLineSegmentRay;
  14051. Cartesian3.clone(p0, ray.origin);
  14052. var direction = Cartesian3.subtract(p1, p0, ray.direction);
  14053. var maxT = Cartesian3.magnitude(direction);
  14054. Cartesian3.normalize(direction, direction);
  14055. result = raySphere(ray, sphere, result);
  14056. if (!defined(result) || result.stop < 0.0 || result.start > maxT) {
  14057. return undefined;
  14058. }
  14059. result.start = Math.max(result.start, 0.0);
  14060. result.stop = Math.min(result.stop, maxT);
  14061. return result;
  14062. };
  14063. var scratchQ = new Cartesian3();
  14064. var scratchW = new Cartesian3();
  14065. /**
  14066. * Computes the intersection points of a ray with an ellipsoid.
  14067. *
  14068. * @param {Ray} ray The ray.
  14069. * @param {Ellipsoid} ellipsoid The ellipsoid.
  14070. * @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.
  14071. */
  14072. IntersectionTests.rayEllipsoid = function(ray, ellipsoid) {
  14073. if (!defined(ray)) {
  14074. throw new DeveloperError('ray is required.');
  14075. }
  14076. if (!defined(ellipsoid)) {
  14077. throw new DeveloperError('ellipsoid is required.');
  14078. }
  14079. var inverseRadii = ellipsoid.oneOverRadii;
  14080. var q = Cartesian3.multiplyComponents(inverseRadii, ray.origin, scratchQ);
  14081. var w = Cartesian3.multiplyComponents(inverseRadii, ray.direction, scratchW);
  14082. var q2 = Cartesian3.magnitudeSquared(q);
  14083. var qw = Cartesian3.dot(q, w);
  14084. var difference, w2, product, discriminant, temp;
  14085. if (q2 > 1.0) {
  14086. // Outside ellipsoid.
  14087. if (qw >= 0.0) {
  14088. // Looking outward or tangent (0 intersections).
  14089. return undefined;
  14090. }
  14091. // qw < 0.0.
  14092. var qw2 = qw * qw;
  14093. difference = q2 - 1.0; // Positively valued.
  14094. w2 = Cartesian3.magnitudeSquared(w);
  14095. product = w2 * difference;
  14096. if (qw2 < product) {
  14097. // Imaginary roots (0 intersections).
  14098. return undefined;
  14099. } else if (qw2 > product) {
  14100. // Distinct roots (2 intersections).
  14101. discriminant = qw * qw - product;
  14102. temp = -qw + Math.sqrt(discriminant); // Avoid cancellation.
  14103. var root0 = temp / w2;
  14104. var root1 = difference / temp;
  14105. if (root0 < root1) {
  14106. return {
  14107. start : root0,
  14108. stop : root1
  14109. };
  14110. }
  14111. return {
  14112. start : root1,
  14113. stop : root0
  14114. };
  14115. } else {
  14116. // qw2 == product. Repeated roots (2 intersections).
  14117. var root = Math.sqrt(difference / w2);
  14118. return {
  14119. start : root,
  14120. stop : root
  14121. };
  14122. }
  14123. } else if (q2 < 1.0) {
  14124. // Inside ellipsoid (2 intersections).
  14125. difference = q2 - 1.0; // Negatively valued.
  14126. w2 = Cartesian3.magnitudeSquared(w);
  14127. product = w2 * difference; // Negatively valued.
  14128. discriminant = qw * qw - product;
  14129. temp = -qw + Math.sqrt(discriminant); // Positively valued.
  14130. return {
  14131. start : 0.0,
  14132. stop : temp / w2
  14133. };
  14134. } else {
  14135. // q2 == 1.0. On ellipsoid.
  14136. if (qw < 0.0) {
  14137. // Looking inward.
  14138. w2 = Cartesian3.magnitudeSquared(w);
  14139. return {
  14140. start : 0.0,
  14141. stop : -qw / w2
  14142. };
  14143. }
  14144. // qw >= 0.0. Looking outward or tangent.
  14145. return undefined;
  14146. }
  14147. };
  14148. function addWithCancellationCheck(left, right, tolerance) {
  14149. var difference = left + right;
  14150. if ((CesiumMath.sign(left) !== CesiumMath.sign(right)) &&
  14151. Math.abs(difference / Math.max(Math.abs(left), Math.abs(right))) < tolerance) {
  14152. return 0.0;
  14153. }
  14154. return difference;
  14155. }
  14156. function quadraticVectorExpression(A, b, c, x, w) {
  14157. var xSquared = x * x;
  14158. var wSquared = w * w;
  14159. var l2 = (A[Matrix3.COLUMN1ROW1] - A[Matrix3.COLUMN2ROW2]) * wSquared;
  14160. var l1 = w * (x * addWithCancellationCheck(A[Matrix3.COLUMN1ROW0], A[Matrix3.COLUMN0ROW1], CesiumMath.EPSILON15) + b.y);
  14161. var l0 = (A[Matrix3.COLUMN0ROW0] * xSquared + A[Matrix3.COLUMN2ROW2] * wSquared) + x * b.x + c;
  14162. var r1 = wSquared * addWithCancellationCheck(A[Matrix3.COLUMN2ROW1], A[Matrix3.COLUMN1ROW2], CesiumMath.EPSILON15);
  14163. var r0 = w * (x * addWithCancellationCheck(A[Matrix3.COLUMN2ROW0], A[Matrix3.COLUMN0ROW2]) + b.z);
  14164. var cosines;
  14165. var solutions = [];
  14166. if (r0 === 0.0 && r1 === 0.0) {
  14167. cosines = QuadraticRealPolynomial.computeRealRoots(l2, l1, l0);
  14168. if (cosines.length === 0) {
  14169. return solutions;
  14170. }
  14171. var cosine0 = cosines[0];
  14172. var sine0 = Math.sqrt(Math.max(1.0 - cosine0 * cosine0, 0.0));
  14173. solutions.push(new Cartesian3(x, w * cosine0, w * -sine0));
  14174. solutions.push(new Cartesian3(x, w * cosine0, w * sine0));
  14175. if (cosines.length === 2) {
  14176. var cosine1 = cosines[1];
  14177. var sine1 = Math.sqrt(Math.max(1.0 - cosine1 * cosine1, 0.0));
  14178. solutions.push(new Cartesian3(x, w * cosine1, w * -sine1));
  14179. solutions.push(new Cartesian3(x, w * cosine1, w * sine1));
  14180. }
  14181. return solutions;
  14182. }
  14183. var r0Squared = r0 * r0;
  14184. var r1Squared = r1 * r1;
  14185. var l2Squared = l2 * l2;
  14186. var r0r1 = r0 * r1;
  14187. var c4 = l2Squared + r1Squared;
  14188. var c3 = 2.0 * (l1 * l2 + r0r1);
  14189. var c2 = 2.0 * l0 * l2 + l1 * l1 - r1Squared + r0Squared;
  14190. var c1 = 2.0 * (l0 * l1 - r0r1);
  14191. var c0 = l0 * l0 - r0Squared;
  14192. if (c4 === 0.0 && c3 === 0.0 && c2 === 0.0 && c1 === 0.0) {
  14193. return solutions;
  14194. }
  14195. cosines = QuarticRealPolynomial.computeRealRoots(c4, c3, c2, c1, c0);
  14196. var length = cosines.length;
  14197. if (length === 0) {
  14198. return solutions;
  14199. }
  14200. for ( var i = 0; i < length; ++i) {
  14201. var cosine = cosines[i];
  14202. var cosineSquared = cosine * cosine;
  14203. var sineSquared = Math.max(1.0 - cosineSquared, 0.0);
  14204. var sine = Math.sqrt(sineSquared);
  14205. //var left = l2 * cosineSquared + l1 * cosine + l0;
  14206. var left;
  14207. if (CesiumMath.sign(l2) === CesiumMath.sign(l0)) {
  14208. left = addWithCancellationCheck(l2 * cosineSquared + l0, l1 * cosine, CesiumMath.EPSILON12);
  14209. } else if (CesiumMath.sign(l0) === CesiumMath.sign(l1 * cosine)) {
  14210. left = addWithCancellationCheck(l2 * cosineSquared, l1 * cosine + l0, CesiumMath.EPSILON12);
  14211. } else {
  14212. left = addWithCancellationCheck(l2 * cosineSquared + l1 * cosine, l0, CesiumMath.EPSILON12);
  14213. }
  14214. var right = addWithCancellationCheck(r1 * cosine, r0, CesiumMath.EPSILON15);
  14215. var product = left * right;
  14216. if (product < 0.0) {
  14217. solutions.push(new Cartesian3(x, w * cosine, w * sine));
  14218. } else if (product > 0.0) {
  14219. solutions.push(new Cartesian3(x, w * cosine, w * -sine));
  14220. } else if (sine !== 0.0) {
  14221. solutions.push(new Cartesian3(x, w * cosine, w * -sine));
  14222. solutions.push(new Cartesian3(x, w * cosine, w * sine));
  14223. ++i;
  14224. } else {
  14225. solutions.push(new Cartesian3(x, w * cosine, w * sine));
  14226. }
  14227. }
  14228. return solutions;
  14229. }
  14230. var firstAxisScratch = new Cartesian3();
  14231. var secondAxisScratch = new Cartesian3();
  14232. var thirdAxisScratch = new Cartesian3();
  14233. var referenceScratch = new Cartesian3();
  14234. var bCart = new Cartesian3();
  14235. var bScratch = new Matrix3();
  14236. var btScratch = new Matrix3();
  14237. var diScratch = new Matrix3();
  14238. var dScratch = new Matrix3();
  14239. var cScratch = new Matrix3();
  14240. var tempMatrix = new Matrix3();
  14241. var aScratch = new Matrix3();
  14242. var sScratch = new Cartesian3();
  14243. var closestScratch = new Cartesian3();
  14244. var surfPointScratch = new Cartographic();
  14245. /**
  14246. * Provides the point along the ray which is nearest to the ellipsoid.
  14247. *
  14248. * @param {Ray} ray The ray.
  14249. * @param {Ellipsoid} ellipsoid The ellipsoid.
  14250. * @returns {Cartesian3} The nearest planetodetic point on the ray.
  14251. */
  14252. IntersectionTests.grazingAltitudeLocation = function(ray, ellipsoid) {
  14253. if (!defined(ray)) {
  14254. throw new DeveloperError('ray is required.');
  14255. }
  14256. if (!defined(ellipsoid)) {
  14257. throw new DeveloperError('ellipsoid is required.');
  14258. }
  14259. var position = ray.origin;
  14260. var direction = ray.direction;
  14261. if (!Cartesian3.equals(position, Cartesian3.ZERO)) {
  14262. var normal = ellipsoid.geodeticSurfaceNormal(position, firstAxisScratch);
  14263. if (Cartesian3.dot(direction, normal) >= 0.0) { // The location provided is the closest point in altitude
  14264. return position;
  14265. }
  14266. }
  14267. var intersects = defined(this.rayEllipsoid(ray, ellipsoid));
  14268. // Compute the scaled direction vector.
  14269. var f = ellipsoid.transformPositionToScaledSpace(direction, firstAxisScratch);
  14270. // Constructs a basis from the unit scaled direction vector. Construct its rotation and transpose.
  14271. var firstAxis = Cartesian3.normalize(f, f);
  14272. var reference = Cartesian3.mostOrthogonalAxis(f, referenceScratch);
  14273. var secondAxis = Cartesian3.normalize(Cartesian3.cross(reference, firstAxis, secondAxisScratch), secondAxisScratch);
  14274. var thirdAxis = Cartesian3.normalize(Cartesian3.cross(firstAxis, secondAxis, thirdAxisScratch), thirdAxisScratch);
  14275. var B = bScratch;
  14276. B[0] = firstAxis.x;
  14277. B[1] = firstAxis.y;
  14278. B[2] = firstAxis.z;
  14279. B[3] = secondAxis.x;
  14280. B[4] = secondAxis.y;
  14281. B[5] = secondAxis.z;
  14282. B[6] = thirdAxis.x;
  14283. B[7] = thirdAxis.y;
  14284. B[8] = thirdAxis.z;
  14285. var B_T = Matrix3.transpose(B, btScratch);
  14286. // Get the scaling matrix and its inverse.
  14287. var D_I = Matrix3.fromScale(ellipsoid.radii, diScratch);
  14288. var D = Matrix3.fromScale(ellipsoid.oneOverRadii, dScratch);
  14289. var C = cScratch;
  14290. C[0] = 0.0;
  14291. C[1] = -direction.z;
  14292. C[2] = direction.y;
  14293. C[3] = direction.z;
  14294. C[4] = 0.0;
  14295. C[5] = -direction.x;
  14296. C[6] = -direction.y;
  14297. C[7] = direction.x;
  14298. C[8] = 0.0;
  14299. var temp = Matrix3.multiply(Matrix3.multiply(B_T, D, tempMatrix), C, tempMatrix);
  14300. var A = Matrix3.multiply(Matrix3.multiply(temp, D_I, aScratch), B, aScratch);
  14301. var b = Matrix3.multiplyByVector(temp, position, bCart);
  14302. // Solve for the solutions to the expression in standard form:
  14303. var solutions = quadraticVectorExpression(A, Cartesian3.negate(b, firstAxisScratch), 0.0, 0.0, 1.0);
  14304. var s;
  14305. var altitude;
  14306. var length = solutions.length;
  14307. if (length > 0) {
  14308. var closest = Cartesian3.clone(Cartesian3.ZERO, closestScratch);
  14309. var maximumValue = Number.NEGATIVE_INFINITY;
  14310. for ( var i = 0; i < length; ++i) {
  14311. s = Matrix3.multiplyByVector(D_I, Matrix3.multiplyByVector(B, solutions[i], sScratch), sScratch);
  14312. var v = Cartesian3.normalize(Cartesian3.subtract(s, position, referenceScratch), referenceScratch);
  14313. var dotProduct = Cartesian3.dot(v, direction);
  14314. if (dotProduct > maximumValue) {
  14315. maximumValue = dotProduct;
  14316. closest = Cartesian3.clone(s, closest);
  14317. }
  14318. }
  14319. var surfacePoint = ellipsoid.cartesianToCartographic(closest, surfPointScratch);
  14320. maximumValue = CesiumMath.clamp(maximumValue, 0.0, 1.0);
  14321. altitude = Cartesian3.magnitude(Cartesian3.subtract(closest, position, referenceScratch)) * Math.sqrt(1.0 - maximumValue * maximumValue);
  14322. altitude = intersects ? -altitude : altitude;
  14323. surfacePoint.height = altitude;
  14324. return ellipsoid.cartographicToCartesian(surfacePoint, new Cartesian3());
  14325. }
  14326. return undefined;
  14327. };
  14328. var lineSegmentPlaneDifference = new Cartesian3();
  14329. /**
  14330. * Computes the intersection of a line segment and a plane.
  14331. *
  14332. * @param {Cartesian3} endPoint0 An end point of the line segment.
  14333. * @param {Cartesian3} endPoint1 The other end point of the line segment.
  14334. * @param {Plane} plane The plane.
  14335. * @param {Cartesian3} [result] The object onto which to store the result.
  14336. * @returns {Cartesian3} The intersection point or undefined if there is no intersection.
  14337. *
  14338. * @example
  14339. * var origin = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);
  14340. * var normal = ellipsoid.geodeticSurfaceNormal(origin);
  14341. * var plane = Cesium.Plane.fromPointNormal(origin, normal);
  14342. *
  14343. * var p0 = new Cesium.Cartesian3(...);
  14344. * var p1 = new Cesium.Cartesian3(...);
  14345. *
  14346. * // find the intersection of the line segment from p0 to p1 and the tangent plane at origin.
  14347. * var intersection = Cesium.IntersectionTests.lineSegmentPlane(p0, p1, plane);
  14348. */
  14349. IntersectionTests.lineSegmentPlane = function(endPoint0, endPoint1, plane, result) {
  14350. if (!defined(endPoint0)) {
  14351. throw new DeveloperError('endPoint0 is required.');
  14352. }
  14353. if (!defined(endPoint1)) {
  14354. throw new DeveloperError('endPoint1 is required.');
  14355. }
  14356. if (!defined(plane)) {
  14357. throw new DeveloperError('plane is required.');
  14358. }
  14359. if (!defined(result)) {
  14360. result = new Cartesian3();
  14361. }
  14362. var difference = Cartesian3.subtract(endPoint1, endPoint0, lineSegmentPlaneDifference);
  14363. var normal = plane.normal;
  14364. var nDotDiff = Cartesian3.dot(normal, difference);
  14365. // check if the segment and plane are parallel
  14366. if (Math.abs(nDotDiff) < CesiumMath.EPSILON6) {
  14367. return undefined;
  14368. }
  14369. var nDotP0 = Cartesian3.dot(normal, endPoint0);
  14370. var t = -(plane.distance + nDotP0) / nDotDiff;
  14371. // intersection only if t is in [0, 1]
  14372. if (t < 0.0 || t > 1.0) {
  14373. return undefined;
  14374. }
  14375. // intersection is endPoint0 + t * (endPoint1 - endPoint0)
  14376. Cartesian3.multiplyByScalar(difference, t, result);
  14377. Cartesian3.add(endPoint0, result, result);
  14378. return result;
  14379. };
  14380. /**
  14381. * Computes the intersection of a triangle and a plane
  14382. *
  14383. * @param {Cartesian3} p0 First point of the triangle
  14384. * @param {Cartesian3} p1 Second point of the triangle
  14385. * @param {Cartesian3} p2 Third point of the triangle
  14386. * @param {Plane} plane Intersection plane
  14387. * @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)
  14388. *
  14389. * @example
  14390. * var origin = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);
  14391. * var normal = ellipsoid.geodeticSurfaceNormal(origin);
  14392. * var plane = Cesium.Plane.fromPointNormal(origin, normal);
  14393. *
  14394. * var p0 = new Cesium.Cartesian3(...);
  14395. * var p1 = new Cesium.Cartesian3(...);
  14396. * var p2 = new Cesium.Cartesian3(...);
  14397. *
  14398. * // convert the triangle composed of points (p0, p1, p2) to three triangles that don't cross the plane
  14399. * var triangles = Cesium.IntersectionTests.trianglePlaneIntersection(p0, p1, p2, plane);
  14400. */
  14401. IntersectionTests.trianglePlaneIntersection = function(p0, p1, p2, plane) {
  14402. if ((!defined(p0)) ||
  14403. (!defined(p1)) ||
  14404. (!defined(p2)) ||
  14405. (!defined(plane))) {
  14406. throw new DeveloperError('p0, p1, p2, and plane are required.');
  14407. }
  14408. var planeNormal = plane.normal;
  14409. var planeD = plane.distance;
  14410. var p0Behind = (Cartesian3.dot(planeNormal, p0) + planeD) < 0.0;
  14411. var p1Behind = (Cartesian3.dot(planeNormal, p1) + planeD) < 0.0;
  14412. var p2Behind = (Cartesian3.dot(planeNormal, p2) + planeD) < 0.0;
  14413. // Given these dots products, the calls to lineSegmentPlaneIntersection
  14414. // always have defined results.
  14415. var numBehind = 0;
  14416. numBehind += p0Behind ? 1 : 0;
  14417. numBehind += p1Behind ? 1 : 0;
  14418. numBehind += p2Behind ? 1 : 0;
  14419. var u1, u2;
  14420. if (numBehind === 1 || numBehind === 2) {
  14421. u1 = new Cartesian3();
  14422. u2 = new Cartesian3();
  14423. }
  14424. if (numBehind === 1) {
  14425. if (p0Behind) {
  14426. IntersectionTests.lineSegmentPlane(p0, p1, plane, u1);
  14427. IntersectionTests.lineSegmentPlane(p0, p2, plane, u2);
  14428. return {
  14429. positions : [p0, p1, p2, u1, u2 ],
  14430. indices : [
  14431. // Behind
  14432. 0, 3, 4,
  14433. // In front
  14434. 1, 2, 4,
  14435. 1, 4, 3
  14436. ]
  14437. };
  14438. } else if (p1Behind) {
  14439. IntersectionTests.lineSegmentPlane(p1, p2, plane, u1);
  14440. IntersectionTests.lineSegmentPlane(p1, p0, plane, u2);
  14441. return {
  14442. positions : [p0, p1, p2, u1, u2 ],
  14443. indices : [
  14444. // Behind
  14445. 1, 3, 4,
  14446. // In front
  14447. 2, 0, 4,
  14448. 2, 4, 3
  14449. ]
  14450. };
  14451. } else if (p2Behind) {
  14452. IntersectionTests.lineSegmentPlane(p2, p0, plane, u1);
  14453. IntersectionTests.lineSegmentPlane(p2, p1, plane, u2);
  14454. return {
  14455. positions : [p0, p1, p2, u1, u2 ],
  14456. indices : [
  14457. // Behind
  14458. 2, 3, 4,
  14459. // In front
  14460. 0, 1, 4,
  14461. 0, 4, 3
  14462. ]
  14463. };
  14464. }
  14465. } else if (numBehind === 2) {
  14466. if (!p0Behind) {
  14467. IntersectionTests.lineSegmentPlane(p1, p0, plane, u1);
  14468. IntersectionTests.lineSegmentPlane(p2, p0, plane, u2);
  14469. return {
  14470. positions : [p0, p1, p2, u1, u2 ],
  14471. indices : [
  14472. // Behind
  14473. 1, 2, 4,
  14474. 1, 4, 3,
  14475. // In front
  14476. 0, 3, 4
  14477. ]
  14478. };
  14479. } else if (!p1Behind) {
  14480. IntersectionTests.lineSegmentPlane(p2, p1, plane, u1);
  14481. IntersectionTests.lineSegmentPlane(p0, p1, plane, u2);
  14482. return {
  14483. positions : [p0, p1, p2, u1, u2 ],
  14484. indices : [
  14485. // Behind
  14486. 2, 0, 4,
  14487. 2, 4, 3,
  14488. // In front
  14489. 1, 3, 4
  14490. ]
  14491. };
  14492. } else if (!p2Behind) {
  14493. IntersectionTests.lineSegmentPlane(p0, p2, plane, u1);
  14494. IntersectionTests.lineSegmentPlane(p1, p2, plane, u2);
  14495. return {
  14496. positions : [p0, p1, p2, u1, u2 ],
  14497. indices : [
  14498. // Behind
  14499. 0, 1, 4,
  14500. 0, 4, 3,
  14501. // In front
  14502. 2, 3, 4
  14503. ]
  14504. };
  14505. }
  14506. }
  14507. // if numBehind is 3, the triangle is completely behind the plane;
  14508. // otherwise, it is completely in front (numBehind is 0).
  14509. return undefined;
  14510. };
  14511. return IntersectionTests;
  14512. });
  14513. /*global define*/
  14514. define('Core/Plane',[
  14515. './Cartesian3',
  14516. './defined',
  14517. './DeveloperError',
  14518. './freezeObject'
  14519. ], function(
  14520. Cartesian3,
  14521. defined,
  14522. DeveloperError,
  14523. freezeObject) {
  14524. 'use strict';
  14525. /**
  14526. * A plane in Hessian Normal Form defined by
  14527. * <pre>
  14528. * ax + by + cz + d = 0
  14529. * </pre>
  14530. * where (a, b, c) is the plane's <code>normal</code>, d is the signed
  14531. * <code>distance</code> to the plane, and (x, y, z) is any point on
  14532. * the plane.
  14533. *
  14534. * @alias Plane
  14535. * @constructor
  14536. *
  14537. * @param {Cartesian3} normal The plane's normal (normalized).
  14538. * @param {Number} distance The shortest distance from the origin to the plane. The sign of
  14539. * <code>distance</code> determines which side of the plane the origin
  14540. * is on. If <code>distance</code> is positive, the origin is in the half-space
  14541. * in the direction of the normal; if negative, the origin is in the half-space
  14542. * opposite to the normal; if zero, the plane passes through the origin.
  14543. *
  14544. * @example
  14545. * // The plane x=0
  14546. * var plane = new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0.0);
  14547. */
  14548. function Plane(normal, distance) {
  14549. if (!defined(normal)) {
  14550. throw new DeveloperError('normal is required.');
  14551. }
  14552. if (!defined(distance)) {
  14553. throw new DeveloperError('distance is required.');
  14554. }
  14555. /**
  14556. * The plane's normal.
  14557. *
  14558. * @type {Cartesian3}
  14559. */
  14560. this.normal = Cartesian3.clone(normal);
  14561. /**
  14562. * The shortest distance from the origin to the plane. The sign of
  14563. * <code>distance</code> determines which side of the plane the origin
  14564. * is on. If <code>distance</code> is positive, the origin is in the half-space
  14565. * in the direction of the normal; if negative, the origin is in the half-space
  14566. * opposite to the normal; if zero, the plane passes through the origin.
  14567. *
  14568. * @type {Number}
  14569. */
  14570. this.distance = distance;
  14571. }
  14572. /**
  14573. * Creates a plane from a normal and a point on the plane.
  14574. *
  14575. * @param {Cartesian3} point The point on the plane.
  14576. * @param {Cartesian3} normal The plane's normal (normalized).
  14577. * @param {Plane} [result] The object onto which to store the result.
  14578. * @returns {Plane} A new plane instance or the modified result parameter.
  14579. *
  14580. * @example
  14581. * var point = Cesium.Cartesian3.fromDegrees(-72.0, 40.0);
  14582. * var normal = ellipsoid.geodeticSurfaceNormal(point);
  14583. * var tangentPlane = Cesium.Plane.fromPointNormal(point, normal);
  14584. */
  14585. Plane.fromPointNormal = function(point, normal, result) {
  14586. if (!defined(point)) {
  14587. throw new DeveloperError('point is required.');
  14588. }
  14589. if (!defined(normal)) {
  14590. throw new DeveloperError('normal is required.');
  14591. }
  14592. var distance = -Cartesian3.dot(normal, point);
  14593. if (!defined(result)) {
  14594. return new Plane(normal, distance);
  14595. }
  14596. Cartesian3.clone(normal, result.normal);
  14597. result.distance = distance;
  14598. return result;
  14599. };
  14600. var scratchNormal = new Cartesian3();
  14601. /**
  14602. * Creates a plane from the general equation
  14603. *
  14604. * @param {Cartesian4} coefficients The plane's normal (normalized).
  14605. * @param {Plane} [result] The object onto which to store the result.
  14606. * @returns {Plane} A new plane instance or the modified result parameter.
  14607. */
  14608. Plane.fromCartesian4 = function(coefficients, result) {
  14609. if (!defined(coefficients)) {
  14610. throw new DeveloperError('coefficients is required.');
  14611. }
  14612. var normal = Cartesian3.fromCartesian4(coefficients, scratchNormal);
  14613. var distance = coefficients.w;
  14614. if (!defined(result)) {
  14615. return new Plane(normal, distance);
  14616. } else {
  14617. Cartesian3.clone(normal, result.normal);
  14618. result.distance = distance;
  14619. return result;
  14620. }
  14621. };
  14622. /**
  14623. * Computes the signed shortest distance of a point to a plane.
  14624. * The sign of the distance determines which side of the plane the point
  14625. * is on. If the distance is positive, the point is in the half-space
  14626. * in the direction of the normal; if negative, the point is in the half-space
  14627. * opposite to the normal; if zero, the plane passes through the point.
  14628. *
  14629. * @param {Plane} plane The plane.
  14630. * @param {Cartesian3} point The point.
  14631. * @returns {Number} The signed shortest distance of the point to the plane.
  14632. */
  14633. Plane.getPointDistance = function(plane, point) {
  14634. if (!defined(plane)) {
  14635. throw new DeveloperError('plane is required.');
  14636. }
  14637. if (!defined(point)) {
  14638. throw new DeveloperError('point is required.');
  14639. }
  14640. return Cartesian3.dot(plane.normal, point) + plane.distance;
  14641. };
  14642. /**
  14643. * A constant initialized to the XY plane passing through the origin, with normal in positive Z.
  14644. *
  14645. * @type {Plane}
  14646. * @constant
  14647. */
  14648. Plane.ORIGIN_XY_PLANE = freezeObject(new Plane(Cartesian3.UNIT_Z, 0.0));
  14649. /**
  14650. * A constant initialized to the YZ plane passing through the origin, with normal in positive X.
  14651. *
  14652. * @type {Plane}
  14653. * @constant
  14654. */
  14655. Plane.ORIGIN_YZ_PLANE = freezeObject(new Plane(Cartesian3.UNIT_X, 0.0));
  14656. /**
  14657. * A constant initialized to the ZX plane passing through the origin, with normal in positive Y.
  14658. *
  14659. * @type {Plane}
  14660. * @constant
  14661. */
  14662. Plane.ORIGIN_ZX_PLANE = freezeObject(new Plane(Cartesian3.UNIT_Y, 0.0));
  14663. return Plane;
  14664. });
  14665. /**
  14666. @license
  14667. when.js - https://github.com/cujojs/when
  14668. MIT License (c) copyright B Cavalier & J Hann
  14669. * A lightweight CommonJS Promises/A and when() implementation
  14670. * when is part of the cujo.js family of libraries (http://cujojs.com/)
  14671. *
  14672. * Licensed under the MIT License at:
  14673. * http://www.opensource.org/licenses/mit-license.php
  14674. *
  14675. * @version 1.7.1
  14676. */
  14677. (function(define) { 'use strict';
  14678. define('ThirdParty/when',[],function () {
  14679. var reduceArray, slice, undef;
  14680. //
  14681. // Public API
  14682. //
  14683. when.defer = defer; // Create a deferred
  14684. when.resolve = resolve; // Create a resolved promise
  14685. when.reject = reject; // Create a rejected promise
  14686. when.join = join; // Join 2 or more promises
  14687. when.all = all; // Resolve a list of promises
  14688. when.map = map; // Array.map() for promises
  14689. when.reduce = reduce; // Array.reduce() for promises
  14690. when.any = any; // One-winner race
  14691. when.some = some; // Multi-winner race
  14692. when.chain = chain; // Make a promise trigger another resolver
  14693. when.isPromise = isPromise; // Determine if a thing is a promise
  14694. /**
  14695. * Register an observer for a promise or immediate value.
  14696. *
  14697. * @param {*} promiseOrValue
  14698. * @param {function?} [onFulfilled] callback to be called when promiseOrValue is
  14699. * successfully fulfilled. If promiseOrValue is an immediate value, callback
  14700. * will be invoked immediately.
  14701. * @param {function?} [onRejected] callback to be called when promiseOrValue is
  14702. * rejected.
  14703. * @param {function?} [onProgress] callback to be called when progress updates
  14704. * are issued for promiseOrValue.
  14705. * @returns {Promise} a new {@link Promise} that will complete with the return
  14706. * value of callback or errback or the completion value of promiseOrValue if
  14707. * callback and/or errback is not supplied.
  14708. */
  14709. function when(promiseOrValue, onFulfilled, onRejected, onProgress) {
  14710. // Get a trusted promise for the input promiseOrValue, and then
  14711. // register promise handlers
  14712. return resolve(promiseOrValue).then(onFulfilled, onRejected, onProgress);
  14713. }
  14714. /**
  14715. * Returns promiseOrValue if promiseOrValue is a {@link Promise}, a new Promise if
  14716. * promiseOrValue is a foreign promise, or a new, already-fulfilled {@link Promise}
  14717. * whose value is promiseOrValue if promiseOrValue is an immediate value.
  14718. *
  14719. * @param {*} promiseOrValue
  14720. * @returns Guaranteed to return a trusted Promise. If promiseOrValue is a when.js {@link Promise}
  14721. * returns promiseOrValue, otherwise, returns a new, already-resolved, when.js {@link Promise}
  14722. * whose resolution value is:
  14723. * * the resolution value of promiseOrValue if it's a foreign promise, or
  14724. * * promiseOrValue if it's a value
  14725. */
  14726. function resolve(promiseOrValue) {
  14727. var promise, deferred;
  14728. if(promiseOrValue instanceof Promise) {
  14729. // It's a when.js promise, so we trust it
  14730. promise = promiseOrValue;
  14731. } else {
  14732. // It's not a when.js promise. See if it's a foreign promise or a value.
  14733. if(isPromise(promiseOrValue)) {
  14734. // It's a thenable, but we don't know where it came from, so don't trust
  14735. // its implementation entirely. Introduce a trusted middleman when.js promise
  14736. deferred = defer();
  14737. // IMPORTANT: This is the only place when.js should ever call .then() on an
  14738. // untrusted promise. Don't expose the return value to the untrusted promise
  14739. promiseOrValue.then(
  14740. function(value) { deferred.resolve(value); },
  14741. function(reason) { deferred.reject(reason); },
  14742. function(update) { deferred.progress(update); }
  14743. );
  14744. promise = deferred.promise;
  14745. } else {
  14746. // It's a value, not a promise. Create a resolved promise for it.
  14747. promise = fulfilled(promiseOrValue);
  14748. }
  14749. }
  14750. return promise;
  14751. }
  14752. /**
  14753. * Returns a rejected promise for the supplied promiseOrValue. The returned
  14754. * promise will be rejected with:
  14755. * - promiseOrValue, if it is a value, or
  14756. * - if promiseOrValue is a promise
  14757. * - promiseOrValue's value after it is fulfilled
  14758. * - promiseOrValue's reason after it is rejected
  14759. * @param {*} promiseOrValue the rejected value of the returned {@link Promise}
  14760. * @returns {Promise} rejected {@link Promise}
  14761. */
  14762. function reject(promiseOrValue) {
  14763. return when(promiseOrValue, rejected);
  14764. }
  14765. /**
  14766. * Trusted Promise constructor. A Promise created from this constructor is
  14767. * a trusted when.js promise. Any other duck-typed promise is considered
  14768. * untrusted.
  14769. * @constructor
  14770. * @name Promise
  14771. */
  14772. function Promise(then) {
  14773. this.then = then;
  14774. }
  14775. Promise.prototype = {
  14776. /**
  14777. * Register a callback that will be called when a promise is
  14778. * fulfilled or rejected. Optionally also register a progress handler.
  14779. * Shortcut for .then(onFulfilledOrRejected, onFulfilledOrRejected, onProgress)
  14780. * @param {function?} [onFulfilledOrRejected]
  14781. * @param {function?} [onProgress]
  14782. * @returns {Promise}
  14783. */
  14784. always: function(onFulfilledOrRejected, onProgress) {
  14785. return this.then(onFulfilledOrRejected, onFulfilledOrRejected, onProgress);
  14786. },
  14787. /**
  14788. * Register a rejection handler. Shortcut for .then(undefined, onRejected)
  14789. * @param {function?} onRejected
  14790. * @returns {Promise}
  14791. */
  14792. otherwise: function(onRejected) {
  14793. return this.then(undef, onRejected);
  14794. },
  14795. /**
  14796. * Shortcut for .then(function() { return value; })
  14797. * @param {*} value
  14798. * @returns {Promise} a promise that:
  14799. * - is fulfilled if value is not a promise, or
  14800. * - if value is a promise, will fulfill with its value, or reject
  14801. * with its reason.
  14802. */
  14803. yield: function(value) {
  14804. return this.then(function() {
  14805. return value;
  14806. });
  14807. },
  14808. /**
  14809. * Assumes that this promise will fulfill with an array, and arranges
  14810. * for the onFulfilled to be called with the array as its argument list
  14811. * i.e. onFulfilled.spread(undefined, array).
  14812. * @param {function} onFulfilled function to receive spread arguments
  14813. * @returns {Promise}
  14814. */
  14815. spread: function(onFulfilled) {
  14816. return this.then(function(array) {
  14817. // array may contain promises, so resolve its contents.
  14818. return all(array, function(array) {
  14819. return onFulfilled.apply(undef, array);
  14820. });
  14821. });
  14822. }
  14823. };
  14824. /**
  14825. * Create an already-resolved promise for the supplied value
  14826. * @private
  14827. *
  14828. * @param {*} value
  14829. * @returns {Promise} fulfilled promise
  14830. */
  14831. function fulfilled(value) {
  14832. var p = new Promise(function(onFulfilled) {
  14833. // TODO: Promises/A+ check typeof onFulfilled
  14834. try {
  14835. return resolve(onFulfilled ? onFulfilled(value) : value);
  14836. } catch(e) {
  14837. return rejected(e);
  14838. }
  14839. });
  14840. return p;
  14841. }
  14842. /**
  14843. * Create an already-rejected {@link Promise} with the supplied
  14844. * rejection reason.
  14845. * @private
  14846. *
  14847. * @param {*} reason
  14848. * @returns {Promise} rejected promise
  14849. */
  14850. function rejected(reason) {
  14851. var p = new Promise(function(_, onRejected) {
  14852. // TODO: Promises/A+ check typeof onRejected
  14853. try {
  14854. return onRejected ? resolve(onRejected(reason)) : rejected(reason);
  14855. } catch(e) {
  14856. return rejected(e);
  14857. }
  14858. });
  14859. return p;
  14860. }
  14861. /**
  14862. * Creates a new, Deferred with fully isolated resolver and promise parts,
  14863. * either or both of which may be given out safely to consumers.
  14864. * The Deferred itself has the full API: resolve, reject, progress, and
  14865. * then. The resolver has resolve, reject, and progress. The promise
  14866. * only has then.
  14867. *
  14868. * @returns {Deferred}
  14869. */
  14870. function defer() {
  14871. var deferred, promise, handlers, progressHandlers,
  14872. _then, _progress, _resolve;
  14873. /**
  14874. * The promise for the new deferred
  14875. * @type {Promise}
  14876. */
  14877. promise = new Promise(then);
  14878. /**
  14879. * The full Deferred object, with {@link Promise} and {@link Resolver} parts
  14880. * @class Deferred
  14881. * @name Deferred
  14882. */
  14883. deferred = {
  14884. then: then, // DEPRECATED: use deferred.promise.then
  14885. resolve: promiseResolve,
  14886. reject: promiseReject,
  14887. // TODO: Consider renaming progress() to notify()
  14888. progress: promiseProgress,
  14889. promise: promise,
  14890. resolver: {
  14891. resolve: promiseResolve,
  14892. reject: promiseReject,
  14893. progress: promiseProgress
  14894. }
  14895. };
  14896. handlers = [];
  14897. progressHandlers = [];
  14898. /**
  14899. * Pre-resolution then() that adds the supplied callback, errback, and progback
  14900. * functions to the registered listeners
  14901. * @private
  14902. *
  14903. * @param {function?} [onFulfilled] resolution handler
  14904. * @param {function?} [onRejected] rejection handler
  14905. * @param {function?} [onProgress] progress handler
  14906. */
  14907. _then = function(onFulfilled, onRejected, onProgress) {
  14908. // TODO: Promises/A+ check typeof onFulfilled, onRejected, onProgress
  14909. var deferred, progressHandler;
  14910. deferred = defer();
  14911. progressHandler = typeof onProgress === 'function'
  14912. ? function(update) {
  14913. try {
  14914. // Allow progress handler to transform progress event
  14915. deferred.progress(onProgress(update));
  14916. } catch(e) {
  14917. // Use caught value as progress
  14918. deferred.progress(e);
  14919. }
  14920. }
  14921. : function(update) { deferred.progress(update); };
  14922. handlers.push(function(promise) {
  14923. promise.then(onFulfilled, onRejected)
  14924. .then(deferred.resolve, deferred.reject, progressHandler);
  14925. });
  14926. progressHandlers.push(progressHandler);
  14927. return deferred.promise;
  14928. };
  14929. /**
  14930. * Issue a progress event, notifying all progress listeners
  14931. * @private
  14932. * @param {*} update progress event payload to pass to all listeners
  14933. */
  14934. _progress = function(update) {
  14935. processQueue(progressHandlers, update);
  14936. return update;
  14937. };
  14938. /**
  14939. * Transition from pre-resolution state to post-resolution state, notifying
  14940. * all listeners of the resolution or rejection
  14941. * @private
  14942. * @param {*} value the value of this deferred
  14943. */
  14944. _resolve = function(value) {
  14945. value = resolve(value);
  14946. // Replace _then with one that directly notifies with the result.
  14947. _then = value.then;
  14948. // Replace _resolve so that this Deferred can only be resolved once
  14949. _resolve = resolve;
  14950. // Make _progress a noop, to disallow progress for the resolved promise.
  14951. _progress = noop;
  14952. // Notify handlers
  14953. processQueue(handlers, value);
  14954. // Free progressHandlers array since we'll never issue progress events
  14955. progressHandlers = handlers = undef;
  14956. return value;
  14957. };
  14958. return deferred;
  14959. /**
  14960. * Wrapper to allow _then to be replaced safely
  14961. * @param {function?} [onFulfilled] resolution handler
  14962. * @param {function?} [onRejected] rejection handler
  14963. * @param {function?} [onProgress] progress handler
  14964. * @returns {Promise} new promise
  14965. */
  14966. function then(onFulfilled, onRejected, onProgress) {
  14967. // TODO: Promises/A+ check typeof onFulfilled, onRejected, onProgress
  14968. return _then(onFulfilled, onRejected, onProgress);
  14969. }
  14970. /**
  14971. * Wrapper to allow _resolve to be replaced
  14972. */
  14973. function promiseResolve(val) {
  14974. return _resolve(val);
  14975. }
  14976. /**
  14977. * Wrapper to allow _reject to be replaced
  14978. */
  14979. function promiseReject(err) {
  14980. return _resolve(rejected(err));
  14981. }
  14982. /**
  14983. * Wrapper to allow _progress to be replaced
  14984. */
  14985. function promiseProgress(update) {
  14986. return _progress(update);
  14987. }
  14988. }
  14989. /**
  14990. * Determines if promiseOrValue is a promise or not. Uses the feature
  14991. * test from http://wiki.commonjs.org/wiki/Promises/A to determine if
  14992. * promiseOrValue is a promise.
  14993. *
  14994. * @param {*} promiseOrValue anything
  14995. * @returns {boolean} true if promiseOrValue is a {@link Promise}
  14996. */
  14997. function isPromise(promiseOrValue) {
  14998. return promiseOrValue && typeof promiseOrValue.then === 'function';
  14999. }
  15000. /**
  15001. * Initiates a competitive race, returning a promise that will resolve when
  15002. * howMany of the supplied promisesOrValues have resolved, or will reject when
  15003. * it becomes impossible for howMany to resolve, for example, when
  15004. * (promisesOrValues.length - howMany) + 1 input promises reject.
  15005. *
  15006. * @param {Array} promisesOrValues array of anything, may contain a mix
  15007. * of promises and values
  15008. * @param howMany {number} number of promisesOrValues to resolve
  15009. * @param {function?} [onFulfilled] resolution handler
  15010. * @param {function?} [onRejected] rejection handler
  15011. * @param {function?} [onProgress] progress handler
  15012. * @returns {Promise} promise that will resolve to an array of howMany values that
  15013. * resolved first, or will reject with an array of (promisesOrValues.length - howMany) + 1
  15014. * rejection reasons.
  15015. */
  15016. function some(promisesOrValues, howMany, onFulfilled, onRejected, onProgress) {
  15017. checkCallbacks(2, arguments);
  15018. return when(promisesOrValues, function(promisesOrValues) {
  15019. var toResolve, toReject, values, reasons, deferred, fulfillOne, rejectOne, progress, len, i;
  15020. len = promisesOrValues.length >>> 0;
  15021. toResolve = Math.max(0, Math.min(howMany, len));
  15022. values = [];
  15023. toReject = (len - toResolve) + 1;
  15024. reasons = [];
  15025. deferred = defer();
  15026. // No items in the input, resolve immediately
  15027. if (!toResolve) {
  15028. deferred.resolve(values);
  15029. } else {
  15030. progress = deferred.progress;
  15031. rejectOne = function(reason) {
  15032. reasons.push(reason);
  15033. if(!--toReject) {
  15034. fulfillOne = rejectOne = noop;
  15035. deferred.reject(reasons);
  15036. }
  15037. };
  15038. fulfillOne = function(val) {
  15039. // This orders the values based on promise resolution order
  15040. // Another strategy would be to use the original position of
  15041. // the corresponding promise.
  15042. values.push(val);
  15043. if (!--toResolve) {
  15044. fulfillOne = rejectOne = noop;
  15045. deferred.resolve(values);
  15046. }
  15047. };
  15048. for(i = 0; i < len; ++i) {
  15049. if(i in promisesOrValues) {
  15050. when(promisesOrValues[i], fulfiller, rejecter, progress);
  15051. }
  15052. }
  15053. }
  15054. return deferred.then(onFulfilled, onRejected, onProgress);
  15055. function rejecter(reason) {
  15056. rejectOne(reason);
  15057. }
  15058. function fulfiller(val) {
  15059. fulfillOne(val);
  15060. }
  15061. });
  15062. }
  15063. /**
  15064. * Initiates a competitive race, returning a promise that will resolve when
  15065. * any one of the supplied promisesOrValues has resolved or will reject when
  15066. * *all* promisesOrValues have rejected.
  15067. *
  15068. * @param {Array|Promise} promisesOrValues array of anything, may contain a mix
  15069. * of {@link Promise}s and values
  15070. * @param {function?} [onFulfilled] resolution handler
  15071. * @param {function?} [onRejected] rejection handler
  15072. * @param {function?} [onProgress] progress handler
  15073. * @returns {Promise} promise that will resolve to the value that resolved first, or
  15074. * will reject with an array of all rejected inputs.
  15075. */
  15076. function any(promisesOrValues, onFulfilled, onRejected, onProgress) {
  15077. function unwrapSingleResult(val) {
  15078. return onFulfilled ? onFulfilled(val[0]) : val[0];
  15079. }
  15080. return some(promisesOrValues, 1, unwrapSingleResult, onRejected, onProgress);
  15081. }
  15082. /**
  15083. * Return a promise that will resolve only once all the supplied promisesOrValues
  15084. * have resolved. The resolution value of the returned promise will be an array
  15085. * containing the resolution values of each of the promisesOrValues.
  15086. * @memberOf when
  15087. *
  15088. * @param {Array|Promise} promisesOrValues array of anything, may contain a mix
  15089. * of {@link Promise}s and values
  15090. * @param {function?} [onFulfilled] resolution handler
  15091. * @param {function?} [onRejected] rejection handler
  15092. * @param {function?} [onProgress] progress handler
  15093. * @returns {Promise}
  15094. */
  15095. function all(promisesOrValues, onFulfilled, onRejected, onProgress) {
  15096. checkCallbacks(1, arguments);
  15097. return map(promisesOrValues, identity).then(onFulfilled, onRejected, onProgress);
  15098. }
  15099. /**
  15100. * Joins multiple promises into a single returned promise.
  15101. * @returns {Promise} a promise that will fulfill when *all* the input promises
  15102. * have fulfilled, or will reject when *any one* of the input promises rejects.
  15103. */
  15104. function join(/* ...promises */) {
  15105. return map(arguments, identity);
  15106. }
  15107. /**
  15108. * Traditional map function, similar to `Array.prototype.map()`, but allows
  15109. * input to contain {@link Promise}s and/or values, and mapFunc may return
  15110. * either a value or a {@link Promise}
  15111. *
  15112. * @param {Array|Promise} promise array of anything, may contain a mix
  15113. * of {@link Promise}s and values
  15114. * @param {function} mapFunc mapping function mapFunc(value) which may return
  15115. * either a {@link Promise} or value
  15116. * @returns {Promise} a {@link Promise} that will resolve to an array containing
  15117. * the mapped output values.
  15118. */
  15119. function map(promise, mapFunc) {
  15120. return when(promise, function(array) {
  15121. var results, len, toResolve, resolve, i, d;
  15122. // Since we know the resulting length, we can preallocate the results
  15123. // array to avoid array expansions.
  15124. toResolve = len = array.length >>> 0;
  15125. results = [];
  15126. d = defer();
  15127. if(!toResolve) {
  15128. d.resolve(results);
  15129. } else {
  15130. resolve = function resolveOne(item, i) {
  15131. when(item, mapFunc).then(function(mapped) {
  15132. results[i] = mapped;
  15133. if(!--toResolve) {
  15134. d.resolve(results);
  15135. }
  15136. }, d.reject);
  15137. };
  15138. // Since mapFunc may be async, get all invocations of it into flight
  15139. for(i = 0; i < len; i++) {
  15140. if(i in array) {
  15141. resolve(array[i], i);
  15142. } else {
  15143. --toResolve;
  15144. }
  15145. }
  15146. }
  15147. return d.promise;
  15148. });
  15149. }
  15150. /**
  15151. * Traditional reduce function, similar to `Array.prototype.reduce()`, but
  15152. * input may contain promises and/or values, and reduceFunc
  15153. * may return either a value or a promise, *and* initialValue may
  15154. * be a promise for the starting value.
  15155. *
  15156. * @param {Array|Promise} promise array or promise for an array of anything,
  15157. * may contain a mix of promises and values.
  15158. * @param {function} reduceFunc reduce function reduce(currentValue, nextValue, index, total),
  15159. * where total is the total number of items being reduced, and will be the same
  15160. * in each call to reduceFunc.
  15161. * @returns {Promise} that will resolve to the final reduced value
  15162. */
  15163. function reduce(promise, reduceFunc /*, initialValue */) {
  15164. var args = slice.call(arguments, 1);
  15165. return when(promise, function(array) {
  15166. var total;
  15167. total = array.length;
  15168. // Wrap the supplied reduceFunc with one that handles promises and then
  15169. // delegates to the supplied.
  15170. args[0] = function (current, val, i) {
  15171. return when(current, function (c) {
  15172. return when(val, function (value) {
  15173. return reduceFunc(c, value, i, total);
  15174. });
  15175. });
  15176. };
  15177. return reduceArray.apply(array, args);
  15178. });
  15179. }
  15180. /**
  15181. * Ensure that resolution of promiseOrValue will trigger resolver with the
  15182. * value or reason of promiseOrValue, or instead with resolveValue if it is provided.
  15183. *
  15184. * @param promiseOrValue
  15185. * @param {Object} resolver
  15186. * @param {function} resolver.resolve
  15187. * @param {function} resolver.reject
  15188. * @param {*} [resolveValue]
  15189. * @returns {Promise}
  15190. */
  15191. function chain(promiseOrValue, resolver, resolveValue) {
  15192. var useResolveValue = arguments.length > 2;
  15193. return when(promiseOrValue,
  15194. function(val) {
  15195. val = useResolveValue ? resolveValue : val;
  15196. resolver.resolve(val);
  15197. return val;
  15198. },
  15199. function(reason) {
  15200. resolver.reject(reason);
  15201. return rejected(reason);
  15202. },
  15203. resolver.progress
  15204. );
  15205. }
  15206. //
  15207. // Utility functions
  15208. //
  15209. /**
  15210. * Apply all functions in queue to value
  15211. * @param {Array} queue array of functions to execute
  15212. * @param {*} value argument passed to each function
  15213. */
  15214. function processQueue(queue, value) {
  15215. var handler, i = 0;
  15216. while (handler = queue[i++]) {
  15217. handler(value);
  15218. }
  15219. }
  15220. /**
  15221. * Helper that checks arrayOfCallbacks to ensure that each element is either
  15222. * a function, or null or undefined.
  15223. * @private
  15224. * @param {number} start index at which to start checking items in arrayOfCallbacks
  15225. * @param {Array} arrayOfCallbacks array to check
  15226. * @throws {Error} if any element of arrayOfCallbacks is something other than
  15227. * a functions, null, or undefined.
  15228. */
  15229. function checkCallbacks(start, arrayOfCallbacks) {
  15230. // TODO: Promises/A+ update type checking and docs
  15231. var arg, i = arrayOfCallbacks.length;
  15232. while(i > start) {
  15233. arg = arrayOfCallbacks[--i];
  15234. if (arg != null && typeof arg != 'function') {
  15235. throw new Error('arg '+i+' must be a function');
  15236. }
  15237. }
  15238. }
  15239. /**
  15240. * No-Op function used in method replacement
  15241. * @private
  15242. */
  15243. function noop() {}
  15244. slice = [].slice;
  15245. // ES5 reduce implementation if native not available
  15246. // See: http://es5.github.com/#x15.4.4.21 as there are many
  15247. // specifics and edge cases.
  15248. reduceArray = [].reduce ||
  15249. function(reduceFunc /*, initialValue */) {
  15250. /*jshint maxcomplexity: 7*/
  15251. // ES5 dictates that reduce.length === 1
  15252. // This implementation deviates from ES5 spec in the following ways:
  15253. // 1. It does not check if reduceFunc is a Callable
  15254. var arr, args, reduced, len, i;
  15255. i = 0;
  15256. // This generates a jshint warning, despite being valid
  15257. // "Missing 'new' prefix when invoking a constructor."
  15258. // See https://github.com/jshint/jshint/issues/392
  15259. arr = Object(this);
  15260. len = arr.length >>> 0;
  15261. args = arguments;
  15262. // If no initialValue, use first item of array (we know length !== 0 here)
  15263. // and adjust i to start at second item
  15264. if(args.length <= 1) {
  15265. // Skip to the first real element in the array
  15266. for(;;) {
  15267. if(i in arr) {
  15268. reduced = arr[i++];
  15269. break;
  15270. }
  15271. // If we reached the end of the array without finding any real
  15272. // elements, it's a TypeError
  15273. if(++i >= len) {
  15274. throw new TypeError();
  15275. }
  15276. }
  15277. } else {
  15278. // If initialValue provided, use it
  15279. reduced = args[1];
  15280. }
  15281. // Do the actual reduce
  15282. for(;i < len; ++i) {
  15283. // Skip holes
  15284. if(i in arr) {
  15285. reduced = reduceFunc(reduced, arr[i], i, arr);
  15286. }
  15287. }
  15288. return reduced;
  15289. };
  15290. function identity(x) {
  15291. return x;
  15292. }
  15293. return when;
  15294. });
  15295. })(typeof define == 'function' && define.amd
  15296. ? define
  15297. : function (factory) { typeof exports === 'object'
  15298. ? (module.exports = factory())
  15299. : (this.when = factory());
  15300. }
  15301. // Boilerplate for AMD, Node, and browser global
  15302. );
  15303. /*global define*/
  15304. define('Core/oneTimeWarning',[
  15305. './defaultValue',
  15306. './defined',
  15307. './DeveloperError'
  15308. ], function(
  15309. defaultValue,
  15310. defined,
  15311. DeveloperError) {
  15312. "use strict";
  15313. var warnings = {};
  15314. /**
  15315. * Logs a one time message to the console. Use this function instead of
  15316. * <code>console.log</code> directly since this does not log duplicate messages
  15317. * unless it is called from multiple workers.
  15318. *
  15319. * @exports oneTimeWarning
  15320. *
  15321. * @param {String} identifier The unique identifier for this warning.
  15322. * @param {String} [message=identifier] The message to log to the console.
  15323. *
  15324. * @example
  15325. * for(var i=0;i<foo.length;++i) {
  15326. * if (!defined(foo[i].bar)) {
  15327. * // Something that can be recovered from but may happen a lot
  15328. * oneTimeWarning('foo.bar undefined', 'foo.bar is undefined. Setting to 0.');
  15329. * foo[i].bar = 0;
  15330. * // ...
  15331. * }
  15332. * }
  15333. *
  15334. * @private
  15335. */
  15336. function oneTimeWarning(identifier, message) {
  15337. if (!defined(identifier)) {
  15338. throw new DeveloperError('identifier is required.');
  15339. }
  15340. if (!defined(warnings[identifier])) {
  15341. warnings[identifier] = true;
  15342. console.log(defaultValue(message, identifier));
  15343. }
  15344. }
  15345. oneTimeWarning.geometryOutlines = 'Entity geometry outlines are unsupported on terrain. Outlines will be disabled. To enable outlines, disable geometry terrain clamping by explicitly setting height to 0.';
  15346. return oneTimeWarning;
  15347. });
  15348. /*global define*/
  15349. define('Core/deprecationWarning',[
  15350. './defined',
  15351. './DeveloperError',
  15352. './oneTimeWarning'
  15353. ], function(
  15354. defined,
  15355. DeveloperError,
  15356. oneTimeWarning) {
  15357. 'use strict';
  15358. /**
  15359. * Logs a deprecation message to the console. Use this function instead of
  15360. * <code>console.log</code> directly since this does not log duplicate messages
  15361. * unless it is called from multiple workers.
  15362. *
  15363. * @exports deprecationWarning
  15364. *
  15365. * @param {String} identifier The unique identifier for this deprecated API.
  15366. * @param {String} message The message to log to the console.
  15367. *
  15368. * @example
  15369. * // Deprecated function or class
  15370. * function Foo() {
  15371. * deprecationWarning('Foo', 'Foo was deprecated in Cesium 1.01. It will be removed in 1.03. Use newFoo instead.');
  15372. * // ...
  15373. * }
  15374. *
  15375. * // Deprecated function
  15376. * Bar.prototype.func = function() {
  15377. * deprecationWarning('Bar.func', 'Bar.func() was deprecated in Cesium 1.01. It will be removed in 1.03. Use Bar.newFunc() instead.');
  15378. * // ...
  15379. * };
  15380. *
  15381. * // Deprecated property
  15382. * defineProperties(Bar.prototype, {
  15383. * prop : {
  15384. * get : function() {
  15385. * deprecationWarning('Bar.prop', 'Bar.prop was deprecated in Cesium 1.01. It will be removed in 1.03. Use Bar.newProp instead.');
  15386. * // ...
  15387. * },
  15388. * set : function(value) {
  15389. * deprecationWarning('Bar.prop', 'Bar.prop was deprecated in Cesium 1.01. It will be removed in 1.03. Use Bar.newProp instead.');
  15390. * // ...
  15391. * }
  15392. * }
  15393. * });
  15394. *
  15395. * @private
  15396. */
  15397. function deprecationWarning(identifier, message) {
  15398. if (!defined(identifier) || !defined(message)) {
  15399. throw new DeveloperError('identifier and message are required.');
  15400. }
  15401. oneTimeWarning(identifier, message);
  15402. }
  15403. return deprecationWarning;
  15404. });
  15405. /*global define*/
  15406. define('Core/binarySearch',[
  15407. './defined',
  15408. './DeveloperError'
  15409. ], function(
  15410. defined,
  15411. DeveloperError) {
  15412. 'use strict';
  15413. /**
  15414. * Finds an item in a sorted array.
  15415. *
  15416. * @exports binarySearch
  15417. *
  15418. * @param {Array} array The sorted array to search.
  15419. * @param {Object} itemToFind The item to find in the array.
  15420. * @param {binarySearch~Comparator} comparator The function to use to compare the item to
  15421. * elements in the array.
  15422. * @returns {Number} The index of <code>itemToFind</code> in the array, if it exists. If <code>itemToFind</code>
  15423. * does not exist, the return value is a negative number which is the bitwise complement (~)
  15424. * of the index before which the itemToFind should be inserted in order to maintain the
  15425. * sorted order of the array.
  15426. *
  15427. * @example
  15428. * // Create a comparator function to search through an array of numbers.
  15429. * function comparator(a, b) {
  15430. * return a - b;
  15431. * };
  15432. * var numbers = [0, 2, 4, 6, 8];
  15433. * var index = Cesium.binarySearch(numbers, 6, comparator); // 3
  15434. */
  15435. function binarySearch(array, itemToFind, comparator) {
  15436. if (!defined(array)) {
  15437. throw new DeveloperError('array is required.');
  15438. }
  15439. if (!defined(itemToFind)) {
  15440. throw new DeveloperError('itemToFind is required.');
  15441. }
  15442. if (!defined(comparator)) {
  15443. throw new DeveloperError('comparator is required.');
  15444. }
  15445. var low = 0;
  15446. var high = array.length - 1;
  15447. var i;
  15448. var comparison;
  15449. while (low <= high) {
  15450. i = ~~((low + high) / 2);
  15451. comparison = comparator(array[i], itemToFind);
  15452. if (comparison < 0) {
  15453. low = i + 1;
  15454. continue;
  15455. }
  15456. if (comparison > 0) {
  15457. high = i - 1;
  15458. continue;
  15459. }
  15460. return i;
  15461. }
  15462. return ~(high + 1);
  15463. }
  15464. /**
  15465. * A function used to compare two items while performing a binary search.
  15466. * @callback binarySearch~Comparator
  15467. *
  15468. * @param {Object} a An item in the array.
  15469. * @param {Object} b The item being searched for.
  15470. * @returns {Number} Returns a negative value if <code>a</code> is less than <code>b</code>,
  15471. * a positive value if <code>a</code> is greater than <code>b</code>, or
  15472. * 0 if <code>a</code> is equal to <code>b</code>.
  15473. *
  15474. * @example
  15475. * function compareNumbers(a, b) {
  15476. * return a - b;
  15477. * }
  15478. */
  15479. return binarySearch;
  15480. });
  15481. /*global define*/
  15482. define('Core/EarthOrientationParametersSample',[],function() {
  15483. 'use strict';
  15484. /**
  15485. * A set of Earth Orientation Parameters (EOP) sampled at a time.
  15486. *
  15487. * @alias EarthOrientationParametersSample
  15488. * @constructor
  15489. *
  15490. * @param {Number} xPoleWander The pole wander about the X axis, in radians.
  15491. * @param {Number} yPoleWander The pole wander about the Y axis, in radians.
  15492. * @param {Number} xPoleOffset The offset to the Celestial Intermediate Pole (CIP) about the X axis, in radians.
  15493. * @param {Number} yPoleOffset The offset to the Celestial Intermediate Pole (CIP) about the Y axis, in radians.
  15494. * @param {Number} ut1MinusUtc The difference in time standards, UT1 - UTC, in seconds.
  15495. *
  15496. * @private
  15497. */
  15498. function EarthOrientationParametersSample(xPoleWander, yPoleWander, xPoleOffset, yPoleOffset, ut1MinusUtc) {
  15499. /**
  15500. * The pole wander about the X axis, in radians.
  15501. * @type {Number}
  15502. */
  15503. this.xPoleWander = xPoleWander;
  15504. /**
  15505. * The pole wander about the Y axis, in radians.
  15506. * @type {Number}
  15507. */
  15508. this.yPoleWander = yPoleWander;
  15509. /**
  15510. * The offset to the Celestial Intermediate Pole (CIP) about the X axis, in radians.
  15511. * @type {Number}
  15512. */
  15513. this.xPoleOffset = xPoleOffset;
  15514. /**
  15515. * The offset to the Celestial Intermediate Pole (CIP) about the Y axis, in radians.
  15516. * @type {Number}
  15517. */
  15518. this.yPoleOffset = yPoleOffset;
  15519. /**
  15520. * The difference in time standards, UT1 - UTC, in seconds.
  15521. * @type {Number}
  15522. */
  15523. this.ut1MinusUtc = ut1MinusUtc;
  15524. }
  15525. return EarthOrientationParametersSample;
  15526. });
  15527. /**
  15528. @license
  15529. sprintf.js from the php.js project - https://github.com/kvz/phpjs
  15530. Directly from https://github.com/kvz/phpjs/blob/master/functions/strings/sprintf.js
  15531. php.js is copyright 2012 Kevin van Zonneveld.
  15532. Portions copyright Brett Zamir (http://brett-zamir.me), Kevin van Zonneveld
  15533. (http://kevin.vanzonneveld.net), Onno Marsman, Theriault, Michael White
  15534. (http://getsprink.com), Waldo Malqui Silva, Paulo Freitas, Jack, Jonas
  15535. Raoni Soares Silva (http://www.jsfromhell.com), Philip Peterson, Legaev
  15536. Andrey, Ates Goral (http://magnetiq.com), Alex, Ratheous, Martijn Wieringa,
  15537. Rafa? Kukawski (http://blog.kukawski.pl), lmeyrick
  15538. (https://sourceforge.net/projects/bcmath-js/), Nate, Philippe Baumann,
  15539. Enrique Gonzalez, Webtoolkit.info (http://www.webtoolkit.info/), Carlos R.
  15540. L. Rodrigues (http://www.jsfromhell.com), Ash Searle
  15541. (http://hexmen.com/blog/), Jani Hartikainen, travc, Ole Vrijenhoek,
  15542. Erkekjetter, Michael Grier, Rafa? Kukawski (http://kukawski.pl), Johnny
  15543. Mast (http://www.phpvrouwen.nl), T.Wild, d3x,
  15544. http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript,
  15545. Rafa? Kukawski (http://blog.kukawski.pl/), stag019, pilus, WebDevHobo
  15546. (http://webdevhobo.blogspot.com/), marrtins, GeekFG
  15547. (http://geekfg.blogspot.com), Andrea Giammarchi
  15548. (http://webreflection.blogspot.com), Arpad Ray (mailto:arpad@php.net),
  15549. gorthaur, Paul Smith, Tim de Koning (http://www.kingsquare.nl), Joris, Oleg
  15550. Eremeev, Steve Hilder, majak, gettimeofday, KELAN, Josh Fraser
  15551. (http://onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/),
  15552. Marc Palau, Martin
  15553. (http://www.erlenwiese.de/), Breaking Par Consulting Inc
  15554. (http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256CFB006C45F7),
  15555. Chris, Mirek Slugen, saulius, Alfonso Jimenez
  15556. (http://www.alfonsojimenez.com), Diplom@t (http://difane.com/), felix,
  15557. Mailfaker (http://www.weedem.fr/), Tyler Akins (http://rumkin.com), Caio
  15558. Ariede (http://caioariede.com), Robin, Kankrelune
  15559. (http://www.webfaktory.info/), Karol Kowalski, Imgen Tata
  15560. (http://www.myipdf.com/), mdsjack (http://www.mdsjack.bo.it), Dreamer,
  15561. Felix Geisendoerfer (http://www.debuggable.com/felix), Lars Fischer, AJ,
  15562. David, Aman Gupta, Michael White, Public Domain
  15563. (http://www.json.org/json2.js), Steven Levithan
  15564. (http://blog.stevenlevithan.com), Sakimori, Pellentesque Malesuada,
  15565. Thunder.m, Dj (http://phpjs.org/functions/htmlentities:425#comment_134018),
  15566. Steve Clay, David James, Francois, class_exists, nobbler, T. Wild, Itsacon
  15567. (http://www.itsacon.net/), date, Ole Vrijenhoek (http://www.nervous.nl/),
  15568. Fox, Raphael (Ao RUDLER), Marco, noname, Mateusz "loonquawl" Zalega, Frank
  15569. Forte, Arno, ger, mktime, john (http://www.jd-tech.net), Nick Kolosov
  15570. (http://sammy.ru), marc andreu, Scott Cariss, Douglas Crockford
  15571. (http://javascript.crockford.com), madipta, Slawomir Kaniecki,
  15572. ReverseSyntax, Nathan, Alex Wilson, kenneth, Bayron Guevara, Adam Wallner
  15573. (http://web2.bitbaro.hu/), paulo kuong, jmweb, Lincoln Ramsay, djmix,
  15574. Pyerre, Jon Hohle, Thiago Mata (http://thiagomata.blog.com), lmeyrick
  15575. (https://sourceforge.net/projects/bcmath-js/this.), Linuxworld, duncan,
  15576. Gilbert, Sanjoy Roy, Shingo, sankai, Oskar Larsson H?gfeldt
  15577. (http://oskar-lh.name/), Denny Wardhana, 0m3r, Everlasto, Subhasis Deb,
  15578. josh, jd, Pier Paolo Ramon (http://www.mastersoup.com/), P, merabi, Soren
  15579. Hansen, Eugene Bulkin (http://doubleaw.com/), Der Simon
  15580. (http://innerdom.sourceforge.net/), echo is bad, Ozh, XoraX
  15581. (http://www.xorax.info), EdorFaus, JB, J A R, Marc Jansen, Francesco, LH,
  15582. Stoyan Kyosev (http://www.svest.org/), nord_ua, omid
  15583. (http://phpjs.org/functions/380:380#comment_137122), Brad Touesnard, MeEtc
  15584. (http://yass.meetcweb.com), Peter-Paul Koch
  15585. (http://www.quirksmode.org/js/beat.html), Olivier Louvignes
  15586. (http://mg-crea.com/), T0bsn, Tim Wiel, Bryan Elliott, Jalal Berrami,
  15587. Martin, JT, David Randall, Thomas Beaucourt (http://www.webapp.fr), taith,
  15588. vlado houba, Pierre-Luc Paour, Kristof Coomans (SCK-CEN Belgian Nucleair
  15589. Research Centre), Martin Pool, Kirk Strobeck, Rick Waldron, Brant Messenger
  15590. (http://www.brantmessenger.com/), Devan Penner-Woelk, Saulo Vallory, Wagner
  15591. B. Soares, Artur Tchernychev, Valentina De Rosa, Jason Wong
  15592. (http://carrot.org/), Christoph, Daniel Esteban, strftime, Mick@el, rezna,
  15593. Simon Willison (http://simonwillison.net), Anton Ongson, Gabriel Paderni,
  15594. Marco van Oort, penutbutterjelly, Philipp Lenssen, Bjorn Roesbeke
  15595. (http://www.bjornroesbeke.be/), Bug?, Eric Nagel, Tomasz Wesolowski,
  15596. Evertjan Garretsen, Bobby Drake, Blues (http://tech.bluesmoon.info/), Luke
  15597. Godfrey, Pul, uestla, Alan C, Ulrich, Rafal Kukawski, Yves Sucaet,
  15598. sowberry, Norman "zEh" Fuchs, hitwork, Zahlii, johnrembo, Nick Callen,
  15599. Steven Levithan (stevenlevithan.com), ejsanders, Scott Baker, Brian Tafoya
  15600. (http://www.premasolutions.com/), Philippe Jausions
  15601. (http://pear.php.net/user/jausions), Aidan Lister
  15602. (http://aidanlister.com/), Rob, e-mike, HKM, ChaosNo1, metjay, strcasecmp,
  15603. strcmp, Taras Bogach, jpfle, Alexander Ermolaev
  15604. (http://snippets.dzone.com/user/AlexanderErmolaev), DxGx, kilops, Orlando,
  15605. dptr1988, Le Torbi, James (http://www.james-bell.co.uk/), Pedro Tainha
  15606. (http://www.pedrotainha.com), James, Arnout Kazemier
  15607. (http://www.3rd-Eden.com), Chris McMacken, gabriel paderni, Yannoo,
  15608. FGFEmperor, baris ozdil, Tod Gentille, Greg Frazier, jakes, 3D-GRAF, Allan
  15609. Jensen (http://www.winternet.no), Howard Yeend, Benjamin Lupton, davook,
  15610. daniel airton wermann (http://wermann.com.br), Atli T¨®r, Maximusya, Ryan
  15611. W Tenney (http://ryan.10e.us), Alexander M Beedie, fearphage
  15612. (http://http/my.opera.com/fearphage/), Nathan Sepulveda, Victor, Matteo,
  15613. Billy, stensi, Cord, Manish, T.J. Leahy, Riddler
  15614. (http://www.frontierwebdev.com/), Rafa? Kukawski, FremyCompany, Matt
  15615. Bradley, Tim de Koning, Luis Salazar (http://www.freaky-media.com/), Diogo
  15616. Resende, Rival, Andrej Pavlovic, Garagoth, Le Torbi
  15617. (http://www.letorbi.de/), Dino, Josep Sanz (http://www.ws3.es/), rem,
  15618. Russell Walker (http://www.nbill.co.uk/), Jamie Beck
  15619. (http://www.terabit.ca/), setcookie, Michael, YUI Library:
  15620. http://developer.yahoo.com/yui/docs/YAHOO.util.DateLocale.html, Blues at
  15621. http://hacks.bluesmoon.info/strftime/strftime.js, Ben
  15622. (http://benblume.co.uk/), DtTvB
  15623. (http://dt.in.th/2008-09-16.string-length-in-bytes.html), Andreas, William,
  15624. meo, incidence, Cagri Ekin, Amirouche, Amir Habibi
  15625. (http://www.residence-mixte.com/), Luke Smith (http://lucassmith.name),
  15626. Kheang Hok Chin (http://www.distantia.ca/), Jay Klehr, Lorenzo Pisani,
  15627. Tony, Yen-Wei Liu, Greenseed, mk.keck, Leslie Hoare, dude, booeyOH, Ben
  15628. Bryan
  15629. Licensed under the MIT (MIT-LICENSE.txt) license.
  15630. Permission is hereby granted, free of charge, to any person obtaining a
  15631. copy of this software and associated documentation files (the
  15632. "Software"), to deal in the Software without restriction, including
  15633. without limitation the rights to use, copy, modify, merge, publish,
  15634. distribute, sublicense, and/or sell copies of the Software, and to
  15635. permit persons to whom the Software is furnished to do so, subject to
  15636. the following conditions:
  15637. The above copyright notice and this permission notice shall be included
  15638. in all copies or substantial portions of the Software.
  15639. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15640. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15641. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  15642. IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES
  15643. OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  15644. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  15645. OTHER DEALINGS IN THE SOFTWARE.
  15646. */
  15647. /*global define*/
  15648. define('ThirdParty/sprintf',[],function() {
  15649. function sprintf () {
  15650. // http://kevin.vanzonneveld.net
  15651. // + original by: Ash Searle (http://hexmen.com/blog/)
  15652. // + namespaced by: Michael White (http://getsprink.com)
  15653. // + tweaked by: Jack
  15654. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  15655. // + input by: Paulo Freitas
  15656. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  15657. // + input by: Brett Zamir (http://brett-zamir.me)
  15658. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  15659. // + improved by: Dj
  15660. // + improved by: Allidylls
  15661. // * example 1: sprintf("%01.2f", 123.1);
  15662. // * returns 1: 123.10
  15663. // * example 2: sprintf("[%10s]", 'monkey');
  15664. // * returns 2: '[ monkey]'
  15665. // * example 3: sprintf("[%'#10s]", 'monkey');
  15666. // * returns 3: '[####monkey]'
  15667. // * example 4: sprintf("%d", 123456789012345);
  15668. // * returns 4: '123456789012345'
  15669. var regex = /%%|%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuideEfFgG])/g;
  15670. var a = arguments,
  15671. i = 0,
  15672. format = a[i++];
  15673. // pad()
  15674. var pad = function (str, len, chr, leftJustify) {
  15675. if (!chr) {
  15676. chr = ' ';
  15677. }
  15678. var padding = (str.length >= len) ? '' : Array(1 + len - str.length >>> 0).join(chr);
  15679. return leftJustify ? str + padding : padding + str;
  15680. };
  15681. // justify()
  15682. var justify = function (value, prefix, leftJustify, minWidth, zeroPad, customPadChar) {
  15683. var diff = minWidth - value.length;
  15684. if (diff > 0) {
  15685. if (leftJustify || !zeroPad) {
  15686. value = pad(value, minWidth, customPadChar, leftJustify);
  15687. } else {
  15688. value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length);
  15689. }
  15690. }
  15691. return value;
  15692. };
  15693. // formatBaseX()
  15694. var formatBaseX = function (value, base, prefix, leftJustify, minWidth, precision, zeroPad) {
  15695. // Note: casts negative numbers to positive ones
  15696. var number = value >>> 0;
  15697. prefix = prefix && number && {
  15698. '2': '0b',
  15699. '8': '0',
  15700. '16': '0x'
  15701. }[base] || '';
  15702. value = prefix + pad(number.toString(base), precision || 0, '0', false);
  15703. return justify(value, prefix, leftJustify, minWidth, zeroPad);
  15704. };
  15705. // formatString()
  15706. var formatString = function (value, leftJustify, minWidth, precision, zeroPad, customPadChar) {
  15707. if (precision != null) {
  15708. value = value.slice(0, precision);
  15709. }
  15710. return justify(value, '', leftJustify, minWidth, zeroPad, customPadChar);
  15711. };
  15712. // doFormat()
  15713. var doFormat = function (substring, valueIndex, flags, minWidth, _, precision, type) {
  15714. var number;
  15715. var prefix;
  15716. var method;
  15717. var textTransform;
  15718. var value;
  15719. if (substring == '%%') {
  15720. return '%';
  15721. }
  15722. // parse flags
  15723. var leftJustify = false,
  15724. positivePrefix = '',
  15725. zeroPad = false,
  15726. prefixBaseX = false,
  15727. customPadChar = ' ';
  15728. var flagsl = flags.length;
  15729. for (var j = 0; flags && j < flagsl; j++) {
  15730. switch (flags.charAt(j)) {
  15731. case ' ':
  15732. positivePrefix = ' ';
  15733. break;
  15734. case '+':
  15735. positivePrefix = '+';
  15736. break;
  15737. case '-':
  15738. leftJustify = true;
  15739. break;
  15740. case "'":
  15741. customPadChar = flags.charAt(j + 1);
  15742. break;
  15743. case '0':
  15744. zeroPad = true;
  15745. break;
  15746. case '#':
  15747. prefixBaseX = true;
  15748. break;
  15749. }
  15750. }
  15751. // parameters may be null, undefined, empty-string or real valued
  15752. // we want to ignore null, undefined and empty-string values
  15753. if (!minWidth) {
  15754. minWidth = 0;
  15755. } else if (minWidth == '*') {
  15756. minWidth = +a[i++];
  15757. } else if (minWidth.charAt(0) == '*') {
  15758. minWidth = +a[minWidth.slice(1, -1)];
  15759. } else {
  15760. minWidth = +minWidth;
  15761. }
  15762. // Note: undocumented perl feature:
  15763. if (minWidth < 0) {
  15764. minWidth = -minWidth;
  15765. leftJustify = true;
  15766. }
  15767. if (!isFinite(minWidth)) {
  15768. throw new Error('sprintf: (minimum-)width must be finite');
  15769. }
  15770. if (!precision) {
  15771. precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type == 'd') ? 0 : undefined;
  15772. } else if (precision == '*') {
  15773. precision = +a[i++];
  15774. } else if (precision.charAt(0) == '*') {
  15775. precision = +a[precision.slice(1, -1)];
  15776. } else {
  15777. precision = +precision;
  15778. }
  15779. // grab value using valueIndex if required?
  15780. value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++];
  15781. switch (type) {
  15782. case 's':
  15783. return formatString(String(value), leftJustify, minWidth, precision, zeroPad, customPadChar);
  15784. case 'c':
  15785. return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad);
  15786. case 'b':
  15787. return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
  15788. case 'o':
  15789. return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
  15790. case 'x':
  15791. return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
  15792. case 'X':
  15793. return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad).toUpperCase();
  15794. case 'u':
  15795. return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
  15796. case 'i':
  15797. case 'd':
  15798. number = +value || 0;
  15799. number = Math.round(number - number % 1); // Plain Math.round doesn't just truncate
  15800. prefix = number < 0 ? '-' : positivePrefix;
  15801. value = prefix + pad(String(Math.abs(number)), precision, '0', false);
  15802. return justify(value, prefix, leftJustify, minWidth, zeroPad);
  15803. case 'e':
  15804. case 'E':
  15805. case 'f': // Should handle locales (as per setlocale)
  15806. case 'F':
  15807. case 'g':
  15808. case 'G':
  15809. number = +value;
  15810. prefix = number < 0 ? '-' : positivePrefix;
  15811. method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())];
  15812. textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2];
  15813. value = prefix + Math.abs(number)[method](precision);
  15814. return justify(value, prefix, leftJustify, minWidth, zeroPad)[textTransform]();
  15815. default:
  15816. return substring;
  15817. }
  15818. };
  15819. return format.replace(regex, doFormat);
  15820. }
  15821. return sprintf;
  15822. });
  15823. /*global define*/
  15824. define('Core/GregorianDate',[],function() {
  15825. 'use strict';
  15826. /**
  15827. * Represents a Gregorian date in a more precise format than the JavaScript Date object.
  15828. * In addition to submillisecond precision, this object can also represent leap seconds.
  15829. * @alias GregorianDate
  15830. * @constructor
  15831. *
  15832. * @see JulianDate#toGregorianDate
  15833. */
  15834. function GregorianDate(year, month, day, hour, minute, second, millisecond, isLeapSecond) {
  15835. /**
  15836. * Gets or sets the year as a whole number.
  15837. * @type {Number}
  15838. */
  15839. this.year = year;
  15840. /**
  15841. * Gets or sets the month as a whole number with range [1, 12].
  15842. * @type {Number}
  15843. */
  15844. this.month = month;
  15845. /**
  15846. * Gets or sets the day of the month as a whole number starting at 1.
  15847. * @type {Number}
  15848. */
  15849. this.day = day;
  15850. /**
  15851. * Gets or sets the hour as a whole number with range [0, 23].
  15852. * @type {Number}
  15853. */
  15854. this.hour = hour;
  15855. /**
  15856. * Gets or sets the minute of the hour as a whole number with range [0, 59].
  15857. * @type {Number}
  15858. */
  15859. this.minute = minute;
  15860. /**
  15861. * Gets or sets the second of the minute as a whole number with range [0, 60], with 60 representing a leap second.
  15862. * @type {Number}
  15863. */
  15864. this.second = second;
  15865. /**
  15866. * Gets or sets the millisecond of the second as a floating point number with range [0.0, 1000.0).
  15867. * @type {Number}
  15868. */
  15869. this.millisecond = millisecond;
  15870. /**
  15871. * Gets or sets whether this time is during a leap second.
  15872. * @type {Boolean}
  15873. */
  15874. this.isLeapSecond = isLeapSecond;
  15875. }
  15876. return GregorianDate;
  15877. });
  15878. /*global define*/
  15879. define('Core/isLeapYear',[
  15880. './DeveloperError'
  15881. ], function(
  15882. DeveloperError) {
  15883. 'use strict';
  15884. /**
  15885. * Determines if a given date is a leap year.
  15886. *
  15887. * @exports isLeapYear
  15888. *
  15889. * @param {Number} year The year to be tested.
  15890. * @returns {Boolean} True if <code>year</code> is a leap year.
  15891. *
  15892. * @example
  15893. * var leapYear = Cesium.isLeapYear(2000); // true
  15894. */
  15895. function isLeapYear(year) {
  15896. if (year === null || isNaN(year)) {
  15897. throw new DeveloperError('year is required and must be a number.');
  15898. }
  15899. return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
  15900. }
  15901. return isLeapYear;
  15902. });
  15903. /*global define*/
  15904. define('Core/LeapSecond',[],function() {
  15905. 'use strict';
  15906. /**
  15907. * Describes a single leap second, which is constructed from a {@link JulianDate} and a
  15908. * numerical offset representing the number of seconds TAI is ahead of the UTC time standard.
  15909. * @alias LeapSecond
  15910. * @constructor
  15911. *
  15912. * @param {JulianDate} [date] A Julian date representing the time of the leap second.
  15913. * @param {Number} [offset] The cumulative number of seconds that TAI is ahead of UTC at the provided date.
  15914. */
  15915. function LeapSecond(date, offset) {
  15916. /**
  15917. * Gets or sets the date at which this leap second occurs.
  15918. * @type {JulianDate}
  15919. */
  15920. this.julianDate = date;
  15921. /**
  15922. * Gets or sets the cumulative number of seconds between the UTC and TAI time standards at the time
  15923. * of this leap second.
  15924. * @type {Number}
  15925. */
  15926. this.offset = offset;
  15927. }
  15928. return LeapSecond;
  15929. });
  15930. /*global define*/
  15931. define('Core/TimeConstants',[
  15932. './freezeObject'
  15933. ], function(
  15934. freezeObject) {
  15935. 'use strict';
  15936. /**
  15937. * Constants for time conversions like those done by {@link JulianDate}.
  15938. *
  15939. * @exports TimeConstants
  15940. *
  15941. * @see JulianDate
  15942. *
  15943. * @private
  15944. */
  15945. var TimeConstants = {
  15946. /**
  15947. * The number of seconds in one millisecond: <code>0.001</code>
  15948. * @type {Number}
  15949. * @constant
  15950. */
  15951. SECONDS_PER_MILLISECOND : 0.001,
  15952. /**
  15953. * The number of seconds in one minute: <code>60</code>.
  15954. * @type {Number}
  15955. * @constant
  15956. */
  15957. SECONDS_PER_MINUTE : 60.0,
  15958. /**
  15959. * The number of minutes in one hour: <code>60</code>.
  15960. * @type {Number}
  15961. * @constant
  15962. */
  15963. MINUTES_PER_HOUR : 60.0,
  15964. /**
  15965. * The number of hours in one day: <code>24</code>.
  15966. * @type {Number}
  15967. * @constant
  15968. */
  15969. HOURS_PER_DAY : 24.0,
  15970. /**
  15971. * The number of seconds in one hour: <code>3600</code>.
  15972. * @type {Number}
  15973. * @constant
  15974. */
  15975. SECONDS_PER_HOUR : 3600.0,
  15976. /**
  15977. * The number of minutes in one day: <code>1440</code>.
  15978. * @type {Number}
  15979. * @constant
  15980. */
  15981. MINUTES_PER_DAY : 1440.0,
  15982. /**
  15983. * The number of seconds in one day, ignoring leap seconds: <code>86400</code>.
  15984. * @type {Number}
  15985. * @constant
  15986. */
  15987. SECONDS_PER_DAY : 86400.0,
  15988. /**
  15989. * The number of days in one Julian century: <code>36525</code>.
  15990. * @type {Number}
  15991. * @constant
  15992. */
  15993. DAYS_PER_JULIAN_CENTURY : 36525.0,
  15994. /**
  15995. * One trillionth of a second.
  15996. * @type {Number}
  15997. * @constant
  15998. */
  15999. PICOSECOND : 0.000000001,
  16000. /**
  16001. * The number of days to subtract from a Julian date to determine the
  16002. * modified Julian date, which gives the number of days since midnight
  16003. * on November 17, 1858.
  16004. * @type {Number}
  16005. * @constant
  16006. */
  16007. MODIFIED_JULIAN_DATE_DIFFERENCE : 2400000.5
  16008. };
  16009. return freezeObject(TimeConstants);
  16010. });
  16011. /*global define*/
  16012. define('Core/TimeStandard',[
  16013. './freezeObject'
  16014. ], function(
  16015. freezeObject) {
  16016. 'use strict';
  16017. /**
  16018. * Provides the type of time standards which JulianDate can take as input.
  16019. *
  16020. * @exports TimeStandard
  16021. *
  16022. * @see JulianDate
  16023. */
  16024. var TimeStandard = {
  16025. /**
  16026. * Represents the coordinated Universal Time (UTC) time standard.
  16027. *
  16028. * UTC is related to TAI according to the relationship
  16029. * <code>UTC = TAI - deltaT</code> where <code>deltaT</code> is the number of leap
  16030. * seconds which have been introduced as of the time in TAI.
  16031. *
  16032. */
  16033. UTC : 0,
  16034. /**
  16035. * Represents the International Atomic Time (TAI) time standard.
  16036. * TAI is the principal time standard to which the other time standards are related.
  16037. */
  16038. TAI : 1
  16039. };
  16040. return freezeObject(TimeStandard);
  16041. });
  16042. /*global define*/
  16043. define('Core/JulianDate',[
  16044. '../ThirdParty/sprintf',
  16045. './binarySearch',
  16046. './defaultValue',
  16047. './defined',
  16048. './DeveloperError',
  16049. './GregorianDate',
  16050. './isLeapYear',
  16051. './LeapSecond',
  16052. './TimeConstants',
  16053. './TimeStandard'
  16054. ], function(
  16055. sprintf,
  16056. binarySearch,
  16057. defaultValue,
  16058. defined,
  16059. DeveloperError,
  16060. GregorianDate,
  16061. isLeapYear,
  16062. LeapSecond,
  16063. TimeConstants,
  16064. TimeStandard) {
  16065. 'use strict';
  16066. var gregorianDateScratch = new GregorianDate();
  16067. var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  16068. var daysInLeapFeburary = 29;
  16069. function compareLeapSecondDates(leapSecond, dateToFind) {
  16070. return JulianDate.compare(leapSecond.julianDate, dateToFind.julianDate);
  16071. }
  16072. // we don't really need a leap second instance, anything with a julianDate property will do
  16073. var binarySearchScratchLeapSecond = new LeapSecond();
  16074. function convertUtcToTai(julianDate) {
  16075. //Even though julianDate is in UTC, we'll treat it as TAI and
  16076. //search the leap second table for it.
  16077. binarySearchScratchLeapSecond.julianDate = julianDate;
  16078. var leapSeconds = JulianDate.leapSeconds;
  16079. var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, compareLeapSecondDates);
  16080. if (index < 0) {
  16081. index = ~index;
  16082. }
  16083. if (index >= leapSeconds.length) {
  16084. index = leapSeconds.length - 1;
  16085. }
  16086. var offset = leapSeconds[index].offset;
  16087. if (index > 0) {
  16088. //Now we have the index of the closest leap second that comes on or after our UTC time.
  16089. //However, if the difference between the UTC date being converted and the TAI
  16090. //defined leap second is greater than the offset, we are off by one and need to use
  16091. //the previous leap second.
  16092. var difference = JulianDate.secondsDifference(leapSeconds[index].julianDate, julianDate);
  16093. if (difference > offset) {
  16094. index--;
  16095. offset = leapSeconds[index].offset;
  16096. }
  16097. }
  16098. JulianDate.addSeconds(julianDate, offset, julianDate);
  16099. }
  16100. function convertTaiToUtc(julianDate, result) {
  16101. binarySearchScratchLeapSecond.julianDate = julianDate;
  16102. var leapSeconds = JulianDate.leapSeconds;
  16103. var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, compareLeapSecondDates);
  16104. if (index < 0) {
  16105. index = ~index;
  16106. }
  16107. //All times before our first leap second get the first offset.
  16108. if (index === 0) {
  16109. return JulianDate.addSeconds(julianDate, -leapSeconds[0].offset, result);
  16110. }
  16111. //All times after our leap second get the last offset.
  16112. if (index >= leapSeconds.length) {
  16113. return JulianDate.addSeconds(julianDate, -leapSeconds[index - 1].offset, result);
  16114. }
  16115. //Compute the difference between the found leap second and the time we are converting.
  16116. var difference = JulianDate.secondsDifference(leapSeconds[index].julianDate, julianDate);
  16117. if (difference === 0) {
  16118. //The date is in our leap second table.
  16119. return JulianDate.addSeconds(julianDate, -leapSeconds[index].offset, result);
  16120. }
  16121. if (difference <= 1.0) {
  16122. //The requested date is during the moment of a leap second, then we cannot convert to UTC
  16123. return undefined;
  16124. }
  16125. //The time is in between two leap seconds, index is the leap second after the date
  16126. //we're converting, so we subtract one to get the correct LeapSecond instance.
  16127. return JulianDate.addSeconds(julianDate, -leapSeconds[--index].offset, result);
  16128. }
  16129. function setComponents(wholeDays, secondsOfDay, julianDate) {
  16130. var extraDays = (secondsOfDay / TimeConstants.SECONDS_PER_DAY) | 0;
  16131. wholeDays += extraDays;
  16132. secondsOfDay -= TimeConstants.SECONDS_PER_DAY * extraDays;
  16133. if (secondsOfDay < 0) {
  16134. wholeDays--;
  16135. secondsOfDay += TimeConstants.SECONDS_PER_DAY;
  16136. }
  16137. julianDate.dayNumber = wholeDays;
  16138. julianDate.secondsOfDay = secondsOfDay;
  16139. return julianDate;
  16140. }
  16141. function computeJulianDateComponents(year, month, day, hour, minute, second, millisecond) {
  16142. // Algorithm from page 604 of the Explanatory Supplement to the
  16143. // Astronomical Almanac (Seidelmann 1992).
  16144. var a = ((month - 14) / 12) | 0;
  16145. var b = year + 4800 + a;
  16146. var dayNumber = (((1461 * b) / 4) | 0) + (((367 * (month - 2 - 12 * a)) / 12) | 0) - (((3 * (((b + 100) / 100) | 0)) / 4) | 0) + day - 32075;
  16147. // JulianDates are noon-based
  16148. hour = hour - 12;
  16149. if (hour < 0) {
  16150. hour += 24;
  16151. }
  16152. var secondsOfDay = second + ((hour * TimeConstants.SECONDS_PER_HOUR) + (minute * TimeConstants.SECONDS_PER_MINUTE) + (millisecond * TimeConstants.SECONDS_PER_MILLISECOND));
  16153. if (secondsOfDay >= 43200.0) {
  16154. dayNumber -= 1;
  16155. }
  16156. return [dayNumber, secondsOfDay];
  16157. }
  16158. //Regular expressions used for ISO8601 date parsing.
  16159. //YYYY
  16160. var matchCalendarYear = /^(\d{4})$/;
  16161. //YYYY-MM (YYYYMM is invalid)
  16162. var matchCalendarMonth = /^(\d{4})-(\d{2})$/;
  16163. //YYYY-DDD or YYYYDDD
  16164. var matchOrdinalDate = /^(\d{4})-?(\d{3})$/;
  16165. //YYYY-Www or YYYYWww or YYYY-Www-D or YYYYWwwD
  16166. var matchWeekDate = /^(\d{4})-?W(\d{2})-?(\d{1})?$/;
  16167. //YYYY-MM-DD or YYYYMMDD
  16168. var matchCalendarDate = /^(\d{4})-?(\d{2})-?(\d{2})$/;
  16169. // Match utc offset
  16170. var utcOffset = /([Z+\-])?(\d{2})?:?(\d{2})?$/;
  16171. // Match hours HH or HH.xxxxx
  16172. var matchHours = /^(\d{2})(\.\d+)?/.source + utcOffset.source;
  16173. // Match hours/minutes HH:MM HHMM.xxxxx
  16174. var matchHoursMinutes = /^(\d{2}):?(\d{2})(\.\d+)?/.source + utcOffset.source;
  16175. // Match hours/minutes HH:MM:SS HHMMSS.xxxxx
  16176. var matchHoursMinutesSeconds = /^(\d{2}):?(\d{2}):?(\d{2})(\.\d+)?/.source + utcOffset.source;
  16177. var iso8601ErrorMessage = 'Invalid ISO 8601 date.';
  16178. /**
  16179. * Represents an astronomical Julian date, which is the number of days since noon on January 1, -4712 (4713 BC).
  16180. * For increased precision, this class stores the whole number part of the date and the seconds
  16181. * part of the date in separate components. In order to be safe for arithmetic and represent
  16182. * leap seconds, the date is always stored in the International Atomic Time standard
  16183. * {@link TimeStandard.TAI}.
  16184. * @alias JulianDate
  16185. * @constructor
  16186. *
  16187. * @param {Number} [julianDayNumber=0.0] The Julian Day Number representing the number of whole days. Fractional days will also be handled correctly.
  16188. * @param {Number} [secondsOfDay=0.0] The number of seconds into the current Julian Day Number. Fractional seconds, negative seconds and seconds greater than a day will be handled correctly.
  16189. * @param {TimeStandard} [timeStandard=TimeStandard.UTC] The time standard in which the first two parameters are defined.
  16190. */
  16191. function JulianDate(julianDayNumber, secondsOfDay, timeStandard) {
  16192. /**
  16193. * Gets or sets the number of whole days.
  16194. * @type {Number}
  16195. */
  16196. this.dayNumber = undefined;
  16197. /**
  16198. * Gets or sets the number of seconds into the current day.
  16199. * @type {Number}
  16200. */
  16201. this.secondsOfDay = undefined;
  16202. julianDayNumber = defaultValue(julianDayNumber, 0.0);
  16203. secondsOfDay = defaultValue(secondsOfDay, 0.0);
  16204. timeStandard = defaultValue(timeStandard, TimeStandard.UTC);
  16205. //If julianDayNumber is fractional, make it an integer and add the number of seconds the fraction represented.
  16206. var wholeDays = julianDayNumber | 0;
  16207. secondsOfDay = secondsOfDay + (julianDayNumber - wholeDays) * TimeConstants.SECONDS_PER_DAY;
  16208. setComponents(wholeDays, secondsOfDay, this);
  16209. if (timeStandard === TimeStandard.UTC) {
  16210. convertUtcToTai(this);
  16211. }
  16212. }
  16213. /**
  16214. * Creates a new instance from a JavaScript Date.
  16215. *
  16216. * @param {Date} date A JavaScript Date.
  16217. * @param {JulianDate} [result] An existing instance to use for the result.
  16218. * @returns {JulianDate} The modified result parameter or a new instance if none was provided.
  16219. *
  16220. * @exception {DeveloperError} date must be a valid JavaScript Date.
  16221. */
  16222. JulianDate.fromDate = function(date, result) {
  16223. if (!(date instanceof Date) || isNaN(date.getTime())) {
  16224. throw new DeveloperError('date must be a valid JavaScript Date.');
  16225. }
  16226. var components = computeJulianDateComponents(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds());
  16227. if (!defined(result)) {
  16228. return new JulianDate(components[0], components[1], TimeStandard.UTC);
  16229. }
  16230. setComponents(components[0], components[1], result);
  16231. convertUtcToTai(result);
  16232. return result;
  16233. };
  16234. /**
  16235. * Creates a new instance from a from an {@link http://en.wikipedia.org/wiki/ISO_8601|ISO 8601} date.
  16236. * This method is superior to <code>Date.parse</code> because it will handle all valid formats defined by the ISO 8601
  16237. * specification, including leap seconds and sub-millisecond times, which discarded by most JavaScript implementations.
  16238. *
  16239. * @param {String} iso8601String An ISO 8601 date.
  16240. * @param {JulianDate} [result] An existing instance to use for the result.
  16241. * @returns {JulianDate} The modified result parameter or a new instance if none was provided.
  16242. *
  16243. * @exception {DeveloperError} Invalid ISO 8601 date.
  16244. */
  16245. JulianDate.fromIso8601 = function(iso8601String, result) {
  16246. if (typeof iso8601String !== 'string') {
  16247. throw new DeveloperError(iso8601ErrorMessage);
  16248. }
  16249. //Comma and decimal point both indicate a fractional number according to ISO 8601,
  16250. //start out by blanket replacing , with . which is the only valid such symbol in JS.
  16251. iso8601String = iso8601String.replace(',', '.');
  16252. //Split the string into its date and time components, denoted by a mandatory T
  16253. var tokens = iso8601String.split('T');
  16254. var year;
  16255. var month = 1;
  16256. var day = 1;
  16257. var hour = 0;
  16258. var minute = 0;
  16259. var second = 0;
  16260. var millisecond = 0;
  16261. //Lacking a time is okay, but a missing date is illegal.
  16262. var date = tokens[0];
  16263. var time = tokens[1];
  16264. var tmp;
  16265. var inLeapYear;
  16266. if (!defined(date)) {
  16267. throw new DeveloperError(iso8601ErrorMessage);
  16268. }
  16269. var dashCount;
  16270. //First match the date against possible regular expressions.
  16271. tokens = date.match(matchCalendarDate);
  16272. if (tokens !== null) {
  16273. dashCount = date.split('-').length - 1;
  16274. if (dashCount > 0 && dashCount !== 2) {
  16275. throw new DeveloperError(iso8601ErrorMessage);
  16276. }
  16277. year = +tokens[1];
  16278. month = +tokens[2];
  16279. day = +tokens[3];
  16280. } else {
  16281. tokens = date.match(matchCalendarMonth);
  16282. if (tokens !== null) {
  16283. year = +tokens[1];
  16284. month = +tokens[2];
  16285. } else {
  16286. tokens = date.match(matchCalendarYear);
  16287. if (tokens !== null) {
  16288. year = +tokens[1];
  16289. } else {
  16290. //Not a year/month/day so it must be an ordinal date.
  16291. var dayOfYear;
  16292. tokens = date.match(matchOrdinalDate);
  16293. if (tokens !== null) {
  16294. year = +tokens[1];
  16295. dayOfYear = +tokens[2];
  16296. inLeapYear = isLeapYear(year);
  16297. //This validation is only applicable for this format.
  16298. if (dayOfYear < 1 || (inLeapYear && dayOfYear > 366) || (!inLeapYear && dayOfYear > 365)) {
  16299. throw new DeveloperError(iso8601ErrorMessage);
  16300. }
  16301. } else {
  16302. tokens = date.match(matchWeekDate);
  16303. if (tokens !== null) {
  16304. //ISO week date to ordinal date from
  16305. //http://en.wikipedia.org/w/index.php?title=ISO_week_date&oldid=474176775
  16306. year = +tokens[1];
  16307. var weekNumber = +tokens[2];
  16308. var dayOfWeek = +tokens[3] || 0;
  16309. dashCount = date.split('-').length - 1;
  16310. if (dashCount > 0 &&
  16311. ((!defined(tokens[3]) && dashCount !== 1) ||
  16312. (defined(tokens[3]) && dashCount !== 2))) {
  16313. throw new DeveloperError(iso8601ErrorMessage);
  16314. }
  16315. var january4 = new Date(Date.UTC(year, 0, 4));
  16316. dayOfYear = (weekNumber * 7) + dayOfWeek - january4.getUTCDay() - 3;
  16317. } else {
  16318. //None of our regular expressions succeeded in parsing the date properly.
  16319. throw new DeveloperError(iso8601ErrorMessage);
  16320. }
  16321. }
  16322. //Split an ordinal date into month/day.
  16323. tmp = new Date(Date.UTC(year, 0, 1));
  16324. tmp.setUTCDate(dayOfYear);
  16325. month = tmp.getUTCMonth() + 1;
  16326. day = tmp.getUTCDate();
  16327. }
  16328. }
  16329. }
  16330. //Now that we have all of the date components, validate them to make sure nothing is out of range.
  16331. inLeapYear = isLeapYear(year);
  16332. if (month < 1 || month > 12 || day < 1 || ((month !== 2 || !inLeapYear) && day > daysInMonth[month - 1]) || (inLeapYear && month === 2 && day > daysInLeapFeburary)) {
  16333. throw new DeveloperError(iso8601ErrorMessage);
  16334. }
  16335. //Not move onto the time string, which is much simpler.
  16336. var offsetIndex;
  16337. if (defined(time)) {
  16338. tokens = time.match(matchHoursMinutesSeconds);
  16339. if (tokens !== null) {
  16340. dashCount = time.split(':').length - 1;
  16341. if (dashCount > 0 && dashCount !== 2 && dashCount !== 3) {
  16342. throw new DeveloperError(iso8601ErrorMessage);
  16343. }
  16344. hour = +tokens[1];
  16345. minute = +tokens[2];
  16346. second = +tokens[3];
  16347. millisecond = +(tokens[4] || 0) * 1000.0;
  16348. offsetIndex = 5;
  16349. } else {
  16350. tokens = time.match(matchHoursMinutes);
  16351. if (tokens !== null) {
  16352. dashCount = time.split(':').length - 1;
  16353. if (dashCount > 2) {
  16354. throw new DeveloperError(iso8601ErrorMessage);
  16355. }
  16356. hour = +tokens[1];
  16357. minute = +tokens[2];
  16358. second = +(tokens[3] || 0) * 60.0;
  16359. offsetIndex = 4;
  16360. } else {
  16361. tokens = time.match(matchHours);
  16362. if (tokens !== null) {
  16363. hour = +tokens[1];
  16364. minute = +(tokens[2] || 0) * 60.0;
  16365. offsetIndex = 3;
  16366. } else {
  16367. throw new DeveloperError(iso8601ErrorMessage);
  16368. }
  16369. }
  16370. }
  16371. //Validate that all values are in proper range. Minutes and hours have special cases at 60 and 24.
  16372. if (minute >= 60 || second >= 61 || hour > 24 || (hour === 24 && (minute > 0 || second > 0 || millisecond > 0))) {
  16373. throw new DeveloperError(iso8601ErrorMessage);
  16374. }
  16375. //Check the UTC offset value, if no value exists, use local time
  16376. //a Z indicates UTC, + or - are offsets.
  16377. var offset = tokens[offsetIndex];
  16378. var offsetHours = +(tokens[offsetIndex + 1]);
  16379. var offsetMinutes = +(tokens[offsetIndex + 2] || 0);
  16380. switch (offset) {
  16381. case '+':
  16382. hour = hour - offsetHours;
  16383. minute = minute - offsetMinutes;
  16384. break;
  16385. case '-':
  16386. hour = hour + offsetHours;
  16387. minute = minute + offsetMinutes;
  16388. break;
  16389. case 'Z':
  16390. break;
  16391. default:
  16392. minute = minute + new Date(Date.UTC(year, month - 1, day, hour, minute)).getTimezoneOffset();
  16393. break;
  16394. }
  16395. } else {
  16396. //If no time is specified, it is considered the beginning of the day, local time.
  16397. minute = minute + new Date(year, month - 1, day).getTimezoneOffset();
  16398. }
  16399. //ISO8601 denotes a leap second by any time having a seconds component of 60 seconds.
  16400. //If that's the case, we need to temporarily subtract a second in order to build a UTC date.
  16401. //Then we add it back in after converting to TAI.
  16402. var isLeapSecond = second === 60;
  16403. if (isLeapSecond) {
  16404. second--;
  16405. }
  16406. //Even if we successfully parsed the string into its components, after applying UTC offset or
  16407. //special cases like 24:00:00 denoting midnight, we need to normalize the data appropriately.
  16408. //milliseconds can never be greater than 1000, and seconds can't be above 60, so we start with minutes
  16409. while (minute >= 60) {
  16410. minute -= 60;
  16411. hour++;
  16412. }
  16413. while (hour >= 24) {
  16414. hour -= 24;
  16415. day++;
  16416. }
  16417. tmp = (inLeapYear && month === 2) ? daysInLeapFeburary : daysInMonth[month - 1];
  16418. while (day > tmp) {
  16419. day -= tmp;
  16420. month++;
  16421. if (month > 12) {
  16422. month -= 12;
  16423. year++;
  16424. }
  16425. tmp = (inLeapYear && month === 2) ? daysInLeapFeburary : daysInMonth[month - 1];
  16426. }
  16427. //If UTC offset is at the beginning/end of the day, minutes can be negative.
  16428. while (minute < 0) {
  16429. minute += 60;
  16430. hour--;
  16431. }
  16432. while (hour < 0) {
  16433. hour += 24;
  16434. day--;
  16435. }
  16436. while (day < 1) {
  16437. month--;
  16438. if (month < 1) {
  16439. month += 12;
  16440. year--;
  16441. }
  16442. tmp = (inLeapYear && month === 2) ? daysInLeapFeburary : daysInMonth[month - 1];
  16443. day += tmp;
  16444. }
  16445. //Now create the JulianDate components from the Gregorian date and actually create our instance.
  16446. var components = computeJulianDateComponents(year, month, day, hour, minute, second, millisecond);
  16447. if (!defined(result)) {
  16448. result = new JulianDate(components[0], components[1], TimeStandard.UTC);
  16449. } else {
  16450. setComponents(components[0], components[1], result);
  16451. convertUtcToTai(result);
  16452. }
  16453. //If we were on a leap second, add it back.
  16454. if (isLeapSecond) {
  16455. JulianDate.addSeconds(result, 1, result);
  16456. }
  16457. return result;
  16458. };
  16459. /**
  16460. * Creates a new instance that represents the current system time.
  16461. * This is equivalent to calling <code>JulianDate.fromDate(new Date());</code>.
  16462. *
  16463. * @param {JulianDate} [result] An existing instance to use for the result.
  16464. * @returns {JulianDate} The modified result parameter or a new instance if none was provided.
  16465. */
  16466. JulianDate.now = function(result) {
  16467. return JulianDate.fromDate(new Date(), result);
  16468. };
  16469. var toGregorianDateScratch = new JulianDate(0, 0, TimeStandard.TAI);
  16470. /**
  16471. * Creates a {@link GregorianDate} from the provided instance.
  16472. *
  16473. * @param {JulianDate} julianDate The date to be converted.
  16474. * @param {GregorianDate} [result] An existing instance to use for the result.
  16475. * @returns {GregorianDate} The modified result parameter or a new instance if none was provided.
  16476. */
  16477. JulianDate.toGregorianDate = function(julianDate, result) {
  16478. if (!defined(julianDate)) {
  16479. throw new DeveloperError('julianDate is required.');
  16480. }
  16481. var isLeapSecond = false;
  16482. var thisUtc = convertTaiToUtc(julianDate, toGregorianDateScratch);
  16483. if (!defined(thisUtc)) {
  16484. //Conversion to UTC will fail if we are during a leap second.
  16485. //If that's the case, subtract a second and convert again.
  16486. //JavaScript doesn't support leap seconds, so this results in second 59 being repeated twice.
  16487. JulianDate.addSeconds(julianDate, -1, toGregorianDateScratch);
  16488. thisUtc = convertTaiToUtc(toGregorianDateScratch, toGregorianDateScratch);
  16489. isLeapSecond = true;
  16490. }
  16491. var julianDayNumber = thisUtc.dayNumber;
  16492. var secondsOfDay = thisUtc.secondsOfDay;
  16493. if (secondsOfDay >= 43200.0) {
  16494. julianDayNumber += 1;
  16495. }
  16496. // Algorithm from page 604 of the Explanatory Supplement to the
  16497. // Astronomical Almanac (Seidelmann 1992).
  16498. var L = (julianDayNumber + 68569) | 0;
  16499. var N = (4 * L / 146097) | 0;
  16500. L = (L - (((146097 * N + 3) / 4) | 0)) | 0;
  16501. var I = ((4000 * (L + 1)) / 1461001) | 0;
  16502. L = (L - (((1461 * I) / 4) | 0) + 31) | 0;
  16503. var J = ((80 * L) / 2447) | 0;
  16504. var day = (L - (((2447 * J) / 80) | 0)) | 0;
  16505. L = (J / 11) | 0;
  16506. var month = (J + 2 - 12 * L) | 0;
  16507. var year = (100 * (N - 49) + I + L) | 0;
  16508. var hour = (secondsOfDay / TimeConstants.SECONDS_PER_HOUR) | 0;
  16509. var remainingSeconds = secondsOfDay - (hour * TimeConstants.SECONDS_PER_HOUR);
  16510. var minute = (remainingSeconds / TimeConstants.SECONDS_PER_MINUTE) | 0;
  16511. remainingSeconds = remainingSeconds - (minute * TimeConstants.SECONDS_PER_MINUTE);
  16512. var second = remainingSeconds | 0;
  16513. var millisecond = ((remainingSeconds - second) / TimeConstants.SECONDS_PER_MILLISECOND);
  16514. // JulianDates are noon-based
  16515. hour += 12;
  16516. if (hour > 23) {
  16517. hour -= 24;
  16518. }
  16519. //If we were on a leap second, add it back.
  16520. if (isLeapSecond) {
  16521. second += 1;
  16522. }
  16523. if (!defined(result)) {
  16524. return new GregorianDate(year, month, day, hour, minute, second, millisecond, isLeapSecond);
  16525. }
  16526. result.year = year;
  16527. result.month = month;
  16528. result.day = day;
  16529. result.hour = hour;
  16530. result.minute = minute;
  16531. result.second = second;
  16532. result.millisecond = millisecond;
  16533. result.isLeapSecond = isLeapSecond;
  16534. return result;
  16535. };
  16536. /**
  16537. * Creates a JavaScript Date from the provided instance.
  16538. * Since JavaScript dates are only accurate to the nearest millisecond and
  16539. * cannot represent a leap second, consider using {@link JulianDate.toGregorianDate} instead.
  16540. * If the provided JulianDate is during a leap second, the previous second is used.
  16541. *
  16542. * @param {JulianDate} julianDate The date to be converted.
  16543. * @returns {Date} A new instance representing the provided date.
  16544. */
  16545. JulianDate.toDate = function(julianDate) {
  16546. if (!defined(julianDate)) {
  16547. throw new DeveloperError('julianDate is required.');
  16548. }
  16549. var gDate = JulianDate.toGregorianDate(julianDate, gregorianDateScratch);
  16550. var second = gDate.second;
  16551. if (gDate.isLeapSecond) {
  16552. second -= 1;
  16553. }
  16554. return new Date(Date.UTC(gDate.year, gDate.month - 1, gDate.day, gDate.hour, gDate.minute, second, gDate.millisecond));
  16555. };
  16556. /**
  16557. * Creates an ISO8601 representation of the provided date.
  16558. *
  16559. * @param {JulianDate} julianDate The date to be converted.
  16560. * @param {Number} [precision] The number of fractional digits used to represent the seconds component. By default, the most precise representation is used.
  16561. * @returns {String} The ISO8601 representation of the provided date.
  16562. */
  16563. JulianDate.toIso8601 = function(julianDate, precision) {
  16564. if (!defined(julianDate)) {
  16565. throw new DeveloperError('julianDate is required.');
  16566. }
  16567. var gDate = JulianDate.toGregorianDate(julianDate, gDate);
  16568. var millisecondStr;
  16569. if (!defined(precision) && gDate.millisecond !== 0) {
  16570. //Forces milliseconds into a number with at least 3 digits to whatever the default toString() precision is.
  16571. millisecondStr = (gDate.millisecond * 0.01).toString().replace('.', '');
  16572. return sprintf("%04d-%02d-%02dT%02d:%02d:%02d.%sZ", gDate.year, gDate.month, gDate.day, gDate.hour, gDate.minute, gDate.second, millisecondStr);
  16573. }
  16574. //Precision is either 0 or milliseconds is 0 with undefined precision, in either case, leave off milliseconds entirely
  16575. if (!defined(precision) || precision === 0) {
  16576. return sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", gDate.year, gDate.month, gDate.day, gDate.hour, gDate.minute, gDate.second);
  16577. }
  16578. //Forces milliseconds into a number with at least 3 digits to whatever the specified precision is.
  16579. millisecondStr = (gDate.millisecond * 0.01).toFixed(precision).replace('.', '').slice(0, precision);
  16580. return sprintf("%04d-%02d-%02dT%02d:%02d:%02d.%sZ", gDate.year, gDate.month, gDate.day, gDate.hour, gDate.minute, gDate.second, millisecondStr);
  16581. };
  16582. /**
  16583. * Duplicates a JulianDate instance.
  16584. *
  16585. * @param {JulianDate} julianDate The date to duplicate.
  16586. * @param {JulianDate} [result] An existing instance to use for the result.
  16587. * @returns {JulianDate} The modified result parameter or a new instance if none was provided. Returns undefined if julianDate is undefined.
  16588. */
  16589. JulianDate.clone = function(julianDate, result) {
  16590. if (!defined(julianDate)) {
  16591. return undefined;
  16592. }
  16593. if (!defined(result)) {
  16594. return new JulianDate(julianDate.dayNumber, julianDate.secondsOfDay, TimeStandard.TAI);
  16595. }
  16596. result.dayNumber = julianDate.dayNumber;
  16597. result.secondsOfDay = julianDate.secondsOfDay;
  16598. return result;
  16599. };
  16600. /**
  16601. * Compares two instances.
  16602. *
  16603. * @param {JulianDate} left The first instance.
  16604. * @param {JulianDate} right The second instance.
  16605. * @returns {Number} A negative value if left is less than right, a positive value if left is greater than right, or zero if left and right are equal.
  16606. */
  16607. JulianDate.compare = function(left, right) {
  16608. if (!defined(left)) {
  16609. throw new DeveloperError('left is required.');
  16610. }
  16611. if (!defined(right)) {
  16612. throw new DeveloperError('right is required.');
  16613. }
  16614. var julianDayNumberDifference = left.dayNumber - right.dayNumber;
  16615. if (julianDayNumberDifference !== 0) {
  16616. return julianDayNumberDifference;
  16617. }
  16618. return left.secondsOfDay - right.secondsOfDay;
  16619. };
  16620. /**
  16621. * Compares two instances and returns <code>true</code> if they are equal, <code>false</code> otherwise.
  16622. *
  16623. * @param {JulianDate} [left] The first instance.
  16624. * @param {JulianDate} [right] The second instance.
  16625. * @returns {Boolean} <code>true</code> if the dates are equal; otherwise, <code>false</code>.
  16626. */
  16627. JulianDate.equals = function(left, right) {
  16628. return (left === right) ||
  16629. (defined(left) &&
  16630. defined(right) &&
  16631. left.dayNumber === right.dayNumber &&
  16632. left.secondsOfDay === right.secondsOfDay);
  16633. };
  16634. /**
  16635. * Compares two instances and returns <code>true</code> if they are within <code>epsilon</code> seconds of
  16636. * each other. That is, in order for the dates to be considered equal (and for
  16637. * this function to return <code>true</code>), the absolute value of the difference between them, in
  16638. * seconds, must be less than <code>epsilon</code>.
  16639. *
  16640. * @param {JulianDate} [left] The first instance.
  16641. * @param {JulianDate} [right] The second instance.
  16642. * @param {Number} epsilon The maximum number of seconds that should separate the two instances.
  16643. * @returns {Boolean} <code>true</code> if the two dates are within <code>epsilon</code> seconds of each other; otherwise <code>false</code>.
  16644. */
  16645. JulianDate.equalsEpsilon = function(left, right, epsilon) {
  16646. if (!defined(epsilon)) {
  16647. throw new DeveloperError('epsilon is required.');
  16648. }
  16649. return (left === right) ||
  16650. (defined(left) &&
  16651. defined(right) &&
  16652. Math.abs(JulianDate.secondsDifference(left, right)) <= epsilon);
  16653. };
  16654. /**
  16655. * Computes the total number of whole and fractional days represented by the provided instance.
  16656. *
  16657. * @param {JulianDate} julianDate The date.
  16658. * @returns {Number} The Julian date as single floating point number.
  16659. */
  16660. JulianDate.totalDays = function(julianDate) {
  16661. if (!defined(julianDate)) {
  16662. throw new DeveloperError('julianDate is required.');
  16663. }
  16664. return julianDate.dayNumber + (julianDate.secondsOfDay / TimeConstants.SECONDS_PER_DAY);
  16665. };
  16666. /**
  16667. * Computes the difference in seconds between the provided instance.
  16668. *
  16669. * @param {JulianDate} left The first instance.
  16670. * @param {JulianDate} right The second instance.
  16671. * @returns {Number} The difference, in seconds, when subtracting <code>right</code> from <code>left</code>.
  16672. */
  16673. JulianDate.secondsDifference = function(left, right) {
  16674. if (!defined(left)) {
  16675. throw new DeveloperError('left is required.');
  16676. }
  16677. if (!defined(right)) {
  16678. throw new DeveloperError('right is required.');
  16679. }
  16680. var dayDifference = (left.dayNumber - right.dayNumber) * TimeConstants.SECONDS_PER_DAY;
  16681. return (dayDifference + (left.secondsOfDay - right.secondsOfDay));
  16682. };
  16683. /**
  16684. * Computes the difference in days between the provided instance.
  16685. *
  16686. * @param {JulianDate} left The first instance.
  16687. * @param {JulianDate} right The second instance.
  16688. * @returns {Number} The difference, in days, when subtracting <code>right</code> from <code>left</code>.
  16689. */
  16690. JulianDate.daysDifference = function(left, right) {
  16691. if (!defined(left)) {
  16692. throw new DeveloperError('left is required.');
  16693. }
  16694. if (!defined(right)) {
  16695. throw new DeveloperError('right is required.');
  16696. }
  16697. var dayDifference = (left.dayNumber - right.dayNumber);
  16698. var secondDifference = (left.secondsOfDay - right.secondsOfDay) / TimeConstants.SECONDS_PER_DAY;
  16699. return dayDifference + secondDifference;
  16700. };
  16701. /**
  16702. * Computes the number of seconds the provided instance is ahead of UTC.
  16703. *
  16704. * @param {JulianDate} julianDate The date.
  16705. * @returns {Number} The number of seconds the provided instance is ahead of UTC
  16706. */
  16707. JulianDate.computeTaiMinusUtc = function(julianDate) {
  16708. binarySearchScratchLeapSecond.julianDate = julianDate;
  16709. var leapSeconds = JulianDate.leapSeconds;
  16710. var index = binarySearch(leapSeconds, binarySearchScratchLeapSecond, compareLeapSecondDates);
  16711. if (index < 0) {
  16712. index = ~index;
  16713. --index;
  16714. if (index < 0) {
  16715. index = 0;
  16716. }
  16717. }
  16718. return leapSeconds[index].offset;
  16719. };
  16720. /**
  16721. * Adds the provided number of seconds to the provided date instance.
  16722. *
  16723. * @param {JulianDate} julianDate The date.
  16724. * @param {Number} seconds The number of seconds to add or subtract.
  16725. * @param {JulianDate} result An existing instance to use for the result.
  16726. * @returns {JulianDate} The modified result parameter.
  16727. */
  16728. JulianDate.addSeconds = function(julianDate, seconds, result) {
  16729. if (!defined(julianDate)) {
  16730. throw new DeveloperError('julianDate is required.');
  16731. }
  16732. if (!defined(seconds)) {
  16733. throw new DeveloperError('seconds is required.');
  16734. }
  16735. if (!defined(result)) {
  16736. throw new DeveloperError('result is required.');
  16737. }
  16738. return setComponents(julianDate.dayNumber, julianDate.secondsOfDay + seconds, result);
  16739. };
  16740. /**
  16741. * Adds the provided number of minutes to the provided date instance.
  16742. *
  16743. * @param {JulianDate} julianDate The date.
  16744. * @param {Number} minutes The number of minutes to add or subtract.
  16745. * @param {JulianDate} result An existing instance to use for the result.
  16746. * @returns {JulianDate} The modified result parameter.
  16747. */
  16748. JulianDate.addMinutes = function(julianDate, minutes, result) {
  16749. if (!defined(julianDate)) {
  16750. throw new DeveloperError('julianDate is required.');
  16751. }
  16752. if (!defined(minutes)) {
  16753. throw new DeveloperError('minutes is required.');
  16754. }
  16755. if (!defined(result)) {
  16756. throw new DeveloperError('result is required.');
  16757. }
  16758. var newSecondsOfDay = julianDate.secondsOfDay + (minutes * TimeConstants.SECONDS_PER_MINUTE);
  16759. return setComponents(julianDate.dayNumber, newSecondsOfDay, result);
  16760. };
  16761. /**
  16762. * Adds the provided number of hours to the provided date instance.
  16763. *
  16764. * @param {JulianDate} julianDate The date.
  16765. * @param {Number} hours The number of hours to add or subtract.
  16766. * @param {JulianDate} result An existing instance to use for the result.
  16767. * @returns {JulianDate} The modified result parameter.
  16768. */
  16769. JulianDate.addHours = function(julianDate, hours, result) {
  16770. if (!defined(julianDate)) {
  16771. throw new DeveloperError('julianDate is required.');
  16772. }
  16773. if (!defined(hours)) {
  16774. throw new DeveloperError('hours is required.');
  16775. }
  16776. if (!defined(result)) {
  16777. throw new DeveloperError('result is required.');
  16778. }
  16779. var newSecondsOfDay = julianDate.secondsOfDay + (hours * TimeConstants.SECONDS_PER_HOUR);
  16780. return setComponents(julianDate.dayNumber, newSecondsOfDay, result);
  16781. };
  16782. /**
  16783. * Adds the provided number of days to the provided date instance.
  16784. *
  16785. * @param {JulianDate} julianDate The date.
  16786. * @param {Number} days The number of days to add or subtract.
  16787. * @param {JulianDate} result An existing instance to use for the result.
  16788. * @returns {JulianDate} The modified result parameter.
  16789. */
  16790. JulianDate.addDays = function(julianDate, days, result) {
  16791. if (!defined(julianDate)) {
  16792. throw new DeveloperError('julianDate is required.');
  16793. }
  16794. if (!defined(days)) {
  16795. throw new DeveloperError('days is required.');
  16796. }
  16797. if (!defined(result)) {
  16798. throw new DeveloperError('result is required.');
  16799. }
  16800. var newJulianDayNumber = julianDate.dayNumber + days;
  16801. return setComponents(newJulianDayNumber, julianDate.secondsOfDay, result);
  16802. };
  16803. /**
  16804. * Compares the provided instances and returns <code>true</code> if <code>left</code> is earlier than <code>right</code>, <code>false</code> otherwise.
  16805. *
  16806. * @param {JulianDate} left The first instance.
  16807. * @param {JulianDate} right The second instance.
  16808. * @returns {Boolean} <code>true</code> if <code>left</code> is earlier than <code>right</code>, <code>false</code> otherwise.
  16809. */
  16810. JulianDate.lessThan = function(left, right) {
  16811. return JulianDate.compare(left, right) < 0;
  16812. };
  16813. /**
  16814. * Compares the provided instances and returns <code>true</code> if <code>left</code> is earlier than or equal to <code>right</code>, <code>false</code> otherwise.
  16815. *
  16816. * @param {JulianDate} left The first instance.
  16817. * @param {JulianDate} right The second instance.
  16818. * @returns {Boolean} <code>true</code> if <code>left</code> is earlier than or equal to <code>right</code>, <code>false</code> otherwise.
  16819. */
  16820. JulianDate.lessThanOrEquals = function(left, right) {
  16821. return JulianDate.compare(left, right) <= 0;
  16822. };
  16823. /**
  16824. * Compares the provided instances and returns <code>true</code> if <code>left</code> is later than <code>right</code>, <code>false</code> otherwise.
  16825. *
  16826. * @param {JulianDate} left The first instance.
  16827. * @param {JulianDate} right The second instance.
  16828. * @returns {Boolean} <code>true</code> if <code>left</code> is later than <code>right</code>, <code>false</code> otherwise.
  16829. */
  16830. JulianDate.greaterThan = function(left, right) {
  16831. return JulianDate.compare(left, right) > 0;
  16832. };
  16833. /**
  16834. * Compares the provided instances and returns <code>true</code> if <code>left</code> is later than or equal to <code>right</code>, <code>false</code> otherwise.
  16835. *
  16836. * @param {JulianDate} left The first instance.
  16837. * @param {JulianDate} right The second instance.
  16838. * @returns {Boolean} <code>true</code> if <code>left</code> is later than or equal to <code>right</code>, <code>false</code> otherwise.
  16839. */
  16840. JulianDate.greaterThanOrEquals = function(left, right) {
  16841. return JulianDate.compare(left, right) >= 0;
  16842. };
  16843. /**
  16844. * Duplicates this instance.
  16845. *
  16846. * @param {JulianDate} [result] An existing instance to use for the result.
  16847. * @returns {JulianDate} The modified result parameter or a new instance if none was provided.
  16848. */
  16849. JulianDate.prototype.clone = function(result) {
  16850. return JulianDate.clone(this, result);
  16851. };
  16852. /**
  16853. * Compares this and the provided instance and returns <code>true</code> if they are equal, <code>false</code> otherwise.
  16854. *
  16855. * @param {JulianDate} [right] The second instance.
  16856. * @returns {Boolean} <code>true</code> if the dates are equal; otherwise, <code>false</code>.
  16857. */
  16858. JulianDate.prototype.equals = function(right) {
  16859. return JulianDate.equals(this, right);
  16860. };
  16861. /**
  16862. * Compares this and the provided instance and returns <code>true</code> if they are within <code>epsilon</code> seconds of
  16863. * each other. That is, in order for the dates to be considered equal (and for
  16864. * this function to return <code>true</code>), the absolute value of the difference between them, in
  16865. * seconds, must be less than <code>epsilon</code>.
  16866. *
  16867. * @param {JulianDate} [right] The second instance.
  16868. * @param {Number} epsilon The maximum number of seconds that should separate the two instances.
  16869. * @returns {Boolean} <code>true</code> if the two dates are within <code>epsilon</code> seconds of each other; otherwise <code>false</code>.
  16870. */
  16871. JulianDate.prototype.equalsEpsilon = function(right, epsilon) {
  16872. return JulianDate.equalsEpsilon(this, right, epsilon);
  16873. };
  16874. /**
  16875. * Creates a string representing this date in ISO8601 format.
  16876. *
  16877. * @returns {String} A string representing this date in ISO8601 format.
  16878. */
  16879. JulianDate.prototype.toString = function() {
  16880. return JulianDate.toIso8601(this);
  16881. };
  16882. /**
  16883. * Gets or sets the list of leap seconds used throughout Cesium.
  16884. * @memberof JulianDate
  16885. * @type {LeapSecond[]}
  16886. */
  16887. JulianDate.leapSeconds = [
  16888. new LeapSecond(new JulianDate(2441317, 43210.0, TimeStandard.TAI), 10), // January 1, 1972 00:00:00 UTC
  16889. new LeapSecond(new JulianDate(2441499, 43211.0, TimeStandard.TAI), 11), // July 1, 1972 00:00:00 UTC
  16890. new LeapSecond(new JulianDate(2441683, 43212.0, TimeStandard.TAI), 12), // January 1, 1973 00:00:00 UTC
  16891. new LeapSecond(new JulianDate(2442048, 43213.0, TimeStandard.TAI), 13), // January 1, 1974 00:00:00 UTC
  16892. new LeapSecond(new JulianDate(2442413, 43214.0, TimeStandard.TAI), 14), // January 1, 1975 00:00:00 UTC
  16893. new LeapSecond(new JulianDate(2442778, 43215.0, TimeStandard.TAI), 15), // January 1, 1976 00:00:00 UTC
  16894. new LeapSecond(new JulianDate(2443144, 43216.0, TimeStandard.TAI), 16), // January 1, 1977 00:00:00 UTC
  16895. new LeapSecond(new JulianDate(2443509, 43217.0, TimeStandard.TAI), 17), // January 1, 1978 00:00:00 UTC
  16896. new LeapSecond(new JulianDate(2443874, 43218.0, TimeStandard.TAI), 18), // January 1, 1979 00:00:00 UTC
  16897. new LeapSecond(new JulianDate(2444239, 43219.0, TimeStandard.TAI), 19), // January 1, 1980 00:00:00 UTC
  16898. new LeapSecond(new JulianDate(2444786, 43220.0, TimeStandard.TAI), 20), // July 1, 1981 00:00:00 UTC
  16899. new LeapSecond(new JulianDate(2445151, 43221.0, TimeStandard.TAI), 21), // July 1, 1982 00:00:00 UTC
  16900. new LeapSecond(new JulianDate(2445516, 43222.0, TimeStandard.TAI), 22), // July 1, 1983 00:00:00 UTC
  16901. new LeapSecond(new JulianDate(2446247, 43223.0, TimeStandard.TAI), 23), // July 1, 1985 00:00:00 UTC
  16902. new LeapSecond(new JulianDate(2447161, 43224.0, TimeStandard.TAI), 24), // January 1, 1988 00:00:00 UTC
  16903. new LeapSecond(new JulianDate(2447892, 43225.0, TimeStandard.TAI), 25), // January 1, 1990 00:00:00 UTC
  16904. new LeapSecond(new JulianDate(2448257, 43226.0, TimeStandard.TAI), 26), // January 1, 1991 00:00:00 UTC
  16905. new LeapSecond(new JulianDate(2448804, 43227.0, TimeStandard.TAI), 27), // July 1, 1992 00:00:00 UTC
  16906. new LeapSecond(new JulianDate(2449169, 43228.0, TimeStandard.TAI), 28), // July 1, 1993 00:00:00 UTC
  16907. new LeapSecond(new JulianDate(2449534, 43229.0, TimeStandard.TAI), 29), // July 1, 1994 00:00:00 UTC
  16908. new LeapSecond(new JulianDate(2450083, 43230.0, TimeStandard.TAI), 30), // January 1, 1996 00:00:00 UTC
  16909. new LeapSecond(new JulianDate(2450630, 43231.0, TimeStandard.TAI), 31), // July 1, 1997 00:00:00 UTC
  16910. new LeapSecond(new JulianDate(2451179, 43232.0, TimeStandard.TAI), 32), // January 1, 1999 00:00:00 UTC
  16911. new LeapSecond(new JulianDate(2453736, 43233.0, TimeStandard.TAI), 33), // January 1, 2006 00:00:00 UTC
  16912. new LeapSecond(new JulianDate(2454832, 43234.0, TimeStandard.TAI), 34), // January 1, 2009 00:00:00 UTC
  16913. new LeapSecond(new JulianDate(2456109, 43235.0, TimeStandard.TAI), 35), // July 1, 2012 00:00:00 UTC
  16914. new LeapSecond(new JulianDate(2457204, 43236.0, TimeStandard.TAI), 36), // July 1, 2015 00:00:00 UTC
  16915. new LeapSecond(new JulianDate(2457754, 43237.0, TimeStandard.TAI), 37) // January 1, 2017 00:00:00 UTC
  16916. ];
  16917. return JulianDate;
  16918. });
  16919. /*global define*/
  16920. define('Core/clone',[
  16921. './defaultValue'
  16922. ], function(
  16923. defaultValue) {
  16924. 'use strict';
  16925. /**
  16926. * Clones an object, returning a new object containing the same properties.
  16927. *
  16928. * @exports clone
  16929. *
  16930. * @param {Object} object The object to clone.
  16931. * @param {Boolean} [deep=false] If true, all properties will be deep cloned recursively.
  16932. * @returns {Object} The cloned object.
  16933. */
  16934. function clone(object, deep) {
  16935. if (object === null || typeof object !== 'object') {
  16936. return object;
  16937. }
  16938. deep = defaultValue(deep, false);
  16939. var result = new object.constructor();
  16940. for ( var propertyName in object) {
  16941. if (object.hasOwnProperty(propertyName)) {
  16942. var value = object[propertyName];
  16943. if (deep) {
  16944. value = clone(value, deep);
  16945. }
  16946. result[propertyName] = value;
  16947. }
  16948. }
  16949. return result;
  16950. }
  16951. return clone;
  16952. });
  16953. /*global define*/
  16954. define('Core/parseResponseHeaders',[], function() {
  16955. 'use strict';
  16956. /**
  16957. * Parses the result of XMLHttpRequest's getAllResponseHeaders() method into
  16958. * a dictionary.
  16959. *
  16960. * @exports parseResponseHeaders
  16961. *
  16962. * @param {String} headerString The header string returned by getAllResponseHeaders(). The format is
  16963. * described here: http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders()-method
  16964. * @returns {Object} A dictionary of key/value pairs, where each key is the name of a header and the corresponding value
  16965. * is that header's value.
  16966. *
  16967. * @private
  16968. */
  16969. function parseResponseHeaders(headerString) {
  16970. var headers = {};
  16971. if (!headerString) {
  16972. return headers;
  16973. }
  16974. var headerPairs = headerString.split('\u000d\u000a');
  16975. for (var i = 0; i < headerPairs.length; ++i) {
  16976. var headerPair = headerPairs[i];
  16977. // Can't use split() here because it does the wrong thing
  16978. // if the header value has the string ": " in it.
  16979. var index = headerPair.indexOf('\u003a\u0020');
  16980. if (index > 0) {
  16981. var key = headerPair.substring(0, index);
  16982. var val = headerPair.substring(index + 2);
  16983. headers[key] = val;
  16984. }
  16985. }
  16986. return headers;
  16987. }
  16988. return parseResponseHeaders;
  16989. });
  16990. /*global define*/
  16991. define('Core/RequestErrorEvent',[
  16992. './defined',
  16993. './parseResponseHeaders'
  16994. ], function(
  16995. defined,
  16996. parseResponseHeaders) {
  16997. 'use strict';
  16998. /**
  16999. * An event that is raised when a request encounters an error.
  17000. *
  17001. * @constructor
  17002. * @alias RequestErrorEvent
  17003. *
  17004. * @param {Number} [statusCode] The HTTP error status code, such as 404.
  17005. * @param {Object} [response] The response included along with the error.
  17006. * @param {String|Object} [responseHeaders] The response headers, represented either as an object literal or as a
  17007. * string in the format returned by XMLHttpRequest's getAllResponseHeaders() function.
  17008. */
  17009. function RequestErrorEvent(statusCode, response, responseHeaders) {
  17010. /**
  17011. * The HTTP error status code, such as 404. If the error does not have a particular
  17012. * HTTP code, this property will be undefined.
  17013. *
  17014. * @type {Number}
  17015. */
  17016. this.statusCode = statusCode;
  17017. /**
  17018. * The response included along with the error. If the error does not include a response,
  17019. * this property will be undefined.
  17020. *
  17021. * @type {Object}
  17022. */
  17023. this.response = response;
  17024. /**
  17025. * The headers included in the response, represented as an object literal of key/value pairs.
  17026. * If the error does not include any headers, this property will be undefined.
  17027. *
  17028. * @type {Object}
  17029. */
  17030. this.responseHeaders = responseHeaders;
  17031. if (typeof this.responseHeaders === 'string') {
  17032. this.responseHeaders = parseResponseHeaders(this.responseHeaders);
  17033. }
  17034. }
  17035. /**
  17036. * Creates a string representing this RequestErrorEvent.
  17037. * @memberof RequestErrorEvent
  17038. *
  17039. * @returns {String} A string representing the provided RequestErrorEvent.
  17040. */
  17041. RequestErrorEvent.prototype.toString = function() {
  17042. var str = 'Request has failed.';
  17043. if (defined(this.statusCode)) {
  17044. str += ' Status Code: ' + this.statusCode;
  17045. }
  17046. return str;
  17047. };
  17048. return RequestErrorEvent;
  17049. });
  17050. /**
  17051. * @license
  17052. *
  17053. * Grauw URI utilities
  17054. *
  17055. * See: http://hg.grauw.nl/grauw-lib/file/tip/src/uri.js
  17056. *
  17057. * @author Laurens Holst (http://www.grauw.nl/)
  17058. *
  17059. * Copyright 2012 Laurens Holst
  17060. *
  17061. * Licensed under the Apache License, Version 2.0 (the "License");
  17062. * you may not use this file except in compliance with the License.
  17063. * You may obtain a copy of the License at
  17064. *
  17065. * http://www.apache.org/licenses/LICENSE-2.0
  17066. *
  17067. * Unless required by applicable law or agreed to in writing, software
  17068. * distributed under the License is distributed on an "AS IS" BASIS,
  17069. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17070. * See the License for the specific language governing permissions and
  17071. * limitations under the License.
  17072. *
  17073. */
  17074. /*global define*/
  17075. define('ThirdParty/Uri',[],function() {
  17076. /**
  17077. * Constructs a URI object.
  17078. * @constructor
  17079. * @class Implementation of URI parsing and base URI resolving algorithm in RFC 3986.
  17080. * @param {string|URI} uri A string or URI object to create the object from.
  17081. */
  17082. function URI(uri) {
  17083. if (uri instanceof URI) { // copy constructor
  17084. this.scheme = uri.scheme;
  17085. this.authority = uri.authority;
  17086. this.path = uri.path;
  17087. this.query = uri.query;
  17088. this.fragment = uri.fragment;
  17089. } else if (uri) { // uri is URI string or cast to string
  17090. var c = parseRegex.exec(uri);
  17091. this.scheme = c[1];
  17092. this.authority = c[2];
  17093. this.path = c[3];
  17094. this.query = c[4];
  17095. this.fragment = c[5];
  17096. }
  17097. }
  17098. // Initial values on the prototype
  17099. URI.prototype.scheme = null;
  17100. URI.prototype.authority = null;
  17101. URI.prototype.path = '';
  17102. URI.prototype.query = null;
  17103. URI.prototype.fragment = null;
  17104. // Regular expression from RFC 3986 appendix B
  17105. var parseRegex = new RegExp('^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\\?([^#]*))?(?:#(.*))?$');
  17106. /**
  17107. * Returns the scheme part of the URI.
  17108. * In "http://example.com:80/a/b?x#y" this is "http".
  17109. */
  17110. URI.prototype.getScheme = function() {
  17111. return this.scheme;
  17112. };
  17113. /**
  17114. * Returns the authority part of the URI.
  17115. * In "http://example.com:80/a/b?x#y" this is "example.com:80".
  17116. */
  17117. URI.prototype.getAuthority = function() {
  17118. return this.authority;
  17119. };
  17120. /**
  17121. * Returns the path part of the URI.
  17122. * In "http://example.com:80/a/b?x#y" this is "/a/b".
  17123. * In "mailto:mike@example.com" this is "mike@example.com".
  17124. */
  17125. URI.prototype.getPath = function() {
  17126. return this.path;
  17127. };
  17128. /**
  17129. * Returns the query part of the URI.
  17130. * In "http://example.com:80/a/b?x#y" this is "x".
  17131. */
  17132. URI.prototype.getQuery = function() {
  17133. return this.query;
  17134. };
  17135. /**
  17136. * Returns the fragment part of the URI.
  17137. * In "http://example.com:80/a/b?x#y" this is "y".
  17138. */
  17139. URI.prototype.getFragment = function() {
  17140. return this.fragment;
  17141. };
  17142. /**
  17143. * Tests whether the URI is an absolute URI.
  17144. * See RFC 3986 section 4.3.
  17145. */
  17146. URI.prototype.isAbsolute = function() {
  17147. return !!this.scheme && !this.fragment;
  17148. };
  17149. ///**
  17150. //* Extensive validation of the URI against the ABNF in RFC 3986
  17151. //*/
  17152. //URI.prototype.validate
  17153. /**
  17154. * Tests whether the URI is a same-document reference.
  17155. * See RFC 3986 section 4.4.
  17156. *
  17157. * To perform more thorough comparison, you can normalise the URI objects.
  17158. */
  17159. URI.prototype.isSameDocumentAs = function(uri) {
  17160. return uri.scheme == this.scheme &&
  17161. uri.authority == this.authority &&
  17162. uri.path == this.path &&
  17163. uri.query == this.query;
  17164. };
  17165. /**
  17166. * Simple String Comparison of two URIs.
  17167. * See RFC 3986 section 6.2.1.
  17168. *
  17169. * To perform more thorough comparison, you can normalise the URI objects.
  17170. */
  17171. URI.prototype.equals = function(uri) {
  17172. return this.isSameDocumentAs(uri) && uri.fragment == this.fragment;
  17173. };
  17174. /**
  17175. * Normalizes the URI using syntax-based normalization.
  17176. * This includes case normalization, percent-encoding normalization and path segment normalization.
  17177. * XXX: Percent-encoding normalization does not escape characters that need to be escaped.
  17178. * (Although that would not be a valid URI in the first place. See validate().)
  17179. * See RFC 3986 section 6.2.2.
  17180. */
  17181. URI.prototype.normalize = function() {
  17182. this.removeDotSegments();
  17183. if (this.scheme)
  17184. this.scheme = this.scheme.toLowerCase();
  17185. if (this.authority)
  17186. this.authority = this.authority.replace(authorityRegex, replaceAuthority).
  17187. replace(caseRegex, replaceCase);
  17188. if (this.path)
  17189. this.path = this.path.replace(caseRegex, replaceCase);
  17190. if (this.query)
  17191. this.query = this.query.replace(caseRegex, replaceCase);
  17192. if (this.fragment)
  17193. this.fragment = this.fragment.replace(caseRegex, replaceCase);
  17194. };
  17195. var caseRegex = /%[0-9a-z]{2}/gi;
  17196. var percentRegex = /[a-zA-Z0-9\-\._~]/;
  17197. var authorityRegex = /(.*@)?([^@:]*)(:.*)?/;
  17198. function replaceCase(str) {
  17199. var dec = unescape(str);
  17200. return percentRegex.test(dec) ? dec : str.toUpperCase();
  17201. }
  17202. function replaceAuthority(str, p1, p2, p3) {
  17203. return (p1 || '') + p2.toLowerCase() + (p3 || '');
  17204. }
  17205. /**
  17206. * Resolve a relative URI (this) against a base URI.
  17207. * The base URI must be an absolute URI.
  17208. * See RFC 3986 section 5.2
  17209. */
  17210. URI.prototype.resolve = function(baseURI) {
  17211. var uri = new URI();
  17212. if (this.scheme) {
  17213. uri.scheme = this.scheme;
  17214. uri.authority = this.authority;
  17215. uri.path = this.path;
  17216. uri.query = this.query;
  17217. } else {
  17218. uri.scheme = baseURI.scheme;
  17219. if (this.authority) {
  17220. uri.authority = this.authority;
  17221. uri.path = this.path;
  17222. uri.query = this.query;
  17223. } else {
  17224. uri.authority = baseURI.authority;
  17225. if (this.path == '') {
  17226. uri.path = baseURI.path;
  17227. uri.query = this.query || baseURI.query;
  17228. } else {
  17229. if (this.path.charAt(0) == '/') {
  17230. uri.path = this.path;
  17231. uri.removeDotSegments();
  17232. } else {
  17233. if (baseURI.authority && baseURI.path == '') {
  17234. uri.path = '/' + this.path;
  17235. } else {
  17236. uri.path = baseURI.path.substring(0, baseURI.path.lastIndexOf('/') + 1) + this.path;
  17237. }
  17238. uri.removeDotSegments();
  17239. }
  17240. uri.query = this.query;
  17241. }
  17242. }
  17243. }
  17244. uri.fragment = this.fragment;
  17245. return uri;
  17246. };
  17247. /**
  17248. * Remove dot segments from path.
  17249. * See RFC 3986 section 5.2.4
  17250. * @private
  17251. */
  17252. URI.prototype.removeDotSegments = function() {
  17253. var input = this.path.split('/'),
  17254. output = [],
  17255. segment,
  17256. absPath = input[0] == '';
  17257. if (absPath)
  17258. input.shift();
  17259. var sFirst = input[0] == '' ? input.shift() : null;
  17260. while (input.length) {
  17261. segment = input.shift();
  17262. if (segment == '..') {
  17263. output.pop();
  17264. } else if (segment != '.') {
  17265. output.push(segment);
  17266. }
  17267. }
  17268. if (segment == '.' || segment == '..')
  17269. output.push('');
  17270. if (absPath)
  17271. output.unshift('');
  17272. this.path = output.join('/');
  17273. };
  17274. // We don't like this function because it builds up a cache that is never cleared.
  17275. // /**
  17276. // * Resolves a relative URI against an absolute base URI.
  17277. // * Convenience method.
  17278. // * @param {String} uri the relative URI to resolve
  17279. // * @param {String} baseURI the base URI (must be absolute) to resolve against
  17280. // */
  17281. // URI.resolve = function(sURI, sBaseURI) {
  17282. // var uri = cache[sURI] || (cache[sURI] = new URI(sURI));
  17283. // var baseURI = cache[sBaseURI] || (cache[sBaseURI] = new URI(sBaseURI));
  17284. // return uri.resolve(baseURI).toString();
  17285. // };
  17286. // var cache = {};
  17287. /**
  17288. * Serialises the URI to a string.
  17289. */
  17290. URI.prototype.toString = function() {
  17291. var result = '';
  17292. if (this.scheme)
  17293. result += this.scheme + ':';
  17294. if (this.authority)
  17295. result += '//' + this.authority;
  17296. result += this.path;
  17297. if (this.query)
  17298. result += '?' + this.query;
  17299. if (this.fragment)
  17300. result += '#' + this.fragment;
  17301. return result;
  17302. };
  17303. return URI;
  17304. });
  17305. /*global define*/
  17306. define('Core/TrustedServers',[
  17307. '../ThirdParty/Uri',
  17308. './defined',
  17309. './DeveloperError'
  17310. ], function(
  17311. Uri,
  17312. defined,
  17313. DeveloperError) {
  17314. 'use strict';
  17315. /**
  17316. * A singleton that contains all of the servers that are trusted. Credentials will be sent with
  17317. * any requests to these servers.
  17318. *
  17319. * @exports TrustedServers
  17320. *
  17321. * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}
  17322. */
  17323. var TrustedServers = {};
  17324. var _servers = {};
  17325. /**
  17326. * Adds a trusted server to the registry
  17327. *
  17328. * @param {String} host The host to be added.
  17329. * @param {Number} port The port used to access the host.
  17330. *
  17331. * @example
  17332. * // Add a trusted server
  17333. * TrustedServers.add('my.server.com', 80);
  17334. */
  17335. TrustedServers.add = function(host, port) {
  17336. if (!defined(host)) {
  17337. throw new DeveloperError('host is required.');
  17338. }
  17339. if (!defined(port) || port <= 0) {
  17340. throw new DeveloperError('port is required to be greater than 0.');
  17341. }
  17342. var authority = host.toLowerCase() + ':' + port;
  17343. if (!defined(_servers[authority])) {
  17344. _servers[authority] = true;
  17345. }
  17346. };
  17347. /**
  17348. * Removes a trusted server from the registry
  17349. *
  17350. * @param {String} host The host to be removed.
  17351. * @param {Number} port The port used to access the host.
  17352. *
  17353. * @example
  17354. * // Remove a trusted server
  17355. * TrustedServers.remove('my.server.com', 80);
  17356. */
  17357. TrustedServers.remove = function(host, port) {
  17358. if (!defined(host)) {
  17359. throw new DeveloperError('host is required.');
  17360. }
  17361. if (!defined(port) || port <= 0) {
  17362. throw new DeveloperError('port is required to be greater than 0.');
  17363. }
  17364. var authority = host.toLowerCase() + ':' + port;
  17365. if (defined(_servers[authority])) {
  17366. delete _servers[authority];
  17367. }
  17368. };
  17369. function getAuthority(url) {
  17370. var uri = new Uri(url);
  17371. uri.normalize();
  17372. // Removes username:password@ so we just have host[:port]
  17373. var authority = uri.getAuthority();
  17374. if (!defined(authority)) {
  17375. return undefined; // Relative URL
  17376. }
  17377. if (authority.indexOf('@') !== -1) {
  17378. var parts = authority.split('@');
  17379. authority = parts[1];
  17380. }
  17381. // If the port is missing add one based on the scheme
  17382. if (authority.indexOf(':') === -1) {
  17383. var scheme = uri.getScheme();
  17384. if (!defined(scheme)) {
  17385. scheme = window.location.protocol;
  17386. scheme = scheme.substring(0, scheme.length-1);
  17387. }
  17388. if (scheme === 'http') {
  17389. authority += ':80';
  17390. } else if (scheme === 'https') {
  17391. authority += ':443';
  17392. } else {
  17393. return undefined;
  17394. }
  17395. }
  17396. return authority;
  17397. }
  17398. /**
  17399. * Tests whether a server is trusted or not. The server must have been added with the port if it is included in the url.
  17400. *
  17401. * @param {String} url The url to be tested against the trusted list
  17402. *
  17403. * @returns {boolean} Returns true if url is trusted, false otherwise.
  17404. *
  17405. * @example
  17406. * // Add server
  17407. * TrustedServers.add('my.server.com', 81);
  17408. *
  17409. * // Check if server is trusted
  17410. * if (TrustedServers.contains('https://my.server.com:81/path/to/file.png')) {
  17411. * // my.server.com:81 is trusted
  17412. * }
  17413. * if (TrustedServers.contains('https://my.server.com/path/to/file.png')) {
  17414. * // my.server.com isn't trusted
  17415. * }
  17416. */
  17417. TrustedServers.contains = function(url) {
  17418. if (!defined(url)) {
  17419. throw new DeveloperError('url is required.');
  17420. }
  17421. var authority = getAuthority(url);
  17422. if (defined(authority) && defined(_servers[authority])) {
  17423. return true;
  17424. }
  17425. return false;
  17426. };
  17427. /**
  17428. * Clears the registry
  17429. *
  17430. * @example
  17431. * // Remove a trusted server
  17432. * TrustedServers.clear();
  17433. */
  17434. TrustedServers.clear = function() {
  17435. _servers = {};
  17436. };
  17437. return TrustedServers;
  17438. });
  17439. /*global define*/
  17440. define('Core/loadWithXhr',[
  17441. '../ThirdParty/when',
  17442. './defaultValue',
  17443. './defined',
  17444. './DeveloperError',
  17445. './RequestErrorEvent',
  17446. './RuntimeError',
  17447. './TrustedServers'
  17448. ], function(
  17449. when,
  17450. defaultValue,
  17451. defined,
  17452. DeveloperError,
  17453. RequestErrorEvent,
  17454. RuntimeError,
  17455. TrustedServers) {
  17456. 'use strict';
  17457. /**
  17458. * Asynchronously loads the given URL. Returns a promise that will resolve to
  17459. * the result once loaded, or reject if the URL failed to load. The data is loaded
  17460. * using XMLHttpRequest, which means that in order to make requests to another origin,
  17461. * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.
  17462. *
  17463. * @exports loadWithXhr
  17464. *
  17465. * @param {Object} options Object with the following properties:
  17466. * @param {String|Promise.<String>} options.url The URL of the data, or a promise for the URL.
  17467. * @param {String} [options.responseType] The type of response. This controls the type of item returned.
  17468. * @param {String} [options.method='GET'] The HTTP method to use.
  17469. * @param {String} [options.data] The data to send with the request, if any.
  17470. * @param {Object} [options.headers] HTTP headers to send with the request, if any.
  17471. * @param {String} [options.overrideMimeType] Overrides the MIME type returned by the server.
  17472. * @returns {Promise.<Object>} a promise that will resolve to the requested data when loaded.
  17473. *
  17474. *
  17475. * @example
  17476. * // Load a single URL asynchronously. In real code, you should use loadBlob instead.
  17477. * Cesium.loadWithXhr({
  17478. * url : 'some/url',
  17479. * responseType : 'blob'
  17480. * }).then(function(blob) {
  17481. * // use the data
  17482. * }).otherwise(function(error) {
  17483. * // an error occurred
  17484. * });
  17485. *
  17486. * @see loadArrayBuffer
  17487. * @see loadBlob
  17488. * @see loadJson
  17489. * @see loadText
  17490. * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}
  17491. * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}
  17492. */
  17493. function loadWithXhr(options) {
  17494. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  17495. if (!defined(options.url)) {
  17496. throw new DeveloperError('options.url is required.');
  17497. }
  17498. var responseType = options.responseType;
  17499. var method = defaultValue(options.method, 'GET');
  17500. var data = options.data;
  17501. var headers = options.headers;
  17502. var overrideMimeType = options.overrideMimeType;
  17503. return when(options.url, function(url) {
  17504. var deferred = when.defer();
  17505. loadWithXhr.load(url, responseType, method, data, headers, deferred, overrideMimeType);
  17506. return deferred.promise;
  17507. });
  17508. }
  17509. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  17510. function decodeDataUriText(isBase64, data) {
  17511. var result = decodeURIComponent(data);
  17512. if (isBase64) {
  17513. return atob(result);
  17514. }
  17515. return result;
  17516. }
  17517. function decodeDataUriArrayBuffer(isBase64, data) {
  17518. var byteString = decodeDataUriText(isBase64, data);
  17519. var buffer = new ArrayBuffer(byteString.length);
  17520. var view = new Uint8Array(buffer);
  17521. for (var i = 0; i < byteString.length; i++) {
  17522. view[i] = byteString.charCodeAt(i);
  17523. }
  17524. return buffer;
  17525. }
  17526. function decodeDataUri(dataUriRegexResult, responseType) {
  17527. responseType = defaultValue(responseType, '');
  17528. var mimeType = dataUriRegexResult[1];
  17529. var isBase64 = !!dataUriRegexResult[2];
  17530. var data = dataUriRegexResult[3];
  17531. switch (responseType) {
  17532. case '':
  17533. case 'text':
  17534. return decodeDataUriText(isBase64, data);
  17535. case 'arraybuffer':
  17536. return decodeDataUriArrayBuffer(isBase64, data);
  17537. case 'blob':
  17538. var buffer = decodeDataUriArrayBuffer(isBase64, data);
  17539. return new Blob([buffer], {
  17540. type : mimeType
  17541. });
  17542. case 'document':
  17543. var parser = new DOMParser();
  17544. return parser.parseFromString(decodeDataUriText(isBase64, data), mimeType);
  17545. case 'json':
  17546. return JSON.parse(decodeDataUriText(isBase64, data));
  17547. default:
  17548. throw new DeveloperError('Unhandled responseType: ' + responseType);
  17549. }
  17550. }
  17551. // This is broken out into a separate function so that it can be mocked for testing purposes.
  17552. loadWithXhr.load = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
  17553. var dataUriRegexResult = dataUriRegex.exec(url);
  17554. if (dataUriRegexResult !== null) {
  17555. deferred.resolve(decodeDataUri(dataUriRegexResult, responseType));
  17556. return;
  17557. }
  17558. var xhr = new XMLHttpRequest();
  17559. if (TrustedServers.contains(url)) {
  17560. xhr.withCredentials = true;
  17561. }
  17562. if (defined(overrideMimeType) && defined(xhr.overrideMimeType)) {
  17563. xhr.overrideMimeType(overrideMimeType);
  17564. }
  17565. xhr.open(method, url, true);
  17566. if (defined(headers)) {
  17567. for (var key in headers) {
  17568. if (headers.hasOwnProperty(key)) {
  17569. xhr.setRequestHeader(key, headers[key]);
  17570. }
  17571. }
  17572. }
  17573. if (defined(responseType)) {
  17574. xhr.responseType = responseType;
  17575. }
  17576. xhr.onload = function() {
  17577. if (xhr.status < 200 || xhr.status >= 300) {
  17578. deferred.reject(new RequestErrorEvent(xhr.status, xhr.response, xhr.getAllResponseHeaders()));
  17579. return;
  17580. }
  17581. var response = xhr.response;
  17582. var browserResponseType = xhr.responseType;
  17583. //All modern browsers will go into either the first if block or last else block.
  17584. //Other code paths support older browsers that either do not support the supplied responseType
  17585. //or do not support the xhr.response property.
  17586. if (defined(response) && (!defined(responseType) || (browserResponseType === responseType))) {
  17587. deferred.resolve(response);
  17588. } else if ((responseType === 'json') && typeof response === 'string') {
  17589. try {
  17590. deferred.resolve(JSON.parse(response));
  17591. } catch (e) {
  17592. deferred.reject(e);
  17593. }
  17594. } else if ((browserResponseType === '' || browserResponseType === 'document') && defined(xhr.responseXML) && xhr.responseXML.hasChildNodes()) {
  17595. deferred.resolve(xhr.responseXML);
  17596. } else if ((browserResponseType === '' || browserResponseType === 'text') && defined(xhr.responseText)) {
  17597. deferred.resolve(xhr.responseText);
  17598. } else {
  17599. deferred.reject(new RuntimeError('Invalid XMLHttpRequest response type.'));
  17600. }
  17601. };
  17602. xhr.onerror = function(e) {
  17603. deferred.reject(new RequestErrorEvent());
  17604. };
  17605. xhr.send(data);
  17606. };
  17607. loadWithXhr.defaultLoad = loadWithXhr.load;
  17608. return loadWithXhr;
  17609. });
  17610. /*global define*/
  17611. define('Core/loadText',[
  17612. './loadWithXhr'
  17613. ], function(
  17614. loadWithXhr) {
  17615. 'use strict';
  17616. /**
  17617. * Asynchronously loads the given URL as text. Returns a promise that will resolve to
  17618. * a String once loaded, or reject if the URL failed to load. The data is loaded
  17619. * using XMLHttpRequest, which means that in order to make requests to another origin,
  17620. * the server must have Cross-Origin Resource Sharing (CORS) headers enabled.
  17621. *
  17622. * @exports loadText
  17623. *
  17624. * @param {String|Promise.<String>} url The URL to request, or a promise for the URL.
  17625. * @param {Object} [headers] HTTP headers to send with the request.
  17626. * @returns {Promise.<String>} a promise that will resolve to the requested data when loaded.
  17627. *
  17628. *
  17629. * @example
  17630. * // load text from a URL, setting a custom header
  17631. * Cesium.loadText('http://someUrl.com/someJson.txt', {
  17632. * 'X-Custom-Header' : 'some value'
  17633. * }).then(function(text) {
  17634. * // Do something with the text
  17635. * }).otherwise(function(error) {
  17636. * // an error occurred
  17637. * });
  17638. *
  17639. * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest|XMLHttpRequest}
  17640. * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}
  17641. * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}
  17642. */
  17643. function loadText(url, headers) {
  17644. return loadWithXhr({
  17645. url : url,
  17646. headers : headers
  17647. });
  17648. }
  17649. return loadText;
  17650. });
  17651. /*global define*/
  17652. define('Core/loadJson',[
  17653. './clone',
  17654. './defined',
  17655. './DeveloperError',
  17656. './loadText'
  17657. ], function(
  17658. clone,
  17659. defined,
  17660. DeveloperError,
  17661. loadText) {
  17662. 'use strict';
  17663. var defaultHeaders = {
  17664. Accept : 'application/json,*/*;q=0.01'
  17665. };
  17666. // note: &#42;&#47;&#42; below is */* but that ends the comment block early
  17667. /**
  17668. * Asynchronously loads the given URL as JSON. Returns a promise that will resolve to
  17669. * a JSON object once loaded, or reject if the URL failed to load. The data is loaded
  17670. * using XMLHttpRequest, which means that in order to make requests to another origin,
  17671. * the server must have Cross-Origin Resource Sharing (CORS) headers enabled. This function
  17672. * adds 'Accept: application/json,&#42;&#47;&#42;;q=0.01' to the request headers, if not
  17673. * already specified.
  17674. *
  17675. * @exports loadJson
  17676. *
  17677. * @param {String|Promise.<String>} url The URL to request, or a promise for the URL.
  17678. * @param {Object} [headers] HTTP headers to send with the request.
  17679. * 'Accept: application/json,&#42;&#47;&#42;;q=0.01' is added to the request headers automatically
  17680. * if not specified.
  17681. * @returns {Promise.<Object>} a promise that will resolve to the requested data when loaded.
  17682. *
  17683. *
  17684. * @example
  17685. * Cesium.loadJson('http://someUrl.com/someJson.txt').then(function(jsonData) {
  17686. * // Do something with the JSON object
  17687. * }).otherwise(function(error) {
  17688. * // an error occurred
  17689. * });
  17690. *
  17691. * @see loadText
  17692. * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}
  17693. * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A}
  17694. */
  17695. function loadJson(url, headers) {
  17696. if (!defined(url)) {
  17697. throw new DeveloperError('url is required.');
  17698. }
  17699. if (!defined(headers)) {
  17700. headers = defaultHeaders;
  17701. } else if (!defined(headers.Accept)) {
  17702. // clone before adding the Accept header
  17703. headers = clone(headers);
  17704. headers.Accept = defaultHeaders.Accept;
  17705. }
  17706. return loadText(url, headers).then(function(value) {
  17707. return JSON.parse(value);
  17708. });
  17709. }
  17710. return loadJson;
  17711. });
  17712. /*global define*/
  17713. define('Core/EarthOrientationParameters',[
  17714. '../ThirdParty/when',
  17715. './binarySearch',
  17716. './defaultValue',
  17717. './defined',
  17718. './EarthOrientationParametersSample',
  17719. './freezeObject',
  17720. './JulianDate',
  17721. './LeapSecond',
  17722. './loadJson',
  17723. './RuntimeError',
  17724. './TimeConstants',
  17725. './TimeStandard'
  17726. ], function(
  17727. when,
  17728. binarySearch,
  17729. defaultValue,
  17730. defined,
  17731. EarthOrientationParametersSample,
  17732. freezeObject,
  17733. JulianDate,
  17734. LeapSecond,
  17735. loadJson,
  17736. RuntimeError,
  17737. TimeConstants,
  17738. TimeStandard) {
  17739. 'use strict';
  17740. /**
  17741. * Specifies Earth polar motion coordinates and the difference between UT1 and UTC.
  17742. * These Earth Orientation Parameters (EOP) are primarily used in the transformation from
  17743. * the International Celestial Reference Frame (ICRF) to the International Terrestrial
  17744. * Reference Frame (ITRF).
  17745. *
  17746. * @alias EarthOrientationParameters
  17747. * @constructor
  17748. *
  17749. * @param {Object} [options] Object with the following properties:
  17750. * @param {String} [options.url] The URL from which to obtain EOP data. If neither this
  17751. * parameter nor options.data is specified, all EOP values are assumed
  17752. * to be 0.0. If options.data is specified, this parameter is
  17753. * ignored.
  17754. * @param {Object} [options.data] The actual EOP data. If neither this
  17755. * parameter nor options.data is specified, all EOP values are assumed
  17756. * to be 0.0.
  17757. * @param {Boolean} [options.addNewLeapSeconds=true] True if leap seconds that
  17758. * are specified in the EOP data but not in {@link JulianDate.leapSeconds}
  17759. * should be added to {@link JulianDate.leapSeconds}. False if
  17760. * new leap seconds should be handled correctly in the context
  17761. * of the EOP data but otherwise ignored.
  17762. *
  17763. * @example
  17764. * // An example EOP data file, EOP.json:
  17765. * {
  17766. * "columnNames" : ["dateIso8601","modifiedJulianDateUtc","xPoleWanderRadians","yPoleWanderRadians","ut1MinusUtcSeconds","lengthOfDayCorrectionSeconds","xCelestialPoleOffsetRadians","yCelestialPoleOffsetRadians","taiMinusUtcSeconds"],
  17767. * "samples" : [
  17768. * "2011-07-01T00:00:00Z",55743.0,2.117957047295119e-7,2.111518721609984e-6,-0.2908948,-2.956e-4,3.393695767766752e-11,3.3452143996557983e-10,34.0,
  17769. * "2011-07-02T00:00:00Z",55744.0,2.193297093339541e-7,2.115460256837405e-6,-0.29065,-1.824e-4,-8.241832578862112e-11,5.623838700870617e-10,34.0,
  17770. * "2011-07-03T00:00:00Z",55745.0,2.262286080161428e-7,2.1191157519929706e-6,-0.2905572,1.9e-6,-3.490658503988659e-10,6.981317007977318e-10,34.0
  17771. * ]
  17772. * }
  17773. *
  17774. * @example
  17775. * // Loading the EOP data
  17776. * var eop = new Cesium.EarthOrientationParameters({ url : 'Data/EOP.json' });
  17777. * Cesium.Transforms.earthOrientationParameters = eop;
  17778. *
  17779. * @private
  17780. */
  17781. function EarthOrientationParameters(options) {
  17782. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  17783. this._dates = undefined;
  17784. this._samples = undefined;
  17785. this._dateColumn = -1;
  17786. this._xPoleWanderRadiansColumn = -1;
  17787. this._yPoleWanderRadiansColumn = -1;
  17788. this._ut1MinusUtcSecondsColumn = -1;
  17789. this._xCelestialPoleOffsetRadiansColumn = -1;
  17790. this._yCelestialPoleOffsetRadiansColumn = -1;
  17791. this._taiMinusUtcSecondsColumn = -1;
  17792. this._columnCount = 0;
  17793. this._lastIndex = -1;
  17794. this._downloadPromise = undefined;
  17795. this._dataError = undefined;
  17796. this._addNewLeapSeconds = defaultValue(options.addNewLeapSeconds, true);
  17797. if (defined(options.data)) {
  17798. // Use supplied EOP data.
  17799. onDataReady(this, options.data);
  17800. } else if (defined(options.url)) {
  17801. // Download EOP data.
  17802. var that = this;
  17803. this._downloadPromise = when(loadJson(options.url), function(eopData) {
  17804. onDataReady(that, eopData);
  17805. }, function() {
  17806. that._dataError = 'An error occurred while retrieving the EOP data from the URL ' + options.url + '.';
  17807. });
  17808. } else {
  17809. // Use all zeros for EOP data.
  17810. onDataReady(this, {
  17811. 'columnNames' : ['dateIso8601', 'modifiedJulianDateUtc', 'xPoleWanderRadians', 'yPoleWanderRadians', 'ut1MinusUtcSeconds', 'lengthOfDayCorrectionSeconds', 'xCelestialPoleOffsetRadians', 'yCelestialPoleOffsetRadians', 'taiMinusUtcSeconds'],
  17812. 'samples' : []
  17813. });
  17814. }
  17815. }
  17816. /**
  17817. * A default {@link EarthOrientationParameters} instance that returns zero for all EOP values.
  17818. */
  17819. EarthOrientationParameters.NONE = freezeObject({
  17820. getPromiseToLoad : function() {
  17821. return when();
  17822. },
  17823. compute : function(date, result) {
  17824. if (!defined(result)) {
  17825. result = new EarthOrientationParametersSample(0.0, 0.0, 0.0, 0.0, 0.0);
  17826. } else {
  17827. result.xPoleWander = 0.0;
  17828. result.yPoleWander = 0.0;
  17829. result.xPoleOffset = 0.0;
  17830. result.yPoleOffset = 0.0;
  17831. result.ut1MinusUtc = 0.0;
  17832. }
  17833. return result;
  17834. }
  17835. });
  17836. /**
  17837. * Gets a promise that, when resolved, indicates that the EOP data has been loaded and is
  17838. * ready to use.
  17839. *
  17840. * @returns {Promise.<undefined>} The promise.
  17841. *
  17842. * @see when
  17843. */
  17844. EarthOrientationParameters.prototype.getPromiseToLoad = function() {
  17845. return when(this._downloadPromise);
  17846. };
  17847. /**
  17848. * Computes the Earth Orientation Parameters (EOP) for a given date by interpolating.
  17849. * If the EOP data has not yet been download, this method returns undefined.
  17850. *
  17851. * @param {JulianDate} date The date for each to evaluate the EOP.
  17852. * @param {EarthOrientationParametersSample} [result] The instance to which to copy the result.
  17853. * If this parameter is undefined, a new instance is created and returned.
  17854. * @returns {EarthOrientationParametersSample} The EOP evaluated at the given date, or
  17855. * undefined if the data necessary to evaluate EOP at the date has not yet been
  17856. * downloaded.
  17857. *
  17858. * @exception {RuntimeError} The loaded EOP data has an error and cannot be used.
  17859. *
  17860. * @see EarthOrientationParameters#getPromiseToLoad
  17861. */
  17862. EarthOrientationParameters.prototype.compute = function(date, result) {
  17863. // We cannot compute until the samples are available.
  17864. if (!defined(this._samples)) {
  17865. if (defined(this._dataError)) {
  17866. throw new RuntimeError(this._dataError);
  17867. }
  17868. return undefined;
  17869. }
  17870. if (!defined(result)) {
  17871. result = new EarthOrientationParametersSample(0.0, 0.0, 0.0, 0.0, 0.0);
  17872. }
  17873. if (this._samples.length === 0) {
  17874. result.xPoleWander = 0.0;
  17875. result.yPoleWander = 0.0;
  17876. result.xPoleOffset = 0.0;
  17877. result.yPoleOffset = 0.0;
  17878. result.ut1MinusUtc = 0.0;
  17879. return result;
  17880. }
  17881. var dates = this._dates;
  17882. var lastIndex = this._lastIndex;
  17883. var before = 0;
  17884. var after = 0;
  17885. if (defined(lastIndex)) {
  17886. var previousIndexDate = dates[lastIndex];
  17887. var nextIndexDate = dates[lastIndex + 1];
  17888. var isAfterPrevious = JulianDate.lessThanOrEquals(previousIndexDate, date);
  17889. var isAfterLastSample = !defined(nextIndexDate);
  17890. var isBeforeNext = isAfterLastSample || JulianDate.greaterThanOrEquals(nextIndexDate, date);
  17891. if (isAfterPrevious && isBeforeNext) {
  17892. before = lastIndex;
  17893. if (!isAfterLastSample && nextIndexDate.equals(date)) {
  17894. ++before;
  17895. }
  17896. after = before + 1;
  17897. interpolate(this, dates, this._samples, date, before, after, result);
  17898. return result;
  17899. }
  17900. }
  17901. var index = binarySearch(dates, date, JulianDate.compare, this._dateColumn);
  17902. if (index >= 0) {
  17903. // If the next entry is the same date, use the later entry. This way, if two entries
  17904. // describe the same moment, one before a leap second and the other after, then we will use
  17905. // the post-leap second data.
  17906. if (index < dates.length - 1 && dates[index + 1].equals(date)) {
  17907. ++index;
  17908. }
  17909. before = index;
  17910. after = index;
  17911. } else {
  17912. after = ~index;
  17913. before = after - 1;
  17914. // Use the first entry if the date requested is before the beginning of the data.
  17915. if (before < 0) {
  17916. before = 0;
  17917. }
  17918. }
  17919. this._lastIndex = before;
  17920. interpolate(this, dates, this._samples, date, before, after, result);
  17921. return result;
  17922. };
  17923. function compareLeapSecondDates(leapSecond, dateToFind) {
  17924. return JulianDate.compare(leapSecond.julianDate, dateToFind);
  17925. }
  17926. function onDataReady(eop, eopData) {
  17927. if (!defined(eopData.columnNames)) {
  17928. eop._dataError = 'Error in loaded EOP data: The columnNames property is required.';
  17929. return;
  17930. }
  17931. if (!defined(eopData.samples)) {
  17932. eop._dataError = 'Error in loaded EOP data: The samples property is required.';
  17933. return;
  17934. }
  17935. var dateColumn = eopData.columnNames.indexOf('modifiedJulianDateUtc');
  17936. var xPoleWanderRadiansColumn = eopData.columnNames.indexOf('xPoleWanderRadians');
  17937. var yPoleWanderRadiansColumn = eopData.columnNames.indexOf('yPoleWanderRadians');
  17938. var ut1MinusUtcSecondsColumn = eopData.columnNames.indexOf('ut1MinusUtcSeconds');
  17939. var xCelestialPoleOffsetRadiansColumn = eopData.columnNames.indexOf('xCelestialPoleOffsetRadians');
  17940. var yCelestialPoleOffsetRadiansColumn = eopData.columnNames.indexOf('yCelestialPoleOffsetRadians');
  17941. var taiMinusUtcSecondsColumn = eopData.columnNames.indexOf('taiMinusUtcSeconds');
  17942. if (dateColumn < 0 || xPoleWanderRadiansColumn < 0 || yPoleWanderRadiansColumn < 0 || ut1MinusUtcSecondsColumn < 0 || xCelestialPoleOffsetRadiansColumn < 0 || yCelestialPoleOffsetRadiansColumn < 0 || taiMinusUtcSecondsColumn < 0) {
  17943. eop._dataError = 'Error in loaded EOP data: The columnNames property must include modifiedJulianDateUtc, xPoleWanderRadians, yPoleWanderRadians, ut1MinusUtcSeconds, xCelestialPoleOffsetRadians, yCelestialPoleOffsetRadians, and taiMinusUtcSeconds columns';
  17944. return;
  17945. }
  17946. var samples = eop._samples = eopData.samples;
  17947. var dates = eop._dates = [];
  17948. eop._dateColumn = dateColumn;
  17949. eop._xPoleWanderRadiansColumn = xPoleWanderRadiansColumn;
  17950. eop._yPoleWanderRadiansColumn = yPoleWanderRadiansColumn;
  17951. eop._ut1MinusUtcSecondsColumn = ut1MinusUtcSecondsColumn;
  17952. eop._xCelestialPoleOffsetRadiansColumn = xCelestialPoleOffsetRadiansColumn;
  17953. eop._yCelestialPoleOffsetRadiansColumn = yCelestialPoleOffsetRadiansColumn;
  17954. eop._taiMinusUtcSecondsColumn = taiMinusUtcSecondsColumn;
  17955. eop._columnCount = eopData.columnNames.length;
  17956. eop._lastIndex = undefined;
  17957. var lastTaiMinusUtc;
  17958. var addNewLeapSeconds = eop._addNewLeapSeconds;
  17959. // Convert the ISO8601 dates to JulianDates.
  17960. for (var i = 0, len = samples.length; i < len; i += eop._columnCount) {
  17961. var mjd = samples[i + dateColumn];
  17962. var taiMinusUtc = samples[i + taiMinusUtcSecondsColumn];
  17963. var day = mjd + TimeConstants.MODIFIED_JULIAN_DATE_DIFFERENCE;
  17964. var date = new JulianDate(day, taiMinusUtc, TimeStandard.TAI);
  17965. dates.push(date);
  17966. if (addNewLeapSeconds) {
  17967. if (taiMinusUtc !== lastTaiMinusUtc && defined(lastTaiMinusUtc)) {
  17968. // We crossed a leap second boundary, so add the leap second
  17969. // if it does not already exist.
  17970. var leapSeconds = JulianDate.leapSeconds;
  17971. var leapSecondIndex = binarySearch(leapSeconds, date, compareLeapSecondDates);
  17972. if (leapSecondIndex < 0) {
  17973. var leapSecond = new LeapSecond(date, taiMinusUtc);
  17974. leapSeconds.splice(~leapSecondIndex, 0, leapSecond);
  17975. }
  17976. }
  17977. lastTaiMinusUtc = taiMinusUtc;
  17978. }
  17979. }
  17980. }
  17981. function fillResultFromIndex(eop, samples, index, columnCount, result) {
  17982. var start = index * columnCount;
  17983. result.xPoleWander = samples[start + eop._xPoleWanderRadiansColumn];
  17984. result.yPoleWander = samples[start + eop._yPoleWanderRadiansColumn];
  17985. result.xPoleOffset = samples[start + eop._xCelestialPoleOffsetRadiansColumn];
  17986. result.yPoleOffset = samples[start + eop._yCelestialPoleOffsetRadiansColumn];
  17987. result.ut1MinusUtc = samples[start + eop._ut1MinusUtcSecondsColumn];
  17988. }
  17989. function linearInterp(dx, y1, y2) {
  17990. return y1 + dx * (y2 - y1);
  17991. }
  17992. function interpolate(eop, dates, samples, date, before, after, result) {
  17993. var columnCount = eop._columnCount;
  17994. // First check the bounds on the EOP data
  17995. // If we are after the bounds of the data, return zeros.
  17996. // The 'before' index should never be less than zero.
  17997. if (after > dates.length - 1) {
  17998. result.xPoleWander = 0;
  17999. result.yPoleWander = 0;
  18000. result.xPoleOffset = 0;
  18001. result.yPoleOffset = 0;
  18002. result.ut1MinusUtc = 0;
  18003. return result;
  18004. }
  18005. var beforeDate = dates[before];
  18006. var afterDate = dates[after];
  18007. if (beforeDate.equals(afterDate) || date.equals(beforeDate)) {
  18008. fillResultFromIndex(eop, samples, before, columnCount, result);
  18009. return result;
  18010. } else if (date.equals(afterDate)) {
  18011. fillResultFromIndex(eop, samples, after, columnCount, result);
  18012. return result;
  18013. }
  18014. var factor = JulianDate.secondsDifference(date, beforeDate) / JulianDate.secondsDifference(afterDate, beforeDate);
  18015. var startBefore = before * columnCount;
  18016. var startAfter = after * columnCount;
  18017. // Handle UT1 leap second edge case
  18018. var beforeUt1MinusUtc = samples[startBefore + eop._ut1MinusUtcSecondsColumn];
  18019. var afterUt1MinusUtc = samples[startAfter + eop._ut1MinusUtcSecondsColumn];
  18020. var offsetDifference = afterUt1MinusUtc - beforeUt1MinusUtc;
  18021. if (offsetDifference > 0.5 || offsetDifference < -0.5) {
  18022. // The absolute difference between the values is more than 0.5, so we may have
  18023. // crossed a leap second. Check if this is the case and, if so, adjust the
  18024. // afterValue to account for the leap second. This way, our interpolation will
  18025. // produce reasonable results.
  18026. var beforeTaiMinusUtc = samples[startBefore + eop._taiMinusUtcSecondsColumn];
  18027. var afterTaiMinusUtc = samples[startAfter + eop._taiMinusUtcSecondsColumn];
  18028. if (beforeTaiMinusUtc !== afterTaiMinusUtc) {
  18029. if (afterDate.equals(date)) {
  18030. // If we are at the end of the leap second interval, take the second value
  18031. // Otherwise, the interpolation below will yield the wrong side of the
  18032. // discontinuity
  18033. // At the end of the leap second, we need to start accounting for the jump
  18034. beforeUt1MinusUtc = afterUt1MinusUtc;
  18035. } else {
  18036. // Otherwise, remove the leap second so that the interpolation is correct
  18037. afterUt1MinusUtc -= afterTaiMinusUtc - beforeTaiMinusUtc;
  18038. }
  18039. }
  18040. }
  18041. result.xPoleWander = linearInterp(factor, samples[startBefore + eop._xPoleWanderRadiansColumn], samples[startAfter + eop._xPoleWanderRadiansColumn]);
  18042. result.yPoleWander = linearInterp(factor, samples[startBefore + eop._yPoleWanderRadiansColumn], samples[startAfter + eop._yPoleWanderRadiansColumn]);
  18043. result.xPoleOffset = linearInterp(factor, samples[startBefore + eop._xCelestialPoleOffsetRadiansColumn], samples[startAfter + eop._xCelestialPoleOffsetRadiansColumn]);
  18044. result.yPoleOffset = linearInterp(factor, samples[startBefore + eop._yCelestialPoleOffsetRadiansColumn], samples[startAfter + eop._yCelestialPoleOffsetRadiansColumn]);
  18045. result.ut1MinusUtc = linearInterp(factor, beforeUt1MinusUtc, afterUt1MinusUtc);
  18046. return result;
  18047. }
  18048. return EarthOrientationParameters;
  18049. });
  18050. /*global define*/
  18051. define('Core/HeadingPitchRoll',[
  18052. './defaultValue',
  18053. './defined',
  18054. './DeveloperError',
  18055. './Math'
  18056. ], function(
  18057. defaultValue,
  18058. defined,
  18059. DeveloperError,
  18060. CesiumMath) {
  18061. "use strict";
  18062. /**
  18063. * A rotation expressed as a heading, pitch, and roll. Heading is the rotation about the
  18064. * negative z axis. Pitch is the rotation about the negative y axis. Roll is the rotation about
  18065. * the positive x axis.
  18066. * @alias HeadingPitchRoll
  18067. * @constructor
  18068. *
  18069. * @param {Number} [heading=0.0] The heading component in radians.
  18070. * @param {Number} [pitch=0.0] The pitch component in radians.
  18071. * @param {Number} [roll=0.0] The roll component in radians.
  18072. */
  18073. function HeadingPitchRoll(heading, pitch, roll) {
  18074. this.heading = defaultValue(heading, 0.0);
  18075. this.pitch = defaultValue(pitch, 0.0);
  18076. this.roll = defaultValue(roll, 0.0);
  18077. }
  18078. /**
  18079. * Computes the heading, pitch and roll from a quaternion (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )
  18080. *
  18081. * @param {Quaternion} quaternion The quaternion from which to retrieve heading, pitch, and roll, all expressed in radians.
  18082. * @param {Quaternion} [result] The object in which to store the result. If not provided, a new instance is created and returned.
  18083. * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided.
  18084. */
  18085. HeadingPitchRoll.fromQuaternion = function(quaternion, result) {
  18086. if (!defined(quaternion)) {
  18087. throw new DeveloperError('quaternion is required');
  18088. }
  18089. if (!defined(result)) {
  18090. result = new HeadingPitchRoll();
  18091. }
  18092. var test = 2 * (quaternion.w * quaternion.y - quaternion.z * quaternion.x);
  18093. var denominatorRoll = 1 - 2 * (quaternion.x * quaternion.x + quaternion.y * quaternion.y);
  18094. var numeratorRoll = 2 * (quaternion.w * quaternion.x + quaternion.y * quaternion.z);
  18095. var denominatorHeading = 1 - 2 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z);
  18096. var numeratorHeading = 2 * (quaternion.w * quaternion.z + quaternion.x * quaternion.y);
  18097. result.heading = -Math.atan2(numeratorHeading, denominatorHeading);
  18098. result.roll = Math.atan2(numeratorRoll, denominatorRoll);
  18099. result.pitch = -Math.asin(test);
  18100. return result;
  18101. };
  18102. /**
  18103. * Returns a new HeadingPitchRoll instance from angles given in degrees.
  18104. *
  18105. * @param {Number} heading the heading in degrees
  18106. * @param {Number} pitch the pitch in degrees
  18107. * @param {Number} roll the heading in degrees
  18108. * @param {HeadingPitchRoll} [result] The object in which to store the result. If not provided, a new instance is created and returned.
  18109. * @returns {HeadingPitchRoll} A new HeadingPitchRoll instance
  18110. */
  18111. HeadingPitchRoll.fromDegrees = function(heading, pitch, roll, result) {
  18112. if (!defined(heading)) {
  18113. throw new DeveloperError('heading is required');
  18114. }
  18115. if (!defined(pitch)) {
  18116. throw new DeveloperError('pitch is required');
  18117. }
  18118. if (!defined(roll)) {
  18119. throw new DeveloperError('roll is required');
  18120. }
  18121. if (!defined(result)) {
  18122. result = new HeadingPitchRoll();
  18123. }
  18124. result.heading = heading * CesiumMath.RADIANS_PER_DEGREE;
  18125. result.pitch = pitch * CesiumMath.RADIANS_PER_DEGREE;
  18126. result.roll = roll * CesiumMath.RADIANS_PER_DEGREE;
  18127. return result;
  18128. };
  18129. /**
  18130. * Duplicates a HeadingPitchRoll instance.
  18131. *
  18132. * @param {HeadingPitchRoll} headingPitchRoll The HeadingPitchRoll to duplicate.
  18133. * @param {HeadingPitchRoll} [result] The object onto which to store the result.
  18134. * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided. (Returns undefined if headingPitchRoll is undefined)
  18135. */
  18136. HeadingPitchRoll.clone = function(headingPitchRoll, result) {
  18137. if (!defined(headingPitchRoll)) {
  18138. return undefined;
  18139. }
  18140. if (!defined(result)) {
  18141. return new HeadingPitchRoll(headingPitchRoll.heading, headingPitchRoll.pitch, headingPitchRoll.roll);
  18142. }
  18143. result.heading = headingPitchRoll.heading;
  18144. result.pitch = headingPitchRoll.pitch;
  18145. result.roll = headingPitchRoll.roll;
  18146. return result;
  18147. };
  18148. /**
  18149. * Compares the provided HeadingPitchRolls componentwise and returns
  18150. * <code>true</code> if they are equal, <code>false</code> otherwise.
  18151. *
  18152. * @param {HeadingPitchRoll} [left] The first HeadingPitchRoll.
  18153. * @param {HeadingPitchRoll} [right] The second HeadingPitchRoll.
  18154. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  18155. */
  18156. HeadingPitchRoll.equals = function(left, right) {
  18157. return (left === right) ||
  18158. ((defined(left)) &&
  18159. (defined(right)) &&
  18160. (left.heading === right.heading) &&
  18161. (left.pitch === right.pitch) &&
  18162. (left.roll === right.roll));
  18163. };
  18164. /**
  18165. * Compares the provided HeadingPitchRolls componentwise and returns
  18166. * <code>true</code> if they pass an absolute or relative tolerance test,
  18167. * <code>false</code> otherwise.
  18168. *
  18169. * @param {HeadingPitchRoll} [left] The first HeadingPitchRoll.
  18170. * @param {HeadingPitchRoll} [right] The second HeadingPitchRoll.
  18171. * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
  18172. * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  18173. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  18174. */
  18175. HeadingPitchRoll.equalsEpsilon = function(left, right, relativeEpsilon, absoluteEpsilon) {
  18176. return (left === right) ||
  18177. (defined(left) &&
  18178. defined(right) &&
  18179. CesiumMath.equalsEpsilon(left.heading, right.heading, relativeEpsilon, absoluteEpsilon) &&
  18180. CesiumMath.equalsEpsilon(left.pitch, right.pitch, relativeEpsilon, absoluteEpsilon) &&
  18181. CesiumMath.equalsEpsilon(left.roll, right.roll, relativeEpsilon, absoluteEpsilon));
  18182. };
  18183. /**
  18184. * Duplicates this HeadingPitchRoll instance.
  18185. *
  18186. * @param {HeadingPitchRoll} [result] The object onto which to store the result.
  18187. * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided.
  18188. */
  18189. HeadingPitchRoll.prototype.clone = function(result) {
  18190. return HeadingPitchRoll.clone(this, result);
  18191. };
  18192. /**
  18193. * Compares this HeadingPitchRoll against the provided HeadingPitchRoll componentwise and returns
  18194. * <code>true</code> if they are equal, <code>false</code> otherwise.
  18195. *
  18196. * @param {HeadingPitchRoll} [right] The right hand side HeadingPitchRoll.
  18197. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  18198. */
  18199. HeadingPitchRoll.prototype.equals = function(right) {
  18200. return HeadingPitchRoll.equals(this, right);
  18201. };
  18202. /**
  18203. * Compares this HeadingPitchRoll against the provided HeadingPitchRoll componentwise and returns
  18204. * <code>true</code> if they pass an absolute or relative tolerance test,
  18205. * <code>false</code> otherwise.
  18206. *
  18207. * @param {HeadingPitchRoll} [right] The right hand side HeadingPitchRoll.
  18208. * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
  18209. * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  18210. * @returns {Boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
  18211. */
  18212. HeadingPitchRoll.prototype.equalsEpsilon = function(right, relativeEpsilon, absoluteEpsilon) {
  18213. return HeadingPitchRoll.equalsEpsilon(this, right, relativeEpsilon, absoluteEpsilon);
  18214. };
  18215. /**
  18216. * Creates a string representing this HeadingPitchRoll in the format '(heading, pitch, roll)' in radians.
  18217. *
  18218. * @returns {String} A string representing the provided HeadingPitchRoll in the format '(heading, pitch, roll)'.
  18219. */
  18220. HeadingPitchRoll.prototype.toString = function() {
  18221. return '(' + this.heading + ', ' + this.pitch + ', ' + this.roll + ')';
  18222. };
  18223. return HeadingPitchRoll;
  18224. });
  18225. /*global define*/
  18226. define('Core/getAbsoluteUri',[
  18227. '../ThirdParty/Uri',
  18228. './defaultValue',
  18229. './defined',
  18230. './DeveloperError'
  18231. ], function(
  18232. Uri,
  18233. defaultValue,
  18234. defined,
  18235. DeveloperError) {
  18236. 'use strict';
  18237. /**
  18238. * Given a relative Uri and a base Uri, returns the absolute Uri of the relative Uri.
  18239. * @exports getAbsoluteUri
  18240. *
  18241. * @param {String} relative The relative Uri.
  18242. * @param {String} [base] The base Uri.
  18243. * @returns {String} The absolute Uri of the given relative Uri.
  18244. *
  18245. * @example
  18246. * //absolute Uri will be "https://test.com/awesome.png";
  18247. * var absoluteUri = Cesium.getAbsoluteUri('awesome.png', 'https://test.com');
  18248. */
  18249. function getAbsoluteUri(relative, base) {
  18250. if (!defined(relative)) {
  18251. throw new DeveloperError('relative uri is required.');
  18252. }
  18253. base = defaultValue(base, document.location.href);
  18254. var baseUri = new Uri(base);
  18255. var relativeUri = new Uri(relative);
  18256. return relativeUri.resolve(baseUri).toString();
  18257. }
  18258. return getAbsoluteUri;
  18259. });
  18260. /*global define*/
  18261. define('Core/joinUrls',[
  18262. '../ThirdParty/Uri',
  18263. './defaultValue',
  18264. './defined',
  18265. './DeveloperError'
  18266. ], function(
  18267. Uri,
  18268. defaultValue,
  18269. defined,
  18270. DeveloperError) {
  18271. 'use strict';
  18272. /**
  18273. * Function for joining URLs in a manner that is aware of query strings and fragments.
  18274. * This is useful when the base URL has a query string that needs to be maintained
  18275. * (e.g. a presigned base URL).
  18276. * @param {String|Uri} first The base URL.
  18277. * @param {String|Uri} second The URL path to join to the base URL. If this URL is absolute, it is returned unmodified.
  18278. * @param {Boolean} [appendSlash=true] The boolean determining whether there should be a forward slash between first and second.
  18279. * @private
  18280. */
  18281. function joinUrls(first, second, appendSlash) {
  18282. if (!defined(first)) {
  18283. throw new DeveloperError('first is required');
  18284. }
  18285. if (!defined(second)) {
  18286. throw new DeveloperError('second is required');
  18287. }
  18288. appendSlash = defaultValue(appendSlash, true);
  18289. if (!(first instanceof Uri)) {
  18290. first = new Uri(first);
  18291. }
  18292. if (!(second instanceof Uri)) {
  18293. second = new Uri(second);
  18294. }
  18295. // Uri.isAbsolute returns false for a URL like '//foo.com'. So if we have an authority but
  18296. // not a scheme, add a scheme matching the page's scheme.
  18297. if (defined(second.authority) && !defined(second.scheme)) {
  18298. if (typeof document !== 'undefined' && defined(document.location) && defined(document.location.href)) {
  18299. second.scheme = new Uri(document.location.href).scheme;
  18300. } else {
  18301. // Not in a browser? Use the first URL's scheme instead.
  18302. second.scheme = first.scheme;
  18303. }
  18304. }
  18305. // If the second URL is absolute, use it for the scheme, authority, and path.
  18306. var baseUri = first;
  18307. if (second.isAbsolute()) {
  18308. baseUri = second;
  18309. }
  18310. var url = '';
  18311. if (defined(baseUri.scheme)) {
  18312. url += baseUri.scheme + ':';
  18313. }
  18314. if (defined(baseUri.authority)) {
  18315. url += '//' + baseUri.authority;
  18316. if (baseUri.path !== '' && baseUri.path !== '/') {
  18317. url = url.replace(/\/?$/, '/');
  18318. baseUri.path = baseUri.path.replace(/^\/?/g, '');
  18319. }
  18320. }
  18321. // Combine the paths (only if second is relative).
  18322. if (baseUri === first) {
  18323. if (appendSlash) {
  18324. url += first.path.replace(/\/?$/, '/') + second.path.replace(/^\/?/g, '');
  18325. } else {
  18326. url += first.path + second.path;
  18327. }
  18328. } else {
  18329. url += second.path;
  18330. }
  18331. // Combine the queries and fragments.
  18332. var hasFirstQuery = defined(first.query);
  18333. var hasSecondQuery = defined(second.query);
  18334. if (hasFirstQuery && hasSecondQuery) {
  18335. url += '?' + first.query + '&' + second.query;
  18336. } else if (hasFirstQuery && !hasSecondQuery) {
  18337. url += '?' + first.query;
  18338. } else if (!hasFirstQuery && hasSecondQuery) {
  18339. url += '?' + second.query;
  18340. }
  18341. var hasSecondFragment = defined(second.fragment);
  18342. if (defined(first.fragment) && !hasSecondFragment) {
  18343. url += '#' + first.fragment;
  18344. } else if (hasSecondFragment) {
  18345. url += '#' + second.fragment;
  18346. }
  18347. return url;
  18348. }
  18349. return joinUrls;
  18350. });
  18351. /*global define*/
  18352. define('Core/buildModuleUrl',[
  18353. '../ThirdParty/Uri',
  18354. './defined',
  18355. './DeveloperError',
  18356. './getAbsoluteUri',
  18357. './joinUrls',
  18358. 'require'
  18359. ], function(
  18360. Uri,
  18361. defined,
  18362. DeveloperError,
  18363. getAbsoluteUri,
  18364. joinUrls,
  18365. require) {
  18366. 'use strict';
  18367. /*global CESIUM_BASE_URL*/
  18368. var cesiumScriptRegex = /((?:.*\/)|^)cesium[\w-]*\.js(?:\W|$)/i;
  18369. function getBaseUrlFromCesiumScript() {
  18370. var scripts = document.getElementsByTagName('script');
  18371. for ( var i = 0, len = scripts.length; i < len; ++i) {
  18372. var src = scripts[i].getAttribute('src');
  18373. var result = cesiumScriptRegex.exec(src);
  18374. if (result !== null) {
  18375. return result[1];
  18376. }
  18377. }
  18378. return undefined;
  18379. }
  18380. var baseUrl;
  18381. function getCesiumBaseUrl() {
  18382. if (defined(baseUrl)) {
  18383. return baseUrl;
  18384. }
  18385. var baseUrlString;
  18386. if (typeof CESIUM_BASE_URL !== 'undefined') {
  18387. baseUrlString = CESIUM_BASE_URL;
  18388. } else {
  18389. baseUrlString = getBaseUrlFromCesiumScript();
  18390. }
  18391. if (!defined(baseUrlString)) {
  18392. throw new DeveloperError('Unable to determine Cesium base URL automatically, try defining a global variable called CESIUM_BASE_URL.');
  18393. }
  18394. baseUrl = new Uri(getAbsoluteUri(baseUrlString));
  18395. return baseUrl;
  18396. }
  18397. function buildModuleUrlFromRequireToUrl(moduleID) {
  18398. //moduleID will be non-relative, so require it relative to this module, in Core.
  18399. return require.toUrl('../' + moduleID);
  18400. }
  18401. function buildModuleUrlFromBaseUrl(moduleID) {
  18402. return joinUrls(getCesiumBaseUrl(), moduleID);
  18403. }
  18404. var implementation;
  18405. var a;
  18406. /**
  18407. * Given a non-relative moduleID, returns an absolute URL to the file represented by that module ID,
  18408. * using, in order of preference, require.toUrl, the value of a global CESIUM_BASE_URL, or
  18409. * the base URL of the Cesium.js script.
  18410. *
  18411. * @private
  18412. */
  18413. function buildModuleUrl(moduleID) {
  18414. if (!defined(implementation)) {
  18415. //select implementation
  18416. if (defined(require.toUrl)) {
  18417. implementation = buildModuleUrlFromRequireToUrl;
  18418. } else {
  18419. implementation = buildModuleUrlFromBaseUrl;
  18420. }
  18421. }
  18422. if (!defined(a)) {
  18423. a = document.createElement('a');
  18424. }
  18425. var url = implementation(moduleID);
  18426. a.href = url;
  18427. a.href = a.href; // IE only absolutizes href on get, not set
  18428. return a.href;
  18429. }
  18430. // exposed for testing
  18431. buildModuleUrl._cesiumScriptRegex = cesiumScriptRegex;
  18432. /**
  18433. * Sets the base URL for resolving modules.
  18434. * @param {String} value The new base URL.
  18435. */
  18436. buildModuleUrl.setBaseUrl = function(value) {
  18437. baseUrl = new Uri(value).resolve(new Uri(document.location.href));
  18438. };
  18439. return buildModuleUrl;
  18440. });
  18441. /*global define*/
  18442. define('Core/Iau2006XysSample',[],function() {
  18443. 'use strict';
  18444. /**
  18445. * An IAU 2006 XYS value sampled at a particular time.
  18446. *
  18447. * @alias Iau2006XysSample
  18448. * @constructor
  18449. *
  18450. * @param {Number} x The X value.
  18451. * @param {Number} y The Y value.
  18452. * @param {Number} s The S value.
  18453. *
  18454. * @private
  18455. */
  18456. function Iau2006XysSample(x, y, s) {
  18457. /**
  18458. * The X value.
  18459. * @type {Number}
  18460. */
  18461. this.x = x;
  18462. /**
  18463. * The Y value.
  18464. * @type {Number}
  18465. */
  18466. this.y = y;
  18467. /**
  18468. * The S value.
  18469. * @type {Number}
  18470. */
  18471. this.s = s;
  18472. }
  18473. return Iau2006XysSample;
  18474. });
  18475. /*global define*/
  18476. define('Core/Iau2006XysData',[
  18477. '../ThirdParty/when',
  18478. './buildModuleUrl',
  18479. './defaultValue',
  18480. './defined',
  18481. './Iau2006XysSample',
  18482. './JulianDate',
  18483. './loadJson',
  18484. './TimeStandard'
  18485. ], function(
  18486. when,
  18487. buildModuleUrl,
  18488. defaultValue,
  18489. defined,
  18490. Iau2006XysSample,
  18491. JulianDate,
  18492. loadJson,
  18493. TimeStandard) {
  18494. 'use strict';
  18495. /**
  18496. * A set of IAU2006 XYS data that is used to evaluate the transformation between the International
  18497. * Celestial Reference Frame (ICRF) and the International Terrestrial Reference Frame (ITRF).
  18498. *
  18499. * @alias Iau2006XysData
  18500. * @constructor
  18501. *
  18502. * @param {Object} [options] Object with the following properties:
  18503. * @param {String} [options.xysFileUrlTemplate='Assets/IAU2006_XYS/IAU2006_XYS_{0}.json'] A template URL for obtaining the XYS data. In the template,
  18504. * `{0}` will be replaced with the file index.
  18505. * @param {Number} [options.interpolationOrder=9] The order of interpolation to perform on the XYS data.
  18506. * @param {Number} [options.sampleZeroJulianEphemerisDate=2442396.5] The Julian ephemeris date (JED) of the
  18507. * first XYS sample.
  18508. * @param {Number} [options.stepSizeDays=1.0] The step size, in days, between successive XYS samples.
  18509. * @param {Number} [options.samplesPerXysFile=1000] The number of samples in each XYS file.
  18510. * @param {Number} [options.totalSamples=27426] The total number of samples in all XYS files.
  18511. *
  18512. * @private
  18513. */
  18514. function Iau2006XysData(options) {
  18515. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  18516. this._xysFileUrlTemplate = options.xysFileUrlTemplate;
  18517. this._interpolationOrder = defaultValue(options.interpolationOrder, 9);
  18518. this._sampleZeroJulianEphemerisDate = defaultValue(options.sampleZeroJulianEphemerisDate, 2442396.5);
  18519. this._sampleZeroDateTT = new JulianDate(this._sampleZeroJulianEphemerisDate, 0.0, TimeStandard.TAI);
  18520. this._stepSizeDays = defaultValue(options.stepSizeDays, 1.0);
  18521. this._samplesPerXysFile = defaultValue(options.samplesPerXysFile, 1000);
  18522. this._totalSamples = defaultValue(options.totalSamples, 27426);
  18523. this._samples = new Array(this._totalSamples * 3);
  18524. this._chunkDownloadsInProgress = [];
  18525. var order = this._interpolationOrder;
  18526. // Compute denominators and X values for interpolation.
  18527. var denom = this._denominators = new Array(order + 1);
  18528. var xTable = this._xTable = new Array(order + 1);
  18529. var stepN = Math.pow(this._stepSizeDays, order);
  18530. for ( var i = 0; i <= order; ++i) {
  18531. denom[i] = stepN;
  18532. xTable[i] = i * this._stepSizeDays;
  18533. for ( var j = 0; j <= order; ++j) {
  18534. if (j !== i) {
  18535. denom[i] *= (i - j);
  18536. }
  18537. }
  18538. denom[i] = 1.0 / denom[i];
  18539. }
  18540. // Allocate scratch arrays for interpolation.
  18541. this._work = new Array(order + 1);
  18542. this._coef = new Array(order + 1);
  18543. }
  18544. var julianDateScratch = new JulianDate(0, 0.0, TimeStandard.TAI);
  18545. function getDaysSinceEpoch(xys, dayTT, secondTT) {
  18546. var dateTT = julianDateScratch;
  18547. dateTT.dayNumber = dayTT;
  18548. dateTT.secondsOfDay = secondTT;
  18549. return JulianDate.daysDifference(dateTT, xys._sampleZeroDateTT);
  18550. }
  18551. /**
  18552. * Preloads XYS data for a specified date range.
  18553. *
  18554. * @param {Number} startDayTT The Julian day number of the beginning of the interval to preload, expressed in
  18555. * the Terrestrial Time (TT) time standard.
  18556. * @param {Number} startSecondTT The seconds past noon of the beginning of the interval to preload, expressed in
  18557. * the Terrestrial Time (TT) time standard.
  18558. * @param {Number} stopDayTT The Julian day number of the end of the interval to preload, expressed in
  18559. * the Terrestrial Time (TT) time standard.
  18560. * @param {Number} stopSecondTT The seconds past noon of the end of the interval to preload, expressed in
  18561. * the Terrestrial Time (TT) time standard.
  18562. * @returns {Promise.<undefined>} A promise that, when resolved, indicates that the requested interval has been
  18563. * preloaded.
  18564. */
  18565. Iau2006XysData.prototype.preload = function(startDayTT, startSecondTT, stopDayTT, stopSecondTT) {
  18566. var startDaysSinceEpoch = getDaysSinceEpoch(this, startDayTT, startSecondTT);
  18567. var stopDaysSinceEpoch = getDaysSinceEpoch(this, stopDayTT, stopSecondTT);
  18568. var startIndex = (startDaysSinceEpoch / this._stepSizeDays - this._interpolationOrder / 2) | 0;
  18569. if (startIndex < 0) {
  18570. startIndex = 0;
  18571. }
  18572. var stopIndex = (stopDaysSinceEpoch / this._stepSizeDays - this._interpolationOrder / 2) | 0 + this._interpolationOrder;
  18573. if (stopIndex >= this._totalSamples) {
  18574. stopIndex = this._totalSamples - 1;
  18575. }
  18576. var startChunk = (startIndex / this._samplesPerXysFile) | 0;
  18577. var stopChunk = (stopIndex / this._samplesPerXysFile) | 0;
  18578. var promises = [];
  18579. for ( var i = startChunk; i <= stopChunk; ++i) {
  18580. promises.push(requestXysChunk(this, i));
  18581. }
  18582. return when.all(promises);
  18583. };
  18584. /**
  18585. * Computes the XYS values for a given date by interpolating. If the required data is not yet downloaded,
  18586. * this method will return undefined.
  18587. *
  18588. * @param {Number} dayTT The Julian day number for which to compute the XYS value, expressed in
  18589. * the Terrestrial Time (TT) time standard.
  18590. * @param {Number} secondTT The seconds past noon of the date for which to compute the XYS value, expressed in
  18591. * the Terrestrial Time (TT) time standard.
  18592. * @param {Iau2006XysSample} [result] The instance to which to copy the interpolated result. If this parameter
  18593. * is undefined, a new instance is allocated and returned.
  18594. * @returns {Iau2006XysSample} The interpolated XYS values, or undefined if the required data for this
  18595. * computation has not yet been downloaded.
  18596. *
  18597. * @see Iau2006XysData#preload
  18598. */
  18599. Iau2006XysData.prototype.computeXysRadians = function(dayTT, secondTT, result) {
  18600. var daysSinceEpoch = getDaysSinceEpoch(this, dayTT, secondTT);
  18601. if (daysSinceEpoch < 0.0) {
  18602. // Can't evaluate prior to the epoch of the data.
  18603. return undefined;
  18604. }
  18605. var centerIndex = (daysSinceEpoch / this._stepSizeDays) | 0;
  18606. if (centerIndex >= this._totalSamples) {
  18607. // Can't evaluate after the last sample in the data.
  18608. return undefined;
  18609. }
  18610. var degree = this._interpolationOrder;
  18611. var firstIndex = centerIndex - ((degree / 2) | 0);
  18612. if (firstIndex < 0) {
  18613. firstIndex = 0;
  18614. }
  18615. var lastIndex = firstIndex + degree;
  18616. if (lastIndex >= this._totalSamples) {
  18617. lastIndex = this._totalSamples - 1;
  18618. firstIndex = lastIndex - degree;
  18619. if (firstIndex < 0) {
  18620. firstIndex = 0;
  18621. }
  18622. }
  18623. // Are all the samples we need present?
  18624. // We can assume so if the first and last are present
  18625. var isDataMissing = false;
  18626. var samples = this._samples;
  18627. if (!defined(samples[firstIndex * 3])) {
  18628. requestXysChunk(this, (firstIndex / this._samplesPerXysFile) | 0);
  18629. isDataMissing = true;
  18630. }
  18631. if (!defined(samples[lastIndex * 3])) {
  18632. requestXysChunk(this, (lastIndex / this._samplesPerXysFile) | 0);
  18633. isDataMissing = true;
  18634. }
  18635. if (isDataMissing) {
  18636. return undefined;
  18637. }
  18638. if (!defined(result)) {
  18639. result = new Iau2006XysSample(0.0, 0.0, 0.0);
  18640. } else {
  18641. result.x = 0.0;
  18642. result.y = 0.0;
  18643. result.s = 0.0;
  18644. }
  18645. var x = daysSinceEpoch - firstIndex * this._stepSizeDays;
  18646. var work = this._work;
  18647. var denom = this._denominators;
  18648. var coef = this._coef;
  18649. var xTable = this._xTable;
  18650. var i, j;
  18651. for (i = 0; i <= degree; ++i) {
  18652. work[i] = x - xTable[i];
  18653. }
  18654. for (i = 0; i <= degree; ++i) {
  18655. coef[i] = 1.0;
  18656. for (j = 0; j <= degree; ++j) {
  18657. if (j !== i) {
  18658. coef[i] *= work[j];
  18659. }
  18660. }
  18661. coef[i] *= denom[i];
  18662. var sampleIndex = (firstIndex + i) * 3;
  18663. result.x += coef[i] * samples[sampleIndex++];
  18664. result.y += coef[i] * samples[sampleIndex++];
  18665. result.s += coef[i] * samples[sampleIndex];
  18666. }
  18667. return result;
  18668. };
  18669. function requestXysChunk(xysData, chunkIndex) {
  18670. if (xysData._chunkDownloadsInProgress[chunkIndex]) {
  18671. // Chunk has already been requested.
  18672. return xysData._chunkDownloadsInProgress[chunkIndex];
  18673. }
  18674. var deferred = when.defer();
  18675. xysData._chunkDownloadsInProgress[chunkIndex] = deferred;
  18676. var chunkUrl;
  18677. var xysFileUrlTemplate = xysData._xysFileUrlTemplate;
  18678. if (defined(xysFileUrlTemplate)) {
  18679. chunkUrl = xysFileUrlTemplate.replace('{0}', chunkIndex);
  18680. } else {
  18681. chunkUrl = buildModuleUrl('Assets/IAU2006_XYS/IAU2006_XYS_' + chunkIndex + '.json');
  18682. }
  18683. when(loadJson(chunkUrl), function(chunk) {
  18684. xysData._chunkDownloadsInProgress[chunkIndex] = false;
  18685. var samples = xysData._samples;
  18686. var newSamples = chunk.samples;
  18687. var startIndex = chunkIndex * xysData._samplesPerXysFile * 3;
  18688. for ( var i = 0, len = newSamples.length; i < len; ++i) {
  18689. samples[startIndex + i] = newSamples[i];
  18690. }
  18691. deferred.resolve();
  18692. });
  18693. return deferred.promise;
  18694. }
  18695. return Iau2006XysData;
  18696. });
  18697. /*global define*/
  18698. define('Core/Quaternion',[
  18699. './Cartesian3',
  18700. './defaultValue',
  18701. './defined',
  18702. './DeveloperError',
  18703. './FeatureDetection',
  18704. './freezeObject',
  18705. './Math',
  18706. './Matrix3'
  18707. ], function(
  18708. Cartesian3,
  18709. defaultValue,
  18710. defined,
  18711. DeveloperError,
  18712. FeatureDetection,
  18713. freezeObject,
  18714. CesiumMath,
  18715. Matrix3) {
  18716. 'use strict';
  18717. /**
  18718. * A set of 4-dimensional coordinates used to represent rotation in 3-dimensional space.
  18719. * @alias Quaternion
  18720. * @constructor
  18721. *
  18722. * @param {Number} [x=0.0] The X component.
  18723. * @param {Number} [y=0.0] The Y component.
  18724. * @param {Number} [z=0.0] The Z component.
  18725. * @param {Number} [w=0.0] The W component.
  18726. *
  18727. * @see PackableForInterpolation
  18728. */
  18729. function Quaternion(x, y, z, w) {
  18730. /**
  18731. * The X component.
  18732. * @type {Number}
  18733. * @default 0.0
  18734. */
  18735. this.x = defaultValue(x, 0.0);
  18736. /**
  18737. * The Y component.
  18738. * @type {Number}
  18739. * @default 0.0
  18740. */
  18741. this.y = defaultValue(y, 0.0);
  18742. /**
  18743. * The Z component.
  18744. * @type {Number}
  18745. * @default 0.0
  18746. */
  18747. this.z = defaultValue(z, 0.0);
  18748. /**
  18749. * The W component.
  18750. * @type {Number}
  18751. * @default 0.0
  18752. */
  18753. this.w = defaultValue(w, 0.0);
  18754. }
  18755. var fromAxisAngleScratch = new Cartesian3();
  18756. /**
  18757. * Computes a quaternion representing a rotation around an axis.
  18758. *
  18759. * @param {Cartesian3} axis The axis of rotation.
  18760. * @param {Number} angle The angle in radians to rotate around the axis.
  18761. * @param {Quaternion} [result] The object onto which to store the result.
  18762. * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.
  18763. */
  18764. Quaternion.fromAxisAngle = function(axis, angle, result) {
  18765. if (!defined(axis)) {
  18766. throw new DeveloperError('axis is required.');
  18767. }
  18768. if (typeof angle !== 'number') {
  18769. throw new DeveloperError('angle is required and must be a number.');
  18770. }
  18771. var halfAngle = angle / 2.0;
  18772. var s = Math.sin(halfAngle);
  18773. fromAxisAngleScratch = Cartesian3.normalize(axis, fromAxisAngleScratch);
  18774. var x = fromAxisAngleScratch.x * s;
  18775. var y = fromAxisAngleScratch.y * s;
  18776. var z = fromAxisAngleScratch.z * s;
  18777. var w = Math.cos(halfAngle);
  18778. if (!defined(result)) {
  18779. return new Quaternion(x, y, z, w);
  18780. }
  18781. result.x = x;
  18782. result.y = y;
  18783. result.z = z;
  18784. result.w = w;
  18785. return result;
  18786. };
  18787. var fromRotationMatrixNext = [1, 2, 0];
  18788. var fromRotationMatrixQuat = new Array(3);
  18789. /**
  18790. * Computes a Quaternion from the provided Matrix3 instance.
  18791. *
  18792. * @param {Matrix3} matrix The rotation matrix.
  18793. * @param {Quaternion} [result] The object onto which to store the result.
  18794. * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.
  18795. *
  18796. * @see Matrix3.fromQuaternion
  18797. */
  18798. Quaternion.fromRotationMatrix = function(matrix, result) {
  18799. if (!defined(matrix)) {
  18800. throw new DeveloperError('matrix is required.');
  18801. }
  18802. var root;
  18803. var x;
  18804. var y;
  18805. var z;
  18806. var w;
  18807. var m00 = matrix[Matrix3.COLUMN0ROW0];
  18808. var m11 = matrix[Matrix3.COLUMN1ROW1];
  18809. var m22 = matrix[Matrix3.COLUMN2ROW2];
  18810. var trace = m00 + m11 + m22;
  18811. if (trace > 0.0) {
  18812. // |w| > 1/2, may as well choose w > 1/2
  18813. root = Math.sqrt(trace + 1.0); // 2w
  18814. w = 0.5 * root;
  18815. root = 0.5 / root; // 1/(4w)
  18816. x = (matrix[Matrix3.COLUMN1ROW2] - matrix[Matrix3.COLUMN2ROW1]) * root;
  18817. y = (matrix[Matrix3.COLUMN2ROW0] - matrix[Matrix3.COLUMN0ROW2]) * root;
  18818. z = (matrix[Matrix3.COLUMN0ROW1] - matrix[Matrix3.COLUMN1ROW0]) * root;
  18819. } else {
  18820. // |w| <= 1/2
  18821. var next = fromRotationMatrixNext;
  18822. var i = 0;
  18823. if (m11 > m00) {
  18824. i = 1;
  18825. }
  18826. if (m22 > m00 && m22 > m11) {
  18827. i = 2;
  18828. }
  18829. var j = next[i];
  18830. var k = next[j];
  18831. root = Math.sqrt(matrix[Matrix3.getElementIndex(i, i)] - matrix[Matrix3.getElementIndex(j, j)] - matrix[Matrix3.getElementIndex(k, k)] + 1.0);
  18832. var quat = fromRotationMatrixQuat;
  18833. quat[i] = 0.5 * root;
  18834. root = 0.5 / root;
  18835. w = (matrix[Matrix3.getElementIndex(k, j)] - matrix[Matrix3.getElementIndex(j, k)]) * root;
  18836. quat[j] = (matrix[Matrix3.getElementIndex(j, i)] + matrix[Matrix3.getElementIndex(i, j)]) * root;
  18837. quat[k] = (matrix[Matrix3.getElementIndex(k, i)] + matrix[Matrix3.getElementIndex(i, k)]) * root;
  18838. x = -quat[0];
  18839. y = -quat[1];
  18840. z = -quat[2];
  18841. }
  18842. if (!defined(result)) {
  18843. return new Quaternion(x, y, z, w);
  18844. }
  18845. result.x = x;
  18846. result.y = y;
  18847. result.z = z;
  18848. result.w = w;
  18849. return result;
  18850. };
  18851. var scratchHPRQuaternion = new Quaternion();
  18852. /**
  18853. * Computes a rotation from the given heading, pitch and roll angles. Heading is the rotation about the
  18854. * negative z axis. Pitch is the rotation about the negative y axis. Roll is the rotation about
  18855. * the positive x axis.
  18856. *
  18857. * @param {Number} heading The heading angle in radians.
  18858. * @param {Number} pitch The pitch angle in radians.
  18859. * @param {Number} roll The roll angle in radians.
  18860. * @param {Quaternion} [result] The object onto which to store the result.
  18861. * @returns {Quaternion} The modified result parameter or a new Quaternion instance if none was provided.
  18862. */
  18863. Quaternion.fromHeadingPitchRoll = function(heading, pitch, roll, result) {
  18864. if (!defined(heading)) {
  18865. throw new DeveloperError('heading is required.');
  18866. }
  18867. if (!defined(pitch)) {
  18868. throw new DeveloperError('pitch is required.');
  18869. }
  18870. if (!defined(roll)) {
  18871. throw new DeveloperError('roll is required.');
  18872. }
  18873. var rollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, roll, scratchHPRQuaternion);
  18874. var pitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, -pitch, result);
  18875. result = Quaternion.multiply(pitchQuaternion, rollQuaternion, pitchQuaternion);
  18876. var headingQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Z, -heading, scratchHPRQuaternion);
  18877. return Quaternion.multiply(headingQuaternion, result, result);
  18878. };
  18879. var sampledQuaternionAxis = new Cartesian3();
  18880. var sampledQuaternionRotation = new Cartesian3();
  18881. var sampledQuaternionTempQuaternion = new Quaternion();
  18882. var sampledQuaternionQuaternion0 = new Quaternion();
  18883. var sampledQuaternionQuaternion0Conjugate = new Quaternion();
  18884. /**
  18885. * The number of elements used to pack the object into an array.
  18886. * @type {Number}
  18887. */
  18888. Quaternion.packedLength = 4;
  18889. /**
  18890. * Stores the provided instance into the provided array.
  18891. *
  18892. * @param {Quaternion} value The value to pack.
  18893. * @param {Number[]} array The array to pack into.
  18894. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  18895. *
  18896. * @returns {Number[]} The array that was packed into
  18897. */
  18898. Quaternion.pack = function(value, array, startingIndex) {
  18899. if (!defined(value)) {
  18900. throw new DeveloperError('value is required');
  18901. }
  18902. if (!defined(array)) {
  18903. throw new DeveloperError('array is required');
  18904. }
  18905. startingIndex = defaultValue(startingIndex, 0);
  18906. array[startingIndex++] = value.x;
  18907. array[startingIndex++] = value.y;
  18908. array[startingIndex++] = value.z;
  18909. array[startingIndex] = value.w;
  18910. return array;
  18911. };
  18912. /**
  18913. * Retrieves an instance from a packed array.
  18914. *
  18915. * @param {Number[]} array The packed array.
  18916. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  18917. * @param {Quaternion} [result] The object into which to store the result.
  18918. * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.
  18919. */
  18920. Quaternion.unpack = function(array, startingIndex, result) {
  18921. if (!defined(array)) {
  18922. throw new DeveloperError('array is required');
  18923. }
  18924. startingIndex = defaultValue(startingIndex, 0);
  18925. if (!defined(result)) {
  18926. result = new Quaternion();
  18927. }
  18928. result.x = array[startingIndex];
  18929. result.y = array[startingIndex + 1];
  18930. result.z = array[startingIndex + 2];
  18931. result.w = array[startingIndex + 3];
  18932. return result;
  18933. };
  18934. /**
  18935. * The number of elements used to store the object into an array in its interpolatable form.
  18936. * @type {Number}
  18937. */
  18938. Quaternion.packedInterpolationLength = 3;
  18939. /**
  18940. * Converts a packed array into a form suitable for interpolation.
  18941. *
  18942. * @param {Number[]} packedArray The packed array.
  18943. * @param {Number} [startingIndex=0] The index of the first element to be converted.
  18944. * @param {Number} [lastIndex=packedArray.length] The index of the last element to be converted.
  18945. * @param {Number[]} result The object into which to store the result.
  18946. */
  18947. Quaternion.convertPackedArrayForInterpolation = function(packedArray, startingIndex, lastIndex, result) {
  18948. Quaternion.unpack(packedArray, lastIndex * 4, sampledQuaternionQuaternion0Conjugate);
  18949. Quaternion.conjugate(sampledQuaternionQuaternion0Conjugate, sampledQuaternionQuaternion0Conjugate);
  18950. for (var i = 0, len = lastIndex - startingIndex + 1; i < len; i++) {
  18951. var offset = i * 3;
  18952. Quaternion.unpack(packedArray, (startingIndex + i) * 4, sampledQuaternionTempQuaternion);
  18953. Quaternion.multiply(sampledQuaternionTempQuaternion, sampledQuaternionQuaternion0Conjugate, sampledQuaternionTempQuaternion);
  18954. if (sampledQuaternionTempQuaternion.w < 0) {
  18955. Quaternion.negate(sampledQuaternionTempQuaternion, sampledQuaternionTempQuaternion);
  18956. }
  18957. Quaternion.computeAxis(sampledQuaternionTempQuaternion, sampledQuaternionAxis);
  18958. var angle = Quaternion.computeAngle(sampledQuaternionTempQuaternion);
  18959. result[offset] = sampledQuaternionAxis.x * angle;
  18960. result[offset + 1] = sampledQuaternionAxis.y * angle;
  18961. result[offset + 2] = sampledQuaternionAxis.z * angle;
  18962. }
  18963. };
  18964. /**
  18965. * Retrieves an instance from a packed array converted with {@link convertPackedArrayForInterpolation}.
  18966. *
  18967. * @param {Number[]} array The array previously packed for interpolation.
  18968. * @param {Number[]} sourceArray The original packed array.
  18969. * @param {Number} [startingIndex=0] The startingIndex used to convert the array.
  18970. * @param {Number} [lastIndex=packedArray.length] The lastIndex used to convert the array.
  18971. * @param {Quaternion} [result] The object into which to store the result.
  18972. * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.
  18973. */
  18974. Quaternion.unpackInterpolationResult = function(array, sourceArray, firstIndex, lastIndex, result) {
  18975. if (!defined(result)) {
  18976. result = new Quaternion();
  18977. }
  18978. Cartesian3.fromArray(array, 0, sampledQuaternionRotation);
  18979. var magnitude = Cartesian3.magnitude(sampledQuaternionRotation);
  18980. Quaternion.unpack(sourceArray, lastIndex * 4, sampledQuaternionQuaternion0);
  18981. if (magnitude === 0) {
  18982. Quaternion.clone(Quaternion.IDENTITY, sampledQuaternionTempQuaternion);
  18983. } else {
  18984. Quaternion.fromAxisAngle(sampledQuaternionRotation, magnitude, sampledQuaternionTempQuaternion);
  18985. }
  18986. return Quaternion.multiply(sampledQuaternionTempQuaternion, sampledQuaternionQuaternion0, result);
  18987. };
  18988. /**
  18989. * Duplicates a Quaternion instance.
  18990. *
  18991. * @param {Quaternion} quaternion The quaternion to duplicate.
  18992. * @param {Quaternion} [result] The object onto which to store the result.
  18993. * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided. (Returns undefined if quaternion is undefined)
  18994. */
  18995. Quaternion.clone = function(quaternion, result) {
  18996. if (!defined(quaternion)) {
  18997. return undefined;
  18998. }
  18999. if (!defined(result)) {
  19000. return new Quaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
  19001. }
  19002. result.x = quaternion.x;
  19003. result.y = quaternion.y;
  19004. result.z = quaternion.z;
  19005. result.w = quaternion.w;
  19006. return result;
  19007. };
  19008. /**
  19009. * Computes the conjugate of the provided quaternion.
  19010. *
  19011. * @param {Quaternion} quaternion The quaternion to conjugate.
  19012. * @param {Quaternion} result The object onto which to store the result.
  19013. * @returns {Quaternion} The modified result parameter.
  19014. */
  19015. Quaternion.conjugate = function(quaternion, result) {
  19016. if (!defined(quaternion)) {
  19017. throw new DeveloperError('quaternion is required');
  19018. }
  19019. if (!defined(result)) {
  19020. throw new DeveloperError('result is required');
  19021. }
  19022. result.x = -quaternion.x;
  19023. result.y = -quaternion.y;
  19024. result.z = -quaternion.z;
  19025. result.w = quaternion.w;
  19026. return result;
  19027. };
  19028. /**
  19029. * Computes magnitude squared for the provided quaternion.
  19030. *
  19031. * @param {Quaternion} quaternion The quaternion to conjugate.
  19032. * @returns {Number} The magnitude squared.
  19033. */
  19034. Quaternion.magnitudeSquared = function(quaternion) {
  19035. if (!defined(quaternion)) {
  19036. throw new DeveloperError('quaternion is required');
  19037. }
  19038. return quaternion.x * quaternion.x + quaternion.y * quaternion.y + quaternion.z * quaternion.z + quaternion.w * quaternion.w;
  19039. };
  19040. /**
  19041. * Computes magnitude for the provided quaternion.
  19042. *
  19043. * @param {Quaternion} quaternion The quaternion to conjugate.
  19044. * @returns {Number} The magnitude.
  19045. */
  19046. Quaternion.magnitude = function(quaternion) {
  19047. return Math.sqrt(Quaternion.magnitudeSquared(quaternion));
  19048. };
  19049. /**
  19050. * Computes the normalized form of the provided quaternion.
  19051. *
  19052. * @param {Quaternion} quaternion The quaternion to normalize.
  19053. * @param {Quaternion} result The object onto which to store the result.
  19054. * @returns {Quaternion} The modified result parameter.
  19055. */
  19056. Quaternion.normalize = function(quaternion, result) {
  19057. if (!defined(result)) {
  19058. throw new DeveloperError('result is required');
  19059. }
  19060. var inverseMagnitude = 1.0 / Quaternion.magnitude(quaternion);
  19061. var x = quaternion.x * inverseMagnitude;
  19062. var y = quaternion.y * inverseMagnitude;
  19063. var z = quaternion.z * inverseMagnitude;
  19064. var w = quaternion.w * inverseMagnitude;
  19065. result.x = x;
  19066. result.y = y;
  19067. result.z = z;
  19068. result.w = w;
  19069. return result;
  19070. };
  19071. /**
  19072. * Computes the inverse of the provided quaternion.
  19073. *
  19074. * @param {Quaternion} quaternion The quaternion to normalize.
  19075. * @param {Quaternion} result The object onto which to store the result.
  19076. * @returns {Quaternion} The modified result parameter.
  19077. */
  19078. Quaternion.inverse = function(quaternion, result) {
  19079. if (!defined(result)) {
  19080. throw new DeveloperError('result is required');
  19081. }
  19082. var magnitudeSquared = Quaternion.magnitudeSquared(quaternion);
  19083. result = Quaternion.conjugate(quaternion, result);
  19084. return Quaternion.multiplyByScalar(result, 1.0 / magnitudeSquared, result);
  19085. };
  19086. /**
  19087. * Computes the componentwise sum of two quaternions.
  19088. *
  19089. * @param {Quaternion} left The first quaternion.
  19090. * @param {Quaternion} right The second quaternion.
  19091. * @param {Quaternion} result The object onto which to store the result.
  19092. * @returns {Quaternion} The modified result parameter.
  19093. */
  19094. Quaternion.add = function(left, right, result) {
  19095. if (!defined(left)) {
  19096. throw new DeveloperError('left is required');
  19097. }
  19098. if (!defined(right)) {
  19099. throw new DeveloperError('right is required');
  19100. }
  19101. if (!defined(result)) {
  19102. throw new DeveloperError('result is required');
  19103. }
  19104. result.x = left.x + right.x;
  19105. result.y = left.y + right.y;
  19106. result.z = left.z + right.z;
  19107. result.w = left.w + right.w;
  19108. return result;
  19109. };
  19110. /**
  19111. * Computes the componentwise difference of two quaternions.
  19112. *
  19113. * @param {Quaternion} left The first quaternion.
  19114. * @param {Quaternion} right The second quaternion.
  19115. * @param {Quaternion} result The object onto which to store the result.
  19116. * @returns {Quaternion} The modified result parameter.
  19117. */
  19118. Quaternion.subtract = function(left, right, result) {
  19119. if (!defined(left)) {
  19120. throw new DeveloperError('left is required');
  19121. }
  19122. if (!defined(right)) {
  19123. throw new DeveloperError('right is required');
  19124. }
  19125. if (!defined(result)) {
  19126. throw new DeveloperError('result is required');
  19127. }
  19128. result.x = left.x - right.x;
  19129. result.y = left.y - right.y;
  19130. result.z = left.z - right.z;
  19131. result.w = left.w - right.w;
  19132. return result;
  19133. };
  19134. /**
  19135. * Negates the provided quaternion.
  19136. *
  19137. * @param {Quaternion} quaternion The quaternion to be negated.
  19138. * @param {Quaternion} result The object onto which to store the result.
  19139. * @returns {Quaternion} The modified result parameter.
  19140. */
  19141. Quaternion.negate = function(quaternion, result) {
  19142. if (!defined(quaternion)) {
  19143. throw new DeveloperError('quaternion is required');
  19144. }
  19145. if (!defined(result)) {
  19146. throw new DeveloperError('result is required');
  19147. }
  19148. result.x = -quaternion.x;
  19149. result.y = -quaternion.y;
  19150. result.z = -quaternion.z;
  19151. result.w = -quaternion.w;
  19152. return result;
  19153. };
  19154. /**
  19155. * Computes the dot (scalar) product of two quaternions.
  19156. *
  19157. * @param {Quaternion} left The first quaternion.
  19158. * @param {Quaternion} right The second quaternion.
  19159. * @returns {Number} The dot product.
  19160. */
  19161. Quaternion.dot = function(left, right) {
  19162. if (!defined(left)) {
  19163. throw new DeveloperError('left is required');
  19164. }
  19165. if (!defined(right)) {
  19166. throw new DeveloperError('right is required');
  19167. }
  19168. return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
  19169. };
  19170. /**
  19171. * Computes the product of two quaternions.
  19172. *
  19173. * @param {Quaternion} left The first quaternion.
  19174. * @param {Quaternion} right The second quaternion.
  19175. * @param {Quaternion} result The object onto which to store the result.
  19176. * @returns {Quaternion} The modified result parameter.
  19177. */
  19178. Quaternion.multiply = function(left, right, result) {
  19179. if (!defined(left)) {
  19180. throw new DeveloperError('left is required');
  19181. }
  19182. if (!defined(right)) {
  19183. throw new DeveloperError('right is required');
  19184. }
  19185. if (!defined(result)) {
  19186. throw new DeveloperError('result is required');
  19187. }
  19188. var leftX = left.x;
  19189. var leftY = left.y;
  19190. var leftZ = left.z;
  19191. var leftW = left.w;
  19192. var rightX = right.x;
  19193. var rightY = right.y;
  19194. var rightZ = right.z;
  19195. var rightW = right.w;
  19196. var x = leftW * rightX + leftX * rightW + leftY * rightZ - leftZ * rightY;
  19197. var y = leftW * rightY - leftX * rightZ + leftY * rightW + leftZ * rightX;
  19198. var z = leftW * rightZ + leftX * rightY - leftY * rightX + leftZ * rightW;
  19199. var w = leftW * rightW - leftX * rightX - leftY * rightY - leftZ * rightZ;
  19200. result.x = x;
  19201. result.y = y;
  19202. result.z = z;
  19203. result.w = w;
  19204. return result;
  19205. };
  19206. /**
  19207. * Multiplies the provided quaternion componentwise by the provided scalar.
  19208. *
  19209. * @param {Quaternion} quaternion The quaternion to be scaled.
  19210. * @param {Number} scalar The scalar to multiply with.
  19211. * @param {Quaternion} result The object onto which to store the result.
  19212. * @returns {Quaternion} The modified result parameter.
  19213. */
  19214. Quaternion.multiplyByScalar = function(quaternion, scalar, result) {
  19215. if (!defined(quaternion)) {
  19216. throw new DeveloperError('quaternion is required');
  19217. }
  19218. if (typeof scalar !== 'number') {
  19219. throw new DeveloperError('scalar is required and must be a number.');
  19220. }
  19221. if (!defined(result)) {
  19222. throw new DeveloperError('result is required');
  19223. }
  19224. result.x = quaternion.x * scalar;
  19225. result.y = quaternion.y * scalar;
  19226. result.z = quaternion.z * scalar;
  19227. result.w = quaternion.w * scalar;
  19228. return result;
  19229. };
  19230. /**
  19231. * Divides the provided quaternion componentwise by the provided scalar.
  19232. *
  19233. * @param {Quaternion} quaternion The quaternion to be divided.
  19234. * @param {Number} scalar The scalar to divide by.
  19235. * @param {Quaternion} result The object onto which to store the result.
  19236. * @returns {Quaternion} The modified result parameter.
  19237. */
  19238. Quaternion.divideByScalar = function(quaternion, scalar, result) {
  19239. if (!defined(quaternion)) {
  19240. throw new DeveloperError('quaternion is required');
  19241. }
  19242. if (typeof scalar !== 'number') {
  19243. throw new DeveloperError('scalar is required and must be a number.');
  19244. }
  19245. if (!defined(result)) {
  19246. throw new DeveloperError('result is required');
  19247. }
  19248. result.x = quaternion.x / scalar;
  19249. result.y = quaternion.y / scalar;
  19250. result.z = quaternion.z / scalar;
  19251. result.w = quaternion.w / scalar;
  19252. return result;
  19253. };
  19254. /**
  19255. * Computes the axis of rotation of the provided quaternion.
  19256. *
  19257. * @param {Quaternion} quaternion The quaternion to use.
  19258. * @param {Cartesian3} result The object onto which to store the result.
  19259. * @returns {Cartesian3} The modified result parameter.
  19260. */
  19261. Quaternion.computeAxis = function(quaternion, result) {
  19262. if (!defined(quaternion)) {
  19263. throw new DeveloperError('quaternion is required');
  19264. }
  19265. if (!defined(result)) {
  19266. throw new DeveloperError('result is required');
  19267. }
  19268. var w = quaternion.w;
  19269. if (Math.abs(w - 1.0) < CesiumMath.EPSILON6) {
  19270. result.x = result.y = result.z = 0;
  19271. return result;
  19272. }
  19273. var scalar = 1.0 / Math.sqrt(1.0 - (w * w));
  19274. result.x = quaternion.x * scalar;
  19275. result.y = quaternion.y * scalar;
  19276. result.z = quaternion.z * scalar;
  19277. return result;
  19278. };
  19279. /**
  19280. * Computes the angle of rotation of the provided quaternion.
  19281. *
  19282. * @param {Quaternion} quaternion The quaternion to use.
  19283. * @returns {Number} The angle of rotation.
  19284. */
  19285. Quaternion.computeAngle = function(quaternion) {
  19286. if (!defined(quaternion)) {
  19287. throw new DeveloperError('quaternion is required');
  19288. }
  19289. if (Math.abs(quaternion.w - 1.0) < CesiumMath.EPSILON6) {
  19290. return 0.0;
  19291. }
  19292. return 2.0 * Math.acos(quaternion.w);
  19293. };
  19294. var lerpScratch = new Quaternion();
  19295. /**
  19296. * Computes the linear interpolation or extrapolation at t using the provided quaternions.
  19297. *
  19298. * @param {Quaternion} start The value corresponding to t at 0.0.
  19299. * @param {Quaternion} end The value corresponding to t at 1.0.
  19300. * @param {Number} t The point along t at which to interpolate.
  19301. * @param {Quaternion} result The object onto which to store the result.
  19302. * @returns {Quaternion} The modified result parameter.
  19303. */
  19304. Quaternion.lerp = function(start, end, t, result) {
  19305. if (!defined(start)) {
  19306. throw new DeveloperError('start is required.');
  19307. }
  19308. if (!defined(end)) {
  19309. throw new DeveloperError('end is required.');
  19310. }
  19311. if (typeof t !== 'number') {
  19312. throw new DeveloperError('t is required and must be a number.');
  19313. }
  19314. if (!defined(result)) {
  19315. throw new DeveloperError('result is required');
  19316. }
  19317. lerpScratch = Quaternion.multiplyByScalar(end, t, lerpScratch);
  19318. result = Quaternion.multiplyByScalar(start, 1.0 - t, result);
  19319. return Quaternion.add(lerpScratch, result, result);
  19320. };
  19321. var slerpEndNegated = new Quaternion();
  19322. var slerpScaledP = new Quaternion();
  19323. var slerpScaledR = new Quaternion();
  19324. /**
  19325. * Computes the spherical linear interpolation or extrapolation at t using the provided quaternions.
  19326. *
  19327. * @param {Quaternion} start The value corresponding to t at 0.0.
  19328. * @param {Quaternion} end The value corresponding to t at 1.0.
  19329. * @param {Number} t The point along t at which to interpolate.
  19330. * @param {Quaternion} result The object onto which to store the result.
  19331. * @returns {Quaternion} The modified result parameter.
  19332. *
  19333. * @see Quaternion#fastSlerp
  19334. */
  19335. Quaternion.slerp = function(start, end, t, result) {
  19336. if (!defined(start)) {
  19337. throw new DeveloperError('start is required.');
  19338. }
  19339. if (!defined(end)) {
  19340. throw new DeveloperError('end is required.');
  19341. }
  19342. if (typeof t !== 'number') {
  19343. throw new DeveloperError('t is required and must be a number.');
  19344. }
  19345. if (!defined(result)) {
  19346. throw new DeveloperError('result is required');
  19347. }
  19348. var dot = Quaternion.dot(start, end);
  19349. // The angle between start must be acute. Since q and -q represent
  19350. // the same rotation, negate q to get the acute angle.
  19351. var r = end;
  19352. if (dot < 0.0) {
  19353. dot = -dot;
  19354. r = slerpEndNegated = Quaternion.negate(end, slerpEndNegated);
  19355. }
  19356. // dot > 0, as the dot product approaches 1, the angle between the
  19357. // quaternions vanishes. use linear interpolation.
  19358. if (1.0 - dot < CesiumMath.EPSILON6) {
  19359. return Quaternion.lerp(start, r, t, result);
  19360. }
  19361. var theta = Math.acos(dot);
  19362. slerpScaledP = Quaternion.multiplyByScalar(start, Math.sin((1 - t) * theta), slerpScaledP);
  19363. slerpScaledR = Quaternion.multiplyByScalar(r, Math.sin(t * theta), slerpScaledR);
  19364. result = Quaternion.add(slerpScaledP, slerpScaledR, result);
  19365. return Quaternion.multiplyByScalar(result, 1.0 / Math.sin(theta), result);
  19366. };
  19367. /**
  19368. * The logarithmic quaternion function.
  19369. *
  19370. * @param {Quaternion} quaternion The unit quaternion.
  19371. * @param {Cartesian3} result The object onto which to store the result.
  19372. * @returns {Cartesian3} The modified result parameter.
  19373. */
  19374. Quaternion.log = function(quaternion, result) {
  19375. if (!defined(quaternion)) {
  19376. throw new DeveloperError('quaternion is required.');
  19377. }
  19378. if (!defined(result)) {
  19379. throw new DeveloperError('result is required');
  19380. }
  19381. var theta = CesiumMath.acosClamped(quaternion.w);
  19382. var thetaOverSinTheta = 0.0;
  19383. if (theta !== 0.0) {
  19384. thetaOverSinTheta = theta / Math.sin(theta);
  19385. }
  19386. return Cartesian3.multiplyByScalar(quaternion, thetaOverSinTheta, result);
  19387. };
  19388. /**
  19389. * The exponential quaternion function.
  19390. *
  19391. * @param {Cartesian3} cartesian The cartesian.
  19392. * @param {Quaternion} result The object onto which to store the result.
  19393. * @returns {Quaternion} The modified result parameter.
  19394. */
  19395. Quaternion.exp = function(cartesian, result) {
  19396. if (!defined(cartesian)) {
  19397. throw new DeveloperError('cartesian is required.');
  19398. }
  19399. if (!defined(result)) {
  19400. throw new DeveloperError('result is required');
  19401. }
  19402. var theta = Cartesian3.magnitude(cartesian);
  19403. var sinThetaOverTheta = 0.0;
  19404. if (theta !== 0.0) {
  19405. sinThetaOverTheta = Math.sin(theta) / theta;
  19406. }
  19407. result.x = cartesian.x * sinThetaOverTheta;
  19408. result.y = cartesian.y * sinThetaOverTheta;
  19409. result.z = cartesian.z * sinThetaOverTheta;
  19410. result.w = Math.cos(theta);
  19411. return result;
  19412. };
  19413. var squadScratchCartesian0 = new Cartesian3();
  19414. var squadScratchCartesian1 = new Cartesian3();
  19415. var squadScratchQuaternion0 = new Quaternion();
  19416. var squadScratchQuaternion1 = new Quaternion();
  19417. /**
  19418. * Computes an inner quadrangle point.
  19419. * <p>This will compute quaternions that ensure a squad curve is C<sup>1</sup>.</p>
  19420. *
  19421. * @param {Quaternion} q0 The first quaternion.
  19422. * @param {Quaternion} q1 The second quaternion.
  19423. * @param {Quaternion} q2 The third quaternion.
  19424. * @param {Quaternion} result The object onto which to store the result.
  19425. * @returns {Quaternion} The modified result parameter.
  19426. *
  19427. * @see Quaternion#squad
  19428. */
  19429. Quaternion.computeInnerQuadrangle = function(q0, q1, q2, result) {
  19430. if (!defined(q0) || !defined(q1) || !defined(q2)) {
  19431. throw new DeveloperError('q0, q1, and q2 are required.');
  19432. }
  19433. if (!defined(result)) {
  19434. throw new DeveloperError('result is required');
  19435. }
  19436. var qInv = Quaternion.conjugate(q1, squadScratchQuaternion0);
  19437. Quaternion.multiply(qInv, q2, squadScratchQuaternion1);
  19438. var cart0 = Quaternion.log(squadScratchQuaternion1, squadScratchCartesian0);
  19439. Quaternion.multiply(qInv, q0, squadScratchQuaternion1);
  19440. var cart1 = Quaternion.log(squadScratchQuaternion1, squadScratchCartesian1);
  19441. Cartesian3.add(cart0, cart1, cart0);
  19442. Cartesian3.multiplyByScalar(cart0, 0.25, cart0);
  19443. Cartesian3.negate(cart0, cart0);
  19444. Quaternion.exp(cart0, squadScratchQuaternion0);
  19445. return Quaternion.multiply(q1, squadScratchQuaternion0, result);
  19446. };
  19447. /**
  19448. * Computes the spherical quadrangle interpolation between quaternions.
  19449. *
  19450. * @param {Quaternion} q0 The first quaternion.
  19451. * @param {Quaternion} q1 The second quaternion.
  19452. * @param {Quaternion} s0 The first inner quadrangle.
  19453. * @param {Quaternion} s1 The second inner quadrangle.
  19454. * @param {Number} t The time in [0,1] used to interpolate.
  19455. * @param {Quaternion} result The object onto which to store the result.
  19456. * @returns {Quaternion} The modified result parameter.
  19457. *
  19458. *
  19459. * @example
  19460. * // 1. compute the squad interpolation between two quaternions on a curve
  19461. * var s0 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[i - 1], quaternions[i], quaternions[i + 1], new Cesium.Quaternion());
  19462. * var s1 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[i], quaternions[i + 1], quaternions[i + 2], new Cesium.Quaternion());
  19463. * var q = Cesium.Quaternion.squad(quaternions[i], quaternions[i + 1], s0, s1, t, new Cesium.Quaternion());
  19464. *
  19465. * // 2. compute the squad interpolation as above but where the first quaternion is a end point.
  19466. * var s1 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[0], quaternions[1], quaternions[2], new Cesium.Quaternion());
  19467. * var q = Cesium.Quaternion.squad(quaternions[0], quaternions[1], quaternions[0], s1, t, new Cesium.Quaternion());
  19468. *
  19469. * @see Quaternion#computeInnerQuadrangle
  19470. */
  19471. Quaternion.squad = function(q0, q1, s0, s1, t, result) {
  19472. if (!defined(q0) || !defined(q1) || !defined(s0) || !defined(s1)) {
  19473. throw new DeveloperError('q0, q1, s0, and s1 are required.');
  19474. }
  19475. if (typeof t !== 'number') {
  19476. throw new DeveloperError('t is required and must be a number.');
  19477. }
  19478. if (!defined(result)) {
  19479. throw new DeveloperError('result is required');
  19480. }
  19481. var slerp0 = Quaternion.slerp(q0, q1, t, squadScratchQuaternion0);
  19482. var slerp1 = Quaternion.slerp(s0, s1, t, squadScratchQuaternion1);
  19483. return Quaternion.slerp(slerp0, slerp1, 2.0 * t * (1.0 - t), result);
  19484. };
  19485. var fastSlerpScratchQuaternion = new Quaternion();
  19486. var opmu = 1.90110745351730037;
  19487. var u = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];
  19488. var v = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];
  19489. var bT = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];
  19490. var bD = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];
  19491. for (var i = 0; i < 7; ++i) {
  19492. var s = i + 1.0;
  19493. var t = 2.0 * s + 1.0;
  19494. u[i] = 1.0 / (s * t);
  19495. v[i] = s / t;
  19496. }
  19497. u[7] = opmu / (8.0 * 17.0);
  19498. v[7] = opmu * 8.0 / 17.0;
  19499. /**
  19500. * Computes the spherical linear interpolation or extrapolation at t using the provided quaternions.
  19501. * This implementation is faster than {@link Quaternion#slerp}, but is only accurate up to 10<sup>-6</sup>.
  19502. *
  19503. * @param {Quaternion} start The value corresponding to t at 0.0.
  19504. * @param {Quaternion} end The value corresponding to t at 1.0.
  19505. * @param {Number} t The point along t at which to interpolate.
  19506. * @param {Quaternion} result The object onto which to store the result.
  19507. * @returns {Quaternion} The modified result parameter.
  19508. *
  19509. * @see Quaternion#slerp
  19510. */
  19511. Quaternion.fastSlerp = function(start, end, t, result) {
  19512. if (!defined(start)) {
  19513. throw new DeveloperError('start is required.');
  19514. }
  19515. if (!defined(end)) {
  19516. throw new DeveloperError('end is required.');
  19517. }
  19518. if (typeof t !== 'number') {
  19519. throw new DeveloperError('t is required and must be a number.');
  19520. }
  19521. if (!defined(result)) {
  19522. throw new DeveloperError('result is required');
  19523. }
  19524. var x = Quaternion.dot(start, end);
  19525. var sign;
  19526. if (x >= 0) {
  19527. sign = 1.0;
  19528. } else {
  19529. sign = -1.0;
  19530. x = -x;
  19531. }
  19532. var xm1 = x - 1.0;
  19533. var d = 1.0 - t;
  19534. var sqrT = t * t;
  19535. var sqrD = d * d;
  19536. for (var i = 7; i >= 0; --i) {
  19537. bT[i] = (u[i] * sqrT - v[i]) * xm1;
  19538. bD[i] = (u[i] * sqrD - v[i]) * xm1;
  19539. }
  19540. var cT = sign * t * (
  19541. 1.0 + bT[0] * (1.0 + bT[1] * (1.0 + bT[2] * (1.0 + bT[3] * (
  19542. 1.0 + bT[4] * (1.0 + bT[5] * (1.0 + bT[6] * (1.0 + bT[7]))))))));
  19543. var cD = d * (
  19544. 1.0 + bD[0] * (1.0 + bD[1] * (1.0 + bD[2] * (1.0 + bD[3] * (
  19545. 1.0 + bD[4] * (1.0 + bD[5] * (1.0 + bD[6] * (1.0 + bD[7]))))))));
  19546. var temp = Quaternion.multiplyByScalar(start, cD, fastSlerpScratchQuaternion);
  19547. Quaternion.multiplyByScalar(end, cT, result);
  19548. return Quaternion.add(temp, result, result);
  19549. };
  19550. /**
  19551. * Computes the spherical quadrangle interpolation between quaternions.
  19552. * An implementation that is faster than {@link Quaternion#squad}, but less accurate.
  19553. *
  19554. * @param {Quaternion} q0 The first quaternion.
  19555. * @param {Quaternion} q1 The second quaternion.
  19556. * @param {Quaternion} s0 The first inner quadrangle.
  19557. * @param {Quaternion} s1 The second inner quadrangle.
  19558. * @param {Number} t The time in [0,1] used to interpolate.
  19559. * @param {Quaternion} result The object onto which to store the result.
  19560. * @returns {Quaternion} The modified result parameter or a new instance if none was provided.
  19561. *
  19562. * @see Quaternion#squad
  19563. */
  19564. Quaternion.fastSquad = function(q0, q1, s0, s1, t, result) {
  19565. if (!defined(q0) || !defined(q1) || !defined(s0) || !defined(s1)) {
  19566. throw new DeveloperError('q0, q1, s0, and s1 are required.');
  19567. }
  19568. if (typeof t !== 'number') {
  19569. throw new DeveloperError('t is required and must be a number.');
  19570. }
  19571. if (!defined(result)) {
  19572. throw new DeveloperError('result is required');
  19573. }
  19574. var slerp0 = Quaternion.fastSlerp(q0, q1, t, squadScratchQuaternion0);
  19575. var slerp1 = Quaternion.fastSlerp(s0, s1, t, squadScratchQuaternion1);
  19576. return Quaternion.fastSlerp(slerp0, slerp1, 2.0 * t * (1.0 - t), result);
  19577. };
  19578. /**
  19579. * Compares the provided quaternions componentwise and returns
  19580. * <code>true</code> if they are equal, <code>false</code> otherwise.
  19581. *
  19582. * @param {Quaternion} [left] The first quaternion.
  19583. * @param {Quaternion} [right] The second quaternion.
  19584. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  19585. */
  19586. Quaternion.equals = function(left, right) {
  19587. return (left === right) ||
  19588. ((defined(left)) &&
  19589. (defined(right)) &&
  19590. (left.x === right.x) &&
  19591. (left.y === right.y) &&
  19592. (left.z === right.z) &&
  19593. (left.w === right.w));
  19594. };
  19595. /**
  19596. * Compares the provided quaternions componentwise and returns
  19597. * <code>true</code> if they are within the provided epsilon,
  19598. * <code>false</code> otherwise.
  19599. *
  19600. * @param {Quaternion} [left] The first quaternion.
  19601. * @param {Quaternion} [right] The second quaternion.
  19602. * @param {Number} epsilon The epsilon to use for equality testing.
  19603. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  19604. */
  19605. Quaternion.equalsEpsilon = function(left, right, epsilon) {
  19606. if (typeof epsilon !== 'number') {
  19607. throw new DeveloperError('epsilon is required and must be a number.');
  19608. }
  19609. return (left === right) ||
  19610. ((defined(left)) &&
  19611. (defined(right)) &&
  19612. (Math.abs(left.x - right.x) <= epsilon) &&
  19613. (Math.abs(left.y - right.y) <= epsilon) &&
  19614. (Math.abs(left.z - right.z) <= epsilon) &&
  19615. (Math.abs(left.w - right.w) <= epsilon));
  19616. };
  19617. /**
  19618. * An immutable Quaternion instance initialized to (0.0, 0.0, 0.0, 0.0).
  19619. *
  19620. * @type {Quaternion}
  19621. * @constant
  19622. */
  19623. Quaternion.ZERO = freezeObject(new Quaternion(0.0, 0.0, 0.0, 0.0));
  19624. /**
  19625. * An immutable Quaternion instance initialized to (0.0, 0.0, 0.0, 1.0).
  19626. *
  19627. * @type {Quaternion}
  19628. * @constant
  19629. */
  19630. Quaternion.IDENTITY = freezeObject(new Quaternion(0.0, 0.0, 0.0, 1.0));
  19631. /**
  19632. * Duplicates this Quaternion instance.
  19633. *
  19634. * @param {Quaternion} [result] The object onto which to store the result.
  19635. * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided.
  19636. */
  19637. Quaternion.prototype.clone = function(result) {
  19638. return Quaternion.clone(this, result);
  19639. };
  19640. /**
  19641. * Compares this and the provided quaternion componentwise and returns
  19642. * <code>true</code> if they are equal, <code>false</code> otherwise.
  19643. *
  19644. * @param {Quaternion} [right] The right hand side quaternion.
  19645. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  19646. */
  19647. Quaternion.prototype.equals = function(right) {
  19648. return Quaternion.equals(this, right);
  19649. };
  19650. /**
  19651. * Compares this and the provided quaternion componentwise and returns
  19652. * <code>true</code> if they are within the provided epsilon,
  19653. * <code>false</code> otherwise.
  19654. *
  19655. * @param {Quaternion} [right] The right hand side quaternion.
  19656. * @param {Number} epsilon The epsilon to use for equality testing.
  19657. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  19658. */
  19659. Quaternion.prototype.equalsEpsilon = function(right, epsilon) {
  19660. return Quaternion.equalsEpsilon(this, right, epsilon);
  19661. };
  19662. /**
  19663. * Returns a string representing this quaternion in the format (x, y, z, w).
  19664. *
  19665. * @returns {String} A string representing this Quaternion.
  19666. */
  19667. Quaternion.prototype.toString = function() {
  19668. return '(' + this.x + ', ' + this.y + ', ' + this.z + ', ' + this.w + ')';
  19669. };
  19670. return Quaternion;
  19671. });
  19672. /*global define*/
  19673. define('Core/Transforms',[
  19674. '../ThirdParty/when',
  19675. './Cartesian2',
  19676. './Cartesian3',
  19677. './Cartesian4',
  19678. './Cartographic',
  19679. './defaultValue',
  19680. './defined',
  19681. './deprecationWarning',
  19682. './DeveloperError',
  19683. './EarthOrientationParameters',
  19684. './EarthOrientationParametersSample',
  19685. './Ellipsoid',
  19686. './HeadingPitchRoll',
  19687. './Iau2006XysData',
  19688. './Iau2006XysSample',
  19689. './JulianDate',
  19690. './Math',
  19691. './Matrix3',
  19692. './Matrix4',
  19693. './Quaternion',
  19694. './TimeConstants'
  19695. ], function(
  19696. when,
  19697. Cartesian2,
  19698. Cartesian3,
  19699. Cartesian4,
  19700. Cartographic,
  19701. defaultValue,
  19702. defined,
  19703. deprecationWarning,
  19704. DeveloperError,
  19705. EarthOrientationParameters,
  19706. EarthOrientationParametersSample,
  19707. Ellipsoid,
  19708. HeadingPitchRoll,
  19709. Iau2006XysData,
  19710. Iau2006XysSample,
  19711. JulianDate,
  19712. CesiumMath,
  19713. Matrix3,
  19714. Matrix4,
  19715. Quaternion,
  19716. TimeConstants) {
  19717. 'use strict';
  19718. /**
  19719. * Contains functions for transforming positions to various reference frames.
  19720. *
  19721. * @exports Transforms
  19722. */
  19723. var Transforms = {};
  19724. var eastNorthUpToFixedFrameNormal = new Cartesian3();
  19725. var eastNorthUpToFixedFrameTangent = new Cartesian3();
  19726. var eastNorthUpToFixedFrameBitangent = new Cartesian3();
  19727. /**
  19728. * Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes
  19729. * centered at the provided origin to the provided ellipsoid's fixed reference frame.
  19730. * The local axes are defined as:
  19731. * <ul>
  19732. * <li>The <code>x</code> axis points in the local east direction.</li>
  19733. * <li>The <code>y</code> axis points in the local north direction.</li>
  19734. * <li>The <code>z</code> axis points in the direction of the ellipsoid surface normal which passes through the position.</li>
  19735. * </ul>
  19736. *
  19737. * @param {Cartesian3} origin The center point of the local reference frame.
  19738. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
  19739. * @param {Matrix4} [result] The object onto which to store the result.
  19740. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.
  19741. *
  19742. * @example
  19743. * // Get the transform from local east-north-up at cartographic (0.0, 0.0) to Earth's fixed frame.
  19744. * var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
  19745. * var transform = Cesium.Transforms.eastNorthUpToFixedFrame(center);
  19746. */
  19747. Transforms.eastNorthUpToFixedFrame = function(origin, ellipsoid, result) {
  19748. if (!defined(origin)) {
  19749. throw new DeveloperError('origin is required.');
  19750. }
  19751. // If x and y are zero, assume origin is at a pole, which is a special case.
  19752. if (CesiumMath.equalsEpsilon(origin.x, 0.0, CesiumMath.EPSILON14) &&
  19753. CesiumMath.equalsEpsilon(origin.y, 0.0, CesiumMath.EPSILON14)) {
  19754. var sign = CesiumMath.sign(origin.z);
  19755. if (!defined(result)) {
  19756. return new Matrix4(
  19757. 0.0, -sign, 0.0, origin.x,
  19758. 1.0, 0.0, 0.0, origin.y,
  19759. 0.0, 0.0, sign, origin.z,
  19760. 0.0, 0.0, 0.0, 1.0);
  19761. }
  19762. result[0] = 0.0;
  19763. result[1] = 1.0;
  19764. result[2] = 0.0;
  19765. result[3] = 0.0;
  19766. result[4] = -sign;
  19767. result[5] = 0.0;
  19768. result[6] = 0.0;
  19769. result[7] = 0.0;
  19770. result[8] = 0.0;
  19771. result[9] = 0.0;
  19772. result[10] = sign;
  19773. result[11] = 0.0;
  19774. result[12] = origin.x;
  19775. result[13] = origin.y;
  19776. result[14] = origin.z;
  19777. result[15] = 1.0;
  19778. return result;
  19779. }
  19780. var normal = eastNorthUpToFixedFrameNormal;
  19781. var tangent = eastNorthUpToFixedFrameTangent;
  19782. var bitangent = eastNorthUpToFixedFrameBitangent;
  19783. ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
  19784. ellipsoid.geodeticSurfaceNormal(origin, normal);
  19785. tangent.x = -origin.y;
  19786. tangent.y = origin.x;
  19787. tangent.z = 0.0;
  19788. Cartesian3.normalize(tangent, tangent);
  19789. Cartesian3.cross(normal, tangent, bitangent);
  19790. if (!defined(result)) {
  19791. return new Matrix4(
  19792. tangent.x, bitangent.x, normal.x, origin.x,
  19793. tangent.y, bitangent.y, normal.y, origin.y,
  19794. tangent.z, bitangent.z, normal.z, origin.z,
  19795. 0.0, 0.0, 0.0, 1.0);
  19796. }
  19797. result[0] = tangent.x;
  19798. result[1] = tangent.y;
  19799. result[2] = tangent.z;
  19800. result[3] = 0.0;
  19801. result[4] = bitangent.x;
  19802. result[5] = bitangent.y;
  19803. result[6] = bitangent.z;
  19804. result[7] = 0.0;
  19805. result[8] = normal.x;
  19806. result[9] = normal.y;
  19807. result[10] = normal.z;
  19808. result[11] = 0.0;
  19809. result[12] = origin.x;
  19810. result[13] = origin.y;
  19811. result[14] = origin.z;
  19812. result[15] = 1.0;
  19813. return result;
  19814. };
  19815. var northEastDownToFixedFrameNormal = new Cartesian3();
  19816. var northEastDownToFixedFrameTangent = new Cartesian3();
  19817. var northEastDownToFixedFrameBitangent = new Cartesian3();
  19818. /**
  19819. * Computes a 4x4 transformation matrix from a reference frame with an north-east-down axes
  19820. * centered at the provided origin to the provided ellipsoid's fixed reference frame.
  19821. * The local axes are defined as:
  19822. * <ul>
  19823. * <li>The <code>x</code> axis points in the local north direction.</li>
  19824. * <li>The <code>y</code> axis points in the local east direction.</li>
  19825. * <li>The <code>z</code> axis points in the opposite direction of the ellipsoid surface normal which passes through the position.</li>
  19826. * </ul>
  19827. *
  19828. * @param {Cartesian3} origin The center point of the local reference frame.
  19829. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
  19830. * @param {Matrix4} [result] The object onto which to store the result.
  19831. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.
  19832. *
  19833. * @example
  19834. * // Get the transform from local north-east-down at cartographic (0.0, 0.0) to Earth's fixed frame.
  19835. * var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
  19836. * var transform = Cesium.Transforms.northEastDownToFixedFrame(center);
  19837. */
  19838. Transforms.northEastDownToFixedFrame = function(origin, ellipsoid, result) {
  19839. if (!defined(origin)) {
  19840. throw new DeveloperError('origin is required.');
  19841. }
  19842. if (CesiumMath.equalsEpsilon(origin.x, 0.0, CesiumMath.EPSILON14) &&
  19843. CesiumMath.equalsEpsilon(origin.y, 0.0, CesiumMath.EPSILON14)) {
  19844. // The poles are special cases. If x and y are zero, assume origin is at a pole.
  19845. var sign = CesiumMath.sign(origin.z);
  19846. if (!defined(result)) {
  19847. return new Matrix4(
  19848. -sign, 0.0, 0.0, origin.x,
  19849. 0.0, 1.0, 0.0, origin.y,
  19850. 0.0, 0.0, -sign, origin.z,
  19851. 0.0, 0.0, 0.0, 1.0);
  19852. }
  19853. result[0] = -sign;
  19854. result[1] = 0.0;
  19855. result[2] = 0.0;
  19856. result[3] = 0.0;
  19857. result[4] = 0.0;
  19858. result[5] = 1.0;
  19859. result[6] = 0.0;
  19860. result[7] = 0.0;
  19861. result[8] = 0.0;
  19862. result[9] = 0.0;
  19863. result[10] = -sign;
  19864. result[11] = 0.0;
  19865. result[12] = origin.x;
  19866. result[13] = origin.y;
  19867. result[14] = origin.z;
  19868. result[15] = 1.0;
  19869. return result;
  19870. }
  19871. var normal = northEastDownToFixedFrameNormal;
  19872. var tangent = northEastDownToFixedFrameTangent;
  19873. var bitangent = northEastDownToFixedFrameBitangent;
  19874. ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
  19875. ellipsoid.geodeticSurfaceNormal(origin, normal);
  19876. tangent.x = -origin.y;
  19877. tangent.y = origin.x;
  19878. tangent.z = 0.0;
  19879. Cartesian3.normalize(tangent, tangent);
  19880. Cartesian3.cross(normal, tangent, bitangent);
  19881. if (!defined(result)) {
  19882. return new Matrix4(
  19883. bitangent.x, tangent.x, -normal.x, origin.x,
  19884. bitangent.y, tangent.y, -normal.y, origin.y,
  19885. bitangent.z, tangent.z, -normal.z, origin.z,
  19886. 0.0, 0.0, 0.0, 1.0);
  19887. }
  19888. result[0] = bitangent.x;
  19889. result[1] = bitangent.y;
  19890. result[2] = bitangent.z;
  19891. result[3] = 0.0;
  19892. result[4] = tangent.x;
  19893. result[5] = tangent.y;
  19894. result[6] = tangent.z;
  19895. result[7] = 0.0;
  19896. result[8] = -normal.x;
  19897. result[9] = -normal.y;
  19898. result[10] = -normal.z;
  19899. result[11] = 0.0;
  19900. result[12] = origin.x;
  19901. result[13] = origin.y;
  19902. result[14] = origin.z;
  19903. result[15] = 1.0;
  19904. return result;
  19905. };
  19906. /**
  19907. * Computes a 4x4 transformation matrix from a reference frame with an north-up-east axes
  19908. * centered at the provided origin to the provided ellipsoid's fixed reference frame.
  19909. * The local axes are defined as:
  19910. * <ul>
  19911. * <li>The <code>x</code> axis points in the local north direction.</li>
  19912. * <li>The <code>y</code> axis points in the direction of the ellipsoid surface normal which passes through the position.</li>
  19913. * <li>The <code>z</code> axis points in the local east direction.</li>
  19914. * </ul>
  19915. *
  19916. * @param {Cartesian3} origin The center point of the local reference frame.
  19917. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
  19918. * @param {Matrix4} [result] The object onto which to store the result.
  19919. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.
  19920. *
  19921. * @example
  19922. * // Get the transform from local north-up-east at cartographic (0.0, 0.0) to Earth's fixed frame.
  19923. * var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
  19924. * var transform = Cesium.Transforms.northUpEastToFixedFrame(center);
  19925. */
  19926. Transforms.northUpEastToFixedFrame = function(origin, ellipsoid, result) {
  19927. if (!defined(origin)) {
  19928. throw new DeveloperError('origin is required.');
  19929. }
  19930. // If x and y are zero, assume origin is at a pole, which is a special case.
  19931. if (CesiumMath.equalsEpsilon(origin.x, 0.0, CesiumMath.EPSILON14) &&
  19932. CesiumMath.equalsEpsilon(origin.y, 0.0, CesiumMath.EPSILON14)) {
  19933. var sign = CesiumMath.sign(origin.z);
  19934. if (!defined(result)) {
  19935. return new Matrix4(
  19936. -sign, 0.0, 0.0, origin.x,
  19937. 0.0, 0.0, 1.0, origin.y,
  19938. 0.0, sign, 0.0, origin.z,
  19939. 0.0, 0.0, 0.0, 1.0);
  19940. }
  19941. result[0] = -sign;
  19942. result[1] = 0.0;
  19943. result[2] = 0.0;
  19944. result[3] = 0.0;
  19945. result[4] = 0.0;
  19946. result[5] = 0.0;
  19947. result[6] = sign;
  19948. result[7] = 0.0;
  19949. result[8] = 0.0;
  19950. result[9] = 1.0;
  19951. result[10] = 0.0;
  19952. result[11] = 0.0;
  19953. result[12] = origin.x;
  19954. result[13] = origin.y;
  19955. result[14] = origin.z;
  19956. result[15] = 1.0;
  19957. return result;
  19958. }
  19959. var normal = eastNorthUpToFixedFrameNormal;
  19960. var tangent = eastNorthUpToFixedFrameTangent;
  19961. var bitangent = eastNorthUpToFixedFrameBitangent;
  19962. ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
  19963. ellipsoid.geodeticSurfaceNormal(origin, normal);
  19964. tangent.x = -origin.y;
  19965. tangent.y = origin.x;
  19966. tangent.z = 0.0;
  19967. Cartesian3.normalize(tangent, tangent);
  19968. Cartesian3.cross(normal, tangent, bitangent);
  19969. if (!defined(result)) {
  19970. return new Matrix4(
  19971. bitangent.x, normal.x, tangent.x, origin.x,
  19972. bitangent.y, normal.y, tangent.y, origin.y,
  19973. bitangent.z, normal.z, tangent.z, origin.z,
  19974. 0.0, 0.0, 0.0, 1.0);
  19975. }
  19976. result[0] = bitangent.x;
  19977. result[1] = bitangent.y;
  19978. result[2] = bitangent.z;
  19979. result[3] = 0.0;
  19980. result[4] = normal.x;
  19981. result[5] = normal.y;
  19982. result[6] = normal.z;
  19983. result[7] = 0.0;
  19984. result[8] = tangent.x;
  19985. result[9] = tangent.y;
  19986. result[10] = tangent.z;
  19987. result[11] = 0.0;
  19988. result[12] = origin.x;
  19989. result[13] = origin.y;
  19990. result[14] = origin.z;
  19991. result[15] = 1.0;
  19992. return result;
  19993. };
  19994. /**
  19995. * Computes a 4x4 transformation matrix from a reference frame with an north-west-up axes
  19996. * centered at the provided origin to the provided ellipsoid's fixed reference frame.
  19997. * The local axes are defined as:
  19998. * <ul>
  19999. * <li>The <code>x</code> axis points in the local north direction.</li>
  20000. * <li>The <code>y</code> axis points in the local west direction.</li>
  20001. * <li>The <code>z</code> axis points in the direction of the ellipsoid surface normal which passes through the position.</li>
  20002. * </ul>
  20003. *
  20004. * @param {Cartesian3} origin The center point of the local reference frame.
  20005. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
  20006. * @param {Matrix4} [result] The object onto which to store the result.
  20007. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.
  20008. *
  20009. * @example
  20010. * // Get the transform from local north-West-Up at cartographic (0.0, 0.0) to Earth's fixed frame.
  20011. * var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
  20012. * var transform = Cesium.Transforms.northWestUpToFixedFrame(center);
  20013. */
  20014. Transforms.northWestUpToFixedFrame = function(origin, ellipsoid, result) {
  20015. if (!defined(origin)) {
  20016. throw new DeveloperError('origin is required.');
  20017. }
  20018. // If x and y are zero, assume origin is at a pole, which is a special case.
  20019. if (CesiumMath.equalsEpsilon(origin.x, 0.0, CesiumMath.EPSILON14) &&
  20020. CesiumMath.equalsEpsilon(origin.y, 0.0, CesiumMath.EPSILON14)) {
  20021. var sign = CesiumMath.sign(origin.z);
  20022. if (!defined(result)) {
  20023. return new Matrix4(
  20024. -sign, 0.0, 0.0, origin.x,
  20025. 0.0, -1.0, 0.0, origin.y,
  20026. 0.0, 0.0, sign, origin.z,
  20027. 0.0, 0.0, 0.0, 1.0);
  20028. }
  20029. result[0] = -sign;
  20030. result[1] = 0.0;
  20031. result[2] = 0.0;
  20032. result[3] = 0.0;
  20033. result[4] = 0.0;
  20034. result[5] = -1.0;
  20035. result[6] = 0.0;
  20036. result[7] = 0.0;
  20037. result[8] = 0.0;
  20038. result[9] = 0.0;
  20039. result[10] = sign;
  20040. result[11] = 0.0;
  20041. result[12] = origin.x;
  20042. result[13] = origin.y;
  20043. result[14] = origin.z;
  20044. result[15] = 1.0;
  20045. return result;
  20046. }
  20047. var normal = eastNorthUpToFixedFrameNormal;//Up
  20048. var tangent = eastNorthUpToFixedFrameTangent;//East
  20049. var bitangent = eastNorthUpToFixedFrameBitangent;//North
  20050. ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
  20051. ellipsoid.geodeticSurfaceNormal(origin, normal);
  20052. tangent.x = -origin.y;
  20053. tangent.y = origin.x;
  20054. tangent.z = 0.0;
  20055. Cartesian3.normalize(tangent, tangent);
  20056. Cartesian3.cross(normal, tangent, bitangent);
  20057. if (!defined(result)) {
  20058. return new Matrix4(
  20059. bitangent.x, -tangent.x, normal.x, origin.x,
  20060. bitangent.y, -tangent.y, normal.y, origin.y,
  20061. bitangent.z, -tangent.z, normal.z, origin.z,
  20062. 0.0, 0.0, 0.0, 1.0);
  20063. }
  20064. result[0] = bitangent.x;
  20065. result[1] = bitangent.y;
  20066. result[2] = bitangent.z;
  20067. result[3] = 0.0;
  20068. result[4] = -tangent.x;
  20069. result[5] = -tangent.y;
  20070. result[6] = -tangent.z;
  20071. result[7] = 0.0;
  20072. result[8] = normal.x;
  20073. result[9] = normal.y;
  20074. result[10] = normal.z;
  20075. result[11] = 0.0;
  20076. result[12] = origin.x;
  20077. result[13] = origin.y;
  20078. result[14] = origin.z;
  20079. result[15] = 1.0;
  20080. return result;
  20081. };
  20082. var scratchHPRQuaternion = new Quaternion();
  20083. var scratchScale = new Cartesian3(1.0, 1.0, 1.0);
  20084. var scratchHPRMatrix4 = new Matrix4();
  20085. /**
  20086. * Computes a 4x4 transformation matrix from a reference frame with axes computed from the heading-pitch-roll angles
  20087. * centered at the provided origin to the provided ellipsoid's fixed reference frame. Heading is the rotation from the local north
  20088. * direction where a positive angle is increasing eastward. Pitch is the rotation from the local east-north plane. Positive pitch angles
  20089. * are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.
  20090. *
  20091. * @param {Cartesian3} origin The center point of the local reference frame.
  20092. * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll.
  20093. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
  20094. * @param {Matrix4} [result] The object onto which to store the result.
  20095. * @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.
  20096. *
  20097. * @example
  20098. * // Get the transform from local heading-pitch-roll at cartographic (0.0, 0.0) to Earth's fixed frame.
  20099. * var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
  20100. * var heading = -Cesium.Math.PI_OVER_TWO;
  20101. * var pitch = Cesium.Math.PI_OVER_FOUR;
  20102. * var roll = 0.0;
  20103. * var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
  20104. * var transform = Cesium.Transforms.headingPitchRollToFixedFrame(center, hpr);
  20105. */
  20106. Transforms.headingPitchRollToFixedFrame = function(origin, headingPitchRoll, pitch, roll, ellipsoid, result) {
  20107. var heading;
  20108. if (typeof headingPitchRoll === 'object') {
  20109. // Shift arguments using assignments to encourage JIT optimization.
  20110. ellipsoid = pitch;
  20111. result = roll;
  20112. heading = headingPitchRoll.heading;
  20113. pitch = headingPitchRoll.pitch;
  20114. roll = headingPitchRoll.roll;
  20115. } else {
  20116. deprecationWarning('headingPitchRollToFixedFrame', 'headingPitchRollToFixedFrame with separate heading, pitch, and roll arguments was deprecated in 1.27. It will be removed in 1.30. Use a HeadingPitchRoll object.');
  20117. heading = headingPitchRoll;
  20118. }
  20119. // checks for required parameters happen in the called functions
  20120. var hprQuaternion = Quaternion.fromHeadingPitchRoll(heading, pitch, roll, scratchHPRQuaternion);
  20121. var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(Cartesian3.ZERO, hprQuaternion, scratchScale, scratchHPRMatrix4);
  20122. result = Transforms.eastNorthUpToFixedFrame(origin, ellipsoid, result);
  20123. return Matrix4.multiply(result, hprMatrix, result);
  20124. };
  20125. var scratchHPR = new HeadingPitchRoll();
  20126. var scratchENUMatrix4 = new Matrix4();
  20127. var scratchHPRMatrix3 = new Matrix3();
  20128. /**
  20129. * Computes a quaternion from a reference frame with axes computed from the heading-pitch-roll angles
  20130. * centered at the provided origin. Heading is the rotation from the local north
  20131. * direction where a positive angle is increasing eastward. Pitch is the rotation from the local east-north plane. Positive pitch angles
  20132. * are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.
  20133. *
  20134. * @param {Cartesian3} origin The center point of the local reference frame.
  20135. * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll.
  20136. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
  20137. * @param {Quaternion} [result] The object onto which to store the result.
  20138. * @returns {Quaternion} The modified result parameter or a new Quaternion instance if none was provided.
  20139. *
  20140. * @example
  20141. * // Get the quaternion from local heading-pitch-roll at cartographic (0.0, 0.0) to Earth's fixed frame.
  20142. * var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
  20143. * var heading = -Cesium.Math.PI_OVER_TWO;
  20144. * var pitch = Cesium.Math.PI_OVER_FOUR;
  20145. * var roll = 0.0;
  20146. * var hpr = new HeadingPitchRoll(heading, pitch, roll);
  20147. * var quaternion = Cesium.Transforms.headingPitchRollQuaternion(center, hpr);
  20148. */
  20149. Transforms.headingPitchRollQuaternion = function(origin, headingPitchRoll, pitch, roll, ellipsoid, result) {
  20150. var hpr;
  20151. if (typeof headingPitchRoll === 'object') {
  20152. // Shift arguments using assignment to encourage JIT optimization.
  20153. hpr = headingPitchRoll;
  20154. ellipsoid = pitch;
  20155. result = roll;
  20156. } else {
  20157. deprecationWarning('headingPitchRollQuaternion', 'headingPitchRollQuaternion with separate heading, pitch, and roll arguments was deprecated in 1.27. It will be removed in 1.30. Use a HeadingPitchRoll object.');
  20158. scratchHPR.heading = headingPitchRoll;
  20159. scratchHPR.pitch = pitch;
  20160. scratchHPR.roll = roll;
  20161. hpr = scratchHPR;
  20162. }
  20163. // checks for required parameters happen in the called functions
  20164. var transform = Transforms.headingPitchRollToFixedFrame(origin, hpr, ellipsoid, scratchENUMatrix4);
  20165. var rotation = Matrix4.getRotation(transform, scratchHPRMatrix3);
  20166. return Quaternion.fromRotationMatrix(rotation, result);
  20167. };
  20168. var gmstConstant0 = 6 * 3600 + 41 * 60 + 50.54841;
  20169. var gmstConstant1 = 8640184.812866;
  20170. var gmstConstant2 = 0.093104;
  20171. var gmstConstant3 = -6.2E-6;
  20172. var rateCoef = 1.1772758384668e-19;
  20173. var wgs84WRPrecessing = 7.2921158553E-5;
  20174. var twoPiOverSecondsInDay = CesiumMath.TWO_PI / 86400.0;
  20175. var dateInUtc = new JulianDate();
  20176. /**
  20177. * Computes a rotation matrix to transform a point or vector from True Equator Mean Equinox (TEME) axes to the
  20178. * pseudo-fixed axes at a given time. This method treats the UT1 time standard as equivalent to UTC.
  20179. *
  20180. * @param {JulianDate} date The time at which to compute the rotation matrix.
  20181. * @param {Matrix3} [result] The object onto which to store the result.
  20182. * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if none was provided.
  20183. *
  20184. * @example
  20185. * //Set the view to in the inertial frame.
  20186. * scene.preRender.addEventListener(function(scene, time) {
  20187. * var now = Cesium.JulianDate.now();
  20188. * var offset = Cesium.Matrix4.multiplyByPoint(camera.transform, camera.position, new Cesium.Cartesian3());
  20189. * var transform = Cesium.Matrix4.fromRotationTranslation(Cesium.Transforms.computeTemeToPseudoFixedMatrix(now));
  20190. * var inverseTransform = Cesium.Matrix4.inverseTransformation(transform, new Cesium.Matrix4());
  20191. * Cesium.Matrix4.multiplyByPoint(inverseTransform, offset, offset);
  20192. * camera.lookAtTransform(transform, offset);
  20193. * });
  20194. */
  20195. Transforms.computeTemeToPseudoFixedMatrix = function (date, result) {
  20196. if (!defined(date)) {
  20197. throw new DeveloperError('date is required.');
  20198. }
  20199. // GMST is actually computed using UT1. We're using UTC as an approximation of UT1.
  20200. // We do not want to use the function like convertTaiToUtc in JulianDate because
  20201. // we explicitly do not want to fail when inside the leap second.
  20202. dateInUtc = JulianDate.addSeconds(date, -JulianDate.computeTaiMinusUtc(date), dateInUtc);
  20203. var utcDayNumber = dateInUtc.dayNumber;
  20204. var utcSecondsIntoDay = dateInUtc.secondsOfDay;
  20205. var t;
  20206. var diffDays = utcDayNumber - 2451545;
  20207. if (utcSecondsIntoDay >= 43200.0) {
  20208. t = (diffDays + 0.5) / TimeConstants.DAYS_PER_JULIAN_CENTURY;
  20209. } else {
  20210. t = (diffDays - 0.5) / TimeConstants.DAYS_PER_JULIAN_CENTURY;
  20211. }
  20212. var gmst0 = gmstConstant0 + t * (gmstConstant1 + t * (gmstConstant2 + t * gmstConstant3));
  20213. var angle = (gmst0 * twoPiOverSecondsInDay) % CesiumMath.TWO_PI;
  20214. var ratio = wgs84WRPrecessing + rateCoef * (utcDayNumber - 2451545.5);
  20215. var secondsSinceMidnight = (utcSecondsIntoDay + TimeConstants.SECONDS_PER_DAY * 0.5) % TimeConstants.SECONDS_PER_DAY;
  20216. var gha = angle + (ratio * secondsSinceMidnight);
  20217. var cosGha = Math.cos(gha);
  20218. var sinGha = Math.sin(gha);
  20219. if (!defined(result)) {
  20220. return new Matrix3(cosGha, sinGha, 0.0,
  20221. -sinGha, cosGha, 0.0,
  20222. 0.0, 0.0, 1.0);
  20223. }
  20224. result[0] = cosGha;
  20225. result[1] = -sinGha;
  20226. result[2] = 0.0;
  20227. result[3] = sinGha;
  20228. result[4] = cosGha;
  20229. result[5] = 0.0;
  20230. result[6] = 0.0;
  20231. result[7] = 0.0;
  20232. result[8] = 1.0;
  20233. return result;
  20234. };
  20235. /**
  20236. * The source of IAU 2006 XYS data, used for computing the transformation between the
  20237. * Fixed and ICRF axes.
  20238. * @type {Iau2006XysData}
  20239. *
  20240. * @see Transforms.computeIcrfToFixedMatrix
  20241. * @see Transforms.computeFixedToIcrfMatrix
  20242. *
  20243. * @private
  20244. */
  20245. Transforms.iau2006XysData = new Iau2006XysData();
  20246. /**
  20247. * The source of Earth Orientation Parameters (EOP) data, used for computing the transformation
  20248. * between the Fixed and ICRF axes. By default, zero values are used for all EOP values,
  20249. * yielding a reasonable but not completely accurate representation of the ICRF axes.
  20250. * @type {EarthOrientationParameters}
  20251. *
  20252. * @see Transforms.computeIcrfToFixedMatrix
  20253. * @see Transforms.computeFixedToIcrfMatrix
  20254. *
  20255. * @private
  20256. */
  20257. Transforms.earthOrientationParameters = EarthOrientationParameters.NONE;
  20258. var ttMinusTai = 32.184;
  20259. var j2000ttDays = 2451545.0;
  20260. /**
  20261. * Preloads the data necessary to transform between the ICRF and Fixed axes, in either
  20262. * direction, over a given interval. This function returns a promise that, when resolved,
  20263. * indicates that the preload has completed.
  20264. *
  20265. * @param {TimeInterval} timeInterval The interval to preload.
  20266. * @returns {Promise.<undefined>} A promise that, when resolved, indicates that the preload has completed
  20267. * and evaluation of the transformation between the fixed and ICRF axes will
  20268. * no longer return undefined for a time inside the interval.
  20269. *
  20270. *
  20271. * @example
  20272. * var interval = new Cesium.TimeInterval(...);
  20273. * when(Cesium.Transforms.preloadIcrfFixed(interval), function() {
  20274. * // the data is now loaded
  20275. * });
  20276. *
  20277. * @see Transforms.computeIcrfToFixedMatrix
  20278. * @see Transforms.computeFixedToIcrfMatrix
  20279. * @see when
  20280. */
  20281. Transforms.preloadIcrfFixed = function(timeInterval) {
  20282. var startDayTT = timeInterval.start.dayNumber;
  20283. var startSecondTT = timeInterval.start.secondsOfDay + ttMinusTai;
  20284. var stopDayTT = timeInterval.stop.dayNumber;
  20285. var stopSecondTT = timeInterval.stop.secondsOfDay + ttMinusTai;
  20286. var xysPromise = Transforms.iau2006XysData.preload(startDayTT, startSecondTT, stopDayTT, stopSecondTT);
  20287. var eopPromise = Transforms.earthOrientationParameters.getPromiseToLoad();
  20288. return when.all([xysPromise, eopPromise]);
  20289. };
  20290. /**
  20291. * Computes a rotation matrix to transform a point or vector from the International Celestial
  20292. * Reference Frame (GCRF/ICRF) inertial frame axes to the Earth-Fixed frame axes (ITRF)
  20293. * at a given time. This function may return undefined if the data necessary to
  20294. * do the transformation is not yet loaded.
  20295. *
  20296. * @param {JulianDate} date The time at which to compute the rotation matrix.
  20297. * @param {Matrix3} [result] The object onto which to store the result. If this parameter is
  20298. * not specified, a new instance is created and returned.
  20299. * @returns {Matrix3} The rotation matrix, or undefined if the data necessary to do the
  20300. * transformation is not yet loaded.
  20301. *
  20302. *
  20303. * @example
  20304. * scene.preRender.addEventListener(function(scene, time) {
  20305. * var icrfToFixed = Cesium.Transforms.computeIcrfToFixedMatrix(time);
  20306. * if (Cesium.defined(icrfToFixed)) {
  20307. * var offset = Cesium.Matrix4.multiplyByPoint(camera.transform, camera.position, new Cesium.Cartesian3());
  20308. * var transform = Cesium.Matrix4.fromRotationTranslation(icrfToFixed)
  20309. * var inverseTransform = Cesium.Matrix4.inverseTransformation(transform, new Cesium.Matrix4());
  20310. * Cesium.Matrix4.multiplyByPoint(inverseTransform, offset, offset);
  20311. * camera.lookAtTransform(transform, offset);
  20312. * }
  20313. * });
  20314. *
  20315. * @see Transforms.preloadIcrfFixed
  20316. */
  20317. Transforms.computeIcrfToFixedMatrix = function(date, result) {
  20318. if (!defined(date)) {
  20319. throw new DeveloperError('date is required.');
  20320. }
  20321. if (!defined(result)) {
  20322. result = new Matrix3();
  20323. }
  20324. var fixedToIcrfMtx = Transforms.computeFixedToIcrfMatrix(date, result);
  20325. if (!defined(fixedToIcrfMtx)) {
  20326. return undefined;
  20327. }
  20328. return Matrix3.transpose(fixedToIcrfMtx, result);
  20329. };
  20330. var xysScratch = new Iau2006XysSample(0.0, 0.0, 0.0);
  20331. var eopScratch = new EarthOrientationParametersSample(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  20332. var rotation1Scratch = new Matrix3();
  20333. var rotation2Scratch = new Matrix3();
  20334. /**
  20335. * Computes a rotation matrix to transform a point or vector from the Earth-Fixed frame axes (ITRF)
  20336. * to the International Celestial Reference Frame (GCRF/ICRF) inertial frame axes
  20337. * at a given time. This function may return undefined if the data necessary to
  20338. * do the transformation is not yet loaded.
  20339. *
  20340. * @param {JulianDate} date The time at which to compute the rotation matrix.
  20341. * @param {Matrix3} [result] The object onto which to store the result. If this parameter is
  20342. * not specified, a new instance is created and returned.
  20343. * @returns {Matrix3} The rotation matrix, or undefined if the data necessary to do the
  20344. * transformation is not yet loaded.
  20345. *
  20346. *
  20347. * @example
  20348. * // Transform a point from the ICRF axes to the Fixed axes.
  20349. * var now = Cesium.JulianDate.now();
  20350. * var pointInFixed = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
  20351. * var fixedToIcrf = Cesium.Transforms.computeIcrfToFixedMatrix(now);
  20352. * var pointInInertial = new Cesium.Cartesian3();
  20353. * if (Cesium.defined(fixedToIcrf)) {
  20354. * pointInInertial = Cesium.Matrix3.multiplyByVector(fixedToIcrf, pointInFixed, pointInInertial);
  20355. * }
  20356. *
  20357. * @see Transforms.preloadIcrfFixed
  20358. */
  20359. Transforms.computeFixedToIcrfMatrix = function(date, result) {
  20360. if (!defined(date)) {
  20361. throw new DeveloperError('date is required.');
  20362. }
  20363. if (!defined(result)) {
  20364. result = new Matrix3();
  20365. }
  20366. // Compute pole wander
  20367. var eop = Transforms.earthOrientationParameters.compute(date, eopScratch);
  20368. if (!defined(eop)) {
  20369. return undefined;
  20370. }
  20371. // There is no external conversion to Terrestrial Time (TT).
  20372. // So use International Atomic Time (TAI) and convert using offsets.
  20373. // Here we are assuming that dayTT and secondTT are positive
  20374. var dayTT = date.dayNumber;
  20375. // It's possible here that secondTT could roll over 86400
  20376. // This does not seem to affect the precision (unit tests check for this)
  20377. var secondTT = date.secondsOfDay + ttMinusTai;
  20378. var xys = Transforms.iau2006XysData.computeXysRadians(dayTT, secondTT, xysScratch);
  20379. if (!defined(xys)) {
  20380. return undefined;
  20381. }
  20382. var x = xys.x + eop.xPoleOffset;
  20383. var y = xys.y + eop.yPoleOffset;
  20384. // Compute XYS rotation
  20385. var a = 1.0 / (1.0 + Math.sqrt(1.0 - x * x - y * y));
  20386. var rotation1 = rotation1Scratch;
  20387. rotation1[0] = 1.0 - a * x * x;
  20388. rotation1[3] = -a * x * y;
  20389. rotation1[6] = x;
  20390. rotation1[1] = -a * x * y;
  20391. rotation1[4] = 1 - a * y * y;
  20392. rotation1[7] = y;
  20393. rotation1[2] = -x;
  20394. rotation1[5] = -y;
  20395. rotation1[8] = 1 - a * (x * x + y * y);
  20396. var rotation2 = Matrix3.fromRotationZ(-xys.s, rotation2Scratch);
  20397. var matrixQ = Matrix3.multiply(rotation1, rotation2, rotation1Scratch);
  20398. // Similar to TT conversions above
  20399. // It's possible here that secondTT could roll over 86400
  20400. // This does not seem to affect the precision (unit tests check for this)
  20401. var dateUt1day = date.dayNumber;
  20402. var dateUt1sec = date.secondsOfDay - JulianDate.computeTaiMinusUtc(date) + eop.ut1MinusUtc;
  20403. // Compute Earth rotation angle
  20404. // The IERS standard for era is
  20405. // era = 0.7790572732640 + 1.00273781191135448 * Tu
  20406. // where
  20407. // Tu = JulianDateInUt1 - 2451545.0
  20408. // However, you get much more precision if you make the following simplification
  20409. // era = a + (1 + b) * (JulianDayNumber + FractionOfDay - 2451545)
  20410. // era = a + (JulianDayNumber - 2451545) + FractionOfDay + b (JulianDayNumber - 2451545 + FractionOfDay)
  20411. // era = a + FractionOfDay + b (JulianDayNumber - 2451545 + FractionOfDay)
  20412. // since (JulianDayNumber - 2451545) represents an integer number of revolutions which will be discarded anyway.
  20413. var daysSinceJ2000 = dateUt1day - 2451545;
  20414. var fractionOfDay = dateUt1sec / TimeConstants.SECONDS_PER_DAY;
  20415. var era = 0.7790572732640 + fractionOfDay + 0.00273781191135448 * (daysSinceJ2000 + fractionOfDay);
  20416. era = (era % 1.0) * CesiumMath.TWO_PI;
  20417. var earthRotation = Matrix3.fromRotationZ(era, rotation2Scratch);
  20418. // pseudoFixed to ICRF
  20419. var pfToIcrf = Matrix3.multiply(matrixQ, earthRotation, rotation1Scratch);
  20420. // Compute pole wander matrix
  20421. var cosxp = Math.cos(eop.xPoleWander);
  20422. var cosyp = Math.cos(eop.yPoleWander);
  20423. var sinxp = Math.sin(eop.xPoleWander);
  20424. var sinyp = Math.sin(eop.yPoleWander);
  20425. var ttt = (dayTT - j2000ttDays) + secondTT / TimeConstants.SECONDS_PER_DAY;
  20426. ttt /= 36525.0;
  20427. // approximate sp value in rad
  20428. var sp = -47.0e-6 * ttt * CesiumMath.RADIANS_PER_DEGREE / 3600.0;
  20429. var cossp = Math.cos(sp);
  20430. var sinsp = Math.sin(sp);
  20431. var fToPfMtx = rotation2Scratch;
  20432. fToPfMtx[0] = cosxp * cossp;
  20433. fToPfMtx[1] = cosxp * sinsp;
  20434. fToPfMtx[2] = sinxp;
  20435. fToPfMtx[3] = -cosyp * sinsp + sinyp * sinxp * cossp;
  20436. fToPfMtx[4] = cosyp * cossp + sinyp * sinxp * sinsp;
  20437. fToPfMtx[5] = -sinyp * cosxp;
  20438. fToPfMtx[6] = -sinyp * sinsp - cosyp * sinxp * cossp;
  20439. fToPfMtx[7] = sinyp * cossp - cosyp * sinxp * sinsp;
  20440. fToPfMtx[8] = cosyp * cosxp;
  20441. return Matrix3.multiply(pfToIcrf, fToPfMtx, result);
  20442. };
  20443. var pointToWindowCoordinatesTemp = new Cartesian4();
  20444. /**
  20445. * Transform a point from model coordinates to window coordinates.
  20446. *
  20447. * @param {Matrix4} modelViewProjectionMatrix The 4x4 model-view-projection matrix.
  20448. * @param {Matrix4} viewportTransformation The 4x4 viewport transformation.
  20449. * @param {Cartesian3} point The point to transform.
  20450. * @param {Cartesian2} [result] The object onto which to store the result.
  20451. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided.
  20452. */
  20453. Transforms.pointToWindowCoordinates = function (modelViewProjectionMatrix, viewportTransformation, point, result) {
  20454. result = Transforms.pointToGLWindowCoordinates(modelViewProjectionMatrix, viewportTransformation, point, result);
  20455. result.y = 2.0 * viewportTransformation[5] - result.y;
  20456. return result;
  20457. };
  20458. /**
  20459. * @private
  20460. */
  20461. Transforms.pointToGLWindowCoordinates = function(modelViewProjectionMatrix, viewportTransformation, point, result) {
  20462. if (!defined(modelViewProjectionMatrix)) {
  20463. throw new DeveloperError('modelViewProjectionMatrix is required.');
  20464. }
  20465. if (!defined(viewportTransformation)) {
  20466. throw new DeveloperError('viewportTransformation is required.');
  20467. }
  20468. if (!defined(point)) {
  20469. throw new DeveloperError('point is required.');
  20470. }
  20471. if (!defined(result)) {
  20472. result = new Cartesian2();
  20473. }
  20474. var tmp = pointToWindowCoordinatesTemp;
  20475. Matrix4.multiplyByVector(modelViewProjectionMatrix, Cartesian4.fromElements(point.x, point.y, point.z, 1, tmp), tmp);
  20476. Cartesian4.multiplyByScalar(tmp, 1.0 / tmp.w, tmp);
  20477. Matrix4.multiplyByVector(viewportTransformation, tmp, tmp);
  20478. return Cartesian2.fromCartesian4(tmp, result);
  20479. };
  20480. var normalScratch = new Cartesian3();
  20481. var rightScratch = new Cartesian3();
  20482. var upScratch = new Cartesian3();
  20483. /**
  20484. * @private
  20485. */
  20486. Transforms.rotationMatrixFromPositionVelocity = function(position, velocity, ellipsoid, result) {
  20487. if (!defined(position)) {
  20488. throw new DeveloperError('position is required.');
  20489. }
  20490. if (!defined(velocity)) {
  20491. throw new DeveloperError('velocity is required.');
  20492. }
  20493. var normal = defaultValue(ellipsoid, Ellipsoid.WGS84).geodeticSurfaceNormal(position, normalScratch);
  20494. var right = Cartesian3.cross(velocity, normal, rightScratch);
  20495. if (Cartesian3.equalsEpsilon(right, Cartesian3.ZERO, CesiumMath.EPSILON6)) {
  20496. right = Cartesian3.clone(Cartesian3.UNIT_X, right);
  20497. }
  20498. var up = Cartesian3.cross(right, velocity, upScratch);
  20499. Cartesian3.cross(velocity, up, right);
  20500. Cartesian3.negate(right, right);
  20501. if (!defined(result)) {
  20502. result = new Matrix3();
  20503. }
  20504. result[0] = velocity.x;
  20505. result[1] = velocity.y;
  20506. result[2] = velocity.z;
  20507. result[3] = right.x;
  20508. result[4] = right.y;
  20509. result[5] = right.z;
  20510. result[6] = up.x;
  20511. result[7] = up.y;
  20512. result[8] = up.z;
  20513. return result;
  20514. };
  20515. var scratchCartographic = new Cartographic();
  20516. var scratchCartesian3Projection = new Cartesian3();
  20517. var scratchCartesian3 = new Cartesian3();
  20518. var scratchCartesian4Origin = new Cartesian4();
  20519. var scratchCartesian4NewOrigin = new Cartesian4();
  20520. var scratchCartesian4NewXAxis = new Cartesian4();
  20521. var scratchCartesian4NewYAxis = new Cartesian4();
  20522. var scratchCartesian4NewZAxis = new Cartesian4();
  20523. var scratchFromENU = new Matrix4();
  20524. var scratchToENU = new Matrix4();
  20525. /**
  20526. * @private
  20527. */
  20528. Transforms.basisTo2D = function(projection, matrix, result) {
  20529. if (!defined(projection)) {
  20530. throw new DeveloperError('projection is required.');
  20531. }
  20532. if (!defined(matrix)) {
  20533. throw new DeveloperError('matrix is required.');
  20534. }
  20535. if (!defined(result)) {
  20536. throw new DeveloperError('result is required.');
  20537. }
  20538. var ellipsoid = projection.ellipsoid;
  20539. var origin = Matrix4.getColumn(matrix, 3, scratchCartesian4Origin);
  20540. var cartographic = ellipsoid.cartesianToCartographic(origin, scratchCartographic);
  20541. var fromENU = Transforms.eastNorthUpToFixedFrame(origin, ellipsoid, scratchFromENU);
  20542. var toENU = Matrix4.inverseTransformation(fromENU, scratchToENU);
  20543. var projectedPosition = projection.project(cartographic, scratchCartesian3Projection);
  20544. var newOrigin = scratchCartesian4NewOrigin;
  20545. newOrigin.x = projectedPosition.z;
  20546. newOrigin.y = projectedPosition.x;
  20547. newOrigin.z = projectedPosition.y;
  20548. newOrigin.w = 1.0;
  20549. var xAxis = Matrix4.getColumn(matrix, 0, scratchCartesian3);
  20550. var xScale = Cartesian3.magnitude(xAxis);
  20551. var newXAxis = Matrix4.multiplyByVector(toENU, xAxis, scratchCartesian4NewXAxis);
  20552. Cartesian4.fromElements(newXAxis.z, newXAxis.x, newXAxis.y, 0.0, newXAxis);
  20553. var yAxis = Matrix4.getColumn(matrix, 1, scratchCartesian3);
  20554. var yScale = Cartesian3.magnitude(yAxis);
  20555. var newYAxis = Matrix4.multiplyByVector(toENU, yAxis, scratchCartesian4NewYAxis);
  20556. Cartesian4.fromElements(newYAxis.z, newYAxis.x, newYAxis.y, 0.0, newYAxis);
  20557. var zAxis = Matrix4.getColumn(matrix, 2, scratchCartesian3);
  20558. var zScale = Cartesian3.magnitude(zAxis);
  20559. var newZAxis = scratchCartesian4NewZAxis;
  20560. Cartesian3.cross(newXAxis, newYAxis, newZAxis);
  20561. Cartesian3.normalize(newZAxis, newZAxis);
  20562. Cartesian3.cross(newYAxis, newZAxis, newXAxis);
  20563. Cartesian3.normalize(newXAxis, newXAxis);
  20564. Cartesian3.cross(newZAxis, newXAxis, newYAxis);
  20565. Cartesian3.normalize(newYAxis, newYAxis);
  20566. Cartesian3.multiplyByScalar(newXAxis, xScale, newXAxis);
  20567. Cartesian3.multiplyByScalar(newYAxis, yScale, newYAxis);
  20568. Cartesian3.multiplyByScalar(newZAxis, zScale, newZAxis);
  20569. Matrix4.setColumn(result, 0, newXAxis, result);
  20570. Matrix4.setColumn(result, 1, newYAxis, result);
  20571. Matrix4.setColumn(result, 2, newZAxis, result);
  20572. Matrix4.setColumn(result, 3, newOrigin, result);
  20573. return result;
  20574. };
  20575. return Transforms;
  20576. });
  20577. /*global define*/
  20578. define('Core/EllipsoidTangentPlane',[
  20579. './AxisAlignedBoundingBox',
  20580. './Cartesian2',
  20581. './Cartesian3',
  20582. './Cartesian4',
  20583. './defaultValue',
  20584. './defined',
  20585. './defineProperties',
  20586. './DeveloperError',
  20587. './Ellipsoid',
  20588. './IntersectionTests',
  20589. './Matrix4',
  20590. './Plane',
  20591. './Ray',
  20592. './Transforms'
  20593. ], function(
  20594. AxisAlignedBoundingBox,
  20595. Cartesian2,
  20596. Cartesian3,
  20597. Cartesian4,
  20598. defaultValue,
  20599. defined,
  20600. defineProperties,
  20601. DeveloperError,
  20602. Ellipsoid,
  20603. IntersectionTests,
  20604. Matrix4,
  20605. Plane,
  20606. Ray,
  20607. Transforms) {
  20608. 'use strict';
  20609. var scratchCart4 = new Cartesian4();
  20610. /**
  20611. * A plane tangent to the provided ellipsoid at the provided origin.
  20612. * If origin is not on the surface of the ellipsoid, it's surface projection will be used.
  20613. * If origin is at the center of the ellipsoid, an exception will be thrown.
  20614. * @alias EllipsoidTangentPlane
  20615. * @constructor
  20616. *
  20617. * @param {Cartesian3} origin The point on the surface of the ellipsoid where the tangent plane touches.
  20618. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use.
  20619. *
  20620. * @exception {DeveloperError} origin must not be at the center of the ellipsoid.
  20621. */
  20622. function EllipsoidTangentPlane(origin, ellipsoid) {
  20623. if (!defined(origin)) {
  20624. throw new DeveloperError('origin is required.');
  20625. }
  20626. ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
  20627. origin = ellipsoid.scaleToGeodeticSurface(origin);
  20628. if (!defined(origin)) {
  20629. throw new DeveloperError('origin must not be at the center of the ellipsoid.');
  20630. }
  20631. var eastNorthUp = Transforms.eastNorthUpToFixedFrame(origin, ellipsoid);
  20632. this._ellipsoid = ellipsoid;
  20633. this._origin = origin;
  20634. this._xAxis = Cartesian3.fromCartesian4(Matrix4.getColumn(eastNorthUp, 0, scratchCart4));
  20635. this._yAxis = Cartesian3.fromCartesian4(Matrix4.getColumn(eastNorthUp, 1, scratchCart4));
  20636. var normal = Cartesian3.fromCartesian4(Matrix4.getColumn(eastNorthUp, 2, scratchCart4));
  20637. this._plane = Plane.fromPointNormal(origin, normal);
  20638. }
  20639. defineProperties(EllipsoidTangentPlane.prototype, {
  20640. /**
  20641. * Gets the ellipsoid.
  20642. * @memberof EllipsoidTangentPlane.prototype
  20643. * @type {Ellipsoid}
  20644. */
  20645. ellipsoid : {
  20646. get : function() {
  20647. return this._ellipsoid;
  20648. }
  20649. },
  20650. /**
  20651. * Gets the origin.
  20652. * @memberof EllipsoidTangentPlane.prototype
  20653. * @type {Cartesian3}
  20654. */
  20655. origin : {
  20656. get : function() {
  20657. return this._origin;
  20658. }
  20659. },
  20660. /**
  20661. * Gets the plane which is tangent to the ellipsoid.
  20662. * @memberof EllipsoidTangentPlane.prototype
  20663. * @readonly
  20664. * @type {Plane}
  20665. */
  20666. plane : {
  20667. get : function() {
  20668. return this._plane;
  20669. }
  20670. },
  20671. /**
  20672. * Gets the local X-axis (east) of the tangent plane.
  20673. * @memberof EllipsoidTangentPlane.prototype
  20674. * @readonly
  20675. * @type {Cartesian3}
  20676. */
  20677. xAxis : {
  20678. get : function() {
  20679. return this._xAxis;
  20680. }
  20681. },
  20682. /**
  20683. * Gets the local Y-axis (north) of the tangent plane.
  20684. * @memberof EllipsoidTangentPlane.prototype
  20685. * @readonly
  20686. * @type {Cartesian3}
  20687. */
  20688. yAxis : {
  20689. get : function() {
  20690. return this._yAxis;
  20691. }
  20692. },
  20693. /**
  20694. * Gets the local Z-axis (up) of the tangent plane.
  20695. * @member EllipsoidTangentPlane.prototype
  20696. * @readonly
  20697. * @type {Cartesian3}
  20698. */
  20699. zAxis : {
  20700. get : function() {
  20701. return this._plane.normal;
  20702. }
  20703. }
  20704. });
  20705. var tmp = new AxisAlignedBoundingBox();
  20706. /**
  20707. * Creates a new instance from the provided ellipsoid and the center
  20708. * point of the provided Cartesians.
  20709. *
  20710. * @param {Ellipsoid} ellipsoid The ellipsoid to use.
  20711. * @param {Cartesian3} cartesians The list of positions surrounding the center point.
  20712. */
  20713. EllipsoidTangentPlane.fromPoints = function(cartesians, ellipsoid) {
  20714. if (!defined(cartesians)) {
  20715. throw new DeveloperError('cartesians is required.');
  20716. }
  20717. var box = AxisAlignedBoundingBox.fromPoints(cartesians, tmp);
  20718. return new EllipsoidTangentPlane(box.center, ellipsoid);
  20719. };
  20720. var scratchProjectPointOntoPlaneRay = new Ray();
  20721. var scratchProjectPointOntoPlaneCartesian3 = new Cartesian3();
  20722. /**
  20723. * Computes the projection of the provided 3D position onto the 2D plane, radially outward from the {@link EllipsoidTangentPlane.ellipsoid} coordinate system origin.
  20724. *
  20725. * @param {Cartesian3} cartesian The point to project.
  20726. * @param {Cartesian2} [result] The object onto which to store the result.
  20727. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided. Undefined if there is no intersection point
  20728. */
  20729. EllipsoidTangentPlane.prototype.projectPointOntoPlane = function(cartesian, result) {
  20730. if (!defined(cartesian)) {
  20731. throw new DeveloperError('cartesian is required.');
  20732. }
  20733. var ray = scratchProjectPointOntoPlaneRay;
  20734. ray.origin = cartesian;
  20735. Cartesian3.normalize(cartesian, ray.direction);
  20736. var intersectionPoint = IntersectionTests.rayPlane(ray, this._plane, scratchProjectPointOntoPlaneCartesian3);
  20737. if (!defined(intersectionPoint)) {
  20738. Cartesian3.negate(ray.direction, ray.direction);
  20739. intersectionPoint = IntersectionTests.rayPlane(ray, this._plane, scratchProjectPointOntoPlaneCartesian3);
  20740. }
  20741. if (defined(intersectionPoint)) {
  20742. var v = Cartesian3.subtract(intersectionPoint, this._origin, intersectionPoint);
  20743. var x = Cartesian3.dot(this._xAxis, v);
  20744. var y = Cartesian3.dot(this._yAxis, v);
  20745. if (!defined(result)) {
  20746. return new Cartesian2(x, y);
  20747. }
  20748. result.x = x;
  20749. result.y = y;
  20750. return result;
  20751. }
  20752. return undefined;
  20753. };
  20754. /**
  20755. * Computes the projection of the provided 3D positions onto the 2D plane (where possible), radially outward from the global origin.
  20756. * The resulting array may be shorter than the input array - if a single projection is impossible it will not be included.
  20757. *
  20758. * @see EllipsoidTangentPlane.projectPointOntoPlane
  20759. *
  20760. * @param {Cartesian3[]} cartesians The array of points to project.
  20761. * @param {Cartesian2[]} [result] The array of Cartesian2 instances onto which to store results.
  20762. * @returns {Cartesian2[]} The modified result parameter or a new array of Cartesian2 instances if none was provided.
  20763. */
  20764. EllipsoidTangentPlane.prototype.projectPointsOntoPlane = function(cartesians, result) {
  20765. if (!defined(cartesians)) {
  20766. throw new DeveloperError('cartesians is required.');
  20767. }
  20768. if (!defined(result)) {
  20769. result = [];
  20770. }
  20771. var count = 0;
  20772. var length = cartesians.length;
  20773. for ( var i = 0; i < length; i++) {
  20774. var p = this.projectPointOntoPlane(cartesians[i], result[count]);
  20775. if (defined(p)) {
  20776. result[count] = p;
  20777. count++;
  20778. }
  20779. }
  20780. result.length = count;
  20781. return result;
  20782. };
  20783. /**
  20784. * Computes the projection of the provided 3D position onto the 2D plane, along the plane normal.
  20785. *
  20786. * @param {Cartesian3} cartesian The point to project.
  20787. * @param {Cartesian2} [result] The object onto which to store the result.
  20788. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if none was provided.
  20789. */
  20790. EllipsoidTangentPlane.prototype.projectPointToNearestOnPlane = function(cartesian, result) {
  20791. if (!defined(cartesian)) {
  20792. throw new DeveloperError('cartesian is required.');
  20793. }
  20794. if (!defined(result)) {
  20795. result = new Cartesian2();
  20796. }
  20797. var ray = scratchProjectPointOntoPlaneRay;
  20798. ray.origin = cartesian;
  20799. Cartesian3.clone(this._plane.normal, ray.direction);
  20800. var intersectionPoint = IntersectionTests.rayPlane(ray, this._plane, scratchProjectPointOntoPlaneCartesian3);
  20801. if (!defined(intersectionPoint)) {
  20802. Cartesian3.negate(ray.direction, ray.direction);
  20803. intersectionPoint = IntersectionTests.rayPlane(ray, this._plane, scratchProjectPointOntoPlaneCartesian3);
  20804. }
  20805. var v = Cartesian3.subtract(intersectionPoint, this._origin, intersectionPoint);
  20806. var x = Cartesian3.dot(this._xAxis, v);
  20807. var y = Cartesian3.dot(this._yAxis, v);
  20808. result.x = x;
  20809. result.y = y;
  20810. return result;
  20811. };
  20812. /**
  20813. * Computes the projection of the provided 3D positions onto the 2D plane, along the plane normal.
  20814. *
  20815. * @see EllipsoidTangentPlane.projectPointToNearestOnPlane
  20816. *
  20817. * @param {Cartesian3[]} cartesians The array of points to project.
  20818. * @param {Cartesian2[]} [result] The array of Cartesian2 instances onto which to store results.
  20819. * @returns {Cartesian2[]} The modified result parameter or a new array of Cartesian2 instances if none was provided. This will have the same length as <code>cartesians</code>.
  20820. */
  20821. EllipsoidTangentPlane.prototype.projectPointsToNearestOnPlane = function(cartesians, result) {
  20822. if (!defined(cartesians)) {
  20823. throw new DeveloperError('cartesians is required.');
  20824. }
  20825. if (!defined(result)) {
  20826. result = [];
  20827. }
  20828. var length = cartesians.length;
  20829. result.length = length;
  20830. for (var i = 0; i < length; i++) {
  20831. result[i] = this.projectPointToNearestOnPlane(cartesians[i], result[i]);
  20832. }
  20833. return result;
  20834. };
  20835. var projectPointsOntoEllipsoidScratch = new Cartesian3();
  20836. /**
  20837. * Computes the projection of the provided 2D positions onto the 3D ellipsoid.
  20838. *
  20839. * @param {Cartesian2[]} cartesians The array of points to project.
  20840. * @param {Cartesian3[]} [result] The array of Cartesian3 instances onto which to store results.
  20841. * @returns {Cartesian3[]} The modified result parameter or a new array of Cartesian3 instances if none was provided.
  20842. */
  20843. EllipsoidTangentPlane.prototype.projectPointsOntoEllipsoid = function(cartesians, result) {
  20844. if (!defined(cartesians)) {
  20845. throw new DeveloperError('cartesians is required.');
  20846. }
  20847. var length = cartesians.length;
  20848. if (!defined(result)) {
  20849. result = new Array(length);
  20850. } else {
  20851. result.length = length;
  20852. }
  20853. var ellipsoid = this._ellipsoid;
  20854. var origin = this._origin;
  20855. var xAxis = this._xAxis;
  20856. var yAxis = this._yAxis;
  20857. var tmp = projectPointsOntoEllipsoidScratch;
  20858. for ( var i = 0; i < length; ++i) {
  20859. var position = cartesians[i];
  20860. Cartesian3.multiplyByScalar(xAxis, position.x, tmp);
  20861. if (!defined(result[i])) {
  20862. result[i] = new Cartesian3();
  20863. }
  20864. var point = Cartesian3.add(origin, tmp, result[i]);
  20865. Cartesian3.multiplyByScalar(yAxis, position.y, tmp);
  20866. Cartesian3.add(point, tmp, point);
  20867. ellipsoid.scaleToGeocentricSurface(point, point);
  20868. }
  20869. return result;
  20870. };
  20871. return EllipsoidTangentPlane;
  20872. });
  20873. /*global define*/
  20874. define('ThirdParty/earcut-2.1.1',[], function() {
  20875. 'use strict';
  20876. function earcut(data, holeIndices, dim) {
  20877. dim = dim || 2;
  20878. var hasHoles = holeIndices && holeIndices.length,
  20879. outerLen = hasHoles ? holeIndices[0] * dim : data.length,
  20880. outerNode = linkedList(data, 0, outerLen, dim, true),
  20881. triangles = [];
  20882. if (!outerNode) return triangles;
  20883. var minX, minY, maxX, maxY, x, y, size;
  20884. if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
  20885. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  20886. if (data.length > 80 * dim) {
  20887. minX = maxX = data[0];
  20888. minY = maxY = data[1];
  20889. for (var i = dim; i < outerLen; i += dim) {
  20890. x = data[i];
  20891. y = data[i + 1];
  20892. if (x < minX) minX = x;
  20893. if (y < minY) minY = y;
  20894. if (x > maxX) maxX = x;
  20895. if (y > maxY) maxY = y;
  20896. }
  20897. // minX, minY and size are later used to transform coords into integers for z-order calculation
  20898. size = Math.max(maxX - minX, maxY - minY);
  20899. }
  20900. earcutLinked(outerNode, triangles, dim, minX, minY, size);
  20901. return triangles;
  20902. }
  20903. // create a circular doubly linked list from polygon points in the specified winding order
  20904. function linkedList(data, start, end, dim, clockwise) {
  20905. var i, last;
  20906. if (clockwise === (signedArea(data, start, end, dim) > 0)) {
  20907. for (i = start; i < end; i += dim) last = insertNode(i, data[i], data[i + 1], last);
  20908. } else {
  20909. for (i = end - dim; i >= start; i -= dim) last = insertNode(i, data[i], data[i + 1], last);
  20910. }
  20911. if (last && equals(last, last.next)) {
  20912. removeNode(last);
  20913. last = last.next;
  20914. }
  20915. return last;
  20916. }
  20917. // eliminate colinear or duplicate points
  20918. function filterPoints(start, end) {
  20919. if (!start) return start;
  20920. if (!end) end = start;
  20921. var p = start,
  20922. again;
  20923. do {
  20924. again = false;
  20925. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  20926. removeNode(p);
  20927. p = end = p.prev;
  20928. if (p === p.next) return null;
  20929. again = true;
  20930. } else {
  20931. p = p.next;
  20932. }
  20933. } while (again || p !== end);
  20934. return end;
  20935. }
  20936. // main ear slicing loop which triangulates a polygon (given as a linked list)
  20937. function earcutLinked(ear, triangles, dim, minX, minY, size, pass) {
  20938. if (!ear) return;
  20939. // interlink polygon nodes in z-order
  20940. if (!pass && size) indexCurve(ear, minX, minY, size);
  20941. var stop = ear,
  20942. prev, next;
  20943. // iterate through ears, slicing them one by one
  20944. while (ear.prev !== ear.next) {
  20945. prev = ear.prev;
  20946. next = ear.next;
  20947. if (size ? isEarHashed(ear, minX, minY, size) : isEar(ear)) {
  20948. // cut off the triangle
  20949. triangles.push(prev.i / dim);
  20950. triangles.push(ear.i / dim);
  20951. triangles.push(next.i / dim);
  20952. removeNode(ear);
  20953. // skipping the next vertice leads to less sliver triangles
  20954. ear = next.next;
  20955. stop = next.next;
  20956. continue;
  20957. }
  20958. ear = next;
  20959. // if we looped through the whole remaining polygon and can't find any more ears
  20960. if (ear === stop) {
  20961. // try filtering points and slicing again
  20962. if (!pass) {
  20963. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, size, 1);
  20964. // if this didn't work, try curing all small self-intersections locally
  20965. } else if (pass === 1) {
  20966. ear = cureLocalIntersections(ear, triangles, dim);
  20967. earcutLinked(ear, triangles, dim, minX, minY, size, 2);
  20968. // as a last resort, try splitting the remaining polygon into two
  20969. } else if (pass === 2) {
  20970. splitEarcut(ear, triangles, dim, minX, minY, size);
  20971. }
  20972. break;
  20973. }
  20974. }
  20975. }
  20976. // check whether a polygon node forms a valid ear with adjacent nodes
  20977. function isEar(ear) {
  20978. var a = ear.prev,
  20979. b = ear,
  20980. c = ear.next;
  20981. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  20982. // now make sure we don't have other points inside the potential ear
  20983. var p = ear.next.next;
  20984. while (p !== ear.prev) {
  20985. if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  20986. area(p.prev, p, p.next) >= 0) return false;
  20987. p = p.next;
  20988. }
  20989. return true;
  20990. }
  20991. function isEarHashed(ear, minX, minY, size) {
  20992. var a = ear.prev,
  20993. b = ear,
  20994. c = ear.next;
  20995. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  20996. // triangle bbox; min & max are calculated like this for speed
  20997. var minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x),
  20998. minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y),
  20999. maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x),
  21000. maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y);
  21001. // z-order range for the current triangle bbox;
  21002. var minZ = zOrder(minTX, minTY, minX, minY, size),
  21003. maxZ = zOrder(maxTX, maxTY, minX, minY, size);
  21004. // first look for points inside the triangle in increasing z-order
  21005. var p = ear.nextZ;
  21006. while (p && p.z <= maxZ) {
  21007. if (p !== ear.prev && p !== ear.next &&
  21008. pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  21009. area(p.prev, p, p.next) >= 0) return false;
  21010. p = p.nextZ;
  21011. }
  21012. // then look for points in decreasing z-order
  21013. p = ear.prevZ;
  21014. while (p && p.z >= minZ) {
  21015. if (p !== ear.prev && p !== ear.next &&
  21016. pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
  21017. area(p.prev, p, p.next) >= 0) return false;
  21018. p = p.prevZ;
  21019. }
  21020. return true;
  21021. }
  21022. // go through all polygon nodes and cure small local self-intersections
  21023. function cureLocalIntersections(start, triangles, dim) {
  21024. var p = start;
  21025. do {
  21026. var a = p.prev,
  21027. b = p.next.next;
  21028. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  21029. triangles.push(a.i / dim);
  21030. triangles.push(p.i / dim);
  21031. triangles.push(b.i / dim);
  21032. // remove two nodes involved
  21033. removeNode(p);
  21034. removeNode(p.next);
  21035. p = start = b;
  21036. }
  21037. p = p.next;
  21038. } while (p !== start);
  21039. return p;
  21040. }
  21041. // try splitting polygon into two and triangulate them independently
  21042. function splitEarcut(start, triangles, dim, minX, minY, size) {
  21043. // look for a valid diagonal that divides the polygon into two
  21044. var a = start;
  21045. do {
  21046. var b = a.next.next;
  21047. while (b !== a.prev) {
  21048. if (a.i !== b.i && isValidDiagonal(a, b)) {
  21049. // split the polygon in two by the diagonal
  21050. var c = splitPolygon(a, b);
  21051. // filter colinear points around the cuts
  21052. a = filterPoints(a, a.next);
  21053. c = filterPoints(c, c.next);
  21054. // run earcut on each half
  21055. earcutLinked(a, triangles, dim, minX, minY, size);
  21056. earcutLinked(c, triangles, dim, minX, minY, size);
  21057. return;
  21058. }
  21059. b = b.next;
  21060. }
  21061. a = a.next;
  21062. } while (a !== start);
  21063. }
  21064. // link every hole into the outer loop, producing a single-ring polygon without holes
  21065. function eliminateHoles(data, holeIndices, outerNode, dim) {
  21066. var queue = [],
  21067. i, len, start, end, list;
  21068. for (i = 0, len = holeIndices.length; i < len; i++) {
  21069. start = holeIndices[i] * dim;
  21070. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  21071. list = linkedList(data, start, end, dim, false);
  21072. if (list === list.next) list.steiner = true;
  21073. queue.push(getLeftmost(list));
  21074. }
  21075. queue.sort(compareX);
  21076. // process holes from left to right
  21077. for (i = 0; i < queue.length; i++) {
  21078. eliminateHole(queue[i], outerNode);
  21079. outerNode = filterPoints(outerNode, outerNode.next);
  21080. }
  21081. return outerNode;
  21082. }
  21083. function compareX(a, b) {
  21084. return a.x - b.x;
  21085. }
  21086. // find a bridge between vertices that connects hole with an outer ring and and link it
  21087. function eliminateHole(hole, outerNode) {
  21088. outerNode = findHoleBridge(hole, outerNode);
  21089. if (outerNode) {
  21090. var b = splitPolygon(outerNode, hole);
  21091. filterPoints(b, b.next);
  21092. }
  21093. }
  21094. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  21095. function findHoleBridge(hole, outerNode) {
  21096. var p = outerNode,
  21097. hx = hole.x,
  21098. hy = hole.y,
  21099. qx = -Infinity,
  21100. m;
  21101. // find a segment intersected by a ray from the hole's leftmost point to the left;
  21102. // segment's endpoint with lesser x will be potential connection point
  21103. do {
  21104. if (hy <= p.y && hy >= p.next.y) {
  21105. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  21106. if (x <= hx && x > qx) {
  21107. qx = x;
  21108. if (x === hx) {
  21109. if (hy === p.y) return p;
  21110. if (hy === p.next.y) return p.next;
  21111. }
  21112. m = p.x < p.next.x ? p : p.next;
  21113. }
  21114. }
  21115. p = p.next;
  21116. } while (p !== outerNode);
  21117. if (!m) return null;
  21118. if (hx === qx) return m.prev; // hole touches outer segment; pick lower endpoint
  21119. // look for points inside the triangle of hole point, segment intersection and endpoint;
  21120. // if there are no points found, we have a valid connection;
  21121. // otherwise choose the point of the minimum angle with the ray as connection point
  21122. var stop = m,
  21123. mx = m.x,
  21124. my = m.y,
  21125. tanMin = Infinity,
  21126. tan;
  21127. p = m.next;
  21128. while (p !== stop) {
  21129. if (hx >= p.x && p.x >= mx &&
  21130. pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
  21131. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  21132. if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && locallyInside(p, hole)) {
  21133. m = p;
  21134. tanMin = tan;
  21135. }
  21136. }
  21137. p = p.next;
  21138. }
  21139. return m;
  21140. }
  21141. // interlink polygon nodes in z-order
  21142. function indexCurve(start, minX, minY, size) {
  21143. var p = start;
  21144. do {
  21145. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, size);
  21146. p.prevZ = p.prev;
  21147. p.nextZ = p.next;
  21148. p = p.next;
  21149. } while (p !== start);
  21150. p.prevZ.nextZ = null;
  21151. p.prevZ = null;
  21152. sortLinked(p);
  21153. }
  21154. // Simon Tatham's linked list merge sort algorithm
  21155. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  21156. function sortLinked(list) {
  21157. var i, p, q, e, tail, numMerges, pSize, qSize,
  21158. inSize = 1;
  21159. do {
  21160. p = list;
  21161. list = null;
  21162. tail = null;
  21163. numMerges = 0;
  21164. while (p) {
  21165. numMerges++;
  21166. q = p;
  21167. pSize = 0;
  21168. for (i = 0; i < inSize; i++) {
  21169. pSize++;
  21170. q = q.nextZ;
  21171. if (!q) break;
  21172. }
  21173. qSize = inSize;
  21174. while (pSize > 0 || (qSize > 0 && q)) {
  21175. if (pSize === 0) {
  21176. e = q;
  21177. q = q.nextZ;
  21178. qSize--;
  21179. } else if (qSize === 0 || !q) {
  21180. e = p;
  21181. p = p.nextZ;
  21182. pSize--;
  21183. } else if (p.z <= q.z) {
  21184. e = p;
  21185. p = p.nextZ;
  21186. pSize--;
  21187. } else {
  21188. e = q;
  21189. q = q.nextZ;
  21190. qSize--;
  21191. }
  21192. if (tail) tail.nextZ = e;
  21193. else list = e;
  21194. e.prevZ = tail;
  21195. tail = e;
  21196. }
  21197. p = q;
  21198. }
  21199. tail.nextZ = null;
  21200. inSize *= 2;
  21201. } while (numMerges > 1);
  21202. return list;
  21203. }
  21204. // z-order of a point given coords and size of the data bounding box
  21205. function zOrder(x, y, minX, minY, size) {
  21206. // coords are transformed into non-negative 15-bit integer range
  21207. x = 32767 * (x - minX) / size;
  21208. y = 32767 * (y - minY) / size;
  21209. x = (x | (x << 8)) & 0x00FF00FF;
  21210. x = (x | (x << 4)) & 0x0F0F0F0F;
  21211. x = (x | (x << 2)) & 0x33333333;
  21212. x = (x | (x << 1)) & 0x55555555;
  21213. y = (y | (y << 8)) & 0x00FF00FF;
  21214. y = (y | (y << 4)) & 0x0F0F0F0F;
  21215. y = (y | (y << 2)) & 0x33333333;
  21216. y = (y | (y << 1)) & 0x55555555;
  21217. return x | (y << 1);
  21218. }
  21219. // find the leftmost node of a polygon ring
  21220. function getLeftmost(start) {
  21221. var p = start,
  21222. leftmost = start;
  21223. do {
  21224. if (p.x < leftmost.x) leftmost = p;
  21225. p = p.next;
  21226. } while (p !== start);
  21227. return leftmost;
  21228. }
  21229. // check if a point lies within a convex triangle
  21230. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  21231. return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 &&
  21232. (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 &&
  21233. (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
  21234. }
  21235. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  21236. function isValidDiagonal(a, b) {
  21237. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) &&
  21238. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b);
  21239. }
  21240. // signed area of a triangle
  21241. function area(p, q, r) {
  21242. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  21243. }
  21244. // check if two points are equal
  21245. function equals(p1, p2) {
  21246. return p1.x === p2.x && p1.y === p2.y;
  21247. }
  21248. // check if two segments intersect
  21249. function intersects(p1, q1, p2, q2) {
  21250. if ((equals(p1, q1) && equals(p2, q2)) ||
  21251. (equals(p1, q2) && equals(p2, q1))) return true;
  21252. return area(p1, q1, p2) > 0 !== area(p1, q1, q2) > 0 &&
  21253. area(p2, q2, p1) > 0 !== area(p2, q2, q1) > 0;
  21254. }
  21255. // check if a polygon diagonal intersects any polygon segments
  21256. function intersectsPolygon(a, b) {
  21257. var p = a;
  21258. do {
  21259. if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  21260. intersects(p, p.next, a, b)) return true;
  21261. p = p.next;
  21262. } while (p !== a);
  21263. return false;
  21264. }
  21265. // check if a polygon diagonal is locally inside the polygon
  21266. function locallyInside(a, b) {
  21267. return area(a.prev, a, a.next) < 0 ?
  21268. area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 :
  21269. area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
  21270. }
  21271. // check if the middle point of a polygon diagonal is inside the polygon
  21272. function middleInside(a, b) {
  21273. var p = a,
  21274. inside = false,
  21275. px = (a.x + b.x) / 2,
  21276. py = (a.y + b.y) / 2;
  21277. do {
  21278. if (((p.y > py) !== (p.next.y > py)) && (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))
  21279. inside = !inside;
  21280. p = p.next;
  21281. } while (p !== a);
  21282. return inside;
  21283. }
  21284. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  21285. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  21286. function splitPolygon(a, b) {
  21287. var a2 = new Node(a.i, a.x, a.y),
  21288. b2 = new Node(b.i, b.x, b.y),
  21289. an = a.next,
  21290. bp = b.prev;
  21291. a.next = b;
  21292. b.prev = a;
  21293. a2.next = an;
  21294. an.prev = a2;
  21295. b2.next = a2;
  21296. a2.prev = b2;
  21297. bp.next = b2;
  21298. b2.prev = bp;
  21299. return b2;
  21300. }
  21301. // create a node and optionally link it with previous one (in a circular doubly linked list)
  21302. function insertNode(i, x, y, last) {
  21303. var p = new Node(i, x, y);
  21304. if (!last) {
  21305. p.prev = p;
  21306. p.next = p;
  21307. } else {
  21308. p.next = last.next;
  21309. p.prev = last;
  21310. last.next.prev = p;
  21311. last.next = p;
  21312. }
  21313. return p;
  21314. }
  21315. function removeNode(p) {
  21316. p.next.prev = p.prev;
  21317. p.prev.next = p.next;
  21318. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  21319. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  21320. }
  21321. function Node(i, x, y) {
  21322. // vertice index in coordinates array
  21323. this.i = i;
  21324. // vertex coordinates
  21325. this.x = x;
  21326. this.y = y;
  21327. // previous and next vertice nodes in a polygon ring
  21328. this.prev = null;
  21329. this.next = null;
  21330. // z-order curve value
  21331. this.z = null;
  21332. // previous and next nodes in z-order
  21333. this.prevZ = null;
  21334. this.nextZ = null;
  21335. // indicates whether this is a steiner point
  21336. this.steiner = false;
  21337. }
  21338. // return a percentage difference between the polygon area and its triangulation area;
  21339. // used to verify correctness of triangulation
  21340. earcut.deviation = function (data, holeIndices, dim, triangles) {
  21341. var hasHoles = holeIndices && holeIndices.length;
  21342. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  21343. var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
  21344. if (hasHoles) {
  21345. for (var i = 0, len = holeIndices.length; i < len; i++) {
  21346. var start = holeIndices[i] * dim;
  21347. var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  21348. polygonArea -= Math.abs(signedArea(data, start, end, dim));
  21349. }
  21350. }
  21351. var trianglesArea = 0;
  21352. for (i = 0; i < triangles.length; i += 3) {
  21353. var a = triangles[i] * dim;
  21354. var b = triangles[i + 1] * dim;
  21355. var c = triangles[i + 2] * dim;
  21356. trianglesArea += Math.abs(
  21357. (data[a] - data[c]) * (data[b + 1] - data[a + 1]) -
  21358. (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
  21359. }
  21360. return polygonArea === 0 && trianglesArea === 0 ? 0 :
  21361. Math.abs((trianglesArea - polygonArea) / polygonArea);
  21362. };
  21363. function signedArea(data, start, end, dim) {
  21364. var sum = 0;
  21365. for (var i = start, j = end - dim; i < end; i += dim) {
  21366. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  21367. j = i;
  21368. }
  21369. return sum;
  21370. }
  21371. // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts
  21372. earcut.flatten = function (data) {
  21373. var dim = data[0][0].length,
  21374. result = {vertices: [], holes: [], dimensions: dim},
  21375. holeIndex = 0;
  21376. for (var i = 0; i < data.length; i++) {
  21377. for (var j = 0; j < data[i].length; j++) {
  21378. for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]);
  21379. }
  21380. if (i > 0) {
  21381. holeIndex += data[i - 1].length;
  21382. result.holes.push(holeIndex);
  21383. }
  21384. }
  21385. return result;
  21386. };
  21387. return earcut;
  21388. });
  21389. /*global define*/
  21390. define('Core/WindingOrder',[
  21391. './freezeObject',
  21392. './WebGLConstants'
  21393. ], function(
  21394. freezeObject,
  21395. WebGLConstants) {
  21396. 'use strict';
  21397. /**
  21398. * Winding order defines the order of vertices for a triangle to be considered front-facing.
  21399. *
  21400. * @exports WindingOrder
  21401. */
  21402. var WindingOrder = {
  21403. /**
  21404. * Vertices are in clockwise order.
  21405. *
  21406. * @type {Number}
  21407. * @constant
  21408. */
  21409. CLOCKWISE : WebGLConstants.CW,
  21410. /**
  21411. * Vertices are in counter-clockwise order.
  21412. *
  21413. * @type {Number}
  21414. * @constant
  21415. */
  21416. COUNTER_CLOCKWISE : WebGLConstants.CCW,
  21417. /**
  21418. * @private
  21419. */
  21420. validate : function(windingOrder) {
  21421. return windingOrder === WindingOrder.CLOCKWISE ||
  21422. windingOrder === WindingOrder.COUNTER_CLOCKWISE;
  21423. }
  21424. };
  21425. return freezeObject(WindingOrder);
  21426. });
  21427. /*global define*/
  21428. define('Core/PolygonPipeline',[
  21429. '../ThirdParty/earcut-2.1.1',
  21430. './Cartesian2',
  21431. './Cartesian3',
  21432. './ComponentDatatype',
  21433. './defaultValue',
  21434. './defined',
  21435. './DeveloperError',
  21436. './Ellipsoid',
  21437. './Geometry',
  21438. './GeometryAttribute',
  21439. './Math',
  21440. './PrimitiveType',
  21441. './WindingOrder'
  21442. ], function(
  21443. earcut,
  21444. Cartesian2,
  21445. Cartesian3,
  21446. ComponentDatatype,
  21447. defaultValue,
  21448. defined,
  21449. DeveloperError,
  21450. Ellipsoid,
  21451. Geometry,
  21452. GeometryAttribute,
  21453. CesiumMath,
  21454. PrimitiveType,
  21455. WindingOrder) {
  21456. 'use strict';
  21457. var scaleToGeodeticHeightN = new Cartesian3();
  21458. var scaleToGeodeticHeightP = new Cartesian3();
  21459. /**
  21460. * @private
  21461. */
  21462. var PolygonPipeline = {};
  21463. /**
  21464. * @exception {DeveloperError} At least three positions are required.
  21465. */
  21466. PolygonPipeline.computeArea2D = function(positions) {
  21467. if (!defined(positions)) {
  21468. throw new DeveloperError('positions is required.');
  21469. }
  21470. if (positions.length < 3) {
  21471. throw new DeveloperError('At least three positions are required.');
  21472. }
  21473. var length = positions.length;
  21474. var area = 0.0;
  21475. for ( var i0 = length - 1, i1 = 0; i1 < length; i0 = i1++) {
  21476. var v0 = positions[i0];
  21477. var v1 = positions[i1];
  21478. area += (v0.x * v1.y) - (v1.x * v0.y);
  21479. }
  21480. return area * 0.5;
  21481. };
  21482. /**
  21483. * @returns {WindingOrder} The winding order.
  21484. *
  21485. * @exception {DeveloperError} At least three positions are required.
  21486. */
  21487. PolygonPipeline.computeWindingOrder2D = function(positions) {
  21488. var area = PolygonPipeline.computeArea2D(positions);
  21489. return (area > 0.0) ? WindingOrder.COUNTER_CLOCKWISE : WindingOrder.CLOCKWISE;
  21490. };
  21491. /**
  21492. * Triangulate a polygon.
  21493. *
  21494. * @param {Cartesian2[]} positions Cartesian2 array containing the vertices of the polygon
  21495. * @param {Number[]} [holes] An array of the staring indices of the holes.
  21496. * @returns {Number[]} Index array representing triangles that fill the polygon
  21497. */
  21498. PolygonPipeline.triangulate = function(positions, holes) {
  21499. if (!defined(positions)) {
  21500. throw new DeveloperError('positions is required.');
  21501. }
  21502. var flattenedPositions = Cartesian2.packArray(positions);
  21503. return earcut(flattenedPositions, holes, 2);
  21504. };
  21505. var subdivisionV0Scratch = new Cartesian3();
  21506. var subdivisionV1Scratch = new Cartesian3();
  21507. var subdivisionV2Scratch = new Cartesian3();
  21508. var subdivisionS0Scratch = new Cartesian3();
  21509. var subdivisionS1Scratch = new Cartesian3();
  21510. var subdivisionS2Scratch = new Cartesian3();
  21511. var subdivisionMidScratch = new Cartesian3();
  21512. /**
  21513. * Subdivides positions and raises points to the surface of the ellipsoid.
  21514. *
  21515. * @param {Ellipsoid} ellipsoid The ellipsoid the polygon in on.
  21516. * @param {Cartesian3[]} positions An array of {@link Cartesian3} positions of the polygon.
  21517. * @param {Number[]} indices An array of indices that determines the triangles in the polygon.
  21518. * @param {Number} [granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.
  21519. *
  21520. * @exception {DeveloperError} At least three indices are required.
  21521. * @exception {DeveloperError} The number of indices must be divisable by three.
  21522. * @exception {DeveloperError} Granularity must be greater than zero.
  21523. */
  21524. PolygonPipeline.computeSubdivision = function(ellipsoid, positions, indices, granularity) {
  21525. granularity = defaultValue(granularity, CesiumMath.RADIANS_PER_DEGREE);
  21526. if (!defined(ellipsoid)) {
  21527. throw new DeveloperError('ellipsoid is required.');
  21528. }
  21529. if (!defined(positions)) {
  21530. throw new DeveloperError('positions is required.');
  21531. }
  21532. if (!defined(indices)) {
  21533. throw new DeveloperError('indices is required.');
  21534. }
  21535. if (indices.length < 3) {
  21536. throw new DeveloperError('At least three indices are required.');
  21537. }
  21538. if (indices.length % 3 !== 0) {
  21539. throw new DeveloperError('The number of indices must be divisable by three.');
  21540. }
  21541. if (granularity <= 0.0) {
  21542. throw new DeveloperError('granularity must be greater than zero.');
  21543. }
  21544. // triangles that need (or might need) to be subdivided.
  21545. var triangles = indices.slice(0);
  21546. // New positions due to edge splits are appended to the positions list.
  21547. var i;
  21548. var length = positions.length;
  21549. var subdividedPositions = new Array(length * 3);
  21550. var q = 0;
  21551. for (i = 0; i < length; i++) {
  21552. var item = positions[i];
  21553. subdividedPositions[q++] = item.x;
  21554. subdividedPositions[q++] = item.y;
  21555. subdividedPositions[q++] = item.z;
  21556. }
  21557. var subdividedIndices = [];
  21558. // Used to make sure shared edges are not split more than once.
  21559. var edges = {};
  21560. var radius = ellipsoid.maximumRadius;
  21561. var minDistance = CesiumMath.chordLength(granularity, radius);
  21562. var minDistanceSqrd = minDistance * minDistance;
  21563. while (triangles.length > 0) {
  21564. var i2 = triangles.pop();
  21565. var i1 = triangles.pop();
  21566. var i0 = triangles.pop();
  21567. var v0 = Cartesian3.fromArray(subdividedPositions, i0 * 3, subdivisionV0Scratch);
  21568. var v1 = Cartesian3.fromArray(subdividedPositions, i1 * 3, subdivisionV1Scratch);
  21569. var v2 = Cartesian3.fromArray(subdividedPositions, i2 * 3, subdivisionV2Scratch);
  21570. var s0 = Cartesian3.multiplyByScalar(Cartesian3.normalize(v0, subdivisionS0Scratch), radius, subdivisionS0Scratch);
  21571. var s1 = Cartesian3.multiplyByScalar(Cartesian3.normalize(v1, subdivisionS1Scratch), radius, subdivisionS1Scratch);
  21572. var s2 = Cartesian3.multiplyByScalar(Cartesian3.normalize(v2, subdivisionS2Scratch), radius, subdivisionS2Scratch);
  21573. var g0 = Cartesian3.magnitudeSquared(Cartesian3.subtract(s0, s1, subdivisionMidScratch));
  21574. var g1 = Cartesian3.magnitudeSquared(Cartesian3.subtract(s1, s2, subdivisionMidScratch));
  21575. var g2 = Cartesian3.magnitudeSquared(Cartesian3.subtract(s2, s0, subdivisionMidScratch));
  21576. var max = Math.max(g0, g1, g2);
  21577. var edge;
  21578. var mid;
  21579. // if the max length squared of a triangle edge is greater than the chord length of squared
  21580. // of the granularity, subdivide the triangle
  21581. if (max > minDistanceSqrd) {
  21582. if (g0 === max) {
  21583. edge = Math.min(i0, i1) + ' ' + Math.max(i0, i1);
  21584. i = edges[edge];
  21585. if (!defined(i)) {
  21586. mid = Cartesian3.add(v0, v1, subdivisionMidScratch);
  21587. Cartesian3.multiplyByScalar(mid, 0.5, mid);
  21588. subdividedPositions.push(mid.x, mid.y, mid.z);
  21589. i = subdividedPositions.length / 3 - 1;
  21590. edges[edge] = i;
  21591. }
  21592. triangles.push(i0, i, i2);
  21593. triangles.push(i, i1, i2);
  21594. } else if (g1 === max) {
  21595. edge = Math.min(i1, i2) + ' ' + Math.max(i1, i2);
  21596. i = edges[edge];
  21597. if (!defined(i)) {
  21598. mid = Cartesian3.add(v1, v2, subdivisionMidScratch);
  21599. Cartesian3.multiplyByScalar(mid, 0.5, mid);
  21600. subdividedPositions.push(mid.x, mid.y, mid.z);
  21601. i = subdividedPositions.length / 3 - 1;
  21602. edges[edge] = i;
  21603. }
  21604. triangles.push(i1, i, i0);
  21605. triangles.push(i, i2, i0);
  21606. } else if (g2 === max) {
  21607. edge = Math.min(i2, i0) + ' ' + Math.max(i2, i0);
  21608. i = edges[edge];
  21609. if (!defined(i)) {
  21610. mid = Cartesian3.add(v2, v0, subdivisionMidScratch);
  21611. Cartesian3.multiplyByScalar(mid, 0.5, mid);
  21612. subdividedPositions.push(mid.x, mid.y, mid.z);
  21613. i = subdividedPositions.length / 3 - 1;
  21614. edges[edge] = i;
  21615. }
  21616. triangles.push(i2, i, i1);
  21617. triangles.push(i, i0, i1);
  21618. }
  21619. } else {
  21620. subdividedIndices.push(i0);
  21621. subdividedIndices.push(i1);
  21622. subdividedIndices.push(i2);
  21623. }
  21624. }
  21625. return new Geometry({
  21626. attributes : {
  21627. position : new GeometryAttribute({
  21628. componentDatatype : ComponentDatatype.DOUBLE,
  21629. componentsPerAttribute : 3,
  21630. values : subdividedPositions
  21631. })
  21632. },
  21633. indices : subdividedIndices,
  21634. primitiveType : PrimitiveType.TRIANGLES
  21635. });
  21636. };
  21637. /**
  21638. * Scales each position of a geometry's position attribute to a height, in place.
  21639. *
  21640. * @param {Number[]} positions The array of numbers representing the positions to be scaled
  21641. * @param {Number} [height=0.0] The desired height to add to the positions
  21642. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie.
  21643. * @param {Boolean} [scaleToSurface=true] <code>true</code> if the positions need to be scaled to the surface before the height is added.
  21644. * @returns {Number[]} The input array of positions, scaled to height
  21645. */
  21646. PolygonPipeline.scaleToGeodeticHeight = function(positions, height, ellipsoid, scaleToSurface) {
  21647. ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84);
  21648. var n = scaleToGeodeticHeightN;
  21649. var p = scaleToGeodeticHeightP;
  21650. height = defaultValue(height, 0.0);
  21651. scaleToSurface = defaultValue(scaleToSurface, true);
  21652. if (defined(positions)) {
  21653. var length = positions.length;
  21654. for ( var i = 0; i < length; i += 3) {
  21655. Cartesian3.fromArray(positions, i, p);
  21656. if (scaleToSurface) {
  21657. p = ellipsoid.scaleToGeodeticSurface(p, p);
  21658. }
  21659. if (height !== 0) {
  21660. n = ellipsoid.geodeticSurfaceNormal(p, n);
  21661. Cartesian3.multiplyByScalar(n, height, n);
  21662. Cartesian3.add(p, n, p);
  21663. }
  21664. positions[i] = p.x;
  21665. positions[i + 1] = p.y;
  21666. positions[i + 2] = p.z;
  21667. }
  21668. }
  21669. return positions;
  21670. };
  21671. return PolygonPipeline;
  21672. });
  21673. /*global define*/
  21674. define('Core/EllipsoidGeodesic',[
  21675. './Cartesian3',
  21676. './Cartographic',
  21677. './defaultValue',
  21678. './defined',
  21679. './defineProperties',
  21680. './DeveloperError',
  21681. './Ellipsoid',
  21682. './Math'
  21683. ], function(
  21684. Cartesian3,
  21685. Cartographic,
  21686. defaultValue,
  21687. defined,
  21688. defineProperties,
  21689. DeveloperError,
  21690. Ellipsoid,
  21691. CesiumMath) {
  21692. 'use strict';
  21693. function setConstants(ellipsoidGeodesic) {
  21694. var uSquared = ellipsoidGeodesic._uSquared;
  21695. var a = ellipsoidGeodesic._ellipsoid.maximumRadius;
  21696. var b = ellipsoidGeodesic._ellipsoid.minimumRadius;
  21697. var f = (a - b) / a;
  21698. var cosineHeading = Math.cos(ellipsoidGeodesic._startHeading);
  21699. var sineHeading = Math.sin(ellipsoidGeodesic._startHeading);
  21700. var tanU = (1 - f) * Math.tan(ellipsoidGeodesic._start.latitude);
  21701. var cosineU = 1.0 / Math.sqrt(1.0 + tanU * tanU);
  21702. var sineU = cosineU * tanU;
  21703. var sigma = Math.atan2(tanU, cosineHeading);
  21704. var sineAlpha = cosineU * sineHeading;
  21705. var sineSquaredAlpha = sineAlpha * sineAlpha;
  21706. var cosineSquaredAlpha = 1.0 - sineSquaredAlpha;
  21707. var cosineAlpha = Math.sqrt(cosineSquaredAlpha);
  21708. var u2Over4 = uSquared / 4.0;
  21709. var u4Over16 = u2Over4 * u2Over4;
  21710. var u6Over64 = u4Over16 * u2Over4;
  21711. var u8Over256 = u4Over16 * u4Over16;
  21712. var a0 = (1.0 + u2Over4 - 3.0 * u4Over16 / 4.0 + 5.0 * u6Over64 / 4.0 - 175.0 * u8Over256 / 64.0);
  21713. var a1 = (1.0 - u2Over4 + 15.0 * u4Over16 / 8.0 - 35.0 * u6Over64 / 8.0);
  21714. var a2 = (1.0 - 3.0 * u2Over4 + 35.0 * u4Over16 / 4.0);
  21715. var a3 = (1.0 - 5.0 * u2Over4);
  21716. var distanceRatio = a0 * sigma - a1 * Math.sin(2.0 * sigma) * u2Over4 / 2.0 - a2 * Math.sin(4.0 * sigma) * u4Over16 / 16.0 -
  21717. a3 * Math.sin(6.0 * sigma) * u6Over64 / 48.0 - Math.sin(8.0 * sigma) * 5.0 * u8Over256 / 512;
  21718. var constants = ellipsoidGeodesic._constants;
  21719. constants.a = a;
  21720. constants.b = b;
  21721. constants.f = f;
  21722. constants.cosineHeading = cosineHeading;
  21723. constants.sineHeading = sineHeading;
  21724. constants.tanU = tanU;
  21725. constants.cosineU = cosineU;
  21726. constants.sineU = sineU;
  21727. constants.sigma = sigma;
  21728. constants.sineAlpha = sineAlpha;
  21729. constants.sineSquaredAlpha = sineSquaredAlpha;
  21730. constants.cosineSquaredAlpha = cosineSquaredAlpha;
  21731. constants.cosineAlpha = cosineAlpha;
  21732. constants.u2Over4 = u2Over4;
  21733. constants.u4Over16 = u4Over16;
  21734. constants.u6Over64 = u6Over64;
  21735. constants.u8Over256 = u8Over256;
  21736. constants.a0 = a0;
  21737. constants.a1 = a1;
  21738. constants.a2 = a2;
  21739. constants.a3 = a3;
  21740. constants.distanceRatio = distanceRatio;
  21741. }
  21742. function computeC(f, cosineSquaredAlpha) {
  21743. return f * cosineSquaredAlpha * (4.0 + f * (4.0 - 3.0 * cosineSquaredAlpha)) / 16.0;
  21744. }
  21745. function computeDeltaLambda(f, sineAlpha, cosineSquaredAlpha, sigma, sineSigma, cosineSigma, cosineTwiceSigmaMidpoint) {
  21746. var C = computeC(f, cosineSquaredAlpha);
  21747. return (1.0 - C) * f * sineAlpha * (sigma + C * sineSigma * (cosineTwiceSigmaMidpoint +
  21748. C * cosineSigma * (2.0 * cosineTwiceSigmaMidpoint * cosineTwiceSigmaMidpoint - 1.0)));
  21749. }
  21750. function vincentyInverseFormula(ellipsoidGeodesic, major, minor, firstLongitude, firstLatitude, secondLongitude, secondLatitude) {
  21751. var eff = (major - minor) / major;
  21752. var l = secondLongitude - firstLongitude;
  21753. var u1 = Math.atan((1 - eff) * Math.tan(firstLatitude));
  21754. var u2 = Math.atan((1 - eff) * Math.tan(secondLatitude));
  21755. var cosineU1 = Math.cos(u1);
  21756. var sineU1 = Math.sin(u1);
  21757. var cosineU2 = Math.cos(u2);
  21758. var sineU2 = Math.sin(u2);
  21759. var cc = cosineU1 * cosineU2;
  21760. var cs = cosineU1 * sineU2;
  21761. var ss = sineU1 * sineU2;
  21762. var sc = sineU1 * cosineU2;
  21763. var lambda = l;
  21764. var lambdaDot = CesiumMath.TWO_PI;
  21765. var cosineLambda = Math.cos(lambda);
  21766. var sineLambda = Math.sin(lambda);
  21767. var sigma;
  21768. var cosineSigma;
  21769. var sineSigma;
  21770. var cosineSquaredAlpha;
  21771. var cosineTwiceSigmaMidpoint;
  21772. do {
  21773. cosineLambda = Math.cos(lambda);
  21774. sineLambda = Math.sin(lambda);
  21775. var temp = cs - sc * cosineLambda;
  21776. sineSigma = Math.sqrt(cosineU2 * cosineU2 * sineLambda * sineLambda + temp * temp);
  21777. cosineSigma = ss + cc * cosineLambda;
  21778. sigma = Math.atan2(sineSigma, cosineSigma);
  21779. var sineAlpha;
  21780. if (sineSigma === 0.0) {
  21781. sineAlpha = 0.0;
  21782. cosineSquaredAlpha = 1.0;
  21783. } else {
  21784. sineAlpha = cc * sineLambda / sineSigma;
  21785. cosineSquaredAlpha = 1.0 - sineAlpha * sineAlpha;
  21786. }
  21787. lambdaDot = lambda;
  21788. cosineTwiceSigmaMidpoint = cosineSigma - 2.0 * ss / cosineSquaredAlpha;
  21789. if (isNaN(cosineTwiceSigmaMidpoint)) {
  21790. cosineTwiceSigmaMidpoint = 0.0;
  21791. }
  21792. lambda = l + computeDeltaLambda(eff, sineAlpha, cosineSquaredAlpha,
  21793. sigma, sineSigma, cosineSigma, cosineTwiceSigmaMidpoint);
  21794. } while (Math.abs(lambda - lambdaDot) > CesiumMath.EPSILON12);
  21795. var uSquared = cosineSquaredAlpha * (major * major - minor * minor) / (minor * minor);
  21796. var A = 1.0 + uSquared * (4096.0 + uSquared * (uSquared * (320.0 - 175.0 * uSquared) - 768.0)) / 16384.0;
  21797. var B = uSquared * (256.0 + uSquared * (uSquared * (74.0 - 47.0 * uSquared) - 128.0)) / 1024.0;
  21798. var cosineSquaredTwiceSigmaMidpoint = cosineTwiceSigmaMidpoint * cosineTwiceSigmaMidpoint;
  21799. var deltaSigma = B * sineSigma * (cosineTwiceSigmaMidpoint + B * (cosineSigma *
  21800. (2.0 * cosineSquaredTwiceSigmaMidpoint - 1.0) - B * cosineTwiceSigmaMidpoint *
  21801. (4.0 * sineSigma * sineSigma - 3.0) * (4.0 * cosineSquaredTwiceSigmaMidpoint - 3.0) / 6.0) / 4.0);
  21802. var distance = minor * A * (sigma - deltaSigma);
  21803. var startHeading = Math.atan2(cosineU2 * sineLambda, cs - sc * cosineLambda);
  21804. var endHeading = Math.atan2(cosineU1 * sineLambda, cs * cosineLambda - sc);
  21805. ellipsoidGeodesic._distance = distance;
  21806. ellipsoidGeodesic._startHeading = startHeading;
  21807. ellipsoidGeodesic._endHeading = endHeading;
  21808. ellipsoidGeodesic._uSquared = uSquared;
  21809. }
  21810. function computeProperties(ellipsoidGeodesic, start, end, ellipsoid) {
  21811. var firstCartesian = Cartesian3.normalize(ellipsoid.cartographicToCartesian(start, scratchCart2), scratchCart1);
  21812. var lastCartesian = Cartesian3.normalize(ellipsoid.cartographicToCartesian(end, scratchCart2), scratchCart2);
  21813. if (Math.abs(Math.abs(Cartesian3.angleBetween(firstCartesian, lastCartesian)) - Math.PI) < 0.0125) {
  21814. throw new DeveloperError('geodesic position is not unique');
  21815. }
  21816. vincentyInverseFormula(ellipsoidGeodesic, ellipsoid.maximumRadius, ellipsoid.minimumRadius,
  21817. start.longitude, start.latitude, end.longitude, end.latitude);
  21818. ellipsoidGeodesic._start = Cartographic.clone(start, ellipsoidGeodesic._start);
  21819. ellipsoidGeodesic._end = Cartographic.clone(end, ellipsoidGeodesic._end);
  21820. ellipsoidGeodesic._start.height = 0;
  21821. ellipsoidGeodesic._end.height = 0;
  21822. setConstants(ellipsoidGeodesic);
  21823. }
  21824. var scratchCart1 = new Cartesian3();
  21825. var scratchCart2 = new Cartesian3();
  21826. /**
  21827. * Initializes a geodesic on the ellipsoid connecting the two provided planetodetic points.
  21828. *
  21829. * @alias EllipsoidGeodesic
  21830. * @constructor
  21831. *
  21832. * @param {Cartographic} [start] The initial planetodetic point on the path.
  21833. * @param {Cartographic} [end] The final planetodetic point on the path.
  21834. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the geodesic lies.
  21835. */
  21836. function EllipsoidGeodesic(start, end, ellipsoid) {
  21837. var e = defaultValue(ellipsoid, Ellipsoid.WGS84);
  21838. this._ellipsoid = e;
  21839. this._start = new Cartographic();
  21840. this._end = new Cartographic();
  21841. this._constants = {};
  21842. this._startHeading = undefined;
  21843. this._endHeading = undefined;
  21844. this._distance = undefined;
  21845. this._uSquared = undefined;
  21846. if (defined(start) && defined(end)) {
  21847. computeProperties(this, start, end, e);
  21848. }
  21849. }
  21850. defineProperties(EllipsoidGeodesic.prototype, {
  21851. /**
  21852. * Gets the ellipsoid.
  21853. * @memberof EllipsoidGeodesic.prototype
  21854. * @type {Ellipsoid}
  21855. * @readonly
  21856. */
  21857. ellipsoid : {
  21858. get : function() {
  21859. return this._ellipsoid;
  21860. }
  21861. },
  21862. /**
  21863. * Gets the surface distance between the start and end point
  21864. * @memberof EllipsoidGeodesic.prototype
  21865. * @type {Number}
  21866. * @readonly
  21867. */
  21868. surfaceDistance : {
  21869. get : function() {
  21870. if (!defined(this._distance)) {
  21871. throw new DeveloperError('set end positions before getting surfaceDistance');
  21872. }
  21873. return this._distance;
  21874. }
  21875. },
  21876. /**
  21877. * Gets the initial planetodetic point on the path.
  21878. * @memberof EllipsoidGeodesic.prototype
  21879. * @type {Cartographic}
  21880. * @readonly
  21881. */
  21882. start : {
  21883. get : function() {
  21884. return this._start;
  21885. }
  21886. },
  21887. /**
  21888. * Gets the final planetodetic point on the path.
  21889. * @memberof EllipsoidGeodesic.prototype
  21890. * @type {Cartographic}
  21891. * @readonly
  21892. */
  21893. end : {
  21894. get : function() {
  21895. return this._end;
  21896. }
  21897. },
  21898. /**
  21899. * Gets the heading at the initial point.
  21900. * @memberof EllipsoidGeodesic.prototype
  21901. * @type {Number}
  21902. * @readonly
  21903. */
  21904. startHeading : {
  21905. get : function() {
  21906. if (!defined(this._distance)) {
  21907. throw new DeveloperError('set end positions before getting startHeading');
  21908. }
  21909. return this._startHeading;
  21910. }
  21911. },
  21912. /**
  21913. * Gets the heading at the final point.
  21914. * @memberof EllipsoidGeodesic.prototype
  21915. * @type {Number}
  21916. * @readonly
  21917. */
  21918. endHeading : {
  21919. get : function() {
  21920. if (!defined(this._distance)) {
  21921. throw new DeveloperError('set end positions before getting endHeading');
  21922. }
  21923. return this._endHeading;
  21924. }
  21925. }
  21926. });
  21927. /**
  21928. * Sets the start and end points of the geodesic
  21929. *
  21930. * @param {Cartographic} start The initial planetodetic point on the path.
  21931. * @param {Cartographic} end The final planetodetic point on the path.
  21932. */
  21933. EllipsoidGeodesic.prototype.setEndPoints = function(start, end) {
  21934. if (!defined(start)) {
  21935. throw new DeveloperError('start cartographic position is required');
  21936. }
  21937. if (!defined(end)) {
  21938. throw new DeveloperError('end cartgraphic position is required');
  21939. }
  21940. computeProperties(this, start, end, this._ellipsoid);
  21941. };
  21942. /**
  21943. * Provides the location of a point at the indicated portion along the geodesic.
  21944. *
  21945. * @param {Number} fraction The portion of the distance between the initial and final points.
  21946. * @returns {Cartographic} The location of the point along the geodesic.
  21947. */
  21948. EllipsoidGeodesic.prototype.interpolateUsingFraction = function(fraction, result) {
  21949. return this.interpolateUsingSurfaceDistance(this._distance * fraction, result);
  21950. };
  21951. /**
  21952. * Provides the location of a point at the indicated distance along the geodesic.
  21953. *
  21954. * @param {Number} distance The distance from the inital point to the point of interest along the geodesic
  21955. * @returns {Cartographic} The location of the point along the geodesic.
  21956. *
  21957. * @exception {DeveloperError} start and end must be set before calling function interpolateUsingSurfaceDistance
  21958. */
  21959. EllipsoidGeodesic.prototype.interpolateUsingSurfaceDistance = function(distance, result) {
  21960. if (!defined(this._distance)) {
  21961. throw new DeveloperError('start and end must be set before calling function interpolateUsingSurfaceDistance');
  21962. }
  21963. var constants = this._constants;
  21964. var s = constants.distanceRatio + distance / constants.b;
  21965. var cosine2S = Math.cos(2.0 * s);
  21966. var cosine4S = Math.cos(4.0 * s);
  21967. var cosine6S = Math.cos(6.0 * s);
  21968. var sine2S = Math.sin(2.0 * s);
  21969. var sine4S = Math.sin(4.0 * s);
  21970. var sine6S = Math.sin(6.0 * s);
  21971. var sine8S = Math.sin(8.0 * s);
  21972. var s2 = s * s;
  21973. var s3 = s * s2;
  21974. var u8Over256 = constants.u8Over256;
  21975. var u2Over4 = constants.u2Over4;
  21976. var u6Over64 = constants.u6Over64;
  21977. var u4Over16 = constants.u4Over16;
  21978. var sigma = 2.0 * s3 * u8Over256 * cosine2S / 3.0 +
  21979. s * (1.0 - u2Over4 + 7.0 * u4Over16 / 4.0 - 15.0 * u6Over64 / 4.0 + 579.0 * u8Over256 / 64.0 -
  21980. (u4Over16 - 15.0 * u6Over64 / 4.0 + 187.0 * u8Over256 / 16.0) * cosine2S -
  21981. (5.0 * u6Over64 / 4.0 - 115.0 * u8Over256 / 16.0) * cosine4S -
  21982. 29.0 * u8Over256 * cosine6S / 16.0) +
  21983. (u2Over4 / 2.0 - u4Over16 + 71.0 * u6Over64 / 32.0 - 85.0 * u8Over256 / 16.0) * sine2S +
  21984. (5.0 * u4Over16 / 16.0 - 5.0 * u6Over64 / 4.0 + 383.0 * u8Over256 / 96.0) * sine4S -
  21985. s2 * ((u6Over64 - 11.0 * u8Over256 / 2.0) * sine2S + 5.0 * u8Over256 * sine4S / 2.0) +
  21986. (29.0 * u6Over64 / 96.0 - 29.0 * u8Over256 / 16.0) * sine6S +
  21987. 539.0 * u8Over256 * sine8S / 1536.0;
  21988. var theta = Math.asin(Math.sin(sigma) * constants.cosineAlpha);
  21989. var latitude = Math.atan(constants.a / constants.b * Math.tan(theta));
  21990. // Redefine in terms of relative argument of latitude.
  21991. sigma = sigma - constants.sigma;
  21992. var cosineTwiceSigmaMidpoint = Math.cos(2.0 * constants.sigma + sigma);
  21993. var sineSigma = Math.sin(sigma);
  21994. var cosineSigma = Math.cos(sigma);
  21995. var cc = constants.cosineU * cosineSigma;
  21996. var ss = constants.sineU * sineSigma;
  21997. var lambda = Math.atan2(sineSigma * constants.sineHeading, cc - ss * constants.cosineHeading);
  21998. var l = lambda - computeDeltaLambda(constants.f, constants.sineAlpha, constants.cosineSquaredAlpha,
  21999. sigma, sineSigma, cosineSigma, cosineTwiceSigmaMidpoint);
  22000. if (defined(result)) {
  22001. result.longitude = this._start.longitude + l;
  22002. result.latitude = latitude;
  22003. result.height = 0.0;
  22004. return result;
  22005. }
  22006. return new Cartographic(this._start.longitude + l, latitude, 0.0);
  22007. };
  22008. return EllipsoidGeodesic;
  22009. });
  22010. /*global define*/
  22011. define('Core/PolylinePipeline',[
  22012. './Cartesian3',
  22013. './Cartographic',
  22014. './defaultValue',
  22015. './defined',
  22016. './DeveloperError',
  22017. './Ellipsoid',
  22018. './EllipsoidGeodesic',
  22019. './IntersectionTests',
  22020. './isArray',
  22021. './Math',
  22022. './Matrix4',
  22023. './Plane'
  22024. ], function(
  22025. Cartesian3,
  22026. Cartographic,
  22027. defaultValue,
  22028. defined,
  22029. DeveloperError,
  22030. Ellipsoid,
  22031. EllipsoidGeodesic,
  22032. IntersectionTests,
  22033. isArray,
  22034. CesiumMath,
  22035. Matrix4,
  22036. Plane) {
  22037. 'use strict';
  22038. /**
  22039. * @private
  22040. */
  22041. var PolylinePipeline = {};
  22042. PolylinePipeline.numberOfPoints = function(p0, p1, minDistance) {
  22043. var distance = Cartesian3.distance(p0, p1);
  22044. return Math.ceil(distance / minDistance);
  22045. };
  22046. var cartoScratch = new Cartographic();
  22047. PolylinePipeline.extractHeights = function(positions, ellipsoid) {
  22048. var length = positions.length;
  22049. var heights = new Array(length);
  22050. for (var i = 0; i < length; i++) {
  22051. var p = positions[i];
  22052. heights[i] = ellipsoid.cartesianToCartographic(p, cartoScratch).height;
  22053. }
  22054. return heights;
  22055. };
  22056. var wrapLongitudeInversMatrix = new Matrix4();
  22057. var wrapLongitudeOrigin = new Cartesian3();
  22058. var wrapLongitudeXZNormal = new Cartesian3();
  22059. var wrapLongitudeXZPlane = new Plane(Cartesian3.ZERO, 0.0);
  22060. var wrapLongitudeYZNormal = new Cartesian3();
  22061. var wrapLongitudeYZPlane = new Plane(Cartesian3.ZERO, 0.0);
  22062. var wrapLongitudeIntersection = new Cartesian3();
  22063. var wrapLongitudeOffset = new Cartesian3();
  22064. var subdivideHeightsScratchArray = [];
  22065. function subdivideHeights(numPoints, h0, h1) {
  22066. var heights = subdivideHeightsScratchArray;
  22067. heights.length = numPoints;
  22068. var i;
  22069. if (h0 === h1) {
  22070. for (i = 0; i < numPoints; i++) {
  22071. heights[i] = h0;
  22072. }
  22073. return heights;
  22074. }
  22075. var dHeight = h1 - h0;
  22076. var heightPerVertex = dHeight / numPoints;
  22077. for (i = 0; i < numPoints; i++) {
  22078. var h = h0 + i*heightPerVertex;
  22079. heights[i] = h;
  22080. }
  22081. return heights;
  22082. }
  22083. var carto1 = new Cartographic();
  22084. var carto2 = new Cartographic();
  22085. var cartesian = new Cartesian3();
  22086. var scaleFirst = new Cartesian3();
  22087. var scaleLast = new Cartesian3();
  22088. var ellipsoidGeodesic = new EllipsoidGeodesic();
  22089. //Returns subdivided line scaled to ellipsoid surface starting at p1 and ending at p2.
  22090. //Result includes p1, but not include p2. This function is called for a sequence of line segments,
  22091. //and this prevents duplication of end point.
  22092. function generateCartesianArc(p0, p1, minDistance, ellipsoid, h0, h1, array, offset) {
  22093. var first = ellipsoid.scaleToGeodeticSurface(p0, scaleFirst);
  22094. var last = ellipsoid.scaleToGeodeticSurface(p1, scaleLast);
  22095. var numPoints = PolylinePipeline.numberOfPoints(p0, p1, minDistance);
  22096. var start = ellipsoid.cartesianToCartographic(first, carto1);
  22097. var end = ellipsoid.cartesianToCartographic(last, carto2);
  22098. var heights = subdivideHeights(numPoints, h0, h1);
  22099. ellipsoidGeodesic.setEndPoints(start, end);
  22100. var surfaceDistanceBetweenPoints = ellipsoidGeodesic.surfaceDistance / numPoints;
  22101. var index = offset;
  22102. start.height = h0;
  22103. var cart = ellipsoid.cartographicToCartesian(start, cartesian);
  22104. Cartesian3.pack(cart, array, index);
  22105. index += 3;
  22106. for (var i = 1; i < numPoints; i++) {
  22107. var carto = ellipsoidGeodesic.interpolateUsingSurfaceDistance(i * surfaceDistanceBetweenPoints, carto2);
  22108. carto.height = heights[i];
  22109. cart = ellipsoid.cartographicToCartesian(carto, cartesian);
  22110. Cartesian3.pack(cart, array, index);
  22111. index += 3;
  22112. }
  22113. return index;
  22114. }
  22115. /**
  22116. * Breaks a {@link Polyline} into segments such that it does not cross the &plusmn;180 degree meridian of an ellipsoid.
  22117. *
  22118. * @param {Cartesian3[]} positions The polyline's Cartesian positions.
  22119. * @param {Matrix4} [modelMatrix=Matrix4.IDENTITY] The polyline's model matrix. Assumed to be an affine
  22120. * transformation matrix, where the upper left 3x3 elements are a rotation matrix, and
  22121. * the upper three elements in the fourth column are the translation. The bottom row is assumed to be [0, 0, 0, 1].
  22122. * The matrix is not verified to be in the proper form.
  22123. * @returns {Object} An object with a <code>positions</code> property that is an array of positions and a
  22124. * <code>segments</code> property.
  22125. *
  22126. *
  22127. * @example
  22128. * var polylines = new Cesium.PolylineCollection();
  22129. * var polyline = polylines.add(...);
  22130. * var positions = polyline.positions;
  22131. * var modelMatrix = polylines.modelMatrix;
  22132. * var segments = Cesium.PolylinePipeline.wrapLongitude(positions, modelMatrix);
  22133. *
  22134. * @see PolygonPipeline.wrapLongitude
  22135. * @see Polyline
  22136. * @see PolylineCollection
  22137. */
  22138. PolylinePipeline.wrapLongitude = function(positions, modelMatrix) {
  22139. var cartesians = [];
  22140. var segments = [];
  22141. if (defined(positions) && positions.length > 0) {
  22142. modelMatrix = defaultValue(modelMatrix, Matrix4.IDENTITY);
  22143. var inverseModelMatrix = Matrix4.inverseTransformation(modelMatrix, wrapLongitudeInversMatrix);
  22144. var origin = Matrix4.multiplyByPoint(inverseModelMatrix, Cartesian3.ZERO, wrapLongitudeOrigin);
  22145. var xzNormal = Matrix4.multiplyByPointAsVector(inverseModelMatrix, Cartesian3.UNIT_Y, wrapLongitudeXZNormal);
  22146. var xzPlane = Plane.fromPointNormal(origin, xzNormal, wrapLongitudeXZPlane);
  22147. var yzNormal = Matrix4.multiplyByPointAsVector(inverseModelMatrix, Cartesian3.UNIT_X, wrapLongitudeYZNormal);
  22148. var yzPlane = Plane.fromPointNormal(origin, yzNormal, wrapLongitudeYZPlane);
  22149. var count = 1;
  22150. cartesians.push(Cartesian3.clone(positions[0]));
  22151. var prev = cartesians[0];
  22152. var length = positions.length;
  22153. for (var i = 1; i < length; ++i) {
  22154. var cur = positions[i];
  22155. // intersects the IDL if either endpoint is on the negative side of the yz-plane
  22156. if (Plane.getPointDistance(yzPlane, prev) < 0.0 || Plane.getPointDistance(yzPlane, cur) < 0.0) {
  22157. // and intersects the xz-plane
  22158. var intersection = IntersectionTests.lineSegmentPlane(prev, cur, xzPlane, wrapLongitudeIntersection);
  22159. if (defined(intersection)) {
  22160. // move point on the xz-plane slightly away from the plane
  22161. var offset = Cartesian3.multiplyByScalar(xzNormal, 5.0e-9, wrapLongitudeOffset);
  22162. if (Plane.getPointDistance(xzPlane, prev) < 0.0) {
  22163. Cartesian3.negate(offset, offset);
  22164. }
  22165. cartesians.push(Cartesian3.add(intersection, offset, new Cartesian3()));
  22166. segments.push(count + 1);
  22167. Cartesian3.negate(offset, offset);
  22168. cartesians.push(Cartesian3.add(intersection, offset, new Cartesian3()));
  22169. count = 1;
  22170. }
  22171. }
  22172. cartesians.push(Cartesian3.clone(positions[i]));
  22173. count++;
  22174. prev = cur;
  22175. }
  22176. segments.push(count);
  22177. }
  22178. return {
  22179. positions : cartesians,
  22180. lengths : segments
  22181. };
  22182. };
  22183. /**
  22184. * Subdivides polyline and raises all points to the specified height. Returns an array of numbers to represent the positions.
  22185. * @param {Cartesian3[]} positions The array of type {Cartesian3} representing positions.
  22186. * @param {Number|Number[]} [height=0.0] A number or array of numbers representing the heights of each position.
  22187. * @param {Number} [granularity = CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.
  22188. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie.
  22189. * @returns {Number[]} A new array of positions of type {Number} that have been subdivided and raised to the surface of the ellipsoid.
  22190. *
  22191. * @example
  22192. * var positions = Cesium.Cartesian3.fromDegreesArray([
  22193. * -105.0, 40.0,
  22194. * -100.0, 38.0,
  22195. * -105.0, 35.0,
  22196. * -100.0, 32.0
  22197. * ]);
  22198. * var surfacePositions = Cesium.PolylinePipeline.generateArc({
  22199. * positons: positions
  22200. * });
  22201. */
  22202. PolylinePipeline.generateArc = function(options) {
  22203. if (!defined(options)) {
  22204. options = {};
  22205. }
  22206. var positions = options.positions;
  22207. if (!defined(positions)) {
  22208. throw new DeveloperError('options.positions is required.');
  22209. }
  22210. var length = positions.length;
  22211. var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);
  22212. var height = defaultValue(options.height, 0);
  22213. var hasHeightArray = isArray(height);
  22214. if (length < 1) {
  22215. return [];
  22216. } else if (length === 1) {
  22217. var p = ellipsoid.scaleToGeodeticSurface(positions[0], scaleFirst);
  22218. height = hasHeightArray ? height[0] : height;
  22219. if (height !== 0) {
  22220. var n = ellipsoid.geodeticSurfaceNormal(p, cartesian);
  22221. Cartesian3.multiplyByScalar(n, height, n);
  22222. Cartesian3.add(p, n, p);
  22223. }
  22224. return [p.x, p.y, p.z];
  22225. }
  22226. var minDistance = options.minDistance;
  22227. if (!defined(minDistance)) {
  22228. var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE);
  22229. minDistance = CesiumMath.chordLength(granularity, ellipsoid.maximumRadius);
  22230. }
  22231. var numPoints = 0;
  22232. var i;
  22233. for (i = 0; i < length -1; i++) {
  22234. numPoints += PolylinePipeline.numberOfPoints(positions[i], positions[i+1], minDistance);
  22235. }
  22236. var arrayLength = (numPoints + 1) * 3;
  22237. var newPositions = new Array(arrayLength);
  22238. var offset = 0;
  22239. for (i = 0; i < length - 1; i++) {
  22240. var p0 = positions[i];
  22241. var p1 = positions[i + 1];
  22242. var h0 = hasHeightArray ? height[i] : height;
  22243. var h1 = hasHeightArray ? height[i + 1] : height;
  22244. offset = generateCartesianArc(p0, p1, minDistance, ellipsoid, h0, h1, newPositions, offset);
  22245. }
  22246. subdivideHeightsScratchArray.length = 0;
  22247. var lastPoint = positions[length - 1];
  22248. var carto = ellipsoid.cartesianToCartographic(lastPoint, carto1);
  22249. carto.height = hasHeightArray ? height[length - 1] : height;
  22250. var cart = ellipsoid.cartographicToCartesian(carto, cartesian);
  22251. Cartesian3.pack(cart, newPositions, arrayLength - 3);
  22252. return newPositions;
  22253. };
  22254. /**
  22255. * Subdivides polyline and raises all points to the specified height. Returns an array of new {Cartesian3} positions.
  22256. * @param {Cartesian3[]} positions The array of type {Cartesian3} representing positions.
  22257. * @param {Number|Number[]} [height=0.0] A number or array of numbers representing the heights of each position.
  22258. * @param {Number} [granularity = CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.
  22259. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie.
  22260. * @returns {Cartesian3[]} A new array of cartesian3 positions that have been subdivided and raised to the surface of the ellipsoid.
  22261. *
  22262. * @example
  22263. * var positions = Cesium.Cartesian3.fromDegreesArray([
  22264. * -105.0, 40.0,
  22265. * -100.0, 38.0,
  22266. * -105.0, 35.0,
  22267. * -100.0, 32.0
  22268. * ]);
  22269. * var surfacePositions = Cesium.PolylinePipeline.generateCartesianArc({
  22270. * positons: positions
  22271. * });
  22272. */
  22273. PolylinePipeline.generateCartesianArc = function(options) {
  22274. var numberArray = PolylinePipeline.generateArc(options);
  22275. var size = numberArray.length/3;
  22276. var newPositions = new Array(size);
  22277. for (var i = 0; i < size; i++) {
  22278. newPositions[i] = Cartesian3.unpack(numberArray, i*3);
  22279. }
  22280. return newPositions;
  22281. };
  22282. return PolylinePipeline;
  22283. });
  22284. /*global define*/
  22285. define('Core/WallGeometryLibrary',[
  22286. './Cartographic',
  22287. './defined',
  22288. './EllipsoidTangentPlane',
  22289. './Math',
  22290. './PolygonPipeline',
  22291. './PolylinePipeline',
  22292. './WindingOrder'
  22293. ], function(
  22294. Cartographic,
  22295. defined,
  22296. EllipsoidTangentPlane,
  22297. CesiumMath,
  22298. PolygonPipeline,
  22299. PolylinePipeline,
  22300. WindingOrder) {
  22301. 'use strict';
  22302. /**
  22303. * private
  22304. */
  22305. var WallGeometryLibrary = {};
  22306. function latLonEquals(c0, c1) {
  22307. return ((CesiumMath.equalsEpsilon(c0.latitude, c1.latitude, CesiumMath.EPSILON14)) && (CesiumMath.equalsEpsilon(c0.longitude, c1.longitude, CesiumMath.EPSILON14)));
  22308. }
  22309. var scratchCartographic1 = new Cartographic();
  22310. var scratchCartographic2 = new Cartographic();
  22311. function removeDuplicates(ellipsoid, positions, topHeights, bottomHeights) {
  22312. var length = positions.length;
  22313. if (length < 2) {
  22314. return;
  22315. }
  22316. var hasBottomHeights = defined(bottomHeights);
  22317. var hasTopHeights = defined(topHeights);
  22318. var hasAllZeroHeights = true;
  22319. var cleanedPositions = new Array(length);
  22320. var cleanedTopHeights = new Array(length);
  22321. var cleanedBottomHeights = new Array(length);
  22322. var v0 = positions[0];
  22323. cleanedPositions[0] = v0;
  22324. var c0 = ellipsoid.cartesianToCartographic(v0, scratchCartographic1);
  22325. if (hasTopHeights) {
  22326. c0.height = topHeights[0];
  22327. }
  22328. hasAllZeroHeights = hasAllZeroHeights && c0.height <= 0;
  22329. cleanedTopHeights[0] = c0.height;
  22330. if (hasBottomHeights) {
  22331. cleanedBottomHeights[0] = bottomHeights[0];
  22332. } else {
  22333. cleanedBottomHeights[0] = 0.0;
  22334. }
  22335. var index = 1;
  22336. for (var i = 1; i < length; ++i) {
  22337. var v1 = positions[i];
  22338. var c1 = ellipsoid.cartesianToCartographic(v1, scratchCartographic2);
  22339. if (hasTopHeights) {
  22340. c1.height = topHeights[i];
  22341. }
  22342. hasAllZeroHeights = hasAllZeroHeights && c1.height <= 0;
  22343. if (!latLonEquals(c0, c1)) {
  22344. cleanedPositions[index] = v1; // Shallow copy!
  22345. cleanedTopHeights[index] = c1.height;
  22346. if (hasBottomHeights) {
  22347. cleanedBottomHeights[index] = bottomHeights[i];
  22348. } else {
  22349. cleanedBottomHeights[index] = 0.0;
  22350. }
  22351. Cartographic.clone(c1, c0);
  22352. ++index;
  22353. } else if (c0.height < c1.height) {
  22354. cleanedTopHeights[index - 1] = c1.height;
  22355. }
  22356. }
  22357. if (hasAllZeroHeights || index < 2) {
  22358. return;
  22359. }
  22360. cleanedPositions.length = index;
  22361. cleanedTopHeights.length = index;
  22362. cleanedBottomHeights.length = index;
  22363. return {
  22364. positions: cleanedPositions,
  22365. topHeights: cleanedTopHeights,
  22366. bottomHeights: cleanedBottomHeights
  22367. };
  22368. }
  22369. var positionsArrayScratch = new Array(2);
  22370. var heightsArrayScratch = new Array(2);
  22371. var generateArcOptionsScratch = {
  22372. positions : undefined,
  22373. height : undefined,
  22374. granularity : undefined,
  22375. ellipsoid : undefined
  22376. };
  22377. /**
  22378. * @private
  22379. */
  22380. WallGeometryLibrary.computePositions = function(ellipsoid, wallPositions, maximumHeights, minimumHeights, granularity, duplicateCorners) {
  22381. var o = removeDuplicates(ellipsoid, wallPositions, maximumHeights, minimumHeights);
  22382. if (!defined(o)) {
  22383. return;
  22384. }
  22385. wallPositions = o.positions;
  22386. maximumHeights = o.topHeights;
  22387. minimumHeights = o.bottomHeights;
  22388. if (wallPositions.length >= 3) {
  22389. // Order positions counter-clockwise
  22390. var tangentPlane = EllipsoidTangentPlane.fromPoints(wallPositions, ellipsoid);
  22391. var positions2D = tangentPlane.projectPointsOntoPlane(wallPositions);
  22392. if (PolygonPipeline.computeWindingOrder2D(positions2D) === WindingOrder.CLOCKWISE) {
  22393. wallPositions.reverse();
  22394. maximumHeights.reverse();
  22395. minimumHeights.reverse();
  22396. }
  22397. }
  22398. var length = wallPositions.length;
  22399. var numCorners = length - 2;
  22400. var topPositions;
  22401. var bottomPositions;
  22402. var minDistance = CesiumMath.chordLength(granularity, ellipsoid.maximumRadius);
  22403. var generateArcOptions = generateArcOptionsScratch;
  22404. generateArcOptions.minDistance = minDistance;
  22405. generateArcOptions.ellipsoid = ellipsoid;
  22406. if (duplicateCorners) {
  22407. var count = 0;
  22408. var i;
  22409. for (i = 0; i < length - 1; i++) {
  22410. count += PolylinePipeline.numberOfPoints(wallPositions[i], wallPositions[i+1], minDistance) + 1;
  22411. }
  22412. topPositions = new Float64Array(count * 3);
  22413. bottomPositions = new Float64Array(count * 3);
  22414. var generateArcPositions = positionsArrayScratch;
  22415. var generateArcHeights = heightsArrayScratch;
  22416. generateArcOptions.positions = generateArcPositions;
  22417. generateArcOptions.height = generateArcHeights;
  22418. var offset = 0;
  22419. for (i = 0; i < length - 1; i++) {
  22420. generateArcPositions[0] = wallPositions[i];
  22421. generateArcPositions[1] = wallPositions[i + 1];
  22422. generateArcHeights[0] = maximumHeights[i];
  22423. generateArcHeights[1] = maximumHeights[i + 1];
  22424. var pos = PolylinePipeline.generateArc(generateArcOptions);
  22425. topPositions.set(pos, offset);
  22426. generateArcHeights[0] = minimumHeights[i];
  22427. generateArcHeights[1] = minimumHeights[i + 1];
  22428. bottomPositions.set(PolylinePipeline.generateArc(generateArcOptions), offset);
  22429. offset += pos.length;
  22430. }
  22431. } else {
  22432. generateArcOptions.positions = wallPositions;
  22433. generateArcOptions.height = maximumHeights;
  22434. topPositions = new Float64Array(PolylinePipeline.generateArc(generateArcOptions));
  22435. generateArcOptions.height = minimumHeights;
  22436. bottomPositions = new Float64Array(PolylinePipeline.generateArc(generateArcOptions));
  22437. }
  22438. return {
  22439. bottomPositions: bottomPositions,
  22440. topPositions: topPositions,
  22441. numCorners: numCorners
  22442. };
  22443. };
  22444. return WallGeometryLibrary;
  22445. });
  22446. /*global define*/
  22447. define('Core/WallGeometry',[
  22448. './BoundingSphere',
  22449. './Cartesian3',
  22450. './ComponentDatatype',
  22451. './defaultValue',
  22452. './defined',
  22453. './DeveloperError',
  22454. './Ellipsoid',
  22455. './Geometry',
  22456. './GeometryAttribute',
  22457. './GeometryAttributes',
  22458. './IndexDatatype',
  22459. './Math',
  22460. './PrimitiveType',
  22461. './VertexFormat',
  22462. './WallGeometryLibrary'
  22463. ], function(
  22464. BoundingSphere,
  22465. Cartesian3,
  22466. ComponentDatatype,
  22467. defaultValue,
  22468. defined,
  22469. DeveloperError,
  22470. Ellipsoid,
  22471. Geometry,
  22472. GeometryAttribute,
  22473. GeometryAttributes,
  22474. IndexDatatype,
  22475. CesiumMath,
  22476. PrimitiveType,
  22477. VertexFormat,
  22478. WallGeometryLibrary) {
  22479. 'use strict';
  22480. var scratchCartesian3Position1 = new Cartesian3();
  22481. var scratchCartesian3Position2 = new Cartesian3();
  22482. var scratchCartesian3Position3 = new Cartesian3();
  22483. var scratchCartesian3Position4 = new Cartesian3();
  22484. var scratchCartesian3Position5 = new Cartesian3();
  22485. var scratchBinormal = new Cartesian3();
  22486. var scratchTangent = new Cartesian3();
  22487. var scratchNormal = new Cartesian3();
  22488. /**
  22489. * A description of a wall, which is similar to a KML line string. A wall is defined by a series of points,
  22490. * which extrude down to the ground. Optionally, they can extrude downwards to a specified height.
  22491. *
  22492. * @alias WallGeometry
  22493. * @constructor
  22494. *
  22495. * @param {Object} options Object with the following properties:
  22496. * @param {Cartesian3[]} options.positions An array of Cartesian objects, which are the points of the wall.
  22497. * @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.
  22498. * @param {Number[]} [options.maximumHeights] An array parallel to <code>positions</code> that give the maximum height of the
  22499. * wall at <code>positions</code>. If undefined, the height of each position in used.
  22500. * @param {Number[]} [options.minimumHeights] An array parallel to <code>positions</code> that give the minimum height of the
  22501. * wall at <code>positions</code>. If undefined, the height at each position is 0.0.
  22502. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for coordinate manipulation
  22503. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  22504. *
  22505. * @exception {DeveloperError} positions length must be greater than or equal to 2.
  22506. * @exception {DeveloperError} positions and maximumHeights must have the same length.
  22507. * @exception {DeveloperError} positions and minimumHeights must have the same length.
  22508. *
  22509. * @see WallGeometry#createGeometry
  22510. * @see WallGeometry#fromConstantHeight
  22511. *
  22512. * @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Wall.html|Cesium Sandcastle Wall Demo}
  22513. *
  22514. * @example
  22515. * // create a wall that spans from ground level to 10000 meters
  22516. * var wall = new Cesium.WallGeometry({
  22517. * positions : Cesium.Cartesian3.fromDegreesArrayHeights([
  22518. * 19.0, 47.0, 10000.0,
  22519. * 19.0, 48.0, 10000.0,
  22520. * 20.0, 48.0, 10000.0,
  22521. * 20.0, 47.0, 10000.0,
  22522. * 19.0, 47.0, 10000.0
  22523. * ])
  22524. * });
  22525. * var geometry = Cesium.WallGeometry.createGeometry(wall);
  22526. */
  22527. function WallGeometry(options) {
  22528. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  22529. var wallPositions = options.positions;
  22530. var maximumHeights = options.maximumHeights;
  22531. var minimumHeights = options.minimumHeights;
  22532. if (!defined(wallPositions)) {
  22533. throw new DeveloperError('options.positions is required.');
  22534. }
  22535. if (defined(maximumHeights) && maximumHeights.length !== wallPositions.length) {
  22536. throw new DeveloperError('options.positions and options.maximumHeights must have the same length.');
  22537. }
  22538. if (defined(minimumHeights) && minimumHeights.length !== wallPositions.length) {
  22539. throw new DeveloperError('options.positions and options.minimumHeights must have the same length.');
  22540. }
  22541. var vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT);
  22542. var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE);
  22543. var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);
  22544. this._positions = wallPositions;
  22545. this._minimumHeights = minimumHeights;
  22546. this._maximumHeights = maximumHeights;
  22547. this._vertexFormat = VertexFormat.clone(vertexFormat);
  22548. this._granularity = granularity;
  22549. this._ellipsoid = Ellipsoid.clone(ellipsoid);
  22550. this._workerName = 'createWallGeometry';
  22551. var numComponents = 1 + wallPositions.length * Cartesian3.packedLength + 2;
  22552. if (defined(minimumHeights)) {
  22553. numComponents += minimumHeights.length;
  22554. }
  22555. if (defined(maximumHeights)) {
  22556. numComponents += maximumHeights.length;
  22557. }
  22558. /**
  22559. * The number of elements used to pack the object into an array.
  22560. * @type {Number}
  22561. */
  22562. this.packedLength = numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 1;
  22563. }
  22564. /**
  22565. * Stores the provided instance into the provided array.
  22566. *
  22567. * @param {WallGeometry} value The value to pack.
  22568. * @param {Number[]} array The array to pack into.
  22569. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  22570. *
  22571. * @returns {Number[]} The array that was packed into
  22572. */
  22573. WallGeometry.pack = function(value, array, startingIndex) {
  22574. if (!defined(value)) {
  22575. throw new DeveloperError('value is required');
  22576. }
  22577. if (!defined(array)) {
  22578. throw new DeveloperError('array is required');
  22579. }
  22580. startingIndex = defaultValue(startingIndex, 0);
  22581. var i;
  22582. var positions = value._positions;
  22583. var length = positions.length;
  22584. array[startingIndex++] = length;
  22585. for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {
  22586. Cartesian3.pack(positions[i], array, startingIndex);
  22587. }
  22588. var minimumHeights = value._minimumHeights;
  22589. length = defined(minimumHeights) ? minimumHeights.length : 0;
  22590. array[startingIndex++] = length;
  22591. if (defined(minimumHeights)) {
  22592. for (i = 0; i < length; ++i) {
  22593. array[startingIndex++] = minimumHeights[i];
  22594. }
  22595. }
  22596. var maximumHeights = value._maximumHeights;
  22597. length = defined(maximumHeights) ? maximumHeights.length : 0;
  22598. array[startingIndex++] = length;
  22599. if (defined(maximumHeights)) {
  22600. for (i = 0; i < length; ++i) {
  22601. array[startingIndex++] = maximumHeights[i];
  22602. }
  22603. }
  22604. Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  22605. startingIndex += Ellipsoid.packedLength;
  22606. VertexFormat.pack(value._vertexFormat, array, startingIndex);
  22607. startingIndex += VertexFormat.packedLength;
  22608. array[startingIndex] = value._granularity;
  22609. return array;
  22610. };
  22611. var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);
  22612. var scratchVertexFormat = new VertexFormat();
  22613. var scratchOptions = {
  22614. positions : undefined,
  22615. minimumHeights : undefined,
  22616. maximumHeights : undefined,
  22617. ellipsoid : scratchEllipsoid,
  22618. vertexFormat : scratchVertexFormat,
  22619. granularity : undefined
  22620. };
  22621. /**
  22622. * Retrieves an instance from a packed array.
  22623. *
  22624. * @param {Number[]} array The packed array.
  22625. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  22626. * @param {WallGeometry} [result] The object into which to store the result.
  22627. * @returns {WallGeometry} The modified result parameter or a new WallGeometry instance if one was not provided.
  22628. */
  22629. WallGeometry.unpack = function(array, startingIndex, result) {
  22630. if (!defined(array)) {
  22631. throw new DeveloperError('array is required');
  22632. }
  22633. startingIndex = defaultValue(startingIndex, 0);
  22634. var i;
  22635. var length = array[startingIndex++];
  22636. var positions = new Array(length);
  22637. for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {
  22638. positions[i] = Cartesian3.unpack(array, startingIndex);
  22639. }
  22640. length = array[startingIndex++];
  22641. var minimumHeights;
  22642. if (length > 0) {
  22643. minimumHeights = new Array(length);
  22644. for (i = 0; i < length; ++i) {
  22645. minimumHeights[i] = array[startingIndex++];
  22646. }
  22647. }
  22648. length = array[startingIndex++];
  22649. var maximumHeights;
  22650. if (length > 0) {
  22651. maximumHeights = new Array(length);
  22652. for (i = 0; i < length; ++i) {
  22653. maximumHeights[i] = array[startingIndex++];
  22654. }
  22655. }
  22656. var ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  22657. startingIndex += Ellipsoid.packedLength;
  22658. var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat);
  22659. startingIndex += VertexFormat.packedLength;
  22660. var granularity = array[startingIndex];
  22661. if (!defined(result)) {
  22662. scratchOptions.positions = positions;
  22663. scratchOptions.minimumHeights = minimumHeights;
  22664. scratchOptions.maximumHeights = maximumHeights;
  22665. scratchOptions.granularity = granularity;
  22666. return new WallGeometry(scratchOptions);
  22667. }
  22668. result._positions = positions;
  22669. result._minimumHeights = minimumHeights;
  22670. result._maximumHeights = maximumHeights;
  22671. result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);
  22672. result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);
  22673. result._granularity = granularity;
  22674. return result;
  22675. };
  22676. /**
  22677. * A description of a wall, which is similar to a KML line string. A wall is defined by a series of points,
  22678. * which extrude down to the ground. Optionally, they can extrude downwards to a specified height.
  22679. *
  22680. * @param {Object} options Object with the following properties:
  22681. * @param {Cartesian3[]} options.positions An array of Cartesian objects, which are the points of the wall.
  22682. * @param {Number} [options.maximumHeight] A constant that defines the maximum height of the
  22683. * wall at <code>positions</code>. If undefined, the height of each position in used.
  22684. * @param {Number} [options.minimumHeight] A constant that defines the minimum height of the
  22685. * wall at <code>positions</code>. If undefined, the height at each position is 0.0.
  22686. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for coordinate manipulation
  22687. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  22688. * @returns {WallGeometry}
  22689. *
  22690. *
  22691. * @example
  22692. * // create a wall that spans from 10000 meters to 20000 meters
  22693. * var wall = Cesium.WallGeometry.fromConstantHeights({
  22694. * positions : Cesium.Cartesian3.fromDegreesArray([
  22695. * 19.0, 47.0,
  22696. * 19.0, 48.0,
  22697. * 20.0, 48.0,
  22698. * 20.0, 47.0,
  22699. * 19.0, 47.0,
  22700. * ]),
  22701. * minimumHeight : 20000.0,
  22702. * maximumHeight : 10000.0
  22703. * });
  22704. * var geometry = Cesium.WallGeometry.createGeometry(wall);
  22705. *
  22706. * @see WallGeometry#createGeometry
  22707. */
  22708. WallGeometry.fromConstantHeights = function(options) {
  22709. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  22710. var positions = options.positions;
  22711. if (!defined(positions)) {
  22712. throw new DeveloperError('options.positions is required.');
  22713. }
  22714. var minHeights;
  22715. var maxHeights;
  22716. var min = options.minimumHeight;
  22717. var max = options.maximumHeight;
  22718. var doMin = defined(min);
  22719. var doMax = defined(max);
  22720. if (doMin || doMax) {
  22721. var length = positions.length;
  22722. minHeights = (doMin) ? new Array(length) : undefined;
  22723. maxHeights = (doMax) ? new Array(length) : undefined;
  22724. for (var i = 0; i < length; ++i) {
  22725. if (doMin) {
  22726. minHeights[i] = min;
  22727. }
  22728. if (doMax) {
  22729. maxHeights[i] = max;
  22730. }
  22731. }
  22732. }
  22733. var newOptions = {
  22734. positions : positions,
  22735. maximumHeights : maxHeights,
  22736. minimumHeights : minHeights,
  22737. ellipsoid : options.ellipsoid,
  22738. vertexFormat : options.vertexFormat
  22739. };
  22740. return new WallGeometry(newOptions);
  22741. };
  22742. /**
  22743. * Computes the geometric representation of a wall, including its vertices, indices, and a bounding sphere.
  22744. *
  22745. * @param {WallGeometry} wallGeometry A description of the wall.
  22746. * @returns {Geometry|undefined} The computed vertices and indices.
  22747. */
  22748. WallGeometry.createGeometry = function(wallGeometry) {
  22749. var wallPositions = wallGeometry._positions;
  22750. var minimumHeights = wallGeometry._minimumHeights;
  22751. var maximumHeights = wallGeometry._maximumHeights;
  22752. var vertexFormat = wallGeometry._vertexFormat;
  22753. var granularity = wallGeometry._granularity;
  22754. var ellipsoid = wallGeometry._ellipsoid;
  22755. var pos = WallGeometryLibrary.computePositions(ellipsoid, wallPositions, maximumHeights, minimumHeights, granularity, true);
  22756. if (!defined(pos)) {
  22757. return;
  22758. }
  22759. var bottomPositions = pos.bottomPositions;
  22760. var topPositions = pos.topPositions;
  22761. var numCorners = pos.numCorners;
  22762. var length = topPositions.length;
  22763. var size = length * 2;
  22764. var positions = vertexFormat.position ? new Float64Array(size) : undefined;
  22765. var normals = vertexFormat.normal ? new Float32Array(size) : undefined;
  22766. var tangents = vertexFormat.tangent ? new Float32Array(size) : undefined;
  22767. var binormals = vertexFormat.binormal ? new Float32Array(size) : undefined;
  22768. var textureCoordinates = vertexFormat.st ? new Float32Array(size / 3 * 2) : undefined;
  22769. var positionIndex = 0;
  22770. var normalIndex = 0;
  22771. var binormalIndex = 0;
  22772. var tangentIndex = 0;
  22773. var stIndex = 0;
  22774. // add lower and upper points one after the other, lower
  22775. // points being even and upper points being odd
  22776. var normal = scratchNormal;
  22777. var tangent = scratchTangent;
  22778. var binormal = scratchBinormal;
  22779. var recomputeNormal = true;
  22780. length /= 3;
  22781. var i;
  22782. var s = 0;
  22783. var ds = 1/(length - wallPositions.length + 1);
  22784. for (i = 0; i < length; ++i) {
  22785. var i3 = i * 3;
  22786. var topPosition = Cartesian3.fromArray(topPositions, i3, scratchCartesian3Position1);
  22787. var bottomPosition = Cartesian3.fromArray(bottomPositions, i3, scratchCartesian3Position2);
  22788. if (vertexFormat.position) {
  22789. // insert the lower point
  22790. positions[positionIndex++] = bottomPosition.x;
  22791. positions[positionIndex++] = bottomPosition.y;
  22792. positions[positionIndex++] = bottomPosition.z;
  22793. // insert the upper point
  22794. positions[positionIndex++] = topPosition.x;
  22795. positions[positionIndex++] = topPosition.y;
  22796. positions[positionIndex++] = topPosition.z;
  22797. }
  22798. if (vertexFormat.st) {
  22799. textureCoordinates[stIndex++] = s;
  22800. textureCoordinates[stIndex++] = 0.0;
  22801. textureCoordinates[stIndex++] = s;
  22802. textureCoordinates[stIndex++] = 1.0;
  22803. }
  22804. if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.binormal) {
  22805. var nextPosition;
  22806. var nextTop = Cartesian3.clone(Cartesian3.ZERO, scratchCartesian3Position5);
  22807. var groundPosition = ellipsoid.scaleToGeodeticSurface(Cartesian3.fromArray(topPositions, i3, scratchCartesian3Position2), scratchCartesian3Position2);
  22808. if (i + 1 < length) {
  22809. nextPosition = ellipsoid.scaleToGeodeticSurface(Cartesian3.fromArray(topPositions, i3 + 3, scratchCartesian3Position3), scratchCartesian3Position3);
  22810. nextTop = Cartesian3.fromArray(topPositions, i3 + 3, scratchCartesian3Position5);
  22811. }
  22812. if (recomputeNormal) {
  22813. var scalednextPosition = Cartesian3.subtract(nextTop, topPosition, scratchCartesian3Position4);
  22814. var scaledGroundPosition = Cartesian3.subtract(groundPosition, topPosition, scratchCartesian3Position1);
  22815. normal = Cartesian3.normalize(Cartesian3.cross(scaledGroundPosition, scalednextPosition, normal), normal);
  22816. recomputeNormal = false;
  22817. }
  22818. if (Cartesian3.equalsEpsilon(nextPosition, groundPosition, CesiumMath.EPSILON10)) {
  22819. recomputeNormal = true;
  22820. } else {
  22821. s += ds;
  22822. if (vertexFormat.tangent) {
  22823. tangent = Cartesian3.normalize(Cartesian3.subtract(nextPosition, groundPosition, tangent), tangent);
  22824. }
  22825. if (vertexFormat.binormal) {
  22826. binormal = Cartesian3.normalize(Cartesian3.cross(normal, tangent, binormal), binormal);
  22827. }
  22828. }
  22829. if (vertexFormat.normal) {
  22830. normals[normalIndex++] = normal.x;
  22831. normals[normalIndex++] = normal.y;
  22832. normals[normalIndex++] = normal.z;
  22833. normals[normalIndex++] = normal.x;
  22834. normals[normalIndex++] = normal.y;
  22835. normals[normalIndex++] = normal.z;
  22836. }
  22837. if (vertexFormat.tangent) {
  22838. tangents[tangentIndex++] = tangent.x;
  22839. tangents[tangentIndex++] = tangent.y;
  22840. tangents[tangentIndex++] = tangent.z;
  22841. tangents[tangentIndex++] = tangent.x;
  22842. tangents[tangentIndex++] = tangent.y;
  22843. tangents[tangentIndex++] = tangent.z;
  22844. }
  22845. if (vertexFormat.binormal) {
  22846. binormals[binormalIndex++] = binormal.x;
  22847. binormals[binormalIndex++] = binormal.y;
  22848. binormals[binormalIndex++] = binormal.z;
  22849. binormals[binormalIndex++] = binormal.x;
  22850. binormals[binormalIndex++] = binormal.y;
  22851. binormals[binormalIndex++] = binormal.z;
  22852. }
  22853. }
  22854. }
  22855. var attributes = new GeometryAttributes();
  22856. if (vertexFormat.position) {
  22857. attributes.position = new GeometryAttribute({
  22858. componentDatatype : ComponentDatatype.DOUBLE,
  22859. componentsPerAttribute : 3,
  22860. values : positions
  22861. });
  22862. }
  22863. if (vertexFormat.normal) {
  22864. attributes.normal = new GeometryAttribute({
  22865. componentDatatype : ComponentDatatype.FLOAT,
  22866. componentsPerAttribute : 3,
  22867. values : normals
  22868. });
  22869. }
  22870. if (vertexFormat.tangent) {
  22871. attributes.tangent = new GeometryAttribute({
  22872. componentDatatype : ComponentDatatype.FLOAT,
  22873. componentsPerAttribute : 3,
  22874. values : tangents
  22875. });
  22876. }
  22877. if (vertexFormat.binormal) {
  22878. attributes.binormal = new GeometryAttribute({
  22879. componentDatatype : ComponentDatatype.FLOAT,
  22880. componentsPerAttribute : 3,
  22881. values : binormals
  22882. });
  22883. }
  22884. if (vertexFormat.st) {
  22885. attributes.st = new GeometryAttribute({
  22886. componentDatatype : ComponentDatatype.FLOAT,
  22887. componentsPerAttribute : 2,
  22888. values : textureCoordinates
  22889. });
  22890. }
  22891. // prepare the side walls, two triangles for each wall
  22892. //
  22893. // A (i+1) B (i+3) E
  22894. // +--------+-------+
  22895. // | / | /| triangles: A C B
  22896. // | / | / | B C D
  22897. // | / | / |
  22898. // | / | / |
  22899. // | / | / |
  22900. // | / | / |
  22901. // +--------+-------+
  22902. // C (i) D (i+2) F
  22903. //
  22904. var numVertices = size / 3;
  22905. size -= 6 * (numCorners + 1);
  22906. var indices = IndexDatatype.createTypedArray(numVertices, size);
  22907. var edgeIndex = 0;
  22908. for (i = 0; i < numVertices - 2; i += 2) {
  22909. var LL = i;
  22910. var LR = i + 2;
  22911. var pl = Cartesian3.fromArray(positions, LL * 3, scratchCartesian3Position1);
  22912. var pr = Cartesian3.fromArray(positions, LR * 3, scratchCartesian3Position2);
  22913. if (Cartesian3.equalsEpsilon(pl, pr, CesiumMath.EPSILON10)) {
  22914. continue;
  22915. }
  22916. var UL = i + 1;
  22917. var UR = i + 3;
  22918. indices[edgeIndex++] = UL;
  22919. indices[edgeIndex++] = LL;
  22920. indices[edgeIndex++] = UR;
  22921. indices[edgeIndex++] = UR;
  22922. indices[edgeIndex++] = LL;
  22923. indices[edgeIndex++] = LR;
  22924. }
  22925. return new Geometry({
  22926. attributes : attributes,
  22927. indices : indices,
  22928. primitiveType : PrimitiveType.TRIANGLES,
  22929. boundingSphere : new BoundingSphere.fromVertices(positions)
  22930. });
  22931. };
  22932. return WallGeometry;
  22933. });
  22934. /*global define*/
  22935. define('Workers/createWallGeometry',[
  22936. '../Core/defined',
  22937. '../Core/Ellipsoid',
  22938. '../Core/WallGeometry'
  22939. ], function(
  22940. defined,
  22941. Ellipsoid,
  22942. WallGeometry) {
  22943. 'use strict';
  22944. function createWallGeometry(wallGeometry, offset) {
  22945. if (defined(offset)) {
  22946. wallGeometry = WallGeometry.unpack(wallGeometry, offset);
  22947. }
  22948. wallGeometry._ellipsoid = Ellipsoid.clone(wallGeometry._ellipsoid);
  22949. return WallGeometry.createGeometry(wallGeometry);
  22950. }
  22951. return createWallGeometry;
  22952. });
  22953. }());