Modified the read_curve function to work with the new Conic_arc constructors.

Also changed format of approximated end-points in the input files.
This commit is contained in:
Efi Fogel 2003-02-02 16:21:05 +00:00
parent 0b26189b4b
commit 039c7c47fe
7 changed files with 104 additions and 41 deletions

View File

@ -9,7 +9,8 @@ s -1 3 3 -1
e 3 2 0 0 -3 0 3 0
# Curve #2: part of the upper portion of the right branch of the hyperbola
# (x/2)^2 - (y/1)^2 = 1
h 2 1 0 0 3 1.118034 2 0
# given by its intersections with x=2 and x=3.
i 1 -4 0 0 0 -4 3 1.118034 0 0 0 1 0 -3 2 0 0 0 0 1 0 -2
# Curve #3: the upper part of the circle x^2 + y^2 = 2^2.
e 2 2 0 0 -2 0 2 0
# Curve #4: the lower part of the circle x^2 + (y-3)^2 = 1^2

View File

@ -17,8 +17,8 @@ s 0 0 0 -3
e 3 1 0 -1 -3 -1 0 0
# Curve #6: a horizontal segment
s -2 0 0 0
# curve #7: a portion of the hyperbola y + 1 = 1/(x + 1)
a 0 0 1 1 1 0 -0.9 9 0 0
# curve #7: a segment
s -1 1 0 0
#-----------------------------------------------------------
# Number of "stand alone" points
1

View File

@ -17,8 +17,8 @@ s 0 0 0 -3
e 3 1 0 -1 -3 -1 0 0
# Curve #6: a horizontal segment
s -2 0 0 0
# curve #7: a portion of the hyperbola y + 1 = 1/(x + 1)
a 0 0 1 1 1 0 -0.9 9 0 0
# curve #7: a segment
s -1 1 0 0
#-----------------------------------------------------------
# Number of "stand alone" points
1

View File

@ -9,8 +9,9 @@ e 5 3 0 0 0 3 5 0
s -1 3 2 4
# Curve #2: a vertical segment
s 0 1 0 0
# Curve #3: a portion of the hyperbola y = 1/x
a 0 0 1 0 0 -1 0.1 10 2 0.5
# Curve #3: a portion of the upper branch of the hyperbola y = 1/x
# given by its intersections with y=100x and x=4y
i 0 0 1 0 0 -1 0.1 10 0 0 0 100 -1 0 2 0.5 0 0 0 1 -4 0
# Curve #4: a portion of the parabola y = 3*x^2 - 2*x + 5
a 3 0 0 -2 -1 5 2 13 -1 10
#-----------------------------------------------------------

View File

@ -8,8 +8,9 @@ e 5 3 0 0 -5 0 5 0
s -1 3 3 -1
# Curve #2: a vertical segment
s 0 -2 0 0
# Curve #3: a portion of the hyperbola y = 1/x
a 0 0 1 0 0 -1 0.1 10 2 0.5
# Curve #3: a portion of the upper branch of the hyperbola y = 1/x
# given by its intersections with y=100x and x=4y
i 0 0 1 0 0 -1 0.1 10 0 0 0 100 -1 0 2 0.5 0 0 0 1 -4 0
# Curve #4: a portion of the parabola y = 3*x^2 - 2*x + 5
a 3 0 0 -2 -1 5 2 13 -1 10
#-----------------------------------------------------------

View File

@ -8,8 +8,9 @@ e 5 3 0 0 -5 0 5 0
s -1 3 3 -1
# Curve #2: a vertical segment
s 0 -2 0 0
# Curve #3: a portion of the hyperbola y = 1/x
a 0 0 1 0 0 -1 0.1 10 2 0.5
# Curve #3: a portion of the upper branch of the hyperbola y = 1/x
# given by its intersections with y=100x and x=4y
i 0 0 1 0 0 -1 0.1 10 0 0 0 100 -1 0 2 0.5 0 0 0 1 -4 0
# Curve #4: a portion of the parabola y = 3*x^2 - 2*x + 5
a 3 0 0 -2 -1 5 2 13 -1 10
#-----------------------------------------------------------

View File

@ -14,9 +14,10 @@ public Base_traits_test<Traits_class, Number_type>
typedef Number_type NT;
typedef typename Traits_class::Point_2 Point;
typedef typename Traits_class::Segment_2 Segment;
typedef typename Traits_class::Circle_2 Circle;
typedef typename Traits_class::X_curve_2 X_curve;
typedef typename Traits_class::Curve_2 Curve;
typedef typename Traits_class::Curve_2 Conic;
public:
@ -50,12 +51,13 @@ read_curve (std::ifstream & is, Curve & cv)
char one_line[128];
skip_comments (is, one_line);
std::string stringvalues(one_line);
std::istringstream str_line (stringvalues, std::istringstream::in);
std::istrstream str_line( one_line, 128 );
// Get the arc type.
char type;
Conic conic;
char type;
bool is_circle = false; // Is this a circle.
Circle circle;
NT r, s, t, u, v, w; // The conic coefficients.
str_line >> type;
@ -75,14 +77,29 @@ read_curve (std::ifstream & is, Curve & cv)
NT a_sq = a*a;
NT b_sq = b*b;
conic = Conic (b_sq, a_sq, 0,
-2*x0*b_sq, -2*y0*a_sq,
x0*x0*b_sq + y0*y0*a_sq - a_sq*b_sq);
if (a == b)
{
is_circle = true;
circle = Circle (Point (x0, y0), a*b, CGAL::CLOCKWISE);
}
else
{
r = b_sq;
s = a_sq;
t = 0;
u = -2*x0*b_sq;
v = -2*y0*a_sq;
w = x0*x0*b_sq + y0*y0*a_sq - a_sq*b_sq;
}
if (type == 'f' || type == 'F')
{
// Create a full ellipse.
cv = Curve(conic);
// Create a full ellipse (or circle).
if (is_circle)
cv = Curve (circle);
else
cv = Curve (r, s, t, u, v, w);
return;
}
}
@ -101,9 +118,12 @@ read_curve (std::ifstream & is, Curve & cv)
NT a_sq = a*a;
NT b_sq = b*b;
conic = Conic (b_sq, -a_sq, 0,
-2*x0*b_sq, 2*y0*a_sq,
x0*x0*b_sq - y0*y0*a_sq - a_sq*b_sq);
r = b_sq;
s= -a_sq;
t = 0;
u = -2*x0*b_sq;
v = 2*y0*a_sq;
w = x0*x0*b_sq - y0*y0*a_sq - a_sq*b_sq;
}
else if (type == 'p' || type == 'P')
{
@ -116,23 +136,22 @@ read_curve (std::ifstream & is, Curve & cv)
str_line >> c >> x0 >> y0;
conic = Conic (1, 0, 0,
-2*x0, -4*c,
x0*x0 + 4*c*y0);
r = 1;
s = 0;
t = 0;
u = -2*x0;
v = -4*c;
w = x0*x0 + 4*c*y0;
}
else if (type == 'c' || type == 'C' || type == 'a' || type == 'A')
{
// Read a general conic, given by its coefficients <r,s,t,u,v,w>.
NT r, s, t, u, v, w;
str_line >> r >> s >> t >> u >> v >> w;
conic = Conic (r, s, t, u, v, w);
if (type == 'c' || type == 'C')
{
// Create a full conic (should work only for ellipses).
cv = Curve(conic);
cv = Curve (r, s, t, u, v, w);
return;
}
}
@ -143,18 +162,51 @@ read_curve (std::ifstream & is, Curve & cv)
str_line >> x1 >> y1 >> x2 >> y2;
conic = Conic (0, 0, 0,
y1 - y2, x2 - x1,
x1*y2 - x2*y1);
Point source (x1, y1);
Point target (x2, y2);
Segment segment (source, target);
// Create the segment.
cv = Curve(conic, Point(x1,y1), Point(x2,y2));
cv = Curve (segment);
return;
}
else if (type == 'i' || type == 'I')
{
// Read a general conic, given by its coefficients <r,s,t,u,v,w>.
str_line >> r >> s >> t >> u >> v >> w;
// Read the approximated source, along with a general conic
// <r_1,s_1,t_1,u_1,v_1,w_1> whose intersection with <r,s,t,u,v,w>
// defines the source.
NT r1, s1, t1, u1, v1, w1;
NT x1, y1;
str_line >> x1 >> y1;
str_line >> r1 >> s1 >> t1 >> u1 >> v1 >> w1;
Point app_source (x1, y1);
// Read the approximated target, along with a general conic
// <r_2,s_2,t_2,u_2,v_2,w_2> whose intersection with <r,s,t,u,v,w>
// defines the target.
NT r2, s2, t2, u2, v2, w2;
NT x2, y2;
str_line >> x2 >> y2;
str_line >> r2 >> s2 >> t2 >> u2 >> v2 >> w2;
Point app_target (x2, y2);
// Create the conic arc.
cv = Curve (r, s, t, u, v ,w,
app_source, r1, s1, t1, u1, v1, w1,
app_target, r2, s2, t2, u2, v2, w2);
return;
}
else
{
std::cerr << "Illegal conic type specification: " << type << "." << std::endl;
std::cerr << "Illegal conic type specification: " << type << "."
<< std::endl;
return;
}
@ -166,10 +218,17 @@ read_curve (std::ifstream & is, Curve & cv)
Point source (x1, y1);
Point target (x2, y2);
// Create the circular arc.
cv = Curve (conic,
source, target,
_error_eps); // It's OK to move the endpoints a bit.
// Create the conic (or circular) arc.
if (is_circle)
{
cv = Curve (circle,
source, target);
}
else
{
cv = Curve (r, s, t, u, v, w,
source, target);
}
return;
}