/* Ċ Ġ* ĠCopyright ĠÂ© Ġ 2 0 2 1 ĠE no ve a Ġ( fab ien . me ur isse @ en ove a . net ) Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġdil iv ia . s 2 . index . shape Ċ Ċ import Ġdil iv ia . s 2 . S 1 Angle Ċ import Ġdil iv ia . s 2 . S 2 Earth Ċ import Ġdil iv ia . s 2 . S 2 Point Ċ import Ġdil iv ia . s 2 . S 2 Random Ċ import Ġdil iv ia . s 2 . S 2 Text Parser Ċ import Ġdil iv ia . s 2 . index . shape . S 2 Contains Point Query . Companion . make S 2 Contains Point Query Ċ import Ġdil iv ia . s 2 . region . S 2 Cap Ċ import Ġdil iv ia . s 2 . region . S 2 Loop Ċ import Ġdil iv ia . s 2 . shape . S 2 Shape Ċ import Ġdil iv ia . s 2 . shape . Shape Edge Id Ċ import Ġmu . Kotlin Logging Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Test Ċ Ċ type alias ĠEdge Id Vector Ġ= ĠMutable List < Shape Edge Id > Ċ Ċ class ĠS 2 Contains Point Query Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġlogger Ġ= ĠKotlin Logging . logger Ġ{ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcontains Point Query Vertex Model Open () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġindex Ġ= ĠS 2 Text Parser . make Index (" 0 : 0 Ġ# Ġ- 1 : 1 , Ġ 1 : 1 Ġ# Ġ 0 : 5 , Ġ 0 : 7 , Ġ 2 : 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġoptions Ġ= ĠS 2 Contains Point Query Options ( S 2 Vertex Model . OPEN ) ĊĠĠĠĠĠĠĠ Ġval Ġq Ġ= Ġmake S 2 Contains Point Query ( index , Ġoptions ) ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 0 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point ("- 1 : 1 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 1 : 1 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 2 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 3 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 5 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 7 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 2 : 6 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 1 : 6 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 1 0 : 1 0 ")) ). isFalse () ĊĊĠĠĠĠĠĠĠ Ġ// ĠTest Ġthe Ġlast Ġfew Ġcases Ġusing Ġthe ĠInit () Ġmethod Ġinstead . ĊĠĠĠĠĠĠĠ Ġval Ġq 2 Ġ= ĠS 2 Contains Point Query < Mutable S 2 Shape Index >() ĊĠĠĠĠĠĠĠ Ġq 2 . init ( index , Ġoptions ) ĊĠĠĠĠĠĠĠ ĠassertThat ( q 2 . shape Contains ( index . shape ( 1 ) !! , ĠS 2 Text Parser . make Point (" 1 : 6 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q 2 . shape Contains ( index . shape ( 2 ) !! , ĠS 2 Text Parser . make Point (" 1 : 6 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q 2 . shape Contains ( index . shape ( 2 ) !! , ĠS 2 Text Parser . make Point (" 0 : 5 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q 2 . shape Contains ( index . shape ( 2 ) !! , ĠS 2 Text Parser . make Point (" 0 : 7 ")) ). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcontains Point Query Vertex Model Sem i Open () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġindex Ġ= ĠS 2 Text Parser . make Index (" 0 : 0 Ġ# Ġ- 1 : 1 , Ġ 1 : 1 Ġ# Ġ 0 : 5 , Ġ 0 : 7 , Ġ 2 : 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġoptions Ġ= ĠS 2 Contains Point Query Options ( S 2 Vertex Model . SE MI _ OPEN ) ĊĠĠĠĠĠĠĠ Ġval Ġq Ġ= Ġmake S 2 Contains Point Query ( index , Ġoptions ) ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 0 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point ("- 1 : 1 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 1 : 1 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 2 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 5 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 7 ")) ). isTrue () Ġ Ġ// ĠCont ained Ġvertex . ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 2 : 6 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 1 : 6 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 1 0 : 1 0 ")) ). isFalse () ĊĊĠĠĠĠĠĠĠ Ġ// ĠTest Ġthe Ġlast Ġfew Ġcases Ġusing Ġthe ĠInit () Ġmethod Ġinstead . ĊĠĠĠĠĠĠĠ Ġval Ġq 2 Ġ= ĠS 2 Contains Point Query < Mutable S 2 Shape Index >() ĊĠĠĠĠĠĠĠ Ġq 2 . init ( index , Ġoptions ) ĊĠĠĠĠĠĠĠ ĠassertThat ( q 2 . shape Contains ( index . shape ( 1 ) !! , ĠS 2 Text Parser . make Point (" 1 : 6 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q 2 . shape Contains ( index . shape ( 2 ) !! , ĠS 2 Text Parser . make Point (" 1 : 6 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q 2 . shape Contains ( index . shape ( 2 ) !! , ĠS 2 Text Parser . make Point (" 0 : 5 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q 2 . shape Contains ( index . shape ( 2 ) !! , ĠS 2 Text Parser . make Point (" 0 : 7 ")) ). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcontains Point Query Vertex Model Closed () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġindex Ġ= ĠS 2 Text Parser . make Index (" 0 : 0 Ġ# Ġ- 1 : 1 , Ġ 1 : 1 Ġ# Ġ 0 : 5 , Ġ 0 : 7 , Ġ 2 : 6 ") ĊĠĠĠĠĠĠĠ Ġval Ġoptions Ġ= ĠS 2 Contains Point Query Options ( S 2 Vertex Model . CLOSED ) ĊĠĠĠĠĠĠĠ Ġval Ġq Ġ= Ġmake S 2 Contains Point Query ( index , Ġoptions ) ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 0 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point ("- 1 : 1 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 1 : 1 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 2 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 5 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 0 : 7 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 2 : 6 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 1 : 6 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q . contains ( S 2 Text Parser . make Point (" 1 0 : 1 0 ")) ). isFalse () ĊĊĠĠĠĠĠĠĠ Ġ// ĠTest Ġthe Ġlast Ġfew Ġcases Ġusing Ġthe ĠInit () Ġmethod Ġinstead . ĊĠĠĠĠĠĠĠ Ġval Ġq 2 Ġ= ĠS 2 Contains Point Query < Mutable S 2 Shape Index >() ĊĠĠĠĠĠĠĠ Ġq 2 . init ( index , Ġoptions ) ĊĠĠĠĠĠĠĠ ĠassertThat ( q 2 . shape Contains ( index . shape ( 1 ) !! , ĠS 2 Text Parser . make Point (" 1 : 6 ")) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( q 2 . shape Contains ( index . shape ( 2 ) !! , ĠS 2 Text Parser . make Point (" 1 : 6 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q 2 . shape Contains ( index . shape ( 2 ) !! , ĠS 2 Text Parser . make Point (" 0 : 5 ")) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( q 2 . shape Contains ( index . shape ( 2 ) !! , ĠS 2 Text Parser . make Point (" 0 : 7 ")) ). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcontains Point Query Get Containing Shapes () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠAlso Ġtests Ġshape Contains (). ĊĠĠĠĠĠĠĠ Ġval Ġk Num Vertices Per Loop Ġ= Ġ 1 0 ĊĠĠĠĠĠĠĠ Ġval Ġk Max Loop Radius Ġ= ĠS 1 Angle . radians ( S 2 Earth . km To Radians ( 1 0 . 0 )) ĊĠĠĠĠĠĠĠ Ġval Ġcenter Cap Ġ= ĠS 2 Cap . from Center Angle ( S 2 Random . random Point (), Ġk Max Loop Radius ) ĊĊĠĠĠĠĠĠĠ Ġlogger . trace Ġ{ Ġ" Test Ġparams : Ġnum Ġvertices Ġper Ġloop Ġ= Ġ$ k Num Vertices Per Loop , Ġmax Ġloop Ġradius Ġ= Ġ$ k Max Loop Radius , Ġcenter Ġcap Ġ= Ġ$ center Cap " Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġindex Ġ= ĠMutable S 2 Shape Index () ĊĠĠĠĠĠĠĠ Ġrepeat ( 1 0 0 ) Ġ{ Ġi Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcenter Ġ= ĠS 2 Random . sample Point ( center Cap ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġradius Ġ= Ġk Max Loop Radius Ġ* ĠS 2 Random . random Double () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġloop Ġ= ĠS 2 Loop . make Regular Loop ( center , Ġradius , Ġk Num Vertices Per Loop ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlogger . trace Ġ{ Ġ" Create Ġloop Ġ$ i : Ġcenter Ġ= Ġ$ center , Ġradius Ġ= Ġ${ radius . radians } Ġ=> Ġ$ loop " Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġindex . add ( S 2 Loop . Shape ( loop Ġ= Ġloop )) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġlogger . trace Ġ{ Ġ" Index :\ n ------------------- \ n ${ index . to Debug String () }\ n -------------------- " Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġquery Ġ= Ġmake S 2 Contains Point Query ( index ) ĊĠĠĠĠĠĠĠ Ġrepeat ( 1 0 0 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġp Ġ= ĠS 2 Random . sample Point ( center Cap ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġexpected Ġ= Ġmutable ListOf < S 2 Shape >() ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfor Ġ( shape Ġin Ġindex ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġloop Ġ= Ġ( shape Ġas ĠS 2 Loop . Shape ). loop ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġloop Contains Point Ġ= Ġloop . contains ( p ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġshape Contains Point Ġ= Ġquery . shape Contains ( shape , Ġp ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( loop Contains Point ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( shape Contains Point ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Fail Message (" loop Ġcontains Ġpoint Ġ$ p Ġbut Ġquery Ġresult Ġis Ġfalse : Ġid Ġ= Ġ${ shape . id }, Ġloop Ġ= Ġ$ loop "). isTrue () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġexpected . add ( shape ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( shape Contains Point ). isFalse () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġquery . get Containing Shapes ( p ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( actual ). isEqualTo ( expected ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġexpect Incident Edge Ids ( expected : ĠEdge Id Vector , Ġindex : ĠMutable S 2 Shape Index , Ġp : ĠS 2 Point ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġactual : ĠEdge Id Vector Ġ= Ġmutable ListOf () ĊĠĠĠĠĠĠĠ Ġval Ġq Ġ= Ġmake S 2 Contains Point Query ( index ) ĊĠĠĠĠĠĠĠ ĠassertThat ( q . visit Incident Edges ( p ) Ġ{ Ġe Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactual . add ( e . id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠ Ġ}). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( actual ). isEqualTo ( expected ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcontains Point Query Visit Incident Edges () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġindex Ġ= ĠS 2 Text Parser . make Index (" 0 : 0 Ġ| Ġ 1 : 1 Ġ# Ġ 1 : 1 , Ġ 1 : 2 Ġ# Ġ 1 : 2 , Ġ 1 : 3 , Ġ 2 : 2 ") ĊĠĠĠĠĠĠĠ Ġexpect Incident Edge Ids ( mutable ListOf ( Shape Edge Id ( 0 , Ġ 0 )), Ġindex , ĠS 2 Text Parser . make Point (" 0 : 0 ")) ĊĠĠĠĠĠĠĠ Ġexpect Incident Edge Ids ( mutable ListOf ( Shape Edge Id ( 0 , Ġ 1 ), ĠShape Edge Id ( 1 , Ġ 0 )), Ġindex , ĠS 2 Text Parser . make Point (" 1 : 1 ")) ĊĠĠĠĠĠĠĠ Ġexpect Incident Edge Ids ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmutable ListOf ( Shape Edge Id ( 1 , Ġ 0 ), ĠShape Edge Id ( 2 , Ġ 0 ), ĠShape Edge Id ( 2 , Ġ 2 )), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġindex , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠS 2 Text Parser . make Point (" 1 : 2 ") ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġexpect Incident Edge Ids ( mutable ListOf ( Shape Edge Id ( 2 , Ġ 0 ), ĠShape Edge Id ( 2 , Ġ 1 )), Ġindex , ĠS 2 Text Parser . make Point (" 1 : 3 ")) ĊĠĠĠĠĠĠĠ Ġexpect Incident Edge Ids ( mutable ListOf ( Shape Edge Id ( 2 , Ġ 1 ), ĠShape Edge Id ( 2 , Ġ 2 )), Ġindex , ĠS 2 Text Parser . make Point (" 2 : 2 ")) ĊĠĠĠ Ġ} Ċ Ċ } Ċ