1- using FluentAssertions ;
1+ using System . Collections . Generic ;
2+ using FluentAssertions ;
23using GShark . Core ;
34using GShark . Geometry ;
4- using System . Collections . Generic ;
5- using GShark . Operation ;
65using Xunit ;
76
8- namespace GShark . Test . XUnit . Core
7+ namespace GShark . Test . XUnit . Core ;
8+
9+ public class TrigonometryTests
910{
10- public class TrigonometryTests
11+ [ Fact ]
12+ public void It_Returns_True_If_Points_Are_Planar ( )
13+ {
14+ // Arrange
15+ Point3 pt1 = new Point3 ( 0.0 , 0.0 , 0.0 ) ;
16+ Point3 pt2 = new Point3 ( 10.0 , 0.0 , 0.0 ) ;
17+ Point3 pt3 = new Point3 ( 5.0 , 5.0 , 0.0 ) ;
18+ Point3 pt4 = new Point3 ( - 5.0 , - 15.0 , 0.0 ) ;
19+ List < Point3 > points = new List < Point3 > { pt1 , pt2 , pt3 , pt4 } ;
20+
21+ // Arrange
22+ Trigonometry . ArePointsCoplanar ( points ) . Should ( ) . BeTrue ( ) ;
23+ }
24+
25+ [ Fact ]
26+ public void It_Returns_True_If_Three_Points_Are_Collinear ( )
1127 {
12- [ Fact ]
13- public void It_Returns_True_If_Points_Are_Planar ( )
14- {
15- // Arrange
16- Point3 pt1 = new Point3 ( 0.0 , 0.0 , 0.0 ) ;
17- Point3 pt2 = new Point3 ( 10.0 , 0.0 , 0.0 ) ;
18- Point3 pt3 = new Point3 ( 5.0 , 5.0 , 0.0 ) ;
19- Point3 pt4 = new Point3 ( - 5.0 , - 15.0 , 0.0 ) ;
20- List < Point3 > points = new List < Point3 > { pt1 , pt2 , pt3 , pt4 } ;
28+ // Arrange
29+ Point3 pt1 = new Point3 ( 25.923 , 27.057 , 0.0 ) ;
30+ Point3 pt2 = new Point3 ( 35.964 , 31.367 , 0.0 ) ;
31+ Point3 pt3 = new Point3 ( 51.299 , 37.950 , 0.0 ) ;
32+
33+ // Assert
34+ Trigonometry . ArePointsCollinear ( pt1 , pt2 , pt3 ) . Should ( ) . BeTrue ( ) ;
35+ }
2136
22- // Arrange
23- Trigonometry . ArePointsCoplanar ( points ) . Should ( ) . BeTrue ( ) ;
24- }
37+ [ Fact ]
38+ public void It_Returns_False_If_Three_Points_Are_Not_Collinear ( )
39+ {
40+ // Arrange
41+ Point3 pt1 = new Point3 ( 25.923 , 27.057 , 0.0 ) ;
42+ Point3 pt2 = new Point3 ( 35.964 , 20.451 , 0.0 ) ;
43+ Point3 pt3 = new Point3 ( 51.299 , 37.950 , 0.0 ) ;
2544
26- [ Fact ]
27- public void It_Returns_True_If_Three_Points_Are_Collinear ( )
28- {
29- // Arrange
30- Point3 pt1 = new Point3 ( 25.923 , 27.057 , 0.0 ) ;
31- Point3 pt2 = new Point3 ( 35.964 , 31.367 , 0.0 ) ;
32- Point3 pt3 = new Point3 ( 51.299 , 37.950 , 0.0 ) ;
45+ // Assert
46+ Trigonometry . ArePointsCollinear ( pt1 , pt2 , pt3 ) . Should ( ) . BeFalse ( ) ;
47+ }
3348
34- // Assert
35- Trigonometry . ArePointsCollinear ( pt1 , pt2 , pt3 ) . Should ( ) . BeTrue ( ) ;
36- }
49+ [ Theory ]
50+ [ InlineData ( new double [ ] { 5 , 7 , 0 } , new double [ ] { 6 , 6 , 0 } , 0.2 ) ]
51+ [ InlineData ( new double [ ] { 7 , 6 , 0 } , new [ ] { 6.5 , 6.5 , 0 } , 0.3 ) ]
52+ [ InlineData ( new double [ ] { 5 , 9 , 0 } , new double [ ] { 7 , 7 , 0 } , 0.4 ) ]
53+ public void It_Returns_The_Closest_Point_On_A_Segment ( double [ ] ptToCheck , double [ ] ptExpected , double tValExpected )
54+ {
55+ // Arrange
56+ // We are not passing a segment like a line or ray but the part that compose the segment,
57+ // t values [0 and 1] and start and end point.
58+ var testPt = new Point3 ( ptToCheck [ 0 ] , ptToCheck [ 1 ] , ptToCheck [ 2 ] ) ;
59+ var expectedPt = new Point3 ( ptExpected [ 0 ] , ptExpected [ 1 ] , ptExpected [ 2 ] ) ;
60+ Point3 pt0 = new Point3 ( 5 , 5 , 0 ) ;
61+ Point3 pt1 = new Point3 ( 10 , 10 , 0 ) ;
3762
38- [ Fact ]
39- public void It_Returns_False_If_Three_Points_Are_Not_Collinear ( )
40- {
41- // Arrange
42- Point3 pt1 = new Point3 ( 25.923 , 27.057 , 0.0 ) ;
43- Point3 pt2 = new Point3 ( 35.964 , 20.451 , 0.0 ) ;
44- Point3 pt3 = new Point3 ( 51.299 , 37.950 , 0.0 ) ;
63+ // Act
64+ ( double tValue , Point3 pt ) closestPt = Trigonometry . ClosestPointToSegment ( testPt , pt0 , pt1 , 0 , 1 ) ;
4565
46- // Assert
47- Trigonometry . ArePointsCollinear ( pt1 , pt2 , pt3 ) . Should ( ) . BeFalse ( ) ;
48- }
66+ // Assert
67+ closestPt . tValue . Should ( ) . BeApproximately ( tValExpected , GSharkMath . MaxTolerance ) ;
68+ closestPt . pt . EpsilonEquals ( expectedPt , GSharkMath . Epsilon ) . Should ( ) . BeTrue ( ) ;
69+ }
4970
50- [ Theory ]
51- [ InlineData ( new double [ ] { 5 , 7 , 0 } , new double [ ] { 6 , 6 , 0 } , 0.2 ) ]
52- [ InlineData ( new double [ ] { 7 , 6 , 0 } , new double [ ] { 6.5 , 6.5 , 0 } , 0.3 ) ]
53- [ InlineData ( new double [ ] { 5 , 9 , 0 } , new double [ ] { 7 , 7 , 0 } , 0.4 ) ]
54- public void It_Returns_The_Closest_Point_On_A_Segment ( double [ ] ptToCheck , double [ ] ptExpected , double tValExpected )
55- {
56- // Arrange
57- // We are not passing a segment like a line or ray but the part that compose the segment,
58- // t values [0 and 1] and start and end point.
59- var testPt = new Point3 ( ptToCheck [ 0 ] , ptToCheck [ 1 ] , ptToCheck [ 2 ] ) ;
60- var expectedPt = new Point3 ( ptExpected [ 0 ] , ptExpected [ 1 ] , ptExpected [ 2 ] ) ;
61- Point3 pt0 = new Point3 ( 5 , 5 , 0 ) ;
62- Point3 pt1 = new Point3 ( 10 , 10 , 0 ) ;
71+ [ Fact ]
72+ public void It_Returns_The_Area_Of_A_Triangle_From_A_Polyline ( )
73+ {
74+ // Arrange
75+ Point3 pt1 = new Point3 ( - 4.27 , 5.90 , 5.76 ) ;
76+ Point3 pt2 = new Point3 ( - 10 , - 7.69 , 0.0 ) ;
77+ Point3 pt3 = new Point3 ( 9.93 , - 2.65 , - 5.57 ) ;
78+ double expectedArea = 150.865499 ;
6379
64- // Act
65- ( double tValue , Point3 pt ) closestPt = Trigonometry . ClosestPointToSegment ( testPt , pt0 , pt1 , 0 , 1 ) ;
80+ // Act
81+ double area = Trigonometry . AreaOfTriangle ( pt1 , pt2 , pt3 ) ;
6682
67- // Assert
68- closestPt . tValue . Should ( ) . BeApproximately ( tValExpected , GSharkMath . MaxTolerance ) ;
69- closestPt . pt . EpsilonEquals ( expectedPt , GSharkMath . Epsilon ) . Should ( ) . BeTrue ( ) ;
70- }
83+ // Assert
84+ area . Should ( ) . BeApproximately ( expectedArea , GSharkMath . MaxTolerance ) ;
7185 }
72- }
86+ }
0 commit comments