1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*
* mask_diamond.cc -- ePiX diamond crop mask
*
* This file is part of ePiX, a C++ library for creating high-quality
* figures in LaTeX
*
* Version 1.1.10
* Last Change: August 09, 2007
*/
/*
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
* Andrew D. Hwang <rot 13 nujnat at zngupf dot ubylpebff dot rqh>
* Department of Mathematics and Computer Science
* College of the Holy Cross
* Worcester, MA, 01610-2395, USA
*/
/*
* ePiX 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 2 of the License, or
* (at your option) any later version.
*
* ePiX 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 ePiX; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <cmath>
#include "functions.h"
//#include "errors.h"
#include "constants.h"
#include "pairs.h"
#include "Color.h"
#include "paint_style.h"
#include "length.h"
#include "pen_line.h"
#include "pen_fill.h"
#include "edge_data.h"
#include "screen_crop.h"
#include "screen_mask.h"
#include "mask_diamond.h"
namespace ePiX {
mask_diamond::mask_diamond(const pair& arg1, const pair& arg2)
: m_hmin(min(arg1.x1(), arg2.x1())),
m_hmax(max(arg1.x1(), arg2.x1())),
m_vmin(min(arg1.x2(), arg2.x2())),
m_vmax(max(arg1.x2(), arg2.x2()))
{
m_border.push_back(edge2d(l(), b(), true));
m_border.push_back(edge2d(b(), r(), true));
m_border.push_back(edge2d(r(), t(), true));
m_border.push_back(edge2d(t(), l(), true));
}
mask_diamond* mask_diamond::clone() const
{
return new mask_diamond(*this);
}
// corners and midpoints
double mask_diamond::h_min() const { return m_hmin; }
double mask_diamond::v_min() const { return m_vmin; }
double mask_diamond::h_max() const { return m_hmax; }
double mask_diamond::v_max() const { return m_vmax; }
double mask_diamond::h_avg() const { return 0.5*(m_hmin+m_hmax); }
double mask_diamond::v_avg() const { return 0.5*(m_vmin+m_vmax); }
double mask_diamond::h_size() const { return m_hmax - m_hmin; }
double mask_diamond::v_size() const { return m_vmax - m_vmin; }
// diamond-specific functions
bool mask_diamond::crops(const pair& arg) const
{
const double x(fabs(arg.x1() - h_avg())/h_size());
const double y(fabs(arg.x2() - v_avg())/v_size());
return !((x + y) <= 0.5);
}
std::list<edge2d>& mask_diamond::crop_path(std::list<edge2d>& L) const
{
return crop_path_2nd(m_border, L);
}
std::list<edge2d>& mask_diamond::crop_loop(std::list<edge2d>& L) const
{
return crop_loop_2nd(m_border, L);
}
pen_line mask_diamond::border(const Color& col, const length& len) const
{
return pen_line(pen_data(col, len), Xfine(), m_border);
}
pen_fill mask_diamond::backing(const Color& col) const
{
return pen_fill(col, pen_data(col, PLAIN_WIDTH), 0, m_border);
}
pen_line mask_diamond::border() const
{
return pen_line(the_paint_style().line_pen(),
the_paint_style().base_pen(), m_border);
}
pen_fill mask_diamond::backing() const
{
const Color& col(the_paint_style().fill_color());
return pen_fill(col, pen_data(col, PLAIN_WIDTH), 0, m_border);
}
} // end of ePiX namespace
|