#! /usr/bin/env julia

using Benchmark
using PolygonClipping
using DataFrames

function intersection1()
    polya = Polygon()
    push!(polya, Vertex(0.38717397323666614,0.9175286859623484))
    push!(polya, Vertex(0.22863911382759805,0.97369797312849))
    push!(polya, Vertex(0.411735284885411,0.67925592862104))
    push!(polya, Vertex(0.4760881945244875,0.6150149154240558))
    push!(polya, Vertex(0.05897662471214904,0.8393947489758318))
    push!(polya, Vertex(0.1138425905192968,0.4935408034874309))
    push!(polya, Vertex(0.5369414505688628,0.20213738997953312))
    push!(polya, Vertex(0.8894594154609499,0.9924712388095045))
    push!(polya, Vertex(0.9256610367848219,0.9190955722799556))
    push!(polya, Vertex(0.6895872059237731,0.43384802891551))
    push!(polya, Vertex(0.9087449635347744,0.47063971708226404))
    push!(polya, Vertex(0.9757793404848136,0.7322250783012572))
    push!(polya, Vertex(0.12339214488107642,0.11118441062092432))
    push!(polya, Vertex(0.6140766278925023,0.7892323008875815))
    push!(polya, Vertex(0.9080611442010653,0.8482511305518234))
    push!(polya, Vertex(0.10274769769723902,0.38869064624120186))
    push!(polya, Vertex(0.6082870387345407,0.9944088302986258))
    push!(polya, Vertex(0.3641405100568089,0.6359528425953462))
    push!(polya, Vertex(0.6835875991611398,0.6110124950747555))
    push!(polya, Vertex(0.7131748261757693,0.8537241667688524))
    push!(polya, Vertex(0.47313568651228555,0.84090661977734))
    push!(polya, Vertex(0.6122874995061984,0.4397916059818694))
    push!(polya, Vertex(0.9378622844157258,0.6928400362996152))
    push!(polya, Vertex(0.37988141528846486,0.3924066347636528))
    push!(polya, Vertex(0.37612785711290586,0.1262573371450586))
    push!(polya, Vertex(0.2855066522487957,0.34807448520950257))
    push!(polya, Vertex(0.3226665347220963,0.7530552496358307))
    push!(polya, Vertex(0.6260310508679137,0.9624257683012829))
    push!(polya, Vertex(0.5090596161323337,0.6293681446635448))
    push!(polya, Vertex(0.15373073711802787,0.699604530492266))
    push!(polya, Vertex(0.5916127221754168,0.5134368361443975))
    push!(polya, Vertex(0.5476501761702322,0.12025320226897085))
    push!(polya, Vertex(0.7364982683875068,0.6573742771739695))
    push!(polya, Vertex(0.3564770108133659,0.6190436269899608))
    push!(polya, Vertex(0.1942877121254134,0.7460859067795749))
    push!(polya, Vertex(0.48141346512614325,0.33226336281429103))
    push!(polya, Vertex(0.029892986776481,0.2174442631248703))
    push!(polya, Vertex(0.6110877370822994,0.6597597834785822))
    push!(polya, Vertex(0.6492858228562519,0.6866871593335842))
    push!(polya, Vertex(0.7810487364244136,0.6630376297746976))
    push!(polya, Vertex(0.7517037010056422,0.5481097354087443))
    push!(polya, Vertex(0.32595306165531923,0.827698654052716))
    push!(polya, Vertex(0.0946562934579609,0.06511398366340826))
    push!(polya, Vertex(0.4016822086257372,0.2633273020831326))
    push!(polya, Vertex(0.14840039175150355,0.26329155785679026))
    push!(polya, Vertex(0.660892803459532,0.14824001535942988))
    push!(polya, Vertex(0.7270462350880156,0.9616603642178803))
    push!(polya, Vertex(0.20565290637531142,0.45438554764185524))
    push!(polya, Vertex(0.01226767618359137,0.4346542090688914))
    push!(polya, Vertex(0.8443656165997122,0.6218309213080848))
    push!(polya, Vertex(0.36543895623038214,0.575693893269152))
    push!(polya, Vertex(0.2057450566974688,0.41382632848748657))
    push!(polya, Vertex(0.6578438918849019,0.018731630167831304))
    push!(polya, Vertex(0.9251751209532304,0.27030612773533713))
    push!(polya, Vertex(0.3698114785252209,0.08714925463572976))
    push!(polya, Vertex(0.8310050243916558,0.19245735232136196))
    push!(polya, Vertex(0.09311535434229778,0.5708872306538855))
    push!(polya, Vertex(0.2275489167423912,0.10333866005215286))
    push!(polya, Vertex(0.5691689464441063,0.07917751066510315))
    push!(polya, Vertex(0.9441999955891076,0.08863956272995877))
    push!(polya, Vertex(0.06944908047821619,0.9580858557547942))
    push!(polya, Vertex(0.13317769494718235,0.30579396918400126))
    push!(polya, Vertex(0.8916959800005415,0.49287891827534636))
    push!(polya, Vertex(0.05313909148370777,0.568467861010775))
    push!(polya, Vertex(0.8839793776888005,0.3922614940305833))
    push!(polya, Vertex(0.29947054407245455,0.13067176985025442))
    push!(polya, Vertex(0.6412436143042177,0.05964508351161513))
    push!(polya, Vertex(0.9907882336943714,0.18490674849468958))
    push!(polya, Vertex(0.3164116203917908,0.6915262366567434))
    push!(polya, Vertex(0.670340857966748,0.2494086348537079))
    push!(polya, Vertex(0.9516002726498964,0.5877410895223771))
    push!(polya, Vertex(0.37859268972845683,0.5498068716998208))
    push!(polya, Vertex(0.4585342971405306,0.009925253379711174))
    push!(polya, Vertex(0.825358328321574,0.02436860679566233))
    push!(polya, Vertex(0.2944481729419708,0.35565821826071664))
    push!(polya, Vertex(0.9479518990808133,0.022876736181673296))
    push!(polya, Vertex(0.32890511871298855,0.5903117675591205))
    push!(polya, Vertex(0.13434078534002403,0.8043761349960912))
    push!(polya, Vertex(0.36305742044837475,0.8074864926312384))
    push!(polya, Vertex(0.37006152533035075,0.810010072925335))
    push!(polya, Vertex(0.30245125983035126,0.531982907605898))
    push!(polya, Vertex(0.6061475382439927,0.3591482019894219))
    push!(polya, Vertex(0.4318224796352559,0.6906958337163789))
    push!(polya, Vertex(0.5484989647598377,0.5979198296052988))
    push!(polya, Vertex(0.3283124258298571,0.550335718203822))
    push!(polya, Vertex(0.731217871868109,0.694746265475011))
    push!(polya, Vertex(0.33503956272666824,0.7135843285873211))
    push!(polya, Vertex(0.4458879602562089,0.8271969180995566))
    push!(polya, Vertex(0.7868344276375905,0.9746067374413514))
    push!(polya, Vertex(0.12173043080454882,0.8576124078521512))
    push!(polya, Vertex(0.5907417299265332,0.6830068306826631))
    push!(polya, Vertex(0.2927496535507432,0.9373149390911051))
    push!(polya, Vertex(0.8550155012852447,0.9303058527010857))
    push!(polya, Vertex(0.30123570126170174,0.5735420574883527))
    push!(polya, Vertex(0.8967395912778122,0.018901254929095))
    push!(polya, Vertex(0.6950306441092162,0.32167381094779923))
    push!(polya, Vertex(0.8612213482620878,0.8954192932054237))
    push!(polya, Vertex(0.755007334348081,0.6441892302099188))
    push!(polya, Vertex(0.5129282217003186,0.6163889826956628))
    push!(polya, Vertex(0.5956877205258515,0.207078358084255))


    polyb = Polygon()
    push!(polyb, Vertex(0.45922312991074965,0.8634708765893035))
    push!(polyb, Vertex(0.3432506505322517,0.7610444169585342))
    push!(polyb, Vertex(0.7745733205429546,0.6432459662157686))
    push!(polyb, Vertex(0.6626248852675782,0.3756202023478652))
    push!(polyb, Vertex(0.11391157584189071,0.1175951719793249))
    push!(polyb, Vertex(0.47290352518324696,0.2521388807609466))
    push!(polyb, Vertex(0.975042508309663,0.31523396145745664))
    push!(polyb, Vertex(0.6645972006883816,0.39747175992018424))
    push!(polyb, Vertex(0.4033012612046003,0.6697684324194775))
    push!(polyb, Vertex(0.7478015750621811,0.26064185515728866))
    push!(polyb, Vertex(0.5408637693590228,0.6848821125508033))
    push!(polyb, Vertex(0.20715997569592037,0.6570627238206466))
    push!(polyb, Vertex(0.23093726175916385,0.8287208212251969))
    push!(polyb, Vertex(0.6024572633721841,0.8204147304496012))
    push!(polyb, Vertex(0.7025482053945702,0.6316840227377571))
    push!(polyb, Vertex(0.15103563731064762,0.5804190220758261))
    push!(polyb, Vertex(0.9887757894210867,0.9772711166739021))
    push!(polyb, Vertex(0.6251517614575921,0.38220971314131513))
    push!(polyb, Vertex(0.23163449016202686,0.7955298748003772))
    push!(polyb, Vertex(0.008749232698707532,0.7038966642300737))
    push!(polyb, Vertex(0.36552065983260706,0.007266458811545862))
    push!(polyb, Vertex(0.8431274574795424,0.975174390993478))
    push!(polyb, Vertex(0.9674040599289924,0.7546437140411728))
    push!(polyb, Vertex(0.6299023469869027,0.5941113636172484))
    push!(polyb, Vertex(0.3651692839350955,0.9412811548927036))
    push!(polyb, Vertex(0.46700978293718576,0.6372087264115178))
    push!(polyb, Vertex(0.09441852929672212,0.712398255967287))
    push!(polyb, Vertex(0.6594117537641844,0.8556959981933909))
    push!(polyb, Vertex(0.41749612512996004,0.7726528031089717))
    push!(polyb, Vertex(0.8230135867808732,0.9270969466572365))
    push!(polyb, Vertex(0.04389833237303109,0.5609640399741183))
    push!(polyb, Vertex(0.4125116220480387,0.5160396701522856))
    push!(polyb, Vertex(0.8836833851491399,0.7590081568215858))
    push!(polyb, Vertex(0.5428845419686217,0.5433520734475961))
    push!(polyb, Vertex(0.5473279623543394,0.48707911841886875))
    push!(polyb, Vertex(0.504975646406884,0.6269770507544459))
    push!(polyb, Vertex(0.6692031351652192,0.8269983773582317))
    push!(polyb, Vertex(0.5665824658182701,0.28971587253261544))
    push!(polyb, Vertex(0.6979596641936274,0.6963299758066004))
    push!(polyb, Vertex(0.41393013487701724,0.02515192656365972))
    push!(polyb, Vertex(0.4146094682050434,0.7760774006253788))
    push!(polyb, Vertex(0.916841516397837,0.3812664317124159))
    push!(polyb, Vertex(0.5694746452391368,0.021859026116122227))
    push!(polyb, Vertex(0.5811595135265466,0.2757689306043134))
    push!(polyb, Vertex(0.4894054388068505,0.35643214512810095))
    push!(polyb, Vertex(0.5595554636066462,0.5848619132982462))
    push!(polyb, Vertex(0.055595115965147324,0.08067075687112912))
    push!(polyb, Vertex(0.8201820592938383,0.5690753436287503))
    push!(polyb, Vertex(0.1630668008610887,0.21593074025144188))
    push!(polyb, Vertex(0.3818523211281113,0.49892970559056926))
    push!(polyb, Vertex(0.5879509816156174,0.7091657227073489))
    push!(polyb, Vertex(0.7906807122153934,0.2210363105879154))
    push!(polyb, Vertex(0.5593694790678512,0.4640752428580712))
    push!(polyb, Vertex(0.6012166172350997,0.31394337995190624))
    push!(polyb, Vertex(0.5626052673349125,0.8689869237375565))
    push!(polyb, Vertex(0.9062078706328689,0.5926285281119317))
    push!(polyb, Vertex(0.2116818069931432,0.7097461450894131))
    push!(polyb, Vertex(0.23462798149426778,0.6347647741466378))
    push!(polyb, Vertex(0.8333332026965838,0.4044637675513083))
    push!(polyb, Vertex(0.38151281356770417,0.5842041828199334))
    push!(polyb, Vertex(0.15019329095984024,0.4211489213025983))
    push!(polyb, Vertex(0.8360328648037809,0.023292893005907978))
    push!(polyb, Vertex(0.31874416444804177,0.11721397482037488))
    push!(polyb, Vertex(0.39155608346680637,0.0016294336268325438))
    push!(polyb, Vertex(0.49241666713123067,0.827810647049537))
    push!(polyb, Vertex(0.28852655549271455,0.5134511690270223))
    push!(polyb, Vertex(0.6320220046603813,0.8851410292212929))
    push!(polyb, Vertex(0.9740042546342045,0.18256471264167917))
    push!(polyb, Vertex(0.5780722916281602,0.20879214268020507))
    push!(polyb, Vertex(0.6201054810476829,0.09914904930053448))
    push!(polyb, Vertex(0.6219009431337508,0.1516866613709651))
    push!(polyb, Vertex(0.34716243679494574,0.006595091110359164))
    push!(polyb, Vertex(0.6890583759094768,0.3440450342993846))
    push!(polyb, Vertex(0.9778512374676402,0.5744641432773667))
    push!(polyb, Vertex(0.0033568324875912214,0.6148369261343873))
    push!(polyb, Vertex(0.34832869925563625,0.40428761834628935))
    push!(polyb, Vertex(0.2907179321707041,0.5340135773079302))
    push!(polyb, Vertex(0.12479109273224198,0.8885089407774147))
    push!(polyb, Vertex(0.9876184891473105,0.5950350229751693))
    push!(polyb, Vertex(0.2006836897721096,0.44523290012385375))
    push!(polyb, Vertex(0.24482339423302024,0.11468063465242362))
    push!(polyb, Vertex(0.28181652810828073,0.2035021093756293))
    push!(polyb, Vertex(0.06733186631795296,0.45001635767596593))
    push!(polyb, Vertex(0.21527661471388138,0.3520300299617407))
    push!(polyb, Vertex(0.5927741449744783,0.8525914294328816))
    push!(polyb, Vertex(0.6258613640600956,0.43656539966226804))
    push!(polyb, Vertex(0.5910220014222105,0.3521522088352207))
    push!(polyb, Vertex(0.6106632086832191,0.5346375695717998))
    push!(polyb, Vertex(0.34566121714575027,0.5845480914914436))
    push!(polyb, Vertex(0.8691587357382462,0.32313446735351126))
    push!(polyb, Vertex(0.3861919843487014,0.12972240893508835))
    push!(polyb, Vertex(0.37769973424020375,0.051694328774281484))
    push!(polyb, Vertex(0.4552128830552533,0.16435305304622982))
    push!(polyb, Vertex(0.16131619574158784,0.3971212509168853))
    push!(polyb, Vertex(0.24572158657159515,0.8610180990083223))
    push!(polyb, Vertex(0.7284331633547654,0.7187589226042599))
    push!(polyb, Vertex(0.03504548735067359,0.6029694383465394))
    push!(polyb, Vertex(0.9995434477131571,0.3499686099551058))
    push!(polyb, Vertex(0.8042033719306321,0.17999362049770196))
    push!(polyb, Vertex(0.7467041955244049,0.3309946873417935))

    results = intersection(polya, polyb)
end

outfile = Pkg.dir("PolygonClipping")*"/perf/intersection1_benchmarks.csv"

out = benchmark(intersection1, "Clipping", "Intersection 1", 10)

if isfile(outfile)
    previous = readtable(outfile)
    out = vcat(previous, out)
end
writetable(outfile, out)

