Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix open_edges, now checks all. Refactor edge_intersect
- Loading branch information
Showing
5 changed files
with
71 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ __pycache__ | |
poly.png | ||
.cache | ||
.idea | ||
runtime | ||
/examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import cProfile | ||
import pstats | ||
import shapefile | ||
import matplotlib.pyplot as plt | ||
import matplotlib.patches as patches | ||
from matplotlib.patches import Polygon | ||
from matplotlib.collections import PatchCollection | ||
from graph import Graph, Point, Edge | ||
from visible_vertices import (edge_intersect, point_edge_distance, | ||
visible_vertices, angle) | ||
|
||
|
||
def test_country(): | ||
sf = shapefile.Reader("examples/GSHHS_c_L1.dbf") | ||
shapes = sf.shapes() | ||
|
||
poly1 = [Point(a[0], a[1]) for a in shapes[4].points] | ||
graph = Graph([poly1]) | ||
ship = Point(-80, -30) | ||
|
||
fig = plt.figure(1, figsize=(10, 10), dpi=90) | ||
ax = fig.add_subplot(111) | ||
|
||
x = [a.x for a in poly1] | ||
y = [a.y for a in poly1] | ||
ax.plot(x, y, color='gray', alpha=0.7, linewidth=1, | ||
solid_capstyle='round', zorder=2) | ||
|
||
for pp in graph.get_points(): | ||
visible = visible_vertices(pp, graph, ship, None) | ||
for point in visible: | ||
x = [pp.x, point.x] | ||
y = [pp.y, point.y] | ||
ax.plot(x, y, color='red', alpha=0.7, linewidth=1) | ||
|
||
ax.set_title("Python visibility graph") | ||
fig.savefig("poly.png", bbox_inches='tight') | ||
|
||
cProfile.run('test_country()', 'runtime') | ||
p = pstats.Stats('runtime') | ||
p.sort_stats('cumulative').print_stats(10) | ||
p.sort_stats('time').print_stats(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters