Cells_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  ring1 = f2c.LinearRing(f2c.VectorPoint(
16  [f2c.Point(0,0), f2c.Point(1,0), f2c.Point(1,1), f2c.Point(0,1), f2c.Point(0,0)]));
17  ring2 = f2c.LinearRing(f2c.VectorPoint(
18  [f2c.Point(.1,.1), f2c.Point(.9,.1), f2c.Point(.9,.9),
19  f2c.Point(.1,.9), f2c.Point(.1,.1)]));
20  cell = f2c.Cell(ring1);
21  cell.addRing(ring2);
22  cells = f2c.Cells();
23  near(cells.size(), 0);
24  cells.addGeometry(cell);
25 
26  cells_clone = cells.clone();
27 
28  near(cells.area(), 0.36);
29  near(cells_clone.area(), 0.36);
30  near(cells_clone.getGeometry(0).area(), 0.36);
31 
32 
33  cell2 = f2c.Cell(ring2);
34  near(cell2.area(), 0.64);
35  cells.addGeometry(cell2);
36 
37  cells_ring = cells.getInteriorRing(0, 0)
38  near(cells_ring.length(), 3.2);
39 
40 
42  ring1 = f2c.LinearRing(f2c.VectorPoint(
43  [f2c.Point(0,0), f2c.Point(2,0), f2c.Point(2,2), f2c.Point(0,2), f2c.Point(0,0)]));
44  ring2 = f2c.LinearRing(f2c.VectorPoint(
45  [f2c.Point(1,0), f2c.Point(3,0), f2c.Point(3,2), f2c.Point(1,2), f2c.Point(1,0)]));
46  cell1 = f2c.Cell();
47  cell2 = f2c.Cell();
48  cell1.addRing(ring1);
49  cell2.addRing(ring2);
50  near(ring1.size(), 5);
51  near(ring2.size(), 5);
52  near(cell1.area(), 4);
53  near(cell2.area(), 4);
54  near(f2c.Cells(cell1).area(), 4);
55  near(f2c.Cells(cell2).area(), 4);
56  near(f2c.Cells(cell1).difference(f2c.Cells(cell2)).area(), 2);
57 
58 
60  cell1 = f2c.Cell(f2c.LinearRing(f2c.VectorPoint(
61  [f2c.Point(0,0), f2c.Point(2,0), f2c.Point(2,2), f2c.Point(0,2), f2c.Point(0,0)])));
62  cell2 = f2c.Cell(f2c.LinearRing(f2c.VectorPoint(
63  [f2c.Point(1,0), f2c.Point(3,0), f2c.Point(3,2), f2c.Point(1,2), f2c.Point(1,0)])));
64  cells2 = f2c.Cells(cell2);
65  near(f2c.Cells.intersection(cell1, cell2).area(), 2);
66 
68  cells = f2c.Cells(f2c.Cell(f2c.LinearRing(f2c.VectorPoint(
69  [f2c.Point(0,0), f2c.Point(2,0), f2c.Point(2,2), f2c.Point(0,2), f2c.Point(0,0)]))));
70  line1 = cells.createSemiLongLine(f2c.Point(), math.pi * 3.0/4.0)
71  line2 = cells.createStraightLongLine(f2c.Point(), math.pi * 3.0/4.0)
72 
73  near(line1.getX(0), 0, 1e-3);
74  near(line1.getY(0), 0, 1e-3);
75  near(line1.getX(1), -2*math.sqrt(2), 1e-3);
76  near(line1.getY(1), 2*math.sqrt(2), 1e-3);
77  near(line2.getX(0), 2*math.sqrt(2), 1e-3);
78  near(line2.getY(0), -2*math.sqrt(2), 1e-3);
79  near(line2.getX(1), -2*math.sqrt(2), 1e-3);
80  near(line2.getY(1), 2*math.sqrt(2), 1e-3);
81 
83  cells = f2c.Cells(f2c.Cell(f2c.LinearRing(f2c.VectorPoint(
84  [f2c.Point(0,0), f2c.Point(2,0), f2c.Point(2,2), f2c.Point(0,2), f2c.Point(0,0)]))));
85  cells.addGeometry(f2c.Cell(f2c.LinearRing(f2c.VectorPoint(
86  [f2c.Point(10,9), f2c.Point(12,9),f2c.Point(12,12),f2c.Point(10,12), f2c.Point(10,9)]))));
87  assert (cells.isPointInBorder(f2c.Point(0, 0)));
88  assert (cells.isPointInBorder(f2c.Point(1, 0)));
89  assert (cells.isPointInBorder(f2c.Point(11, 12)));
90  assert not (cells.isPointInBorder(f2c.Point(1, 1)));
91  assert not (cells.isPointInBorder(f2c.Point(5, 5)));
92  near(cells.getCellWherePoint(f2c.Point(5, 5)).area(), 0);
93  near(cells.getCellWherePoint(f2c.Point(1, 1)).area(), 4);
94  near(cells.getCellWherePoint(f2c.Point(0, 0)).area(), 4);
95  near(cells.getCellWherePoint(f2c.Point(11, 11)).area(), 6);
96 
Cells_test.test_fields2cover_types_cells_Difference
def test_fields2cover_types_cells_Difference()
Definition: Cells_test.py:41
Cells_test.test_fields2cover_types_cells_longLines
def test_fields2cover_types_cells_longLines()
Definition: Cells_test.py:67
Cells_test.test_fields2cover_types_cells_wherePoint
def test_fields2cover_types_cells_wherePoint()
Definition: Cells_test.py:82
Cells_test.near
def near(a, b, error=1e-7)
Definition: Cells_test.py:11
Cells_test.test_fields2cover_types_cells_Intersection
def test_fields2cover_types_cells_Intersection()
Definition: Cells_test.py:59
Cells_test.test_fields2cover_types_cells_constructor
def test_fields2cover_types_cells_constructor()
Definition: Cells_test.py:14


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