this is my csv
shape,x,y
circle,9.040911354898284,0.0
circle,9.994050280428253,0.6287723479093885
circle,10.519468151421421,1.3289178731526987
circle,9.14061449831813,1.7436654701011292
circle,9.18178539073531,2.3574817986027647
circle,8.98047312608742,2.917932600156103
circle,8.439977172954322,3.341623356386025
circle,9.36666738192862,4.4076191039314825
circle,9.213236646348774,5.065019708083154
circle,8.314707875905958,5.276674071492235
circle,7.349708608886506,5.339875872803166
circle,8.009770731399206,6.626258619758
circle,7.396817665471883,6.94607413201312
circle,7.137854431368056,7.60104294139
circle,6.1231693666004,7.401640290609014
circle,5.463173684188578,7.519413487311049
circle,5.351836166177173,8.433144385756512
circle,4.833327634052153,8.791790328237841
circle,4.3771364107548925,9.301888361519206
circle,3.8834955573084997,9.80859012501075
circle,3.265474550041969,10.050097263728935
circle,2.2993452692744207,8.955358558523326
circle,2.0171344421046475,10.574189053298864
circle,1.149212176775009,9.096951088580381
circle,0.6294675262189372,10.005099823243832
circle,6.707947802142274e-16,10.95491011255263
circle,-0.6633541286342488,10.543711944940258
circle,-1.19222082428471,9.437399589465326
circle,-1.8393175750230035,9.642040392238494
circle,-2.332881506148971,9.08597357747171
circle,-2.7951966671383333,8.602730765618794
circle,-3.769662722664303,9.52108120390699
circle,-4.4012735127069815,9.353182314153917
circle,-5.2267374935029585,9.507400205992644
circle,-5.404457689687919,8.516062638816853
circle,-5.559347801582188,7.65178580370889
circle,-5.822480209266422,7.03816953737259
circle,-6.66251520163403,7.094858074259963
circle,-7.628798711527528,7.163918834424301
circle,-7.214758609315008,5.968567394449701
circle,-7.683041000427903,5.582056031219728
circle,-8.536953795535753,5.417715620889754
circle,-9.330451767045744,5.12945926599365
circle,-9.083707645079773,4.2744683587492
circle,-9.899002028353296,3.9192921621705263
circle,-10.233519201586015,3.325071950372943
circle,-10.028068281645975,2.5747703135144695
circle,-9.153198881891791,1.7460660696564365
circle,-10.243707678780794,1.2940812240440065
circle,-10.041764322384193,0.6317742609823752
circle,-9.270466832776068,1.1353047533360913e-15
circle,-10.574032738198374,-0.6652617512529494
circle,-10.250449693126914,-1.2949329385258237
circle,-9.419483783361839,-1.7968626313086162
circle,-9.921270506762939,-2.547349305540122
circle,-10.457733400152579,-3.3979235596622925
circle,-9.327141935864036,-3.6928767344403703
circle,-8.886295903130518,-4.181573444295983
circle,-8.018032333471606,-4.407950576758069
circle,-8.60307082690098,-5.459674764890451
circle,-8.386509948220043,-6.093156138921891
circle,-7.1291713431823664,-5.897763450245683
circle,-7.2421860569182135,-6.800865386206116
circle,-6.572787308383094,-6.999307572887511
circle,-6.737526526481658,-8.144270525892857
circle,-6.361914382300973,-8.75642393538459
circle,-4.859070371954989,-7.656669740045157
circle,-4.986250075129354,-9.069955215915005
circle,-4.433185813231312,-9.420999404822433
circle,-4.02906555688317,-10.176257974569344
circle,-3.175993199353858,-9.774701983831926
circle,-2.627615483436806,-10.233886629618585
circle,-1.9040466596204544,-9.981362136735736
circle,-1.3201130545027435,-10.44977083510228
circle,-0.5725869066652535,-9.101008265001013
circle,-1.7856286074247384e-15,-9.720509394588777
circle,0.6816352030934381,-10.834281302725978
circle,1.2380022894002873,-9.799797201791952
circle,1.943805093129933,-10.189783144089924
circle,2.6136258273278465,-10.179400516445266
circle,2.9489084822911678,-9.075807088583996
circle,3.6290608510284517,-9.165961413158161
circle,3.9467575489447473,-8.387286724732391
circle,4.493522077827191,-8.173686316076038
circle,5.314671552824818,-8.37458232579997
circle,6.135246886433261,-8.444442892113805
circle,5.954367086911944,-7.197593386189914
circle,6.251284464162244,-6.656941817435525
circle,6.637572668172245,-6.2330956223195315
circle,8.22351957240467,-6.803087039405952
circle,7.438601822460306,-5.404460572915599
circle,8.81729690835826,-5.595626770220515
circle,8.33605595383675,-4.582785541561003
circle,9.297280908438077,-4.374968307907557
circle,9.756146057752183,-3.8627314821855587
circle,9.63417821251134,-3.130334258262872
circle,8.867324021003597,-2.276741841834205
circle,10.052173027719592,-1.9175545595038122
circle,9.97551242901594,-1.2602002848390146
circle,10.110477850720395,-0.6360973497534685
square,-5.0,-4.405809139836923
square,-4.6,-5.658308300585837
square,-4.2,-4.806501018685861
square,-3.8,-4.187056127325281
square,-3.4,-5.180165472701657
square,-3.0,-4.093119181834865
square,-2.6,-4.29144344392929
square,-2.1999999999999997,-4.688609447496885
square,-1.7999999999999998,-5.766309851602534
square,-1.4000000000000004,-4.2567393535708575
square,-1.0,-4.051786913308964
square,-0.5999999999999996,-5.457421941218315
square,-0.20000000000000018,-4.8220875966198555
square,0.20000000000000018,-4.007713863542251
square,0.6000000000000005,-4.32315871080897
square,1.0,-5.899648724862608
square,1.4000000000000004,-4.035597453564651
square,1.8000000000000007,-4.513569041591947
square,2.1999999999999993,-5.706494638546345
square,2.5999999999999996,-5.4750491929880605
square,3.0,-4.516425105721168
square,3.4000000000000004,-5.597949440215427
square,3.8000000000000007,-4.228875609466231
square,4.200000000000001,-5.470932940256626
square,4.6,-4.356736687746513
square,4.431343318617621,-5.0
square,4.060589333534174,-4.6
square,5.455208098155937,-4.2
square,5.839952002578064,-3.8
square,4.190075081010733,-3.4
square,5.514892703255661,-3.0
square,5.968861693606842,-2.6
square,4.87049182004815,-2.1999999999999997
square,4.16775370115029,-1.7999999999999998
square,4.965300045967642,-1.4000000000000004
square,5.499405614390874,-1.0
square,4.2976238336247885,-0.5999999999999996
square,4.548143939766771,-0.20000000000000018
square,4.53669020692408,0.20000000000000018
square,4.734425115997253,0.6000000000000005
square,4.245346011726386,1.0
square,4.4178775860834305,1.4000000000000004
square,4.0071367509285265,1.8000000000000007
square,4.302567868348797,2.1999999999999993
square,4.41056462088942,2.5999999999999996
square,5.0597698891427285,3.0
square,4.9252210695005285,3.4000000000000004
square,4.139818701150805,3.8000000000000007
square,5.06410307621091,4.200000000000001
square,4.760787273767774,4.6
square,5.0,4.384584235525644
square,4.6,5.1855778559883525
square,4.2,5.543203139261952
square,3.8,5.482903396315816
square,3.4,5.100291529611343
square,3.0,5.359434447642414
square,2.6,4.405506994226269
square,2.1999999999999997,4.745171884029525
square,1.7999999999999998,5.6832061117913675
square,1.4000000000000004,5.316755288450563
square,1.0,5.492704287501552
square,0.5999999999999996,4.4881893631695595
square,0.20000000000000018,5.645952915704768
square,-0.20000000000000018,4.5768157296089855
square,-0.6000000000000005,5.94504710141856
square,-1.0,4.579204317574339
square,-1.4000000000000004,4.45736803027011
square,-1.8000000000000007,4.92547915880102
square,-2.1999999999999993,5.220669956764819
square,-2.5999999999999996,4.138359254239073
square,-3.0,4.670192645264958
square,-3.4000000000000004,5.9644498481974
square,-3.8000000000000007,4.870457251944184
square,-4.200000000000001,4.0300553260981005
square,-4.6,5.5618490844124135
square,-5.9013117881649855,5.0
square,-5.357918397181317,4.6
square,-5.800431741854435,4.2
square,-5.853356227655748,3.8
square,-4.712613895246873,3.4
square,-5.914681456964058,3.0
square,-5.522913237825346,2.6
square,-4.047676006057026,2.1999999999999997
square,-5.970465087938764,1.7999999999999998
square,-5.08242821393044,1.4000000000000004
square,-4.843406146032645,1.0
square,-4.44403400813793,0.5999999999999996
square,-5.450725772663318,0.20000000000000018
square,-4.763119706420459,-0.20000000000000018
square,-5.489179621813369,-0.6000000000000005
square,-5.1198032672024,-1.0
square,-4.5273055260088775,-1.4000000000000004
square,-5.060621552277403,-1.8000000000000007
square,-4.931594500599471,-2.1999999999999993
square,-5.706973163349836,-2.5999999999999996
square,-4.0586477134282815,-3.0
square,-5.539344809156371,-3.4000000000000004
square,-4.829948117597624,-3.8000000000000007
square,-5.921587697006915,-4.200000000000001
square,-5.325394805974063,-4.6
star,9.691928125070362,-0.02994148944190005
star,9.120986909175057,0.2807330750783216
star,8.493245450563395,0.6106864620502087
star,7.938378837406874,0.9035399708340973
star,7.3966335060158155,1.1789449960755352
star,6.831969134909988,1.4868102326141868
star,6.316931776519644,1.728215220927765
star,5.690468353991332,2.047549805233295
star,5.115697743670603,2.3172978154884305
star,4.634624836646498,2.605524629075994
star,4.0532757761545275,2.9405336722915223
star,3.929410849905143,3.6487754403901667
star,3.9013602691711347,4.334197256327028
star,3.745040406677401,5.021278717201183
star,3.651752239648418,5.721006916148642
star,3.6543960722449533,6.391280746005301
star,3.495083004687771,7.065413317024836
star,3.4149645271125904,7.739952314599858
star,3.3541961378894123,8.430959386985716
star,3.232781006227542,9.113763344409142
star,3.2360274273360448,9.80558828036609
star,2.7162811315218622,9.315748014213366
star,2.2001612098090937,8.865225142490228
star,1.7881183732022385,8.437928320316487
star,1.2335508879300372,7.930315391982321
star,0.72772104771167,7.394485751416225
star,0.25713952398930606,6.934874587215198
star,-0.19078437630097628,6.471980044841792
star,-0.6747340472889234,6.045347873821304
star,-1.1506975597770306,5.512641690668262
star,-1.6393557419561158,5.056472834751245
star,-2.3557607886426037,5.189063975144947
star,-2.9406671980771146,5.210518199930884
star,-3.6134117230125513,5.3055774427856175
star,-4.2800613661425535,5.489294382140921
star,-4.952204454566015,5.555495025237077
star,-5.625328938033941,5.628730632853522
star,-6.329874360797586,5.7332476623034765
star,-7.018455020110681,5.898843173086166
star,-7.699138843625158,5.962898270913759
star,-8.376537074559174,6.098543113185549
star,-7.991335168653288,5.431304116171433
star,-7.576122047129484,4.842159487097704
star,-7.267916177901022,4.210960180029211
star,-6.841894418467499,3.6325068829005542
star,-6.45188154507905,3.0130049065461497
star,-6.062219053139473,2.425315992148379
star,-5.709758585158603,1.8491633999147472
star,-5.382213158476629,1.220738667860447
star,-4.990306373768353,0.5586904649546411
star,-4.597462543580873,0.003445025691881973
star,-4.884249177031567,-0.5836892056030184
star,-5.246866487423855,-1.1659784341359904
star,-5.575361429570332,-1.6716795501656325
star,-5.93865357611949,-2.2461714201770895
star,-6.225912573411138,-2.8432408814013277
star,-6.547754721925517,-3.4260440086406043
star,-6.909341354077054,-3.972847440375857
star,-7.194246805973351,-4.586674008364594
star,-7.615436266299783,-5.163865956302094
star,-7.857557266627085,-5.749772135078798
star,-7.2631403983337,-5.645123525921274
star,-6.6371134613475204,-5.555591849332287
star,-5.973015997657121,-5.383817829957068
star,-5.305120624971344,-5.279379033350568
star,-4.686231253370966,-5.2290439129588115
star,-4.043213763515518,-5.0638340371096024
star,-3.444252246504709,-5.000372460045084
star,-2.74890084774287,-4.831697163906329
star,-2.151534305057093,-4.748689383773352
star,-1.543191195618515,-4.63899183597147
star,-1.0662873405713047,-5.1252833062377885
star,-0.5913291298208346,-5.66763899481779
star,-0.14444322984246405,-6.1696645515465915
star,0.39775826843216233,-6.6869937221413185
star,0.8699457967312796,-7.208126456133162
star,1.2723996041839272,-7.7100319702043825
star,1.7928245764916084,-8.208431939789264
star,2.2469784742468866,-8.79914435491872
star,2.689229386519771,-9.280621027026168
star,3.19130271933642,-9.829196593842935
star,3.198652354601399,-9.045521428963792
star,3.260160542300104,-8.355142169127996
star,3.381411826513496,-7.671885130596455
star,3.4551699459788168,-7.02424593461714
star,3.5183943377554665,-6.2740409963622294
star,3.538691139956457,-5.571101992582599
star,3.577326631606425,-4.911503818934243
star,3.658740285908055,-4.116678024206102
star,3.699267661920203,-3.466158679902242
star,3.7831325829444205,-2.717427418383946
star,4.335997118220975,-2.5169213113606133
star,4.932105520902315,-2.1652642676939955
star,5.581233654152444,-1.9358511003869996
star,6.116911727568995,-1.6832197481871058
star,6.723206777549412,-1.3980406742017513
star,7.326715326621627,-1.0760894702892578
star,7.896215022281717,-0.862759770378869
star,8.467236636654635,-0.5711758797961289
star,9.037841082530484,-0.22887518486509772


