void GerberImporter::linear_draw_circular_aperture(point_type startpoint, point_type endpoint, coordinate_type radius, unsigned int circle_points, ring_type& ring) { const coordinate_type dx = endpoint.x() - startpoint.x(); const coordinate_type dy = endpoint.y() - startpoint.y(); double angle_step; double offset; if (circle_points % 2 == 0) ++circle_points; if (startpoint.x() > endpoint.x()) swap(startpoint, endpoint); angle_step = 2 * bg::math::pi<double>() / circle_points; if (dx == 0) offset = bg::math::pi<double>(); else offset = atan(dy / dx) + bg::math::pi<double>() / 2; for (unsigned int i = 0; i < circle_points / 2 + 1; i++) ring.push_back(point_type(cos(angle_step * i + offset) * radius + startpoint.x(), sin(angle_step * i + offset) * radius + startpoint.y())); offset += bg::math::pi<double>(); for (unsigned int i = 0; i < circle_points / 2 + 1; i++) ring.push_back(point_type(cos(angle_step * i + offset) * radius + endpoint.x(), sin(angle_step * i + offset) * radius + endpoint.y())); bg::correct(ring); }
void GerberImporter::linear_draw_rectangular_aperture(point_type startpoint, point_type endpoint, coordinate_type width, coordinate_type height, ring_type& ring) { if (startpoint.y() > endpoint.y()) swap(startpoint, endpoint); if (startpoint.x() > endpoint.x()) { ring.push_back(point_type(startpoint.x() + width / 2, startpoint.y() + height / 2)); ring.push_back(point_type(startpoint.x() + width / 2, startpoint.y() - height / 2)); ring.push_back(point_type(startpoint.x() - width / 2, startpoint.y() - height / 2)); ring.push_back(point_type(endpoint.x() - width / 2, endpoint.y() - height / 2)); ring.push_back(point_type(endpoint.x() - width / 2, endpoint.y() + height / 2)); ring.push_back(point_type(endpoint.x() + width / 2, endpoint.y() + height / 2)); } else { ring.push_back(point_type(startpoint.x() + width / 2, startpoint.y() - height / 2)); ring.push_back(point_type(startpoint.x() - width / 2, startpoint.y() - height / 2)); ring.push_back(point_type(startpoint.x() - width / 2, startpoint.y() + height / 2)); ring.push_back(point_type(endpoint.x() - width / 2, endpoint.y() + height / 2)); ring.push_back(point_type(endpoint.x() + width / 2, endpoint.y() + height / 2)); ring.push_back(point_type(endpoint.x() + width / 2, endpoint.y() - height / 2)); } bg::correct(ring); }
void GerberImporter::draw_regular_polygon(point_type center, coordinate_type diameter, unsigned int vertices, coordinate_type offset, bool clockwise, ring_type& ring) { double angle_step; if (clockwise) angle_step = -2 * bg::math::pi<double>() / vertices; else angle_step = 2 * bg::math::pi<double>() / vertices; offset *= bg::math::pi<double>() / 180.0; for (unsigned int i = 0; i < vertices; i++) ring.push_back(point_type(cos(angle_step * i + offset) * diameter / 2 + center.x(), sin(angle_step * i + offset) * diameter / 2 + center.y())); ring.push_back(ring.front()); }
void Voronoi::copy_ring(const ring_type& ring, vector<segment_type_p> &segments) { for (auto iter = ring.begin(); iter + 1 != ring.end(); iter++) segments.push_back(segment_type_p(point_type_p(iter->x(), iter->y()), point_type_p((iter + 1)->x(), (iter + 1)->y()))); }
bool GerberImporter::simplify_cutins(ring_type& ring, polygon_type& polygon) { for (int i = 0; i < int(ring.size()) - 2; i++) { for (int j = i + 1; j < int(ring.size()) - 1; j++) { if (bg::equals(ring.at(i), ring.at(j + 1)) && bg::equals(ring.at(i + 1), ring.at(j))) { polygon.inners().resize(polygon.inners().size() + 1); polygon.inners().back().resize(j - i); copy(ring.begin() + i + 1, ring.begin() + j + 1, polygon.inners().back().begin()); ring.erase(ring.begin() + i + 1, ring.begin() + j + 2); break; } } } if (polygon.inners().size() > 0) { if (&ring != &(polygon.outer())) { polygon.outer().resize(ring.size()); copy(ring.begin(), ring.end(), polygon.outer().begin()); } bg::correct(polygon); return true; } else return false; }
void multipolygon_add_location(const osmium::geom::Coordinates& xy) { assert(!!m_polygon); assert(!!m_ring); m_ring->addPoint(xy.x, xy.y); }
void multipolygon_inner_ring_finish() { assert(!!m_polygon); assert(!!m_ring); m_polygon->addRingDirectly(m_ring.release()); }
void multipolygon_inner_ring_start() { m_ring.reset(new OGRLinearRing{}); }
polygon_type polygon_finish(size_t /* num_points */) { auto polygon = std::unique_ptr<OGRPolygon>{new OGRPolygon{}}; polygon->addRingDirectly(m_ring.release()); return polygon; }
void polygon_start() { m_ring.reset(new OGRLinearRing{}); }
void multipolygon_outer_ring_start() { m_ring.reset(new OGRLinearRing()); }