phetsims / kite

A library for creating, manipulating and displaying 2D shapes in JavaScript.
http://scenerystack.org/
MIT License
15 stars 6 forks source link

Intersection failure in CLB #74

Closed jonathanolson closed 6 years ago

jonathanolson commented 6 years ago

It can be reproduced with the following:

new kite.Shape( 'M 304.90681252543902246543 567.54710280120116294711 L 300.66417183831975989960 574.33532790059200578980 L 295.14873894506467877363 579.85076079384725744603 L 292.60315453279315534019 577.30517638157562032575 L 298.11858742604823646616 571.78974348832048235636 L 304.90681252543902246543 567.54710280120116294711 Z' ).shapeIntersection( new kite.Shape( 'M 74.50000000000000000000 564.30580079512674274156 L 74.50000000000000000000 453.29999999999995452526 A 3.50000000000000000000 3.50000000000000000000 0 1 1 81.50000000000000000000 453.29999999999995452526 L 81.50000000000000000000 560.80580079512674274156 L 304.49419920487315494029 560.80580079512674274156 A 3.50000000000000000000 3.50000000000000000000 0 1 1 304.49419920487315494029 567.80580079512674274156 L 78.00000000000000000000 567.80580079512674274156 A 3.50000000000000000000 3.50000000000000000000 0 0 1 74.50000000000000000000 564.30580079512674274156 Z' ) )

See https://github.com/phetsims/capacitor-lab-basics/issues/251

jonathanolson commented 6 years ago

This looks related to the blackbody-spectrum issue, which can be reproduced with:

