void check_merge_2() { Polycurve_conic_traits_2 traits; Polycurve_conic_traits_2::Construct_x_monotone_curve_2 construct_x_monotone_curve_2 = traits.construct_x_monotone_curve_2_object(); Polycurve_conic_traits_2::Merge_2 merge_2 = traits.merge_2_object(); //create a curve Rat_point_2 ps1(1, 10); Rat_point_2 pmid1(5, 4); Rat_point_2 pt1(10, 1); Conic_curve_2 c1(ps1, pmid1, pt1); Rat_point_2 ps2(10, 1); Rat_point_2 pmid2(15, 14); Rat_point_2 pt2(20, 20); Conic_curve_2 c2(ps2, pmid2, pt2); //construct x-monotone curve (compatible with polyline class) Polycurve_conic_traits_2::X_monotone_curve_2 polyline_xmc1 = construct_x_monotone_curve_2(c1); Polycurve_conic_traits_2::X_monotone_curve_2 polyline_xmc2 = construct_x_monotone_curve_2(c2); Polycurve_conic_traits_2::X_monotone_curve_2 merged_xmc; merge_2(polyline_xmc1, polyline_xmc2, merged_xmc); std::cout<< "Merge_2:: Mergable x-monotone curves merged successfully" << std:: endl; }
int main() { HasPtr ps1("This is a string"), ps3("This is another string"); HasPtr ps2 = ps1; ps2 = ps3; return 0; }
void TestPatterns() { Process explorer; std::vector<DWORD> procs; std::vector<ptr_t> results; std::wcout << L"Remote pattern match test. Using 'explorer.exe as a target'\n"; Process::EnumByName( L"explorer.exe", procs ); if (!procs.empty()) { explorer.Attach( procs.front() ); auto pMainMod = explorer.modules().GetMainModule(); // Initialize patterns PatternSearch ps1( "\x48\x89\xD1" ); PatternSearch ps2{ 0x56, 0x57, 0xCC, 0x55 }; // Scan all allocated process memory std::wcout << L"Searching for '48 89 D1'... "; ps1.SearchRemoteWhole( explorer, false, 0, results ); std::wcout << L"Found " << results.size() << L" results\n"; results.clear(); // Scan only inside 'explorer.exe' module std::wcout << L"Searching for '56 57 ?? 55 using CC as a wildcard'... "; ps2.SearchRemote( explorer, 0xCC, pMainMod->baseAddress, pMainMod->size, results ); std::wcout << L"Found " << results.size() << L" results\n\n"; results.clear(); } else std::wcout << L"Can't find explorer.exe, aborting\n\n"; }
void array_var_bool_element(IntVar* _x, vec<BoolView>& a, BoolView y, int offset) { _x->specialiseToEL(); IntView<4> x(_x, 1, -offset); vec<Lit> ps1(a.size()+1); vec<Lit> ps2(a.size()+1); // Add clause !y \/ c_1 \/ ... \/ c_n // Add clause y \/ d_1 \/ ... \/ d_n ps1[0] = ~y; ps2[0] = y; for (int i = 0; i < a.size(); i++) { BoolView c_i(Lit(sat.newVar(),1)); BoolView d_i(Lit(sat.newVar(),1)); sat.addClause(~c_i, x = i); sat.addClause(~c_i, a[i]); sat.addClause(~d_i, x = i); sat.addClause(~d_i, ~a[i]); vec<Lit> ps3(3), ps4(3); ps3[0] = y; ps3[1] = ~a[i]; ps3[2] = (x != i); sat.addClause(ps3); ps4[0] = ~y; ps4[1] = a[i]; ps4[2] = (x != i); sat.addClause(ps4); ps1[i+1] = c_i; ps2[i+1] = d_i; } sat.addClause(ps1); sat.addClause(ps2); }
void tst_QRegion::intersected_data() { QTest::addColumn<QRegion>("r1"); QTest::addColumn<QRegion>("r2"); QTest::addColumn<bool>("intersects"); // QTest::addColumn<QRegion>("intersected"); QPolygon ps1(8); QPolygon ps2(8); ps1.putPoints(0,8, 20,20, 50,20, 50,100, 70,100, 70,20, 120,20, 120,200, 20, 200); ps2.putPoints(0,8, 100,150, 140,150, 140,160, 160,160, 160,150, 200,150, 200,180, 100,180); QTest::newRow("task30716") << QRegion(ps1) << QRegion(ps2) << true; }
void check_equal() { bool are_equal; Polycurve_conic_traits_2 traits; Polycurve_conic_traits_2::Equal_2 equal = traits.equal_2_object(); Polycurve_conic_traits_2::Construct_x_monotone_curve_2 construct_x_monotone_curve_2 = traits.construct_x_monotone_curve_2_object(); //create some curves Conic_point_2 ps1(Rational(1,4), 4); Conic_point_2 pt1(2, Rational(1,2)); Conic_curve_2 c1(0, 0, 1, 0, 0, -1, CGAL::COUNTERCLOCKWISE, ps1, pt1); Conic_point_2 ps2(Rational(1,4), 4); Conic_point_2 pt2(2, Rational(1,2)); Conic_curve_2 c2(0, 0, 1, 0, 0, -1, CGAL::COUNTERCLOCKWISE, ps2, pt2); Rat_point_2 ps3(Rational(1,4), 4); Rat_point_2 pmid3(Rational(3,2), 2); Rat_point_2 pt3(2, Rational(1,3)); Conic_curve_2 c3(ps3, pmid3, pt3); Rat_point_2 ps4(1, 5); Rat_point_2 pmid4(Rational(3,2), 3); Rat_point_2 pt4(3, Rational(1,3)); Conic_curve_2 c4(ps4, pmid4, pt4); // //make x_monotone Polycurve_conic_traits_2::X_monotone_curve_2 xmc1 = construct_x_monotone_curve_2(c1); Polycurve_conic_traits_2::X_monotone_curve_2 xmc2 = construct_x_monotone_curve_2(c2); Polycurve_conic_traits_2::X_monotone_curve_2 xmc3 = construct_x_monotone_curve_2(c3); Polycurve_conic_traits_2::X_monotone_curve_2 xmc4 = construct_x_monotone_curve_2(c4); are_equal = equal(xmc1, xmc2); std::cout << "Two equal conic arcs are computed as: " << ((are_equal) ? "equal" : "Not equal") << std::endl; are_equal = equal(xmc3, xmc2); std::cout << "Two un-equal conic arcs are computed as: " << ((are_equal) ? "equal" : "Not equal") << std::endl; are_equal = equal(xmc3, xmc4); std::cout << "Two un-equal conic arcs are computed as: " << ((are_equal) ? "equal" : "Not equal") << std::endl; }
void ClientConnection::RestoreArea(RECT &r) { int x = r.left; int y = r.top; int w = r.right - r.left; int h = r.bottom - r.top; HBITMAP m_hTempBitmap=NULL; HDC m_hTempBitmapDC=NULL; boost::recursive_mutex::scoped_lock l(m_bitmapdcMutex); ObjectSelector b1(m_hBitmapDC, m_hBitmap); PaletteSelector ps1(m_hBitmapDC, m_hPalette); m_hTempBitmapDC = CreateCompatibleDC(m_hBitmapDC); m_hTempBitmap = CreateCompatibleBitmap(m_hBitmapDC, w, h); ObjectSelector b3(m_hTempBitmapDC, m_hTempBitmap); PaletteSelector ps3(m_hTempBitmapDC, m_hPalette); ObjectSelector b2(m_hCacheBitmapDC, m_hCacheBitmap); PaletteSelector ps2(m_hCacheBitmapDC, m_hPalette); if (!BitBlt(m_hTempBitmapDC, 0, 0, w, h, m_hBitmapDC, x, y, SRCCOPY)) { //vnclog.Print(0, _T("Error saving temp bitmap\n")); Log.WinError(_ERROR_, "Error saving temp bitmap"); } if (!BitBlt(m_hBitmapDC, x, y, w, h, m_hCacheBitmapDC, x, y, SRCCOPY)) { //vnclog.Print(0, _T("Error restoring screen\n")); Log.WinError(_ERROR_, "Error restoring screen"); } if (!BitBlt(m_hCacheBitmapDC, x, y, w, h, m_hTempBitmapDC, 0, 0, SRCCOPY)) { //vnclog.Print(0, _T("Error restoring screen under cursor\n")); Log.WinError(_ERROR_, "Error restoring screen under cursor"); } DeleteDC(m_hTempBitmapDC); if (m_hTempBitmap != NULL) DeleteObject(m_hTempBitmap); if (m_hCacheBitmapDC != NULL) DeleteObject(m_hTempBitmapDC); }
void check_compare_end_points_xy_2() { Polycurve_conic_traits_2 traits; Polycurve_conic_traits_2::Construct_x_monotone_curve_2 construct_x_monotone_curve_2 = traits.construct_x_monotone_curve_2_object(); Polycurve_conic_traits_2::Compare_endpoints_xy_2 compare_endpoints_xy_2 = traits.compare_endpoints_xy_2_object(); //create some curves Conic_point_2 ps1(Rational(1,4), 4); Conic_point_2 pt1(2, Rational(1,2)); Conic_curve_2 c1(0, 0, 1, 0, 0, -1, CGAL::COUNTERCLOCKWISE, ps1, pt1); // Insert a parabolic arc that is supported by a parabola y = -x^2 // (or: x^2 + y = 0) and whose endpoints are (-sqrt(3), -3) ~ (-1.73, -3) // and (sqrt(2), -2) ~ (1.41, -2). Notice that since the x-coordinates // of the endpoints cannot be acccurately represented, we specify them // as the intersections of the parabola with the lines y = -3 and y = -2. // Note that the arc is clockwise oriented. Conic_curve_2 c2 = Conic_curve_2(1, 0, 0, 0, 1, 0, // The parabola. CGAL::CLOCKWISE, Conic_point_2(-1.73, -3), // Approximation of the source. 0, 0, 0, 0, 1, 3, // The line: y = -3. Conic_point_2(1.41, -2), // Approximation of the target. 0, 0, 0, 0, 1, 2); // The line: y = -2. CGAL_assertion(c2.is_valid()); //make polyline x-monotone curves Polycurve_conic_traits_2::X_monotone_curve_2 polyline_xmc1 = construct_x_monotone_curve_2(c1); Polycurve_conic_traits_2::X_monotone_curve_2 polyline_xmc2 = construct_x_monotone_curve_2(c2); CGAL::Comparison_result res = compare_endpoints_xy_2(polyline_xmc1); std::cout << "compare_end_points_xy_2 for counterclockwise curve: " << (res == CGAL::SMALLER ? "SMALLER": (res == CGAL::LARGER ? "LARGER" : "EQUAL")) << std::endl; res = compare_endpoints_xy_2(polyline_xmc2); std::cout<< "compare_end_points_xy_2 for clockwise curve: " << (res == CGAL::SMALLER ? "SMALLER": (res == CGAL::LARGER ? "LARGER" : "EQUAL")) << std::endl; }
void ClientConnection::SaveArea(RECT &r) { if (!m_opts.m_fEnableCache) return; // sf@2002 int x = r.left; int y = r.top; int w = r.right - r.left; int h = r.bottom - r.top; omni_mutex_lock l(m_bitmapdcMutex); ObjectSelector b1(m_hBitmapDC, m_hBitmap); PaletteSelector ps1(m_hBitmapDC, m_hPalette); ObjectSelector b2(m_hCacheBitmapDC, m_hCacheBitmap); PaletteSelector ps2(m_hCacheBitmapDC, m_hPalette); if (m_hCacheBitmapDC!=NULL) if (!BitBlt(m_hCacheBitmapDC, x, y, w, h, m_hBitmapDC, x, y, SRCCOPY)) { vnclog.Print(0, _T("Error saving screen\n")); } }
void check_are_mergable() { Polycurve_conic_traits_2 traits; Polycurve_conic_traits_2::Construct_x_monotone_curve_2 construct_x_monotone_curve_2 = traits.construct_x_monotone_curve_2_object(); Polycurve_conic_traits_2::Are_mergeable_2 are_mergeable_2 = traits.are_mergeable_2_object(); //create a curve Rat_point_2 ps1(1, 10); Rat_point_2 pmid1(5, 4); Rat_point_2 pt1(10, 1); Conic_curve_2 c1(ps1, pmid1, pt1); Rat_point_2 ps2(10, 1); Rat_point_2 pmid2(15, 14); Rat_point_2 pt2(20, 20); Conic_curve_2 c2(ps2, pmid2, pt2); Rat_point_2 ps3(Rational(1,4), 4); Rat_point_2 pmid3(Rational(3,2), 2); Rat_point_2 pt3(2, Rational(1,3)); Conic_curve_2 c3(ps3, pmid3, pt3); //construct x-monotone curve(compatible with polyline class) Polycurve_conic_traits_2::X_monotone_curve_2 polyline_xmc1 = construct_x_monotone_curve_2(c1); Polycurve_conic_traits_2::X_monotone_curve_2 polyline_xmc2 = construct_x_monotone_curve_2(c2); Polycurve_conic_traits_2::X_monotone_curve_2 polyline_xmc3 = construct_x_monotone_curve_2(c3); bool result = are_mergeable_2(polyline_xmc1, polyline_xmc2); std::cout << "Are_mergable:: Mergable x-monotone polycurves are Computed as: " << ((result)? "Mergable" : "Not-Mergable") << std::endl; result = are_mergeable_2(polyline_xmc1, polyline_xmc3); std::cout << "Are_mergable:: Non-Mergable x-monotone polycurves are Computed as: " << ((result)? "Mergable" : "Not-Mergable") << std::endl; }
void check_construct_opposite() { Polycurve_conic_traits_2 traits; Polycurve_conic_traits_2::Construct_x_monotone_curve_2 construct_x_monotone_curve_2 = traits.construct_x_monotone_curve_2_object(); Polycurve_conic_traits_2::Construct_opposite_2 construct_opposite_2 = traits.construct_opposite_2_object(); //create a curve Rat_point_2 ps1(1, 10); Rat_point_2 pmid1(5, 4); Rat_point_2 pt1(10, 1); Conic_curve_2 c1(ps1, pmid1, pt1); //construct x-monotone curve (compatible with polyline class) Polycurve_conic_traits_2::X_monotone_curve_2 polyline_xmc1 = construct_x_monotone_curve_2(c1); Polycurve_conic_traits_2::X_monotone_curve_2 polyline_opposite_curve = construct_opposite_2(polyline_xmc1); std::cout<< "Construct_opposite_2:: Opposite curve created"; }
void check_is_vertical() { Polycurve_conic_traits_2 traits; Polycurve_conic_traits_2::Construct_x_monotone_curve_2 construct_x_monotone_curve_2 = traits.construct_x_monotone_curve_2_object(); Polycurve_conic_traits_2::Is_vertical_2 is_vertical = traits.is_vertical_2_object(); //create a curve Rat_point_2 ps1(1, 10); Rat_point_2 pmid1(5, 4); Rat_point_2 pt1(10, 1); Conic_curve_2 c1(ps1, pmid1, pt1); //make x-monotone curve Polycurve_conic_traits_2::X_monotone_curve_2 polyline_xmc1 = construct_x_monotone_curve_2(c1); bool result = is_vertical(polyline_xmc1); std::cout << "Is_verticle:: Expected first result is not vertivle: Computed: " << ((result)? "vertical" : "not vertical") << std::endl; }
void EGS_TrackView::setProjection(EGS_Vector pxo, EGS_Vector px_screen, EGS_Vector pv1_screen, EGS_Vector pv2_screen, EGS_Float psx, EGS_Float psy) { // set camera and screen variables xo = pxo; sx = psx; sy = psy; x_screen = px_screen; v1_screen = pv1_screen; v2_screen = pv2_screen; v1_screen.normalize(); v2_screen.normalize(); // calculate the equation of the projection plane defined by the screen: // a*x + b*y + c*z = 1 EGS_Vector ps1(x_screen); EGS_Vector ps2(x_screen + v1_screen); EGS_Vector ps3(x_screen + v2_screen); double d = det(ps1, ps2, ps3); EGS_Vector a1 = ps1; a1.x = 1; EGS_Vector a2 = ps2; a2.x = 1; EGS_Vector a3 = ps3; a3.x = 1; double d1 = det(a1, a2, a3); EGS_Vector b1 = ps1; b1.y = 1; EGS_Vector b2 = ps2; b2.y = 1; EGS_Vector b3 = ps3; b3.y = 1; double d2 = det(b1, b2, b3); EGS_Vector c1 = ps1; c1.z = 1; EGS_Vector c2 = ps2; c2.z = 1; EGS_Vector c3 = ps3; c3.z = 1; double d3 = det(c1, c2, c3); // avoid seg faults if (d == 0.0000) d += 0.001; m_scr_a = d1/d; m_scr_b = d2/d; m_scr_c = d3/d; };
void PyHelpersTest::RunTests() { // Test py::Ptr construction { { // NULL pointer PyObject * p = NULL; SHOULDFAIL(py::Ptr(p, /* allowNULL: */false)); py::Ptr pp1(p, /* allowNULL: */true); TEST((PyObject *)pp1 == NULL); TEST(pp1.isNULL()); } // Non-NULL pointer { PyObject * p = PyTuple_New(1); py::Ptr pp2(p); TEST(!pp2.isNULL()); TEST((PyObject *)pp2 == p); pp2.release(); TEST(pp2.isNULL()); Py_DECREF(p); } // assign { PyObject * p = PyTuple_New(1); TEST(p->ob_refcnt == 1); py::Ptr pp(NULL, /* allowNULL */ true); TEST(pp.isNULL()); NTA_DEBUG << "*** Before assign"; pp.assign(p); NTA_DEBUG << "*** After assign"; TEST(p->ob_refcnt == 2); TEST(!(pp.isNULL())); Py_DECREF(p); TEST(p->ob_refcnt == 1); } } // py::String { py::String ps1(std::string("123")); TEST(PyString_Check(ps1) != 0); py::String ps2("123", size_t(3)); TEST(PyString_Check(ps2) != 0); py::String ps3("123"); TEST(PyString_Check(ps3) != 0); std::string s1(PyString_AsString(ps1)); std::string s2(PyString_AsString(ps2)); std::string s3(PyString_AsString(ps3)); std::string expected("123"); TEST(s1 == expected); TEST(s2 == expected); TEST(s3 == expected); TEST(std::string(ps1) == expected); TEST(std::string(ps2) == expected); TEST(std::string(ps3) == expected); PyObject * p = PyString_FromString("777"); py::String ps4(p); TEST(std::string(ps4) == std::string("777")); } // py::Int { py::Int n1(-5); py::Int n2(-6666); py::Int n3(long(0)); py::Int n4(555); py::Int n5(6666); TEST(n1 == -5); int x = n2; int expected = -6666; TEST(x == expected); TEST(n3 == 0); TEST(n4 == 555); x = n5; expected = 6666; TEST(x == expected); } // py::Long { py::Long n1(-5); py::Long n2(-66666666); py::Long n3(long(0)); py::Long n4(555); py::Long n5(66666666); TEST(n1 == -5); long x = n2; long expected = -66666666; TEST(x == expected); TEST(n3 == 0); TEST(n4 == 555); x = n5; expected = 66666666; TEST(x == expected); } // py::UnsignedLong { py::UnsignedLong n1((unsigned long)(-5)); py::UnsignedLong n2((unsigned long)(-66666666)); py::UnsignedLong n3((unsigned long)(0)); py::UnsignedLong n4(555); py::UnsignedLong n5(66666666); TEST(n1 == (unsigned long)(-5)); TEST(n2 == (unsigned long)(-66666666)); TEST(n3 == 0); TEST(n4 == 555); TEST(n5 == 66666666); } // py::Float { TEST(py::Float::getMax() == std::numeric_limits<double>::max()); TEST(py::Float::getMin() == std::numeric_limits<double>::min()); py::Float max(std::numeric_limits<double>::max()); py::Float min(std::numeric_limits<double>::min()); py::Float n1(-0.5); py::Float n2(double(0)); py::Float n3(333.555); py::Float n4(0.02); py::Float n5("0.02"); TEST(max == py::Float::getMax()); TEST(min == py::Float::getMin()); TEST(n1 == -0.5); TEST(n2 == 0); TEST(n3 == 333.555); TEST(n4 == 0.02); TEST(n5 == 0.02); } // py::Tuple { py::String s1("item_1"); py::String s2("item_2"); // Empty tuple { py::Tuple empty; TEST(PyTuple_Check(empty) != 0); TEST(empty.getCount() == 0); SHOULDFAIL(empty.setItem(0, s1)); SHOULDFAIL(empty.getItem(0)); } // One item tuple { py::Tuple t1(1); TEST(PyTuple_Check(t1) != 0); TEST(t1.getCount() == 1); t1.setItem(0, s1); py::String item1(t1.getItem(0)); TEST(std::string(item1) == std::string(s1)); py::String fastItem1(t1.fastGetItem(0)); TEST(std::string(fastItem1) == std::string(s1)); fastItem1.release(); SHOULDFAIL(t1.setItem(1, s2)); SHOULDFAIL(t1.getItem(1)); TEST(t1.getCount() == 1); } // 2 items tuple { py::Tuple t2(2); TEST(PyTuple_Check(t2) != 0); TEST(t2.getCount() == 2); t2.setItem(0, s1); py::String item1(t2.getItem(0)); TEST(std::string(item1) == std::string(s1)); py::String fastItem1(t2.fastGetItem(0)); TEST(std::string(fastItem1) == std::string(s1)); fastItem1.release(); t2.setItem(1, s2); py::String item2(t2.getItem(1)); TEST(std::string(item2) == std::string(s2)); py::String fastItem2(t2.fastGetItem(1)); TEST(std::string(fastItem2) == std::string(s2)); fastItem2.release(); SHOULDFAIL(t2.setItem(2, s2)); SHOULDFAIL(t2.getItem(2)); TEST(t2.getCount() == 2); } } // py::List { py::String s1("item_1"); py::String s2("item_2"); // Empty list { py::List empty; TEST(PyList_Check(empty) != 0); TEST(empty.getCount() == 0); SHOULDFAIL(empty.setItem(0, s1)); SHOULDFAIL(empty.getItem(0)); } // One item list { py::List t1; TEST(PyList_Check(t1) != 0); TEST(t1.getCount() == 0); t1.append(s1); py::String item1(t1.getItem(0)); TEST(std::string(item1) == std::string(s1)); py::String fastItem1(t1.fastGetItem(0)); TEST(std::string(fastItem1) == std::string(s1)); fastItem1.release(); TEST(t1.getCount() == 1); TEST(std::string(item1) == std::string(s1)); SHOULDFAIL(t1.getItem(1)); } // Two items list { py::List t2; TEST(PyList_Check(t2) != 0); TEST(t2.getCount() == 0); t2.append(s1); py::String item1(t2.getItem(0)); TEST(std::string(item1) == std::string(s1)); py::String fastItem1(t2.fastGetItem(0)); TEST(std::string(fastItem1) == std::string(s1)); fastItem1.release(); t2.append(s2); TEST(t2.getCount() == 2); py::String item2(t2.getItem(1)); TEST(std::string(item2) == std::string(s2)); py::String fastItem2(t2.fastGetItem(1)); TEST(std::string(fastItem2) == std::string(s2)); fastItem2.release(); SHOULDFAIL(t2.getItem(2)); } } // py::Dict { // Empty dict { py::Dict d; TEST(PyDict_Size(d) == 0); TEST(d.getItem("blah") == NULL); } // Failed External PyObject * { // NULL object SHOULDFAIL(py::Dict(NULL)); // Wrong type (must be a dictionary) py::String s("1234"); try { py::Dict d(s.release()); NTA_THROW << "py::Dict d(s) Should fail!!!"; } catch(...) { } // SHOULDFAIL fails to fail :-) //SHOULDFAIL(py::Dict(s)); } // Successful external PyObject * { PyObject * p = PyDict_New(); PyDict_SetItem(p, py::String("1234"), py::String("5678")); py::Dict d(p); TEST(PyDict_Contains(d, py::String("1234")) == 1); PyDict_SetItem(d, py::String("777"), py::String("999")); TEST(PyDict_Contains(d, py::String("777")) == 1); } // getItem with default (exisiting and non-exisitng key) { py::Dict d; d.setItem("A", py::String("AAA")); PyObject * defaultItem = (PyObject *)123; py::String A(d.getItem("A")); TEST(std::string(A) == std::string("AAA")); // No "B" in the dict, so expect to get the default item PyObject * B = (d.getItem("B", defaultItem)); TEST(B == defaultItem); PyDict_SetItem(d, py::String("777"), py::String("999")); TEST(PyDict_Contains(d, py::String("777")) == 1); } //NTA_DEBUG << ss << ": " << ss->ob_refcnt; } // py::Module { py::Module module("sys"); TEST(std::string(PyModule_GetName(module)) == std::string("sys")); } // py::Class { py::Class c("datetime", "date"); } // py::Instance { py::Tuple args(3); args.setItem(0, py::Long(2000)); args.setItem(1, py::Long(11)); args.setItem(2, py::Long(5)); py::Instance date("datetime", "date", args, py::Dict()); // Test invoke() { py::String result(date.invoke("__str__", py::Tuple(), py::Dict())); std::string res((const char *)result); std::string expected("2000-11-05"); TEST(res == expected); } // Test hasAttr() { py::String result(date.invoke("__str__", py::Tuple(), py::Dict())); std::string res((const char *)result); std::string expected("2000-11-05"); TEST(!(date.hasAttr("No such attribute"))); TEST(date.hasAttr("year")); } // Test getAttr() { py::Int year(date.getAttr("year")); TEST(2000 == long(year)); } // Test toString() { std::string res((const char *)py::String(date.toString())); std::string expected("2000-11-05"); TEST(res == expected); } } // Test custom exception { py::Tuple args(1); args.setItem(0, py::String("error message!")); py::Instance e(PyExc_RuntimeError, args); e.setAttr("traceback", py::String("traceback!!!")); PyErr_SetObject(PyExc_RuntimeError, e); try { py::checkPyError(0); } catch (const nta::Exception & e) { NTA_DEBUG << e.getMessage(); } } }
bool check_compare_y_at_x_2() { Polycurve_conic_traits_2 traits; Polycurve_conic_traits_2::Compare_y_at_x_2 cmp_y_at_x_2 = traits.compare_y_at_x_2_object(); //polycurve constructors Polycurve_conic_traits_2::Construct_x_monotone_curve_2 construct_x_mono_polycurve = traits.construct_x_monotone_curve_2_object(); Polycurve_conic_traits_2::Construct_curve_2 construct_polycurve = traits.construct_curve_2_object(); //create a curve Rat_point_2 ps1(1, 10); Rat_point_2 pmid1(5, 4); Rat_point_2 pt1(10, 1); Conic_curve_2 c1(ps1, pmid1, pt1); //create a curve Rat_point_2 ps2(10, 1); Rat_point_2 pmid2(15, 5); Rat_point_2 pt2(20, 10); Conic_curve_2 c2(ps2, pmid2, pt2); Conic_curve_2 c3(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(0), Algebraic(0)), Conic_point_2(Algebraic(3), Algebraic(9))); Conic_curve_2 c4(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(3), Algebraic(9)), Conic_point_2(Algebraic(5), Algebraic(25))); std::vector<Conic_curve_2> conic_curves, conic_curves_2, Conic_curves_3; conic_curves.push_back(c1); conic_curves.push_back(c2); //conic_curves_2.push_back(c3); //conic_curves_2.push_back(c4); Conic_x_monotone_curve_2 xc1(c1); Conic_x_monotone_curve_2 xc2(c2); Conic_x_monotone_curve_2 xc3(c3); Conic_x_monotone_curve_2 xc4(c4); std::vector<Conic_x_monotone_curve_2> xmono_conic_curves, xmono_conic_curves_2; /* VERY IMPORTANT * For efficiency reasons, we recommend users not to construct x-monotone * conic arc directly, but rather use the Make_x_monotone_2 functor supplied * by the conic-arc traits class to convert conic curves to x-monotone curves. */ xmono_conic_curves.push_back(xc1); xmono_conic_curves.push_back(xc2); xmono_conic_curves_2.push_back(xc3); xmono_conic_curves_2.push_back(xc4); //construct x-monotone poly-curve Polycurve_conic_traits_2::X_monotone_curve_2 conic_x_mono_polycurve = construct_x_mono_polycurve(xmono_conic_curves.begin(), xmono_conic_curves.end()); Polycurve_conic_traits_2::X_monotone_curve_2 conic_x_mono_polycurve_2 = construct_x_mono_polycurve(xmono_conic_curves_2.begin(), xmono_conic_curves_2.end()); //construct poly-curve Polycurve_conic_traits_2::Curve_2 conic_polycurve = construct_polycurve(conic_curves.begin(), conic_curves.end()); //Polycurve_conic_traits_2::Curve_2 conic_polycurve_2 = // construct_polycurve(conic_curves_2.begin(), conic_curves_2.end()); //make x-monotone curve //Polycurve_conic_traits_2::X_monotone_curve_2 polyline_xmc1 = // construct_x_monotone_curve_2(c1); //create points Polycurve_conic_traits_2::Point_2 point_above_line = Polycurve_conic_traits_2::Point_2(2,10), point_below_line = Polycurve_conic_traits_2::Point_2(4,7), point_on_line = Polycurve_conic_traits_2::Point_2(2,4); CGAL::Comparison_result result; result = cmp_y_at_x_2(point_above_line, conic_x_mono_polycurve_2); std::cout << "Compare_y_at_x_2:: for point above the curve computed Answer is: " << (result == CGAL::SMALLER ? "Below": (result == CGAL::LARGER ? "Above" : "On-line")) << std::endl; result = cmp_y_at_x_2(point_below_line, conic_x_mono_polycurve_2); std::cout << "Compare_y_at_x_2:: for point below the curve computed Answer is: " << (result == CGAL::SMALLER ? "Below": (result == CGAL::LARGER ? "Above" : "On-line")) << std::endl; result = cmp_y_at_x_2(point_on_line, conic_x_mono_polycurve_2); std::cout << "Compare_y_at_x_2:: for point on the curve computed Answer is: " << (result == CGAL::SMALLER ? "Below": (result == CGAL::LARGER ? "Above" : "On-line")) << std::endl; return true; }