Ejemplo n.º 1
0
CADEntity_CSPtr Circle::scale(const geo::Coordinate& scale_center, const geo::Coordinate& scale_factor) const {
    // TODO return ellipse if scalefactor.x != scalefactor.y
    auto newCircle = std::make_shared<Circle>(this->center().scale(scale_center, scale_factor), this->radius() * fabs(scale_factor.x()), layer());
    newCircle->setID(this->id());
    //    return newCircle;

    if (fabs(scale_factor.x() - scale_factor.y()) > TOLERANCE) {
        auto newEllipse = std::make_shared<Ellipse>(this->center(), geo::Coordinate(this->radius(), 1.0), 1.0, 0., 0., layer());
        newEllipse->setID(this->id());
        return newEllipse;
    } else {
        return newCircle;
    }

}
Ejemplo n.º 2
0
void Intersect::visit(Line_CSPtr l1, const geo::Vector& v) {
    const geo::Coordinate p1 = l1->start();
    const geo::Coordinate p2 = l1->end();
    const geo::Coordinate p3 = v.start();
    const geo::Coordinate p4 = v.end();

    const double num = ((p4.x() - p3.x()) * (p1.y() - p3.y()) - (p4.y() - p3.y()) * (p1.x() - p3.x()));
    const double div = ((p4.y() - p3.y()) * (p2.x() - p1.x()) - (p4.x() - p3.x()) * (p2.y() - p1.y()));

    // TODO: We properly should add a tolorance here ??
    if (std::abs(div) > _tolerance) {
        double u = num / div;
        double xs = p1.x() + u * (p2.x() - p1.x());
        double ys = p1.y() + u * (p2.y() - p1.y());
        const geo::Coordinate coord(xs, ys);

        const geo::Area a1(p1, p2);
        const geo::Area a2(p3, p4);

        const bool a1b = a1.inArea(coord);
        const bool a2b = a2.inArea(coord);

        if (_method == Method::Any) {
            _intersectionPoints.push_back(coord);
        } else if (a1b && a2b) { // Test if it positivly fit's within a area
            _intersectionPoints.push_back(coord);
        } else if (
            (p1.x() == p2.x() && ys >= a1.minP().y() && ys <= a1.maxP().y() && a2b) || // when we deal with orizontal or vertical lines, inArea might not
            (p3.x() == p4.x() && ys >= a2.minP().y() && ys <= a2.maxP().y() && a1b) || // give a positive result, this conditions will confirm without using tolerance
            (p1.y() == p2.y() && xs >= a1.minP().x() && xs <= a1.maxP().x() && a2b) ||
            (p3.y() == p4.y() && xs >= a2.minP().x() && xs <= a2.maxP().x() && a1b)
        ) {
            _intersectionPoints.push_back(coord);
        }
    }
}
Ejemplo n.º 3
0
CADEntity_CSPtr Coordinate::copy(const geo::Coordinate& offset) const {
    auto newCoordinate = std::make_shared<Coordinate>(this->x() + offset.x(), this->y() + offset.y(), layer());
    return newCoordinate;
}
Ejemplo n.º 4
0
CADEntity_CSPtr Arc::scale(const geo::Coordinate& scale_center, const geo::Coordinate& scale_factor) const {
    auto newArc = std::make_shared<Arc>(this->center().scale(scale_center, scale_factor), this->radius() * fabs(scale_factor.x()),
                                        this->startAngle(), this->endAngle(), layer());
    newArc->setID(this->id());
    return newArc;

}