Ejemplo n.º 1
0
bool Graph_Completer::crosses_an_edge(const segment &S)
{
    bool crossing = false;
    segment segment_1 = S, segment_2;

    vertex_label label;
    Point content;
    std::vector<vertex_label> N;

    unsigned int j, k;
    for(j=0; j<G_->nb_vertices(); j++)
    {
        label = G_->get_label_by_index(j);
        content = G_->get_content_by_index(j);
        N = G_->get_neighbors_by_index(j);

        for(k=0; k<N.size(); k++)
        {
            if(N[k] < label)
            {
                continue;
            }
            else
            {
                segment_2 = segment(content, G_->get_content_by_label(N[k]));
                if (segment_1.first.get_affix() == segment_2.first.get_affix() &&
                        segment_1.second.get_affix() == segment_2.second.get_affix())
                {
                    crossing = true;
                    break;
                }
                if(segment_1.first.get_affix() == segment_2.first.get_affix() ||
                        segment_1.first.get_affix() == segment_2.second.get_affix() ||
                        segment_1.second.get_affix() == segment_2.first.get_affix() ||
                        segment_1.second.get_affix() == segment_2.second.get_affix())
                {
                    continue;
                }
                if(are_intersecting(segment_1,segment_2))
                {
                    crossing = true;
                    break;
                }
            }
        }

        if(crossing)
        {
            break;
        }
    }

    return crossing;
}
Ejemplo n.º 2
0
void c15()
{
    double lines[max_number_of_lines][parameters + 2]; // array to store lines, entered by user
    int lines_entered     = 0;                         // counter, how many lines are entered
    const int checked     = 1;                         // flag line is already processed (used in parallelness check and printing)
    const int not_checked = -1;                        // flag line is not yet processed

    // getting lines from user
    for (int line = 0; line < max_number_of_lines; line++, lines_entered++)
    {
        double* input_line = get_line();

        if (is_stop(input_line))
        {
            lines_entered--;
            break;
        }
        else
        {
            lines[line][a]  = input_line[a];
            lines[line][b]  = input_line[b];
            lines[line][c]  = input_line[c];
            lines[line][state]        = not_checked;
            lines[line][parallelness] = not_checked;
        }
    }

    bool exists_parallels = false;

    // mark lines parallel
    for (int line = 0; line < lines_entered; line++)
    {
        // if line not yet marked as being parallel
        if (lines[line][state] == not_checked)
        {
            // loop through lines, starting from next one till end
            for (int next_line = line + 1; next_line < lines_entered; next_line++)
            {
                if (is_parallel(lines[line], lines[next_line]))
                {
                    // mark current line as parallel to line from outer loop
                    lines[next_line][state] = checked;
                    lines[next_line][parallelness] = line;
                    exists_parallels = true;
                }
            }
        }
    }

    // reseting state for printing
    for (int line = 0; line < lines_entered; line++)
        lines[line][state] = not_checked;

    // print out result of parallelness check
    if (exists_parallels)
    {
        bool has_parallels;
        print("Parallel lines are:");
        for (int line = 0; line < lines_entered; line++)
        {
            // cout << "entering with line " << line + 1 << endl;

            string output_lines = "    Line " + to_char(line+1);
            has_parallels = false;

            // if line is not yet printed
            if (lines[line][state] == not_checked)
            {
                for (int next_line = line + 1; next_line < lines_entered; next_line++)
                {
                    if (lines[next_line][parallelness] == line)
                    {
                        lines[next_line][state] = checked;
                        output_lines += ", line " + to_char(next_line+1);
                        has_parallels = true;
                    }
                }
            }
            if (has_parallels) print(output_lines);
        }
    }
    else
    {
        print("There are no parallel lines.");
    }

    // combinations by 3 lines out of all lines
    bool exists_triple_intersection = false;

    for (int line1 = 0; line1 < lines_entered; line1++)
    {
        for (int line2 = line1+1; line2 < lines_entered; line2++)
        {
            for (int line3 = line2+1; line3 < lines_entered; line3++)
            {
                if (are_intersecting(lines[line1], lines[line2], lines[line3]))
                {
                    exists_triple_intersection = true;
                    // double* intersection_of_1_and_2 = intersection(lines[line1], lines[line2]);
                    // cout << "Intersection is " << intersection_of_1_and_2[0] << ";" << intersection_of_1_and_2[1];
                    cout << endl << "Following lines are intersecting at same point: ";
                    print(lines[line1]);
                    print(lines[line2]);
                    print(lines[line3]);
                }
            }
        }
    }

    if (!exists_triple_intersection)
        print("Not triple intersection exists.");
}