<% side_names = ["xMin", "xMax", "yMin", "yMax", "zMin", "zMax"] def convert(value, type_1, type_2) if type_1 == "x" then if type_2 == "d" then return "xtod(#{value})" end if type_2 == "f" then return "xtof(#{value})" end if type_2 == "i" then return "#{value} >> 16" end end if type_2 == "x" then if type_1 == "d" then return "dtox(#{value})" end if type_1 == "f" then return "ftox(#{value})" end if type_1 == "i" then return "#{value} << 16" end end return value end -%> /* Copyright (c) 2015 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __RectBoxConversions_H__ #define __RectBoxConversions_H__ #ifdef __cplusplus extern "C" { #endif <% ["d", "f", "i", "x"].each do |type_suffix| -%> <% ["d", "f", "i", "x"].each do |type_suffix_2| -%> <% next if type_suffix == type_suffix_2 -%> #define Rect4<%= type_suffix %>_toRect4<%= type_suffix_2 %>(rect) RECT4<%= type_suffix_2 %>(<%= convert("rect.xMin", type_suffix, type_suffix_2) %><% 1.upto(3) do |side| %>, <%= convert("rect.#{side_names[side]}", type_suffix, type_suffix_2) %><% end %>) <% end %> <% end -%> <% ["d", "f", "i", "x"].each do |type_suffix| -%> <% ["d", "f", "i", "x"].each do |type_suffix_2| -%> <% next if type_suffix == type_suffix_2 -%> #define Box6<%= type_suffix %>_toBox6<%= type_suffix_2 %>(box) BOX6<%= type_suffix_2 %>(<%= convert("box.xMin", type_suffix, type_suffix_2) %><% 1.upto(5) do |side| %>, <%= convert("box.#{side_names[side]}", type_suffix, type_suffix_2) %><% end %>) <% end %> <% end -%> #ifdef __cplusplus } #endif #endif