Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix point in poligon #3341

Merged
merged 2 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions dbms/src/Functions/GeoUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ void PointInPolygonWithGrid<CoordinateType>::addComplexPolygonCell(
cells[index].index_of_inner_polygon = polygons.size();

/// Expand box in (1 + eps_factor) times to eliminate errors for points on box bound.
static constexpr float eps_factor = 0.01;
float x_eps = eps_factor * (box.max_corner().x() - box.min_corner().x());
float y_eps = eps_factor * (box.max_corner().y() - box.min_corner().y());
static constexpr CoordinateType eps_factor = 0.01;
auto x_eps = eps_factor * (box.max_corner().x() - box.min_corner().x());
auto y_eps = eps_factor * (box.max_corner().y() - box.min_corner().y());

Point min_corner(box.min_corner().x() - x_eps, box.min_corner().y() - y_eps);
Point max_corner(box.max_corner().x() + x_eps, box.max_corner().y() + y_eps);
Expand Down Expand Up @@ -615,12 +615,11 @@ ColumnPtr pointInPolygon(const IColumn & x, const IColumn & y, PointInPolygonImp

/// Total angle (signed) between neighbor vectors in linestring. Zero if linestring.size() < 2.
template <typename Linestring>
float calcLinestringRotation(const Linestring & points)
double calcLinestringRotation(const Linestring & points)
{
using Point = std::decay_t<decltype(*points.begin())>;
float rotation = 0;
double rotation = 0;

auto sqrLength = [](const Point & point) { return point.x() * point.x() + point.y() * point.y(); };
auto vecProduct = [](const Point & from, const Point & to) { return from.x() * to.y() - from.y() * to.x(); };
auto scalarProduct = [](const Point & from, const Point & to) { return from.x() * to.x() + from.y() * to.y(); };
auto getVector = [](const Point & from, const Point & to) -> Point
Expand All @@ -640,20 +639,11 @@ float calcLinestringRotation(const Linestring & points)

Point from = getVector(*prev, *it);
Point to = getVector(*it, *next);
float sqr_from_len = sqrLength(from);
float sqr_to_len = sqrLength(to);
float sqr_len_product = (sqr_from_len * sqr_to_len);
if (std::isfinite(sqr_len_product))
{
float vec_prod = vecProduct(from, to);
float scalar_prod = scalarProduct(from, to);
float sin_ang = vec_prod * std::fabs(vec_prod) / sqr_len_product;
float cos_ang = scalar_prod * std::fabs(scalar_prod) / sqr_len_product;
sin_ang = std::max(-1.f, std::min(1.f, sin_ang));
cos_ang = std::max(-1.f, std::min(1.f, cos_ang));
float ang = std::atan2(sin_ang, cos_ang);
rotation += ang;
}

auto vec_prod = vecProduct(from, to);
auto scalar_prod = scalarProduct(from, to);
auto ang = std::atan2(vec_prod, scalar_prod);
rotation += ang;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT pointInPolygon((106.677085876465,10.7744951248169), [(106.667161868227,10.7675128359024),(106.667165727127,10.7675059912261),(106.667170817563,10.7674904752629),(106.667229225265,10.7672278502066),(106.667231193621,10.7672115129572),(106.667229912029,10.7671951075415),(106.667225430503,10.767179274157),(106.667217923927,10.7671646306786),(106.667207685234,10.7671517485471),(106.667195113975,10.7671411304688),(106.667180700725,10.7671331907989),(106.66716500794,10.7671282393715),(106.666628232995,10.7670156787539),(106.666612233649,10.7670139127584),(106.666596193354,10.7670152569112),(106.666580711053,10.7670196610218),(106.666566364856,10.7670269606408),(106.666553690448,10.7670368832008),(106.666543161092,10.767049058194),(106.666535169952,10.7670630310067),(106.666530015418,10.7670782798948),(106.666482284259,10.7672828714379),(106.666480170141,10.7672985245675),(106.666481048788,10.7673142953614),(106.666484888609,10.7673296167758),(106.666491551541,10.7673439379244),(106.666500798017,10.7673567438858),(106.666512295576,10.7673675742178),(106.666525630821,10.7673760395122),(106.667032331859,10.7676338521733),(106.6671413386,10.7676893154858),(106.667371048786,10.7678061934666),(106.667552760053,10.7678987010209),(106.667801848625,10.7680278028917),(106.667817742281,10.7680340673957),(106.667834579682,10.7680369577679),(106.66785165264,10.7680363524383),(106.667868243061,10.7680322768672),(106.667878683314,10.7680285412847),(106.667885469819,10.7680268413536),(106.667892390269,10.7680258148018),(106.667899378015,10.7680254715159),(106.667906365761,10.7680258148018),(106.667913286211,10.7680268413536),(106.667920072716,10.7680285412847),(106.667926659921,10.7680308982244),(106.667932984386,10.7680338894736),(106.667938985204,10.7680374862253),(106.667944604583,10.7680416538412),(106.667949788405,10.7680463521828),(106.667954486747,10.7680515360051),(106.667958654362,10.7680571553826),(106.667962251113,10.7680631561994),(106.667965242363,10.7680694806664),(106.667967599303,10.7680760678724),(106.667969299234,10.7680828543774),(106.667970926246,10.7680938227996),(106.667974657027,10.7681089916695),(106.667981154238,10.7681231972879),(106.667990189396,10.7681359400994),(106.668001444773,10.7681467719897),(106.668014524559,10.7681553120441),(106.668198488147,10.7682521458591),(106.669562015793,10.7689901124345),(106.669614757162,10.7690820717448),(106.669623023723,10.7690939566151),(106.669633223154,10.7691042307472),(106.669645047385,10.7691125838155),(106.670748051536,10.7697559307954),(106.670751419717,10.7697577924329),(106.671035494073,10.7699063431327),(106.671270162713,10.7700364834325),(106.67127192876,10.7700374352053),(106.671437929267,10.7701243344783),(106.671665917937,10.7702517637461),(106.67166656035,10.7702521191025),(106.671943689514,10.7704038245574),(106.671943806749,10.7704038886117),(106.6722776446,10.7705859421916),(106.672278295949,10.7705862936499),(106.673020324076,10.7709824352208),(106.673433726727,10.7712057751884),(106.673694081332,10.7713489702214),(106.673977066657,10.7715146655761),(106.674254247937,10.7716778144336),(106.67440928634,10.7717698954974),(106.674658478275,10.7719268836667),(106.674658802254,10.7719270867325),(106.6748919449,10.7720724734391),(106.675071660589,10.7721853602936),(106.675350447469,10.7723606751059),(106.675350748696,10.7723608636368),(106.6756252856,10.7725318758852),(106.675888735092,10.7726957126602),(106.676114500069,10.7728361211927),(106.676379504941,10.7730007692002),(106.67661713771,10.7731502653527),(106.676617572241,10.773150536857),(106.676852995814,10.7732966297465),(106.677284352687,10.7735807849214),(106.677738143311,10.7738851794554),(106.677752655777,10.7738929549383),(106.677768414072,10.773897724206),(106.677784802596,10.7738993009456),(106.677801181124,10.7738976235612),(106.677816909825,10.7738927575805),(106.677831374252,10.7738848930944),(106.677844009349,10.7738743373313),(106.677920079221,10.7737967983562),(106.678239245717,10.7735243703649),(106.67839926068,10.7733892116467),(106.678400691571,10.7733879749217),(106.678515896101,10.7732860955802),(106.678557979259,10.7732504310319),(106.67855930664,10.7732492818517),(106.679033975331,10.7728295048433),(106.679053201911,10.772844898411),(106.679632133733,10.7733262832973),(106.679771732358,10.7734524450384),(106.679773325229,10.7734538481348),(106.680011463819,10.7736582857586),(106.680175801881,10.7738018862846),(106.680176891116,10.7738028216402),(106.680320149367,10.773923712053),(106.680672123374,10.7742204563391),(106.68094213423,10.7744504786771),(106.68094233625,10.7744506502241),(106.68124725775,10.7747087432576),(106.681247329066,10.7747088035527),(106.681470746982,10.7748974804345),(106.681471338135,10.7748979749973),(106.681840030697,10.7752035373868),(106.682304929691,10.7756040772245),(106.682308650112,10.7756071005185),(106.682312917236,10.7756103687835),(106.682359764439,10.7756490693986),(106.682640114944,10.7758996628849),(106.682644070655,10.7759029839554),(106.682711710544,10.7759562859055),(106.682806505954,10.7760368956153),(106.68280745353,10.776037689352),(106.683169164535,10.7763361378178),(106.68363265876,10.7767252395911),(106.683677875719,10.7767650291442),(106.683797775698,10.77688614766),(106.684138558845,10.7772306328105),(106.68414063031,10.7772326552454),(106.684827531639,10.777880369263),(106.685228619785,10.7782605077038),(106.685228896163,10.7782607684525),(106.686025996525,10.7790093622583),(106.686026813787,10.7790101368229),(106.68658269265,10.7795369738106),(106.687194479537,10.7801158277128),(106.688401155505,10.7812670656457),(106.688401571342,10.7812674596561),(106.689622367701,10.7824162362891),(106.690002723257,10.7827815572149),(106.690002908997,10.7827817350625),(106.690359062158,10.7831217027417),(106.690359638585,10.7831222477508),(106.690747557266,10.7834855403784),(106.691628272565,10.7843952548301),(106.692179613338,10.7849709155958),(106.692179802225,10.7849711121697),(106.692743910048,10.7855562574979),(106.693288875836,10.7861225208133),(106.693601234729,10.7864484801726),(106.69220838651,10.7875617536129),(106.692196691453,10.787573150248),(106.692187444486,10.7875866094924),(106.692181000965,10.7876016141149),(106.692177608512,10.7876175874962),(106.692177397496,10.7876339157883),(106.692180376026,10.7876499715041),(106.692186429639,10.7876651376314),(106.692195325699,10.7876788313445),(106.692206722334,10.7876905264015),(106.692220181578,10.7876997733682),(106.692235186201,10.7877062168886),(106.692251159582,10.787709609342),(106.692267487874,10.7877098203582),(106.69228354359,10.7877068418281),(106.692298709717,10.7877007882148),(106.69231240343,10.7876918921553),(106.693776442708,10.7865217172423),(106.693788736175,10.7865096022178),(106.693798269005,10.7864952137411),(106.693804631934,10.7864791695437),(106.693807551784,10.7864621584413),(106.693806903199,10.7864449107613),(106.693802714026,10.7864281669878),(106.693795164114,10.786412645971),(106.693784577601,10.7863990140651),(106.69340910087,10.7860071886444),(106.69340897739,10.7860070600637),(106.692863924954,10.7854407067139),(106.69229983717,10.7848555821281),(106.691748435669,10.7842798579551),(106.691748124777,10.7842795350934),(106.690865834778,10.7833681940925),(106.690862927107,10.7833653342196),(106.690473809086,10.7830009183885),(106.690118035849,10.7826613133679),(106.689737465891,10.7822957865149),(106.689736848623,10.7822951996834),(106.688515950726,10.7811463275029),(106.687309357068,10.7799951680976),(106.687309106711,10.779994930232),(106.686697270266,10.7794160294802),(106.686141416688,10.7788892164565),(106.686140461741,10.7788883114),(106.686140185762,10.7788880510296),(106.6853430856,10.7781394574112),(106.684942058447,10.7777593767781),(106.684941904463,10.7777592312084),(106.684255979358,10.7771124377212),(106.683916204215,10.776768971525),(106.683794256559,10.7766457845149),(106.68379008676,10.7766418525893),(106.683741989497,10.7765995284558),(106.683740519326,10.7765982647987),(106.683276011394,10.7762083120217),(106.683275466929,10.7762078588774),(106.68291395946,10.77590957835),(106.682818451152,10.775828362424),(106.682816046951,10.7758263940715),(106.682749215964,10.7757737295564),(106.682469581984,10.775523776542),(106.682467121137,10.7755216616573),(106.682417839663,10.775480950083),(106.68241543796,10.7754790393628),(106.682411856108,10.7754762959601),(106.681948170223,10.775076801292),(106.681946953215,10.7750757728772),(106.681577943952,10.7747699480145),(106.681354856141,10.7745815499075),(106.681050071432,10.7743235726569),(106.680779998801,10.774093497693),(106.680779672798,10.7740932214111),(106.680427578845,10.7737963760106),(106.680284883706,10.7736759607876),(106.680120811518,10.7735325925854),(106.680120259999,10.7735321149047),(106.679882649978,10.7733281310479),(106.679742564868,10.7732015296478),(106.67973997054,10.7731992804165),(106.679159125009,10.772716304271),(106.679157929246,10.7727153285815),(106.679083371982,10.7726556350576),(106.679069423592,10.7726465921904),(106.679053957365,10.7726404990091),(106.679037589221,10.7726375981655),(106.679020970997,10.7726380051815),(106.679004764489,10.7726417038483),(106.678989615098,10.7726485468719),(106.678976126125,10.772658261739),(106.678449597495,10.7731239014943),(106.678407514754,10.773159565689),(106.678406188192,10.7731607141448),(106.678291034854,10.7732625482153),(106.678131577851,10.7733972356454),(106.678131249559,10.7733975143985),(106.677809116892,10.7736724741964),(106.677803734254,10.7736774962862),(106.67777351642,10.773708297704),(106.677376870851,10.7734422350384),(106.677376291861,10.7734418501559),(106.676943701895,10.7731568826838),(106.676941799819,10.7731556663352),(106.676705634648,10.7730091132449),(106.676468020922,10.7728596290723),(106.676467624617,10.7728593813034),(106.676202468827,10.7726946395397),(106.675976718772,10.7725542402878),(106.675713344944,10.7723904505946),(106.675438984881,10.7722195485022),(106.675160330528,10.7720443170291),(106.674980445983,10.7719313240966),(106.674980215342,10.7719311797465),(106.674747119479,10.7717858222138),(106.674497164595,10.7716283533947),(106.674495300219,10.7716272127471),(106.674339180867,10.7715344896819),(106.674338897981,10.771534322423),(106.674061493048,10.7713710419232),(106.674061328848,10.7713709455279),(106.673777295695,10.7712046366425),(106.673775349509,10.7712035319333),(106.673513740027,10.7710596467179),(106.673513190173,10.7710593469847),(106.673099330442,10.7708357600807),(106.673098966779,10.7708355647753),(106.672357083034,10.7704395002842),(106.672023628724,10.7702576558632),(106.671746880137,10.7701061587426),(106.671518215262,10.7699783515251),(106.671516207112,10.7699772649622),(106.671350083838,10.7698903014222),(106.671115399209,10.7697601522552),(106.671113600766,10.7697591835329),(106.670830326847,10.7696110514048),(106.66974820551,10.7689798847013),(106.66969475177,10.7688866833063),(106.669685913661,10.7688741199651),(106.669674918986,10.7688633930448),(106.669662141606,10.7688548673033),(106.668277363011,10.7681053993183),(106.668276514094,10.7681049461882),(106.668126503268,10.7680259842551),(106.668125839186,10.7680237950692),(106.66812072496,10.7680095017658),(106.668117596648,10.7680019493532),(106.66811110606,10.7679882261576),(106.668107252546,10.7679810167398),(106.668099448104,10.7679679958141),(106.668094906497,10.767961198818),(106.668085863361,10.7679490055608),(106.668080677403,10.7679426864524),(106.668070482664,10.7679314382913),(106.668064702296,10.7679256579236),(106.668053454135,10.7679154631847),(106.668047135024,10.7679102772246),(106.668034941766,10.7679012340887),(106.668028144776,10.7678966924853),(106.668015123851,10.7678888880428),(106.668007914429,10.7678850345264),(106.667994191233,10.7678785439383),(106.667986638821,10.7678754156266),(106.667972345518,10.7678703014008),(106.667964522841,10.7678679284177),(106.667949797082,10.7678642398071),(106.667941779481,10.7678626450072),(106.667926763083,10.767860417535),(106.667918627772,10.7678596162768),(106.667903465352,10.7678588713949),(106.667895290678,10.7678588713949),(106.667880128258,10.7678596162768),(106.667871992947,10.767860417535),(106.667856976549,10.7678626450072),(106.667848958948,10.7678642398071),(106.667848526162,10.7678643482145),(106.667629153721,10.7677506481269),(106.667628614008,10.7677503708842),(106.66744662399,10.7676577214203),(106.667216888626,10.7675408306262),(106.667161868227,10.7675128359024),(106.667012119458,10.7674366427911),(106.666659357657,10.7672571553777),(106.666673753979,10.7671954479766),(106.667048293768,10.7672739882109),(106.667012119458,10.7674366427911)]);