[consider merging] suppress normalization of orientation on GSI DPolygon#to_itype and Polygon#to_dtype

This commit is contained in:
Matthias Koefferlein 2025-09-08 21:16:05 +02:00
parent e2b5c29131
commit 0ddc07392b
4 changed files with 66 additions and 33 deletions

View File

@ -511,7 +511,7 @@ MeasureNetEval::put_func (const tl::Variant &name, const tl::Variant &value) con
MeasureNetEval::AreaAndPerimeter
MeasureNetEval::compute_area_and_perimeter (int layer_index) const
{
if (layer_index < 0 || layer_index >= (unsigned int) m_layers.size ()) {
if (layer_index < 0 || layer_index >= (int) m_layers.size ()) {
return AreaAndPerimeter ();
}

View File

@ -1512,16 +1512,17 @@ public:
* @param tr The transformation to apply on assignment
* @param compress True, if the contours shall be compressed
* @param remove_reflected True, if reflecting spikes shall be removed on compression
* @param normalize If true, the orientation is normalized
*/
template <class D, class T>
polygon (const db::polygon<D> &p, const T &tr, bool compress = default_compression<C> (), bool remove_reflected = false)
polygon (const db::polygon<D> &p, const T &tr, bool compress = default_compression<C> (), bool remove_reflected = false, bool normalize = true)
{
// create an entry for the hull contour
m_bbox = box_type (tr (p.box ().p1 ()), tr (p.box ().p2 ()));
m_ctrs.resize (p.holes () + 1);
m_ctrs [0].assign (p.begin_hull (), p.end_hull (), tr, false, compress, true /*normalize*/, remove_reflected);
m_ctrs [0].assign (p.begin_hull (), p.end_hull (), tr, false, compress, normalize, remove_reflected);
for (unsigned int i = 0; i < m_ctrs.size () - 1; ++i) {
m_ctrs [i + 1].assign (p.begin_hole (i), p.end_hole (i), tr, true, compress, true /*normalize*/, remove_reflected);
m_ctrs [i + 1].assign (p.begin_hole (i), p.end_hole (i), tr, true, compress, normalize, remove_reflected);
}
}
@ -1533,16 +1534,16 @@ public:
* @param remove_reflected True, if reflecting spikes shall be removed on compression
*/
template <class D>
explicit polygon (const db::polygon<D> &p, bool compress = default_compression<C> (), bool remove_reflected = false)
explicit polygon (const db::polygon<D> &p, bool compress = default_compression<C> (), bool remove_reflected = false, bool normalize = true)
{
db::point_coord_converter<C, D> tr;
// create an entry for the hull contour
m_bbox = box_type (tr (p.box ().p1 ()), tr (p.box ().p2 ()));
m_ctrs.resize (p.holes () + 1);
m_ctrs [0].assign (p.begin_hull (), p.end_hull (), tr, false, compress, true /*normalize*/, remove_reflected);
m_ctrs [0].assign (p.begin_hull (), p.end_hull (), tr, false, compress, normalize, remove_reflected);
for (unsigned int i = 0; i < m_ctrs.size () - 1; ++i) {
m_ctrs [i + 1].assign (p.begin_hole (i), p.end_hole (i), tr, true, compress, true /*normalize*/, remove_reflected);
m_ctrs [i + 1].assign (p.begin_hole (i), p.end_hole (i), tr, true, compress, normalize, remove_reflected);
}
}
@ -2072,11 +2073,12 @@ public:
* @param end The end of the sequence of points for the contour
* @param compress true, if the sequence shall be compressed (colinear points removed)
* @param remove_reflected True, if reflecting spikes shall be removed on compression
* @param normalize If true, the orientation is normalized
*/
template <class I>
void assign_hull (I start, I end, bool compress = default_compression<C> (), bool remove_reflected = false)
void assign_hull (I start, I end, bool compress = default_compression<C> (), bool remove_reflected = false, bool normalize = true)
{
m_ctrs [0].assign (start, end, false, compress, true /*normalize*/, remove_reflected);
m_ctrs [0].assign (start, end, false, compress, normalize, remove_reflected);
m_bbox = m_ctrs [0].bbox ();
}
@ -2089,14 +2091,15 @@ public:
* so it is oriented properly.
* @param compress true, if the sequence shall be compressed (colinear points removed)
* @param remove_reflected True, if reflecting spikes shall be removed on compression
* @param normalize If true, the orientation is normalized
*
* @param start The start of the sequence of points for the contour
* @param end The end of the sequence of points for the contour
*/
template <class I, class T>
void assign_hull (I start, I end, T op, bool compress = default_compression<C> (), bool remove_reflected = false)
void assign_hull (I start, I end, T op, bool compress = default_compression<C> (), bool remove_reflected = false, bool normalize = true)
{
m_ctrs [0].assign (start, end, op, false, compress, true /*normalize*/, remove_reflected);
m_ctrs [0].assign (start, end, op, false, compress, normalize, remove_reflected);
m_bbox = m_ctrs [0].bbox ();
}
@ -2128,11 +2131,12 @@ public:
* @param end The end of the sequence of points for the contour
* @param compress true, if the sequence shall be compressed (colinear points removed)
* @param remove_reflected True, if reflecting spikes shall be removed on compression
* @param normalize If true, the orientation is normalized
*/
template <class I>
void assign_hole (unsigned int h, I start, I end, bool compress = default_compression<C> (), bool remove_reflected = false)
void assign_hole (unsigned int h, I start, I end, bool compress = default_compression<C> (), bool remove_reflected = false, bool normalize = true)
{
m_ctrs [h + 1].assign (start, end, true, compress, true /*normalize*/, remove_reflected);
m_ctrs [h + 1].assign (start, end, true, compress, normalize, remove_reflected);
}
/**
@ -2144,14 +2148,15 @@ public:
* so it is oriented properly.
* @param compress true, if the sequence shall be compressed (colinear points removed)
* @param remove_reflected True, if reflecting spikes shall be removed on compression
* @param normalize If true, the orientation is normalized
*
* @param start The start of the sequence of points for the contour
* @param end The end of the sequence of points for the contour
*/
template <class I, class T>
void assign_hole (unsigned int h, I start, I end, T op, bool compress = default_compression<C> (), bool remove_reflected = false)
void assign_hole (unsigned int h, I start, I end, T op, bool compress = default_compression<C> (), bool remove_reflected = false, bool normalize = true)
{
m_ctrs [h + 1].assign (start, end, op, true, compress, true /*normalize*/, remove_reflected);
m_ctrs [h + 1].assign (start, end, op, true, compress, normalize, remove_reflected);
}
/**
@ -2183,11 +2188,12 @@ public:
* @param end The end of the sequence of points for the contour
* @param compress true, if the sequence shall be compressed (colinear points removed)
* @param remove_reflected True, if reflecting spikes shall be removed on compression
* @param normalize If true, the orientation is normalized
*/
template <class I>
void insert_hole (I start, I end, bool compress = default_compression<C> (), bool remove_reflected = false)
void insert_hole (I start, I end, bool compress = default_compression<C> (), bool remove_reflected = false, bool normalize = true)
{
insert_hole (start, end, db::unit_trans<C> (), compress, remove_reflected);
insert_hole (start, end, db::unit_trans<C> (), compress, remove_reflected, normalize);
}
/**
@ -2204,13 +2210,14 @@ public:
* @param end The end of the sequence of points for the contour
* @param compress true, if the sequence shall be compressed (colinear points removed)
* @param remove_reflected True, if reflecting spikes shall be removed on compression
* @param normalize If true, the orientation is normalized
*/
template <class I, class T>
void insert_hole (I start, I end, T op, bool compress = default_compression<C> (), bool remove_reflected = false)
void insert_hole (I start, I end, T op, bool compress = default_compression<C> (), bool remove_reflected = false, bool normalize = true)
{
// add the hole
contour_type &h = add_hole ();
h.assign (start, end, op, true, compress, true /*normalize*/, remove_reflected);
h.assign (start, end, op, true, compress, normalize, remove_reflected);
}
/**
@ -2637,13 +2644,14 @@ public:
* @param tr The transformation to apply
* @param compress true, if the sequence shall be compressed (colinear points removed)
* @param remove_reflected True, if reflecting spikes shall be removed on compression
* @param normalize If true, the orientation is normalized
*/
template <class D, class T>
simple_polygon (const db::simple_polygon<D> &p, const T &tr, bool compress = default_compression<C> (), bool remove_reflected = false)
simple_polygon (const db::simple_polygon<D> &p, const T &tr, bool compress = default_compression<C> (), bool remove_reflected = false, bool normalize = true)
{
// create an entry for the hull contour
m_bbox = box_type (tr (p.box ().p1 ()), tr (p.box ().p2 ()));
m_hull.assign (p.begin_hull (), p.end_hull (), tr, false, compress, true /*normalize*/, remove_reflected);
m_hull.assign (p.begin_hull (), p.end_hull (), tr, false, compress, normalize, remove_reflected);
}
/**
@ -2652,15 +2660,16 @@ public:
* @param p The source polygon
* @param compress true, if the sequence shall be compressed (colinear points removed)
* @param remove_reflected True, if reflecting spikes shall be removed on compression
* @param normalize If true, the orientation is normalized
*/
template <class D>
explicit simple_polygon (const db::simple_polygon<D> &p, bool compress = default_compression<C> (), bool remove_reflected = false)
explicit simple_polygon (const db::simple_polygon<D> &p, bool compress = default_compression<C> (), bool remove_reflected = false, bool normalize = true)
{
db::point_coord_converter<C, D> tr;
// create an entry for the hull contour
m_bbox = box_type (tr (p.box ().p1 ()), tr (p.box ().p2 ()));
m_hull.assign (p.begin_hull (), p.end_hull (), tr, false, compress, true /*normalize*/, remove_reflected);
m_hull.assign (p.begin_hull (), p.end_hull (), tr, false, compress, normalize, remove_reflected);
}
/**
@ -2992,11 +3001,12 @@ public:
* @param end The end of the sequence of points for the contour
* @param compress true, if the sequence shall be compressed (colinear segments joined)
* @param remove_reflected True, if reflecting spikes shall be removed on compression
* @param normalize If true, the orientation is normalized
*/
template <class I, class T>
void assign_hull (I start, I end, T op, bool compress = default_compression<C> (), bool remove_reflected = false)
void assign_hull (I start, I end, T op, bool compress = default_compression<C> (), bool remove_reflected = false, bool normalize = true)
{
m_hull.assign (start, end, op, false, compress, true /*normalize*/, remove_reflected);
m_hull.assign (start, end, op, false, compress, normalize, remove_reflected);
m_bbox = m_hull.bbox ();
}

View File

@ -868,12 +868,12 @@ static db::SimplePolygon transformed_icplx_sp (const db::SimplePolygon *p, const
static db::SimplePolygon *spolygon_from_dspolygon (const db::DSimplePolygon &p)
{
return new db::SimplePolygon (p, false);
return new db::SimplePolygon (p, false, false /*don't remove reflected*/, false /*no normalize*/);
}
static db::DSimplePolygon spolygon_to_dspolygon (const db::SimplePolygon *p, double dbu)
{
return db::DSimplePolygon (*p * dbu, false);
return db::DSimplePolygon (*p, db::CplxTrans (dbu), false, false /*don't remove reflected*/, false /*no normalize*/);
}
Class<db::SimplePolygon> decl_SimplePolygon ("db", "SimplePolygon",
@ -1031,12 +1031,12 @@ Class<db::SimplePolygonWithProperties> decl_SimplePolygonWithProperties (decl_Si
static db::DSimplePolygon *dspolygon_from_ispolygon (const db::SimplePolygon &p)
{
return new db::DSimplePolygon (p, false);
return new db::DSimplePolygon (p, false, false /*don't remove reflected*/, false /*no normalize*/);
}
static db::SimplePolygon dspolygon_to_spolygon (const db::DSimplePolygon *p, double dbu)
{
return db::SimplePolygon (*p * (1.0 / dbu), false);
return db::SimplePolygon (*p, db::VCplxTrans (1.0 / dbu), false, false /*don't remove reflected*/, false /*no normalize*/);
}
static db::SimplePolygon transformed_vplx_sp (const db::DSimplePolygon *p, const db::VCplxTrans &t)
@ -2036,12 +2036,12 @@ static db::Polygon minkowski_sum_pc (const db::Polygon *p, const std::vector<db:
static db::Polygon *polygon_from_dpolygon (const db::DPolygon &p)
{
return new db::Polygon (p, false);
return new db::Polygon (p, false, false /*don't remove reflected*/, false /*no normalize*/);
}
static db::DPolygon polygon_to_dpolygon (const db::Polygon *p, double dbu)
{
return db::DPolygon (*p * dbu, false);
return db::DPolygon (*p, db::CplxTrans (dbu), false, false /*don't remove reflected*/, false /*no normalize*/);
}
static bool is_convex (const db::Polygon *p)
@ -2380,12 +2380,12 @@ Class<db::PolygonWithProperties> decl_PolygonWithProperties (decl_Polygon, "db",
static db::DPolygon *dpolygon_from_ipolygon (const db::Polygon &p)
{
return new db::DPolygon (p, false);
return new db::DPolygon (p, false, false /*don't remove reflected*/, false /*no normalize*/);
}
static db::Polygon dpolygon_to_polygon (const db::DPolygon *p, double dbu)
{
return db::Polygon (*p * (1.0 / dbu), false);
return db::Polygon (*p, db::VCplxTrans (1.0 / dbu), false, false /*don't remove reflected*/, false /*no normalize*/);
}
static db::Polygon transformed_vcplx_dp (const db::DPolygon *p, const db::VCplxTrans &t)

View File

@ -1032,6 +1032,29 @@ class DBPolygon_TestClass < TestBase
end
def test_sized_transform
# to_itype and to_dtype need to preserve the non-orientation of
# the sized() result, so they are useful for this application
p = RBA::DPolygon::new(RBA::DBox::new(0, 0, 0.4, 0.5))
res = RBA::EdgeProcessor::new.simple_merge_p2p([ p.sized(-0.12, -0.22).to_itype(0.001) ], false, false, 1)
res = res.collect { |p| p.to_s }
assert_equal(res, ["(120,120;120,380;280,380;280,120)"])
res = RBA::EdgeProcessor::new.simple_merge_p2p([ p.sized(-0.22, -0.22).to_itype(0.001) ], false, false, 1)
res = res.collect { |p| p.to_s }
assert_equal(res, [])
p = RBA::Polygon::new(RBA::Box::new(0, 0, 400, 500))
res = RBA::EdgeProcessor::new.simple_merge_p2p([ p.sized(-120, -220).to_dtype(0.001).to_itype(0.001) ], false, false, 1)
res = res.collect { |p| p.to_s }
assert_equal(res, ["(120,120;120,380;280,380;280,120)"])
res = RBA::EdgeProcessor::new.simple_merge_p2p([ p.sized(-220, -220).to_dtype(0.001).to_itype(0.001) ], false, false, 1)
res = res.collect { |p| p.to_s }
assert_equal(res, [])
end
end
load("test_epilogue.rb")