Commit 6c9c273ad0f2449c7949a45d89c638aacbd48462

Authored by Jürgen Knödlseder
1 parent 9fccc588

Enhance GSkyRegionRectangle unit tests (#3248)

include/GSkyRegionRectangle.hpp
... ... @@ -95,12 +95,12 @@ public:
95 95 void height(const double& height);
96 96 const double& posang(void) const;
97 97 void posang(const double& posang);
  98 + GSkyDir corner(const int& index) const;
98 99 void read(const std::string& line);
99 100 std::string write(void) const;
100 101 bool contains(const GSkyDir& dir) const;
101 102 bool contains(const GSkyRegion& reg) const;
102 103 bool overlaps(const GSkyRegion& reg) const;
103   - GSkyDir corner(const int& index) const;
104 104 std::string print(const GChatter& chatter = NORMAL) const;
105 105  
106 106 protected:
... ...
pyext/GSkyRegionRectangle.i
... ... @@ -67,12 +67,12 @@ public:
67 67 void height(const double& height);
68 68 const double& posang(void) const;
69 69 void posang(const double& posang);
  70 + GSkyDir corner(const int& index) const;
70 71 void read(const std::string& line);
71 72 std::string write(void) const;
72 73 bool contains(const GSkyDir& dir) const;
73 74 bool contains(const GSkyRegion& reg) const;
74 75 bool overlaps(const GSkyRegion& reg) const;
75   - GSkyDir corner(const int& index) const;
76 76 };
77 77  
78 78  
... ...
src/sky/GSkyRegionCircle.cpp
... ... @@ -533,7 +533,8 @@ bool GSkyRegionCircle::contains(const GSkyRegion& reg) const
533 533 if (reg.type() == "Circle") {
534 534  
535 535 // Create circular region from reg
536   - const GSkyRegionCircle* circle = dynamic_cast<const GSkyRegionCircle*>(&reg);
  536 + const GSkyRegionCircle* circle =
  537 + static_cast<const GSkyRegionCircle*>(&reg);
537 538  
538 539 // Calculate angular distance between the centres
539 540 double ang_dist = m_centre.dist_deg(circle->centre());
... ... @@ -551,7 +552,7 @@ bool GSkyRegionCircle::contains(const GSkyRegion&amp; reg) const
551 552  
552 553 // Create rectangular region from reg
553 554 const GSkyRegionRectangle* rect =
554   - dynamic_cast<const GSkyRegionRectangle*>(&reg);
  555 + static_cast<const GSkyRegionRectangle*>(&reg);
555 556  
556 557 // Check containment of all corners
557 558 contains = this->contains(rect->corner(0)) &&
... ... @@ -566,7 +567,7 @@ bool GSkyRegionCircle::contains(const GSkyRegion&amp; reg) const
566 567 else if (reg.type() == "Map") {
567 568  
568 569 // Create map from reg
569   - const GSkyRegionMap* map = dynamic_cast<const GSkyRegionMap*>(&reg);
  570 + const GSkyRegionMap* map = static_cast<const GSkyRegionMap*>(&reg);
570 571  
571 572 // Get non-zero indices
572 573 std::vector<int> indices = map->nonzero_indices();
... ... @@ -622,7 +623,8 @@ bool GSkyRegionCircle::overlaps(const GSkyRegion&amp; reg) const
622 623 if (reg.type() == "Circle") {
623 624  
624 625 // Create circular region from reg
625   - const GSkyRegionCircle* circle = dynamic_cast<const GSkyRegionCircle*>(&reg);
  626 + const GSkyRegionCircle* circle =
  627 + static_cast<const GSkyRegionCircle*>(&reg);
626 628  
627 629 // Calculate angular distance between the centres
628 630 double ang_dist = m_centre.dist_deg(circle->centre());
... ... @@ -639,7 +641,7 @@ bool GSkyRegionCircle::overlaps(const GSkyRegion&amp; reg) const
639 641  
640 642 // Create rectangular region from reg
641 643 const GSkyRegionRectangle* rect =
642   - dynamic_cast<const GSkyRegionRectangle*>(&reg);
  644 + static_cast<const GSkyRegionRectangle*>(&reg);
643 645  
644 646 // Check overlap with circle
645 647 overlap = rect->overlaps(*this);
... ... @@ -650,7 +652,7 @@ bool GSkyRegionCircle::overlaps(const GSkyRegion&amp; reg) const
650 652 else if (reg.type() == "Map") {
651 653  
652 654 // Create map from reg
653   - const GSkyRegionMap* map = dynamic_cast<const GSkyRegionMap*>(&reg);
  655 + const GSkyRegionMap* map = static_cast<const GSkyRegionMap*>(&reg);
654 656  
655 657 // Check overlap with circle
656 658 overlap = map->overlaps(*this);
... ...
src/sky/GSkyRegionMap.cpp
... ... @@ -406,7 +406,7 @@ bool GSkyRegionMap::contains(const GSkyRegion&amp; reg) const
406 406 if (reg.type() == "Map") {
407 407  
408 408 // Cast to map type
409   - const GSkyRegionMap* inreg = dynamic_cast<const GSkyRegionMap*>(&reg);
  409 + const GSkyRegionMap* inreg = static_cast<const GSkyRegionMap*>(&reg);
410 410  
411 411 // Retrieve map data
412 412 const GSkyMap& regmap = inreg->map();
... ... @@ -426,7 +426,8 @@ bool GSkyRegionMap::contains(const GSkyRegion&amp; reg) const
426 426 else if (reg.type() == "Circle") {
427 427  
428 428 // Create circular region from reg
429   - const GSkyRegionCircle* inreg = dynamic_cast<const GSkyRegionCircle*>(&reg);
  429 + const GSkyRegionCircle* inreg =
  430 + static_cast<const GSkyRegionCircle*>(&reg);
430 431  
431 432 // Retrieve circle data
432 433 const GSkyDir& centre = inreg->centre();
... ... @@ -452,7 +453,7 @@ bool GSkyRegionMap::contains(const GSkyRegion&amp; reg) const
452 453  
453 454 // Create rectangular region from reg
454 455 const GSkyRegionRectangle* rect =
455   - dynamic_cast<const GSkyRegionRectangle*>(&reg);
  456 + static_cast<const GSkyRegionRectangle*>(&reg);
456 457  
457 458 // Create region map from rectangle
458 459 GSkyRegionMap rect_map(rect);
... ...
src/sky/GSkyRegionRectangle.cpp
... ... @@ -519,7 +519,7 @@ bool GSkyRegionRectangle::contains(const GSkyRegion&amp; reg) const
519 519  
520 520 // Create circular region from reg
521 521 const GSkyRegionCircle* circle =
522   - dynamic_cast<const GSkyRegionCircle*>(&reg);
  522 + static_cast<const GSkyRegionCircle*>(&reg);
523 523  
524 524 // Transform circle center to local coordinate system
525 525 GSkyPixel local = dir_to_local(circle->centre());
... ... @@ -544,7 +544,7 @@ bool GSkyRegionRectangle::contains(const GSkyRegion&amp; reg) const
544 544  
545 545 // Create rectangular region from reg
546 546 const GSkyRegionRectangle* rect =
547   - dynamic_cast<const GSkyRegionRectangle*>(&reg);
  547 + static_cast<const GSkyRegionRectangle*>(&reg);
548 548  
549 549 // Initialise containment flag to true
550 550 contains = true;
... ... @@ -571,10 +571,10 @@ bool GSkyRegionRectangle::contains(const GSkyRegion&amp; reg) const
571 571 else if (reg.type() == "Map") {
572 572  
573 573 // Create map from reg
574   - const GSkyRegionMap* map = dynamic_cast<const GSkyRegionMap*>(&reg);
  574 + const GSkyRegionMap* map = static_cast<const GSkyRegionMap*>(&reg);
575 575  
576 576 // Get non-zero indices
577   - std::vector<int> indices = map->nonzero_indices();
  577 + const std::vector<int>& indices = map->nonzero_indices();
578 578  
579 579 // Initialise containment flag to true
580 580 contains = true;
... ... @@ -583,7 +583,7 @@ bool GSkyRegionRectangle::contains(const GSkyRegion&amp; reg) const
583 583 for (int i = 0; i < indices.size(); ++i) {
584 584  
585 585 // Get sky direction of map pixel
586   - GSkyDir dir = map->map().inx2dir(i);
  586 + GSkyDir dir = map->map().inx2dir(indices[i]);
587 587  
588 588 // If pixel is not contained then set containment flag to false
589 589 // and break
... ... @@ -628,7 +628,7 @@ bool GSkyRegionRectangle::overlaps(const GSkyRegion&amp; reg) const
628 628  
629 629 // Create circular region from reg
630 630 const GSkyRegionCircle* circle =
631   - dynamic_cast<const GSkyRegionCircle*>(&reg);
  631 + static_cast<const GSkyRegionCircle*>(&reg);
632 632  
633 633 // Transform circle center to local coordinate system
634 634 GSkyPixel local = dir_to_local(circle->centre());
... ... @@ -653,7 +653,7 @@ bool GSkyRegionRectangle::overlaps(const GSkyRegion&amp; reg) const
653 653  
654 654 // Create rectangular region from reg
655 655 const GSkyRegionRectangle* rect =
656   - dynamic_cast<const GSkyRegionRectangle*>(&reg);
  656 + static_cast<const GSkyRegionRectangle*>(&reg);
657 657  
658 658 // Dirty kludge: compare with map
659 659 GSkyRegionMap map = GSkyRegionMap(rect);
... ... @@ -665,7 +665,7 @@ bool GSkyRegionRectangle::overlaps(const GSkyRegion&amp; reg) const
665 665 else if (reg.type() == "Map") {
666 666  
667 667 // Create map from reg
668   - const GSkyRegionMap* map = dynamic_cast<const GSkyRegionMap*>(&reg);
  668 + const GSkyRegionMap* map = static_cast<const GSkyRegionMap*>(&reg);
669 669  
670 670 // Check overlap with circle
671 671 overlap = map->overlaps(*this);
... ...
test/test_GSky.cpp
... ... @@ -1825,27 +1825,98 @@ void TestGSky::test_GSkyRegionCircle(void)
1825 1825 ***************************************************************************/
1826 1826 void TestGSky::test_GSkyRegionRectangle(void)
1827 1827 {
1828   - // Define region for comparison
1829   - GSkyDir refdir_radeczerozero = GSkyDir();
1830   - refdir_radeczerozero.radec_deg(0,0);
1831   - double ref_width = 1.;
1832   - double ref_height = 1.;
1833   - double ref_pa_deg = 0.;
1834   -
1835   - // Test constructing
1836   - test_try("Test constructor");
  1828 + // Test void constructor
  1829 + GSkyRegionRectangle rect0;
  1830 + test_value(rect0.classname(), "GSkyRegionRectangle", "Test classname of void constructor");
  1831 + test_value(rect0.type(), "Rectangle", "Test type of void constructor");
  1832 + test_value(rect0.centre().ra_deg(), 0.0, "Test Right Ascension of centre of void constructor");
  1833 + test_value(rect0.centre().dec_deg(), 0.0, "Test Declination of centre of void constructor");
  1834 + test_value(rect0.ra(), 0.0, "Test Right Ascension of void constructor");
  1835 + test_value(rect0.dec(), 0.0, "Test Declination of void constructor");
  1836 + test_value(rect0.width(), 0.0, "Test width of void constructor");
  1837 + test_value(rect0.height(), 0.0, "Test height of void constructor");
  1838 + test_value(rect0.posang(), 0.0, "Test position angle of void constructor");
  1839 +
  1840 + // Test sky direction constructor
  1841 + GSkyDir dir1;
  1842 + dir1.radec_deg(83.6331,22.0145);
  1843 + GSkyRegionRectangle rect1(dir1, 3.1, 2.9, 43.7);
  1844 + test_value(rect1.centre().ra_deg(), 83.6331, "Test Right Ascension of centre of sky direction constructor");
  1845 + test_value(rect1.centre().dec_deg(), 22.0145, "Test Declination of centre of sky direction constructor");
  1846 + test_value(rect1.ra(), 83.6331, "Test Right Ascension of sky direction constructor");
  1847 + test_value(rect1.dec(), 22.0145, "Test Declination of sky direction constructor");
  1848 + test_value(rect1.width(), 3.1, "Test width of sky direction constructor");
  1849 + test_value(rect1.height(), 2.9, "Test height of sky direction constructor");
  1850 + test_value(rect1.posang(), 43.7, "Test position angle of sky direction constructor");
  1851 +
  1852 + // Test Right Ascension and Declination constructor
  1853 + GSkyRegionRectangle rect2(83.6331, 22.0145, 3.1, 2.9, 43.7);
  1854 + test_value(rect2.centre().ra_deg(), 83.6331, "Test Right Ascension of centre of (RA,Dec) constructor");
  1855 + test_value(rect2.centre().dec_deg(), 22.0145, "Test Declination of centre of (RA,Dec) constructor");
  1856 + test_value(rect2.ra(), 83.6331, "Test Right Ascension of (RA,Dec) constructor");
  1857 + test_value(rect2.dec(), 22.0145, "Test Declination of (RA,Dec) constructor");
  1858 + test_value(rect2.width(), 3.1, "Test width of (RA,Dec) constructor");
  1859 + test_value(rect2.height(), 2.9, "Test height of (RA,Dec) constructor");
  1860 + test_value(rect2.posang(), 43.7, "Test position angle of (RA,Dec) constructor");
  1861 +
  1862 + // Test line constructor
  1863 + GSkyRegionRectangle rect3("fk5;box(83.6331, 22.0145, 3.1, 2.9, 43.7)");
  1864 + test_value(rect3.centre().ra_deg(), 83.6331, "Test Right Ascension of centre of line constructor");
  1865 + test_value(rect3.centre().dec_deg(), 22.0145, "Test Declination of centre of line constructor");
  1866 + test_value(rect3.ra(), 83.6331, "Test Right Ascension of line constructor");
  1867 + test_value(rect3.dec(), 22.0145, "Test Declination of line constructor");
  1868 + test_value(rect3.width(), 3.1, "Test width of line constructor");
  1869 + test_value(rect3.height(), 2.9, "Test height of line constructor");
  1870 + test_value(rect3.posang(), 43.7, "Test position angle of line constructor");
  1871 +
  1872 + // Test copy constructor
  1873 + GSkyRegionRectangle rect4(rect3);
  1874 + test_value(rect4.centre().ra_deg(), 83.6331, "Test Right Ascension of centre of copy constructor");
  1875 + test_value(rect4.centre().dec_deg(), 22.0145, "Test Declination of centre of copy constructor");
  1876 + test_value(rect4.ra(), 83.6331, "Test Right Ascension of copy constructor");
  1877 + test_value(rect4.dec(), 22.0145, "Test Declination of copy constructor");
  1878 + test_value(rect4.width(), 3.1, "Test width of copy constructor");
  1879 + test_value(rect4.height(), 2.9, "Test height of copy constructor");
  1880 + test_value(rect4.posang(), 43.7, "Test position angle of copy constructor");
  1881 +
  1882 + // Test assignment operator
  1883 + GSkyRegionRectangle rect5;
  1884 + rect5 = rect3;
  1885 + test_value(rect5.centre().ra_deg(), 83.6331, "Test Right Ascension of centre of assignment operator");
  1886 + test_value(rect5.centre().dec_deg(), 22.0145, "Test Declination of centre of assignment operator");
  1887 + test_value(rect5.ra(), 83.6331, "Test Right Ascension of assignment operator");
  1888 + test_value(rect5.dec(), 22.0145, "Test Declination of assignment operator");
  1889 + test_value(rect5.width(), 3.1, "Test width of assignment operator");
  1890 + test_value(rect5.height(), 2.9, "Test height of assignment operator");
  1891 + test_value(rect5.posang(), 43.7, "Test position angle of assignment operator");
  1892 +
  1893 + // Test clone method
  1894 + GSkyRegionRectangle* rect6 = rect3.clone();
  1895 + test_value(rect6->centre().ra_deg(), 83.6331, "Test Right Ascension of centre of cloned instance");
  1896 + test_value(rect6->centre().dec_deg(), 22.0145, "Test Declination of centre of cloned instance");
  1897 + test_value(rect6->ra(), 83.6331, "Test Right Ascension of cloned instance");
  1898 + test_value(rect6->dec(), 22.0145, "Test Declination of cloned instance");
  1899 + test_value(rect6->width(), 3.1, "Test width of cloned instance");
  1900 + test_value(rect6->height(), 2.9, "Test height of cloned instance");
  1901 + test_value(rect6->posang(), 43.7, "Test position angle of cloned instance");
  1902 + delete rect6;
  1903 +
  1904 + // Test constructor error modes
  1905 + test_try("Test invalid width in sky direction constructor");
1837 1906 try {
1838   - GSkyRegionRectangle rect(refdir_radeczerozero, ref_width, ref_height, ref_pa_deg);
  1907 + GSkyRegionRectangle rect(dir1, -1.0, 2.9, 43.7);
  1908 + test_try_failure();
  1909 + }
  1910 + catch (GException::invalid_argument &e) {
1839 1911 test_try_success();
1840 1912 }
1841 1913 catch (std::exception &e) {
1842 1914 test_try_failure(e);
1843 1915 }
1844   -
1845   - // Test constructing with negative width (should be forbidden)
1846   - test_try("Test constructor2");
  1916 + //
  1917 + test_try("Test invalid width in (RA,Dec) constructor");
1847 1918 try {
1848   - GSkyRegionRectangle rect(refdir_radeczerozero, -1, ref_height, ref_pa_deg);
  1919 + GSkyRegionRectangle rect(83.6331, 22.0145, 3.1, -1.0, 43.7);
1849 1920 test_try_failure();
1850 1921 }
1851 1922 catch (GException::invalid_argument &e) {
... ... @@ -1854,11 +1925,10 @@ void TestGSky::test_GSkyRegionRectangle(void)
1854 1925 catch (std::exception &e) {
1855 1926 test_try_failure(e);
1856 1927 }
1857   -
1858   - // Test constructing with negative height (should be forbidden)
1859   - test_try("Test constructor3");
  1928 + //
  1929 + test_try("Test invalid width in line constructor");
1860 1930 try {
1861   - GSkyRegionRectangle rect(refdir_radeczerozero, ref_width, -1, ref_pa_deg);
  1931 + GSkyRegionRectangle rect("fk5;box(83.6331, 22.0145, -1.0, 2.9, 43.7)");
1862 1932 test_try_failure();
1863 1933 }
1864 1934 catch (GException::invalid_argument &e) {
... ... @@ -1867,24 +1937,56 @@ void TestGSky::test_GSkyRegionRectangle(void)
1867 1937 catch (std::exception &e) {
1868 1938 test_try_failure(e);
1869 1939 }
1870   -
1871   - // Test constructing with negative posang (should be allowed)
1872   - test_try("Test constructor4");
  1940 + //
  1941 + test_try("Test invalid height in sky direction constructor");
1873 1942 try {
1874   - GSkyRegionRectangle rect(refdir_radeczerozero, ref_width, ref_height, -1);
  1943 + GSkyRegionRectangle rect(dir1, 3.1, -1.0, 43.7);
  1944 + test_try_failure();
  1945 + }
  1946 + catch (GException::invalid_argument &e) {
1875 1947 test_try_success();
1876 1948 }
  1949 + catch (std::exception &e) {
  1950 + test_try_failure(e);
  1951 + }
  1952 + //
  1953 + test_try("Test invalid height in (RA,Dec) constructor");
  1954 + try {
  1955 + GSkyRegionRectangle rect(83.6331, 22.0145, 3.1, -1.0, 43.7);
  1956 + test_try_failure();
  1957 + }
1877 1958 catch (GException::invalid_argument &e) {
  1959 + test_try_success();
  1960 + }
  1961 + catch (std::exception &e) {
  1962 + test_try_failure(e);
  1963 + }
  1964 + //
  1965 + test_try("Test invalid height in line constructor");
  1966 + try {
  1967 + GSkyRegionRectangle rect("fk5;box(83.6331, 22.0145, 3.1, -1.0, 43.7)");
1878 1968 test_try_failure();
1879 1969 }
  1970 + catch (GException::invalid_argument &e) {
  1971 + test_try_success();
  1972 + }
1880 1973 catch (std::exception &e) {
1881 1974 test_try_failure(e);
1882 1975 }
1883 1976  
1884   - // Test assignment of neg width after construction
1885   - test_try("Test width assignment after");
  1977 + // Test assignment methods
  1978 + GSkyRegionRectangle rect7;
  1979 + rect7.width(3.1);
  1980 + rect7.height(2.9);
  1981 + rect7.posang(43.7);
  1982 + test_value(rect7.width(), 3.1, "Test width() methods");
  1983 + test_value(rect7.height(), 2.9, "Test height() methods");
  1984 + test_value(rect7.posang(), 43.7, "Test posang() methods");
  1985 +
  1986 + // Test assignment error modes
  1987 + test_try("Test invalid width() assignment");
1886 1988 try {
1887   - GSkyRegionRectangle rect(refdir_radeczerozero, ref_width, ref_height, ref_pa_deg);
  1989 + GSkyRegionRectangle rect;
1888 1990 rect.width(-1.0);
1889 1991 test_try_failure();
1890 1992 }
... ... @@ -1894,11 +1996,9 @@ void TestGSky::test_GSkyRegionRectangle(void)
1894 1996 catch (std::exception &e) {
1895 1997 test_try_failure(e);
1896 1998 }
1897   -
1898   - // Test assignment of neg height after construction
1899   - test_try("Test height assignment after");
  1999 + test_try("Test invalid height() assignment");
1900 2000 try {
1901   - GSkyRegionRectangle rect(refdir_radeczerozero, ref_width, ref_height, ref_pa_deg);
  2001 + GSkyRegionRectangle rect;
1902 2002 rect.height(-1.0);
1903 2003 test_try_failure();
1904 2004 }
... ... @@ -1909,148 +2009,138 @@ void TestGSky::test_GSkyRegionRectangle(void)
1909 2009 test_try_failure(e);
1910 2010 }
1911 2011  
1912   - // Test assignment of neg posang after construction
1913   - test_try("Test posang assignment after");
  2012 + // Test corner() method
  2013 + rect7.width(1.0);
  2014 + rect7.height(1.0);
  2015 + rect7.posang(0.0);
  2016 + test_value(rect7.corner(0).ra_deg(), 0.50001269, "Test Right Ascension of corner 0");
  2017 + test_value(rect7.corner(0).dec_deg(), 0.49999365, "Test Declination of corner 0");
  2018 + test_value(rect7.corner(1).ra_deg(), 0.50001269, "Test Right Ascension of corner 1");
  2019 + test_value(rect7.corner(1).dec_deg(), -0.49999365, "Test Declination of corner 1");
  2020 + test_value(rect7.corner(2).ra_deg(), -0.50001269, "Test Right Ascension of corner 2");
  2021 + test_value(rect7.corner(2).dec_deg(), -0.49999365, "Test Declination of corner 2");
  2022 + test_value(rect7.corner(3).ra_deg(), -0.50001269, "Test Right Ascension of corner 3");
  2023 + test_value(rect7.corner(3).dec_deg(), 0.49999365, "Test Declination of corner 3");
  2024 +
  2025 + // Test corner() method error modes
  2026 + test_try("Test corner() index < 0");
1914 2027 try {
1915   - GSkyRegionRectangle rect(refdir_radeczerozero, ref_width, ref_height, ref_pa_deg);
1916   - rect.posang(-1.0);
  2028 + GSkyRegionRectangle rect;
  2029 + GSkyDir dir = rect.corner(-1);
  2030 + test_try_failure();
  2031 + }
  2032 + catch (GException::out_of_range &e) {
1917 2033 test_try_success();
1918 2034 }
1919   - catch (GException::invalid_argument &e) {
  2035 + catch (std::exception &e) {
  2036 + test_try_failure(e);
  2037 + }
  2038 + test_try("Test corner() index > 3");
  2039 + try {
  2040 + GSkyRegionRectangle rect;
  2041 + GSkyDir dir = rect.corner(4);
1920 2042 test_try_failure();
1921 2043 }
  2044 + catch (GException::out_of_range &e) {
  2045 + test_try_success();
  2046 + }
1922 2047 catch (std::exception &e) {
1923 2048 test_try_failure(e);
1924 2049 }
1925 2050  
1926   - // Check radius assignment
1927   - GSkyRegionRectangle rect(refdir_radeczerozero, ref_width, ref_height, ref_pa_deg);
1928   -
1929   - double check_width = rect.width();
1930   - test_value(ref_width, check_width, 1.0e-10, "Test width assignment");
1931   -
1932   - double check_height = rect.width();
1933   - test_value(ref_height, check_height, 1.0e-10, "Test height assignment");
1934   -
1935   - double check_pa_deg = rect.posang();
1936   - test_value(ref_pa_deg, check_pa_deg, 1.0e-10, "Test posang assignment");
1937   -
1938   - // Check solid angle assignment
1939   - double solidangle_check = rect.solidangle();
1940   - double solidangle = ref_width*gammalib::deg2rad * ref_height*gammalib::deg2rad;
1941   - test_value(solidangle_check, solidangle, 1.0e-10, "Test solid angle");
1942   -
1943   - // Initialise objects
1944   - refdir_radeczerozero = GSkyDir();
1945   - GSkyDir test_dir_0 = GSkyDir();
1946   - GSkyDir test_dir_1 = GSkyDir();
1947   - GSkyDir test_dir_2 = GSkyDir();
1948   -
1949   - refdir_radeczerozero.radec_deg(0,0);
1950   - GSkyRegionRectangle refregion(refdir_radeczerozero, 10, 6, 0);
1951   -
1952   - // Check GSkyDir containment
1953   - // Upper right
1954   - test_dir_0.radec_deg(6, 2);
1955   - test_dir_1.radec_deg(4, 2);
1956   - test_dir_2.radec_deg(4, 4);
1957   - test_assert(!refregion.contains(test_dir_0),"test for containment");
1958   - test_assert(refregion.contains(test_dir_1),"test for containment");
1959   - test_assert(!refregion.contains(test_dir_2),"test for containment");
1960   -
1961   - // Upper left
1962   - test_dir_0.radec_deg(-6, 2);
1963   - test_dir_1.radec_deg(-4, 2);
1964   - test_dir_2.radec_deg(-4, 4);
1965   - test_assert(!refregion.contains(test_dir_0),"test for containment");
1966   - test_assert(refregion.contains(test_dir_1),"test for containment");
1967   - test_assert(!refregion.contains(test_dir_2),"test for containment");
1968   -
1969   - // Lower left
1970   - test_dir_0.radec_deg(-6, -2);
1971   - test_dir_1.radec_deg(-4, -2);
1972   - test_dir_2.radec_deg(-4, -4);
1973   - test_assert(!refregion.contains(test_dir_0),"test for containment");
1974   - test_assert(refregion.contains(test_dir_1),"test for containment");
1975   - test_assert(!refregion.contains(test_dir_2),"test for containment");
1976   -
1977   - // Lower right
1978   - test_dir_0.radec_deg(6, -2);
1979   - test_dir_1.radec_deg(4, -2);
1980   - test_dir_2.radec_deg(4, -4);
1981   - test_assert(!refregion.contains(test_dir_0),"test for containment");
1982   - test_assert(refregion.contains(test_dir_1),"test for containment");
1983   - test_assert(!refregion.contains(test_dir_2),"test for containment");
1984   -
1985   - // Corners
1986   - test_assert(refregion.contains(refregion.corner(0)),"test for corner containment");
1987   - test_assert(refregion.contains(refregion.corner(1)),"test for corner containment");
1988   - test_assert(refregion.contains(refregion.corner(2)),"test for corner containment");
1989   - test_assert(refregion.contains(refregion.corner(3)),"test for corner containment");
1990   -
1991   -
1992   - // Check GSkyDir containment for rotated rectangle
1993   - GSkyRegionRectangle refregion_rot(refdir_radeczerozero, 10, 10, 45);
1994   -
1995   - // Check corner containment
1996   - test_assert(refregion_rot.contains(refregion_rot.corner(0)),"test for corner containment");
1997   - test_assert(refregion_rot.contains(refregion_rot.corner(1)),"test for corner containment");
1998   - test_assert(refregion_rot.contains(refregion_rot.corner(2)),"test for corner containment");
1999   - test_assert(refregion_rot.contains(refregion_rot.corner(3)),"test for corner containment");
2000   -
2001   - // Check GSkyDir containment
2002   - test_dir_0.radec_deg(refregion_rot.corner(0).ra_deg()+1, 0);
2003   - test_dir_1.radec_deg(refregion_rot.corner(0).ra_deg() , 0);
2004   - test_dir_2.radec_deg(refregion_rot.corner(0).ra_deg()-1, 0);
2005   - test_assert(!refregion_rot.contains(test_dir_0),"test for containment");
2006   - test_assert(refregion_rot.contains(test_dir_1),"test for containment");
2007   - test_assert(refregion_rot.contains(test_dir_2),"test for containment");
2008   -
2009   - // Check local<->global coordinate transformations
2010   - /*
2011   - test_dir_0.radec_deg(50,50);
2012   - test_dir_1 = refregion_rot.transform_to_local(test_dir_0);
2013   - test_dir_2 = refregion_rot.transform_to_global(test_dir_1);
2014   - test_value(test_dir_0.ra(), test_dir_2.ra(), 1.0e-10, "Test coord trafo");
2015   - test_value(test_dir_0.dec(), test_dir_2.dec(), 1.0e-10, "Test coord trafo");
2016   - */
2017   -
2018   - // Check other rects containment
2019   - GSkyDir refdir_raoffset = GSkyDir();
2020   - refdir_raoffset.radec_deg(5,0);
2021   -
2022   - GSkyDir refdir_rapole = GSkyDir();
2023   - refdir_rapole.radec_deg(359,0);
2024   -
2025   - GSkyDir refdir_decpole = GSkyDir();
2026   - refdir_decpole.radec_deg(0,89);
2027   -
2028   - GSkyDir refdir_ndecpole = GSkyDir();
2029   - refdir_ndecpole.radec_deg(100,89);
2030   -
2031   - GSkyRegionRectangle refregion_smaller(refdir_radeczerozero, 5, 3, 0);
2032   - GSkyRegionRectangle refregion_larger(refdir_radeczerozero, 20, 12, 0);
2033   - GSkyRegionRectangle refregion_raoffset(refdir_raoffset, 10, 6, 0);
2034   - GSkyRegionRectangle refregion_rapole(refdir_rapole, 3, 3, 0);
2035   - GSkyRegionRectangle refregion_decpole(refdir_decpole, 3, 3, 0);
2036   -
2037   - // Test contain dirs (same from circle)
2038   - test_assert(refregion.contains(refdir_radeczerozero),"test for containment");
2039   - test_assert(refregion.contains(refregion.centre()), "test if centre in rectangle");
2040   -
2041   - // Test contain regions (same from circle)
2042   - test_assert(refregion.contains(refregion_smaller),"test for containment region");
2043   - test_assert(!refregion.contains(refregion_larger), "test for containment region2 ");
2044   - test_assert(refregion.contains(refregion), "test3 for containment region");
2045   -
2046   - test_assert(refregion.contains(refdir_rapole), "rapole for containment region");
2047   - test_assert(refregion_decpole.contains(refdir_ndecpole), "rapole for containment region");
2048   -
2049   - // Test overlaps (same from circle)
2050   - test_assert(refregion.overlaps(refregion_smaller),"test for overlap");
2051   - test_assert(refregion.overlaps(refregion_larger),"test2 for overlap");
2052   - test_assert(refregion.overlaps(refregion_raoffset),"test3 for overlap");
2053   - test_assert(!refregion.overlaps(refregion_decpole),"test4 for overlap");
  2051 + // Test solid angle computation
  2052 + GSkyRegionRectangle rect8(83.6331, 22.0145, 3.1, 2.9, 43.7);
  2053 + double ref = 3.1*gammalib::deg2rad * 2.9*gammalib::deg2rad;
  2054 + test_value(rect8.solidangle(), ref, "Test solid angle computation");
  2055 +
  2056 + // Test sky direction contains() method
  2057 + GSkyRegionRectangle rect9(1.0, 1.0, 6.0, 10.0, 45.0);
  2058 + GSkyDir test_dir;
  2059 + test_dir.radec_deg(-3.0, 0.0);
  2060 + test_assert(rect9.contains(test_dir), "Test whether (-3,0) lies inside rectangle");
  2061 + test_dir.radec_deg(2.0, 6.0);
  2062 + test_assert(rect9.contains(test_dir), "Test whether (2,6) lies inside rectangle");
  2063 + test_dir.radec_deg(5.0, 4.0);
  2064 + test_assert(rect9.contains(test_dir), "Test whether (5,4) lies inside rectangle");
  2065 + test_dir.radec_deg(1.0, -3.0);
  2066 + test_assert(rect9.contains(test_dir), "Test whether (1,-3) lies inside rectangle");
  2067 + test_dir.radec_deg(-2.0, 3.0);
  2068 + test_assert(!rect9.contains(test_dir), "Test whether (-2,3) lies outside rectangle");
  2069 + test_dir.radec_deg(3.0, 7.0);
  2070 + test_assert(!rect9.contains(test_dir), "Test whether (3,7) lies outside rectangle");
  2071 + test_dir.radec_deg(7.0, 3.0);
  2072 + test_assert(!rect9.contains(test_dir), "Test whether (7,3) lies outside rectangle");
  2073 + test_dir.radec_deg(2.0, -5.0);
  2074 + test_assert(!rect9.contains(test_dir), "Test whether (2,-5) lies outside rectangle");
  2075 + test_dir.radec_deg(-2.0, -4.0);
  2076 + test_assert(!rect9.contains(test_dir), "Test whether (-2,-4) lies outside rectangle");
  2077 +
  2078 + // Test whether corners are contained
  2079 + test_assert(rect9.contains(rect9.corner(0)), "Test whether corner(0) lies inside rectangle");
  2080 + test_assert(rect9.contains(rect9.corner(1)), "Test whether corner(1) lies inside rectangle");
  2081 + test_assert(rect9.contains(rect9.corner(2)), "Test whether corner(2) lies inside rectangle");
  2082 + test_assert(rect9.contains(rect9.corner(3)), "Test whether corner(3) lies inside rectangle");
  2083 +
  2084 + // Test region contains() and overlaps() methods for circle
  2085 + GSkyRegionCircle circle1(1.0, 1.0, 3.0);
  2086 + GSkyRegionCircle circle2(1.0, 1.0, 3.1);
  2087 + GSkyRegionCircle circle3(7.0, 5.0, 0.5);
  2088 + test_assert(rect9.contains(circle1), "Test whether circle is contained in rectangle");
  2089 + test_assert(!rect9.contains(circle2), "Test whether circle is not contained in rectangle");
  2090 + test_assert(rect9.overlaps(circle2), "Test whether circle overlaps with rectangle");
  2091 + test_assert(!rect9.overlaps(circle3), "Test whether circle does not overlap with rectangle");
  2092 +
  2093 + // Test region contains() and overlaps() methods for rectangles
  2094 + GSkyRegionRectangle rect10(1.0, 1.0, 6.1, 10.1, 45.0);
  2095 + GSkyRegionRectangle rect11(6.0, -4.0, 6.0, 10.0, 45.0);
  2096 + test_assert(rect9.contains(rect9), "Test whether rectangle is contained in rectangle");
  2097 + test_assert(!rect9.contains(rect10), "Test whether rectangle is not contained in rectangle");
  2098 + test_assert(rect9.overlaps(rect10), "Test whether rectangle overlaps with rectangle");
  2099 + test_assert(!rect9.overlaps(rect11), "Test whether rectangle does not overlap with rectangle");
  2100 +
  2101 + // Test region contains() and overlaps() methods for maps. The map region
  2102 + // is centred at (0,0) and has a radius of 0.3 deg.
  2103 + GSkyRegionMap map1(sky_region_map);
  2104 + GSkyRegionRectangle rect12(0.0, 0.0, 0.6, 0.6, 45.0);
  2105 + GSkyRegionRectangle rect13(0.0, 0.0, 0.59, 0.59, 45.0);
  2106 + GSkyRegionRectangle rect14(0.6, 0.0, 0.6, 0.6, 0.0);
  2107 + test_assert(rect12.contains(map1), "Test whether map is contained in rectangle");
  2108 + test_assert(!rect13.contains(map1), "Test whether map is not contained in rectangle");
  2109 + test_assert(rect13.overlaps(map1), "Test whether map overlaps with rectangle");
  2110 + test_assert(!rect14.overlaps(map1), "Test whether map does not overlap with rectangle");
  2111 +
  2112 + // Test print() method
  2113 + test_assert(!rect9.print().empty(), "Test whether print() method returns something");
  2114 +
  2115 + // Test read() and write() methods
  2116 + GSkyRegionRectangle rect15;
  2117 + rect15.read("fk5;box(83.6331, 22.0145, 3.1, 2.9, 43.7)");
  2118 + test_value(rect15.centre().ra_deg(), 83.6331, "Test Right Ascension of centre after read()");
  2119 + test_value(rect15.centre().dec_deg(), 22.0145, "Test Declination of centre after read()");
  2120 + test_value(rect15.ra(), 83.6331, "Test Right Ascension after read()");
  2121 + test_value(rect15.dec(), 22.0145, "Test Declination after read()");
  2122 + test_value(rect15.width(), 3.1, "Test width after read()");
  2123 + test_value(rect15.height(), 2.9, "Test height after read()");
  2124 + test_value(rect15.posang(), 43.7, "Test position angle after read()");
  2125 + std::string region = rect15.write();
  2126 + rect14.read(region);
  2127 + test_value(rect14.centre().ra_deg(), 83.6331, "Test Right Ascension of centre after second read()");
  2128 + test_value(rect14.centre().dec_deg(), 22.0145, "Test Declination of centre after second read()");
  2129 + test_value(rect14.ra(), 83.6331, "Test Right Ascension after second read()");
  2130 + test_value(rect14.dec(), 22.0145, "Test Declination after second read()");
  2131 + test_value(rect14.width(), 3.1, "Test width after second read()");
  2132 + test_value(rect14.height(), 2.9, "Test height after second read()");
  2133 + test_value(rect14.posang(), 43.7, "Test position angle after second read()");
  2134 +
  2135 + // Test clear method
  2136 + rect9.clear();
  2137 + test_value(rect9.centre().ra_deg(), 0.0, "Test Right Ascension of centre after clear()");
  2138 + test_value(rect9.centre().dec_deg(), 0.0, "Test Declination of centre after clear()");
  2139 + test_value(rect9.ra(), 0.0, "Test Right Ascension after clear()");
  2140 + test_value(rect9.dec(), 0.0, "Test Declination after clear()");
  2141 + test_value(rect9.width(), 0.0, "Test width after clear()");
  2142 + test_value(rect9.height(), 0.0, "Test height after clear()");
  2143 + test_value(rect9.posang(), 0.0, "Test position angle after clear()");
2054 2144  
2055 2145 // Exit test
2056 2146 return;
... ...