Laxkit  0.0.7.1
coordinate.h
1 //
2 //
3 // The Laxkit, a windowing toolkit
4 // Please consult http://laxkit.sourceforge.net about where to send any
5 // correspondence about this software.
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // Copyright (C) 2004-2012 by Tom Lechner
22 //
23 #ifndef _LAX_COORDINATE_H
24 #define _LAX_COORDINATE_H
25 
26 
27 #include <lax/anobject.h>
28 #include <lax/vectors.h>
29 
30 #include <iostream>
31 using namespace std;
32 
33 
34 namespace LaxInterfaces {
35 
36 
37 //-------------------- SegmentControls ---------------------------
38 
40 {
41  public:
42  virtual int iid()=0;
43  virtual ~SegmentControls() {}
44  virtual SegmentControls *duplicate()=0;
45 };
46 
47 
48 //-------------------- Coordinate ---------------------------
49 
50  // POINT_MASK is basically what kind of coordinate it is
51 #define POINT_VERTEX (1<<0)
52 #define POINT_TONEXT (1<<1)
53 #define POINT_TOPREV (1<<2)
54 #define POINT_MIDDLE (1<<3)
55 #define POINT_LOOP_TERMINATOR (1<<14)
56 #define POINT_TERMINATOR (1<<15)
57 #define POINT_MASK (1|2|4|8|(1<<14)|(1<<15))
58 
59  // Point's x and y coordinates can be defined relative to various things.
60  // This is to facilitate keeping controls with their vertex. One must
61  // define an origin and axis.
62  // Origin: If none of the following 3 are set, then absolute coordinates
63  // are assumed.
64 #define POINT_REL_TO_PREV (1<<4)
65 #define POINT_REL_TO_NEXT (1<<5)
66 #define POINT_REL_TO_MIDPOINT (1<<6)
67 
68  // Axis:
69  // Axis 1 has the x direction == (v2-v1)/||v2-v1||, y=transpose x
70  // Axis 2 has the x direction == (v2-v1)/2, y=transpose x
71  // If neither axis 1 or 2 is set, then the axis of the points coords is used.
72 #define POINT_REL_AXIS_1 (1<<7)
73 #define POINT_REL_AXIS_2 (1<<8)
74 #define POINT_REL_AXIS_DEFAULT (1<<9)
75 
76  // selectable means that PathInterface can select/move/rotate/etc
77 #define POINT_SELECTABLE (1<<10)
78 #define POINT_READONLY (1<<11)
79 
80  // program should make efforts to make the tangent smooth here
81  // (this is attribute of a vertex)
82 #define POINT_SMOOTH (1<<12)
83 
84  // program should make efforts to make the tangent length equal on both sides of the point
85 #define POINT_REALLYSMOOTH (1<<13)
86 
87 #define POINT_NODELETE (1<<14)
88 
90 {
91  public:
92  flatpoint fp;
93  unsigned long flags;
94  int iid,info;
95  SegmentControls *controls;
96  Coordinate *next,*prev;
97 
98  Coordinate();
100  Coordinate(double x,double y);
101  Coordinate(flatpoint pp,unsigned long nflags,SegmentControls *ctl);
102  Coordinate(double x,double y,unsigned long nflags,SegmentControls *ctl);
103  Coordinate(const Coordinate &p);
104  virtual ~Coordinate();
105  const Coordinate &operator=(const Coordinate &p);
106  virtual double x() { return fp.x; }
107  virtual void x(double xx) { fp.x=xx; }
108  virtual double y() { return fp.y; }
109  virtual void y(double yy) { fp.y=yy; }
110  virtual flatpoint p() { return fp; }
111  virtual void p(double xx,double yy) { fp.x=xx; fp.y=yy; }
112  virtual void p(flatpoint pp) { fp=pp; }
113  virtual int isAttachedTo(Coordinate *v);
114  virtual int isEndpoint();
115  virtual Coordinate *previousVertex(int n=0);
116  virtual Coordinate *nextVertex(int n=0);
117  virtual Coordinate *firstPoint(int v=0); // return the first point in open line, or this
118  virtual Coordinate *lastPoint(int v=0); // return the first point in open line, or this
119  virtual int hasCoord(Coordinate *co); // return 1 if c is somewhere in paths
120  virtual void ShiftPoint(flatpoint p) { fp+=p; } //*** this could be an overloaded (Coordinate)+=(flatpoint)
121  virtual Coordinate *duplicate();
122  virtual Coordinate *duplicateAll();
123  virtual void append(double x,double y,unsigned long flags=POINT_VERTEX,SegmentControls *ctl=NULL);
124  virtual void close();
125  virtual int isClosed();
126  virtual void connect(Coordinate *np,char after=1);
127  virtual Coordinate *disconnect(char after=1);
128  virtual Coordinate *detach();
129  virtual Coordinate *detachThrough(Coordinate *p);
130  virtual int insert(Coordinate *c,int after=1);
131  virtual int NumPoints(int v);
132  virtual flatpoint direction(int after);
133 };
134 
135 
136 //----------------------------------- Coordinate Shape Makers ----------------------------------
137 
138 Coordinate *CoordinatePolygon(flatpoint center, double radius, bool point_on_x_axis, int num_sides, int num_winding);
139 //Coordinate RoundedRectangle(flatpoint ll, flatpoint ur, double round,double round2);
140 
141 } //namespace LaxInterfaces
142 
143 #endif
144 
145 

Mon Feb 17 2014 11:52:56, Laxkit