1 /* 2 * mask_ellipse.cc -- ePiX ellipse 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_ellipse.h" 56 57 namespace ePiX { 58 mask_ellipse(const pair & arg1,const pair & arg2)59 mask_ellipse::mask_ellipse(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 const double dt(2*M_PI/EPIX_NUM_PTS); 66 67 const pair ctr(0.5*(m_hmin + m_hmax), 0.5*(m_vmin + m_vmax)); 68 69 const double hsz(0.5*(m_hmax - m_hmin)); 70 const double vsz(0.5*(m_vmax - m_vmin)); 71 72 for (unsigned int i=0; i<EPIX_NUM_PTS; ++i) 73 m_border.push_back(edge2d(ctr + pair(hsz*std::cos(i*dt), 74 vsz*std::sin(i*dt)), 75 ctr + pair(hsz*std::cos((i+1)*dt), 76 vsz*std::sin((i+1)*dt)), true)); 77 } 78 clone() const79 mask_ellipse* mask_ellipse::clone() const 80 { 81 return new mask_ellipse(*this); 82 } 83 84 // corners and midpoints h_min() const85 double mask_ellipse::h_min() const { return m_hmin; } v_min() const86 double mask_ellipse::v_min() const { return m_vmin; } 87 h_max() const88 double mask_ellipse::h_max() const { return m_hmax; } v_max() const89 double mask_ellipse::v_max() const { return m_vmax; } 90 h_avg() const91 double mask_ellipse::h_avg() const { return 0.5*(m_hmin+m_hmax); } v_avg() const92 double mask_ellipse::v_avg() const { return 0.5*(m_vmin+m_vmax); } 93 h_size() const94 double mask_ellipse::h_size() const { return m_hmax - m_hmin; } v_size() const95 double mask_ellipse::v_size() const { return m_vmax - m_vmin; } 96 97 // ellipse-specific functions crops(const pair & arg) const98 bool mask_ellipse::crops(const pair& arg) const 99 { 100 const double dx((arg.x1() - h_avg())/h_size()); 101 const double dy((arg.x2() - v_avg())/v_size()); 102 return !(dx*dx + dy*dy <= 0.25); 103 } 104 crop_path(std::list<edge2d> & L) const105 std::list<edge2d>& mask_ellipse::crop_path(std::list<edge2d>& L) const 106 { 107 return crop_path_2nd(m_border, L); 108 } 109 crop_loop(std::list<edge2d> & L) const110 std::list<edge2d>& mask_ellipse::crop_loop(std::list<edge2d>& L) const 111 { 112 return crop_loop_2nd(m_border, L); 113 } 114 border(const Color & col,const length & len) const115 pen_line mask_ellipse::border(const Color& col, const length& len) const 116 { 117 return pen_line(pen_data(col, len), Xfine(), m_border); 118 } 119 backing(const Color & col) const120 pen_fill mask_ellipse::backing(const Color& col) const 121 { 122 return pen_fill(col, pen_data(col, PLAIN_WIDTH), 0, m_border); 123 } 124 border() const125 pen_line mask_ellipse::border() const 126 { 127 return pen_line(the_paint_style().line_pen(), 128 the_paint_style().base_pen(), m_border); 129 } 130 backing() const131 pen_fill mask_ellipse::backing() const 132 { 133 const Color col(the_paint_style().fill_color()); 134 return pen_fill(col, pen_data(col, PLAIN_WIDTH), 0, m_border); 135 } 136 } // end of ePiX namespace 137