Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
pazmivaniye committed Jun 14, 2024
0 parents commit ad62b54
Show file tree
Hide file tree
Showing 10 changed files with 2,253 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: build
on: [push, pull_request]
jobs:
#windows:
# runs-on: windows-latest
# defaults:
# run:
# shell: msys2 {0}
# steps:
# - uses: actions/checkout@v4
# - uses: msys2/setup-msys2@v2
# with:
# msystem: MINGW64
# update: true
# install: make mingw-w64-x86_64-gcc mingw-w64-x86_64-perl-win32-tieregistry
# - name: Build and Test
# run: |
# : # Fix Perl locale issue
# export LC_ALL=en_US.utf8
# : # Fix Perl search path/Win32::TieRegistry version issue
# dir=D:/a/_temp/msys64/mingw64/lib/perl5/site_perl
# mkdir -p $dir/5.38.2/Win32
# ln $dir/5.32.1/Win32/TieRegistry.pm $dir/5.38.2/Win32/TieRegistry.pm
# : # Downgrade zlib version to match LuaLaTex
# pkg=mingw-w64-x86_64-zlib
# ver=1.3-1
# file=$pkg-$ver-any.pkg.tar.zst
# curl -LO https://repo.msys2.org/mingw/mingw64/$file
# pacman -U --noconfirm $file
# : # Install TeX Live packages
# pacman -S --noconfirm mingw-w64-x86_64-texlive-luatex mingw-w64-x86_64-texlive-latex-extra mingw-w64-x86_64-texlive-fonts-extra
# : # Build and Test
# make -j
#macos:
# runs-on: macos-latest
# steps:
# - uses: actions/checkout@v4
# - uses: melusina-org/setup-macports@v1
# - name: Build and Test
# run: |
# sudo port install texlive-luatex texlive-latex-extra texlive-fonts-extra
# make -j
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build and Test
run: |
sudo apt install texlive-luatex texlive-latex-extra texlive-fonts-extra texlive-xetex texlive-science ghostscript poppler-utils
make -j
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.o
*.a
test/test
test/build
test/output
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright 2019-2024 Benjamin L. Reifler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
87 changes: 87 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
PROJNAME := pgfplotter
CXXVER := 17
MINMACOSVER := 10.15

LIBNAME := $(shell echo $(PROJNAME) | sed 's/_//g' | tr '[:upper:]' '[:lower:]')
ifeq ($(OS), Windows_NT)
LIBPATH := /mingw64/lib
INCLPATH := /mingw64/include
OSPRETTY := Windows
else
ifeq ($(shell uname -s), Darwin)
OSPRETTY := macOS
else
OSPRETTY := Linux
endif
LIBPATH := /usr/local/lib
INCLPATH := /usr/local/include
endif
OPTIM := 3
CFLAGS := -O$(OPTIM) -Wall -Wextra -Wno-missing-braces
ifeq ($(OSPRETTY), macOS)
CFLAGS += -mmacosx-version-min=$(MINMACOSVER) -Wunguarded-availability
else
ifeq ($(OSPRETTY), Windows)
CFLAGS += -Wno-cast-function-type
endif
endif
CXXFLAGS := -std=c++$(CXXVER) $(CFLAGS) -Wold-style-cast
ifeq ($(OSPRETTY), macOS)
CXXFLAGS += -Wno-string-plus-int
else
ifeq ($(OSPRETTY), Windows)
CXXFLAGS += -Wno-deprecated-copy
endif
endif
ARFLAGS := -rcs

SRC := $(wildcard *.cpp)
ifeq ($(OSPRETTY), macOS)
ARMOBJ := $(SRC:.cpp=_arm64.o)
INTOBJ := $(SRC:.cpp=_x86_64.o)
else
OBJ := $(SRC:.cpp=.o)
endif

print-% : ; @echo $* = $($*)

.PHONY: test
default: test

ifeq ($(OSPRETTY), macOS)
lib$(LIBNAME).a: lib$(LIBNAME)_arm64.a lib$(LIBNAME)_x86_64.a
lipo -create -output $@ $^

lib$(LIBNAME)_arm64.a: $(ARMOBJ)
$(RM) $@
ar $(ARFLAGS) $@ $^

lib$(LIBNAME)_x86_64.a: $(INTOBJ)
$(RM) $@
ar $(ARFLAGS) $@ $^
else
lib$(LIBNAME).a: $(OBJ)
$(RM) $@
ar $(ARFLAGS) $@ $^
endif

install: $(PROJNAME) lib$(LIBNAME).a
cmp -s $(PROJNAME) $(INCLPATH)/$(PROJNAME) || cp $(PROJNAME) $(INCLPATH)/
cmp -s lib$(LIBNAME).a $(LIBPATH)/lib$(LIBNAME).a || cp lib$(LIBNAME).a $(LIBPATH)/

test: lib$(LIBNAME).a
$(MAKE) -C test
test/test

%_arm64.o: %.cpp
$(CXX) -arch arm64 -c -o $@ $< $(CXXFLAGS)

%_x86_64.o: %.cpp
$(CXX) -arch x86_64 -c -o $@ $< $(CXXFLAGS)

%.o: %.cpp
$(CXX) -c -o $@ $< $(CXXFLAGS)

clean:
$(RM) *.o *.a
$(MAKE) -C test clean
23 changes: 23 additions & 0 deletions detect_os.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef PGFPLOTTER_DETECT_OS_HPP
#define PGFPLOTTER_DETECT_OS_HPP

#if defined(__APPLE__) && defined(__MACH__)
#if !defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE
#define OS_MACOS
#else
static_assert(false, "Failed to detect an acceptable OS (iOS is not supported)."
"\n");
#endif
#elif defined(_WIN32) || defined(_WIN64)
#define OS_WINDOWS
#elif defined(__linux__)
#define OS_LINUX
#else
static_assert(false, "Failed to detect an acceptable OS (no valid macros define"
"d).\n");
#endif
#if defined(OS_MACOS) || defined(OS_LINUX)
#define OS_UNIX
#endif

#endif
46 changes: 46 additions & 0 deletions mesh_grid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "pgfplotter"

std::array<std::vector<double>, 3> pgfplotter::mesh_grid(const std::function<
double(double, double)>& f, double xMin, double xMax, double yMin, double
yMax, std::size_t res)
{
return mesh_grid(f, xMin, xMax, yMin, yMax, res, res);
}

std::array<std::vector<double>, 3> pgfplotter::mesh_grid(const std::function<
double(double, double)>& f, double xMin, double xMax, double yMin, double
yMax, std::size_t xRes, std::size_t yRes)
{
if(!yRes)
{
yRes = xRes;
}

std::array<std::vector<double>, 3> grid;
for(auto& n : grid)
{
n.resize(xRes*yRes);
}

std::vector<double> x(xRes);
std::vector<double> y(yRes);
for(std::size_t i = 0; i < xRes; ++i)
{
x[i] = xMin + i*(xMax - xMin)/(xRes - 1);
}
for(std::size_t i = 0; i < yRes; ++i)
{
y[i] = yMin + i*(yMax - yMin)/(yRes - 1);
}
for(std::size_t i = 0; i < xRes; ++i)
{
for(std::size_t j = 0; j < yRes; ++j)
{
grid[0][yRes*i + j] = x[i];
grid[1][yRes*i + j] = y[j];
grid[2][yRes*i + j] = f(x[i], y[j]);
}
}

return grid;
}
Loading

0 comments on commit ad62b54

Please sign in to comment.