Merge branch 'points-as-db-objects'

This commit is contained in:
Matthias Koefferlein 2022-12-07 21:59:02 +01:00
commit d81e0ba51e
19 changed files with 613 additions and 31 deletions

View File

@ -56,7 +56,7 @@ class ArrayRepository;
* coordinates box).
*/
template <class C, class R = C>
template <class C, class R>
struct DB_PUBLIC_TEMPLATE box
{
typedef C coord_type;

View File

@ -63,6 +63,7 @@ public:
typedef db::coord_traits<C> coord_traits;
typedef typename coord_traits::distance_type distance_type;
typedef typename coord_traits::area_type area_type;
typedef typename coord_traits::perimeter_type perimeter_type;
typedef db::object_tag< edge_pair<C> > tag;
/**
@ -379,6 +380,30 @@ public:
return box_type (m_first.p1 (), m_first.p2 ()) + box_type (m_second.p1 (), m_second.p2 ());
}
/**
* @brief Gets the perimeter of the edge pair
*
* The perimeter is defined by then sum of the lengths of the edges ("active perimeter")
*/
perimeter_type perimeter () const
{
return m_first.length () + m_second.length ();
}
/**
* @brief Gets the area of the edge pair
*
* This is the area covered between the edges.
*/
area_type area () const
{
vector_type v12 = m_first.p2 () - m_first.p1 ();
vector_type v13 = m_second.p1 () - m_first.p1 ();
vector_type v14 = m_second.p2 () - m_first.p1 ();
area_type a = (db::vprod (v12, v13) + db::vprod (v13, v14)) / 2;
return a < 0 ? -a : a;
}
/**
* @brief Test if the edges are orthogonal (vertical or horizontal)
*/

View File

@ -194,6 +194,9 @@ typedef object_with_properties<DPath> DPathWithProperties;
typedef object_with_properties<PathRef> PathRefWithProperties;
typedef object_with_properties<DPathRef> DPathRefWithProperties;
typedef object_with_properties<Point> PointWithProperties;
typedef object_with_properties<DPoint> DPointWithProperties;
typedef object_with_properties<Edge> EdgeWithProperties;
typedef object_with_properties<DEdge> DEdgeWithProperties;

View File

@ -28,6 +28,7 @@
#include "dbCommon.h"
#include "dbTypes.h"
#include "dbObjectTag.h"
#include "tlString.h"
#include "tlTypeTraits.h"
#include "tlVector.h"
@ -37,6 +38,9 @@
namespace db {
template <class C> class vector;
template <class C, class R = C> struct box;
template <class C> class generic_repository;
class ArrayRepository;
/**
* @brief A point class
@ -51,6 +55,9 @@ public:
typedef db::vector<C> vector_type;
typedef typename coord_traits::distance_type distance_type;
typedef typename coord_traits::area_type area_type;
typedef db::object_tag< point<C> > tag;
typedef db::box<C> box_type;
typedef db::point<C> point_type;
/**
* @brief Default constructor
@ -321,6 +328,24 @@ public:
*/
bool less (const point<C> &p) const;
/**
* @brief The (dummy) translation operator
*/
void translate (const point<C> &d, db::generic_repository<C> &, db::ArrayRepository &)
{
*this = d;
}
/**
* @brief The (dummy) translation operator
*/
template <class T>
void translate (const point<C> &d, const T &t, db::generic_repository<C> &, db::ArrayRepository &)
{
*this = d;
transform (t);
}
private:
C m_x, m_y;
};

View File

@ -95,6 +95,8 @@ db::properties_id_type Shape::prop_id () const
return (**((pedge_iter_type *) m_generic.iter)).properties_id ();
case EdgePair:
return (**((pedge_pair_iter_type *) m_generic.iter)).properties_id ();
case Point:
return (**((ppoint_iter_type *) m_generic.iter)).properties_id ();
case Path:
return (**((ppath_iter_type *) m_generic.iter)).properties_id ();
case PathRef:
@ -144,6 +146,8 @@ db::properties_id_type Shape::prop_id () const
return m_generic.pedge->properties_id ();
case EdgePair:
return m_generic.pedge_pair->properties_id ();
case Point:
return m_generic.ppoint->properties_id ();
case Path:
return m_generic.ppath->properties_id ();
case PathRef:
@ -564,6 +568,9 @@ Shape::box_type Shape::box () const
return m_trans * basic_ptr (box_array_type::tag ())->object ();
} else if (m_type == ShortBoxArrayMember) {
return m_trans * basic_ptr (short_box_array_type::tag ())->object ();
} else if (m_type == Point) {
point_type pt = point ();
return m_trans * box_type (pt, pt);
} else {
raise_no_box ();
}
@ -614,6 +621,12 @@ Shape::perimeter_type Shape::perimeter () const
const short_box_array_type *arr = basic_ptr (short_box_array_type::tag ());
return arr->size () * arr->object ().perimeter ();
}
case Point:
return 0;
case Edge:
return edge ().length ();
case EdgePair:
return edge_pair ().perimeter ();
case Box:
case ShortBox:
case BoxArrayMember:
@ -629,6 +642,9 @@ size_t Shape::array_size () const
switch (m_type) {
case Null:
return 0;
case Point:
case Edge:
case EdgePair:
case Polygon:
case PolygonRef:
case PolygonPtrArrayMember:
@ -681,6 +697,11 @@ Shape::area_type Shape::area () const
switch (m_type) {
case Null:
return area_type ();
case Point:
case Edge:
return 0;
case EdgePair:
return edge_pair ().area ();
case Polygon:
return polygon ().area ();
case PolygonRef:
@ -761,6 +782,8 @@ Shape::box_type Shape::bbox () const
return box_type (edge ().p1 (), edge ().p2 ());
case EdgePair:
return edge_pair ().bbox ();
case Point:
return box_type (point (), point ());
case Path:
return path ().box ();
case PathRef:
@ -835,6 +858,9 @@ Shape::to_string () const
case EdgePair:
r = "edge_pair " + edge_pair ().to_string ();
break;
case Point:
r = "point " + point ().to_string ();
break;
case Path:
case PathRef:
case PathPtrArrayMember:

View File

@ -645,6 +645,7 @@ public:
typedef tl::reuse_vector<db::array<path_ptr_type, disp_type> >::const_iterator path_ptr_array_iter_type;
typedef tl::reuse_vector<db::edge<coord_type> >::const_iterator edge_iter_type;
typedef tl::reuse_vector<db::edge_pair<coord_type> >::const_iterator edge_pair_iter_type;
typedef tl::reuse_vector<db::point<coord_type> >::const_iterator point_iter_type;
typedef tl::reuse_vector<db::text<coord_type> >::const_iterator text_iter_type;
typedef tl::reuse_vector<db::text_ref<text_type, disp_type> >::const_iterator text_ref_iter_type;
typedef tl::reuse_vector<db::text_ref<text_type, unit_trans_type> >::const_iterator text_ptr_iter_type;
@ -669,6 +670,7 @@ public:
typedef tl::reuse_vector<db::object_with_properties<db::array<path_ptr_type, disp_type> > >::const_iterator ppath_ptr_array_iter_type;
typedef tl::reuse_vector<db::object_with_properties<db::edge<coord_type> > >::const_iterator pedge_iter_type;
typedef tl::reuse_vector<db::object_with_properties<db::edge_pair<coord_type> > >::const_iterator pedge_pair_iter_type;
typedef tl::reuse_vector<db::object_with_properties<db::point<coord_type> > >::const_iterator ppoint_iter_type;
typedef tl::reuse_vector<db::object_with_properties<db::text<coord_type> > >::const_iterator ptext_iter_type;
typedef tl::reuse_vector<db::object_with_properties<db::text_ref<text_type, disp_type> > >::const_iterator ptext_ref_iter_type;
typedef tl::reuse_vector<db::object_with_properties<db::text_ref<text_type, unit_trans_type> > >::const_iterator ptext_ptr_iter_type;
@ -709,6 +711,7 @@ public:
TextRef,
TextPtrArray,
TextPtrArrayMember,
Point,
UserObject
};
@ -1029,6 +1032,14 @@ public:
m_type = EdgePair;
}
/**
* @brief Construct a shape proxy as a reference to a point
*/
void init (point_type::tag)
{
m_type = Point;
}
/**
* @brief Construct a shape proxy as a reference to a box
*/
@ -1373,6 +1384,22 @@ public:
}
}
/**
* @brief Return the actual object that this shape reference is pointing to
*
* This is a generalization of the polygon (), etc. methods using a tag to identify the
* target object.
*/
const point_type *basic_ptr (point_type::tag) const
{
tl_assert (m_type == Point);
if (m_stable) {
return m_with_props ? &**(((ppoint_iter_type *) m_generic.iter)) : &**(((point_iter_type *) m_generic.iter));
} else {
return m_with_props ? m_generic.ppoint : m_generic.point;
}
}
/**
* @brief Return the actual object that this shape reference is pointing to
*
@ -1682,6 +1709,23 @@ public:
}
}
/**
* @brief Return the actual object that this shape reference is pointing to for objects with properties
*
* This is a generalization of the polygon (), etc. methods using a tag to identify the
* target object.
*/
const db::object_with_properties<point_type> *basic_ptr (db::object_with_properties<point_type>::tag) const
{
tl_assert (m_type == Point);
tl_assert (m_with_props);
if (m_stable) {
return &**(((ppoint_iter_type *) m_generic.iter));
} else {
return m_generic.ppoint;
}
}
/**
* @brief Return the actual object that this shape reference is pointing to for objects with properties
*
@ -1917,6 +1961,15 @@ public:
return *(((edge_pair_iter_type *) m_generic.iter));
}
/**
* @brief Return the iterator (in stable reference mode) by tag
*/
point_iter_type basic_iter (point_type::tag) const
{
tl_assert (m_type == Point && ! m_with_props);
return *(((point_iter_type *) m_generic.iter));
}
/**
* @brief Return the iterator (in stable reference mode) by tag
*/
@ -2088,6 +2141,15 @@ public:
return *(((pedge_pair_iter_type *) m_generic.iter));
}
/**
* @brief Return the iterator (in stable reference mode) by tag for objects with properties
*/
ppoint_iter_type basic_iter (db::object_with_properties<point_type>::tag) const
{
tl_assert (m_type == Point && m_with_props);
return *(((ppoint_iter_type *) m_generic.iter));
}
/**
* @brief Return the iterator (in stable reference mode) by tag for objects with properties
*/
@ -2395,6 +2457,49 @@ public:
return edge_pair (p);
}
/**
* @brief Return a reference to the point if one is referenced
*/
const point_type &point () const
{
tl_assert (m_type == Point);
return *basic_ptr (point_type::tag ());
}
/**
* @brief Test if the shape proxy points to a point
*/
bool is_point () const
{
return (m_type == Point);
}
/**
* @brief Instantiate the edge object
*
* If a edge is referenced, this object is instantiated
* by this method.
* Returns true, if the conversion was successful.
*/
bool point (point_type &p) const
{
if (is_point ()) {
p = point ();
return true;
} else {
return false;
}
}
/**
* @brief Alias for polymorphic expansion
* Returns true, if the conversion was successful.
*/
bool instantiate (point_type &p) const
{
return point (p);
}
/**
* @brief Return a reference to the text if one is referenced
*/
@ -2675,6 +2780,7 @@ public:
const text_ptr_array_type *text_aref;
const edge_type *edge;
const edge_pair_type *edge_pair;
const point_type *point;
const path_type *path;
const path_ref_type *path_ref;
const path_ptr_array_type *path_aref;
@ -2695,6 +2801,7 @@ public:
const db::object_with_properties<text_ptr_array_type> *ptext_aref;
const db::object_with_properties<edge_type> *pedge;
const db::object_with_properties<edge_pair_type> *pedge_pair;
const db::object_with_properties<point_type> *ppoint;
const db::object_with_properties<path_type> *ppath;
const db::object_with_properties<path_ref_type> *ppath_ref;
const db::object_with_properties<path_ptr_array_type> *ppath_aref;

