diff --git a/.gitignore b/.gitignore index 0a61ee3..782edb0 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,267 @@ csgtool.dbg *.exe *.out *.app + +### Import of +### https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc diff --git a/csgtool.sln b/csgtool.sln new file mode 100644 index 0000000..70f016b --- /dev/null +++ b/csgtool.sln @@ -0,0 +1,38 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcsg", "libcsg.vcxproj", "{9B4E69A7-C992-4566-9DCD-0DDA1356DF89}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "csgtool", "csgtool.vcxproj", "{38CD99E1-3B79-4DC3-B9BB-8A30D5E68B9F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9B4E69A7-C992-4566-9DCD-0DDA1356DF89}.Debug|x64.ActiveCfg = Debug|x64 + {9B4E69A7-C992-4566-9DCD-0DDA1356DF89}.Debug|x64.Build.0 = Debug|x64 + {9B4E69A7-C992-4566-9DCD-0DDA1356DF89}.Debug|x86.ActiveCfg = Debug|Win32 + {9B4E69A7-C992-4566-9DCD-0DDA1356DF89}.Debug|x86.Build.0 = Debug|Win32 + {9B4E69A7-C992-4566-9DCD-0DDA1356DF89}.Release|x64.ActiveCfg = Release|x64 + {9B4E69A7-C992-4566-9DCD-0DDA1356DF89}.Release|x64.Build.0 = Release|x64 + {9B4E69A7-C992-4566-9DCD-0DDA1356DF89}.Release|x86.ActiveCfg = Release|Win32 + {9B4E69A7-C992-4566-9DCD-0DDA1356DF89}.Release|x86.Build.0 = Release|Win32 + {38CD99E1-3B79-4DC3-B9BB-8A30D5E68B9F}.Debug|x64.ActiveCfg = Debug|x64 + {38CD99E1-3B79-4DC3-B9BB-8A30D5E68B9F}.Debug|x64.Build.0 = Debug|x64 + {38CD99E1-3B79-4DC3-B9BB-8A30D5E68B9F}.Debug|x86.ActiveCfg = Debug|Win32 + {38CD99E1-3B79-4DC3-B9BB-8A30D5E68B9F}.Debug|x86.Build.0 = Debug|Win32 + {38CD99E1-3B79-4DC3-B9BB-8A30D5E68B9F}.Release|x64.ActiveCfg = Release|x64 + {38CD99E1-3B79-4DC3-B9BB-8A30D5E68B9F}.Release|x64.Build.0 = Release|x64 + {38CD99E1-3B79-4DC3-B9BB-8A30D5E68B9F}.Release|x86.ActiveCfg = Release|Win32 + {38CD99E1-3B79-4DC3-B9BB-8A30D5E68B9F}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/csgtool.vcxproj b/csgtool.vcxproj new file mode 100644 index 0000000..f974d93 --- /dev/null +++ b/csgtool.vcxproj @@ -0,0 +1,163 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {38CD99E1-3B79-4DC3-B9BB-8A30D5E68B9F} + Win32Proj + exe + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(Configuration)\$(ProjectName)\ + + + true + + + false + $(Configuration)\$(ProjectName)\ + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(ProjectDir)src + + + Console + true + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(ProjectDir)src + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + {9b4e69a7-c992-4566-9dcd-0dda1356df89} + + + + + + \ No newline at end of file diff --git a/csgtool.vcxproj.filters b/csgtool.vcxproj.filters new file mode 100644 index 0000000..896a9db --- /dev/null +++ b/csgtool.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/libcsg.vcxproj b/libcsg.vcxproj new file mode 100644 index 0000000..9b85751 --- /dev/null +++ b/libcsg.vcxproj @@ -0,0 +1,112 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {9B4E69A7-C992-4566-9DCD-0DDA1356DF89} + Win32Proj + libcsg + 8.1 + + + + StaticLibrary + true + v140 + + + StaticLibrary + false + v140 + + + Application + true + v140 + + + Application + false + v140 + + + + + + + + + + + + + + + + + + + + + true + $(Configuration)\$(ProjectName)\ + + + true + $(Configuration)\$(ProjectName)\ + + + + WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + Level3 + ProgramDatabase + Disabled + + + MachineX86 + true + Windows + + + + + WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;NDEBUG;%(PreprocessorDefinitions) + MultiThreadedDLL + Level3 + ProgramDatabase + + + MachineX86 + true + Windows + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/libcsg.vcxproj.filters b/libcsg.vcxproj.filters new file mode 100644 index 0000000..97d3f99 --- /dev/null +++ b/libcsg.vcxproj.filters @@ -0,0 +1,25 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + Header Files + + + diff --git a/src/export.c b/src/export.c index f705153..cdde916 100644 --- a/src/export.c +++ b/src/export.c @@ -45,7 +45,7 @@ bsp_node_t *stl_to_bsp(stl_object *stl) { klist_t(poly) *polys = kl_init(poly); poly_t *poly = NULL; - for(int i = 0; i < stl->facet_count; i++) { + for(unsigned int i = 0; i < stl->facet_count; i++) { poly = poly_make_triangle(stl->facets[i].vertices[0], stl->facets[i].vertices[1], stl->facets[i].vertices[2]); diff --git a/src/poly.c b/src/poly.c index 1702a58..7ea483d 100644 --- a/src/poly.c +++ b/src/poly.c @@ -102,11 +102,11 @@ float poly_triangle_2area(poly_t *triangle) { // The actual area of a triangle `triangle` // Works through poly_triangle_2area float poly_triangle_area(poly_t *triangle) { - return 0.5 * poly_triangle_2area(triangle); + return 0.5f * poly_triangle_2area(triangle); } float poly_area(poly_t *poly) { - return poly_2area(poly) / 2.0; + return poly_2area(poly) / 2.0f; } float poly_2area(poly_t *poly) { diff --git a/src/poly.h b/src/poly.h index 9524b77..603d1d7 100644 --- a/src/poly.h +++ b/src/poly.h @@ -1,5 +1,8 @@ -#include +#ifndef _WIN32 #include +#endif + +#include #include "dbg.h" #include "klist.h" #include "vector.h" diff --git a/src/stl.c b/src/stl.c index 9640122..480df22 100644 --- a/src/stl.c +++ b/src/stl.c @@ -6,8 +6,26 @@ #include #include #include + +// Platform specific IO +#ifndef _WIN32 #include +// Thanks, windows. Love this. +#define O_BINARY 0 +#else +#include + +// And also rename the basics +#define read _read +#define write _write +#define open _open +#define close _close + +// Not technically part of `io.h` +#define fdopen _fdopen +#endif + #include "dbg.h" #include "stl.h" @@ -221,7 +239,7 @@ stl_object *stl_read_file(char *path, int recompute_normals) { int fd = -1; check((reader = stl_detect_reader(path)), "Unable to find reader for format of %s", path); - check((fd = open(path, O_RDONLY)) != -1, "Unable to open '%s'", path); + check((fd = open(path, O_RDONLY | O_BINARY)) != -1, "Unable to open '%s'", path); obj = reader(fd); check(obj != NULL, "Failed to read STL from %s", path); @@ -232,7 +250,7 @@ stl_object *stl_read_file(char *path, int recompute_normals) { close(fd); if(recompute_normals) { - for(int i = 0; i < obj->facet_count; i++) { + for(unsigned int i = 0; i < obj->facet_count; i++) { stl_facet_update_normal(&obj->facets[i]); } } @@ -246,7 +264,7 @@ stl_object *stl_read_file(char *path, int recompute_normals) { int stl_write_file(stl_object *obj, char *path) { int rc = -1; - int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0755); + int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0755); check(fd != -1, "Failed to open '%s' for write", path); rc = stl_write_object(obj, fd); diff --git a/src/stl.h b/src/stl.h index 0f12905..750b427 100644 --- a/src/stl.h +++ b/src/stl.h @@ -1,4 +1,7 @@ +#ifndef _WIN32 #include +#endif + #include #include diff --git a/src/util.c b/src/util.c index 26c06a0..8b03742 100644 --- a/src/util.c +++ b/src/util.c @@ -110,7 +110,7 @@ char *read_line(FILE *f, bool downcase, bool trim) { } if(downcase == true) { - for(int i = 0; i < strlen(line); i++) { + for(size_t i = 0; i < strlen(line); i++) { line[i] = tolower(line[i]); } } diff --git a/src/vector.c b/src/vector.c index 0a72d5d..e73ad64 100644 --- a/src/vector.c +++ b/src/vector.c @@ -11,7 +11,7 @@ float3 *clone_f3(float3 f) { } float f3_magnitude(float3 *v) { - return sqrt((*v)[0] * (*v)[0] + + return sqrtf((*v)[0] * (*v)[0] + (*v)[1] * (*v)[1] + (*v)[2] * (*v)[2]); } @@ -60,7 +60,7 @@ float3 *f3_interpolate(float3 *result, float3 start, float3 v, float alpha) { } float f3_distance(float3 a, float3 b) { - return sqrt(f3_distance2(a, b)); + return sqrtf(f3_distance2(a, b)); } float f3_distance2(float3 a, float3 b) {