# How are PShape contours stored?

**URL:** <https://discourse.processing.org/t/how-are-pshape-contours-stored/26997>\
**Category:** Coding Questions\
**Created:** [January 12, 2021, 7:12pm UTC](https://discourse.processing.org/t/how-are-pshape-contours-stored/26997 "2021-01-12T19:12:36Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![behreajj](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@behreajj](https://discourse.processing.org/u/behreajj)\
**Post date:** [January 12, 2021, 7:45pm UTC](https://discourse.processing.org/t/how-are-pshape-contours-stored/26997/2 "2021-01-12T19:45:02Z")

</div>

Hi @micycle ,

The vertex codes will not match the number of vertices. For a cubic Bezier vertex, there will be 3 pairs (6 floats) in vertices per command; for a quadratic Bezier vertex 2 pairs (4 floats) in vertices per command. That’s why [this happens](https://discourse.processing.org/t/beziervertex-draws-straight-lines-not-a-curved-line/3139/5) when a shape that should be a `PATH` `family` is assigned the `GEOMETRY` family instead.

[beginContour](https://github.com/processing/processing/blob/94144be998354ecf7a06d5301b7b4fab72df724c/core/src/processing/core/PShape.java#L654) inserts a `BREAK` command into the vertex commands list, so maybe you could use that in conjunction with a [vertex winding algorithm](https://gamedev.stackexchange.com/questions/30537/how-to-determine-counter-clockwise-vertex-winding) to get what you’re looking for.

(Also, beware of implementation differences between a super-class `PShape` and its sub-classes, for example `PShapeOpenGL`).

EDIT: When I wanted to convert between a PShape and my own 2D curve class, I used this [routine](https://github.com/behreajj/CamZup/blob/bd01c7a57370ea16956c657f9c59b4704370fab7/src/camzup/pfriendly/Convert.java#L1356) to loop through the commands. The code does _not_ address contours but it may offer a basic outline.

Hope that helps some, Jeremy

---

_[View the full topic](https://discourse.processing.org/t/how-are-pshape-contours-stored/26997)._