new kite.Shape( 'M 0.00000000000000000000 0.00000000000000000000 L 1.83946488294314391965 -0.00000000000000000000 L 3.67892976588628783929 -0.00000000000000000000 L 5.51839464882943175894 -0.00000000000000000000 L 7.35785953177257567859 -0.00000000000000003679 L 9.19732441471571959823 -0.00000000000186576690 L 11.03678929765886351788 -0.00000000216156368981 L 12.87625418060200743753 -0.00000029602736631401 L 14.71571906354515135718 -0.00001083541267232178 L 16.55518394648829527682 -0.00016621614732601037 L 18.39464882943143919647 -0.00139687663467322762 L 20.23411371237458311612 -0.00761694903688425740 L 22.07357859531772703576 -0.03014118099800658021 L 23.91304347826087095541 -0.09347578857555913223 L 25.75250836120401487506 -0.23992484289689394727 L 27.59197324414715879470 -0.53029641647538494631 L 29.43143812709030271435 -1.03956649499755937605 L 31.27090301003344663400 -1.84843945345065097108 L 33.11036789297659055364 -3.03309105116907273825 L 34.94983277591973092058 -4.65557609599566291081 L 36.78929765886287839294 -6.75672438742900016706 L 38.62876254180602586530 -9.35236906841864623630 L 40.46822742474916623223 -12.43287303226884610297 L 42.30769230769230659917 -15.96534197964804313585 L 44.14715719063545407153 -19.89765738717256127188 L 45.98662207357860154389 -24.16345428254172134075 L 47.82608695652174191082 -28.68730737718304624195 L 49.66555183946488227775 -33.38958859223290431828 L 51.50501672240802975011 -38.19066056279294230080 L 53.34448160535117722247 -43.01424212741438424246 L 55.18394648829431758941 -47.78991077207599147414 L 57.02341137123745795634 -52.45479353090901497580 L 58.86287625418060542870 -56.95454828451419615476 L 60.70234113712375290106 -61.24376028941210137191 L 62.54180602006689326799 -65.28588251052717339462 L 64.38127090301003363493 -69.05284001371911983824 L 66.22073578595318110729 -72.52440375904511427052 L 68.06020066889632857965 -75.68742148448932027804 L 69.89966555183946184115 -78.53497552086059840804 L 71.73913043478260931352 -81.06552084515433875822 L 73.57859531772575678588 -83.28204224174950809356 L 75.41806020066890425824 -85.19125738454314955561 L 77.25752508361205173060 -86.80288295547214261205 L 79.09698996655518499210 -88.12897337683817511333 L 80.93645484949833246446 -89.18333607258105644178 L 82.77591973244147993682 -89.98102307727745596821 L 84.61538461538461319833 -90.53789598070727606682 L 86.45484949832776067069 -90.87025935851876567995 L 88.29431438127090814305 -90.99455676126284231486 L 90.13377926421405561541 -90.92712281941054186518 L 91.97324414715720308777 -90.68398491270917816109 L 93.81270903010033634928 -90.28070802340009493037 L 95.65217391304348382164 -89.73227674797279007635 L 97.49163879598663129400 -89.05300890850962503009 L 99.33110367892976455551 -88.25649572870581494044 L 101.17056856187291202787 -87.35556408294766583822 L 103.01003344481605950023 -86.36225686283805202947 L 104.84949832775920697259 -85.28782801669061086614 L 106.68896321070235444495 -84.14274929294117555401 L 108.52842809364548770645 -82.93672615222247657130 L 110.36789297658863517881 -81.67872070261564942939 L 112.20735785953178265117 -80.37697985837540670673 L 114.04682274247491591268 -79.03906722587150568415 L 115.88628762541806338504 -77.67189748428145890102 L 117.72575250836121085740 -76.28177225595915444956 L 119.56521739130435832976 -74.87441665589169303985 L 121.40468227424750580212 -73.45501587480977434552 L 123.24414715719063906363 -72.02825128976803625847 L 125.08361204013378653599 -70.59833571262363705046 L 126.92307692307693400835 -69.16904748381138290370 L 128.76254180602006726986 -67.74376319886266628600 L 130.60200668896322895307 -66.32548892069223711587 L 132.44147157190636221458 -64.91688978393736420003 L 134.28093645484949547608 -63.52031794048280488596 L 136.12040133779265715930 -62.13783882939519997990 L 137.95986622073579042080 -60.77125578125778559979 L 139.79933110367892368231 -59.42213298757238248982 L 141.63879598662208536552 -58.09181688153004330388 L 143.47826086956521862703 -56.78145598795537551950 L 145.31772575250838031025 -55.49201930834533413872 L 147.15719063545151357175 -54.22431331230735196414 L 148.99665551839464683326 -52.97899760988534012540 L 150.83612040133780851647 -51.75659938069295407104 L 152.67558528428094177798 -50.55752663583398742730 L 154.51505016722410346119 -49.38208038758018147973 L 156.35451505016723672270 -48.23046579995965998933 L 158.19397993311036998421 -47.10280239098867127723 L 160.03344481605353166742 -45.99913335443039841266 L 161.87290969899666492893 -44.91943406581900433139 L 163.71237458193979819043 -43.86361983416274057390 L 165.55183946488295987365 -42.83155295731745582088 L 167.39130434782609313515 -41.82304913557756265163 L 169.23076923076922639666 -40.83788329461208377325 L 171.07023411371238807988 -39.87579486552797902732 L 172.90969899665552134138 -38.93649256659373492084 L 174.74916387959868302460 -38.01965872803269519409 L 176.58862876254181628610 -37.12495319830902218428 L 178.42809364548494954761 -36.25201686749102947260 L 180.26755852842811123082 -35.40047484059169846660 L 182.10702341137124449233 -34.56993929125807341052 L 183.94648829431440617554 -33.76001202380744814491 L 185.78595317725753943705 -32.97028676938789004680 L 187.62541806020067269856 -32.20035123996823500647 L 189.46488294314383438177 -31.44978896193467576836 L 191.30434782608696764328 -30.71818090927854072447 L 193.14381270903010090478 -30.00510695470069322255 L 194.98327759197326258800 -29.31014715541871851201 L 196.82274247491639584950 -28.63288288904525202838 L 198.66220735785952911101 -27.97289785359335567705 L 200.50167224080269079423 -27.32977894445797417688 L 202.34113712374582405573 -26.70311702010998189394 L 204.18060200668898573895 -26.09250756721754882506 L 206.02006688963211900045 -25.49755127496894147043 L 207.85953177257525226196 -24.91785452750958285151 L 209.69899665551841394517 -24.35302982261437421130 L 211.53846153846154720668 -23.80269612399159484539 L 213.37792642140470888990 -23.26647915395019339257 L 215.21739130434784215140 -22.74401163255498303783 L 217.05685618729097541291 -22.23493346883714494311 L 218.89632107023413709612 -21.73889190911999591549 L 220.73578595317727035763 -21.25554164705404147639 L 222.57525083612040361913 -20.78454489953185913009 L 224.41471571906356530235 -20.32557145226496331247 L 226.25418060200669856386 -19.87829867845153941630 L 228.09364548494983182536 -19.44241153364086471811 L 229.93311036789299350858 -19.01760252960630381835 L 231.77257525083612677008 -18.60357168977030184465 L 233.61204013377928845330 -18.20002648848033643958 L 235.45150501672242171480 -17.80668177621245362729 L 237.29096989966555497631 -17.42325969257615980723 L 239.13043478260871665952 -17.04948956880993549134 L 240.96989966555184992103 -16.68510782128885239217 L 242.80936454849501160425 -16.32985783741336405228 L 244.64882943143814486575 -15.98348985510921771436 L 246.48829431438127812726 -15.64576083704262821072 L 248.32775919732443981047 -15.31643434054043595438 L 250.16722408026757307198 -14.99528038410067409814 L 252.00668896321070633348 -14.68207531128472709270 L 253.84615384615386801670 -14.37660165269712386760 L 255.68561872909700127821 -14.07864798668055428266 L 257.52508361204013453971 -13.78800879928424372167 L 259.36454849498329622293 -13.50448434399956632035 L 261.20401337792645790614 -13.22788050169953422142 L 263.04347826086956274594 -12.95800864116619344202 L 264.88294314381272442915 -12.69468548054356915600 L 266.72240802675588611237 -12.43773295001037659802 L 268.56187290969899095217 -12.18697805592893601556 L 270.40133779264215263538 -11.94225274669199166055 L 272.24080267558531431860 -11.70339378045750144963 L 274.08026755852841915839 -11.47024259493399789278 L 275.91973244147158084161 -11.24264517935340457200 L 277.75919732441474252482 -11.02045194874563271981 L 279.59866220735784736462 -10.80351762060906750662 L 281.43812709030100904783 -10.59170109405268611624 L 283.27759197324417073105 -10.38486533146930845817 L 285.11705685618733241427 -10.18287724278490458119 L 286.95652173913043725406 -9.98560757231605577999 L 288.79598662207359893728 -9.79293078825595841863 L 290.63545150501676062049 -9.60472497479917031171 L 292.47491638795986546029 -9.42087172690651541984 L 294.31438127090302714350 -9.24125604770314801328 L 296.15384615384618882672 -9.06576624849611079071 L 297.99331103678929366652 -8.89429385139146866379 L 299.83277591973245534973 -8.72673349448565716102 L 301.67224080267561703295 -8.56298283960120976133 L 303.51170568561872187274 -8.40294248253283626582 L 305.35117056856188355596 -8.24651586576654693772 L 307.19063545150504523917 -8.09360919363146358307 L 309.03010033444820692239 -7.94413134984170454800 L 310.86956521739131176219 -7.79799381738342756165 L 312.70903010033447344540 -7.65511060070070747940 L 314.54849498327763512862 -7.51539815013251910614 L 316.38795986622073996841 -7.37877528855199305013 L 318.22742474916390165163 -7.24516314015849260954 L 320.06688963210706333484 -7.11448506137245129111 L 321.90635451505016817464 -6.98666657378264677192 L 323.74581939799332985785 -6.86163529909549385621 L 325.58528428093649154107 -6.73932089603589723481 L 327.42474916387959638087 -6.61965499914951571725 L 329.26421404682275806408 -6.50257115945652497402 L 331.10367892976591974730 -6.38800478690747297605 L 332.94314381270902458709 -6.27589309459224242715 L 334.78260869565218627031 -6.16617504465390631196 L 336.62207357859534795352 -6.05879129585981601736 L 338.46153846153845279332 -5.95368415278311147176 L 340.30100334448161447654 -5.85079751654851243359 L 342.14046822742477615975 -5.75007683709730876842 L 343.97993311036793784297 -5.65146906692709727338 L 345.81939799331104268276 -5.55492261626296013333 L 347.65886287625420436598 -5.46038730961750662374 L 349.49832775919736604919 -5.36781434369834098419 L 351.33779264214047088899 -5.27715624662230187170 L 353.17725752508363257220 -5.18836683839695300691 L 355.01672240802679425542 -5.10140119263065283661 L 356.85618729096989909522 -5.01621559943356309930 L 358.69565217391306077843 -4.93276752947298202656 L 360.53511705685622246165 -4.85101559914718372113 L 362.37458193979932730144 -4.77091953684316383288 L 364.21404682274248898466 -4.69244015024436400552 L 366.05351170568565066787 -4.61553929465560131007 L 367.89297658862881235109 -4.54017984231327353939 L 369.73244147157191719089 -4.46632565264977721142 L 371.57190635451507887410 -4.39394154348207610639 L 373.41137123745824055732 -4.32299326309515663525 L 375.25083612040134539711 -4.25344746319201227891 L 377.09030100334450708033 -4.18527167268260580357 L 378.92976588628766876354 -4.11843427228517455774 L 380.76923076923077360334 -4.05290446991390762577 L 382.60869565217393528656 -3.98865227682800593811 L 384.44816053511709696977 -3.92564848451770709303 L 386.28762541806020180957 -3.86386464230375459294 L 388.12709030100336349278 -3.80327303562751639632 L 389.96655518394652517600 -3.74384666500954432777 L 391.80602006688963001579 -3.68555922565524740619 L 393.64548494983279169901 -3.62838508768688683404 L 395.48494983277595338222 -3.57229927698180160789 L 397.32441471571905822202 -3.51727745659748203266 L 399.16387959866221990524 -3.46329590876460047255 L 401.00334448160538158845 -3.41033151742983386967 L 402.84280936454854327167 -3.35836175133081837885 L 404.68227424749164811146 -3.30736464758622217275 L 406.52173913043480979468 -3.25731879578436434031 L 408.36120401337797147789 -3.20820332255447260295 L 410.20066889632107631769 -3.15999787660510111920 L 412.04013377926423800091 -3.11268261421474967676 L 413.87959866220739968412 -3.06623818516025625769 L 415.71906354515050452392 -3.02064571906895773523 L 417.55852842809366620713 -2.97588681218107042881 L 419.39799331103682789035 -2.93194351450927115366 L 421.23745819397993273014 -2.88879831738273518127 L 423.07692307692309441336 -2.84643414136345862531 L 424.91638795986625609657 -2.80483432452300096571 L 426.75585284280941777979 -2.76398261106820042343 L 428.59531772575252261959 -2.72386314030478482451 L 430.43478260869568430280 -2.68446043592818517354 L 432.27424749163884598602 -2.64575939563118067710 L 434.11371237458195082581 -2.60774528101837699268 L 435.95317725752511250903 -2.57040370781780547205 L 437.79264214046827419224 -2.53372063638031042032 L 439.63210702341137903204 -2.49768236245764319037 L 441.47157190635454071526 -2.46227550825051233474 L 443.31103678929770239847 -2.42748701371811526073 L 445.15050167224080723827 -2.39330412814095616625 L 446.98996655518396892148 -2.35971440192903436639 L 448.82943143812713060470 -2.32670567866772914911 L 450.66889632107023544449 -2.29426608739397464021 L 452.50836120401339712771 -2.26238403509555041637 L 454.34782608695655881093 -2.23104819942656940057 L 456.18729096989966365072 -2.20024752163242887093 L 458.02675585284282533394 -2.16997119967775775606 L 459.86622073578598701715 -2.14020868157108878904 L 461.70568561872914870037 -2.11094965888015950739 L 463.54515050167225354016 -2.08218406043199522060 L 465.38461538461541522338 -2.05390204619208605052 L 467.22408026755857690659 -2.02609400131714600946 L 469.06354515050168174639 -1.99875053037616323692 L 470.90301003344484342961 -1.97186245173458285507 L 472.74247491638800511282 -1.94542079209662999162 L 474.58193979933110995262 -1.91941678120099168403 L 476.42140468227427163583 -1.89384184666516452999 L 478.26086956521743331905 -1.86868760897397456766 L 480.10033444816053815885 -1.84394587660789577299 L 481.93979933110369984206 -1.81960864130696253760 L 483.77926421404686152528 -1.79566807346615409102 L 485.61872909699002320849 -1.77211651765832622907 L 487.45819397993312804829 -1.74894648828085630399 L 489.29765886287628973150 -1.72615066532225869267 L 491.13712374581945141472 -1.70372189024524112178 L 492.97658862876255625451 -1.68165316198268088854 L 494.81605351170571793773 -1.65993763304317232254 L 496.65551839464887962095 -1.63856860572289875222 L 498.49498327759198446074 -1.61753952842066484052 L 500.33444816053514614396 -1.59684399205303395597 L 502.17391304347830782717 -1.57647572656662982027 L 504.01337792642141266697 -1.55642859754473183997 L 505.85284280936457435018 -1.53669660290537413161 L 507.69230769230773603340 -1.51727386968829791591 L 509.53177257525084087320 -1.49815465092813582260 L 511.37123745819400255641 -1.47933332261129835139 L 513.21070234113710739621 -1.46080438071415175116 L 515.05016722408026907942 -1.44256243832010278005 L 516.88963210702343076264 -1.42460222281329995653 L 518.72909698996659244585 -1.40691857314674684254 L 520.56856187290975412907 -1.38950643718266930726 L 522.40802675585291581228 -1.37236086910304400099 L 524.24749163879596380866 -1.35547702688828874962 L 526.08695652173912549188 -1.33885016986215532597 L 527.92642140468228717509 -1.32247565630090524458 L 529.76588628762544885831 -1.30634894110497024045 L 531.60535117056861054152 -1.29046557353128443779 L 533.44481605351177222474 -1.27482119498457802109 L 535.28428093645493390795 -1.25941153686595597172 L 537.12374581939798190433 -1.24423241847714072250 L 538.96321070234114358755 -1.22927974497880088123 L 540.80267558528430527076 -1.21454950540144768212 L 542.64214046822746695398 -1.20003777070742168043 L 544.48160535117062863719 -1.18574069190252839867 L 546.32107023411379032041 -1.17165449819593847636 L 548.16053511705683831678 -1.15777549520700717700 L 550.00000000000000000000 -1.14410006321769741611' ).shapeClip( new kite.Shape( 'M 0.00000000000000000000 0.00000000000000000000 L 550.00000000000000000000 0.00000000000000000000 L 550.00000000000000000000 400.00000000000000000000 L 0.00000000000000000000 400.00000000000000000000 L 0.00000000000000000000 0.00000000000000000000 Z' ) );
jonathanolson commented 6 years ago

The blackbody-spectrum issue looks like our getOverlaps() functions don't handle large values well. The "relative" epsilon results in structures that are far away.

jonathanolson commented 6 years ago

Ok should be cleared up with various kite commits.