13#ifndef pointtypes_declare
14#define pointtypes_declare
25#define ERROR_MESSAGE() std::cout << "ERROR: file: " << __FILE__ << " line: " << __LINE__ << std::endl;
30typedef enum {NO, YES, MAYBE} Boo;
35enum class CritType {ND=0,radial=2,tangential=1,pseudo=3,};
38std::ostream &operator<<(std::ostream &os, CritType
const &p);
42int sign(T val){
return (T(0) < val) - (val < T(0));}
64 if(
this == &p)
return *
this;
75 bool operator==(
const Point_2d &p)
const{
76 return (x[0] == p.x[0])*(x[1] == p.x[1]);
78 bool operator!=(
const Point_2d &p)
const{
79 return (x[0] != p.x[0]) || (x[1] != p.x[1]);
84 tmp.x[0] = x[0] + p.x[0];
85 tmp.x[1] = x[1] + p.x[1];
90 tmp.x[0] = x[0] - p.x[0];
91 tmp.x[1] = x[1] - p.x[1];
104 Point_2d & operator/=(PosType value){
109 Point_2d operator/(PosType value)
const{
115 Point_2d & operator*=(PosType value){
120 Point_2d operator*(PosType value)
const{
121 return Point_2d(x[0]*value,x[1]*value);
126 return x[0]*p.x[0] + x[1]*p.x[1];
130 return x[0]*p.x[1] - x[1]*p.x[0];
135 return sqrt(x[0]*x[0] + x[1]*x[1]);
140 return x[0]*x[0] + x[1]*x[1];
144 void rotate(PosType theta){
145 PosType c = cos(theta),s = sin(theta);
147 x[0] = c*tmp - s*x[1];
148 x[1] = c*x[1] + s*tmp;
154 PosType c = cos(theta),s = sin(theta);
155 p[0] = c*x[0] - s*x[1];
156 p[1] = c*x[1] + s*x[0];
169 PosType* data(){
return x;}
174 PosType & operator[](
size_t i) {
return x[i];}
175 const PosType & operator[](
size_t i)
const {
return x[i];}
185 Matrix2x2(
const Matrix2x2<T> &F){
192 template <
typename B>
193 Matrix2x2<T> operator=(
const Matrix2x2<B> &F){
202 bool operator==(
const Matrix2x2<T> &F){
204 return (a[0] == F.a[0]) * (a[1] == F.a[1]) * (a[2] == F.a[2]) * (a[3] == F.a[3]);
208 Matrix2x2<T> operator*=(T f){
217 Matrix2x2<T> operator/=(T f){
226 Matrix2x2<T> operator*(T f)
const{
227 Matrix2x2<T> m = *
this;
234 v2[0] = a[0]*v[0] + a[1]*v[1];
235 v2[1] = a[2]*v[0] + a[3]*v[1];
240 Matrix2x2<T> operator/(T f)
const{
241 Matrix2x2<T> m = *
this;
247 template <
typename B>
248 Matrix2x2<T> operator*(
const Matrix2x2<B> &F)
const{
251 m.a[0] = a[0] * F.a[0] + a[1] * F.a[2];
252 m.a[1] = a[0] * F.a[1] + a[1] * F.a[3];
253 m.a[2] = a[2] * F.a[0] + a[3] * F.a[2];
254 m.a[3] = a[2] * F.a[1] + a[3] * F.a[3];
259 template <
typename B>
260 Matrix2x2<T> operator+=(
const Matrix2x2<B> &F){
269 template <
typename B>
270 Matrix2x2<T> operator+(
const Matrix2x2<B> &F)
const{
271 Matrix2x2<T> m = *
this;
276 template <
typename B>
277 Matrix2x2<T> operator-=(
const Matrix2x2<B> &F){
286 template <
typename B>
287 Matrix2x2<T> operator-(
const Matrix2x2<B> &F)
const{
288 Matrix2x2<T> m = *
this;
295 T & operator()(
int i,
int j){
299 T operator()(
int i,
int j)
const{
304 T & operator[](
int i){
309 return a[0]*a[3] - a[1]*a[2];
312 Matrix2x2<T> inverse()
const{
326 std::swap(a[0],a[3]);
341 static Matrix2x2<T> I(){
348 static Matrix2x2<T> sig1(){
355 static Matrix2x2<T> sig2(){
358 m.a[1] = m.a[2] = -1;
362 static Matrix2x2<T> sig3(){
370 T kappa()
const {
return 1-(a[0] + a[3])/2; }
372 T gamma1()
const{
return (a[0] - a[3])/2;}
373 T gamma2()
const{
return (a[1] + a[2])/2;}
374 T gamma3()
const{
return (a[2] - a[1])/2;}
376 void set(T kappa,T gamma[3]){
377 a[0] = 1 - kappa + gamma[0];
378 a[3] = 1 - kappa - gamma[0];
380 a[1] = gamma[1] - gamma[3];
381 a[2] = gamma[1] + gamma[3];
384 void gamma(T *g)
const{
392 std::cout << std::endl;
393 std::cout << a[0] <<
" " << a[1] << std::endl;
394 std::cout << a[2] <<
" " << a[3] << std::endl;
398 void eigenv(T lambda[]){
399 T m = (a[0] + a[3])/2;
400 T determinent = det();
402 lambda[0] = m + sqrt( abs(m*m - determinent));
403 lambda[1] = m - sqrt( abs(m*m - determinent));
418 Point(PosType x,PosType y);
421 Point *image=
nullptr;
423 unsigned long head=0;
426 PosType *ptr_y(){
return image->x;}
430 Point_2d::operator=(p);
437 Matrix2x2<KappaType> A;
439 KappaType invmag()
const{
442 KappaType gamma1()
const{
445 KappaType gamma2()
const{
448 KappaType gamma3()
const{
451 KappaType kappa()
const{
456 double flux(){
return surface_brightness * gridsize * gridsize;}
459 float surface_brightness;
468 return (p1->x[0] < p2->x[0]);
471 return (p1->x[0] > p2->x[0]);
474 return (p1->x[1] < p2->x[1]);
477 return (p1->x[1] > p2->x[1]);
485 return (eigens[0] < 0)*(eigens[1] < 0);
489std::ostream &operator<<(std::ostream &os,
Point const &p);
514 A = Matrix2x2<KappaType>::I();
522 y[0] = p.image->x[0];
523 y[1] = p.image->x[1];
533 y[0] = p.image->x[0];
534 y[1] = p.image->x[1];
553 assert(p.image !=
nullptr);
557 y[0] = p.image->x[0];
558 y[1] = p.image->x[1];
569 RAY & operator=(
const RAY &p){
587 PosType *ptr_y(){
return y.x;}
589 Matrix2x2<KappaType> A;
599 KappaType gamma1()
const{
602 KappaType gamma2()
const{
605 KappaType gamma3()
const{
608 KappaType kappa()
const{
616std::ostream &operator<<(std::ostream &os,
Point_2d const &p);
617void write_csv(std::string filename,
const std::vector<Point_2d> &v);
618void write_csv(std::string filename,
const std::vector<RAY> &v);
625std::ostream &operator<<(std::ostream &os,
RAY const &r);
630 ,
double my_boundary_p1[2],
double my_boundary_p2[2]
631 ,
double my_center[2],
int my_level);
634 struct Point *points;
639 unsigned long number;
640 double boundary_p1[2];
641 double boundary_p2[2];
651 PosType area(){
return (boundary_p2[0]-boundary_p1[0])*(boundary_p2[1]-boundary_p1[1]);}
653 std::list<Branch *> neighbors;
655 static unsigned long countID;
674 *
this = std::move(membank);
677 bank = std::move(membank.bank);
681 T * operator()(
size_t N){
682 if(N <= 0)
return nullptr;
684 bank.emplace_back(
new T[N]);
686 return bank.back().get();
707 size_t number_of_blocks(){
return bank.size();}
715 std::vector<std::unique_ptr<T[]> > bank;
767 iterator():current(NULL){ }
773 Point *operator*(){
return current;}
777 if(current->prev == NULL)
return false;
778 current=current->prev;
783 bool operator++(
int){
785 if(current->prev == NULL)
return false;
786 current=current->prev;
793 if(current->next == NULL)
return false;
794 current=current->next;
799 bool operator--(
int){
801 if(current->next == NULL)
return false;
802 current=current->next;
806 void JumpDownList(
int jump){
809 if(jump > 0)
for(i=0;i<jump;++i) --(*
this);
810 if(jump < 0)
for(i=0;i<abs(jump);++i) ++(*
this);
814 bool operator==(
const iterator my_it){
815 return (current == my_it.current);
818 bool operator!=(
const iterator my_it){
819 return (current != my_it.current);
824 unsigned long size()
const {
return Npoints;}
826 inline bool IsTop(PointList::iterator &it)
const{
829 inline bool IsBottom(PointList::iterator &it)
const{
830 return *it == bottom;
833 Point *Top()
const {
return top;}
834 Point *Bottom()
const {
return bottom;}
839 void InsertPointAfterCurrent(iterator ¤t,
Point *);
840 void InsertPointBeforeCurrent(iterator ¤t,
Point *);
842 void MoveCurrentToBottom(iterator ¤t);
845 void InsertListAfterCurrent(iterator ¤t,
PointList *list2);
846 void InsertListBeforeCurrent(iterator ¤t,
PointList *list2);
848 void ShiftList(iterator ¤t);
854 void setN(
unsigned long N){Npoints = N;}
855 void setTop(
Point *p){top = p;}
856 void setBottom(
Point *p){bottom = p;}
861 unsigned long Npoints;
882template <
typename T = PosType>
901 if(
this == &p)
return *
this;
909 tmp.x[0] = x[0] + p.x[0];
910 tmp.x[1] = x[1] + p.x[1];
911 tmp.x[2] = x[2] + p.x[2];
916 tmp.x[0] = x[0] - p.x[0];
917 tmp.x[1] = x[1] - p.x[1];
918 tmp.x[2] = x[2] - p.x[2];
953 Point_3d operator*(PosType value)
const{
964 return x[0]*p.x[0] + x[1]*p.x[1] + x[2]*p.x[2];
970 v[0] = x[1]*p[2] - x[2]*p[1];
971 v[1] = x[2]*p[0] - x[0]*p[2];
972 v[2] = x[0]*p[1] - x[1]*p[0];
978 return sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
981 T length_sqr()
const{
982 return x[0]*x[0] + x[1]*x[1] + x[2]*x[2];
987 T c = cos(theta),s = sin(theta);
988 T tmp = c*x[0] - s*x[1];
989 x[1] = c*x[1] + s*x[0];
993 x[0] = c*tmp - s*x[2];
994 x[2] = c*x[2] + s*tmp;
1007 double s = sqrt(x[0]*x[0] + x[1]*x[1]);
1014 Point_3d<T> v(-x[0]*x[2],-x[1]*x[2] ,x[0]*x[0] + x[1]*x[1]);
1019 T* data(){
return x;}
1022 T & operator[](
size_t i){
return x[i];}
1023 const T & operator[](
size_t i)
const {
return x[i];}
1026template <
typename T>
1027std::ostream &operator<<(std::ostream &os,
Point_3d<T> const &p) {
1028 return os << p.x[0] <<
" " << p.x[1] <<
" " << p.x[2];
1031inline double pointx(
Point &p){
return p.x[0];}
1032inline double pointy(
Point &p){
return p.x[1];}
1055 bool operator++(int){
1057 if(current->prev == NULL) return false;
1058 current=current->prev;
1065 if(current->next == NULL) return false;
1066 current=current->next;
1071 bool operator--(int){
1073 if(current->next == NULL) return false;
1074 current=current->next;
1078 void JumpDownList(int jump){
1081 if(jump > 0) for(i=0;i<jump;++i) --(*this);
1082 if(jump < 0) for(i=0;i<abs(jump);++i) ++(*this);
1086 bool operator==(const iterator my_it){
1087 return (current == my_it.current);
1090 bool operator!=(const iterator my_it){
1091 return (current != my_it.current);
1096template <typename T>
1101 ~LIST(){EmptyList();}
1105 LISTiterator<T> top(){
1107 it.current_it = list.begin();
1111 LISTiterator<T> bottom(){
1113 it.current_it = list.end();
1117 unsigned long size() const {return list.size();}
1119 inline bool IsTop(LISTiterator<T> &it) const{
1120 return it.current_it == list.begin();
1122 inline bool IsBottom(LIST::iterator &it) const{
1123 return it.current_it == list.end();
1126 T *Top() const {return list.front();}
1127 T *Bottom() const {return list.back();}
1129 void EmptyList(){list.clear();}
1131 void InsertAfterCurrent(LISTiterator<T> &it,T &d){
1132 list.insert(it.current_it+1,d);
1134 void InsertBeforeCurrent(LISTiterator<T> &it,T &d){
1135 list.insert(it.current_it,d);
1138 void MoveCurrentToBottom(iterator ¤t);
1139 Point *TakeOutCurrent(iterator ¤t);
1141 void InsertListAfterCurrent(iterator ¤t,PointList *list2);
1142 void InsertListBeforeCurrent(iterator ¤t,PointList *list2);
1143 void MergeLists(PointList* list2);
1144 void ShiftList(iterator ¤t);
1148 //void setN(unsigned long N){Npoints = N;}
1149 //void setTop(Point *p){top = p;}
1150 //void setBottom(Point *p){bottom = p;}
1155 //unsigned long Npoints;
1157 // make a point uncopyable
1158 LIST &operator=(const LIST &p);
1166template <
typename T = PosType>
1179 for(
int i=0 ; i<dim ; ++i ) x[i] = p.x[i];
1183 if(
this == &p)
return *
this;
1184 for(
int i=0 ; i<dim ; ++i ) x[i] = p.x[i];
1189 for(
int i=0 ; i<dim ; ++i ) tmp.x[i] = x[i] + p.x[i];
1194 for(
int i=0 ; i<dim ; ++i ) tmp.x[i] = x[i] - p.x[i];
1198 for(
int i=0 ; i<dim ; ++i ) x[i] += p.x[i];
1202 for(
int i=0 ; i<dim ; ++i ) x[i] -= p.x[i];
1206 for(
int i=0 ; i<dim ; ++i ) x[i]/=value;
1211 for(
int i=0 ; i<dim ; ++i ) tmp.x[i] = x[i]/value;
1215 for(
int i=0 ; i<dim ; ++i ) x[i] *=value;
1218 Point_nd operator*(PosType value)
const{
1220 for(
int i=0 ; i<dim ; ++i ) tmp.x[i] = x[i]*value;
1227 for(
int i=0 ; i<dim ; ++i ) ans += x[i]*p.x[i];
1234 for(
int i=0 ; i<dim ; ++i ) ans += x[i]*x[i];
1242 T* data(){
return x.data();}
1245 T & operator[](
size_t i){
return x[i];}
1246 const T & operator[](
size_t i)
const {
return x[i];}
The box representing a branch of a binary tree structure. Used specifically in TreeStruct for organiz...
Definition point.h:628
void print()
print out all member data for testing purposes
Definition Tree.cpp:168
bool refined
Marks point as start of a level of refinement.
Definition point.h:647
unsigned long npoints
pointer to first points in Branch
Definition point.h:636
A point that automatically has an image point.
Definition point.h:496
Class for representing points or vectors in 2 dimensions. Not that the dereferencing operator is over...
Definition point.h:48
Point_2d rotated(PosType theta) const
returns a copy of the point that it rotated
Definition point.h:152
PosType length() const
length
Definition point.h:134
PosType operator*(const Point_2d &p) const
scalar product
Definition point.h:125
void unitize()
rescale to make a unit length vector
Definition point.h:162
PosType length_sqr() const
length^2
Definition point.h:139
PosType operator^(const Point_2d &p) const
outer product
Definition point.h:129
Class for representing points or vectors in 3 dimensions. Not that the dereferencing operator is over...
Definition point.h:883
T length() const
length
Definition point.h:977
T operator*(const Point_3d &p) const
scalar product
Definition point.h:963
void rotate(T theta, T phi)
a rotation theta around the z-axis followed by a rotation phi around the y-axis
Definition point.h:986
Point_3d< T > unitTheta()
Definition point.h:1013
Point_3d< T > unitPhi()
returns the unit vector in the direction of the right handed spherical coordinate Phi
Definition point.h:1006
void unitize()
rescale to make a unit length vector
Definition point.h:998
Point_3d< T > operator^(const Point_3d< T > &p) const
outer product
Definition point.h:968
T length_sqr() const
length
Definition point.h:1232
T operator*(const Point_nd< T > &p) const
scalar product
Definition point.h:1225
A point on the source or image plane that contains a position and the lensing quantities.
Definition point.h:414
double flux()
surface_brightness * gridsize * gridsize
Definition point.h:456
bool inverted()
returns true if the image is double inverted, At very low magnification or when there is a rotation t...
Definition point.h:481
void Print()
print out all member data for testing purposes
Definition Tree.cpp:103
Point operator=(const Point_2d &p)
Only copies position!!
Definition point.h:429
Point()
Definition Tree.cpp:63
link list for points, uses the linking pointers within the Point type unlike Kist
Definition point.h:755
Point * TakeOutCurrent(iterator ¤t)
Definition list.cpp:105
Simple representaion of a light path giving position on the image and source planes and lensing quant...
Definition point.h:510
KappaType dt
time-delay
Definition point.h:592
Point_2d alpha() const
deflection angle, x-y
Definition point.h:613
Point_2d x
image position
Definition point.h:584
KappaType invmag() const
inverse of the magnification
Definition point.h:596
Point_2d y
source position
Definition point.h:586