From 9b27c61cea3e6ff6eef6511bf4f8c94858bfa2e1 Mon Sep 17 00:00:00 2001 From: HOSOKAWA Kenchi Date: Mon, 22 Mar 2010 00:07:42 +0900 Subject: [PATCH] misc --- dev3/psychlops/core/graphic/canvas.cs | 14 +++---- dev3/psychlops/core/graphic/font.cs | 11 +++--- dev3/psychlops/core/math/matrix.cs | 73 +++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 12 deletions(-) diff --git a/dev3/psychlops/core/graphic/canvas.cs b/dev3/psychlops/core/graphic/canvas.cs index 9d2cad3..bffa5c4 100644 --- a/dev3/psychlops/core/graphic/canvas.cs +++ b/dev3/psychlops/core/graphic/canvas.cs @@ -368,10 +368,10 @@ namespace Psychlops FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic); FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic); LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary(); - LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.TEXT_ALIGN_LEFT, TextAlignment.Left); - LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.TEXT_ALIGN_CENTER, TextAlignment.Center); - LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.TEXT_ALIGN_RIGHT, TextAlignment.Right); - LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.NOT_SPECIFIED, TextAlignment.Left); + LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left); + LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center); + LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right); + LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left); } #endregion public Letters clone() @@ -393,9 +393,9 @@ namespace Psychlops double left = 0; switch (d.align) { - case Letters.HorizontalAlign.TEXT_ALIGN_LEFT: break; - case Letters.HorizontalAlign.TEXT_ALIGN_CENTER: left = tmp.Width / 2; break; - case Letters.HorizontalAlign.TEXT_ALIGN_RIGHT: left = tmp.Width; break; + case Letters.HorizontalAlign.left: break; + case Letters.HorizontalAlign.center: left = tmp.Width / 2; break; + case Letters.HorizontalAlign.right: left = tmp.Width; break; } System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left); System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size); diff --git a/dev3/psychlops/core/graphic/font.cs b/dev3/psychlops/core/graphic/font.cs index 95dd6bc..2d82293 100644 --- a/dev3/psychlops/core/graphic/font.cs +++ b/dev3/psychlops/core/graphic/font.cs @@ -61,26 +61,27 @@ namespace Psychlops protected double width_, height_; public Point datum; - public enum HorizontalAlign { NOT_SPECIFIED=-1, TEXT_ALIGN_LEFT=0, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT }; + public enum HorizontalAlign { not_specified=-1, left=0, center, right }; + public const HorizontalAlign NOT_SPECIFIED=HorizontalAlign.not_specified, TEXT_ALIGN_LEFT=HorizontalAlign.left, TEXT_ALIGN_CENTER = HorizontalAlign.center, TEXT_ALIGN_RIGHT=HorizontalAlign.right; public HorizontalAlign align; public Letters() { str_ = ""; font = Font.default_font; - align = HorizontalAlign.TEXT_ALIGN_LEFT; + align = HorizontalAlign.left; } public Letters(String init_str) { str_ = init_str; font_ = Font.default_font; - align = HorizontalAlign.TEXT_ALIGN_LEFT; + align = HorizontalAlign.center; } public Letters(String init_str, Font init_font) { str_ = init_str; font_ = init_font; - align = HorizontalAlign.TEXT_ALIGN_LEFT; + align = HorizontalAlign.right; } ~Letters() { @@ -100,7 +101,7 @@ namespace Psychlops public Figure centering(Point p) { datum = p; - align = HorizontalAlign.TEXT_ALIGN_CENTER; + align = HorizontalAlign.center; return this; } public Figure shift(Point p) diff --git a/dev3/psychlops/core/math/matrix.cs b/dev3/psychlops/core/math/matrix.cs index fd67eb0..e16003e 100644 --- a/dev3/psychlops/core/math/matrix.cs +++ b/dev3/psychlops/core/math/matrix.cs @@ -3,4 +3,77 @@ namespace Psychlops { + + public abstract class Matrix + { + public abstract double this[int row, int col] + { + get; + set; + } + + public static Matrix operator +(Matrix m, double d) + { + return new MatrixExpression; + } + } + + + namespace Internal + { + + public class MatrixImplementation : Matrix + { + internal double[] elements; + readonly int nrow, ncol; + + public MatrixImplementation(int dnrow, int dncol) + { + nrow = dnrow; + ncol = dncol; + elements = new double[nrow * ncol]; + } + + public override double this[int row, int col] + { + get + { + return elements[(row - 1) * ncol + (col - 1)]; + } + set + { + elements[(row - 1) * ncol + (col - 1)] = value; + } + } + } + + public class MatrixExpression : Matrix + { + MatrixImplementation imp; + readonly int nrow, ncol; + readonly int drow, dcol; + + public MatrixExpression(MatrixImplementation target, int ddrow, int ddcol, int dnrow, int dncol) + { + nrow = dnrow; + ncol = dncol; + drow = ddrow; + dcol = ddcol; + imp = target; + } + + public override double this[int row, int col] + { + get + { + return imp.elements[(row - drow) * ncol + (col - dcol)]; + } + set + { + imp.elements[(row - drow) * ncol + (col - dcol)] = value; + } + } + } + } + } \ No newline at end of file -- 2.11.0