Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.Tests/HeuristicLab.Problems.Bin-Packing-3.3/3D/Geometry/Line3DTest.cs @ 15554

Last change on this file since 15554 was 15554, checked in by rhanghof, 6 years ago

#2817:

  • Unittests
  • Bugfixes on the line projection based extreme point creation method
File size: 4.2 KB
Line 
1using System;
2using Microsoft.VisualStudio.TestTools.UnitTesting;
3using HeuristicLab.Problems.BinPacking3D.Geometry;
4using HeuristicLab.Problems.BinPacking3D;
5
6namespace HeuristicLab.Problems.BinPacking._3D.Geometry.Test {
7  [TestClass]
8  public class Line3DTest {
9    Line3D _line1;
10    Line3D _line2;
11    Line3D _line3;
12    Line3D _line4;
13    Line3D _line5;
14    Line3D _line6;
15
16    Vector3D _point1;
17    Vector3D _point2;
18    Vector3D _point3;
19    Vector3D _point4;
20    Vector3D _point5;
21    Vector3D _point6;
22
23    Plane3D _plane1;
24    Plane3D _plane2;
25    Plane3D _plane3;
26
27    [TestInitialize]
28    public void Initialize() {
29      _line1 = new Line3D(new Vector3D(0, 0, 0), new Vector3D(10, 0, 0));
30      _line2 = new Line3D(new Vector3D(0, 0, 0), new Vector3D(0, 10, 0));
31      _line3 = new Line3D(new Vector3D(0, 0, 0), new Vector3D(0, 0, 10));
32
33      _line4 = new Line3D(new Vector3D(-10, 2, 2), new Vector3D(10, 0, 0));
34      _line5 = new Line3D(new Vector3D(2, -10, 2), new Vector3D(0, 10, 0));
35      _line6 = new Line3D(new Vector3D(2, 2, -10), new Vector3D(0, 0, 10));
36
37      _point1 = new Vector3D(3, 0, 0);
38      _point2 = new Vector3D(0, 3, 0);
39      _point3 = new Vector3D(0, 0, 3);
40
41      _point4 = new Vector3D(5, 5, 5);
42      _point5 = new Vector3D(2, 2, 2);
43      _point6 = new Vector3D(0, 0, 0);
44
45      _plane1 = new Plane3D(_point6.ToPackingPosition(0), new PackingItem(10, 10, 10, new PackingShape()), Side.Top);
46      _plane2 = new Plane3D(_point6.ToPackingPosition(0), new PackingItem(10, 10, 10, new PackingShape()), Side.Right);
47      _plane3 = new Plane3D(_point6.ToPackingPosition(0), new PackingItem(10, 10, 10, new PackingShape()), Side.Front);
48    }
49
50
51    [TestMethod]
52    [TestCategory("Problems.BinPacking.3D")]
53    [TestProperty("Time", "short")]
54    public void TestIntersectsPlane() {
55      Assert.IsFalse(_line1.Intersects(_plane1));
56      Assert.IsTrue(_line2.Intersects(_plane1));
57      Assert.IsFalse(_line3.Intersects(_plane1));
58
59      Assert.IsTrue(_line1.Intersects(_plane2));
60      Assert.IsFalse(_line2.Intersects(_plane2));
61      Assert.IsFalse(_line3.Intersects(_plane2));
62
63      Assert.IsFalse(_line1.Intersects(_plane3));
64      Assert.IsFalse(_line2.Intersects(_plane3));
65      Assert.IsTrue(_line3.Intersects(_plane3));
66
67      Assert.IsTrue((new Line3D(new Vector3D(-1, -2, 2), new Vector3D(1, 3, 1))).Intersects(_plane1));
68      Assert.IsFalse((new Line3D(new Vector3D(-1, -2, 2), new Vector3D(-1, -3, 1))).Intersects(_plane1));
69    }
70
71    [TestMethod]
72    [TestCategory("Problems.BinPacking.3D")]
73    [TestProperty("Time", "short")]
74    public void TestIntersectPlane() {
75      Assert.IsNull(_line1.Intersect(_plane1));
76      Assert.AreEqual(new Vector3D(0, 10, 0), _line2.Intersect(_plane1));
77      Assert.IsNull(_line3.Intersect(_plane1));
78
79      Assert.AreEqual(new Vector3D(10, 0, 0), _line1.Intersect(_plane2));
80      Assert.IsNull(_line2.Intersect(_plane2));
81      Assert.IsNull(_line3.Intersect(_plane2));
82
83      Assert.IsNull(_line1.Intersect(_plane3));
84      Assert.IsNull(_line2.Intersect(_plane3));
85      Assert.AreEqual(new Vector3D(0, 0, 10), _line3.Intersect(_plane3));
86      Assert.AreEqual(new Vector3D(3, 10, 6), (new Line3D(new Vector3D(-1, -2, 2), new Vector3D(1, 3, 1))).Intersect(_plane1));
87      Assert.IsNull((new Line3D(new Vector3D(-1, -2, 2), new Vector3D(-1, -3, 1))).Intersect(_plane1));
88    }
89
90    [TestMethod]
91    [TestCategory("Problems.BinPacking.3D")]
92    [TestProperty("Time", "short")]
93    public void TestIntersectLine() {
94      Assert.IsNull(_line1.Intersect(_line4));
95      Assert.IsNull(_line1.Intersect(_line5));
96      Assert.IsNull(_line1.Intersect(_line6));
97
98      Assert.IsNotNull(_line1.Intersect(_line1));
99      Assert.IsNotNull(_line1.Intersect(_line2));
100      Assert.IsNotNull(_line1.Intersect(_line3));
101
102      Assert.IsNotNull(_line4.Intersect(_line5));
103      Assert.IsNotNull(_line4.Intersect(_line6));
104
105      Assert.IsTrue(_line1.Intersect(_line1).Equals(_point6));
106      Assert.IsTrue(_line1.Intersect(_line2).Equals(_point6));
107
108      Assert.IsTrue(_line4.Intersect(_line5).Equals(_point5));
109      Assert.IsTrue(_line4.Intersect(_line5).Equals(_point5));
110    }   
111  }
112}
Note: See TracBrowser for help on using the repository browser.