PolyLink
A library to allow manipulation of geometry from within Mathematica
 All Classes Namespaces Files Functions Variables Properties
PointRef.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6 using Wolfram.NETLink;
7 
8 namespace PolyLink
9 {
13  public class PointRef : MathLinked
14  {
18  public Expr Expr { get; set; }
19 
24  public PointRef(Expr point)
25  {
26  Expr = point;
27  }
28 
29  public static PointRef PointFromInts(int x, int y, int z)
30  {
31  return new PointRef(("{{ {0}, {1}, {2} }}".MsEvalWith(x,y,z)));
32  }
33 
34  public static Expr operator- (PointRef p1, PointRef p2)
35  {
36  return p1.ML["{0} - {1}"].Format(p1.Expr, p2.Expr).Eval();
37  }
38 
39  public override string ToString()
40  {
41  return "ref:" + Expr.ToString();
42  }
43 
44 
45  //Static methods
46  private static readonly Expr _origin = MSingle.Eval(@"{ 0, 0, 0}");
47  private static readonly PointRef _originRef = new PointRef(Origin);
48  private static readonly Expr _p100 = MSingle.Eval(@"{ 1, 0, 0}");
49  private static readonly PointRef _ref100 = new PointRef(P100);
50  private static readonly Expr _p010 = MSingle.Eval(@"{ 0, 1, 0}");
51  private static readonly PointRef _ref010 = new PointRef(P010);
52 
56  public static Expr Origin
57  {
58  get { return _origin; }
59  }
60 
64  public static PointRef OriginRef
65  {
66  get { return _originRef; }
67  }
68 
72  public static Expr P100
73  {
74  get { return _p100; }
75  }
76 
80  public static PointRef Ref100
81  {
82  get { return _ref100; }
83  }
84 
88  public static Expr P010
89  {
90  get { return _p010; }
91  }
92 
96  public static PointRef Ref010
97  {
98  get { return _ref010; }
99  }
100 
101  public Expr Highlight
102  {
103  get { return ML["List[ {{ PointSize[Large], Orange, Point[{0}] }} ]"].Format(Expr).Eval(); }
104  }
105 
106  public Expr TwoDForm
107  {
108  get
109  {
110  //consider caching this
111  if ((bool) ML["{0} == 0"].Format(Expr.Part(3)).EvalObject())
112  {
113  return ML["{0}[[1;;2]]"].Format(Expr).Eval();
114  }
115  else
116  {
117  throw new InvalidOperationException();
118  }
119  }
120  }
121 
122  public PointRef DeepClone
123  {
124  get
125  {
126  return new PointRef(Expr);
127  }
128  }
129 
130  public void Transform(Expr tf)
131  {
132  Expr = ML["{0}[{1}]"].Format(tf, Expr).Eval();
133  }
134 
135  public static PointRef Constructor(Expr e)
136  {
137  return new PointRef(e);
138  }
139  }
140 }