Cell_test.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 math
9 import fields2cover as f2c
10 
11 def near(a, b, error = 1e-7):
12  assert abs(a - b) < error
13 
15  line = f2c.LinearRing(f2c.VectorPoint(
16  [f2c.Point(), f2c.Point(2,0), f2c.Point(2,2), f2c.Point(0,2), f2c.Point()]));
17  cell = f2c.Cell(line);
18  cell_clone = cell.clone();
19  near(cell.area(), 4)
20  near(cell_clone.area(), 4)
21 
23  ring1 = f2c.LinearRing(f2c.VectorPoint(
24  [f2c.Point(), f2c.Point(2,0), f2c.Point(2,2), f2c.Point(0,2), f2c.Point()]));
25  ring2 = f2c.LinearRing(f2c.VectorPoint(
26  [f2c.Point(0.5,0.5), f2c.Point(1.5,0.5), f2c.Point(1.5,1.5),
27  f2c.Point(0.5,1.5), f2c.Point(0.5,0.5)]));
28  near(ring1.size(), 5);
29  near(ring2.size(), 5);
30 
31  cell1 = f2c.Cell();
32  cell1.addRing(ring1)
33  near(cell1.area(), 4)
34  cell1.addRing(ring2)
35  near(cell1.area(), 3)
36  near(cell1.size(), 2);
37 
38  cell1_ring1 = cell1.getGeometry(0);
39  near(cell1_ring1.size(), 5);
40  near(cell1_ring1.length(), 8);
41  cell1_ring2 = cell1.getGeometry(1);
42  near(cell1_ring2.size(), 5);
43  near(cell1_ring2.length(), 4);
44 
45  cell_ring3 = f2c.LinearRing();
46  cell1.getGeometry(0, cell_ring3);
47  near(cell_ring3.size(), 5);
48  near(cell_ring3.length(), 8);
49  cell_ring4 = f2c.LinearRing();
50  cell1.getGeometry(1, cell_ring4);
51  near(cell_ring4.size(), 5);
52  near(cell_ring4.length(), 4);
53 
54 
56  cell = f2c.Cell();
57  ring1 = f2c.LinearRing(f2c.VectorPoint(
58  [f2c.Point(), f2c.Point(2,0), f2c.Point(2,2), f2c.Point(0,2), f2c.Point()]));
59  cell.addRing(ring1);
60  line = cell.createLineUntilBorder(f2c.Point(1, 1), 0);
61  near(line.size(), 2);
62  if line.size() == 2:
63  near(line.getX(0), 1)
64  near(line.getY(0), 1)
65  near(line.getX(1), 2)
66  near(line.getY(1), 1)
67 
69  cell = f2c.Cell();
70  ring1 = f2c.LinearRing(f2c.VectorPoint(
71  [f2c.Point(), f2c.Point(2,0), f2c.Point(2,2), f2c.Point(0,2), f2c.Point()]));
72  cell.addRing(ring1);
73 
74  assert cell.isPointInBorder(f2c.Point(2,2))
75  assert cell.isPointInBorder(f2c.Point(1,2))
76  assert not cell.isPointInBorder(f2c.Point(1,1))
77  assert not cell.isPointInBorder(f2c.Point(10,10))
78 
80  cell = f2c.Cell(f2c.LinearRing(f2c.VectorPoint(
81  [f2c.Point(), f2c.Point(1,0), f2c.Point(1,1), f2c.Point(0,1), f2c.Point()])))
82  near(cell.area(), 1)
83 
84  cell_buffer = f2c.Cell.buffer(cell, 2.0);
85  near(cell.area(), 1)
86  near(cell_buffer.area(), 25, 0.1)
87 
88  p = f2c.Point(1, 2);
89  point_buffer = f2c.Cell.buffer(p, 3.0)
90  near(point_buffer.area(), 3 * 3 * math.pi, 0.2)
91  near(p.getX(), 1)
92  near(p.getY(), 2)
93 
94  line = f2c.LineString(f2c.VectorPoint([f2c.Point(3,4), f2c.Point(3,6)]))
95  line_buffer = f2c.Cell.buffer(line, 4.0)
96  near(line_buffer.area(), 2 * (4 * 2), 1e-5);
97 
98 
Cell_test.near
def near(a, b, error=1e-7)
Definition: Cell_test.py:11
Cell_test.test_fields2cover_types_cell_constructor
def test_fields2cover_types_cell_constructor()
Definition: Cell_test.py:14
Cell_test.test_fields2cover_types_cell_createLineUntilBorder
def test_fields2cover_types_cell_createLineUntilBorder()
Definition: Cell_test.py:55
Cell_test.test_fields2cover_types_cell_isPointInBorder
def test_fields2cover_types_cell_isPointInBorder()
Definition: Cell_test.py:68
Cell_test.test_fields2cover_types_cell_addRing
def test_fields2cover_types_cell_addRing()
Definition: Cell_test.py:22
Cell_test.test_fields2cover_types_cell_buffer
def test_fields2cover_types_cell_buffer()
Definition: Cell_test.py:79


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