code: function() {
              var EPS = 1e-5;
              var errors = [];
              if (this.isSelfIntersecting(true)) {
                  errors.push("Self intersects");
              }
              var pointcount = {};
              this.sides.map(function(side) {
                  function mappoint(p) {
                      var tag = p.x + " " + p.y;
                      if (!(tag in pointcount)) pointcount[tag] = 0;
                      pointcount[tag] ++;
                  }
                  mappoint(side.vertex0.pos);
                  mappoint(side.vertex1.pos);
              });
              for (var tag in pointcount) {
                  var count = pointcount[tag];
                  if (count & 1) {
                      errors.push("Uneven number of sides (" + count + ") for point " + tag);
                  }
              }
              var area = this.area();
              if (area < EPS*EPS) {
                  errors.push("Area is " + area);
              }
              if (errors.length > 0) {
                  var ertxt = "";
                  errors.map(function(err) {
                      ertxt += err + "\n";
                  });
                  throw new Error(ertxt);
              }
          }
docs: check if we are a valid CAG (for debugging) NOTE(bebbi) uneven side count doesn't work because rounding with EPS isn't taken into account