SG_checker.py
Go to the documentation of this file.
1 #==============================================================================
2 # Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 # Author: Gonzalo Mier
4 # BSD-3 License
5 #==============================================================================
6 
7 import pytest
8 import fields2cover as f2c
9 
10 def near(a, b):
11  assert pytest.approx(a) == pytest.approx(b)
12 
13 
14 def IsSwathGenerationCorrect(sw_gen, obj, poly, swath_width = 1.0, checks = 100):
15  swaths = sw_gen.generateBestSwaths(obj, swath_width, poly);
16  assert not (swaths.size() < 1), "Error 2001: No swaths were generated.";
17  assert not (swaths.size() > poly.area() / (swath_width * swath_width)), \
18  "Error 2002: " + str(swaths.size()) + " swaths were generated." + \
19  "Expected less than " + str(poly.area() / (swath_width * swath_width)) + \
20  "swaths.";
21 
22  rand = f2c.Random();
23  for i in range(checks):
24  rand_ang = rand.getAngleRandom();
25  swaths2 = sw_gen.generateSwaths(rand_ang, swath_width, poly);
26  assert (obj.computeCostWithMinimizingSign(swaths) <= \
27  obj.computeCostWithMinimizingSign(swaths2)), \
28  "Error 2003: Cost (signed) of the optimal angle is " + \
29  str(obj.computeCostWithMinimizingSign(swaths)) + \
30  ", but the cost (signed) of a non-optimal angle (" + \
31  str(rand_ang) + ") is " + \
32  str(obj.computeCostWithMinimizingSign(swaths2)) + ".";
33  assert not (swaths.size() > poly.area() / (swath_width * swath_width)), \
34  "Error 2004: " + str(swaths2.size()) + \
35  " swaths were generated with angle " + str(rand_ang) + \
36  "Expected less than " + str(poly.area() / (swath_width * swath_width)) + \
37  "swaths.";
38 
swath_generator.SG_checker.IsSwathGenerationCorrect
def IsSwathGenerationCorrect(sw_gen, obj, poly, swath_width=1.0, checks=100)
Definition: SG_checker.py:14
f2c::Random
Definition: random.h:23
swath_generator.SG_checker.near
def near(a, b)
Definition: SG_checker.py:10


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31