@@ -4223,6 +4223,34 @@ def testClipped(self):
42234223 self .assertTrue (compareWkt (result , exp , 0.00001 ),
42244224 "clipped: mismatch Expected:\n {}\n Got:\n {}\n " .format (exp , result ))
42254225
4226+ def testHausdorff (self ):
4227+ tests = [["POLYGON((0 0, 0 2, 1 2, 2 2, 2 0, 0 0))" , "POLYGON((0.5 0.5, 0.5 2.5, 1.5 2.5, 2.5 2.5, 2.5 0.5, 0.5 0.5))" , 0.707106781186548 ],
4228+ ["LINESTRING (0 0, 2 1)" , "LINESTRING (0 0, 2 0)" , 1 ],
4229+ ["LINESTRING (0 0, 2 0)" , "LINESTRING (0 1, 1 2, 2 1)" , 2 ],
4230+ ["LINESTRING (0 0, 2 0)" , "MULTIPOINT (0 1, 1 0, 2 1)" , 1 ],
4231+ ["LINESTRING (130 0, 0 0, 0 150)" , "LINESTRING (10 10, 10 150, 130 10)" , 14.142135623730951 ]
4232+ ]
4233+ for t in tests :
4234+ g1 = QgsGeometry .fromWkt (t [0 ])
4235+ g2 = QgsGeometry .fromWkt (t [1 ])
4236+ o = g1 .hausdorffDistance (g2 )
4237+ exp = t [2 ]
4238+ self .assertAlmostEqual (o , exp , 5 ,
4239+ "mismatch for {} to {}, expected:\n {}\n Got:\n {}\n " .format (t [0 ], t [1 ], exp , o ))
4240+
4241+ def testHausdorffDensify (self ):
4242+ tests = [
4243+ ["LINESTRING (130 0, 0 0, 0 150)" , "LINESTRING (10 10, 10 150, 130 10)" , 0.5 , 70.0 ]
4244+ ]
4245+ for t in tests :
4246+ g1 = QgsGeometry .fromWkt (t [0 ])
4247+ g2 = QgsGeometry .fromWkt (t [1 ])
4248+ densify = t [2 ]
4249+ o = g1 .hausdorffDistanceDensify (g2 , densify )
4250+ exp = t [3 ]
4251+ self .assertAlmostEqual (o , exp , 5 ,
4252+ "mismatch for {} to {}, expected:\n {}\n Got:\n {}\n " .format (t [0 ], t [1 ], exp , o ))
4253+
42264254
42274255if __name__ == '__main__' :
42284256 unittest .main ()
0 commit comments