BUAA personal software engineering project

EDITORIAL

project content
Owned courses Spring 2020 Computer Software Engineering Institute (Roger Ren Jian) ​​(Northern)
Work requirements Individual project work
Course targets Training of software development capabilities
This specific role to achieve the objectives of the job The ability to exercise personal development projects
Teaching classes 006
github project address https://github.com/LiuZH-19/SE_IntersectProject

PSP form to record

PSP2.1 Personal Software Process Stages Estimated time consuming (minutes) The actual time-consuming (minutes)
Planning plan
· Estimate • Estimate how much time this task requires 5 10
Development Develop
· Analysis · Needs analysis (including learning new technologies) 180 220
· Design Spec Generate design documents 10 20
· Design Review · Design Review (and his colleagues reviewed the design documents) 15 20
· Coding Standard · Code specifications (development of appropriate norms for the current development) 5 5
· Design · Specific design 30 60
· Coding · Specific coding 120 160
· Code Review · Code Review 20 20
· Test · Test (self-test, modify the code, submit modifications) 120 120
Reporting report
· Test Report · testing report 30 30
· Size Measurement · Computing workload 5 5
· Postmortem & Process Improvement Plan · Hindsight, and propose process improvement plan 10 30
total 550 700

Description of problem-solving ideas

General idea:

After reading the title, think of the method is:

  • Mathematical methods solving two straight lines L1, the presence of the intersection of the formula and its existence conditions intersection L2.

  • Then for any two lines of input, judgment. If there is an intersection, then taken into the container (to avoid repetitive element in the container)

  • Finally, the number of intersections in the output container

    However, considering the need for a linear input twenty-two solving complexity is O ($ n ^ 2 $). I'm going to look it up online to see if there is more clever algorithm.

    Queries to no avail, and small partners to discuss a bit, there is no better algorithm. It is intended by this algorithm, think about details .

    In order to avoid analyze some special cases of a straight line, I am going to line represents the general formula: Ax + By + C = 0

    Additional questions, is similar ideas:

    Solving the intersection of two straight lines two, then before solving the intersection where a straight line, and then solving the case of the intersection between two circles.

    Before solving the intersection, an intersection having a first determination condition is satisfied, to avoid unnecessary calculations

Details to consider:

Intersection of the line and the line count is better, so he worked out a formula hand relationship.

Line and circle equation is hand counted.

Round and round before the intersection formula, solve for my big head, not sure of himself counted out right, so the online reference algorithms. See

Seeking any intersection of two circles

Design and implementation process

Code Organization:

Beginning envisaged :

  • Class design:

    • Line Class
      • = 0 is represented by a straight line Ax + By + C, where A, B, C as x1, y1, x2, y2 function of
      • Attribute A, B, C
      • Member function is getA (), getB (), getC ()
    • Circle class
      • Circle with $ (xX) ^ {2} + (yY) ^ {2} = R ^ 2 $ represents
      • Attributes X, Y, R
      • Member function is getX (), getY (), getR ()
  • With a vector to store all of the straight line

  • Pair intersection of the type used to store all the set intersection

  • Three functions, respectively, between the line and the circle is calculated between two straight lines, where the intersection between two circles.

    According to the realization of the above ideas, I found Line and Circle class a bit redundant. Textbooks also said that only the data package, you do not class with struct. So I'm going to be straight and circular arguments with structure to save. The three cases previously calculated intersection packaged as a function of the Calculator class. Considering also that the loss of accuracy in the calculation of the problem, the point type configuration, the override operator < . Details are as follows:

    Later improvements:

  • Calculator class
    overrides three member functions

    class Calculator
    {
    public:
      Calculator();
      int haveIntersection(Line l1, Line l2, set<Point>& nodeSet);
      int haveIntersection(Circle c, Line l, set<Point>& nodeSet);
      int haveIntersection(Circle c1, Circle c2, set<Point>& nodeSet);
    };
    
  • Point class
    customized operator

    bool Point::operator < (const Point& p)const {
        //return x==p.x?y<p.y:x<p.x;
        return dcmp(x - p.x) == 0 ? dcmp(y - p.y) < 0 : dcmp(x - p.x) < 0;
    
    }
    
    bool Point::operator ==(const Point& p)const {
        if (dcmp(x-p.x)==0&&dcmp(y-p.y)==0)
            return true;
        return false;
    }
  • Line and Circle of body architecture

  • function countALLinsect main () in
    the intersection case, between the line between the line and the circle between the circle and circle are calculated

