mirror of https://github.com/KLayout/klayout.git
Fixed #41 (Polygon#touches? method)
This commit is contained in:
parent
f796ff8971
commit
6f66e04c8e
|
|
@ -210,6 +210,26 @@ struct simple_polygon_defs
|
|||
return std_ext::hfunc (*p);
|
||||
}
|
||||
|
||||
static bool touches_box (const C *p, const db::box<coord_type> &box)
|
||||
{
|
||||
return db::interact (*p, box);
|
||||
}
|
||||
|
||||
static bool touches_edge (const C *p, const db::edge<coord_type> &edge)
|
||||
{
|
||||
return db::interact (*p, edge);
|
||||
}
|
||||
|
||||
static bool touches_poly (const C *p, const db::polygon<coord_type> &poly)
|
||||
{
|
||||
return db::interact (*p, poly);
|
||||
}
|
||||
|
||||
static bool touches_spoly (const C *p, const db::simple_polygon<coord_type> &spoly)
|
||||
{
|
||||
return db::interact (*p, spoly);
|
||||
}
|
||||
|
||||
static gsi::Methods methods ()
|
||||
{
|
||||
return
|
||||
|
|
@ -485,7 +505,32 @@ struct simple_polygon_defs
|
|||
) +
|
||||
method ("bbox", &C::box,
|
||||
"@brief Return the bounding box of the simple polygon"
|
||||
);
|
||||
) +
|
||||
method_ext ("touches?", &touches_box, gsi::arg ("box"),
|
||||
"@brief Returns true, if the polygon touches the given box.\n"
|
||||
"The box and the polygon touch if they overlap or their contours share at least one point.\n"
|
||||
"\n"
|
||||
"This method was introduced in version 0.25.1.\n"
|
||||
) +
|
||||
method_ext ("touches?", &touches_edge, gsi::arg ("edge"),
|
||||
"@brief Returns true, if the polygon touches the given edge.\n"
|
||||
"The box and the polygon touch if they overlap or the edge shares at least one point with the polygon's contour.\n"
|
||||
"\n"
|
||||
"This method was introduced in version 0.25.1.\n"
|
||||
) +
|
||||
method_ext ("touches?", &touches_poly, gsi::arg ("polygon"),
|
||||
"@brief Returns true, if the polygon touches the other polygon.\n"
|
||||
"The polygons touch if they overlap or their contours share at least one point.\n"
|
||||
"\n"
|
||||
"This method was introduced in version 0.25.1.\n"
|
||||
) +
|
||||
method_ext ("touches?", &touches_spoly, gsi::arg ("simple_polygon"),
|
||||
"@brief Returns true, if the polygon touches the other polygon.\n"
|
||||
"The polygons touch if they overlap or their contours share at least one point.\n"
|
||||
"\n"
|
||||
"This method was introduced in version 0.25.1.\n"
|
||||
)
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -993,6 +1038,26 @@ struct polygon_defs
|
|||
return std_ext::hfunc (*p);
|
||||
}
|
||||
|
||||
static bool touches_box (const C *p, const db::box<coord_type> &box)
|
||||
{
|
||||
return db::interact (*p, box);
|
||||
}
|
||||
|
||||
static bool touches_edge (const C *p, const db::edge<coord_type> &edge)
|
||||
{
|
||||
return db::interact (*p, edge);
|
||||
}
|
||||
|
||||
static bool touches_poly (const C *p, const db::polygon<coord_type> &poly)
|
||||
{
|
||||
return db::interact (*p, poly);
|
||||
}
|
||||
|
||||
static bool touches_spoly (const C *p, const db::simple_polygon<coord_type> &spoly)
|
||||
{
|
||||
return db::interact (*p, spoly);
|
||||
}
|
||||
|
||||
static gsi::Methods methods ()
|
||||
{
|
||||
return
|
||||
|
|
@ -1435,7 +1500,32 @@ struct polygon_defs
|
|||
method ("bbox", &C::box,
|
||||
"@brief Return the bounding box of the polygon\n"
|
||||
"The bounding box is the box enclosing all points of the polygon.\n"
|
||||
);
|
||||
) +
|
||||
method_ext ("touches?", &touches_box, gsi::arg ("box"),
|
||||
"@brief Returns true, if the polygon touches the given box.\n"
|
||||
"The box and the polygon touch if they overlap or their contours share at least one point.\n"
|
||||
"\n"
|
||||
"This method was introduced in version 0.25.1.\n"
|
||||
) +
|
||||
method_ext ("touches?", &touches_edge, gsi::arg ("edge"),
|
||||
"@brief Returns true, if the polygon touches the given edge.\n"
|
||||
"The box and the polygon touch if they overlap or the edge shares at least one point with the polygon's contour.\n"
|
||||
"\n"
|
||||
"This method was introduced in version 0.25.1.\n"
|
||||
) +
|
||||
method_ext ("touches?", &touches_poly, gsi::arg ("polygon"),
|
||||
"@brief Returns true, if the polygon touches the other polygon.\n"
|
||||
"The polygons touch if they overlap or their contours share at least one point.\n"
|
||||
"\n"
|
||||
"This method was introduced in version 0.25.1.\n"
|
||||
) +
|
||||
method_ext ("touches?", &touches_spoly, gsi::arg ("simple_polygon"),
|
||||
"@brief Returns true, if the polygon touches the other polygon.\n"
|
||||
"The polygons touch if they overlap or their contours share at least one point.\n"
|
||||
"\n"
|
||||
"This method was introduced in version 0.25.1.\n"
|
||||
)
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -659,6 +659,67 @@ class DBPolygon_TestClass < TestBase
|
|||
|
||||
end
|
||||
|
||||
# touches predicate
|
||||
def test_touches
|
||||
|
||||
p1 = RBA::Polygon::new(RBA::Box::new(10, 20, 30, 40))
|
||||
assert_equal(p1.touches?(RBA::Polygon::new(RBA::Box::new(30, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::Polygon::new(RBA::Box::new(31, 20, 40, 50))), false)
|
||||
assert_equal(p1.touches?(RBA::Polygon::new(RBA::Box::new(29, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::SimplePolygon::new(RBA::Box::new(30, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::SimplePolygon::new(RBA::Box::new(31, 20, 40, 50))), false)
|
||||
assert_equal(p1.touches?(RBA::SimplePolygon::new(RBA::Box::new(29, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::Box::new(30, 20, 40, 50)), true)
|
||||
assert_equal(p1.touches?(RBA::Box::new(31, 20, 40, 50)), false)
|
||||
assert_equal(p1.touches?(RBA::Box::new(29, 20, 40, 50)), true)
|
||||
assert_equal(p1.touches?(RBA::Edge::new(30, 20, 40, 50)), true)
|
||||
assert_equal(p1.touches?(RBA::Edge::new(31, 20, 40, 50)), false)
|
||||
assert_equal(p1.touches?(RBA::Edge::new(29, 20, 40, 50)), true)
|
||||
|
||||
p1 = RBA::SimplePolygon::new(RBA::Box::new(10, 20, 30, 40))
|
||||
assert_equal(p1.touches?(RBA::Polygon::new(RBA::Box::new(30, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::Polygon::new(RBA::Box::new(31, 20, 40, 50))), false)
|
||||
assert_equal(p1.touches?(RBA::Polygon::new(RBA::Box::new(29, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::SimplePolygon::new(RBA::Box::new(30, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::SimplePolygon::new(RBA::Box::new(31, 20, 40, 50))), false)
|
||||
assert_equal(p1.touches?(RBA::SimplePolygon::new(RBA::Box::new(29, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::Box::new(30, 20, 40, 50)), true)
|
||||
assert_equal(p1.touches?(RBA::Box::new(31, 20, 40, 50)), false)
|
||||
assert_equal(p1.touches?(RBA::Box::new(29, 20, 40, 50)), true)
|
||||
assert_equal(p1.touches?(RBA::Edge::new(30, 20, 40, 50)), true)
|
||||
assert_equal(p1.touches?(RBA::Edge::new(31, 20, 40, 50)), false)
|
||||
assert_equal(p1.touches?(RBA::Edge::new(29, 20, 40, 50)), true)
|
||||
|
||||
p1 = RBA::DPolygon::new(RBA::DBox::new(10, 20, 30, 40))
|
||||
assert_equal(p1.touches?(RBA::DPolygon::new(RBA::DBox::new(30, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::DPolygon::new(RBA::DBox::new(31, 20, 40, 50))), false)
|
||||
assert_equal(p1.touches?(RBA::DPolygon::new(RBA::DBox::new(29, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::DSimplePolygon::new(RBA::DBox::new(30, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::DSimplePolygon::new(RBA::DBox::new(31, 20, 40, 50))), false)
|
||||
assert_equal(p1.touches?(RBA::DSimplePolygon::new(RBA::DBox::new(29, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::DBox::new(30, 20, 40, 50)), true)
|
||||
assert_equal(p1.touches?(RBA::DBox::new(31, 20, 40, 50)), false)
|
||||
assert_equal(p1.touches?(RBA::DBox::new(29, 20, 40, 50)), true)
|
||||
assert_equal(p1.touches?(RBA::DEdge::new(30, 20, 40, 50)), true)
|
||||
assert_equal(p1.touches?(RBA::DEdge::new(31, 20, 40, 50)), false)
|
||||
assert_equal(p1.touches?(RBA::DEdge::new(29, 20, 40, 50)), true)
|
||||
|
||||
p1 = RBA::DSimplePolygon::new(RBA::DBox::new(10, 20, 30, 40))
|
||||
assert_equal(p1.touches?(RBA::DPolygon::new(RBA::DBox::new(30, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::DPolygon::new(RBA::DBox::new(31, 20, 40, 50))), false)
|
||||
assert_equal(p1.touches?(RBA::DPolygon::new(RBA::DBox::new(29, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::DSimplePolygon::new(RBA::DBox::new(30, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::DSimplePolygon::new(RBA::DBox::new(31, 20, 40, 50))), false)
|
||||
assert_equal(p1.touches?(RBA::DSimplePolygon::new(RBA::DBox::new(29, 20, 40, 50))), true)
|
||||
assert_equal(p1.touches?(RBA::DBox::new(30, 20, 40, 50)), true)
|
||||
assert_equal(p1.touches?(RBA::DBox::new(31, 20, 40, 50)), false)
|
||||
assert_equal(p1.touches?(RBA::DBox::new(29, 20, 40, 50)), true)
|
||||
assert_equal(p1.touches?(RBA::DEdge::new(30, 20, 40, 50)), true)
|
||||
assert_equal(p1.touches?(RBA::DEdge::new(31, 20, 40, 50)), false)
|
||||
assert_equal(p1.touches?(RBA::DEdge::new(29, 20, 40, 50)), true)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
load("test_epilogue.rb")
|
||||
|
|
|
|||
Loading…
Reference in New Issue