diff options
author | Norbert Preining <norbert@preining.info> | 2020-08-07 03:02:55 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-08-07 03:02:55 +0000 |
commit | 3710c23789342d9d88783cbe9ad23eb5263a7c33 (patch) | |
tree | 1c40b2bfb9f6b652f7877ad0991f5d6b44391154 /graphics/asymptote/drawelement.h | |
parent | d99fea72e367e8d4d2809b43b3b0206b1bb526b8 (diff) |
CTAN sync 202008070302
Diffstat (limited to 'graphics/asymptote/drawelement.h')
-rw-r--r-- | graphics/asymptote/drawelement.h | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/graphics/asymptote/drawelement.h b/graphics/asymptote/drawelement.h index 7dbd1c42b0..f561d2786d 100644 --- a/graphics/asymptote/drawelement.h +++ b/graphics/asymptote/drawelement.h @@ -29,16 +29,16 @@ static const double pixel=1.0; // Adaptive rendering constant. enum Interaction {EMBEDDED=0,BILLBOARD}; void copyArray4x4C(double*& dest, const vm::array *a); - + class box { pair p[4]; public: - + box() {} box(const pair& a, const pair& b, const pair& c, const pair& d) { p[0]=a; p[1]=b; p[2]=c; p[3]=d; } - + // Returns true if the line a--b intersects box b. bool intersect(const pair& a, const pair& b) const { @@ -55,9 +55,9 @@ public: } return false; } - + pair operator [] (Int i) const {return p[i];} - + bool intersect(const box& b) const { for(Int i=0; i < 4; ++i) { pair A=b[i]; @@ -66,25 +66,25 @@ public: } return false; } - + double xmax() { return max(max(max(p[0].x,p[1].x),p[2].x),p[3].x); } - + double ymax() { return max(max(max(p[0].y,p[1].y),p[2].y),p[3].y); } - + double xmin() { return min(min(min(p[0].x,p[1].x),p[2].x),p[3].x); } - + double ymin() { return min(min(min(p[0].y,p[1].y),p[2].y),p[3].y); } - + }; - + class bbox2 { public: double x,y,X,Y; @@ -93,7 +93,7 @@ public: for(size_t i=1; i < n; ++i) bounds(v[i]); } - + bbox2(const triple& m, const triple& M) { Bounds(m); bounds(triple(m.getx(),m.gety(),M.getz())); @@ -104,7 +104,7 @@ public: bounds(triple(M.getx(),M.gety(),m.getz())); bounds(M); } - + bbox2(const triple& m, const triple& M, const Billboard& BB) { Bounds(BB.transform(m)); bounds(BB.transform(triple(m.getx(),m.gety(),M.getz()))); @@ -115,7 +115,7 @@ public: bounds(BB.transform(triple(M.getx(),M.gety(),m.getz()))); bounds(BB.transform(M)); } - + // Is 2D bounding box formed by projecting 3d points in vector v offscreen? bool offscreen() { double eps=1.0e-2; @@ -123,13 +123,13 @@ public: double max=1.0+eps; return X < min || x > max || Y < min || y > max; } - + void Bounds(const triple& v) { pair V=Transform2T(gl::dprojView,v); x=X=V.getx(); y=Y=V.gety(); } - + void bounds(const triple& v) { pair V=Transform2T(gl::dprojView,v); double a=V.getx(); @@ -142,9 +142,9 @@ public: }; typedef mem::vector<box> boxvector; - + typedef mem::list<bbox> bboxlist; - + typedef mem::map<CONST string,unsigned> groupmap; typedef mem::vector<groupmap> groupsmap; @@ -152,20 +152,20 @@ class drawElement : public gc { public: string KEY; - + drawElement(const string& key="") : KEY(key == "" ? processData().KEY : key) - {} - + {} + virtual ~drawElement() {} - + static mem::vector<triple> center; static size_t centerIndex; static triple lastcenter; static size_t lastcenterIndex; - - static pen lastpen; + + static pen lastpen; static const triple zero; - + // Adjust the bbox of the picture based on the addition of this // element. The iopipestream is needed for determining label sizes. virtual void bounds(bbox&, iopipestream&, boxvector&, bboxlist&) {} @@ -175,15 +175,15 @@ public: // Compute bounds on ratio (x,y)/z for 3d picture (not cached). virtual void ratio(const double *t, pair &b, double (*m)(double, double), double fuzz, bool &first) {} - + virtual void minratio(const double *t, pair &b, double fuzz, bool &first) { ratio(t,b,camp::min,fuzz,first); } - + virtual void maxratio(const double *t,pair &b, double fuzz, bool &first) { ratio(t,b,camp::max,fuzz,first); } - + virtual void ratio(pair &b, double (*m)(double, double), double fuzz, bool &first) { ratio(NULL,b,m,fuzz,first); @@ -200,20 +200,20 @@ public: virtual bool islabel() {return false;} virtual bool isnewpage() {return false;} - + virtual bool islayer() {return false;} virtual bool is3D() {return false;} // Implement element as raw SVG code? virtual bool svg() {return false;} - + // Implement SVG element as png image? virtual bool svgpng() {return false;} - + virtual bool beginclip() {return false;} virtual bool endclip() {return false;} - + virtual bool begingroup() {return false;} virtual bool begingroup3() {return false;} @@ -223,7 +223,7 @@ public: virtual const double* transf3() {return NULL;} virtual void save(bool b) {} - + // Output to a PostScript file virtual bool draw(psfile *) { return false; @@ -239,22 +239,22 @@ public: groupsmap& groups) { return false; } - + // Output to a JS file virtual bool write(jsfile *out) { return false; } - + // Used to compute deviation of a surface from a quadrilateral. virtual void displacement() {} // Render with OpenGL virtual void render(double size2, const triple& Min, const triple& Max, - double perspective, bool remesh) + double perspective, bool remesh) {} virtual void meshinit() {} - + size_t centerindex(const triple& center) { if(drawElement::center.empty() || center != drawElement::lastcenter) { drawElement::lastcenter=center; @@ -268,7 +268,7 @@ public: virtual drawElement *transformed(const transform&) { return this; } - + virtual drawElement *transformed(const double* t) { return this; } @@ -279,9 +279,9 @@ public: class drawElementLC : public virtual drawElement { public: double *T; // Keep track of accumulative picture transform - + drawElementLC() : T(NULL) {} - + drawElementLC(const double *t) : T(NULL) { copyTransform3(T,t); } @@ -290,7 +290,7 @@ public: copyArray4x4C(T,&t); } - drawElementLC(const double* t, const drawElementLC *s) : + drawElementLC(const double* t, const drawElementLC *s) : drawElement(s->KEY), T(NULL) { multiplyTransform3(T,t,s->T); } @@ -324,19 +324,19 @@ public: virtual void bounds(bbox& b, iopipestream&, boxvector&, bboxlist&) { b += p.bounds(); } - + virtual void writepath(psfile *out,bool) { out->write(p); } - + virtual void writeclippath(psfile *out, bool newpath=true) { out->writeclip(p,newpath); } - + virtual void writeshiftedpath(texfile *out) { out->writeshifted(p); } -}; +}; // Base class for drawElements that involve paths and pens. class drawPathPenBase : public drawPathBase { @@ -348,28 +348,28 @@ protected: } public: - drawPathPenBase(path p, pen pentype) : + drawPathPenBase(path p, pen pentype) : drawPathBase(p), pentype(pentype) {} - + drawPathPenBase(pen pentype) : pentype(pentype) {} - + virtual bool empty() { return p.empty(); } - + virtual bool cyclic() { return p.cyclic(); } - + void strokebounds(bbox& b, const path& p); - + virtual void penSave(psfile *out) { if (!pentype.getTransform().isIdentity()) out->gsave(); } - + virtual void penTranslate(psfile *out) { out->translate(shiftpair(pentype.getTransform())); @@ -386,7 +386,7 @@ public: out->grestore(); } }; - + // Base class for drawElements that involve superpaths and pens. class drawSuperPathPenBase : public drawPathPenBase { protected: @@ -400,57 +400,57 @@ protected: (*Pt)[i]=vm::read<path>(P,i).transformed(t); return *Pt; } - + public: drawSuperPathPenBase(const vm::array& P, pen pentype) : drawPathPenBase(pentype), P(P), size(P.size()) {} bool empty() { - for(size_t i=0; i < size; i++) + for(size_t i=0; i < size; i++) if(vm::read<path>(P,i).size() != 0) return false; return true; } - + bool cyclic() { - for(size_t i=0; i < size; i++) + for(size_t i=0; i < size; i++) if(!vm::read<path>(P,i).cyclic()) return false; return true; } - + void bounds(bbox& b, iopipestream&, boxvector&, bboxlist&) { for(size_t i=0; i < size; i++) bpath += vm::read<path>(P,i).bounds(); b += bpath; } - + void strokepath(psfile *out) { out->strokepath(); } - + void strokebounds(bbox& b) { for(size_t i=0; i < size; i++) drawPathPenBase::strokebounds(bpath,vm::read<path>(P,i)); b += bpath; } - + void writepath(psfile *out, bool newpath=true) { if(size > 0) out->write(vm::read<path>(P,0),newpath); for(size_t i=1; i < size; i++) out->write(vm::read<path>(P,i),false); } - + void writeclippath(psfile *out, bool newpath=true) { if(size > 0) out->writeclip(vm::read<path>(P,0),newpath); for(size_t i=1; i < size; i++) out->writeclip(vm::read<path>(P,i),false); } - + void writeshiftedpath(texfile *out) { - for(size_t i=0; i < size; i++) + for(size_t i=0; i < size; i++) out->writeshifted(vm::read<path>(P,i),i == 0); } }; - + #ifdef HAVE_LIBGLM void setcolors(bool colors, const prc::RGBAColour& diffuse, @@ -459,7 +459,7 @@ void setcolors(bool colors, double metallic, double fresnel0, jsfile *out=NULL); #endif - + } |