Skip to content

Commit

Permalink
- A triangle can have double points or colinear points, my bad. It is a
Browse files Browse the repository at this point in the history
degenerate triangle
- remove duplicate tests (triangle2())
  • Loading branch information
lbartoletti committed Oct 26, 2017
1 parent acbd9d1 commit 6bcbbeb
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 735 deletions.
128 changes: 40 additions & 88 deletions python/core/geometry/qgstriangle.sip
Expand Up @@ -25,7 +25,6 @@ class QgsTriangle : QgsPolygonV2
QgsTriangle( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3 );
%Docstring
Construct a QgsTriangle from three QgsPointV2.
An empty triangle is returned if there are identical points or if the points are collinear.
\param p1 first point
\param p2 second point
\param p3 third point
Expand All @@ -34,7 +33,6 @@ class QgsTriangle : QgsPolygonV2
explicit QgsTriangle( const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3 );
%Docstring
Construct a QgsTriangle from three QgsPoint.
An empty triangle is returned if there are identical points or if the points are collinear.
\param p1 first point
\param p2 second point
\param p3 third point
Expand All @@ -43,7 +41,6 @@ class QgsTriangle : QgsPolygonV2
explicit QgsTriangle( const QPointF p1, const QPointF p2, const QPointF p3 );
%Docstring
Construct a QgsTriangle from three QPointF.
An empty triangle is returned if there are identical points or if the points are collinear.
\param p1 first point
\param p2 second point
\param p3 third point
Expand Down Expand Up @@ -117,18 +114,14 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
Returns the three lengths of the triangle.
:return: Lengths of triangle ABC where [AB] is at 0, [BC] is at 1, [CA] is at 2.
An empty list is returned for empty or invalid triangle.
An empty list is returned for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
tri.lengths()
# [5.0, 5.0, 7.0710678118654755]
QgsTriangle().lengths()
# []
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).lengths()
# []
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).lengths()
# []
\endcode
:rtype: list of float
%End
Expand All @@ -137,27 +130,45 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
Returns the three angles of the triangle.
:return: Angles in radians of triangle ABC where angle BAC is at 0, angle ABC is at 1, angle BCA is at 2.
An empty list is returned for empty or invalid triangle.
An empty list is returned for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
[math.degrees(i) for i in tri.angles()]
# [45.0, 90.0, 45.0]
QgsTriangle().angles()
# []
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).angles()
# []
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).angles()
# []
\endcode
:rtype: list of float
%End

bool isDegenerate();
%Docstring
Convenient method checking if the geometry is degenerate (have duplicate or colinear point(s)).
:return: True if the triangle is degenerate or empty, otherwise false.
Example:
\code{.py}
tri = QgsTriangle()
tri.isDegenerate()
# True
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
tri.isDegenerate()
# False
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) )
tri.isDegenerate()
# True
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 5, 5 ) )
tri.isDegenerate()
# True
\endcode
:rtype: bool
%End

