1 /* 2 * data_mask.cc -- ePiX::data_mask class 3 * 4 * This file is part of ePiX, a C++ library for creating high-quality 5 * figures in LaTeX 6 * 7 * Version 1.1.8 8 * Last Change: July 22, 2007 9 */ 10 11 /* 12 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 13 * Andrew D. Hwang <rot 13 nujnat at zngupf dot ubylpebff dot rqh> 14 * Department of Mathematics and Computer Science 15 * College of the Holy Cross 16 * Worcester, MA, 01610-2395, USA 17 */ 18 19 /* 20 * ePiX is free software; you can redistribute it and/or modify it 21 * under the terms of the GNU General Public License as published by 22 * the Free Software Foundation; either version 2 of the License, or 23 * (at your option) any later version. 24 * 25 * ePiX is distributed in the hope that it will be useful, but WITHOUT 26 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 27 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 28 * License for more details. 29 * 30 * You should have received a copy of the GNU General Public License 31 * along with ePiX; if not, write to the Free Software Foundation, Inc., 32 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 33 */ 34 #include "functions.h" 35 #include "interval.h" 36 #include "data_mask.h" 37 38 namespace ePiX { 39 identity(double x)40 double identity(double x) { return x; } 41 data_mask(std::string arg)42 data_mask::data_mask(std::string arg) 43 : m_range(arg), m_filter(identity), m_reverse(false) { } 44 data_mask(std::string arg,double f (double))45 data_mask::data_mask(std::string arg, double f(double)) 46 : m_range(arg), m_filter(f), m_reverse(false) { } 47 48 data_mask(const interval & range)49 data_mask::data_mask(const interval& range) 50 : m_range(range), m_filter(identity), m_reverse(false) { } 51 data_mask(const interval & range,double f (double))52 data_mask::data_mask(const interval& range, double f(double)) 53 : m_range(range), m_filter(f), m_reverse(false) { } 54 data_mask(double arg1,double arg2)55 data_mask::data_mask(double arg1, double arg2) 56 : m_range(arg1, arg2), m_filter(identity), m_reverse(false) { } 57 data_mask(double arg1,double arg2,double f (double))58 data_mask::data_mask(double arg1, double arg2, double f(double)) 59 : m_range(arg1, arg2), m_filter(f), m_reverse(false) { } 60 reverse()61 data_mask& data_mask::reverse() 62 { 63 m_reverse = !m_reverse; 64 return *this; 65 } 66 masks(double x) const67 bool data_mask::masks(double x) const 68 { 69 bool masked(!m_range.contains(m_filter(x))); 70 71 if (m_reverse) 72 masked = !masked; 73 74 return masked; 75 } 76 } // end of namespace 77