View File

@ -641,6 +641,9 @@ ShapeIterator::advance_generic (int mode)
case EdgePair:
if (advance_shape<edge_pair_type, StableTag, RegionTag> (mode)) return;
break;
case Point:
if (advance_shape<point_type, StableTag, RegionTag> (mode)) return;
break;
case Path:
if (advance_shape<path_type, StableTag, RegionTag> (mode)) return;
break;
@ -767,6 +770,8 @@ ShapeIterator::quad_box_generic () const
return (quad_box_by_shape<edge_type, StableTag> (region_tag));
case EdgePair:
return (quad_box_by_shape<edge_pair_type, StableTag> (region_tag));
case Point:
return (quad_box_by_shape<point_type, StableTag> (region_tag));
case Path:
return (quad_box_by_shape<path_type, StableTag> (region_tag));
case PathRef:

View File

@ -375,6 +375,8 @@ Shapes::do_insert (const Shapes::shape_type &shape, const Shapes::unit_trans_typ
return (insert_by_tag (shape_type::edge_type::tag (), shape, pm));
case shape_type::EdgePair:
return (insert_by_tag (shape_type::edge_pair_type::tag (), shape, pm));
case shape_type::Point:
return (insert_by_tag (shape_type::point_type::tag (), shape, pm));
case shape_type::Path:
return (insert_by_tag (shape_type::path_type::tag (), shape, pm));
case shape_type::PathRef:
@ -531,6 +533,16 @@ Shapes::do_insert (const Shapes::shape_type &shape, const Trans &t, tl::func_del
return insert (db::object_with_properties<shape_type::edge_type> (p, pm (shape.prop_id ())));
}
}
case shape_type::Point:
{
shape_type::point_type p (shape.point ());
p = t.trans (p);
if (! shape.has_prop_id ()) {
return insert (p);
} else {
return insert (db::object_with_properties<shape_type::point_type> (p, pm (shape.prop_id ())));
}
}
case shape_type::EdgePair:
{
shape_type::edge_pair_type p (shape.edge_pair ());
@ -658,6 +670,8 @@ Shapes::find (const Shapes::shape_type &shape) const
return find_shape_by_tag (shape_type::edge_type::tag (), shape);
case shape_type::EdgePair:
return find_shape_by_tag (shape_type::edge_pair_type::tag (), shape);
case shape_type::Point:
return find_shape_by_tag (shape_type::point_type::tag (), shape);
case shape_type::Path:
return find_shape_by_tag (shape_type::path_type::tag (), shape);
case shape_type::PathRef:
@ -727,6 +741,9 @@ Shapes::replace_prop_id (const Shapes::shape_type &ref, db::properties_id_type p
case shape_type::EdgePair:
replace_prop_id (ref.basic_ptr (object_with_properties<shape_type::edge_pair_type>::tag ()), prop_id);
break;
case shape_type::Point:
replace_prop_id (ref.basic_ptr (object_with_properties<shape_type::point_type>::tag ()), prop_id);
break;
case shape_type::Path:
replace_prop_id (ref.basic_ptr (object_with_properties<shape_type::path_type>::tag ()), prop_id);
break;
@ -789,6 +806,8 @@ Shapes::replace_prop_id (const Shapes::shape_type &ref, db::properties_id_type p
return replace_prop_id_iter (shape_type::simple_polygon_ptr_array_type::tag (), ref.basic_iter (shape_type::simple_polygon_ptr_array_type::tag ()), prop_id);
case shape_type::Edge:
return replace_prop_id_iter (shape_type::edge_type::tag (), ref.basic_iter (shape_type::edge_type::tag ()), prop_id);
case shape_type::Point:
return replace_prop_id_iter (shape_type::point_type::tag (), ref.basic_iter (shape_type::point_type::tag ()), prop_id);
case shape_type::EdgePair:
return replace_prop_id_iter (shape_type::edge_pair_type::tag (), ref.basic_iter (shape_type::edge_pair_type::tag ()), prop_id);
case shape_type::Path:
@ -874,6 +893,12 @@ Shapes::transform (const Shapes::shape_type &ref, const Trans &t)
p.transform (t);
return replace_member_with_props (shape_type::edge_pair_type::tag (), ref, p);
}
case shape_type::Point:
{
shape_type::point_type p (ref.point ());
p = t.trans (p);
return replace_member_with_props (shape_type::point_type::tag (), ref, p);
}
case shape_type::Path:
{
shape_type::path_type p (ref.path ());
@ -962,6 +987,8 @@ Shapes::replace (const Shapes::shape_type &ref, const Sh &sh)
return replace_member_with_props (shape_type::edge_type::tag (), ref, sh);
case shape_type::EdgePair:
return replace_member_with_props (shape_type::edge_pair_type::tag (), ref, sh);
case shape_type::Point:
return replace_member_with_props (shape_type::point_type::tag (), ref, sh);
case shape_type::Path:
return replace_member_with_props (shape_type::path_type::tag (), ref, sh);
case shape_type::PathRef:
@ -1347,6 +1374,7 @@ template DB_PUBLIC Shape Shapes::replace<>(const Shape &, const SimplePolygon &)
template DB_PUBLIC Shape Shapes::replace<>(const Shape &, const Text &);
template DB_PUBLIC Shape Shapes::replace<>(const Shape &, const Edge &);
template DB_PUBLIC Shape Shapes::replace<>(const Shape &, const EdgePair &);
template DB_PUBLIC Shape Shapes::replace<>(const Shape &, const Point &);
template DB_PUBLIC Shape Shapes::transform<> (const Shape &, const ICplxTrans &);
template DB_PUBLIC Shape Shapes::transform<> (const Shape &, const Trans &);
@ -1376,6 +1404,8 @@ template class DB_PUBLIC layer_op<db::Shape::edge_type, db::stable_layer_tag>;
template class DB_PUBLIC layer_op<db::object_with_properties<db::Shape::edge_type>, db::stable_layer_tag>;
template class DB_PUBLIC layer_op<db::Shape::edge_pair_type, db::stable_layer_tag>;
template class DB_PUBLIC layer_op<db::object_with_properties<db::Shape::edge_pair_type>, db::stable_layer_tag>;
template class DB_PUBLIC layer_op<db::Shape::point_type, db::stable_layer_tag>;
template class DB_PUBLIC layer_op<db::object_with_properties<db::Shape::point_type>, db::stable_layer_tag>;
template class DB_PUBLIC layer_op<db::Shape::text_type, db::stable_layer_tag>;
template class DB_PUBLIC layer_op<db::object_with_properties<db::Shape::text_type>, db::stable_layer_tag>;
template class DB_PUBLIC layer_op<db::Shape::text_ref_type, db::stable_layer_tag>;

View File

@ -138,8 +138,9 @@ public:
Text = 15,
TextRef = 16,
TextPtrArray = 17,
UserObject = 18,
Null = 19 // must be last!
Point = 18,
UserObject = 19,
Null = 20 // must be last!
};
enum flags_type
@ -154,6 +155,7 @@ public:
| (1 << SimplePolygonPtrArray),
Edges = (1 << Edge),
EdgePairs = (1 << EdgePair),
Points = (1 << Point),
Paths = (1 << Path)
| (1 << PathRef)
| (1 << PathPtrArray),
@ -392,6 +394,7 @@ private:
char sz17 [sizeof (per_shape_iter_size <text_ref_type>)];
char sz18 [sizeof (per_shape_iter_size <text_ptr_array_type>)];
char sz19 [sizeof (per_shape_iter_size <user_object_type>)];
char sz20 [sizeof (per_shape_iter_size <point_type>)];
};
// this union is simply there to determine the maximum size required for all

View File

@ -679,6 +679,12 @@ inline unsigned int iterator_type_mask (ShapeIterator::edge_pair_type::tag)
return 1 << ShapeIterator::EdgePair;
}
/// @brief Internal: ShapeIterator masks per shape type
inline unsigned int iterator_type_mask (ShapeIterator::point_type::tag)
{
return 1 << ShapeIterator::Point;
}
/// @brief Internal: ShapeIterator masks per shape type
inline unsigned int iterator_type_mask (ShapeIterator::path_type::tag)
{
@ -917,6 +923,8 @@ template class layer_class<db::Shape::path_ptr_array_type, db::stable_layer_tag>
template class layer_class<db::object_with_properties<db::Shape::path_ptr_array_type>, db::stable_layer_tag>;
template class layer_class<db::Shape::edge_type, db::stable_layer_tag>;
template class layer_class<db::object_with_properties<db::Shape::edge_type>, db::stable_layer_tag>;
template class layer_class<db::Shape::point_type, db::stable_layer_tag>;
template class layer_class<db::object_with_properties<db::Shape::point_type>, db::stable_layer_tag>;
template class layer_class<db::Shape::edge_pair_type, db::stable_layer_tag>;
template class layer_class<db::object_with_properties<db::Shape::edge_pair_type>, db::stable_layer_tag>;
template class layer_class<db::Shape::text_type, db::stable_layer_tag>;
@ -957,6 +965,8 @@ template class layer_class<db::Shape::edge_type, db::unstable_layer_tag>;
template class layer_class<db::object_with_properties<db::Shape::edge_type>, db::unstable_layer_tag>;
template class layer_class<db::Shape::edge_pair_type, db::unstable_layer_tag>;
template class layer_class<db::object_with_properties<db::Shape::edge_pair_type>, db::unstable_layer_tag>;
template class layer_class<db::Shape::point_type, db::unstable_layer_tag>;
template class layer_class<db::object_with_properties<db::Shape::point_type>, db::unstable_layer_tag>;
template class layer_class<db::Shape::text_type, db::unstable_layer_tag>;
template class layer_class<db::object_with_properties<db::Shape::text_type>, db::unstable_layer_tag>;
template class layer_class<db::Shape::text_ref_type, db::unstable_layer_tag>;

View File

@ -134,6 +134,8 @@ template DB_PUBLIC layer<db::Shape::edge_type, db::stable_layer_tag> &Shapes::ge
template DB_PUBLIC layer<db::object_with_properties<db::Shape::edge_type>, db::stable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::edge_type>, db::stable_layer_tag> ();
template DB_PUBLIC layer<db::Shape::edge_pair_type, db::stable_layer_tag> &Shapes::get_layer<db::Shape::edge_pair_type, db::stable_layer_tag> ();
template DB_PUBLIC layer<db::object_with_properties<db::Shape::edge_pair_type>, db::stable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::edge_pair_type>, db::stable_layer_tag> ();
template DB_PUBLIC layer<db::Shape::point_type, db::stable_layer_tag> &Shapes::get_layer<db::Shape::point_type, db::stable_layer_tag> ();
template DB_PUBLIC layer<db::object_with_properties<db::Shape::point_type>, db::stable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::point_type>, db::stable_layer_tag> ();
template DB_PUBLIC layer<db::Shape::text_type, db::stable_layer_tag> &Shapes::get_layer<db::Shape::text_type, db::stable_layer_tag> ();
template DB_PUBLIC layer<db::object_with_properties<db::Shape::text_type>, db::stable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::text_type>, db::stable_layer_tag> ();
template DB_PUBLIC layer<db::Shape::text_ref_type, db::stable_layer_tag> &Shapes::get_layer<db::Shape::text_ref_type, db::stable_layer_tag> ();
@ -150,6 +152,7 @@ template DB_PUBLIC layer<db::Shape::short_box_array_type, db::stable_layer_tag>
template DB_PUBLIC layer<db::object_with_properties<db::Shape::short_box_array_type>, db::stable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::short_box_array_type>, db::stable_layer_tag> ();
template DB_PUBLIC layer<db::Shape::user_object_type, db::stable_layer_tag> &Shapes::get_layer<db::Shape::user_object_type, db::stable_layer_tag> ();
template DB_PUBLIC layer<db::object_with_properties<db::Shape::user_object_type>, db::stable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::user_object_type>, db::stable_layer_tag> ();
template DB_PUBLIC layer<db::Shape::polygon_type, db::unstable_layer_tag> &Shapes::get_layer<db::Shape::polygon_type, db::unstable_layer_tag> ();
template DB_PUBLIC layer<db::object_with_properties<db::Shape::polygon_type>, db::unstable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::polygon_type>, db::unstable_layer_tag> ();
template DB_PUBLIC layer<db::Shape::simple_polygon_type, db::unstable_layer_tag> &Shapes::get_layer<db::Shape::simple_polygon_type, db::unstable_layer_tag> ();
@ -172,6 +175,8 @@ template DB_PUBLIC layer<db::Shape::edge_type, db::unstable_layer_tag> &Shapes::
template DB_PUBLIC layer<db::object_with_properties<db::Shape::edge_type>, db::unstable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::edge_type>, db::unstable_layer_tag> ();
template DB_PUBLIC layer<db::Shape::edge_pair_type, db::unstable_layer_tag> &Shapes::get_layer<db::Shape::edge_pair_type, db::unstable_layer_tag> ();
template DB_PUBLIC layer<db::object_with_properties<db::Shape::edge_pair_type>, db::unstable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::edge_pair_type>, db::unstable_layer_tag> ();
template DB_PUBLIC layer<db::Shape::point_type, db::unstable_layer_tag> &Shapes::get_layer<db::Shape::point_type, db::unstable_layer_tag> ();
template DB_PUBLIC layer<db::object_with_properties<db::Shape::point_type>, db::unstable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::point_type>, db::unstable_layer_tag> ();
template DB_PUBLIC layer<db::Shape::text_type, db::unstable_layer_tag> &Shapes::get_layer<db::Shape::text_type, db::unstable_layer_tag> ();
template DB_PUBLIC layer<db::object_with_properties<db::Shape::text_type>, db::unstable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::text_type>, db::unstable_layer_tag> ();
template DB_PUBLIC layer<db::Shape::text_ref_type, db::unstable_layer_tag> &Shapes::get_layer<db::Shape::text_ref_type, db::unstable_layer_tag> ();
@ -211,6 +216,8 @@ template DB_PUBLIC const layer<db::Shape::edge_type, db::stable_layer_tag> &Shap
template DB_PUBLIC const layer<db::object_with_properties<db::Shape::edge_type>, db::stable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::edge_type>, db::stable_layer_tag> () const;
template DB_PUBLIC const layer<db::Shape::edge_pair_type, db::stable_layer_tag> &Shapes::get_layer<db::Shape::edge_pair_type, db::stable_layer_tag> () const;
template DB_PUBLIC const layer<db::object_with_properties<db::Shape::edge_pair_type>, db::stable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::edge_pair_type>, db::stable_layer_tag> () const;
template DB_PUBLIC const layer<db::Shape::point_type, db::stable_layer_tag> &Shapes::get_layer<db::Shape::point_type, db::stable_layer_tag> () const;
template DB_PUBLIC const layer<db::object_with_properties<db::Shape::point_type>, db::stable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::point_type>, db::stable_layer_tag> () const;
template DB_PUBLIC const layer<db::Shape::text_type, db::stable_layer_tag> &Shapes::get_layer<db::Shape::text_type, db::stable_layer_tag> () const;
template DB_PUBLIC const layer<db::object_with_properties<db::Shape::text_type>, db::stable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::text_type>, db::stable_layer_tag> () const;
template DB_PUBLIC const layer<db::Shape::text_ref_type, db::stable_layer_tag> &Shapes::get_layer<db::Shape::text_ref_type, db::stable_layer_tag> () const;
@ -227,6 +234,7 @@ template DB_PUBLIC const layer<db::Shape::short_box_array_type, db::stable_layer
template DB_PUBLIC const layer<db::object_with_properties<db::Shape::short_box_array_type>, db::stable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::short_box_array_type>, db::stable_layer_tag> () const;
template DB_PUBLIC const layer<db::Shape::user_object_type, db::stable_layer_tag> &Shapes::get_layer<db::Shape::user_object_type, db::stable_layer_tag> () const;
template DB_PUBLIC const layer<db::object_with_properties<db::Shape::user_object_type>, db::stable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::user_object_type>, db::stable_layer_tag> () const;
template DB_PUBLIC const layer<db::Shape::polygon_type, db::unstable_layer_tag> &Shapes::get_layer<db::Shape::polygon_type, db::unstable_layer_tag> () const;
template DB_PUBLIC const layer<db::object_with_properties<db::Shape::polygon_type>, db::unstable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::polygon_type>, db::unstable_layer_tag> () const;
template DB_PUBLIC const layer<db::Shape::simple_polygon_type, db::unstable_layer_tag> &Shapes::get_layer<db::Shape::simple_polygon_type, db::unstable_layer_tag> () const;
@ -249,6 +257,8 @@ template DB_PUBLIC const layer<db::Shape::edge_type, db::unstable_layer_tag> &Sh
template DB_PUBLIC const layer<db::object_with_properties<db::Shape::edge_type>, db::unstable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::edge_type>, db::unstable_layer_tag> () const;
template DB_PUBLIC const layer<db::Shape::edge_pair_type, db::unstable_layer_tag> &Shapes::get_layer<db::Shape::edge_pair_type, db::unstable_layer_tag> () const;
template DB_PUBLIC const layer<db::object_with_properties<db::Shape::edge_pair_type>, db::unstable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::edge_pair_type>, db::unstable_layer_tag> () const;
template DB_PUBLIC const layer<db::Shape::point_type, db::unstable_layer_tag> &Shapes::get_layer<db::Shape::point_type, db::unstable_layer_tag> () const;
template DB_PUBLIC const layer<db::object_with_properties<db::Shape::point_type>, db::unstable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::point_type>, db::unstable_layer_tag> () const;
template DB_PUBLIC const layer<db::Shape::text_type, db::unstable_layer_tag> &Shapes::get_layer<db::Shape::text_type, db::unstable_layer_tag> () const;
template DB_PUBLIC const layer<db::object_with_properties<db::Shape::text_type>, db::unstable_layer_tag> &Shapes::get_layer<db::object_with_properties<db::Shape::text_type>, db::unstable_layer_tag> () const;
template DB_PUBLIC const layer<db::Shape::text_ref_type, db::unstable_layer_tag> &Shapes::get_layer<db::Shape::text_ref_type, db::unstable_layer_tag> () const;
@ -315,6 +325,8 @@ Shapes::is_valid (const Shapes::shape_type &shape) const
return is_valid_shape_by_tag (shape_type::edge_type::tag (), shape);
case shape_type::EdgePair:
return is_valid_shape_by_tag (shape_type::edge_pair_type::tag (), shape);
case shape_type::Point:
return is_valid_shape_by_tag (shape_type::point_type::tag (), shape);
case shape_type::Path:
return is_valid_shape_by_tag (shape_type::path_type::tag (), shape);
case shape_type::PathRef:
@ -478,6 +490,9 @@ Shapes::erase_shape (const Shapes::shape_type &shape)
case shape_type::EdgePair:
erase_shape_by_tag (shape_type::edge_pair_type::tag (), shape);
break;
case shape_type::Point:
erase_shape_by_tag (shape_type::point_type::tag (), shape);
break;
case shape_type::Path:
erase_shape_by_tag (shape_type::path_type::tag (), shape);
break;
@ -570,6 +585,9 @@ Shapes::erase_shapes (const std::vector<Shapes::shape_type> &shapes)
case shape_type::Edge:
erase_shapes_by_tag (shape_type::edge_type::tag (), s, snext);
break;
case shape_type::Point:
erase_shapes_by_tag (shape_type::point_type::tag (), s, snext);
break;
case shape_type::EdgePair:
erase_shapes_by_tag (shape_type::edge_pair_type::tag (), s, snext);
break;
@ -625,5 +643,4 @@ Shapes::erase_shapes (const std::vector<Shapes::shape_type> &shapes)
}
}
}