#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#include "matplotlibcpp.h"  // Ensure this path is correct

namespace plt = matplotlibcpp;

// Structure to hold a point
struct Point {
    double x;
    double y;
};

// Function to read CSV and organize points by shape
std::map<std::string, std::vector<Point>> read_csv(const std::string& filename) {
    std::map<std::string, std::vector<Point>> shapes;
    std::ifstream file(filename);
    if (!file.is_open()) {
        std::cerr << "Error: Cannot open file " << filename << std::endl;
        return shapes;
    }

    std::string line;
    // Read header
    std::getline(file, line);
    while (std::getline(file, line)) {
        std::stringstream ss(line);
        std::string shape, x_str, y_str;

        std::getline(ss, shape, ',');
        std::getline(ss, x_str, ',');
        std::getline(ss, y_str, ',');

        Point p;
        try {
            p.x = std::stod(x_str);
            p.y = std::stod(y_str);
            shapes[shape].push_back(p);
        }
        catch (const std::invalid_argument& e) {
            std::cerr << "Invalid number format in CSV: " << e.what() << std::endl;
        }
    }

    file.close();
    return shapes;
}

// Function to normalize a shape: center at origin and scale to unit size
void normalize_shape(std::vector<Point>& shape) {
    double mean_x = 0.0, mean_y = 0.0;
    for (const auto& p : shape) {
        mean_x += p.x;
        mean_y += p.y;
    }
    mean_x /= shape.size();
    mean_y /= shape.size();

    // Center the shape
    for (auto& p : shape) {
        p.x -= mean_x;
        p.y -= mean_y;
    }

    // Scale to unit size
    double max_dist = 0.0;
    for (const auto& p : shape) {
        double dist = std::sqrt(p.x * p.x + p.y * p.y);
        if (dist > max_dist) max_dist = dist;
    }
    if (max_dist > 0.0) {
        for (auto& p : shape) {
            p.x /= max_dist;
            p.y /= max_dist;
        }
    }
}

