Skip to content

Instantly share code, notes, and snippets.

@tkfm-yamaguchi
Last active November 21, 2018 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkfm-yamaguchi/d7ddb0616ecfca62a399728288e8e5c5 to your computer and use it in GitHub Desktop.
Save tkfm-yamaguchi/d7ddb0616ecfca62a399728288e8e5c5 to your computer and use it in GitHub Desktop.
a ruby method to detect x-y coords uniquness of points in VTK file
# Detects whether the x/y coordinates of points in VTK are all different.
#
# @params {string} vtk path to VTK file
# @return {boolean}
def all_coords_uniq?(vtk)
File.open(vtk, "r") do |f|
points_count = 0
while line = f.gets.chomp
if line =~ /^POINTS/
points_count = line.split[1].to_i
break
end
end
points = points_count.times.map do
f.gets.split[0..1]
end
return points.size == points.uniq.size
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment