Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] is_valid_2_object blew up

Subject: CGAL users discussion list

List archive

[cgal-discuss] is_valid_2_object blew up


Chronological Thread 
  • From: Roger House <>
  • To: CGAL discussion <>
  • Subject: [cgal-discuss] is_valid_2_object blew up
  • Date: Mon, 15 Sep 2008 13:54:10 -0700

To avoid obscure errors when calling CGAL functions, I am trying to validate
objects of type Polygon_2 and Polygon_with_holes_2 before doing such things
as boolean operations. To my chagrin, is_valid_2_object blew up when I
called it on this polygon:

(2 0) (4 0) (4 4) (2 0) (0 0) (0 -4)

It seems to me that the worst a validation function should do is return
false. Am I calling the wrong function?

Below is the output produced by the attached program.

Roger House
Software Developer

Written to stderr by error handler

CGAL problem: precondition
Expression: compare_xy(cv1.right(), p) == LARGER && compare_xy(cv2.right(), p) == LARGER
File: c:\users\roghouse\332\build\projects\cgal_eesof\include\cgal\arr_segment_traits_2.h
Line: 609

Written to stdout

Begin test of is_valid_2_object

Two triangles touching
[ 6 vertices: (2 0) (4 0) (4 4) (2 0) (0 0) (0 -4) ]
P is not simple
P is not convex
P has area 8

Just before calling is_valid_2_object
EXCEPTION THROWN!
CGAL ERROR: precondition violation!
Expr: compare_xy(cv1.right(), p) == LARGER && compare_xy(cv2.right(), p) == LARGER
File: c:\users\roghouse\332\build\projects\cgal_eesof\include\cgal\arr_segment_traits_2.h
Line: 609
End test of is_valid_2_object

Press any nonwhitespace key and Enter to terminate

// isvalid.cpp -- Demonstrate problem with is_valid_2_object
//

#include "CGAL\Cartesian.h"
#include "CGAL\Polygon_2.h"
#include <CGAL\Boolean_set_operations_2.h>
#include <CGAL\assertions.h>
#include <CGAL\Polygon_set_2.h>
#include <list>
#include <cassert>
#include <iostream>
#include <sstream>

using namespace std;

typedef CGAL::Cartesian<double> K;
typedef K::Point_2 Point;
typedef list<Point> Point_list;
typedef CGAL::Polygon_2<K> Polygon_2;
typedef CGAL::Polygon_set_2<K> Polygon_set_2;
typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes_2;
typedef list<Polygon_with_holes_2> Pwh_list_2;

// CGAL error handler

void handle_CGAL_errors(
const char *type,
const char *expression,
const char *file,
int line,
const char *explanation)
{
cerr << "CGAL problem: " << type << endl;
cerr << " Expression: " << expression << endl;
cerr << " File: " << file << endl;
cerr << " Line: " << line << endl;
if (explanation != NULL && *explanation != '\0')
cerr << " Explanation: " << explanation << endl;
}


void print_polygon(const Polygon_2 &poly)
{
Polygon_2::Vertex_const_iterator vit;

cout << "[ " << poly.size() << " vertices:";
for (vit = poly.vertices_begin(); vit != poly.vertices_end(); ++vit)
cout << " (" << *vit << ')';
cout << " ]" << endl;
}


void print_polygon_info(
const Polygon_2 &poly,
const string &name,
const string &desc)
{
bool isSimple = poly.is_simple();
bool isConvex = poly.is_convex();
bool isCCW = false;
if (isSimple)
isCCW = poly.is_counterclockwise_oriented();

cout << desc << endl;
cout << " ";
print_polygon(poly);
cout << " " << name << " is " << (isSimple ? "" : "not ")
<< "simple" << endl;
cout << " " << name << " is " << (isConvex ? "" : "not ")
<< "convex" << endl;
if (isSimple)
cout << " " << name << " is " << (isCCW ? "counterclockwise"
: "clockwise") << endl;
cout << " " << name << " has area " << poly.area() << endl;
cout << endl;
}


int main()
{
CGAL::Failure_function prev_error_handler;
CGAL::Failure_function prev_warning_handler;
prev_error_handler = CGAL::set_error_handler (handle_CGAL_errors);
prev_warning_handler = CGAL::set_warning_handler(handle_CGAL_errors);

cout << "Begin test of is_valid_2_object" << endl;
cout << endl;

try
{
Point points[] = { Point(2,0), Point(4,0), Point(4,4), Point(2,0),
Point(0,0), Point(0,-4) };
Polygon_2 P(points, points+6);
print_polygon_info(P, "P", "Two triangles touching");

cout << "Just before calling is_valid_2_object" << endl;
bool isValid = Polygon_set_2::Traits_2().is_valid_2_object()(P);

cout << " P is is " << (isValid ? "" : "not ") << "valid" << endl;
}
catch (exception& e)
{
cout << "EXCEPTION THROWN!" << endl;
cout << e.what() << endl;
}

cout << "End test of is_valid_2_object" << endl;
cout << endl;

cout << "Press any nonwhitespace key and Enter to terminate" << endl;
string c;
cin >> c;

} // end main


// end isvalid.cpp


  • [cgal-discuss] is_valid_2_object blew up, Roger House, 09/15/2008

Archive powered by MHonArc 2.6.16.

Top of Page