Skip to content

Commit

Permalink
~ Improve the way to round lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
bbeaulant committed Oct 14, 2020
1 parent 0b1945c commit 268c99a
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 9 deletions.
Binary file modified dist/ladb_opencutlist-dev.rbz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/manifest-dev.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.9.6-dev",
"build": "202010121754",
"build": "202010140858",
"url": "https://raw.githubusercontent.com/lairdubois/lairdubois-opencutlist-sketchup-extension/master/dist/ladb_opencutlist-dev.rbz"
}
2 changes: 1 addition & 1 deletion src/ladb_opencutlist/ruby/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module Ladb::OpenCutList

EXTENSION_NAME = 'OpenCutList'.freeze
EXTENSION_VERSION = '1.9.6-dev'.freeze
EXTENSION_BUILD = '202010121754'.freeze
EXTENSION_BUILD = '202010140858'.freeze

end
2 changes: 1 addition & 1 deletion src/ladb_opencutlist/ruby/model/cutlist/groupdef.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def initialize(id)
# -----

def self.generate_group_id(material, material_attributes, std_info)
Digest::MD5.hexdigest("#{material.nil? ? 0 : material_attributes.uuid}#{material_attributes.type > MaterialAttributes::TYPE_UNKNOW ? '|' + DimensionUtils.instance.truncate_length_value(std_info[:width].to_l.to_f).to_s + 'x' + DimensionUtils.instance.truncate_length_value(std_info[:thickness].to_l.to_f).to_s : ''}")
Digest::MD5.hexdigest("#{material.nil? ? 0 : material_attributes.uuid}#{material_attributes.type > MaterialAttributes::TYPE_UNKNOW ? '|' + DimensionUtils.instance.round_length_value(std_info[:width].to_l.to_f).to_s + 'x' + DimensionUtils.instance.round_length_value(std_info[:thickness].to_l.to_f).to_s : ''}")
end

# -----
Expand Down
2 changes: 1 addition & 1 deletion src/ladb_opencutlist/ruby/model/cutlist/partdef.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def self.generate_part_id(group_id, definition, definition_attributes, instance_
end

# Include scale into part_id to separate instances with the same definition, but different scale
Digest::MD5.hexdigest("#{group_id}|#{entity_id}|#{DimensionUtils.instance.truncate_length_value(instance_info.size.length.to_f).to_s}|#{DimensionUtils.instance.truncate_length_value(instance_info.size.width.to_f).to_s}|#{DimensionUtils.instance.truncate_length_value(instance_info.size.thickness.to_f).to_s}|#{instance_info.flipped.to_s}")
Digest::MD5.hexdigest("#{group_id}|#{entity_id}|#{DimensionUtils.instance.round_length_value(instance_info.size.length.to_f).to_s}|#{DimensionUtils.instance.round_length_value(instance_info.size.width.to_f).to_s}|#{DimensionUtils.instance.round_length_value(instance_info.size.thickness.to_f).to_s}|#{instance_info.flipped.to_s}")

end

Expand Down
8 changes: 3 additions & 5 deletions src/ladb_opencutlist/ruby/utils/dimension_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,9 @@ def format_value(f, multiplier, precision, unit_sign)
# -----

# Take a float containing a length in inch
# and truncate it to "Sketchup" precision
def truncate_length_value(f)
return f if f == 0
factor = 10**4 # 4 = 0.0000 arbitrary length precision
(f * factor).floor / (factor * 1.0)
# and round it to "Sketchup" max precision
def round_length_value(f)
f.round(6)
end

end
Expand Down

0 comments on commit 268c99a

Please sign in to comment.