Unit test design

  • Test Calculator class specifically includes the following aspects:
    • Intersection of the straight line straight
      • parallel
      • Three lines intersect at one point
      • A straight line parallel to the x-axis
      • A straight line parallel to the y-axis
      • generally
    • Intersection of the straight line and circle
      • Special case of a straight line
      • Line round relations
        • Tangent
        • Way off
        • intersect
    • Intersection relationship circle and circle
      • Way off
      • intersect
      • Exo
      • Endo
      • Contains (concentric)
    • Complex situations (two circle and a straight line)
      • There is a point of intersection overlap
      • There are two points of intersection overlap
      • generally
  • Test point type
    detecting override operator <is correct
  • Overall test
    • Large amounts of data test, the detection time whether the meaning of the questions
    • Whether to re-set detection

When the tests are passed, and the intersection of about 8 million, with a time of 7s, and no timeouts.

Performance Improvements

As can be seen in FIG., The use of the container set, red-black tree constructed occupy the majority of CPU time. Achievements in the process, I used the rewrite of the Point class inside operator <, so the elapsed time is greater. Removing the outer set of related operations, we go to the next function in the Calculator.

Which occupies most of the CPU time is still the set of insert operations. So I could not think of a more optimal algorithm, very little work to do to improve the performance. I will some commonly used calculation formula to work out, to avoid double counting after. For example, FIG:

Eliminate all warnings Code Quality Analysis of

Uses "Microsoft recommends that" style.

Key Code Description

  • Solving the intersection of all cases: Before a straight line, between straight and round, round two

    int countAllinsect(vector<Line> lVec, vector<Circle> cVec, set<Point> &nodeSet){
        Calculator* calc = new Calculator();
        size_t i, j;
        //计算两条直线间的交点
        for (i = 0; i < lVec.size(); i++) {
            for (j = i + 1; j < lVec.size(); j++) {
                calc->haveIntersection(lVec[i], lVec[j], nodeSet);
            }
        }
        //计算直线与圆之间的交点
        for (i = 0; i < cVec.size(); i++) {
            for (j = 0; j < lVec.size(); j++) {
                calc->haveIntersection(cVec[i], lVec[j], nodeSet);
            }
        }
            //计算两圆之间的交点
        for (i = 0; i < cVec.size(); i++) {
            for (j = i + 1; j < cVec.size(); j++) {
                calc->haveIntersection(cVec[i], cVec[j], nodeSet);
            }
        }
        return nodeSet.size();
    }

    Very violent method is to loop through.

confused

The project involves precision floating point calculations. Because of the division and square root formula, resulting in the final points calculated is just approx. So I rewrote the comparison function, EPS ultimately take is 0.0000001. While the EPS is the result of my test repeatedly elected value, but I can not guarantee that any course of his usefulness. Therefore, when determining whether a coincident point, there may be an error.

Here is the relevant code on the accuracy of the problem:

#define EPS  0.0000001

int dcmp(double x) {
    if (fabs(x) < EPS) return 0;
    return x < 0 ? -1 : 1;
}

bool Point::operator < (const Point& p)const {
    //return x==p.x?y<p.y:x<p.x;
    return dcmp(x - p.x) == 0 ? dcmp(y - p.y) < 0 : dcmp(x - p.x) < 0;

}

Guess you like

Origin www.cnblogs.com/lzh-blod/p/12456847.html