1 /* 2 * mask_diamond.cc -- ePiX diamond crop mask 3 * 4 * This file is part of ePiX, a C++ library for creating high-quality 5 * figures in LaTeX 6 * 7 * Version 1.1.10 8 * Last Change: August 09, 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 <cmath> 35 36 #include "functions.h" 37 //#include "errors.h" 38 39 #include "constants.h" 40 41 #include "pairs.h" 42 43 #include "Color.h" 44 45 #include "paint_style.h" 46 #include "length.h" 47 48 #include "pen_line.h" 49 #include "pen_fill.h" 50 51 #include "edge_data.h" 52 #include "screen_crop.h" 53 54 #include "screen_mask.h" 55 #include "mask_diamond.h" 56 57 namespace ePiX { 58 mask_diamond(const pair & arg1,const pair & arg2)59 mask_diamond::mask_diamond(const pair& arg1, const pair& arg2) 60 : m_hmin(min(arg1.x1(), arg2.x1())), 61 m_hmax(max(arg1.x1(), arg2.x1())), 62 m_vmin(min(arg1.x2(), arg2.x2())), 63 m_vmax(max(arg1.x2(), arg2.x2())) 64 { 65 m_border.push_back(edge2d(l(), b(), true)); 66 m_border.push_back(edge2d(b(), r(), true)); 67 m_border.push_back(edge2d(r(), t(), true)); 68 m_border.push_back(edge2d(t(), l(), true)); 69 } 70 clone() const71 mask_diamond* mask_diamond::clone() const 72 { 73 return new mask_diamond(*this); 74 } 75 76 // corners and midpoints h_min() const77 double mask_diamond::h_min() const { return m_hmin; } v_min() const78 double mask_diamond::v_min() const { return m_vmin; } 79 h_max() const80 double mask_diamond::h_max() const { return m_hmax; } v_max() const81 double mask_diamond::v_max() const { return m_vmax; } 82 h_avg() const83 double mask_diamond::h_avg() const { return 0.5*(m_hmin+m_hmax); } v_avg() const84 double mask_diamond::v_avg() const { return 0.5*(m_vmin+m_vmax); } 85 h_size() const86 double mask_diamond::h_size() const { return m_hmax - m_hmin; } v_size() const87 double mask_diamond::v_size() const { return m_vmax - m_vmin; } 88 89 // diamond-specific functions crops(const pair & arg) const90 bool mask_diamond::crops(const pair& arg) const 91 { 92 const double x(fabs(arg.x1() - h_avg())/h_size()); 93 const double y(fabs(arg.x2() - v_avg())/v_size()); 94 95 return !((x + y) <= 0.5); 96 } 97 crop_path(std::list<edge2d> & L) const98 std::list<edge2d>& mask_diamond::crop_path(std::list<edge2d>& L) const 99 { 100 return crop_path_2nd(m_border, L); 101 } 102 crop_loop(std::list<edge2d> & L) const103 std::list<edge2d>& mask_diamond::crop_loop(std::list<edge2d>& L) const 104 { 105 return crop_loop_2nd(m_border, L); 106 } 107 border(const Color & col,const length & len) const108 pen_line mask_diamond::border(const Color& col, const length& len) const 109 { 110 return pen_line(pen_data(col, len), Xfine(), m_border); 111 } 112 backing(const Color & col) const113 pen_fill mask_diamond::backing(const Color& col) const 114 { 115 return pen_fill(col, pen_data(col, PLAIN_WIDTH), 0, m_border); 116 } 117 border() const118 pen_line mask_diamond::border() const 119 { 120 return pen_line(the_paint_style().line_pen(), 121 the_paint_style().base_pen(), m_border); 122 } 123 backing() const124 pen_fill mask_diamond::backing() const 125 { 126 const Color& col(the_paint_style().fill_color()); 127 return pen_fill(col, pen_data(col, PLAIN_WIDTH), 0, m_border); 128 } 129 } // end of ePiX namespace 130