diff options
author | Karl Berry <karl@freefriends.org> | 2020-03-03 22:35:09 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2020-03-03 22:35:09 +0000 |
commit | f6bb2b5974c9dc15a4530842100d30fe1981b973 (patch) | |
tree | 62ef95efa54d91b6eafb6df99f330dc136f77f29 /Build/source/utils/asymptote/beziercurve.cc | |
parent | 24dbc0b1802756862bedad6a4088f50aad68b51b (diff) |
asy 2.63 sources
git-svn-id: svn://tug.org/texlive/trunk@54034 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/beziercurve.cc')
-rw-r--r-- | Build/source/utils/asymptote/beziercurve.cc | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/Build/source/utils/asymptote/beziercurve.cc b/Build/source/utils/asymptote/beziercurve.cc index 23f5fc6779a..9a5eee79f23 100644 --- a/Build/source/utils/asymptote/beziercurve.cc +++ b/Build/source/utils/asymptote/beziercurve.cc @@ -20,11 +20,30 @@ void BezierCurve::init(double res) MaterialIndex=materialIndex; } +inline triple normal(triple bP, triple bPP) +{ + return dot(bP,bP)*bPP-dot(bP,bPP)*bP; +} + void BezierCurve::render(const triple *p, bool straight) { - GLuint i0=data.vertex1(p[0]); - GLuint i3=data.vertex1(p[3]); - + triple p0=p[0]; + triple p3=p[3]; + triple n0,n1; + + if(straight) { + n0=n1=triple(0.0,0.0,1.0); + } else { + triple p1=p[1]; + triple p2=p[2]; + + n0=normal(p1-p0,p0+p2-2.0*p1); + n1=normal(p3-p2,p3+p1-2.0*p2); + } + + GLuint i0=data.vertex(p0,n0); + GLuint i3=data.vertex(p3,n1); + if(straight) { std::vector<GLuint> &q=data.indices; q.push_back(i0); @@ -34,9 +53,9 @@ void BezierCurve::render(const triple *p, bool straight) append(); } -// Use a uniform partition to draw a Bezier patch. +// Use a uniform partition to draw a Bezier curve. // p is an array of 4 triples representing the control points. -// Ii are the vertices indices. +// Ii are the vertex indices. void BezierCurve::render(const triple *p, GLuint I0, GLuint I1) { triple p0=p[0]; @@ -62,7 +81,8 @@ void BezierCurve::render(const triple *p, GLuint I0, GLuint I1) triple s0[]={p0,m0,m3,m5}; triple s1[]={m5,m4,m2,p3}; - GLuint i0=data.vertex1(m5); + triple n0=normal(bezierPh(p0,p1,p2,p3),bezierPPh(p0,p1,p2,p3)); + GLuint i0=data.vertex(m5,n0); render(s0,I0,i0); render(s1,i0,I1); |