From 3b28c00affe8f33f4789be484a32ce9f98db0bda Mon Sep 17 00:00:00 2001 From: Mike Walters Date: Sun, 10 Jan 2016 23:23:56 +0000 Subject: [PATCH] Move clamp from spectrogram to util --- CMakeLists.txt | 1 + mainwindow.cpp | 1 + spectrogram.cpp | 6 +----- util.cpp | 28 ++++++++++++++++++++++++++++ util.h | 22 ++++++++++++++++++++++ 5 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 util.cpp create mode 100644 util.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 025e3f2..6fcf781 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ list(APPEND inspectrum_sources inputsource.cpp spectrogram.cpp spectrogramcontrols.cpp + util.cpp ) INCLUDE(FindPkgConfig) diff --git a/mainwindow.cpp b/mainwindow.cpp index 59ab03e..a970c4f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -21,6 +21,7 @@ #include #include "mainwindow.h" +#include "util.h" MainWindow::MainWindow() { diff --git a/spectrogram.cpp b/spectrogram.cpp index 0ef3f08..1b4a820 100644 --- a/spectrogram.cpp +++ b/spectrogram.cpp @@ -26,6 +26,7 @@ #include #include +#include "util.h" Spectrogram::Spectrogram() @@ -69,11 +70,6 @@ void Spectrogram::openFile(QString fileName) } } -template const T& clamp (const T& value, const T& min, const T& max) -{ - return std::min(max, std::max(min, value)); -} - void Spectrogram::paintEvent(QPaintEvent *event) { QRect rect = event->rect(); diff --git a/util.cpp b/util.cpp new file mode 100644 index 0000000..98eab81 --- /dev/null +++ b/util.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2016, Mike Walters + * + * This file is part of inspectrum. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "util.h" + +template const T& clamp (const T& value, const T& min, const T& max) +{ + return std::min(max, std::max(min, value)); +} +template const float& clamp(const float&, const float&, const float&); +template const int& clamp(const int&, const int&, const int&); diff --git a/util.h b/util.h new file mode 100644 index 0000000..eaf4d77 --- /dev/null +++ b/util.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2016, Mike Walters + * + * This file is part of inspectrum. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +template const T& clamp (const T& value, const T& min, const T& max);