Fix: Allow non Float numeric values as JSON values in viewpoints

pull/7973/head
Wieland Lindenthal 5 years ago
parent acc17cae35
commit 08369e30ea
  1. 6
      modules/bcf/app/contracts/bcf/viewpoints/create_contract.rb
  2. 23
      modules/bcf/lib/open_project/bcf/bcf_json/viewpoint_reader.rb
  3. 82
      modules/bcf/spec/fixtures/viewpoints/full_viewpoint.bcfv.json
  4. 8
      modules/bcf/spec/fixtures/viewpoints/minimal.bcfv.json
  5. 2
      modules/bcf/spec/fixtures/viewpoints/neubau_sc_1.bcfv.json

@ -131,7 +131,7 @@ module Bcf::Viewpoints
if ocjson.keys != ORTHOGONAL_CAMERA_PROPERTIES ||
ocjson.except('view_to_world_scale').any? { |_, direction| invalid_direction?(direction) } ||
!ocjson['view_to_world_scale'].is_a?(Float)
!ocjson['view_to_world_scale'].is_a?(Numeric)
errors.add(:json_viewpoint, :invalid_orthogonal_camera)
end
end
@ -141,7 +141,7 @@ module Bcf::Viewpoints
if pcjson.keys != PERSPECTIVE_CAMERA_PROPERTIES ||
pcjson.except('field_of_view').any? { |_, direction| invalid_direction?(direction) } ||
!pcjson['field_of_view'].is_a?(Float)
!pcjson['field_of_view'].is_a?(Numeric)
errors.add(:json_viewpoint, :invalid_perspective_camera)
end
end
@ -246,7 +246,7 @@ module Bcf::Viewpoints
def invalid_direction?(direction)
!direction.is_a?(Hash) ||
direction.keys != WHITELISTED_DIMENSIONS ||
direction.values.any? { |v| !v.is_a? Float }
direction.values.any? { |v| !v.is_a? Numeric }
end
alias_method :invalid_point?, :invalid_direction?

@ -1,3 +1,5 @@
require 'bigdecimal'
module OpenProject::Bcf
module BcfJson
class ViewpointReader
@ -84,9 +86,9 @@ module OpenProject::Bcf
hash[key].transform_values! do |v|
if v.is_a?(Hash)
v.transform_values!(&:to_f)
v.transform_values! { |val| to_numeric(val) }
else
v.to_f
to_numeric(v)
end
end
end
@ -95,7 +97,7 @@ module OpenProject::Bcf
return unless hash.key?('lines')
hash['lines'] = hash['lines']['line'].map! do |line|
line.deep_transform_values!(&:to_f)
line.deep_transform_values! { |val| to_numeric(val) }
end
end
@ -103,7 +105,7 @@ module OpenProject::Bcf
return unless hash.key?('clipping_planes')
hash['clipping_planes'] = hash['clipping_planes']['clipping_plane'].map! do |plane|
plane.deep_transform_values!(&:to_f)
plane.deep_transform_values! { |val| to_numeric(val) }
end
end
@ -118,13 +120,13 @@ module OpenProject::Bcf
hash['bitmaps'] = bitmaps.map! do |bitmap|
bitmap['bitmap_type'] = bitmap.delete('bitmap').downcase
bitmap['bitmap_data'] = bitmap.delete('reference')
bitmap['height'] = bitmap['height'].to_f
bitmap['height'] = to_numeric(bitmap['height'])
%w[location normal up].each do |key|
next unless bitmap.key?(key)
# Transform all coordinates to floats
bitmap[key].transform_values!(&:to_f)
bitmap[key].transform_values! { |val| to_numeric(val) }
end
bitmap
@ -180,6 +182,15 @@ module OpenProject::Bcf
# Remove the old node
hash['components'].delete('view_setup_hints')
end
def to_numeric(anything)
num = BigDecimal.new(anything.to_s)
if num.frac == 0
num.to_i
else
num.to_f
end
end
end
end
end

@ -79,69 +79,69 @@
"y": 0.126656300502579,
"z": 0.990215996212637
},
"field_of_view": 60.0
"field_of_view": 60
},
"lines": [
{
"start_point": {
"x": 0.0,
"y": 0.0,
"z": 0.0
"x": 0,
"y": 0,
"z": 0
},
"end_point": {
"x": 0.0,
"y": 0.0,
"z": 1.0
"x": 0,
"y": 0,
"z": 1
}
},
{
"start_point": {
"x": 0.0,
"y": 0.0,
"z": 1.0
"x": 0,
"y": 0,
"z": 1
},
"end_point": {
"x": 0.0,
"y": 1.0,
"z": 1.0
"x": 0,
"y": 1,
"z": 1
}
},
{
"start_point": {
"x": 0.0,
"y": 1.0,
"z": 1.0
"x": 0,
"y": 1,
"z": 1
},
"end_point": {
"x": 1.0,
"y": 1.0,
"z": 1.0
"x": 1,
"y": 1,
"z": 1
}
}
],
"clipping_planes": [
{
"location": {
"x": 0.0,
"y": 0.0,
"z": 0.0
"x": 0,
"y": 0,
"z": 0
},
"direction": {
"x": 0.0,
"y": 0.0,
"z": 1.0
"x": 0,
"y": 0,
"z": 1
}
},
{
"location": {
"x": 0.0,
"y": 0.0,
"z": 0.0
"x": 0,
"y": 0,
"z": 0
},
"direction": {
"x": 0.0,
"y": 1.0,
"z": 0.0
"x": 0,
"y": 1,
"z": 0
}
}
],
@ -157,12 +157,12 @@
"normal": {
"x": -0.9999999999999999,
"y": 1.253656364893038E-16,
"z": 0.0
"z": 0
},
"up": {
"x": -5.43903050550883E-34,
"y": -4.338533794284917E-18,
"z": 1.0
"z": 1
},
"height": 1666.1814563907683
},
@ -170,21 +170,21 @@
"bitmap_type": "jpg",
"bitmap_data": "3f6ac03e-de8e-4c5e-b3f0-c7bf5f87fe51/bitmaps-e6f5a36a-c60b-4fcc-815f-a1dd939ebc87.jpg",
"location": {
"x": 1.0,
"y": 2.0,
"z": 3.0
"x": 1,
"y": 2,
"z": 3
},
"normal": {
"x": -3.0,
"x": -3,
"y": 1.253656364893038E-16,
"z": 0.0
"z": 0
},
"up": {
"x": 30.1234,
"y": -9000.0,
"z": 1.0
"y": -9000,
"z": 1
},
"height": 10.0
"height": 10
}
]
}

@ -7,15 +7,15 @@
"z": -1234.1234
},
"camera_direction": {
"x": -1.0,
"y": -2.0,
"z": -3.0
"x": -1,
"y": -2,
"z": -3
},
"camera_up_vector": {
"x": 0.223629,
"y": 0.209889,
"z": 0.951807
},
"field_of_view": 180.0
"field_of_view": 180
}
}

@ -548,6 +548,6 @@
"y": 0.209889,
"z": 0.951807
},
"field_of_view": 60.0
"field_of_view": 60
}
}
Loading…
Cancel
Save