static CArea make_obround(const Point& p0, const Point& p1, double radius) { Point dir = p1 - p0; double d = dir.length(); dir.normalize(); Point right(dir.y, -dir.x); CArea obround; CCurve c; if(fabs(radius) < 0.0000001)radius = (radius > 0.0) ? 0.002 : (-0.002); Point vt0 = p0 + right * radius; Point vt1 = p1 + right * radius; Point vt2 = p1 - right * radius; Point vt3 = p0 - right * radius; c.append(vt0); c.append(vt1); c.append(CVertex(1, vt2, p1)); c.append(vt3); c.append(CVertex(1, vt0, p0)); obround.append(c); return obround; }
void CCurve::CurveIntersections(const CCurve& c, std::list<Point> &pts)const { CArea a; a.append(*this); a.CurveIntersections(c, pts); }
bool CCurve::Offset(double leftwards_value) { // use the kurve code donated by Geoff Hawkesford, to offset the curve as an open curve // returns true for success, false for failure bool success = true; CCurve save_curve = *this; try { geoff_geometry::Kurve k = MakeKurve(*this); geoff_geometry::Kurve kOffset; int ret = 0; k.OffsetMethod1(kOffset, fabs(leftwards_value), (leftwards_value > 0) ? 1:-1, 1, ret); success = (ret == 0); if(success)*this = MakeCCurve(kOffset); } catch(...) { success = false; } if(success == false) { if(this->IsClosed()) { double inwards_offset = leftwards_value; bool cw = false; if(this->IsClockwise()) { inwards_offset = -inwards_offset; cw = true; } CArea a; a.append(*this); a.Offset(inwards_offset); if(a.m_curves.size() == 1) { Span* start_span = NULL; if(this->m_vertices.size() > 1) { std::list<CVertex>::iterator It = m_vertices.begin(); CVertex &v0 = *It; It++; CVertex &v1 = *It; start_span = new Span(v0.m_p, v1, true); } *this = a.m_curves.front(); if(this->IsClockwise() != cw)this->Reverse(); if(start_span) { Point forward = start_span->GetVector(0.0); Point left(-forward.y, forward.x); Point offset_start = start_span->m_p + left * leftwards_value; this->ChangeStart(this->NearestPoint(offset_start)); delete start_span; } success = true; } } } return success; }
ThickLine(const CCurve& curve) { m_curve = curve; m_area.append(curve); m_area.Thicken(0.001); }