# How to check which geometric shape a geom::Source is?

**URL:** <https://discourse.libcinder.org/t/how-to-check-which-geometric-shape-a-geom-source-is/1630>\
**Category:** Using Cinder\
**Created:** [March 17, 2020, 12:34am UTC](https://discourse.libcinder.org/t/how-to-check-which-geometric-shape-a-geom-source-is/1630 "2020-03-17T00:34:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![morphogencc](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@morphogencc](https://discourse.libcinder.org/u/morphogencc)\
**Post date:** [March 17, 2020, 12:34am UTC](https://discourse.libcinder.org/t/how-to-check-which-geometric-shape-a-geom-source-is/1630/1 "2020-03-17T00:34:04Z")

</div>

A pretty simple question – I’d like a function that takes a `geom::Source` and then can tell me which type the function takes in (`geom::Sphere`, `geom::Cube`, `geom::Cylinder`, etc.). However, I’m not sure of the right way to do this!

```
void function(ci::geom::Source& source) {
    if source.type() is ci::geom::Sphere()
        then print("This is a sphere")
    else if source.type() is ci::geom::Cube()
        then print("This is a cube")
}

```

It looks like there’s some primitive enums in `GeomIo.h`, but they’re all OpenGL primitives like triangle strips and fans, not actual geometric primitives.

If there was a clever way to overload the `==` operator that’d work too. I basically just want to have a single function that can take any functioning source, and then perform different behaviors based on which geometric shape is input.

Any suggestions? This feels like it should be pretty simple, but I haven’t figured out a good way to do it…

thanks!

---

<div class="post-metadata">

**Author:** ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)\
**Post date:** [March 17, 2020, 1:37am UTC](https://discourse.libcinder.org/t/how-to-check-which-geometric-shape-a-geom-source-is/1630/2 "2020-03-17T01:37:42Z")

</div>

You’re probably overthinking it. Just write an overload for each primitive and it can call a common function with any shared functionality. You could probably use RTTI if you absolutely had to, but thar be dragons.

```cpp
void iDontRecommendDoingThis ( const ci::geom::Source& source )
{
    if ( typeid(source) == typeid(geom::Sphere) )
    {
        std::cout << "Sphere\n";
        
    }else if ( typeid(source) == typeid(geom::Cube) )
    {
        std::cout << "Cube\n";
    }
}

void YourApp::setup()
{
    iDontRecommendDoingThis( geom::Sphere() );
    iDontRecommendDoingThis( geom::Cube() );
}

```

---

<div class="post-metadata">

**Author:** ![morphogencc](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@morphogencc](https://discourse.libcinder.org/u/morphogencc)\
**Post date:** [March 17, 2020, 2:38am UTC](https://discourse.libcinder.org/t/how-to-check-which-geometric-shape-a-geom-source-is/1630/3 "2020-03-17T02:38:17Z")

</div>

I guess what function to use is where I’m stuck here. I didn’t think about using `typeid()` – wasn’t sure if there were other, better options as well built-in to Cinder.

---

<div class="post-metadata">

**Author:** ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)\
**Post date:** [March 17, 2020, 11:07am UTC](https://discourse.libcinder.org/t/how-to-check-which-geometric-shape-a-geom-source-is/1630/5 "2020-03-17T11:07:15Z")

</div>

Well what exactly are you trying to do? Maybe work backwards and see if a solution shakes itself out.