// Function to plot symmetry lines (Assuming standard symmetry based on shape)
void plot_symmetry_lines(const std::string& shape) {
    if (shape == "circle") {
        // Infinite symmetry lines; skip plotting
        return;
    }
    else if (shape == "square") {
        // Two main diagonals
        plt::plot({ -1.0, 1.0 }, { -1.0, 1.0 }, "k--"); // Diagonal 1
        plt::plot({ -1.0, 1.0 }, { 1.0, -1.0 }, "k--"); // Diagonal 2
    }
    else if (shape == "star") {
        // Five symmetry lines for a 5-pointed star
        for(int i = 0; i <5; ++i){
            double angle = i * (2 * M_PI /5);
            double x = cos(angle);
            double y = sin(angle);
            plt::plot({0.0, x}, {0.0, y}, "k--");
        }
    }
    // Add more shapes and their symmetry lines as needed
}

int main() {
    // Step 1: Read the CSV file
    std::string filename = "/Users/kartik/Desktop/CLG/MINOR/new/shapes.csv";
    auto shapes = read_csv(filename);
    if (shapes.empty()) {
        std::cerr << "No shapes found. Exiting." << std::endl;
        return 1;
    }

    // Step 2: Normalize each shape
    for (auto& [shape_name, points] : shapes) {
        normalize_shape(points);
    }

    // Step 3: Plot each shape with its symmetry lines
    for (const auto& [shape_name, points] : shapes) {
        std::vector<double> xs, ys;
        for (const auto& p : points) {
            xs.push_back(p.x);
            ys.push_back(p.y);
        }

        // Plot the shape
        plt::scatter(xs, ys, 10.0, {{"label", shape_name}});

        // Plot symmetry lines
        plot_symmetry_lines(shape_name);
    }

    // Finalize plot
    plt::legend();
    plt::axis("equal");
    plt::title("Normalized Shapes with Symmetry Lines");
    plt::xlabel("X-axis");
    plt::ylabel("Y-axis");
    std::cout << "Before plotting" << std::endl;
    plt::show();
    std::cout << "After plotting" << std::endl;


    return 0;
}


now make sure to plot the csv before the regularising
then regulare and plot
and then plot the regularised and symmetry one