Ejemplo n.º 1
0
        public void ifLinesAreParallelAndInterSectThenReturnsIntersection()
        {
            Line a = new Line(new Point(0, 0), new Point(1, 1));
            Line b = new Line(new Point(-1, -1), new Point(0, 0));

            Assert.AreEqual(0, a.crosses(b, 0.01).X, "the crossing point x is correct");
            Assert.AreEqual(0, a.crosses(b, 0.01).Y, "the crossing point y is correct");
        }
Ejemplo n.º 2
0
        public void ifLinesAreParallelAndDoNotInterSectThenReturnsNull()
        {
            Line a = new Line(new Point(0, 0), new Point(1, 1));
            Line b = new Line(new Point(-2, -2), new Point(-1, -1));

            Assert.AreEqual(null, a.crosses(b, 0.01), "the crossing point is correctely null");
        }
Ejemplo n.º 3
0
        public void ifLinesCrossThenReturnsCrossingPt()
        {
            Line a = new Line(new Point(0, 0), new Point(2, 2));
            Line b = new Line(new Point(0, 2), new Point(2, 0));

            Assert.AreEqual(new Point(1, 1), a.crosses(b, 0.01), "the crossing point is correctely the intersection point");

            a = new Line(new Point(1, 0), new Point(1, 2));
            b = new Line(new Point(0, 0), new Point(2, 2));

            Assert.AreEqual(new Point(1, 1), a.crosses(b, 0.01), "the crossing point is correctely the intersection point for vertical line");
        }
Ejemplo n.º 4
0
        private void processPath(string path, string transformationData, int officeNumber)
        {
            string[] coordinates = path.Split(' ');

            if (coordinates.Length > 1)
            {
                Point current_pt = new Point(getCoordinateFromString(coordinates[0]), getCoordinateFromString(coordinates[1]));
                transform(transformationData, current_pt);

                for (int i = 2; i < coordinates.Length - 1; i += 2)
                {
                    Point end_pt = new Point(getCoordinateFromString(coordinates[i]), getCoordinateFromString(coordinates[i + 1]));
                    transform(transformationData, end_pt);

                    if (!startNewLine(coordinates[i]))
                    {
                        Line curr_line = new Line(current_pt, end_pt, officeNumber);

                        for (int j = 0; j < lines.Count; j++)
                        {
                            Point crossing_pt = curr_line.crosses(lines[j], epsilon);
                            if (!string.IsNullOrEmpty(Convert.ToString(crossing_pt)))
                            {
                                Node new_node = new Node();
                                new_node.CrossingPoint = crossing_pt;
                                if (curr_line.getOfficeNumber() != -1)
                                {
                                    new_node.OfficeLocation = curr_line.getOfficeNumber();
                                }
                                else if (lines[j].getOfficeNumber() != -1)
                                {
                                    new_node.OfficeLocation = lines[j].getOfficeNumber();
                                }
                                graph.addNode(new_node);
                            }
                        }
                        lines.Add(curr_line);
                    }
                    current_pt = end_pt;
                }
            }
        }