예제 #1
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);
        }
    }
}
예제 #2
0
void Intersect::visit(Line_CSPtr line, Arc_CSPtr arc) {
    visit(arc, geo::Vector(line->start(), line->end()));
}
예제 #3
0
void Intersect::visit(Line_CSPtr line, Circle_CSPtr circle) {
    visit(std::make_shared<Arc>(circle->center(), circle->radius(), 0., M_PI * 2., line->layer()), geo::Vector(line->start(), line->end()));
}
예제 #4
0
void Intersect::visit(Line_CSPtr l1, Line_CSPtr l2) {
    visit(l1, geo::Vector(l2->start(), l2->end()));
}
예제 #5
0
파일: line.cpp 프로젝트: rvirdiz/LibreCAD_3
Line::Line(const Line_CSPtr other, bool sameID) : CADEntity(other->layer(), other->metaTypes()), Vector(other->start(), other->end()) {
    if (sameID) {
        this->setID(other->id());
    }
}
예제 #6
0
Line::Line(const Line_CSPtr& other, bool sameID) : CADEntity(other, sameID),
                                                  geo::Vector(other->start(), other->end()) {
}