View File

@ -169,6 +169,18 @@ struct edge_pair_defs
method ("bbox", &C::bbox,
"@brief Gets the bounding box of the edge pair\n"
) +
method ("perimeter", &C::perimeter,
"@brief Gets the perimeter of the edge pair\n"
"\n"
"The perimeter is defined as the sum of the lengths of both edges ('active perimeter').\n"
"\n"
"This attribute has been introduced in version 0.28."
) +
method ("area", &C::area,
"@brief Gets the area between the edges of the edge pair\n"
"\n"
"This attribute has been introduced in version 0.28."
) +
method ("<", &C::less, gsi::arg ("box"),
"@brief Less operator\n"
"Returns true, if this edge pair is 'less' with respect to first and second edge\n"

View File

@ -709,6 +709,26 @@ static tl::Variant get_dedge_pair (const db::Shape *s)
}
}
static tl::Variant get_point (const db::Shape *s)
{
db::Shape::point_type p;
if (s->point (p)) {
return tl::Variant (p);
} else {
return tl::Variant ();
}
}
static tl::Variant get_dpoint (const db::Shape *s)
{
db::Shape::point_type p;
if (s->point (p)) {
return tl::Variant (db::CplxTrans (shape_dbu (s)) * p);
} else {
return tl::Variant ();
}
}
static tl::Variant get_text (const db::Shape *s)
{
db::Shape::text_type p;
@ -1108,6 +1128,7 @@ static int t_simplePolygonPtrArray () { return db::Shape::SimplePolygonPtr
static int t_simplePolygonPtrArrayMember () { return db::Shape::SimplePolygonPtrArrayMember; }
static int t_edge () { return db::Shape::Edge; }
static int t_edge_pair () { return db::Shape::EdgePair; }
static int t_point () { return db::Shape::Point; }
static int t_path () { return db::Shape::Path; }
static int t_pathRef () { return db::Shape::PathRef; }
static int t_pathPtrArray () { return db::Shape::PathPtrArray; }
@ -1250,6 +1271,22 @@ Class<db::Shape> decl_Shape ("db", "Shape",
"\n"
"This method has been introduced in version 0.25."
) +
gsi::method_ext ("point=", &set_shape<db::Point>, gsi::arg("point"),
"@brief Replaces the shape by the given point\n"
"This method replaces the shape by the given point. This method can only be called "
"for editable layouts. It does not change the user properties of the shape.\n"
"Calling this method will invalidate any iterators. It should not be called inside a "
"loop iterating over shapes.\n"
"\n"
"This method has been introduced in version 0.28."
) +
gsi::method_ext ("point=|dpoint=", &set_dshape<db::DPoint>, gsi::arg("point"),
"@brief Replaces the shape by the given point (in micrometer units)\n"
"This method replaces the shape by the given point, like \\point= with a \\Point argument does. "
"This version translates the point from micrometer units to database units internally.\n"
"\n"
"This method has been introduced in version 0.28."
) +
gsi::method_ext ("edge_pair=", &set_shape<db::EdgePair>, gsi::arg("edge_pair"),
"@brief Replaces the shape by the given edge pair\n"
"This method replaces the shape by the given edge pair. This method can only be called "
@ -1760,6 +1797,23 @@ Class<db::Shape> decl_Shape ("db", "Shape",
"\n"
"This method has been added in version 0.26.\n"
) +
gsi::method ("is_point?", &db::Shape::is_point,
"@brief Returns true, if the object is an point\n"
"\n"
"This method has been introduced in version 0.28.\n"
) +
gsi::method_ext ("point", &get_point,
"@brief Returns the point object\n"
"\n"
"This method has been introduced in version 0.28.\n"
) +
gsi::method_ext ("dpoint", &get_dpoint,
"@brief Returns the point object as a \\DPoint object in micrometer units\n"
"See \\point for a description of this method. This method returns the point after translation to "
"micrometer units.\n"
"\n"
"This method has been introduced in version 0.28.\n"
) +
gsi::method ("is_text?", &db::Shape::is_text,
"@brief Returns true, if the object is a text\n"
) +
@ -2057,6 +2111,7 @@ Class<db::Shape> decl_Shape ("db", "Shape",
gsi::method ("TSimplePolygonPtrArrayMember|#t_simple_polygon_ptr_array_member", &t_simplePolygonPtrArrayMember) +
gsi::method ("TEdge|#t_edge", &t_edge) +
gsi::method ("TEdgePair|#t_edge_pair", &t_edge_pair) +
gsi::method ("TPoint|#t_point", &t_point) +
gsi::method ("TPath|#t_path", &t_path) +
gsi::method ("TPathRef|#t_path_ref", &t_pathRef) +
gsi::method ("TPathPtrArray|#t_path_ptr_array", &t_pathPtrArray) +

View File

@ -454,6 +454,7 @@ static unsigned int s_regions () { return db::ShapeIterator::Regions
static unsigned int s_boxes () { return db::ShapeIterator::Boxes; }
static unsigned int s_edges () { return db::ShapeIterator::Edges; }
static unsigned int s_edge_pairs () { return db::ShapeIterator::EdgePairs; }
static unsigned int s_points () { return db::ShapeIterator::Points; }
static unsigned int s_paths () { return db::ShapeIterator::Paths; }
static unsigned int s_texts () { return db::ShapeIterator::Texts; }
static unsigned int s_user_objects () { return db::ShapeIterator::UserObjects; }
@ -875,6 +876,25 @@ Class<db::Shapes> decl_Shapes ("db", "Shapes",
"\n"
"This variant has been introduced in version 0.26.\n"
) +
gsi::method_ext ("replace", &replace<db::Point>, gsi::arg ("shape"), gsi::arg ("point"),
"@brief Replaces the given shape with an point object\n"
"\n"
"This method replaces the given shape with the "
"object specified. It does not change the property Id. To change the property Id, "
"use the \\replace_prop_id method. To replace a shape and discard the property Id, erase the "
"shape and insert a new shape."
"\n"
"This variant has been introduced in version 0.28."
) +
gsi::method_ext ("replace", &dreplace<db::DPoint>, gsi::arg ("shape"), gsi::arg ("point"),
"@brief Replaces the given shape with an point given in micrometer units\n"
"@return A reference to the new shape (a \\Shape object)\n"
"\n"
"This method behaves like the \\replace version with an \\Point argument, except that it will "
"internally translate the point from micrometer to database units.\n"
"\n"
"This variant has been introduced in version 0.28."
) +
gsi::method_ext ("replace", &replace<db::Text>, gsi::arg ("shape"), gsi::arg ("text"),
"@brief Replaces the given shape with a text object\n"
"@return A reference to the new shape (a \\Shape object)\n"
@ -989,6 +1009,19 @@ Class<db::Shapes> decl_Shapes ("db", "Shapes",
"\n"
"This variant has been introduced in version 0.26."
) +
gsi::method_ext ("insert|#insert_point", &insert<db::Point>, gsi::arg ("point"),
"@brief Inserts an point into the shapes list\n"
"\n"
"This variant has been introduced in version 0.28.\n"
) +
gsi::method_ext ("insert", &dinsert<db::DPoint>, gsi::arg ("point"),
"@brief Inserts a micrometer-unit point into the shapes list\n"
"@return A reference to the new shape (a \\Shape object)\n"
"This method behaves like the \\insert version with a \\Point argument, except that it will "
"internally translate the point from micrometer to database units.\n"
"\n"
"This variant has been introduced in version 0.28.\n"
) +
gsi::method_ext ("insert|#insert_text", &insert<db::Text>, gsi::arg ("text"),
"@brief Inserts a text into the shapes list\n"
"@return A reference to the new shape (a \\Shape object)\n"
@ -1285,6 +1318,11 @@ Class<db::Shapes> decl_Shapes ("db", "Shapes",
gsi::method ("SEdgePairs|#s_edge_pairs", &s_edge_pairs,
"@brief Indicates that edge pairs shall be retrieved"
) +
gsi::method ("SPoints|#s_points", &s_points,
"@brief Indicates that points shall be retrieved"
"\n"
"This constant has been added in version 0.28."
) +
gsi::method ("SPaths|#s_paths", &s_paths,
"@brief Indicates that paths shall be retrieved"
) +

View File

@ -35,11 +35,15 @@ TEST(1)
EXPECT_EQ (ep == db::EdgePair (db::Edge (), db::Edge ()), true);
EXPECT_EQ (ep != db::EdgePair (db::Edge (), db::Edge ()), false);
EXPECT_EQ (ep < db::EdgePair (db::Edge (), db::Edge ()), false);
EXPECT_EQ (ep.area (), db::EdgePair::area_type (0));
EXPECT_EQ (ep.perimeter (), db::EdgePair::perimeter_type (0));
ep = db::EdgePair (db::Edge (db::Point (10, 30), db::Point (15, 30)), db::Edge (db::Point (0, 30), db::Point (0, 40)));
EXPECT_EQ (ep.to_string (), "(10,30;15,30)/(0,30;0,40)");
EXPECT_EQ (ep.normalized ().to_string (), "(15,30;10,30)/(0,30;0,40)");
EXPECT_EQ (ep.normalized ().normalized ().to_string (), "(15,30;10,30)/(0,30;0,40)");
EXPECT_EQ (ep.area (), db::EdgePair::area_type (50)); // weird orientation :(
EXPECT_EQ (ep.perimeter (), db::EdgePair::perimeter_type (15));
ep = db::EdgePair (db::Edge (db::Point (1, 2), db::Point (11, 12)), db::Edge (db::Point (-5, 5), db::Point (5, 15)));
EXPECT_EQ (ep.to_string (), "(1,2;11,12)/(-5,5;5,15)");

View File

@ -815,3 +815,136 @@ TEST(8)
}
// Edges, EdgePairs, Points
TEST(9)
{
db::Manager m (true);
db::Shapes s (&m, 0, db::default_editable_mode ());
s.insert (db::Point (100, 200));
s.insert (db::Edge (db::Point (100, 200), db::Point (200, 400)));
s.insert (db::EdgePair (db::Edge (db::Point (100, 200), db::Point (200, 400)), db::Edge (db::Point (0, 300), db::Point (100, 500))));
db::ShapeIterator si;
si = s.begin (db::ShapeIterator::All);
EXPECT_EQ (si.at_end (), false);
EXPECT_EQ (si->is_edge (), true);
EXPECT_EQ (si->is_edge_pair (), false);
EXPECT_EQ (si->is_point (), false);
EXPECT_EQ (si->to_string (), "edge (100,200;200,400)");
EXPECT_EQ (si->edge ().to_string (), "(100,200;200,400)");
++si;
EXPECT_EQ (si.at_end (), false);
EXPECT_EQ (si->is_edge (), false);
EXPECT_EQ (si->is_edge_pair (), true);
EXPECT_EQ (si->is_point (), false);
EXPECT_EQ (si->to_string (), "edge_pair (100,200;200,400)/(0,300;100,500)");
EXPECT_EQ (si->edge_pair ().to_string (), "(100,200;200,400)/(0,300;100,500)");
++si;
EXPECT_EQ (si.at_end (), false);
EXPECT_EQ (si->is_edge (), false);
EXPECT_EQ (si->is_edge_pair (), false);
EXPECT_EQ (si->is_point (), true);
EXPECT_EQ (si->to_string (), "point 100,200");
EXPECT_EQ (si->point ().to_string (), "100,200");
++si;
EXPECT_EQ (si.at_end (), true);
si = s.begin (db::ShapeIterator::Edges);
EXPECT_EQ (si.at_end (), false);
EXPECT_EQ (si->is_edge (), true);
EXPECT_EQ (si->is_edge_pair (), false);
EXPECT_EQ (si->is_point (), false);
EXPECT_EQ (si->to_string (), "edge (100,200;200,400)");
EXPECT_EQ (si->edge ().to_string (), "(100,200;200,400)");
++si;
EXPECT_EQ (si.at_end (), true);
si = s.begin (db::ShapeIterator::EdgePairs);
EXPECT_EQ (si.at_end (), false);
EXPECT_EQ (si->is_edge (), false);
EXPECT_EQ (si->is_edge_pair (), true);
EXPECT_EQ (si->is_point (), false);
EXPECT_EQ (si->to_string (), "edge_pair (100,200;200,400)/(0,300;100,500)");
EXPECT_EQ (si->edge_pair ().to_string (), "(100,200;200,400)/(0,300;100,500)");
++si;
EXPECT_EQ (si.at_end (), true);
si = s.begin (db::ShapeIterator::Points);
EXPECT_EQ (si.at_end (), false);
EXPECT_EQ (si->is_edge (), false);
EXPECT_EQ (si->is_edge_pair (), false);
EXPECT_EQ (si->is_point (), true);
EXPECT_EQ (si->to_string (), "point 100,200");
EXPECT_EQ (si->point ().to_string (), "100,200");
++si;
EXPECT_EQ (si.at_end (), true);
s.clear ();
s.insert (db::PointWithProperties (db::Point (100, 200), 1));
s.insert (db::EdgeWithProperties (db::Edge (db::Point (100, 200), db::Point (200, 400)), 2));
s.insert (db::EdgePairWithProperties (db::EdgePair (db::Edge (db::Point (100, 200), db::Point (200, 400)), db::Edge (db::Point (0, 300), db::Point (100, 500))), 3));
si = s.begin (db::ShapeIterator::All);
EXPECT_EQ (si.at_end (), false);
EXPECT_EQ (si->is_edge (), true);
EXPECT_EQ (si->prop_id (), db::properties_id_type (2));
EXPECT_EQ (si->is_edge_pair (), false);
EXPECT_EQ (si->is_point (), false);
EXPECT_EQ (si->to_string (), "edge (100,200;200,400) prop_id=2");
EXPECT_EQ (si->edge ().to_string (), "(100,200;200,400)");
++si;
EXPECT_EQ (si.at_end (), false);
EXPECT_EQ (si->is_edge (), false);
EXPECT_EQ (si->is_edge_pair (), true);
EXPECT_EQ (si->prop_id (), db::properties_id_type (3));
EXPECT_EQ (si->is_point (), false);
EXPECT_EQ (si->to_string (), "edge_pair (100,200;200,400)/(0,300;100,500) prop_id=3");
EXPECT_EQ (si->edge_pair ().to_string (), "(100,200;200,400)/(0,300;100,500)");
++si;
EXPECT_EQ (si.at_end (), false);
EXPECT_EQ (si->is_edge (), false);
EXPECT_EQ (si->is_edge_pair (), false);
EXPECT_EQ (si->is_point (), true);
EXPECT_EQ (si->prop_id (), db::properties_id_type (1));
EXPECT_EQ (si->to_string (), "point 100,200 prop_id=1");
EXPECT_EQ (si->point ().to_string (), "100,200");
++si;
EXPECT_EQ (si.at_end (), true);
}

View File

@ -3406,33 +3406,6 @@ TEST(24c)
EXPECT_EQ (shapes_to_string_norm (_this, s1), "");
}
// Bug #107
TEST(100)
{
db::Manager m (true);
db::Shapes shapes1 (&m, 0, true);
m.transaction ("y");
shapes1.insert (db::Box (200, -200, 100, -100));
m.commit ();
EXPECT_EQ (shapes_to_string_norm (_this, shapes1),
"box (100,-200;200,-100) #0\n"
);
m.undo ();
EXPECT_EQ (shapes_to_string_norm (_this, shapes1),
""
);
m.redo ();
EXPECT_EQ (shapes_to_string_norm (_this, shapes1),
"box (100,-200;200,-100) #0\n"
);
m.undo ();
EXPECT_EQ (shapes_to_string_norm (_this, shapes1),
""
);
}
// Shape insert and clear and undo/redo - different layouts
TEST(24d)
{
@ -3499,6 +3472,33 @@ TEST(24d)
EXPECT_EQ (shapes_to_string_norm (_this, s1), "");
}
// Bug #107
TEST(100)
{
db::Manager m (true);
db::Shapes shapes1 (&m, 0, true);
m.transaction ("y");
shapes1.insert (db::Box (200, -200, 100, -100));
m.commit ();
EXPECT_EQ (shapes_to_string_norm (_this, shapes1),
"box (100,-200;200,-100) #0\n"
);
m.undo ();
EXPECT_EQ (shapes_to_string_norm (_this, shapes1),
""
);
m.redo ();
EXPECT_EQ (shapes_to_string_norm (_this, shapes1),
"box (100,-200;200,-100) #0\n"
);
m.undo ();
EXPECT_EQ (shapes_to_string_norm (_this, shapes1),
""
);
}
// Bug #835
TEST(101)
{

View File

@ -31,6 +31,8 @@ class DBEdgePair_TestClass < TestBase
ep = RBA::EdgePair::new
assert_equal(ep.to_s, "(0,0;0,0)/(0,0;0,0)")
assert_equal(ep.to_s, "(0,0;0,0)/(0,0;0,0)")
ep.first = RBA::Edge::new(0, 0, 10, 20)
assert_equal(ep.to_s, "(0,0;10,20)/(0,0;0,0)")
@ -57,6 +59,18 @@ class DBEdgePair_TestClass < TestBase
assert_equal(ep.simple_polygon(0).to_s, "(-10,0;-10,30;0,0;10,20)")
assert_equal(ep.simple_polygon(0).class.to_s, "RBA::SimplePolygon")
ep = RBA::EdgePair::new(RBA::Edge::new(0, 0, 10, 0), RBA::Edge::new(0, 20, 0, 0))
assert_equal(ep.perimeter, 30)
assert_equal(ep.area, 100)
assert_equal(ep.simple_polygon(0).area, 100)
ep = RBA::EdgePair::new(RBA::Edge::new(0, 0, 10, 0), RBA::Edge::new(0, 0, 0, 20))
assert_equal(ep.perimeter, 30)
assert_equal(ep.area, 0)
assert_equal(ep.simple_polygon(0).area, 0)
end
# Basics
@ -92,6 +106,18 @@ class DBEdgePair_TestClass < TestBase
assert_equal(ep.simple_polygon(0).to_s, "(-10,0;-10,30;0,0;10,20)")
assert_equal(ep.simple_polygon(0).class.to_s, "RBA::DSimplePolygon")
ep = RBA::DEdgePair::new(RBA::DEdge::new(0, 0, 10, 0), RBA::DEdge::new(0, 20, 0, 0))
assert_equal(ep.perimeter, 30)
assert_equal(ep.area, 100)
assert_equal(ep.simple_polygon(0).area, 100)
ep = RBA::DEdgePair::new(RBA::DEdge::new(0, 0, 10, 0), RBA::DEdge::new(0, 0, 0, 20))
assert_equal(ep.perimeter, 30)
assert_equal(ep.area, 0)
assert_equal(ep.simple_polygon(0).area, 0)
end
# Fuzzy compare

View File

@ -158,6 +158,9 @@ class DBShapes_TestClass < TestBase
shapes.each( RBA::Shapes::SEdges ) { |s| arr.push( s ) }
assert_equal( arr.size, 0 )
arr = []
shapes.each( RBA::Shapes::SPoints ) { |s| arr.push( s ) }
assert_equal( arr.size, 0 )
arr = []
shapes.each( RBA::Shapes::SBoxes ) { |s| arr.push( s ) }
assert_equal( arr.size, 1 )
assert_equal( arr[0].prop_id, 0 )
@ -166,6 +169,7 @@ class DBShapes_TestClass < TestBase
assert_equal( arr[0].type, RBA::Shape::t_box )
assert_equal( arr[0].polygon.to_s, "(10,-10;10,40;50,40;50,-10)" )
assert_equal( arr[0].simple_polygon.to_s, "(10,-10;10,40;50,40;50,-10)" )
assert_equal( arr[0].point.inspect, "nil" )
assert_equal( arr[0].edge.inspect, "nil" )
assert_equal( arr[0].edge_pair.inspect, "nil" )
assert_equal( arr[0].box.to_s, "(10,-10;50,40)" )
@ -190,6 +194,7 @@ class DBShapes_TestClass < TestBase
assert_equal( arr[0].is_edge?, true )
assert_equal( arr[0].polygon.inspect, "nil" )
assert_equal( arr[0].simple_polygon.inspect, "nil" )
assert_equal( arr[0].point.inspect, "nil" )
assert_equal( arr[0].edge.to_s, "(-1,2;5,2)" )
assert_equal( arr[0].edge_pair.inspect, "nil" )
assert_equal( arr[0].box.inspect, "nil" )
@ -217,6 +222,7 @@ class DBShapes_TestClass < TestBase
assert_equal( arr[0].polygon.inspect, "nil" )
assert_equal( arr[0].simple_polygon.inspect, "nil" )
assert_equal( arr[0].edge_pair.to_s, "(-1,2;5,2)/(-1,5;5,5)" )
assert_equal( arr[0].point.inspect, "nil" )
assert_equal( arr[0].edge.inspect, "nil" )
assert_equal( arr[0].box.inspect, "nil" )
assert_equal( arr[0].path.inspect, "nil" )
@ -228,6 +234,33 @@ class DBShapes_TestClass < TestBase
assert_equal( arr.size, 1 )
assert_equal( arr[0].is_box?, true )
# points
a = RBA::Point::new( -1, 2 )
c1.shapes( lindex ).insert( a )
arr = []
shapes.each( RBA::Shapes::SPoints ) { |s| arr.push( s ) }
assert_equal( arr.size, 1 )
assert_equal( arr[0].prop_id, 0 )
assert_equal( arr[0].has_prop_id?, false )
assert_equal( arr[0].is_null?, false )
assert_equal( arr[0].type, RBA::Shape::t_point )
assert_equal( arr[0].is_point?, true )
assert_equal( arr[0].polygon.inspect, "nil" )
assert_equal( arr[0].simple_polygon.inspect, "nil" )
assert_equal( arr[0].point.to_s, "-1,2" )
assert_equal( arr[0].edge.inspect, "nil" )
assert_equal( arr[0].edge_pair.inspect, "nil" )
assert_equal( arr[0].box.inspect, "nil" )
assert_equal( arr[0].path.inspect, "nil" )
assert_equal( arr[0].text.inspect, "nil" )
assert_equal( arr[0].point == a, true )
assert_equal( arr[0].bbox == RBA::Box::new(a, a), true )
arr = []
shapes.each( RBA::Shapes::SBoxes ) { |s| arr.push( s ) }
assert_equal( arr.size, 1 )
assert_equal( arr[0].is_box?, true )
# paths
a = RBA::Path::new( [ RBA::Point::new( 0, 10 ), RBA::Point::new( 10, 50 ) ], 25 )
@ -486,6 +519,9 @@ class DBShapes_TestClass < TestBase
shapes.each( RBA::Shapes::SEdges ) { |s| arr.push( s ) }
assert_equal( arr.size, 0 )
arr = []
shapes.each( RBA::Shapes::SPoints ) { |s| arr.push( s ) }
assert_equal( arr.size, 0 )
arr = []
shapes.each( RBA::Shapes::SBoxes ) { |s| arr.push( s ) }
assert_equal( arr.size, 1 )
assert_equal( arr[0].prop_id, 0 )
@ -543,6 +579,7 @@ class DBShapes_TestClass < TestBase
assert_equal( arr[0].is_edge_pair?, true )
assert_equal( arr[0].dpolygon.inspect, "nil" )
assert_equal( arr[0].dsimple_polygon.inspect, "nil" )
assert_equal( arr[0].dpoint.inspect, "nil" )
assert_equal( arr[0].dedge_pair.to_s, "(-0.001,0.002;0.005,0.002)/(-0.001,0.005;0.005,0.005)" )
assert_equal( arr[0].dedge.inspect, "nil" )
assert_equal( arr[0].dbox.inspect, "nil" )
@ -554,6 +591,32 @@ class DBShapes_TestClass < TestBase
assert_equal( arr.size, 1 )
assert_equal( arr[0].is_box?, true )
# points
a = RBA::DPoint::new( -1, 2 )
c1.shapes( lindex ).insert( a )
arr = []
shapes.each( RBA::Shapes::SPoints ) { |s| arr.push( s ) }
assert_equal( arr.size, 1 )
assert_equal( arr[0].prop_id, 0 )
assert_equal( arr[0].has_prop_id?, false )
assert_equal( arr[0].is_null?, false )
assert_equal( arr[0].type, RBA::Shape::t_point )
assert_equal( arr[0].is_point?, true )
assert_equal( arr[0].dpolygon.inspect, "nil" )
assert_equal( arr[0].dsimple_polygon.inspect, "nil" )
assert_equal( arr[0].dpoint.to_s, "-1,2" )
assert_equal( arr[0].dedge.inspect, "nil" )
assert_equal( arr[0].dedge_pair.inspect, "nil" )
assert_equal( arr[0].dbox.inspect, "nil" )
assert_equal( arr[0].dpath.inspect, "nil" )
assert_equal( arr[0].dtext.inspect, "nil" )
assert_equal( arr[0].dbbox.to_s, "(-1,2;-1,2)" )
arr = []
shapes.each( RBA::Shapes::SBoxes ) { |s| arr.push( s ) }
assert_equal( arr.size, 1 )
assert_equal( arr[0].is_box?, true )
# paths
a = RBA::DPath::new( [ RBA::DPoint::new( 0, 0.010 ), RBA::DPoint::new( 0.010, 0.050 ) ], 0.025 )