Permalink
Browse files

specs for orientation.. but how about #clockwise? looks better

  • Loading branch information...
1 parent 9f18f8d commit e1370c070847b40356181adb37fa77fd147adaaf @nofxx committed Apr 8, 2011
@@ -191,7 +191,7 @@ def get_record(i)
GeoRuby::SimpleFeatures::LinearRing.from_points(points[(parts[i])...(parts[i+1])])
end
# geometry = GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([GeoRuby::SimpleFeatures::Polygon.from_linear_rings(linear_rings)])
- outer, inner = linear_rings.partition { |lr| lr.orientation == :clockwise}
+ outer, inner = linear_rings.partition { |lr| lr.clockwise? }
# Make polygons from the outer rings so we can concatenate
# them with inner rings.
@@ -24,14 +24,14 @@ def is_closed
end
alias :closed? :is_closed
- def orientation
+ def clockwise?
tuples = @points.zip(
@points[1..-1] + [@points[0]],
@points[2..-1] + [@points[0], @points[1]])
tuples.map!{ |a,b,c| b.x * (c.y - a.y) }
sum = tuples.inject(0.0){ |sum, elem| sum+elem }
- sum < 0.0 ? :clockwise : :anticlockwise
+ sum < 0.0
end
#Bounding box in 2D/3D. Returns an array of 2 points
@@ -12,26 +12,44 @@ def mock_point(x=1,y=2)
end
describe LineString do
+
include LineSpecHelper
- before(:each) do
- @line = LineString.from_points([mock(Point)])
- end
+ describe "Instance Methods" do
- it "should instantiate" do
- violated unless @line
- end
+ let(:line) { LineString.from_points([mock(Point)]) }
- it "should have binary_geometry_type 2" do
- @line.binary_geometry_type.should eql(2)
- end
+ it "should instantiate" do
+ violated unless line
+ end
+
+ it "should have binary_geometry_type 2" do
+ line.binary_geometry_type.should eql(2)
+ end
+
+ it "should have text_geometry_type" do
+ line.text_geometry_type.should eql("LINESTRING")
+ end
+
+ it "should have a points array" do
+ line.points.should be_instance_of(Array)
+ end
- it "should have text_geometry_type" do
- @line.text_geometry_type.should eql("LINESTRING")
end
- it "should have a points array" do
- @line.points.should be_instance_of(Array)
+ describe "Valid LineString" do
+
+ let(:line) { LineString.from_points([Point.xy(1,1), Point.xy(2,2), Point.xy(3,3)]) }
+
+ it "should check orientation" do
+ line.should_not be_clockwise
+ end
+
+ it "should check orientation" do
+ l = LineString.from_points([Point.from_x_y(20,20), Point.from_x_y(10,10), Point.from_x_y(-10,10)])
+ l.should be_clockwise
+ end
+
end
describe "tu converted" do
@@ -148,40 +166,38 @@ def mock_point(x=1,y=2)
describe "> Instantiated" do
- before(:each) do
- @line = LineString.from_points(mock_points(7))
- end
+ let (:line) { LineString.from_points(mock_points(7)) }
it "should be closed if the last point equals the first" do
- @line.push(@line.first)
- @line.should be_closed
- @line.length.should eql(8)
+ line.push(line.first)
+ line.should be_closed
+ line.length.should eql(8)
end
it "should print the text representation" do
- @line.text_representation.should eql("0 0,1 1,2 2,3 3,4 4,5 5,6 6")
+ line.text_representation.should eql("0 0,1 1,2 2,3 3,4 4,5 5,6 6")
end
it "should print the georss_simple_representation" do
- @line.georss_simple_representation({:geom_attr => nil}).
+ line.georss_simple_representation({:geom_attr => nil}).
should eql("<georss:line>0 0 1 1 2 2 3 3 4 4 5 5 6 6</georss:line>\n")
end
it "should map the georss_poslist" do
- @line.georss_poslist.should eql("0 0 1 1 2 2 3 3 4 4 5 5 6 6")
+ line.georss_poslist.should eql("0 0 1 1 2 2 3 3 4 4 5 5 6 6")
end
it "should print the kml_representation" do
- @line.kml_representation.should
+ line.kml_representation.should
eql("<LineString>\n<coordinates>0,0 1,1 2,2 3,3 4,4 5,5 6,6</coordinates>\n</LineString>\n")
end
it "should print the kml_poslist without reverse or z" do
- @line.kml_poslist({}).should eql("0,0 1,1 2,2 3,3 4,4 5,5 6,6")
+ line.kml_poslist({}).should eql("0,0 1,1 2,2 3,3 4,4 5,5 6,6")
end
it "should print the kml_poslist reverse" do
- @line.kml_poslist({:reverse => true}).should eql("6,6 5,5 4,4 3,3 2,2 1,1 0,0")
+ line.kml_poslist({:reverse => true}).should eql("6,6 5,5 4,4 3,3 2,2 1,1 0,0")
end
end
@@ -208,37 +224,35 @@ def mock_point(x=1,y=2)
describe "Simplify" do
- before do
- @line = LineString.from_coordinates([[6,0],[4,1],[3,4],[4,6],[5,8],[5,9],[4,10],[6,15]], 4326)
- end
+ let(:line) { LineString.from_coordinates([[6,0],[4,1],[3,4],[4,6],[5,8],[5,9],[4,10],[6,15]], 4326) }
it "should simplify a simple linestring" do
line = LineString.from_coordinates([[12,15],[14,17],[17, 20]], 4326)
line.simplify.should have(2).points
end
it "should simplify a harder linestring" do
- @line.simplify(6).should have(6).points
- @line.simplify(9).should have(4).points
- @line.simplify(10).should have(3).points
+ line.simplify(6).should have(6).points
+ line.simplify(9).should have(4).points
+ line.simplify(10).should have(3).points
end
it "should barely touch it" do
- @line.simplify(1).should have(7).points
+ line.simplify(1).should have(7).points
end
it "should simplify to five points" do
- @line.simplify(7).should have(5).points
+ line.simplify(7).should have(5).points
end
it "should flatten it" do
- @line.simplify(11).should have(2).points
+ line.simplify(11).should have(2).points
end
it "should be the first and last in a flatten" do
- line = @line.simplify(11)
- line[0].should be_a_point(6, 0)
- line[1].should be_a_point(6, 15)
+ l = line.simplify(11)
+ l[0].should be_a_point(6, 0)
+ l[1].should be_a_point(6, 15)
end
end

0 comments on commit e1370c0

Please sign in to comment.