bool isIsocele( double lengthTolerance = 0.0001 ) const;
%Docstring
Is the triangle isocele (two sides with the same length)?
\param lengthTolerance The tolerance to use
:return: True or False. Always false for empty or invalid triangle.
:return: True or False. Always false for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
Expand All @@ -168,10 +179,6 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
# length of [AB] == length of [BC]
QgsTriangle().isIsocele()
# False
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).isIsocele()
# False
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).isIsocele()
# False
\endcode
:rtype: bool
%End
Expand All @@ -180,7 +187,7 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
Is the triangle equilateral (three sides with the same length)?
\param lengthTolerance The tolerance to use
:return: True or False. Always false for empty or invalid triangle.
:return: True or False. Always false for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 10, 10 ), QgsPoint( 16, 10 ), QgsPoint( 13, 15.1962 ) )
Expand All @@ -191,10 +198,6 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
# All lengths are close to 6.0
QgsTriangle().isEquilateral()
# False
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).isEquilateral()
# False
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).isEquilateral()
# False
\endcode
:rtype: bool
%End
Expand All @@ -203,7 +206,7 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
Is the triangle right-angled?
\param angleTolerance The tolerance to use
:return: True or False. Always false for empty or invalid triangle.
:return: True or False. Always false for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
Expand All @@ -214,10 +217,6 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
# angle of ABC == 90
QgsTriangle().isRight()
# False
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).isRight()
# False
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).isRight()
# False
\endcode
:rtype: bool
%End
Expand All @@ -226,7 +225,7 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
Is the triangle scalene (all sides have differen lengths)?
\param lengthTolerance The tolerance to use
:return: True or False. Always false for empty or invalid triangle.
:return: True or False. Always false for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 7.2825, 4.2368 ), QgsPoint( 13.0058, 3.3218 ), QgsPoint( 9.2145, 6.5242 ) )
Expand All @@ -237,10 +236,6 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
# All lengths are different
QgsTriangle().isScalene()
# False
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).isScalene()
# False
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).isScalene()
# False
\endcode
:rtype: bool
%End
Expand All @@ -249,18 +244,14 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
An altitude is a segment (defined by a QgsLineString) from a vertex to the opposite side (or, if necessary, to the extension of the opposite side).
:return: Three altitudes from this triangle.
An empty list is returned for empty or invalid triangle.
An empty list is returned for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
[alt.asWkt() for alt in tri.altitudes()]
# ['LineString (0 0, 0 5)', 'LineString (0 5, 2.5 2.5)', 'LineString (5 5, 0 5)']
QgsTriangle().altitudes()
# []
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).altitudes()
# []
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).altitudes()
# []
\endcode
:rtype: list of QgsLineString
%End
Expand All @@ -269,18 +260,14 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
A median is a segment (defined by a QgsLineString) from a vertex to the midpoint of the opposite side.
:return: Three medians from this triangle.
An empty list is returned for empty or invalid triangle.
An empty list is returned for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
[med.asWkt() for med in tri.medians()]
# ['LineString (0 0, 2.5 5)', 'LineString (0 5, 2.5 2.5)', 'LineString (5 5, 0 2.5)']
QgsTriangle().medians()
# []
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).medians()
# []
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).medians()
# []
\endcode
:rtype: list of QgsLineString
%End
Expand All @@ -290,18 +277,14 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
The segment (defined by a QgsLineString) returned bisect the angle of a vertex to the opposite side.
\param lengthTolerance The tolerance to use.
:return: Three angle bisector from this triangle.
An empty list is returned for empty or invalid triangle.
An empty list is returned for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
[bis.asWkt() for bis in tri.bisectors()]
# ['LineString (0 0, 2.07106781186547462 5)', 'LineString (0 5, 2.5 2.5)', 'LineString (5 5, 0 2.92893218813452538)']
QgsTriangle().bisectors()
# []
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).bisectors()
# []
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).bisectors()
# []
\endcode
:rtype: list of QgsLineString
%End
Expand All @@ -310,18 +293,14 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
Medial (or midpoint) triangle of a triangle ABC is the triangle with vertices at the midpoints of the triangle's sides.
:return: The medial from this triangle.
An empty triangle is returned for empty or invalid triangle.
An empty triangle is returned for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
tri.medial().asWkt()
# 'Triangle ((0 2.5, 2.5 5, 2.5 2.5, 0 2.5))'
QgsTriangle().medial().asWkt()
# 'Triangle ( )'
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).medial().asWkt()
# 'Triangle ( )'
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).medial().asWkt()
# 'Triangle ( )'
\endcode
:rtype: QgsTriangle
%End
Expand All @@ -331,18 +310,14 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
An orthocenter is the point of intersection of the altitudes of a triangle.
\param lengthTolerance The tolerance to use
:return: The orthocenter of the triangle.
An empty point is returned for empty or invalid triangle.
An empty point is returned for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
tri.orthocenter().asWkt()
# 'Point (0 5)'
QgsTriangle().orthocenter().asWkt()
# 'Point (0 0)'
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).orthocenter().asWkt()
# 'Point (0 0)'
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).orthocenter().asWkt()
# 'Point (0 0)'
\endcode
:rtype: QgsPoint
%End
Expand All @@ -351,18 +326,14 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
Center of the circumscribed circle of the triangle.
:return: The center of the circumscribed circle of the triangle.
An empty point is returned for empty or invalid triangle.
An empty point is returned for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
tri.circumscribedCenter().asWkt()
# 'Point (2.5 2.5)'
QgsTriangle().circumscribedCenter().asWkt()
# 'Point (0 0)'
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).circumscribedCenter().asWkt()
# 'Point (0 0)'
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).circumscribedCenter().asWkt()
# 'Point (0 0)'
\endcode
:rtype: QgsPoint
%End
Expand All @@ -371,18 +342,14 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
Radius of the circumscribed circle of the triangle.
:return: The radius of the circumscribed circle of the triangle.
0.0 is returned for empty or invalid triangle.
0.0 is returned for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
tri.circumscribedRadius()
# 3.5355339059327378
QgsTriangle().circumscribedRadius()
# 0.0
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).circumscribedRadius()
# 0.0
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).circumscribedRadius()
# 0.0
\endcode
:rtype: float
%End
Expand All @@ -391,18 +358,14 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
Circumscribed circle of the triangle.
:return: The circumbscribed of the triangle with a QgsCircle.
An empty circle is returned for empty or invalid triangle.
An empty circle is returned for empty triangle.
Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
tri.circumscribedCircle()
# QgsCircle(Point (2.5 2.5), 3.5355339059327378, 0)
QgsTriangle().circumscribedCircle()
# QgsCircle()
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).circumscribedCircle()
# QgsCircle()
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).circumscribedCircle()
# QgsCircle()
\endcode
:rtype: QgsCircle
%End
Expand All @@ -411,18 +374,14 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
Center of the inscribed circle of the triangle.
:return: The center of the inscribed circle of the triangle.
An empty point is returned for empty or invalid triangle.
An empty point is returned for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
tri.inscribedCenter().asWkt()
# 'Point (1.46446609406726225 3.53553390593273775)'
QgsTriangle().inscribedCenter().asWkt()
# 'Point (0 0)'
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).inscribedCenter().asWkt()
# 'Point (0 0)'
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).inscribedCenter().asWkt()
# 'Point (0 0)'
\endcode
:rtype: QgsPoint
%End
Expand All @@ -431,18 +390,14 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
Radius of the inscribed circle of the triangle.
:return: The radius of the inscribed circle of the triangle.
0.0 is returned for empty or invalid triangle.
0.0 is returned for empty triangle.
* Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
tri.inscribedRadius()
# 1.4644660940672622
QgsTriangle().inscribedRadius()
# 0.0
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).inscribedRadius()
# 0.0
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).inscribedRadius()
# 0.0
\endcode
:rtype: float
%End
Expand All @@ -451,22 +406,19 @@ Inherited method not used. You cannot delete or insert a vertex directly. Return
%Docstring
Inscribed circle of the triangle.
:return: The inscribed of the triangle with a QgsCircle.
An empty circle is returned for empty or invalid triangle.
An empty circle is returned for empty triangle.
Example:
\code{.py}
tri = QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 5 ), QgsPoint( 5, 5 ) )
tri.inscribedCircle()
# QgsCircle(Point (1.46446609406726225 3.53553390593273775), 1.4644660940672622, 0)
QgsTriangle().inscribedCircle()
# QgsCircle()
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 5, 5 ), QgsPoint( 10, 10 ) ).inscribedCircle()
# QgsCircle()
QgsTriangle( QgsPoint( 0, 0 ), QgsPoint( 0, 0 ), QgsPoint( 10, 10 ) ).inscribedCircle()
# QgsCircle()
\endcode
:rtype: QgsCircle
%End


};
/************************************************************************
* This file has been generated automatically from *
Expand Down

0 comments on commit 6bcbbeb

Please sign in to comment.