+ ##
+ # the integer coords (i.e: unscaled) bounding box of the way, assuming
+ # straight line segments.
+ def bbox
+ lons = nodes.collect { |n| n.longitude }
+ lats = nodes.collect { |n| n.latitude }
+ [ lons.min, lats.min, lons.max, lats.max ]
+ end
+
+ def update_from(new_way, user)
+ check_consistency(self, new_way, user)
+ unless new_way.preconditions_ok?
+ raise OSM::APIPreconditionFailedError.new("Cannot update way #{self.id}: data is invalid.")
+ end
+
+ self.changeset_id = new_way.changeset_id
+ self.changeset = new_way.changeset
+ self.tags = new_way.tags
+ self.nds = new_way.nds
+ self.visible = true
+ save_with_history!
+ end
+
+ def create_with_history(user)
+ check_create_consistency(self, user)
+ unless self.preconditions_ok?
+ raise OSM::APIPreconditionFailedError.new("Cannot create way: data is invalid.")
+ end
+ self.version = 0
+ self.visible = true
+ save_with_history!
+ end
+
+ def preconditions_ok?
+ return false if self.nds.empty?
+ if self.nds.length > APP_CONFIG['max_number_of_way_nodes']
+ raise OSM::APITooManyWayNodesError.new(self.nds.length, APP_CONFIG['max_number_of_way_nodes'])
+ end
+ self.nds.each do |n|
+ node = Node.find(:first, :conditions => ["id = ?", n])
+ unless node and node.visible
+ raise OSM::APIPreconditionFailedError.new("The node with id #{n} either does not exist, or is not visible")
+ end
+ end
+ return true
+ end
+
+ def delete_with_history!(new_way, user)
+ unless self.visible
+ raise OSM::APIAlreadyDeletedError.new("way", new_way.id)
+ end