diff --git a/mono/Assistance/Assistance.csproj b/mono/Assistance/Assistance.csproj
index c23bc66..b98c551 100644
--- a/mono/Assistance/Assistance.csproj
+++ b/mono/Assistance/Assistance.csproj
@@ -64,11 +64,7 @@
-
- False
- glib-sharp-2.0
-
-
+
False
gtk-sharp-2.0
@@ -76,10 +72,14 @@
False
gtk-sharp-2.0
-
-
+
+ False
+ glib-sharp-2.0
+
+
False
gtk-sharp-2.0
+
\ No newline at end of file
diff --git a/mono/Assistance/Drawing.cs b/mono/Assistance/Drawing.cs
index fa3f972..5e9e171 100644
--- a/mono/Assistance/Drawing.cs
+++ b/mono/Assistance/Drawing.cs
@@ -4,13 +4,13 @@ namespace Assistance {
namespace Drawing {
public class Helper {
public static Rectangle getBounds(Cairo.Context context) {
- double w = 1.0;
- double h = 1.0;
- if (context.GetTarget() is Cairo.ImageSurface) {
- Cairo.ImageSurface surface = (Cairo.ImageSurface)context.GetTarget();
- w = surface.Width;
- h = surface.Height;
- }
+ double w = 2000;
+ double h = 1500;
+ //if (context.GetTarget() is Cairo.ImageSurface) {
+ // Cairo.ImageSurface surface = (Cairo.ImageSurface)context.GetTarget();
+ // w = surface.Width;
+ // h = surface.Height;
+ //}
Point[] corners = new Point[] {
new Point(0.0, 0.0),
diff --git a/mono/Assistance/DynamicSurface.cs b/mono/Assistance/DynamicSurface.cs
index 9655b9d..20fdbd8 100644
--- a/mono/Assistance/DynamicSurface.cs
+++ b/mono/Assistance/DynamicSurface.cs
@@ -8,6 +8,7 @@ namespace Assistance {
private int offsetX;
private int offsetY;
private Cairo.ImageSurface surface;
+ private Cairo.Context privateContext;
public DynamicSurface(double incrementScale = 1.2)
{ this.incrementScale = incrementScale; }
@@ -24,21 +25,20 @@ namespace Assistance {
public int height
{ get { return isEmpty ? 0 : surface.Height; } }
+ public Cairo.Context context
+ { get { return privateContext; } }
+
public Rectangle getBounds() {
return isEmpty ? new Rectangle()
: new Rectangle((double)offsetX, (double)offsetY, (double)(offsetX + surface.Width), (double)(offsetY + surface.Height));
}
- public Cairo.Context getContext() {
- if (isEmpty) return null;
- Cairo.Context context = new Cairo.Context(surface);
- context.Antialias = Cairo.Antialias.Gray;
- context.Translate(-offsetX, -offsetY);
- return context;
- }
+ public void flush()
+ { if (surface != null) surface.Flush(); }
public void draw(Cairo.Context context, double alpha = 1.0) {
if (isEmpty) return;
+ flush();
context.Save();
context.Translate(offsetX, offsetY);
context.SetSource(surface);
@@ -49,15 +49,19 @@ namespace Assistance {
public void clear() {
if (isEmpty) return;
+ privateContext.Dispose();
+ privateContext = null;
surface.Dispose();
surface = null;
- }
+ }
- private bool doExpand(Rectangle rect, bool noScale) {
+ public bool expand(Rectangle rect, bool noScale = false) {
+ rect = new Rectangle(rect.p0).expand(rect.p1);
+
int rl = (int)Math.Floor(rect.x0 + Geometry.precision);
int rt = (int)Math.Floor(rect.y0 + Geometry.precision);
- int rr = Math.Max(rl, (int)Math.Ceiling(rect.x1 - Geometry.precision));
- int rb = Math.Max(rt, (int)Math.Ceiling(rect.y1 - Geometry.precision));
+ int rr = Math.Max(rl, (int)Math.Ceiling(rect.x1 - Geometry.precision)) + 1;
+ int rb = Math.Max(rt, (int)Math.Ceiling(rect.y1 - Geometry.precision)) + 1;
int l, t, r, b;
if (surface == null) {
@@ -81,46 +85,30 @@ namespace Assistance {
int h = b - t;
if (surface != null && l == offsetX && t == offsetY && w == surface.Width && h == surface.Height)
return false;
-
+ if (w <= 0 || h <= 0)
+ return false;
+
Cairo.ImageSurface newSurface = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
- Cairo.Context context = new Cairo.Context(newSurface);
- if (surface != null) {
- context.Translate(offsetX - l, offsetY - t);
- context.SetSource(surface);
- context.Paint();
- context.GetTarget().Flush();
- context.Dispose();
+ Cairo.Context newContext = new Cairo.Context(newSurface);
+ if (!isEmpty) {
+ flush();
+ newContext.Save();
+ newContext.Translate(offsetX - l, offsetY - t);
+ newContext.SetSource(surface);
+ newContext.Paint();
+ newContext.Restore();
+ clear();
}
-
offsetX = l;
offsetY = t;
surface = newSurface;
+ privateContext = newContext;
+ privateContext.Antialias = Cairo.Antialias.Gray;
+ privateContext.Translate(-offsetX, -offsetY);
return true;
}
- public bool expand(Rectangle rect, bool noScale = false) {
- Cairo.Surface surface = this.surface;
- if (doExpand(rect, noScale)) {
- if (surface != null) surface.Dispose();
- return true;
- }
- return false;
- }
-
- public bool expandContext(ref Cairo.Context context, Rectangle rect, bool noScale = false) {
- Cairo.Surface surface = this.surface;
- if (context != null) context.GetTarget().Flush();
- if (doExpand(rect, noScale)) {
- Cairo.Context oldContext = context;
- context = getContext();
- if (oldContext != null) oldContext.Dispose();
- surface.Dispose();
- return true;
- }
- return false;
- }
-
public void Dispose()
{ Dispose(true); GC.SuppressFinalize(this); }
protected virtual void Dispose(bool disposing)
diff --git a/mono/Assistance/Geometry.cs b/mono/Assistance/Geometry.cs
index e2da322..ce67232 100644
--- a/mono/Assistance/Geometry.cs
+++ b/mono/Assistance/Geometry.cs
@@ -10,14 +10,14 @@ namespace Assistance {
public static bool isEqual(double a, double b)
{ return Math.Abs(b - a) <= precision; }
- public static bool isGreaterOrEqual(double a, double b)
- { return b - a <= precision; }
- public static bool isLessOrEqual(double a, double b)
- { return isGreaterOrEqual(b, a); }
public static bool isLess(double a, double b)
- { return !isGreaterOrEqual(a, b); }
+ { return b - a > precision; }
public static bool isGreater(double a, double b)
- { return !isGreaterOrEqual(b, a); }
+ { return a - b > precision; }
+ public static bool isLessOrEqual(double a, double b)
+ { return a - b <= precision; }
+ public static bool isGreaterOrEqual(double a, double b)
+ { return b - a <= precision; }
public static double logNormalDistribuitionUnscaled(double x, double x0, double w) {
return Math.Exp(-0.5*Math.Pow(Math.Log(x/x0)/w, 2.0))/x;
@@ -113,5 +113,21 @@ namespace Assistance {
+ t0*( 3.0*ll - 4.0*l + 1.0)
+ t1*( 3.0*ll - 2.0*l );
}
+
+ public static Track.Point interpolationSpline(Track.Point p0, Track.Point p1, Track.Point t0, Track.Point t1, double l) {
+ double ll = l*l;
+ double lll = ll*l;
+ return p0*( 2.0*lll - 3.0*ll + 1.0)
+ + p1*(-2.0*lll + 3.0*ll )
+ + t0*( lll - 2.0*ll + l )
+ + t1*( lll - 1.0*ll );
+ }
+
+ public static Track.Point interpolationSplineTangent(Track.Point p0, Track.Point p1, Track.Point t0, Track.Point t1, double l) {
+ double ll = l*l;
+ return (p0 - p1)*6.0*(ll - l)
+ + t0*( 3.0*ll - 4.0*l + 1.0)
+ + t1*( 3.0*ll - 2.0*l );
+ }
}
}
diff --git a/mono/Assistance/Guideline.cs b/mono/Assistance/Guideline.cs
index d224c70..b90545a 100644
--- a/mono/Assistance/Guideline.cs
+++ b/mono/Assistance/Guideline.cs
@@ -8,7 +8,7 @@ namespace Assistance {
public static readonly Pen penActive = new Pen("Deep Sky Blue");
public static readonly double snapLenght = 20.0;
public static readonly double snapScale = 1.0;
- public static readonly double maxLenght = 2.0*snapLenght*snapScale;
+ public static readonly double maxLenght = 20.0*snapLenght*snapScale;
public virtual Track.WayPoint transformPoint(Track.WayPoint point)
{ return point; }
@@ -48,11 +48,11 @@ namespace Assistance {
}
public static Guideline findBest(List guidelines, Track track) {
- double bestWeight = double.PositiveInfinity;
+ double bestWeight = 0.0;
Guideline best = null;
foreach(Guideline guideline in guidelines) {
double weight = guideline.calcTrackWeight(track);
- if (weight < bestWeight) {
+ if (best == null || weight < bestWeight) {
bestWeight = weight;
best = guideline;
}
diff --git a/mono/Assistance/InputManager.cs b/mono/Assistance/InputManager.cs
index dff039c..1049d36 100644
--- a/mono/Assistance/InputManager.cs
+++ b/mono/Assistance/InputManager.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace Assistance {
public class InputManager: Track.IOwner {
- public static readonly Drawing.Pen penPreview = new Drawing.Pen("Dark Green", 1.0, 0.25);
+ public static readonly Drawing.Pen penPreview = new Drawing.Pen("Dark Green", 3.0, 0.25);
public static readonly double levelAlpha = 0.8;
public class TrackHandler: Track.Handler {
@@ -55,7 +55,7 @@ namespace Assistance {
public interface IModifier: Track.IOwner {
void activate();
void modify(List